[kde-doc-english] [trojita/addressbook] src/Gui: GUI: utility function for converting SVG images to a downscaled image usable within QLabel

Jan Kundrát jkt at flaska.net
Fri May 24 15:35:54 UTC 2013


Git commit f7f348d13a0426d0bf013c0a2bbe49d8a94a5be4 by Jan Kundrát.
Committed on 24/05/2013 at 17:13.
Pushed by jkt into branch 'addressbook'.

GUI: utility function for converting SVG images to a downscaled image usable within QLabel

M  +15   -0    src/Gui/Util.cpp
M  +2    -0    src/Gui/Util.h

http://commits.kde.org/trojita/f7f348d13a0426d0bf013c0a2bbe49d8a94a5be4

diff --git a/src/Gui/Util.cpp b/src/Gui/Util.cpp
index dabdd7b..c7bdfdb 100644
--- a/src/Gui/Util.cpp
+++ b/src/Gui/Util.cpp
@@ -22,9 +22,11 @@
 
 
 #include <QApplication>
+#include <QBuffer>
 #include <QCursor> // for Util::centerWidgetOnScreen
 #include <QDesktopWidget> // for Util::centerWidgetOnScreen
 #include <QDir>
+#include <QIcon>
 #include <QProcess>
 #include <QSettings>
 
@@ -201,6 +203,19 @@ QFont systemMonospaceFont()
     return font;
 }
 
+/** @short Return image data from the specified filename as a self-contained URL of the data: scheme
+
+The imaeg is resized and always returned in the PNG format.
+*/
+QString resizedImageAsDataUrl(const QString &fileName, const int extent)
+{
+    QByteArray bdata;
+    QBuffer buf(&bdata);
+    buf.open(QIODevice::WriteOnly);
+    QIcon(fileName).pixmap(extent).toImage().save(&buf, "png");
+    return QLatin1String("data:image/png;base64,") + QString::fromUtf8(bdata.toBase64());
+}
+
 } // namespace Util
 
 } // namespace Gui
diff --git a/src/Gui/Util.h b/src/Gui/Util.h
index 6570566..c2c0230 100644
--- a/src/Gui/Util.h
+++ b/src/Gui/Util.h
@@ -45,6 +45,8 @@ QColor tintColor(const QColor &color, const QColor &tintColor);
 
 QFont systemMonospaceFont();
 
+QString resizedImageAsDataUrl(const QString &fileName, const int extent);
+
 } // namespace Util
 
 } // namespace Gui



More information about the kde-doc-english mailing list