summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-02-16 10:32:36 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-04-15 17:40:51 +0200
commit27075dd89d092ffa91312402c5c701888720ed12 (patch)
tree45ca9e82499d187d55fd23cc1f19e7197486c505
parentfc6b8ee64d732cc322cad6f703f3b449d923e48c (diff)
Qt Designer: Add icon theme enum sub property editor
Task-number: QTBUG-121823 Pick-to: 6.7 Change-Id: Ic5f13e05ea7f836bb99acdef106c973b0a70a170 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r--src/designer/src/components/propertyeditor/designerpropertymanager.cpp111
-rw-r--r--src/designer/src/components/propertyeditor/designerpropertymanager.h7
2 files changed, 116 insertions, 2 deletions
diff --git a/src/designer/src/components/propertyeditor/designerpropertymanager.cpp b/src/designer/src/components/propertyeditor/designerpropertymanager.cpp
index 2f0403a04..868087e2f 100644
--- a/src/designer/src/components/propertyeditor/designerpropertymanager.cpp
+++ b/src/designer/src/components/propertyeditor/designerpropertymanager.cpp
@@ -25,6 +25,7 @@
#include <abstractdialoggui_p.h>
#include <QtWidgets/qapplication.h>
+#include <QtWidgets/qcombobox.h>
#include <QtWidgets/qlabel.h>
#include <QtWidgets/qtoolbutton.h>
#include <QtWidgets/qboxlayout.h>
@@ -53,6 +54,7 @@ static constexpr auto superPaletteAttributeC = "superPalette"_L1;
static constexpr auto defaultResourceAttributeC = "defaultResource"_L1;
static constexpr auto fontAttributeC = "font"_L1;
static constexpr auto themeAttributeC = "theme"_L1;
+static constexpr auto themeEnumAttributeC = "themeEnum"_L1;
class DesignerFlagPropertyType
{
@@ -774,6 +776,8 @@ void DesignerPropertyManager::slotValueChanged(QtProperty *property, const QVari
if (itState != m_iconSubPropertyToState.constEnd()) {
const auto pair = m_iconSubPropertyToState.value(property);
icon.setPixmap(pair.first, pair.second, qvariant_cast<PropertySheetPixmapValue>(value));
+ } else if (attributeValue(property, themeEnumAttributeC).toBool()) {
+ icon.setThemeEnum(value.toInt());
} else { // must be theme property
icon.setTheme(value.toString());
}
@@ -808,6 +812,8 @@ void DesignerPropertyManager::slotPropertyDestroyed(QtProperty *property)
} else if (QtProperty *iconProperty = m_iconSubPropertyToProperty.value(property, 0)) {
if (m_propertyToTheme.value(iconProperty) == property) {
m_propertyToTheme.remove(iconProperty);
+ } else if (m_propertyToThemeEnum.value(iconProperty) == property) {
+ m_propertyToThemeEnum.remove(iconProperty);
} else {
const auto it = m_propertyToIconSubProperties.find(iconProperty);
const auto state = m_iconSubPropertyToState.value(property);
@@ -841,6 +847,8 @@ QStringList DesignerPropertyManager::attributes(int propertyType) const
list.append(themeAttributeC);
} else if (propertyType == QMetaType::QPalette) {
list.append(superPaletteAttributeC);
+ } else if (propertyType == QMetaType::Int) {
+ list.append(themeEnumAttributeC);
}
list.append(resettableAttributeC);
return list;
@@ -907,6 +915,12 @@ QVariant DesignerPropertyManager::attributeValue(const QtProperty *property, con
return it.value();
}
+ if (attribute == themeEnumAttributeC) {
+ const auto it = m_intThemeEnumAttributes.constFind(property);
+ if (it != m_intThemeEnumAttributes.constEnd())
+ return it.value();
+ }
+
if (attribute == superPaletteAttributeC) {
const auto it = m_paletteValues.constFind(property);
if (it != m_paletteValues.cend())
@@ -1034,6 +1048,21 @@ void DesignerPropertyManager::setAttribute(QtProperty *property,
it.value() = newValue;
emit attributeChanged(property, attribute, newValue);
+ } else if (attribute == themeEnumAttributeC && m_intThemeEnumAttributes.contains(property)) {
+ if (value.userType() != QMetaType::Bool)
+ return;
+
+ const auto it = m_intThemeEnumAttributes.find(property);
+ const bool oldValue = it.value();
+
+ const bool newValue = value.toBool();
+
+ if (oldValue == newValue)
+ return;
+
+ it.value() = newValue;
+
+ emit attributeChanged(property, attribute, newValue);
} else if (attribute == superPaletteAttributeC && m_paletteValues.contains(property)) {
if (value.userType() != QMetaType::QPalette)
return;
@@ -1233,6 +1262,12 @@ QString DesignerPropertyManager::valueText(const QtProperty *property) const
return QString();
return QFileInfo(path).fileName();
}
+ if (m_intValues.contains(property)) {
+ const auto value = m_intValues.value(property);
+ if (m_intThemeEnumAttributes.value(property))
+ return IconThemeEnumEditor::iconName(value);
+ return QString::number(value);
+ }
if (m_uintValues.contains(property))
return QString::number(m_uintValues.value(property));
if (m_longLongValues.contains(property))
@@ -1351,6 +1386,8 @@ QVariant DesignerPropertyManager::value(const QtProperty *property) const
|| m_stringListManager.value(property, &rc)
|| m_brushManager.value(property, &rc))
return rc;
+ if (m_intValues.contains(property))
+ return m_intValues.value(property);
if (m_uintValues.contains(property))
return m_uintValues.value(property);
if (m_longLongValues.contains(property))
@@ -1553,6 +1590,12 @@ void DesignerPropertyManager::setValue(QtProperty *property, const QVariant &val
themeSubProperty->setModified(!theme.isEmpty());
themeSubProperty->setValue(theme);
}
+ QtVariantProperty *themeEnumSubProperty = variantProperty(m_propertyToThemeEnum.value(property));
+ if (themeEnumSubProperty) {
+ const int themeEnum = icon.themeEnum();
+ themeEnumSubProperty->setModified(themeEnum != -1);
+ themeEnumSubProperty->setValue(QVariant(themeEnum));
+ }
emit QtVariantPropertyManager::valueChanged(property, QVariant::fromValue(icon));
emit propertyChanged(property);
@@ -1586,6 +1629,23 @@ void DesignerPropertyManager::setValue(QtProperty *property, const QVariant &val
return;
}
+ if (m_intValues.contains(property)) {
+ if (value.metaType().id() != QMetaType::Int && !value.canConvert<int>())
+ return;
+
+ const int v = value.toInt(nullptr);
+
+ const int oldValue = m_intValues.value(property);
+ if (v == oldValue)
+ return;
+
+ m_intValues[property] = v;
+
+ emit QtVariantPropertyManager::valueChanged(property, v);
+ emit propertyChanged(property);
+
+ return;
+ }
if (m_uintValues.contains(property)) {
if (value.metaType().id() != QMetaType::UInt && !value.canConvert<uint>())
return;
@@ -1692,6 +1752,10 @@ void DesignerPropertyManager::initializeProperty(QtProperty *property)
m_stringFontAttributes[property] = QApplication::font();
m_stringThemeAttributes[property] = false;
break;
+ case QMetaType::Int:
+ m_intValues[property] = 0;
+ m_intThemeEnumAttributes[property] = false;
+ break;
case QMetaType::UInt:
m_uintValues[property] = 0;
break;
@@ -1742,7 +1806,15 @@ void DesignerPropertyManager::initializeProperty(QtProperty *property)
m_iconValues[property] = PropertySheetIconValue();
m_defaultIcons[property] = QIcon();
- QtVariantProperty *themeProp = addProperty(QMetaType::QString, tr("Theme"));
+ QtVariantProperty *themeEnumProp = addProperty(QMetaType::Int, tr("Theme"));
+ m_intValues[themeEnumProp] = -1;
+ themeEnumProp->setAttribute(themeEnumAttributeC, true);
+ m_iconSubPropertyToProperty[themeEnumProp] = property;
+ m_propertyToThemeEnum[property] = themeEnumProp;
+ m_resetMap[themeEnumProp] = true;
+ property->addSubProperty(themeEnumProp);
+
+ QtVariantProperty *themeProp = addProperty(QMetaType::QString, tr("XDG Theme"));
themeProp->setAttribute(themeAttributeC, true);
m_iconSubPropertyToProperty[themeProp] = property;
m_propertyToTheme[property] = themeProp;
@@ -1820,6 +1892,11 @@ void DesignerPropertyManager::uninitializeProperty(QtProperty *property)
m_iconSubPropertyToProperty.remove(iconTheme);
}
+ if (QtProperty *iconThemeEnum = m_propertyToThemeEnum.value(property)) {
+ m_iconSubPropertyToProperty.remove(iconThemeEnum);
+ delete iconThemeEnum;
+ }
+
m_propertyToAlignH.remove(property);
m_propertyToAlignV.remove(property);
@@ -1845,6 +1922,7 @@ void DesignerPropertyManager::uninitializeProperty(QtProperty *property)
m_iconSubPropertyToState.remove(property);
m_iconSubPropertyToProperty.remove(property);
+ m_intValues.remove(property);
m_uintValues.remove(property);
m_longLongValues.remove(property);
m_uLongLongValues.remove(property);
@@ -1884,11 +1962,17 @@ bool DesignerPropertyManager::resetIconSubProperty(QtProperty *property)
pixmapProperty->setValue(QVariant::fromValue(PropertySheetPixmapValue()));
return true;
}
- if (m_propertyToTheme.contains(iconProperty)) {
+ if (attributeValue(property, themeAttributeC).toBool()) {
QtVariantProperty *themeProperty = variantProperty(property);
themeProperty->setValue(QString());
return true;
}
+ if (attributeValue(property, themeEnumAttributeC).toBool()) {
+ QtVariantProperty *themeEnumProperty = variantProperty(property);
+ themeEnumProperty->setValue(-1);
+ return true;
+ }
+
return false;
}
@@ -2021,6 +2105,9 @@ void DesignerEditorFactory::slotValueChanged(QtProperty *property, const QVarian
case QMetaType::QPalette:
applyToEditors(m_palettePropertyToEditors.value(property), &PaletteEditorButton::setPalette, qvariant_cast<QPalette>(value));
break;
+ case QMetaType::Int:
+ applyToEditors(m_intPropertyToComboEditors.value(property), &QComboBox::setCurrentIndex, value.toInt());
+ break;
case QMetaType::UInt:
applyToEditors(m_uintPropertyToEditors.value(property), &QLineEdit::setText, QString::number(value.toUInt()));
break;
@@ -2107,6 +2194,18 @@ QWidget *DesignerEditorFactory::createEditor(QtVariantPropertyManager *manager,
editor = ed;
}
break;
+ case QMetaType::Int:
+ if (manager->attributeValue(property, themeEnumAttributeC).toBool()) {
+ auto *ed = IconThemeEnumEditor::createComboBox(parent);
+ ed->setCurrentIndex(manager->value(property).toInt());
+ connect(ed, &QComboBox::currentIndexChanged, this,
+ &DesignerEditorFactory::slotIntChanged);
+ connect(ed, &QObject::destroyed, this, &DesignerEditorFactory::slotEditorDestroyed);
+ m_intPropertyToComboEditors[property].append(ed);
+ m_comboEditorToIntProperty.insert(ed, property);
+ editor = ed;
+ }
+ break;
case QMetaType::UInt: {
QLineEdit *ed = new QLineEdit(parent);
ed->setValidator(new QULongLongValidator(0, UINT_MAX, ed));
@@ -2273,6 +2372,8 @@ void DesignerEditorFactory::slotEditorDestroyed(QObject *object)
return;
if (removeEditor(object, &m_longLongPropertyToEditors, &m_editorToLongLongProperty))
return;
+ if (removeEditor(object, &m_intPropertyToComboEditors, &m_comboEditorToIntProperty))
+ return;
if (removeEditor(object, &m_uLongLongPropertyToEditors, &m_editorToULongLongProperty))
return;
if (removeEditor(object, &m_urlPropertyToEditors, &m_editorToUrlProperty))
@@ -2312,6 +2413,12 @@ void DesignerEditorFactory::slotLongLongChanged(const QString &value)
updateManager(this, &m_changingPropertyValue, m_editorToLongLongProperty, qobject_cast<QWidget *>(sender()), value.toLongLong());
}
+void DesignerEditorFactory::slotIntChanged(int v)
+{
+ updateManager(this, &m_changingPropertyValue, m_comboEditorToIntProperty,
+ qobject_cast<QWidget *>(sender()), v);
+}
+
void DesignerEditorFactory::slotULongLongChanged(const QString &value)
{
updateManager(this, &m_changingPropertyValue, m_editorToULongLongProperty, qobject_cast<QWidget *>(sender()), value.toULongLong());
diff --git a/src/designer/src/components/propertyeditor/designerpropertymanager.h b/src/designer/src/components/propertyeditor/designerpropertymanager.h
index 6bd270edb..be5c224bb 100644
--- a/src/designer/src/components/propertyeditor/designerpropertymanager.h
+++ b/src/designer/src/components/propertyeditor/designerpropertymanager.h
@@ -21,6 +21,7 @@ QT_BEGIN_NAMESPACE
using DesignerIntPair = std::pair<QString, uint>;
using DesignerFlagList = QList<DesignerIntPair>;
+class QComboBox;
class QDesignerFormEditorInterface;
class QLineEdit;
class QUrl;
@@ -183,6 +184,7 @@ private:
QHash<const QtProperty *, std::pair<QIcon::Mode, QIcon::State>> m_iconSubPropertyToState;
PropertyToPropertyMap m_iconSubPropertyToProperty;
PropertyToPropertyMap m_propertyToTheme;
+ PropertyToPropertyMap m_propertyToThemeEnum;
TranslatablePropertyManager<PropertySheetStringValue> m_stringManager;
TranslatablePropertyManager<PropertySheetKeySequenceValue> m_keySequenceManager;
@@ -198,6 +200,7 @@ private:
QHash<const QtProperty *, qdesigner_internal::PropertySheetPixmapValue> m_pixmapValues;
QHash<const QtProperty *, qdesigner_internal::PropertySheetIconValue> m_iconValues;
+ QHash<const QtProperty *, int> m_intValues;
QHash<const QtProperty *, uint> m_uintValues;
QHash<const QtProperty *, qlonglong> m_longLongValues;
QHash<const QtProperty *, qulonglong> m_uLongLongValues;
@@ -207,6 +210,7 @@ private:
QHash<const QtProperty *, int> m_stringAttributes;
QHash<const QtProperty *, QFont> m_stringFontAttributes;
QHash<const QtProperty *, bool> m_stringThemeAttributes;
+ QHash<const QtProperty *, bool> m_intThemeEnumAttributes;
BrushPropertyManager m_brushManager;
FontPropertyManager m_fontManager;
@@ -251,6 +255,7 @@ private slots:
void slotIconThemeChanged(const QString &value);
void slotIconThemeEnumChanged(int value);
void slotUintChanged(const QString &value);
+ void slotIntChanged(int);
void slotLongLongChanged(const QString &value);
void slotULongLongChanged(const QString &value);
void slotUrlChanged(const QString &value);
@@ -276,6 +281,8 @@ private:
QHash<PixmapEditor *, QtProperty *> m_editorToPixmapProperty;
QHash<const QtProperty *, QList<PixmapEditor *>> m_iconPropertyToEditors;
QHash<PixmapEditor *, QtProperty *> m_editorToIconProperty;
+ QHash<const QtProperty *, QList<QComboBox *>> m_intPropertyToComboEditors;
+ QHash<QComboBox *, QtProperty *> m_comboEditorToIntProperty;
QHash<const QtProperty *, QList<QLineEdit *>> m_uintPropertyToEditors;
QHash<QLineEdit *, QtProperty *> m_editorToUintProperty;
QHash<const QtProperty *, QList<QLineEdit *>> m_longLongPropertyToEditors;