diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set (QT_MIN_VERSION "5.7.0") -set (KF5_MIN_VERSION "5.48.0") +set (KF5_MIN_VERSION "5.41.0") set (PA_MIN_VERSION "0.9.16") find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) @@ -39,7 +39,6 @@ DocTools GlobalAccel I18n - IconThemes Notifications Solid WidgetsAddons @@ -262,7 +261,6 @@ KF5::I18n KF5::ConfigCore KF5::ConfigGui - KF5::IconThemes KF5::GlobalAccel KF5::Notifications KF5::XmlGui @@ -285,7 +283,6 @@ kmixcore kmixgui KF5::I18n - KF5::IconThemes KF5::DBusAddons KF5::GlobalAccel KF5::XmlGui diff --git a/apps/kmix.cpp b/apps/kmix.cpp --- a/apps/kmix.cpp +++ b/apps/kmix.cpp @@ -36,7 +36,6 @@ // include files for KDE #include -#include #include #include #include @@ -267,10 +266,8 @@ // runs with 4 fixed Tabs. if (!Mixer::pulseaudioPresent()) { - QPixmap cornerNewPM = KIconLoader::global()->loadScaledIcon("tab-new", KIconLoader::Toolbar, - devicePixelRatioF(), IconSize(KIconLoader::Toolbar)); QPushButton* _cornerLabelNew = new QPushButton(); - _cornerLabelNew->setIcon(cornerNewPM); + _cornerLabelNew->setIcon(QIcon::fromTheme("tab-new")); _cornerLabelNew->setToolTip(i18n("Add new view")); //cornerLabelNew->setSizePolicy(QSizePolicy()); m_wsMixers->setCornerWidget(_cornerLabelNew, Qt::TopLeftCorner); diff --git a/gui/dialogselectmaster.cpp b/gui/dialogselectmaster.cpp --- a/gui/dialogselectmaster.cpp +++ b/gui/dialogselectmaster.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include "core/ControlManager.h" @@ -174,8 +173,7 @@ if (msetCount > 0 && !mixer->isDynamic()) { QString mdName = i18n("Automatic (%1 recommendation)", mixer->getDriverName()); - QPixmap icon = KIconLoader::global()->loadScaledIcon("audio-volume-high", KIconLoader::Small, devicePixelRatioF(), IconSize(KIconLoader::Small)); - QListWidgetItem *item = new QListWidgetItem(icon, mdName, m_channelSelector); + auto *item = new QListWidgetItem(QIcon::fromTheme("audio-volume-high"), mdName, m_channelSelector); item->setData(Qt::UserRole, QString()); // ID here: see apply(), empty String => Automatic if (masterKey.isEmpty()) m_channelSelector->setCurrentItem(item); @@ -188,8 +186,7 @@ if ( md->playbackVolume().hasVolume() ) { QString mdName = md->readableName(); - QPixmap icon = KIconLoader::global()->loadScaledIcon(md->iconName(), KIconLoader::Small, devicePixelRatioF(), IconSize(KIconLoader::Small)); - QListWidgetItem *item = new QListWidgetItem(icon, mdName, m_channelSelector); + auto *item = new QListWidgetItem(QIcon::fromTheme(md->iconName()), mdName, m_channelSelector); item->setData(Qt::UserRole, md->id()); // ID here: see apply() if ( md->id() == masterKey ) { // select the current master diff --git a/gui/dialogviewconfiguration.h b/gui/dialogviewconfiguration.h --- a/gui/dialogviewconfiguration.h +++ b/gui/dialogviewconfiguration.h @@ -43,8 +43,8 @@ class DialogViewConfigurationItem : public QListWidgetItem { public: - DialogViewConfigurationItem(QListWidget *parent, qreal devicePixelRatio, QDataStream &s); - DialogViewConfigurationItem(QListWidget *parent, qreal devicePixelRatio, const QString &id, bool shown, const QString &name, int splitted, const QString &iconName); + DialogViewConfigurationItem(QListWidget *parent, QDataStream &s); + DialogViewConfigurationItem(QListWidget *parent, const QString &id, bool shown, const QString &name, int splitted, const QString &iconName); ~DialogViewConfigurationItem() = default; private: @@ -63,7 +63,6 @@ QString _name; int _splitted; QString _iconName; - qreal _devicePixelRatio; }; class DialogViewConfigurationWidget : public QListWidget diff --git a/gui/dialogviewconfiguration.cpp b/gui/dialogviewconfiguration.cpp --- a/gui/dialogviewconfiguration.cpp +++ b/gui/dialogviewconfiguration.cpp @@ -28,7 +28,6 @@ #include #include -#include #include #include "gui/guiprofile.h" @@ -40,18 +39,17 @@ /** * Standard constructor. */ -DialogViewConfigurationItem::DialogViewConfigurationItem(QListWidget *parent, qreal devicePixelRatio, const QString &id, bool shown, const QString &name, int splitted, const QString& iconName) : - QListWidgetItem(parent), _id(id), _shown(shown), _name(name), _splitted(splitted), _iconName(iconName), _devicePixelRatio(devicePixelRatio) +DialogViewConfigurationItem::DialogViewConfigurationItem(QListWidget *parent, const QString &id, bool shown, const QString &name, int splitted, const QString& iconName) : + QListWidgetItem(parent), _id(id), _shown(shown), _name(name), _splitted(splitted), _iconName(iconName) { refreshItem(); } /** * Deserializing constructor. Used for DnD. */ -DialogViewConfigurationItem::DialogViewConfigurationItem(QListWidget *parent, qreal devicePixelRatio, QDataStream &s) +DialogViewConfigurationItem::DialogViewConfigurationItem(QListWidget *parent, QDataStream &s) : QListWidgetItem(parent) - , _devicePixelRatio(devicePixelRatio) { s >> _id; s >> _shown; @@ -66,7 +64,7 @@ { setFlags((flags() | Qt::ItemIsDragEnabled) & ~Qt::ItemIsDropEnabled); setText(_name); - setIcon(KIconLoader::global()->loadScaledIcon( _iconName, KIconLoader::Small, _devicePixelRatio, IconSize(KIconLoader::Toolbar) )); + setIcon(QIcon::fromTheme(_iconName)); setData(Qt::ToolTipRole, _id); // a hack. I am giving up to do it right setData(Qt::DisplayRole, _name); } @@ -124,7 +122,7 @@ if (data.isEmpty()) return false; QDataStream stream(data); - DialogViewConfigurationItem* item = new DialogViewConfigurationItem(nullptr, devicePixelRatioF(), stream); + DialogViewConfigurationItem* item = new DialogViewConfigurationItem(nullptr, stream); emit dropped(this, index, item); return true; } @@ -267,7 +265,7 @@ } //qCDebug(KMIX_LOG) << "add DialogViewConfigurationItem: " << mdName << " visible=" << mdw->isVisible() << "splitted=" << splitted; - auto *item = new DialogViewConfigurationItem(nullptr, devicePixelRatioF(), md->id(), true, mdName, splitted, mdw->mixDevice()->iconName()); + auto *item = new DialogViewConfigurationItem(nullptr, md->id(), true, mdName, splitted, mdw->mixDevice()->iconName()); if (mdw->isVisible()) _qlwActive->addItem(item); else _qlwInactive->addItem(item); } // for all MDW's diff --git a/gui/kmixtoolbox.cpp b/gui/kmixtoolbox.cpp --- a/gui/kmixtoolbox.cpp +++ b/gui/kmixtoolbox.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include "gui/guiprofile.h" diff --git a/gui/mdwslider.h b/gui/mdwslider.h --- a/gui/mdwslider.h +++ b/gui/mdwslider.h @@ -25,8 +25,6 @@ #include -#include - #include "gui/volumeslider.h" #include "gui/mixdevicewidget.h" #include "core/volume.h" diff --git a/gui/mdwslider.cpp b/gui/mdwslider.cpp --- a/gui/mdwslider.cpp +++ b/gui/mdwslider.cpp @@ -22,7 +22,6 @@ #include "gui/mdwslider.h" #include -#include #include #include #include @@ -561,7 +560,6 @@ QToolButton* MDWSlider::addMediaButton(QString iconName, QLayout* layout, QWidget *parent) { QToolButton *lbl = new QToolButton(parent); - lbl->setIconSize(QSize(IconSize(KIconLoader::Toolbar), IconSize(KIconLoader::Toolbar))); lbl->setAutoRaise(true); lbl->setCheckable(false); @@ -1123,7 +1121,7 @@ if (view()==nullptr) return; QMenu *menu = view()->getPopup(); - menu->addSection( SmallIcon( "kmix" ), mixDevice()->readableName() ); + menu->addSection( QIcon::fromTheme( "kmix" ), mixDevice()->readableName() ); if (m_moveMenu) { MixSet *ms = mixDevice()->moveDestinationMixSet(); diff --git a/gui/mixdevicewidget.cpp b/gui/mixdevicewidget.cpp --- a/gui/mixdevicewidget.cpp +++ b/gui/mixdevicewidget.cpp @@ -22,7 +22,6 @@ #include "gui/mixdevicewidget.h" #include -#include #include #include #include diff --git a/gui/toggletoolbutton.h b/gui/toggletoolbutton.h --- a/gui/toggletoolbutton.h +++ b/gui/toggletoolbutton.h @@ -45,22 +45,22 @@ void setSmallSize(bool small = true) { mSmallSize = small; } bool isActive() const { return (mIsActive); } - void setActiveIcon(const QString &name) { mActiveIcon = name; } - void setInactiveIcon(const QString &name) { mInactiveIcon = name; } + void setActiveIcon(const QString &name) { mActiveIconName = name; } + void setInactiveIcon(const QString &name) { mInactiveIconName = name; } static void setIndicatorIcon(const QString &iconName, QWidget *label, bool small = false); private: bool mSmallSize; - QString mActiveIcon; - QString mInactiveIcon; + QString mActiveIconName; + QString mInactiveIconName; bool mIsActive; bool mFirstTime; - QPixmap mActivePixmap; + QIcon mActiveIcon; bool mActiveLoaded; - QPixmap mInactivePixmap; + QIcon mInactiveIcon; bool mInactiveLoaded; }; diff --git a/gui/toggletoolbutton.cpp b/gui/toggletoolbutton.cpp --- a/gui/toggletoolbutton.cpp +++ b/gui/toggletoolbutton.cpp @@ -23,23 +23,54 @@ #include #include - -#include -#include +#include +#include #include -static const KIconLoader::Group iconLoadGroup = KIconLoader::Small; -static const KIconLoader::Group iconSizeGroup = KIconLoader::Toolbar; static const int iconSmallSize = 10; +class DisabledIconEngine : public QIconEngine +{ + QIcon m_icon; +public: + DisabledIconEngine(const QIcon &icon) : QIconEngine(), m_icon(icon) {} + ~DisabledIconEngine() override {} + + QIconEngine *clone() const override + { + return new DisabledIconEngine(m_icon); + } + + void paint(QPainter *painter, const QRect &rect, QIcon::Mode, QIcon::State state) override + { + return m_icon.paint(painter, rect, Qt::AlignCenter, QIcon::Disabled, state); + } + + QPixmap pixmap(const QSize &size, QIcon::Mode, QIcon::State state) override + { + return m_icon.pixmap(size, QIcon::Disabled, state); + } + + QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state) override + { + return m_icon.actualSize(size, mode, state); + } + + QList availableSizes(QIcon::Mode mode, QIcon::State state) const override + { + return m_icon.availableSizes(mode, state); + } +}; + + ToggleToolButton::ToggleToolButton(const QString &activeIconName, QWidget *pnt) : QToolButton(pnt) { mActiveLoaded = mInactiveLoaded = false; - mActiveIcon = activeIconName; + mActiveIconName = activeIconName; mSmallSize = false; mIsActive = true; mFirstTime = true; @@ -49,107 +80,92 @@ } -// based on MDWSlider::setIcon() -QPixmap getPixmap(const QString &name, qreal devicePixelRatio, bool small) -{ - QPixmap pix = KIconLoader::global()->loadScaledIcon(name, iconLoadGroup, devicePixelRatio, IconSize(iconSizeGroup)); - if (!pix.isNull()) // load icon, check success - { // if wanting small size, scale pixmap - if (small) pix = pix.scaled(QSize(iconSmallSize, iconSmallSize) * devicePixelRatio); - } - else qCWarning(KMIX_LOG) << "failed to load" << name; - - // Return the allocated pixmap even if it failed to load, so that - // the caller can tell and only one load attempt will be made. - return (pix); -} - - void ToggleToolButton::setActive(bool active) { if (!mFirstTime && (active==mIsActive)) return; // no change required mIsActive = active; // record required state mFirstTime = false; // note now initialised - QPixmap *pix = nullptr; // new pixmap to set + QIcon icon; // new icon to set if (mIsActive) // look at new state { - if (mActivePixmap.isNull()) // need pixmap for active state + if (mActiveIcon.isNull()) // need icon for active state { // only if not already tried - if (!mActiveLoaded) mActivePixmap = getPixmap(mActiveIcon, devicePixelRatioF(), mSmallSize); + if (!mActiveLoaded) mActiveIcon = QIcon::fromTheme(mActiveIconName); mActiveLoaded = true; // note not to try again } - pix = &mActivePixmap; // the pixmap to use + icon = mActiveIcon; // the icon to use } else // want inactive state { - if (mInactivePixmap.isNull()) // need pixmap for inactive state + if (mInactiveIcon.isNull()) // need icon for inactive state { - if (!mInactiveIcon.isEmpty()) // inactive icon is set + if (!mInactiveIconName.isEmpty()) // inactive icon is set { - if (!mInactiveLoaded) mInactivePixmap = getPixmap(mInactiveIcon, devicePixelRatioF(), mSmallSize); + if (!mInactiveLoaded) mInactiveIcon = QIcon::fromTheme(mInactiveIconName); } else { // need to derive from active state - if (!mActiveLoaded) mActivePixmap = getPixmap(mActiveIcon, devicePixelRatioF(), mSmallSize); + if (!mActiveLoaded) mActiveIcon = QIcon::fromTheme(mActiveIconName); mActiveLoaded = true; // only if not already tried - if (mActivePixmap.isNull()) qCWarning(KMIX_LOG) << "want inactive but no active available"; + if (mActiveIcon.isNull()) qCWarning(KMIX_LOG) << "want inactive but no active available"; else { - mInactivePixmap = KIconLoader::global()->iconEffect()->apply(mActivePixmap, - KIconLoader::Toolbar, - KIconLoader::DisabledState); + mInactiveIcon = QIcon(new DisabledIconEngine(mActiveIcon)); } } mInactiveLoaded = true; // note not to try again } - pix = &mInactivePixmap; // the pixmap to use + icon = mInactiveIcon; // the icon to use } - if (pix->isNull()) return; // pixmap not available - setIcon(*pix); // set button pixmap + if (icon.isNull()) return; // icon not available + setIcon(icon); // set button icon } /** - * Loads the icon with the given @p iconName in the size KIconLoader::Small, + * Loads the icon with the given @p iconName * and applies it to the @p label widget. The widget must be either a * QLabel or a QToolButton. * * Originally @c MDWSlider::setIcon(), moved here because it uses the same * icon size parameters as a @c ToggleToolButton, and it can share @c getPixmap(). */ void ToggleToolButton::setIndicatorIcon(const QString &iconName, QWidget *label, bool small) { - QPixmap pix = getPixmap(iconName, label->devicePixelRatioF(), small); - if (pix.isNull()) + const auto icon = QIcon::fromTheme(iconName); + if (icon.isNull()) { - qCWarning(KMIX_LOG) << "Could not get pixmap for" << iconName; + qCWarning(KMIX_LOG) << "Could not get icon for" << iconName; return; } + QSize iconSize; if (small) // small size, set for scaled icon { - label->resize(iconSmallSize, iconSmallSize); + iconSize = QSize(iconSmallSize, iconSmallSize); } else // not small size, set for normal icon { - label->resize(IconSize(iconSizeGroup), IconSize(iconSizeGroup)); + const auto toolBarIconSize = label->style()->pixelMetric(QStyle::PM_TabBarIconSize, nullptr, label); + iconSize = QSize(toolBarIconSize, toolBarIconSize); } + label->resize(iconSize); label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); QLabel *lbl = qobject_cast(label); if (lbl!=nullptr) { - lbl->setPixmap(pix); + lbl->setPixmap(icon.pixmap(iconSize)); lbl->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); } else { QToolButton *tbt = qobject_cast(label); - if (tbt!=nullptr) tbt->setIcon(pix); // works because implicit QPixmap -> QIcon + if (tbt!=nullptr) tbt->setIcon(icon); } } diff --git a/gui/viewbase.cpp b/gui/viewbase.cpp --- a/gui/viewbase.cpp +++ b/gui/viewbase.cpp @@ -28,7 +28,6 @@ // KDE #include -#include #include #include #include