kio-extras5/0002-Port-textcreator-thumbnailer.patch

128 lines
4.3 KiB
Diff
Raw Normal View History

From 47777a2631fb09eb930e80015e447037b4467ce7 Mon Sep 17 00:00:00 2001
From: Maarten De Meyer <de.meyer.maarten@gmail.com>
Date: Mon, 29 Sep 2014 00:32:20 +0200
Subject: [PATCH 2/5] Port textcreator thumbnailer
Thumbcreator needs to be a QGuiApplication because we use pixmaps.
CCBUG: 339456
REVIEW: 120408
(cherry picked from commit 7cadf8888ec1b02e30512a44c1bae76202f30f96)
---
thumbnail/CMakeLists.txt | 25 ++++++++++++++-----------
thumbnail/textcreator.cpp | 14 +++++++-------
thumbnail/thumbnail.cpp | 2 +-
3 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/thumbnail/CMakeLists.txt b/thumbnail/CMakeLists.txt
index aec8b8ea9c86f6b8b650caf885c02117dbf014f0..4c2d5e9cab7c500d2d29a5ad479b7dfb514de85c 100644
--- a/thumbnail/CMakeLists.txt
+++ b/thumbnail/CMakeLists.txt
@@ -107,16 +107,19 @@ target_link_libraries(svgthumbnail
install(TARGETS svgthumbnail DESTINATION ${PLUGIN_INSTALL_DIR})
-# ########### next target ###############
-#
-# set(textthumbnail_PART_SRCS textcreator.cpp)
-#
-# add_library(textthumbnail MODULE ${textthumbnail_PART_SRCS})
-#
-# target_link_libraries(textthumbnail ${KIO_LIBRARIES})
-#
-# install(TARGETS textthumbnail DESTINATION ${PLUGIN_INSTALL_DIR})
-#
+########### next target ###############
+
+set(textthumbnail_PART_SRCS textcreator.cpp)
+
+add_library(textthumbnail MODULE ${textthumbnail_PART_SRCS})
+
+target_link_libraries(textthumbnail
+ Qt5::Gui
+ KF5::KIOWidgets
+)
+
+install(TARGETS textthumbnail DESTINATION ${PLUGIN_INSTALL_DIR})
+
# ########### next target ###############
#
# if(NOT WINCE)
@@ -222,7 +225,7 @@ install(FILES
svgthumbnail.desktop
imagethumbnail.desktop
jpegthumbnail.desktop
-# textthumbnail.desktop
+ textthumbnail.desktop
# htmlthumbnail.desktop
# djvuthumbnail.desktop
# desktopthumbnail.desktop
diff --git a/thumbnail/textcreator.cpp b/thumbnail/textcreator.cpp
index d3f633ced1bd780c6e8ce53464fc1607e1ed1795..7c0263c8e8cb4f88d1429b5714c51c2939d817f0 100644
--- a/thumbnail/textcreator.cpp
+++ b/thumbnail/textcreator.cpp
@@ -21,16 +21,15 @@
#include "textcreator.h"
#include <QFile>
+#include <QFontDatabase>
#include <QPixmap>
#include <QImage>
#include <QPainter>
#include <QPalette>
#include <QTextCodec>
-
-#include <kglobalsettings.h>
-#include <kencodingprober.h>
-#include <klocale.h>
+// TODO Fix or remove kencodingprober code
+// #include <kencodingprober.h>
extern "C"
{
@@ -60,7 +59,7 @@ static QTextCodec *codecFromContent(const char *data, int dataSize)
#else
QByteArray ba = QByteArray::fromRawData(data, dataSize);
// try to detect UTF text, fall back to locale default (which is usually UTF-8)
- return QTextCodec::codecForUtfText(ba, KGlobal::locale()->codecForEncoding());
+ return QTextCodec::codecForUtfText(ba, QTextCodec::codecForLocale());
#endif
}
@@ -84,7 +83,8 @@ bool TextCreator::create(const QString &path, int width, int height, QImage &img
int yborder = 1 + pixmapSize.height()/16; // minimum y-border
// this font is supposed to look good at small sizes
- QFont font = KGlobalSettings::smallestReadableFont();
+ QFont font = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont);
+
font.setPixelSize( qMax(7, qMin( 10, ( pixmapSize.height() - 2 * yborder ) / 16 ) ) );
QFontMetrics fm( font );
@@ -121,7 +121,7 @@ bool TextCreator::create(const QString &path, int width, int height, QImage &img
foreach ( const QString &line, textLines ) {
QString trimmedLine = line.trimmed();
if ( trimmedLine.contains( '\t' ) || trimmedLine.contains( " " ) ) {
- font.setFamily( KGlobalSettings::fixedFont().family() );
+ font.setFamily( QFontDatabase::systemFont(QFontDatabase::FixedFont).family());
break;
}
}
diff --git a/thumbnail/thumbnail.cpp b/thumbnail/thumbnail.cpp
index 3a38dc916c33243a23e5e3cb9a69a88eb49e30b0..d4a7f35014af21fb1dacaea59128ac7373e6805b 100644
--- a/thumbnail/thumbnail.cpp
+++ b/thumbnail/thumbnail.cpp
@@ -118,7 +118,7 @@ extern "C" Q_DECL_EXPORT int kdemain( int argc, char **argv )
// and HTML previews need even KApplication :(
putenv(strdup("SESSION_MANAGER="));
- QCoreApplication app( argc, argv);
+ QGuiApplication app(argc, argv);
#endif
--
2.1.2