summaryrefslogtreecommitdiffstats
path: root/src/designer
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-02-12 09:35:26 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-02-27 06:40:22 +0100
commit2f605a34a2d786f4e5172cdaa16ed9fc3799a656 (patch)
treefedf2be53deb0fecf0d4efa4fd766f65da8bb6e8 /src/designer
parentbff3833774796a5721fd286fea84261faff07850 (diff)
Qt Designer/Pixmap Editor: Introduce a state enumeration
Introduce an enumeration indicating what mode the pixmap editor is in. Add a new message indicating the fallback mode. Task-number: QTBUG-121823 Pick-to: 6.7 Change-Id: I26f82d4c6b2f5fa41a93f27e0fa0197cdfcff40d Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Diffstat (limited to 'src/designer')
-rw-r--r--src/designer/src/components/propertyeditor/designerpropertymanager.cpp13
-rw-r--r--src/designer/src/components/propertyeditor/pixmapeditor.cpp90
-rw-r--r--src/designer/src/components/propertyeditor/pixmapeditor.h15
3 files changed, 89 insertions, 29 deletions
diff --git a/src/designer/src/components/propertyeditor/designerpropertymanager.cpp b/src/designer/src/components/propertyeditor/designerpropertymanager.cpp
index fbb732f9d..b43b943a8 100644
--- a/src/designer/src/components/propertyeditor/designerpropertymanager.cpp
+++ b/src/designer/src/components/propertyeditor/designerpropertymanager.cpp
@@ -1225,17 +1225,8 @@ QString DesignerPropertyManager::valueText(const QtProperty *property) const
static const QString inherited = tr("Inherited");
return inherited;
}
- if (m_iconValues.contains(property)) {
- const PropertySheetIconValue icon = m_iconValues.value(property);
- const QString theme = icon.theme();
- if (!theme.isEmpty() && QIcon::hasThemeIcon(theme))
- return PixmapEditor::msgThemeIcon(theme);
- const auto &paths = icon.paths();
- const auto it = paths.constFind({QIcon::Normal, QIcon::Off});
- if (it == paths.constEnd())
- return QString();
- return QFileInfo(it.value().path()).fileName();
- }
+ if (m_iconValues.contains(property))
+ return PixmapEditor::displayText(m_iconValues.value(property));
if (m_pixmapValues.contains(property)) {
const QString path = m_pixmapValues.value(property).path();
if (path.isEmpty())
diff --git a/src/designer/src/components/propertyeditor/pixmapeditor.cpp b/src/designer/src/components/propertyeditor/pixmapeditor.cpp
index 296b16a9a..db18b7389 100644
--- a/src/designer/src/components/propertyeditor/pixmapeditor.cpp
+++ b/src/designer/src/components/propertyeditor/pixmapeditor.cpp
@@ -150,33 +150,39 @@ QString PixmapEditor::msgThemeIcon(const QString &t)
return tr("[Theme] %1").arg(t);
}
+QString PixmapEditor::msgMissingThemeIcon(const QString &t)
+{
+ return tr("[Theme] %1 (missing)").arg(t);
+}
+
void PixmapEditor::updateLabels()
{
- if (m_iconThemeModeEnabled && QIcon::hasThemeIcon(m_theme)) {
+ m_pathLabel->setText(displayText(m_theme, m_path));
+ switch (state()) {
+ case State::Empty:
+ case State::MissingXdgTheme:
+ m_pixmapLabel->setPixmap(m_defaultPixmap);
+ m_copyAction->setEnabled(false);
+ break;
+ case State::XdgTheme:
m_pixmapLabel->setPixmap(QIcon::fromTheme(m_theme).pixmap(ICON_SIZE));
- m_pathLabel->setText(msgThemeIcon(m_theme));
m_copyAction->setEnabled(true);
- } else {
- if (m_path.isEmpty()) {
- m_pathLabel->setText(m_path);
- m_pixmapLabel->setPixmap(m_defaultPixmap);
- m_copyAction->setEnabled(false);
- } else {
- m_pathLabel->setText(QFileInfo(m_path).fileName());
- if (m_pixmapCache) {
- auto pixmap = m_pixmapCache->pixmap(PropertySheetPixmapValue(m_path));
- m_pixmapLabel->setPixmap(QIcon(pixmap).pixmap(ICON_SIZE));
- }
- m_copyAction->setEnabled(true);
+ break;
+ case State::Path:
+ case State::PathFallback:
+ if (m_pixmapCache) {
+ auto pixmap = m_pixmapCache->pixmap(PropertySheetPixmapValue(m_path));
+ m_pixmapLabel->setPixmap(QIcon(pixmap).pixmap(ICON_SIZE));
}
+ m_copyAction->setEnabled(true);
+ break;
}
}
void PixmapEditor::setDefaultPixmapIcon(const QIcon &icon)
{
m_defaultPixmap = icon.pixmap(ICON_SIZE);
- const bool hasThemeIcon = m_iconThemeModeEnabled && QIcon::hasThemeIcon(m_theme);
- if (!hasThemeIcon && m_path.isEmpty())
+ if (state() == State::Empty)
m_pixmapLabel->setPixmap(m_defaultPixmap);
}
@@ -250,14 +256,62 @@ void PixmapEditor::themeActionActivated()
}
}
+PixmapEditor::State PixmapEditor::stateFromData(const QString &xdgTheme, const QString &path)
+{
+ if (!xdgTheme.isEmpty()) {
+ if (QIcon::hasThemeIcon(xdgTheme))
+ return State::XdgTheme;
+ return path.isEmpty() ? State::MissingXdgTheme : State::PathFallback;
+ }
+ return path.isEmpty() ? State::Empty : State::Path;
+}
+
+PixmapEditor::State PixmapEditor::state() const
+{
+ return stateFromData(m_theme, m_path);
+}
+
+QString PixmapEditor::displayText(const QString &xdgTheme, const QString &path)
+{
+ switch (stateFromData(xdgTheme, path)) {
+ case State::XdgTheme:
+ return msgThemeIcon(xdgTheme);
+ case State::MissingXdgTheme:
+ return msgMissingThemeIcon(xdgTheme);
+ case State::Path:
+ return QFileInfo(path).fileName();
+ case State::PathFallback:
+ return tr("%1 (fallback)").arg(QFileInfo(path).fileName());
+ case State::Empty:
+ break;
+ }
+ return {};
+}
+
+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);
+}
+
#if QT_CONFIG(clipboard)
void PixmapEditor::copyActionActivated()
{
QClipboard *clipboard = QApplication::clipboard();
- if (m_iconThemeModeEnabled && QIcon::hasThemeIcon(m_theme))
+ switch (state()) {
+ case State::XdgTheme:
+ case State::MissingXdgTheme:
clipboard->setText(m_theme);
- else
+ break;
+ case State::Path:
+ case State::PathFallback:
clipboard->setText(m_path);
+ break;
+ case State::Empty:
+ break;
+ }
}
void PixmapEditor::pasteActionActivated()
diff --git a/src/designer/src/components/propertyeditor/pixmapeditor.h b/src/designer/src/components/propertyeditor/pixmapeditor.h
index 6d7250456..ed5f918f0 100644
--- a/src/designer/src/components/propertyeditor/pixmapeditor.h
+++ b/src/designer/src/components/propertyeditor/pixmapeditor.h
@@ -22,6 +22,7 @@ namespace qdesigner_internal {
class DesignerPixmapCache;
class IconThemeEditor;
+class PropertySheetIconValue;
class IconThemeDialog : public QDialog
{
@@ -44,6 +45,8 @@ public:
void setIconThemeModeEnabled(bool enabled);
static QString msgThemeIcon(const QString &t);
+ static QString msgMissingThemeIcon(const QString &t);
+ static QString displayText(const PropertySheetIconValue &icon);
public slots:
void setPath(const QString &path);
@@ -69,6 +72,18 @@ private slots:
void clipboardDataChanged();
#endif
private:
+ enum class State {
+ Empty,
+ XdgTheme,
+ MissingXdgTheme,
+ Path,
+ PathFallback // Non-existent theme icon, falling back to path
+ };
+
+ static State stateFromData(const QString &xdgTheme, const QString &path);
+ State state() const;
+ static QString displayText(const QString &xdgTheme, const QString &path);
+
void updateLabels();
bool m_iconThemeModeEnabled;
QDesignerFormEditorInterface *m_core;