From b2fabac69e1468161f3221ca14ad40636a8bc2c4 Mon Sep 17 00:00:00 2001 From: Denis Mingulov Date: Fri, 18 Jun 2010 11:02:48 +0200 Subject: [PATCH] ImageViewer: Pick up the icons from the system theme using QIcon::fromTheme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge-request: 2165 Reviewed-by: Thorbjørn Lindeijer --- src/plugins/imageviewer/imageviewer.cpp | 25 +++++++++++++++++++++++++ src/plugins/imageviewer/imageviewer.h | 11 +++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/plugins/imageviewer/imageviewer.cpp b/src/plugins/imageviewer/imageviewer.cpp index c44b941295d..ad6754c12cb 100644 --- a/src/plugins/imageviewer/imageviewer.cpp +++ b/src/plugins/imageviewer/imageviewer.cpp @@ -36,6 +36,7 @@ #include #include +#include #include #include @@ -69,6 +70,17 @@ ImageViewer::ImageViewer(QWidget *parent) d_ptr->toolbar = new QWidget(); d_ptr->ui_toolbar.setupUi(d_ptr->toolbar); + // icons update - try to use system theme + updateButtonIconByTheme(d_ptr->ui_toolbar.toolButtonZoomIn, "zoom-in"); + updateButtonIconByTheme(d_ptr->ui_toolbar.toolButtonZoomOut, "zoom-out"); + updateButtonIconByTheme(d_ptr->ui_toolbar.toolButtonOriginalSize, "zoom-original"); + updateButtonIconByTheme(d_ptr->ui_toolbar.toolButtonFitToScreen, "zoom-fit-best"); + // a display - something is on the background + updateButtonIconByTheme(d_ptr->ui_toolbar.toolButtonBackground, "video-display"); + // "emblem to specify the directory where the user stores photographs" + // (photograph has outline - piece of paper) + updateButtonIconByTheme(d_ptr->ui_toolbar.toolButtonOutline, "emblem-photos"); + // connections connect(d_ptr->file, SIGNAL(changed()), this, SIGNAL(changed())); @@ -190,5 +202,18 @@ void ImageViewer::scaleFactorUpdate(qreal factor) d_ptr->ui_toolbar.labelInfo->setText(info); } +bool ImageViewer::updateButtonIconByTheme(QAbstractButton *button, const QString &name) +{ + QTC_ASSERT(button, return false); + QTC_ASSERT(!name.isEmpty(), return false); + + if (QIcon::hasThemeIcon(name)) { + button->setIcon(QIcon::fromTheme(name)); + return true; + } + + return false; +} + } // namespace Internal } // namespace ImageViewer diff --git a/src/plugins/imageviewer/imageviewer.h b/src/plugins/imageviewer/imageviewer.h index f18f7d63697..b4426a0b3fc 100644 --- a/src/plugins/imageviewer/imageviewer.h +++ b/src/plugins/imageviewer/imageviewer.h @@ -37,6 +37,8 @@ #include #include +QT_FORWARD_DECLARE_CLASS(QAbstractButton) + namespace ImageViewer { namespace Internal { class ImageViewerFile; @@ -75,6 +77,15 @@ public: public slots: void scaleFactorUpdate(qreal factor); +private: + /*! + \brief Try to change button's icon to the one from the current theme + \param button Button where an icon should be changed + \param name Icon name in the in the current icon theme + \return true if icon is updated, false otherwise + */ + bool updateButtonIconByTheme(QAbstractButton *button, const QString &name); + private: QScopedPointer d_ptr; };