[juk/Applications/18.12] /: hidpi: Port remaining icon uses to use QIcon for HiDPI support.

Michael Pyne null at kde.org
Sun Nov 11 23:50:49 GMT 2018


Git commit 1862b0f61b3261d198d215ec71b7104ccee92694 by Michael Pyne.
Committed on 11/11/2018 at 23:46.
Pushed by mpyne into branch 'Applications/18.12'.

hidpi: Port remaining icon uses to use QIcon for HiDPI support.

GUI: This fixes things like the warning icons in the file deletion
dialog, file renamer, menu icons (such as Create Playlist from Selected
Items), and the "Jump to Playing Track" button on the status bar.

The track position slider remains unfixed.

M  +4    -4    deletedialog.cpp
M  +3    -3    filerenamer.cpp
M  +4    -2    playlist.cpp
M  +1    -7    playlistbox.cpp
M  +2    -2    playlistcollection.cpp
M  +0    -27   playlistitem.cpp
M  +0    -1    playlistitem.h
M  +2    -1    statuslabel.cpp
M  +7    -7    systemtray.cpp
M  +2    -2    systemtray.h
M  +4    -4    viewmode.cpp
M  +3    -3    viewmode.h
M  +6    -4    webimagefetcher.cpp

https://commits.kde.org/juk/1862b0f61b3261d198d215ec71b7104ccee92694

diff --git a/deletedialog.cpp b/deletedialog.cpp
index 3912019..c33025b 100644
--- a/deletedialog.cpp
+++ b/deletedialog.cpp
@@ -70,13 +70,13 @@ void DeleteWidget::slotShouldDelete(bool shouldDelete)
     if(shouldDelete) {
         m_ui->ddDeleteText->setText(i18n("<qt>These items will be <b>permanently "
             "deleted</b> from your hard disk.</qt>"));
-        m_ui->ddWarningIcon->setPixmap(KIconLoader::global()->loadIcon("dialog-warning",
-            KIconLoader::Desktop, KIconLoader::SizeLarge));
+        m_ui->ddWarningIcon->setPixmap(
+                QIcon::fromTheme("dialog-warning").pixmap(KIconLoader::SizeLarge));
     }
     else {
         m_ui->ddDeleteText->setText(i18n("<qt>These items will be moved to the Trash Bin.</qt>"));
-        m_ui->ddWarningIcon->setPixmap(KIconLoader::global()->loadIcon("user-trash-full",
-            KIconLoader::Desktop, KIconLoader::SizeLarge));
+        m_ui->ddWarningIcon->setPixmap(
+                QIcon::fromTheme("user-trash-full").pixmap(KIconLoader::SizeLarge));
     }
 }
 
diff --git a/filerenamer.cpp b/filerenamer.cpp
index 7bd4c9c..f747a30 100644
--- a/filerenamer.cpp
+++ b/filerenamer.cpp
@@ -71,7 +71,7 @@ public:
         vboxLayout->addWidget(hbox);
 
         QLabel *l = new QLabel(hbox);
-        l->setPixmap(SmallIcon("dialog-warning", 32));
+        l->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(KIconLoader::SizeLarge));
         hboxVLayout->addWidget(l);
 
         l = new QLabel(i18n("You are about to rename the following files. "
@@ -336,8 +336,8 @@ FileRenamerWidget::~FileRenamerWidget()
 
 int FileRenamerWidget::addRowCategory(TagType category)
 {
-    static QIcon up   = SmallIcon("go-up");
-    static QIcon down = SmallIcon("go-down");
+    static QIcon up   = QIcon::fromTheme("go-up");
+    static QIcon down = QIcon::fromTheme("go-down");
 
     // Find number of categories already of this type.
     int categoryCount = 0;
diff --git a/playlist.cpp b/playlist.cpp
index 7cc3418..3592f99 100644
--- a/playlist.cpp
+++ b/playlist.cpp
@@ -1868,7 +1868,7 @@ void Playlist::slotShowRMBMenu(const QPoint &point)
 
         m_rmbMenu = new QMenu(this);
 
-        m_rmbMenu->addAction(SmallIcon("go-jump-today"),
+        m_rmbMenu->addAction(QIcon::fromTheme("go-jump-today"),
             i18n("Add to Play Queue"), this, SLOT(slotAddToUpcoming()));
         m_rmbMenu->addSeparator();
 
@@ -1897,7 +1897,9 @@ void Playlist::slotShowRMBMenu(const QPoint &point)
         m_rmbMenu->addSeparator();
 
         m_rmbMenu->addAction(
-            SmallIcon("folder-new"), i18n("Create Playlist From Selected Items..."), this, SLOT(slotCreateGroup()));
+            QIcon::fromTheme("folder-new"),
+            i18n("Create Playlist From Selected Items..."),
+            this, SLOT(slotCreateGroup()));
     }
 
     // Ignore any columns added by subclasses.
diff --git a/playlistbox.cpp b/playlistbox.cpp
index cc3cbb6..cc07fdc 100644
--- a/playlistbox.cpp
+++ b/playlistbox.cpp
@@ -16,7 +16,6 @@
 
 #include "playlistbox.h"
 
-#include <kiconloader.h>
 #include <kmessagebox.h>
 #include <kactioncollection.h>
 #include <ktoggleaction.h>
@@ -746,12 +745,7 @@ void PlaylistBox::Item::init()
 
     list->setupItem(this);
 
-    const auto iconLoader = KIconLoader::global();
-    const KIconLoader::Group iconGroup =
-            list->viewModeIndex() == 0
-                ? KIconLoader::Desktop
-                : KIconLoader::Toolbar;
-    setIcon(0, iconLoader->loadIcon(m_iconName, iconGroup));
+    setIcon(0, QIcon::fromTheme(m_iconName));
     list->addNameToDict(m_text);
 
     if(m_playlist) {
diff --git a/playlistcollection.cpp b/playlistcollection.cpp
index e4b6ac2..73e925a 100644
--- a/playlistcollection.cpp
+++ b/playlistcollection.cpp
@@ -938,7 +938,7 @@ PlaylistCollection::ActionHandler::ActionHandler(PlaylistCollection *collection)
     menu = new KActionMenu(i18n("&Guess Tag Information"), actions());
     actions()->addAction("guessTag", menu);
 
-    /* menu->setIcon(SmallIcon("wizard")); */
+    menu->setIcon(QIcon::fromTheme("wizard"));
 
     menu->addAction(createAction(i18n("From &File Name"), SLOT(slotGuessTagFromFile()),
                               "guessTagFile", "document-import", QKeySequence(Qt::CTRL + Qt::Key_G)));
@@ -971,7 +971,7 @@ PlaylistCollection::ActionHandler::ActionHandler(PlaylistCollection *collection)
 
     menu = new KActionMenu(i18n("Cover Manager"), actions());
     actions()->addAction("coverManager", menu);
-    /* menu->setIcon(SmallIcon("image-x-generic")); */
+    menu->setIcon(QIcon::fromTheme("image-x-generic"));
     menu->addAction(createAction(i18n("&View Cover"),
         SLOT(slotViewCovers()), "viewCover", "document-preview"));
     menu->addAction(createAction(i18n("Get Cover From &File..."),
diff --git a/playlistitem.cpp b/playlistitem.cpp
index 0e264054..6902b2f 100644
--- a/playlistitem.cpp
+++ b/playlistitem.cpp
@@ -99,33 +99,6 @@ FileHandle PlaylistItem::file() const
     return d->fileHandle;
 }
 
-Q_GLOBAL_STATIC_WITH_ARGS(QPixmap, globalGenericImage, (SmallIcon("image-x-generic")))
-Q_GLOBAL_STATIC_WITH_ARGS(QPixmap, globalPlayingImage, (UserIcon("playing")))
-
-const QPixmap *PlaylistItem::pixmap(int column) const
-{
-    int offset = playlist()->columnOffset();
-
-    // Don't use hasCover here because that may dig into the track itself.
-    // Besides, we really just want to know if the cover manager has a cover
-    // for the track.
-
-    if((column - offset) == CoverColumn &&
-        d->fileHandle.coverInfo()->coverId() != CoverManager::NoMatch)
-    {
-        return globalGenericImage;
-    }
-
-    if(column == playlist()->leftColumn() &&
-        m_playingItems.contains(const_cast<PlaylistItem *>(this)))
-    {
-        return globalPlayingImage;
-    }
-
-    //return QTreeWidgetItem::pixmap(column);
-    return nullptr;
-}
-
 QString PlaylistItem::text(int column) const
 {
     if(!d->fileHandle.tag())
diff --git a/playlistitem.h b/playlistitem.h
index 6076420..36f072c 100644
--- a/playlistitem.h
+++ b/playlistitem.h
@@ -96,7 +96,6 @@ public:
     void setFile(const QString &file);
     FileHandle file() const;
 
-    virtual const QPixmap *pixmap(int column) const;
     virtual QString text(int column) const;
     virtual void setText(int column, const QString &text);
 
diff --git a/statuslabel.cpp b/statuslabel.cpp
index c394d0e..725765b 100644
--- a/statuslabel.cpp
+++ b/statuslabel.cpp
@@ -24,6 +24,7 @@
 #include <QAction>
 #include <QMouseEvent>
 #include <QLabel>
+#include <QIcon>
 #include <QFrame>
 #include <QEvent>
 #include <QPushButton>
@@ -79,7 +80,7 @@ StatusLabel::StatusLabel(const PlaylistInterface &currentPlaylist, QStatusBar *p
     setItemCurrentTime(0);
 
     QPushButton *jumpButton = new QPushButton(this);
-    jumpButton->setIcon(SmallIcon("go-up"));
+    jumpButton->setIcon(QIcon::fromTheme("go-jump"));
     jumpButton->setFlat(true);
 
     jumpButton->setToolTip(i18n("Jump to the currently playing item"));
diff --git a/systemtray.cpp b/systemtray.cpp
index 2572b55..c97b865 100644
--- a/systemtray.cpp
+++ b/systemtray.cpp
@@ -156,8 +156,8 @@ SystemTray::SystemTray(PlayerManager *player, QWidget *parent) :
     setCategory(ApplicationStatus);
     setStatus(Active); // We were told to dock in systray by user, force us visible
 
-    m_forwardPix = SmallIcon("media-skip-forward");
-    m_backPix = SmallIcon("media-skip-backward");
+    m_forwardPix = QIcon::fromTheme("media-skip-forward");
+    m_backPix = QIcon::fromTheme("media-skip-backward");
 
     // Just create this here so that it show up in the DBus interface and the
     // key bindings dialog.
@@ -491,16 +491,16 @@ void SystemTray::setToolTip(const QString &tip, const QPixmap &cover)
     if(tip.isEmpty())
         KStatusNotifierItem::setToolTip("juk", i18n("JuK"), QString());
     else {
-        QPixmap myCover;
+        QIcon myCover;
         if(cover.isNull()) {
-            myCover = DesktopIcon("juk");
+            myCover = QIcon::fromTheme("juk");
         } else {
             //Scale to proper icon size, otherwise KStatusNotifierItem will show an unknown icon
-            int iconSize = KIconLoader::global()->currentSize(KIconLoader::Desktop);
-            myCover = cover.scaled(iconSize, iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+            const int iconSize = KIconLoader::global()->currentSize(KIconLoader::Desktop);
+            myCover = QIcon(cover.scaled(iconSize, iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
         }
 
-        KStatusNotifierItem::setToolTip(QIcon(myCover), i18n("JuK"), tip);
+        KStatusNotifierItem::setToolTip(myCover, i18n("JuK"), tip);
     }
 }
 
diff --git a/systemtray.h b/systemtray.h
index 3066aa4..f18a189 100644
--- a/systemtray.h
+++ b/systemtray.h
@@ -129,8 +129,8 @@ private slots:
     void scrollEvent(int delta, Qt::Orientation orientation);
 
 private:
-    QPixmap m_backPix;
-    QPixmap m_forwardPix;
+    QIcon m_backPix;
+    QIcon m_forwardPix;
     QColor m_startColor, m_endColor;
 
     PassiveInfo *m_popup;
diff --git a/viewmode.cpp b/viewmode.cpp
index e48c65b..9dbf8fe 100644
--- a/viewmode.cpp
+++ b/viewmode.cpp
@@ -163,16 +163,16 @@ void ViewMode::setShown(bool shown)
 {
     m_visible = shown;
     if(shown) {
-        updateIcons(32);
+        updateIcons();
         m_needsRefresh = true;
     }
 }
 
-void ViewMode::updateIcons(int size)
+void ViewMode::updateIcons()
 {
     for(QTreeWidgetItemIterator it(m_playlistBox); *it; ++it) {
         PlaylistBox::Item *i = static_cast<PlaylistBox::Item *>(*it);
-        i->setIcon(0, SmallIcon(i->iconName(), size));
+        i->setIcon(0, QIcon::fromTheme(i->iconName()));
     }
 }
 
@@ -293,7 +293,7 @@ void CompactViewMode::setShown(bool shown)
     setVisible(shown);
 
     if(shown) {
-        updateIcons(16);
+        updateIcons();
         updateHeights();
     }
 }
diff --git a/viewmode.h b/viewmode.h
index 622d1e0..f2d0e56 100644
--- a/viewmode.h
+++ b/viewmode.h
@@ -15,8 +15,8 @@
  * this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef VIEWMODE_H
-#define VIEWMODE_H
+#ifndef JUK_VIEWMODE_H
+#define JUK_VIEWMODE_H
 
 #include <QObject>
 #include <QStringList>
@@ -81,7 +81,7 @@ protected:
     PlaylistBox *playlistBox() const { return m_playlistBox; }
     bool visible() const { return m_visible; }
     void setVisible(bool v) { m_visible = v; }
-    void updateIcons(int size);
+    void updateIcons();
     virtual void updateHeights();
     static void paintDropIndicator(QPainter *painter, int width, int height);
 
diff --git a/webimagefetcher.cpp b/webimagefetcher.cpp
index a52ca02..ff28775 100644
--- a/webimagefetcher.cpp
+++ b/webimagefetcher.cpp
@@ -156,7 +156,8 @@ void WebImageFetcher::slotWebRequestFinished(KJob *job)
     //FIXME: We assume they have a sane sorting (smallest -> largest)
     const QString imageUrl = n.lastChildElement("image").text();
     if (imageUrl.isEmpty()) {
-        KMessageBox::information(nullptr, i18n("No available cover for the album '%1'.", d->albumName), i18nc("@title:window", "Cover not Available"));
+        KMessageBox::information(nullptr, i18n("No available cover for the album '%1'.", d->albumName),
+                i18nc("@title:window", "Cover not Available"));
         statusBar->clearMessage();
         return;
     }
@@ -187,9 +188,10 @@ void WebImageFetcher::slotImageFetched(KJob* j)
     auto dlgVLayout = new QVBoxLayout(d->dialog);
 
     if(job->error()) {
-        qCCritical(JUK_LOG) << "Unable to grab image\n";
-        d->dialog->setWindowIcon(DesktopIcon("dialog-error"));
-        // TODO: What kind of error announcement is this??
+        qCCritical(JUK_LOG) << "Unable to grab image" << job->errorText();
+
+        KMessageBox::sorry(nullptr, i18n("Failed to download requested cover art: %1", job->errorString()),
+                i18nc("@title:window", "Could not download cover art"));
         return;
     }
 


More information about the kde-doc-english mailing list