summaryrefslogtreecommitdiffstats
path: root/src/designer
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-02-06 14:36:30 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-02-09 21:30:54 +0100
commit592aa9c392dc5d7cfe0ba92296c6f2be3c3c85bd (patch)
tree87f99e9f8922b3ffbbd321fcfc81ff6b212d9c6e /src/designer
parentbc090b42919d6e6193bdf8e23f5287c661afc880 (diff)
Qt Designer: Refactor some parts of the PixmapEditor
- Use std::optional<> for IconThemeDialog::getTheme() - Trigger theme dialog as default independent of whether the current theme icon exists - Factor out message for value text Task-number: QTBUG-121823 Pick-to: 6.7 Change-Id: Ifd431ae894cb801075a46e54c8f355729bcd0a5a Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Diffstat (limited to 'src/designer')
-rw-r--r--src/designer/src/components/propertyeditor/designerpropertymanager.cpp2
-rw-r--r--src/designer/src/components/propertyeditor/pixmapeditor.cpp36
-rw-r--r--src/designer/src/components/propertyeditor/pixmapeditor.h7
3 files changed, 27 insertions, 18 deletions
diff --git a/src/designer/src/components/propertyeditor/designerpropertymanager.cpp b/src/designer/src/components/propertyeditor/designerpropertymanager.cpp
index 6b52db5fc..ed28d0d3b 100644
--- a/src/designer/src/components/propertyeditor/designerpropertymanager.cpp
+++ b/src/designer/src/components/propertyeditor/designerpropertymanager.cpp
@@ -1231,7 +1231,7 @@ QString DesignerPropertyManager::valueText(const QtProperty *property) const
const PropertySheetIconValue icon = m_iconValues.value(const_cast<QtProperty *>(property));
const QString theme = icon.theme();
if (!theme.isEmpty() && QIcon::hasThemeIcon(theme))
- return tr("[Theme] %1").arg(theme);
+ return PixmapEditor::msgThemeIcon(theme);
const auto &paths = icon.paths();
const auto it = paths.constFind({QIcon::Normal, QIcon::Off});
if (it == paths.constEnd())
diff --git a/src/designer/src/components/propertyeditor/pixmapeditor.cpp b/src/designer/src/components/propertyeditor/pixmapeditor.cpp
index 0da60b01e..296b16a9a 100644
--- a/src/designer/src/components/propertyeditor/pixmapeditor.cpp
+++ b/src/designer/src/components/propertyeditor/pixmapeditor.cpp
@@ -51,16 +51,13 @@ IconThemeDialog::IconThemeDialog(QWidget *parent)
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
}
-QString IconThemeDialog::getTheme(QWidget *parent, const QString &theme, bool *ok)
+std::optional<QString> IconThemeDialog::getTheme(QWidget *parent, const QString &theme)
{
IconThemeDialog dlg(parent);
dlg.m_editor->setTheme(theme);
- if (dlg.exec() == QDialog::Accepted) {
- *ok = true;
+ if (dlg.exec() == QDialog::Accepted)
return dlg.m_editor->theme();
- }
- *ok = false;
- return QString();
+ return std::nullopt;
}
PixmapEditor::PixmapEditor(QDesignerFormEditorInterface *core, QWidget *parent) :
@@ -148,11 +145,16 @@ void PixmapEditor::setTheme(const QString &theme)
updateLabels();
}
+QString PixmapEditor::msgThemeIcon(const QString &t)
+{
+ return tr("[Theme] %1").arg(t);
+}
+
void PixmapEditor::updateLabels()
{
if (m_iconThemeModeEnabled && QIcon::hasThemeIcon(m_theme)) {
m_pixmapLabel->setPixmap(QIcon::fromTheme(m_theme).pixmap(ICON_SIZE));
- m_pathLabel->setText(tr("[Theme] %1").arg(m_theme));
+ m_pathLabel->setText(msgThemeIcon(m_theme));
m_copyAction->setEnabled(true);
} else {
if (m_path.isEmpty()) {
@@ -194,7 +196,7 @@ void PixmapEditor::contextMenuEvent(QContextMenuEvent *event)
void PixmapEditor::defaultActionActivated()
{
- if (m_iconThemeModeEnabled && QIcon::hasThemeIcon(m_theme)) {
+ if (m_iconThemeModeEnabled) {
themeActionActivated();
return;
}
@@ -219,7 +221,7 @@ void PixmapEditor::resourceActionActivated()
const QString newPath = IconSelector::choosePixmapResource(m_core, m_core->resourceModel(),
oldPath, this);
if (!newPath.isEmpty() && newPath != oldPath) {
- setTheme(QString());
+ setTheme({});
setPath(newPath);
emit pathChanged(newPath);
}
@@ -229,7 +231,7 @@ void PixmapEditor::fileActionActivated()
{
const QString newPath = IconSelector::choosePixmapFile(m_path, m_core->dialogGui(), this);
if (!newPath.isEmpty() && newPath != m_path) {
- setTheme(QString());
+ setTheme({});
setPath(newPath);
emit pathChanged(newPath);
}
@@ -237,12 +239,14 @@ void PixmapEditor::fileActionActivated()
void PixmapEditor::themeActionActivated()
{
- bool ok;
- const QString newTheme = IconThemeDialog::getTheme(this, m_theme, &ok);
- if (ok && newTheme != m_theme) {
- setTheme(newTheme);
- setPath(QString());
- emit themeChanged(newTheme);
+ const auto newThemeO = IconThemeDialog::getTheme(this, m_theme);
+ if (newThemeO.has_value()) {
+ const QString newTheme = newThemeO.value();
+ if (newTheme != m_theme) {
+ setTheme(newTheme);
+ setPath({});
+ emit themeChanged(newTheme);
+ }
}
}
diff --git a/src/designer/src/components/propertyeditor/pixmapeditor.h b/src/designer/src/components/propertyeditor/pixmapeditor.h
index fd161c3df..6d7250456 100644
--- a/src/designer/src/components/propertyeditor/pixmapeditor.h
+++ b/src/designer/src/components/propertyeditor/pixmapeditor.h
@@ -8,6 +8,8 @@
#include <QtGui/qpixmap.h>
+#include <optional>
+
QT_BEGIN_NAMESPACE
class QLabel;
@@ -25,7 +27,7 @@ class IconThemeDialog : public QDialog
{
Q_OBJECT
public:
- static QString getTheme(QWidget *parent, const QString &theme, bool *ok);
+ static std::optional<QString> getTheme(QWidget *parent, const QString &theme);
private:
explicit IconThemeDialog(QWidget *parent);
IconThemeEditor *m_editor;
@@ -40,6 +42,9 @@ public:
void setSpacing(int spacing);
void setPixmapCache(DesignerPixmapCache *cache);
void setIconThemeModeEnabled(bool enabled);
+
+ static QString msgThemeIcon(const QString &t);
+
public slots:
void setPath(const QString &path);
void setTheme(const QString &theme);