summaryrefslogtreecommitdiffstats
path: root/src/designer
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-02-09 13:59:22 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-04-15 17:40:47 +0200
commitfc6b8ee64d732cc322cad6f703f3b449d923e48c (patch)
tree93a4fc5b13156c42f80fdfda16fe141dec497ddd /src/designer
parentd0e2a4d3e12b2a75e085a0c8b498a31b4b312715 (diff)
Qt Designer: Add icon theme enums to the main icon property
Rename the old string-based editor to XDG an add a new editor for the enumerations. Task-number: QTBUG-121823 Pick-to: 6.7 Change-Id: Ib619c76d1406a1173b9eff902356f020b507057e Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Diffstat (limited to 'src/designer')
-rw-r--r--src/designer/src/components/propertyeditor/designerpropertymanager.cpp11
-rw-r--r--src/designer/src/components/propertyeditor/designerpropertymanager.h1
-rw-r--r--src/designer/src/components/propertyeditor/pixmapeditor.cpp63
-rw-r--r--src/designer/src/components/propertyeditor/pixmapeditor.h11
4 files changed, 76 insertions, 10 deletions
diff --git a/src/designer/src/components/propertyeditor/designerpropertymanager.cpp b/src/designer/src/components/propertyeditor/designerpropertymanager.cpp
index 8f5b98f6b..2f0403a04 100644
--- a/src/designer/src/components/propertyeditor/designerpropertymanager.cpp
+++ b/src/designer/src/components/propertyeditor/designerpropertymanager.cpp
@@ -2043,6 +2043,7 @@ void DesignerEditorFactory::slotValueChanged(QtProperty *property, const QVarian
if (type == DesignerPropertyManager::designerIconTypeId()) {
PropertySheetIconValue iconValue = qvariant_cast<PropertySheetIconValue>(value);
applyToEditors(m_iconPropertyToEditors.value(property), &PixmapEditor::setTheme, iconValue.theme());
+ applyToEditors(m_iconPropertyToEditors.value(property), &PixmapEditor::setThemeEnum, iconValue.themeEnum());
applyToEditors(m_iconPropertyToEditors.value(property), &PixmapEditor::setPath, iconValue.pixmap(QIcon::Normal, QIcon::Off).path());
} else if (type == DesignerPropertyManager::designerPixmapTypeId()) {
applyToEditors(m_pixmapPropertyToEditors.value(property), &PixmapEditor::setPath, qvariant_cast<PropertySheetPixmapValue>(value).path());
@@ -2176,6 +2177,7 @@ QWidget *DesignerEditorFactory::createEditor(QtVariantPropertyManager *manager,
ed->setIconThemeModeEnabled(true);
PropertySheetIconValue value = qvariant_cast<PropertySheetIconValue>(manager->value(property));
ed->setTheme(value.theme());
+ ed->setThemeEnum(value.themeEnum());
ed->setPath(value.pixmap(QIcon::Normal, QIcon::Off).path());
QIcon defaultPixmap;
if (!property->isModified())
@@ -2189,6 +2191,7 @@ QWidget *DesignerEditorFactory::createEditor(QtVariantPropertyManager *manager,
connect(ed, &QObject::destroyed, this, &DesignerEditorFactory::slotEditorDestroyed);
connect(ed, &PixmapEditor::pathChanged, this, &DesignerEditorFactory::slotIconChanged);
connect(ed, &PixmapEditor::themeChanged, this, &DesignerEditorFactory::slotIconThemeChanged);
+ connect(ed, &PixmapEditor::themeEnumChanged, this, &DesignerEditorFactory::slotIconThemeEnumChanged);
editor = ed;
} else if (type == DesignerPropertyManager::designerStringTypeId()) {
const TextPropertyValidationMode tvm = static_cast<TextPropertyValidationMode>(manager->attributeValue(property, validationModesAttributeC).toInt());
@@ -2400,6 +2403,14 @@ void DesignerEditorFactory::slotIconThemeChanged(const QString &value)
QVariant::fromValue(icon));
}
+void DesignerEditorFactory::slotIconThemeEnumChanged(int value)
+{
+ PropertySheetIconValue icon;
+ icon.setThemeEnum(value);
+ updateManager(this, &m_changingPropertyValue, m_editorToIconProperty,
+ qobject_cast<QWidget *>(sender()), QVariant::fromValue(icon));
+}
+
void DesignerEditorFactory::slotStringListChanged(const QStringList &value)
{
if (QtProperty *prop = findPropertyForEditor(m_editorToStringListProperty, sender())) {
diff --git a/src/designer/src/components/propertyeditor/designerpropertymanager.h b/src/designer/src/components/propertyeditor/designerpropertymanager.h
index e181fccce..6bd270edb 100644
--- a/src/designer/src/components/propertyeditor/designerpropertymanager.h
+++ b/src/designer/src/components/propertyeditor/designerpropertymanager.h
@@ -249,6 +249,7 @@ private slots:
void slotPixmapChanged(const QString &value);
void slotIconChanged(const QString &value);
void slotIconThemeChanged(const QString &value);
+ void slotIconThemeEnumChanged(int value);
void slotUintChanged(const QString &value);
void slotLongLongChanged(const QString &value);
void slotULongLongChanged(const QString &value);
diff --git a/src/designer/src/components/propertyeditor/pixmapeditor.cpp b/src/designer/src/components/propertyeditor/pixmapeditor.cpp
index 0a8e2d905..312fd135c 100644
--- a/src/designer/src/components/propertyeditor/pixmapeditor.cpp
+++ b/src/designer/src/components/propertyeditor/pixmapeditor.cpp
@@ -90,7 +90,8 @@ PixmapEditor::PixmapEditor(QDesignerFormEditorInterface *core, QWidget *parent)
m_button(new QToolButton(this)),
m_resourceAction(new QAction(tr("Choose Resource..."), this)),
m_fileAction(new QAction(tr("Choose File..."), this)),
- m_themeAction(new QAction(tr("Set Icon From Theme..."), this)),
+ m_themeEnumAction(new QAction(tr("Set Icon From Theme..."), this)),
+ m_themeAction(new QAction(tr("Set Icon From XDG Theme..."), this)),
m_copyAction(new QAction(createIconSet(QIcon::ThemeIcon::EditCopy, "editcopy.png"_L1),
tr("Copy Path"), this)),
m_pasteAction(new QAction(createIconSet(QIcon::ThemeIcon::EditPaste, "editpaste.png"_L1),
@@ -111,10 +112,12 @@ PixmapEditor::PixmapEditor(QDesignerFormEditorInterface *core, QWidget *parent)
m_pixmapLabel->setAlignment(Qt::AlignCenter);
m_pathLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed));
m_themeAction->setVisible(false);
+ m_themeEnumAction->setVisible(false);
QMenu *menu = new QMenu(this);
menu->addAction(m_resourceAction);
menu->addAction(m_fileAction);
+ menu->addAction(m_themeEnumAction);
menu->addAction(m_themeAction);
m_button->setMenu(menu);
@@ -123,6 +126,7 @@ PixmapEditor::PixmapEditor(QDesignerFormEditorInterface *core, QWidget *parent)
connect(m_button, &QAbstractButton::clicked, this, &PixmapEditor::defaultActionActivated);
connect(m_resourceAction, &QAction::triggered, this, &PixmapEditor::resourceActionActivated);
connect(m_fileAction, &QAction::triggered, this, &PixmapEditor::fileActionActivated);
+ connect(m_themeEnumAction, &QAction::triggered, this, &PixmapEditor::themeEnumActionActivated);
connect(m_themeAction, &QAction::triggered, this, &PixmapEditor::themeActionActivated);
#if QT_CONFIG(clipboard)
connect(m_copyAction, &QAction::triggered, this, &PixmapEditor::copyActionActivated);
@@ -149,6 +153,7 @@ void PixmapEditor::setIconThemeModeEnabled(bool enabled)
return;
m_iconThemeModeEnabled = enabled;
m_themeAction->setVisible(enabled);
+ m_themeEnumAction->setVisible(enabled);
}
void PixmapEditor::setSpacing(int spacing)
@@ -178,15 +183,26 @@ QString PixmapEditor::msgMissingThemeIcon(const QString &t)
return tr("[Theme] %1 (missing)").arg(t);
}
+void PixmapEditor::setThemeEnum(int e)
+{
+ m_themeEnum = e;
+ updateLabels();
+}
+
void PixmapEditor::updateLabels()
{
- m_pathLabel->setText(displayText(m_theme, m_path));
+ m_pathLabel->setText(displayText(m_themeEnum, m_theme, m_path));
switch (state()) {
case State::Empty:
case State::MissingXdgTheme:
+ case State::MissingThemeEnum:
m_pixmapLabel->setPixmap(m_defaultPixmap);
m_copyAction->setEnabled(false);
break;
+ case State::ThemeEnum:
+ m_pixmapLabel->setPixmap(QIcon::fromTheme(static_cast<QIcon::ThemeIcon>(m_themeEnum)).pixmap(ICON_SIZE));
+ m_copyAction->setEnabled(true);
+ break;
case State::XdgTheme:
m_pixmapLabel->setPixmap(QIcon::fromTheme(m_theme).pixmap(ICON_SIZE));
m_copyAction->setEnabled(true);
@@ -226,7 +242,7 @@ void PixmapEditor::contextMenuEvent(QContextMenuEvent *event)
void PixmapEditor::defaultActionActivated()
{
if (m_iconThemeModeEnabled) {
- themeActionActivated();
+ themeEnumActionActivated();
return;
}
// Default to resource
@@ -251,6 +267,7 @@ void PixmapEditor::resourceActionActivated()
oldPath, this);
if (!newPath.isEmpty() && newPath != oldPath) {
setTheme({});
+ setThemeEnum(-1);
setPath(newPath);
emit pathChanged(newPath);
}
@@ -261,11 +278,26 @@ void PixmapEditor::fileActionActivated()
const QString newPath = IconSelector::choosePixmapFile(m_path, m_core->dialogGui(), this);
if (!newPath.isEmpty() && newPath != m_path) {
setTheme({});
+ setThemeEnum(-1);
setPath(newPath);
emit pathChanged(newPath);
}
}
+void PixmapEditor::themeEnumActionActivated()
+{
+ const auto newThemeO = IconThemeEnumDialog::getTheme(this, {});
+ if (newThemeO.has_value()) {
+ const int newTheme = newThemeO.value();
+ if (newTheme != m_themeEnum) {
+ setThemeEnum(newTheme);
+ setTheme({});
+ setPath({});
+ emit themeEnumChanged(newTheme);
+ }
+ }
+}
+
void PixmapEditor::themeActionActivated()
{
const auto newThemeO = IconThemeDialog::getTheme(this, m_theme);
@@ -273,14 +305,21 @@ void PixmapEditor::themeActionActivated()
const QString newTheme = newThemeO.value();
if (newTheme != m_theme) {
setTheme(newTheme);
+ setThemeEnum(-1);
setPath({});
emit themeChanged(newTheme);
}
}
}
-PixmapEditor::State PixmapEditor::stateFromData(const QString &xdgTheme, const QString &path)
+PixmapEditor::State PixmapEditor::stateFromData(int themeEnum, const QString &xdgTheme,
+ const QString &path)
{
+ if (themeEnum != -1) {
+ if (QIcon::hasThemeIcon(static_cast<QIcon::ThemeIcon>(themeEnum)))
+ return State::ThemeEnum;
+ return path.isEmpty() ? State::MissingThemeEnum : State::PathFallback;
+ }
if (!xdgTheme.isEmpty()) {
if (QIcon::hasThemeIcon(xdgTheme))
return State::XdgTheme;
@@ -291,12 +330,16 @@ PixmapEditor::State PixmapEditor::stateFromData(const QString &xdgTheme, const Q
PixmapEditor::State PixmapEditor::state() const
{
- return stateFromData(m_theme, m_path);
+ return stateFromData(m_themeEnum, m_theme, m_path);
}
-QString PixmapEditor::displayText(const QString &xdgTheme, const QString &path)
+QString PixmapEditor::displayText(int themeEnum, const QString &xdgTheme, const QString &path)
{
- switch (stateFromData(xdgTheme, path)) {
+ switch (stateFromData(themeEnum, xdgTheme, path)) {
+ case State::ThemeEnum:
+ return msgThemeIcon(IconThemeEnumEditor::iconName(themeEnum));
+ case State::MissingThemeEnum:
+ return msgMissingThemeIcon(IconThemeEnumEditor::iconName(themeEnum));
case State::XdgTheme:
return msgThemeIcon(xdgTheme);
case State::MissingXdgTheme:
@@ -316,7 +359,7 @@ QString PixmapEditor::displayText(const PropertySheetIconValue &icon)
const auto &paths = icon.paths();
const auto &it = paths.constFind({QIcon::Normal, QIcon::Off});
const QString path = it != paths.constEnd() ? it.value().path() : QString{};
- return displayText(icon.theme(), path);
+ return displayText(icon.themeEnum(), icon.theme(), path);
}
#if QT_CONFIG(clipboard)
@@ -324,6 +367,10 @@ void PixmapEditor::copyActionActivated()
{
QClipboard *clipboard = QApplication::clipboard();
switch (state()) {
+ case State::ThemeEnum:
+ case State::MissingThemeEnum:
+ clipboard->setText(IconThemeEnumEditor::iconName(m_themeEnum));
+ break;
case State::XdgTheme:
case State::MissingXdgTheme:
clipboard->setText(m_theme);
diff --git a/src/designer/src/components/propertyeditor/pixmapeditor.h b/src/designer/src/components/propertyeditor/pixmapeditor.h
index 8ed334830..9ca730595 100644
--- a/src/designer/src/components/propertyeditor/pixmapeditor.h
+++ b/src/designer/src/components/propertyeditor/pixmapeditor.h
@@ -63,11 +63,13 @@ public:
public slots:
void setPath(const QString &path);
void setTheme(const QString &theme);
+ void setThemeEnum(int e);
void setDefaultPixmap(const QPixmap &pixmap);
void setDefaultPixmapIcon(const QIcon &icon);
signals:
void pathChanged(const QString &path);
+ void themeEnumChanged(int themeEnum);
void themeChanged(const QString &theme);
protected:
@@ -77,6 +79,7 @@ private slots:
void defaultActionActivated();
void resourceActionActivated();
void fileActionActivated();
+ void themeEnumActionActivated();
void themeActionActivated();
#if QT_CONFIG(clipboard)
void copyActionActivated();
@@ -86,15 +89,17 @@ private slots:
private:
enum class State {
Empty,
+ ThemeEnum,
+ MissingThemeEnum,
XdgTheme,
MissingXdgTheme,
Path,
PathFallback // Non-existent theme icon, falling back to path
};
- static State stateFromData(const QString &xdgTheme, const QString &path);
+ static State stateFromData(int themeEnum, const QString &xdgTheme, const QString &path);
State state() const;
- static QString displayText(const QString &xdgTheme, const QString &path);
+ static QString displayText(int themeEnum, const QString &xdgTheme, const QString &path);
void updateLabels();
bool m_iconThemeModeEnabled;
@@ -104,6 +109,7 @@ private:
QToolButton *m_button;
QAction *m_resourceAction;
QAction *m_fileAction;
+ QAction *m_themeEnumAction;
QAction *m_themeAction;
QAction *m_copyAction;
QAction *m_pasteAction;
@@ -111,6 +117,7 @@ private:
QPixmap m_defaultPixmap;
QString m_path;
QString m_theme;
+ int m_themeEnum = -1;
DesignerPixmapCache *m_pixmapCache;
};