mirror of
https://git.FreeBSD.org/ports.git
synced 2024-12-26 05:02:18 +00:00
Fix QIcon button styling from qrc:/ with KDE Plasma style
Another QQC2 style fix; this is going to land eventually in KF5 5.76, but applies to 5.74 (current ports version) and 5.75 (upcoming). Reported upstream as and obtained from https://bugs.kde.org/show_bug.cgi?id=427449 https://invent.kde.org/frameworks/qqc2-desktop-style/-/merge_requests/35 The symptoms are toolbar icons in QML-based applications would not be rendered (at all), while switching styles to Qt-internal styles or disabling styling entirely would render the icons; this was spotted by swills@ while packaging Redis Desktop Manager. Reported by: swills Obtained from: KDE
This commit is contained in:
parent
af172d5404
commit
16ffd4b114
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=551754
@ -2,7 +2,7 @@
|
||||
|
||||
PORTNAME= qqc2-desktop-style
|
||||
DISTVERSION= ${KDE_FRAMEWORKS_VERSION}
|
||||
PORTREVISION= 1
|
||||
PORTREVISION= 2
|
||||
CATEGORIES= x11-themes kde kde-frameworks
|
||||
|
||||
MAINTAINER= kde@FreeBSD.org
|
||||
|
@ -0,0 +1,116 @@
|
||||
Add support for qrc icons to StyleItem
|
||||
|
||||
BUG: 427449
|
||||
|
||||
diff --git plugin/kquickstyleitem.cpp plugin/kquickstyleitem.cpp
|
||||
index b1cf5b1..f280661 100644
|
||||
--- plugin/kquickstyleitem.cpp
|
||||
+++ plugin/kquickstyleitem.cpp
|
||||
@@ -179,14 +179,8 @@ void KQuickStyleItem::initStyleOption()
|
||||
QStyleOptionButton *opt = qstyleoption_cast<QStyleOptionButton*>(m_styleoption);
|
||||
opt->text = text();
|
||||
|
||||
- const QVariant icon = m_properties[QStringLiteral("icon")];
|
||||
- if (icon.canConvert<QIcon>()) {
|
||||
- opt->icon = icon.value<QIcon>();
|
||||
- } else if (icon.canConvert<QUrl>() && icon.value<QUrl>().isLocalFile()) {
|
||||
- opt->icon = QIcon(icon.value<QUrl>().toLocalFile());
|
||||
- } else if (icon.canConvert<QString>()) {
|
||||
- opt->icon = m_theme->iconFromTheme(icon.value<QString>(), m_properties[QStringLiteral("iconColor")].value<QColor>());
|
||||
- }
|
||||
+ opt->icon = iconFromIconProperty();
|
||||
+
|
||||
auto iconSize = QSize(m_properties[QStringLiteral("iconWidth")].toInt(), m_properties[QStringLiteral("iconHeight")].toInt());
|
||||
if (iconSize.isEmpty()) {
|
||||
int e = KQuickStyleItem::style()->pixelMetric(QStyle::PM_ButtonIconSize, m_styleoption, nullptr);
|
||||
@@ -303,12 +297,9 @@ void KQuickStyleItem::initStyleOption()
|
||||
|
||||
opt->activeSubControls = QStyle::SC_ToolButton;
|
||||
opt->text = text();
|
||||
- const QVariant icon = m_properties[QStringLiteral("icon")];
|
||||
- if (icon.canConvert<QIcon>()) {
|
||||
- opt->icon = icon.value<QIcon>();
|
||||
- } else if (icon.canConvert<QString>()) {
|
||||
- opt->icon = m_theme->iconFromTheme(icon.value<QString>(), m_properties[QStringLiteral("iconColor")].value<QColor>());
|
||||
- }
|
||||
+
|
||||
+ opt->icon = iconFromIconProperty();
|
||||
+
|
||||
auto iconSize = QSize(m_properties[QStringLiteral("iconWidth")].toInt(), m_properties[QStringLiteral("iconHeight")].toInt());
|
||||
if (iconSize.isEmpty()) {
|
||||
int e = KQuickStyleItem::style()->pixelMetric(QStyle::PM_ToolBarIconSize, m_styleoption, nullptr);
|
||||
@@ -483,8 +474,7 @@ void KQuickStyleItem::initStyleOption()
|
||||
QStyleOptionMenuItem::NonExclusive;
|
||||
}
|
||||
}
|
||||
- if (m_properties[QStringLiteral("icon")].canConvert<QIcon>())
|
||||
- opt->icon = m_properties[QStringLiteral("icon")].value<QIcon>();
|
||||
+ opt->icon = iconFromIconProperty();
|
||||
setProperty("_q_showUnderlined", m_hints[QStringLiteral("showUnderlined")].toBool());
|
||||
|
||||
const QFont font = qApp->font(m_itemType == ComboBoxItem ?"QComboMenuItem" : "QMenu");
|
||||
@@ -507,14 +497,8 @@ void KQuickStyleItem::initStyleOption()
|
||||
opt->state |= QStyle::State_NoChange;
|
||||
opt->text = text();
|
||||
|
||||
- const QVariant icon = m_properties[QStringLiteral("icon")];
|
||||
- if (icon.canConvert<QIcon>()) {
|
||||
- opt->icon = icon.value<QIcon>();
|
||||
- } else if (icon.canConvert<QUrl>() && icon.value<QUrl>().isLocalFile()) {
|
||||
- opt->icon = QIcon(icon.value<QUrl>().toLocalFile());
|
||||
- } else if (icon.canConvert<QString>()) {
|
||||
- opt->icon = m_theme->iconFromTheme(icon.value<QString>(), m_properties[QStringLiteral("iconColor")].value<QColor>());
|
||||
- }
|
||||
+ opt->icon = iconFromIconProperty();
|
||||
+
|
||||
auto iconSize = QSize(m_properties[QStringLiteral("iconWidth")].toInt(), m_properties[QStringLiteral("iconHeight")].toInt());
|
||||
if (iconSize.isEmpty()) {
|
||||
int e = KQuickStyleItem::style()->pixelMetric(QStyle::PM_ButtonIconSize, m_styleoption, nullptr);
|
||||
@@ -742,6 +726,35 @@ void KQuickStyleItem::initStyleOption()
|
||||
|
||||
}
|
||||
|
||||
+QIcon KQuickStyleItem::iconFromIconProperty() const
|
||||
+{
|
||||
+ QIcon icon;
|
||||
+ const QVariant iconProperty = m_properties[QStringLiteral("icon")];
|
||||
+ switch(iconProperty.type()){
|
||||
+ case QVariant::Icon:
|
||||
+ icon = iconProperty.value<QIcon>();
|
||||
+ break;
|
||||
+ case QVariant::Url:
|
||||
+ case QVariant::String: {
|
||||
+ QString iconSource = iconProperty.toString();
|
||||
+ if (iconSource.startsWith(QLatin1String("qrc:/"))) {
|
||||
+ iconSource = iconSource.mid(3);
|
||||
+ } else if (iconSource.startsWith(QLatin1String("file:/"))) {
|
||||
+ iconSource = QUrl(iconSource).path();
|
||||
+ }
|
||||
+ if (iconSource.contains(QLatin1String("/"))) {
|
||||
+ icon = QIcon(iconSource);
|
||||
+ } else {
|
||||
+ icon = m_theme->iconFromTheme(iconSource, m_properties[QStringLiteral("iconColor")].value<QColor>());
|
||||
+ }
|
||||
+ }
|
||||
+ break;
|
||||
+ default:
|
||||
+ break;
|
||||
+ }
|
||||
+ return icon;
|
||||
+}
|
||||
+
|
||||
const char* KQuickStyleItem::classNameForItem() const
|
||||
{
|
||||
switch(m_itemType) {
|
||||
diff --git plugin/kquickstyleitem_p.h plugin/kquickstyleitem_p.h
|
||||
index 5dbfebf..80c0958 100644
|
||||
--- plugin/kquickstyleitem_p.h
|
||||
+++ plugin/kquickstyleitem_p.h
|
||||
@@ -256,6 +256,7 @@ protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
|
||||
private:
|
||||
+ QIcon iconFromIconProperty() const;
|
||||
const char* classNameForItem() const;
|
||||
QSize sizeFromContents(int width, int height);
|
||||
qreal baselineOffset();
|
Loading…
Reference in New Issue
Block a user