diff options
Diffstat (limited to 'tools/designer/src/components/propertyeditor/designerpropertymanager.cpp')
-rw-r--r-- | tools/designer/src/components/propertyeditor/designerpropertymanager.cpp | 310 |
1 files changed, 268 insertions, 42 deletions
diff --git a/tools/designer/src/components/propertyeditor/designerpropertymanager.cpp b/tools/designer/src/components/propertyeditor/designerpropertymanager.cpp index e251511..8e7312f 100644 --- a/tools/designer/src/components/propertyeditor/designerpropertymanager.cpp +++ b/tools/designer/src/components/propertyeditor/designerpropertymanager.cpp @@ -83,6 +83,7 @@ static const char *validationModesAttributeC = "validationMode"; static const char *superPaletteAttributeC = "superPalette"; static const char *defaultResourceAttributeC = "defaultResource"; static const char *fontAttributeC = "font"; +static const char *themeAttributeC = "theme"; class DesignerFlagPropertyType { @@ -113,13 +114,15 @@ public: void setTextPropertyValidationMode(TextPropertyValidationMode vm); void setRichTextDefaultFont(const QFont &font) { m_richTextDefaultFont = font; } - QFont richTextDefaultFont() const { return m_richTextDefaultFont; } + QFont richTextDefaultFont() const { return m_richTextDefaultFont; } void setSpacing(int spacing); TextPropertyEditor::UpdateMode updateMode() const { return m_editor->updateMode(); } void setUpdateMode(TextPropertyEditor::UpdateMode um) { m_editor->setUpdateMode(um); } + void setIconThemeModeEnabled(bool enable); + public slots: void setText(const QString &text); @@ -132,6 +135,8 @@ private slots: void fileActionActivated(); private: TextPropertyEditor *m_editor; + IconThemeEditor *m_themeEditor; + bool m_iconThemeModeEnabled; QFont m_richTextDefaultFont; QToolButton *m_button; QMenu *m_menu; @@ -144,6 +149,8 @@ private: TextEditor::TextEditor(QDesignerFormEditorInterface *core, QWidget *parent) : QWidget(parent), m_editor(new TextPropertyEditor(this)), + m_themeEditor(new IconThemeEditor(this, false)), + m_iconThemeModeEnabled(false), m_richTextDefaultFont(QApplication::font()), m_button(new QToolButton(this)), m_menu(new QMenu(this)), @@ -152,7 +159,11 @@ TextEditor::TextEditor(QDesignerFormEditorInterface *core, QWidget *parent) : m_layout(new QHBoxLayout(this)), m_core(core) { + m_themeEditor->setVisible(false); + m_button->setVisible(false); + m_layout->addWidget(m_editor); + m_layout->addWidget(m_themeEditor); m_button->setText(tr("...")); m_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored); m_button->setFixedWidth(20); @@ -163,9 +174,10 @@ TextEditor::TextEditor(QDesignerFormEditorInterface *core, QWidget *parent) : connect(m_resourceAction, SIGNAL(triggered()), this, SLOT(resourceActionActivated())); connect(m_fileAction, SIGNAL(triggered()), this, SLOT(fileActionActivated())); connect(m_editor, SIGNAL(textChanged(QString)), this, SIGNAL(textChanged(QString))); + connect(m_themeEditor, SIGNAL(edited(QString)), this, SIGNAL(textChanged(QString))); connect(m_button, SIGNAL(clicked()), this, SLOT(buttonClicked())); + setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); - m_button->setVisible(false); setFocusProxy(m_editor); m_menu->addAction(m_resourceAction); @@ -177,6 +189,22 @@ void TextEditor::setSpacing(int spacing) m_layout->setSpacing(spacing); } +void TextEditor::setIconThemeModeEnabled(bool enable) +{ + if (m_iconThemeModeEnabled == enable) + return; // nothing changes + m_iconThemeModeEnabled = enable; + m_editor->setVisible(!enable); + m_themeEditor->setVisible(enable); + if (enable) { + m_themeEditor->setTheme(m_editor->text()); + setFocusProxy(m_themeEditor); + } else { + m_editor->setText(m_themeEditor->theme()); + setFocusProxy(m_editor); + } +} + TextPropertyValidationMode TextEditor::textPropertyValidationMode() const { return m_editor->textPropertyValidationMode(); @@ -199,7 +227,10 @@ void TextEditor::setTextPropertyValidationMode(TextPropertyValidationMode vm) void TextEditor::setText(const QString &text) { - m_editor->setText(text); + if (m_iconThemeModeEnabled) + m_themeEditor->setTheme(text); + else + m_editor->setText(text); } void TextEditor::buttonClicked() @@ -279,6 +310,49 @@ void TextEditor::fileActionActivated() emit textChanged(newText); } +// ------------ ThemeInputDialog + +class IconThemeDialog : public QDialog +{ + Q_OBJECT +public: + static QString getTheme(QWidget *parent, const QString &theme, bool *ok); +private: + IconThemeDialog(QWidget *parent); + IconThemeEditor *m_editor; +}; + +IconThemeDialog::IconThemeDialog(QWidget *parent) + : QDialog(parent) +{ + setWindowTitle(tr("Set Icon From Theme")); + + QVBoxLayout *layout = new QVBoxLayout(this); + QLabel *label = new QLabel(tr("Input icon name from the current theme:"), this); + m_editor = new IconThemeEditor(this); + QDialogButtonBox *buttons = new QDialogButtonBox(this); + buttons->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + + layout->addWidget(label); + layout->addWidget(m_editor); + layout->addWidget(buttons); + + connect(buttons, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttons, SIGNAL(rejected()), this, SLOT(reject())); +} + +QString IconThemeDialog::getTheme(QWidget *parent, const QString &theme, bool *ok) +{ + IconThemeDialog dlg(parent); + dlg.m_editor->setTheme(theme); + if (dlg.exec() == QDialog::Accepted) { + *ok = true; + return dlg.m_editor->theme(); + } + *ok = false; + return QString(); +} + // ------------ PixmapEditor class PixmapEditor : public QWidget { @@ -288,12 +362,15 @@ public: void setSpacing(int spacing); void setPixmapCache(DesignerPixmapCache *cache); + void setIconThemeModeEnabled(bool enabled); public slots: void setPath(const QString &path); + void setTheme(const QString &theme); void setDefaultPixmap(const QPixmap &pixmap); signals: void pathChanged(const QString &path); + void themeChanged(const QString &theme); protected: void contextMenuEvent(QContextMenuEvent *event); @@ -302,32 +379,39 @@ private slots: void defaultActionActivated(); void resourceActionActivated(); void fileActionActivated(); + void themeActionActivated(); void copyActionActivated(); void pasteActionActivated(); void clipboardDataChanged(); private: + void updateLabels(); + bool m_iconThemeModeEnabled; QDesignerFormEditorInterface *m_core; QLabel *m_pixmapLabel; QLabel *m_pathLabel; QToolButton *m_button; QAction *m_resourceAction; QAction *m_fileAction; + QAction *m_themeAction; QAction *m_copyAction; QAction *m_pasteAction; QHBoxLayout *m_layout; QPixmap m_defaultPixmap; QString m_path; + QString m_theme; DesignerPixmapCache *m_pixmapCache; }; PixmapEditor::PixmapEditor(QDesignerFormEditorInterface *core, QWidget *parent) : QWidget(parent), + m_iconThemeModeEnabled(false), m_core(core), m_pixmapLabel(new QLabel(this)), m_pathLabel(new QLabel(this)), 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_copyAction(new QAction(createIconSet(QLatin1String("editcopy.png")), tr("Copy Path"), this)), m_pasteAction(new QAction(createIconSet(QLatin1String("editpaste.png")), tr("Paste Path"), this)), m_layout(new QHBoxLayout(this)), @@ -345,10 +429,12 @@ PixmapEditor::PixmapEditor(QDesignerFormEditorInterface *core, QWidget *parent) m_pixmapLabel->setFixedWidth(16); m_pixmapLabel->setAlignment(Qt::AlignCenter); m_pathLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed)); + m_themeAction->setVisible(false); QMenu *menu = new QMenu(this); menu->addAction(m_resourceAction); menu->addAction(m_fileAction); + menu->addAction(m_themeAction); m_button->setMenu(menu); m_button->setText(tr("...")); @@ -356,6 +442,7 @@ PixmapEditor::PixmapEditor(QDesignerFormEditorInterface *core, QWidget *parent) connect(m_button, SIGNAL(clicked()), this, SLOT(defaultActionActivated())); connect(m_resourceAction, SIGNAL(triggered()), this, SLOT(resourceActionActivated())); connect(m_fileAction, SIGNAL(triggered()), this, SLOT(fileActionActivated())); + connect(m_themeAction, SIGNAL(triggered()), this, SLOT(themeActionActivated())); connect(m_copyAction, SIGNAL(triggered()), this, SLOT(copyActionActivated())); connect(m_pasteAction, SIGNAL(triggered()), this, SLOT(pasteActionActivated())); setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored)); @@ -370,6 +457,14 @@ void PixmapEditor::setPixmapCache(DesignerPixmapCache *cache) m_pixmapCache = cache; } +void PixmapEditor::setIconThemeModeEnabled(bool enabled) +{ + if (m_iconThemeModeEnabled == enabled) + return; + m_iconThemeModeEnabled = enabled; + m_themeAction->setVisible(enabled); +} + void PixmapEditor::setSpacing(int spacing) { m_layout->setSpacing(spacing); @@ -378,22 +473,40 @@ void PixmapEditor::setSpacing(int spacing) void PixmapEditor::setPath(const QString &path) { m_path = path; - if (m_path.isEmpty()) { - m_pathLabel->setText(path); - m_pixmapLabel->setPixmap(m_defaultPixmap); - m_copyAction->setEnabled(false); - } else { - m_pathLabel->setText(QFileInfo(m_path).fileName()); - if (m_pixmapCache) - m_pixmapLabel->setPixmap(QIcon(m_pixmapCache->pixmap(PropertySheetPixmapValue(path))).pixmap(16, 16)); + updateLabels(); +} + +void PixmapEditor::setTheme(const QString &theme) +{ + m_theme = theme; + updateLabels(); +} + +void PixmapEditor::updateLabels() +{ + if (m_iconThemeModeEnabled && QIcon::hasThemeIcon(m_theme)) { + m_pixmapLabel->setPixmap(QIcon::fromTheme(m_theme).pixmap(16, 16)); + m_pathLabel->setText(tr("[Theme] %1").arg(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) + m_pixmapLabel->setPixmap(QIcon(m_pixmapCache->pixmap(PropertySheetPixmapValue(m_path))).pixmap(16, 16)); + m_copyAction->setEnabled(true); + } } } void PixmapEditor::setDefaultPixmap(const QPixmap &pixmap) { m_defaultPixmap = QIcon(pixmap).pixmap(16, 16); - if (m_path.isEmpty()) + const bool hasThemeIcon = m_iconThemeModeEnabled && QIcon::hasThemeIcon(m_theme); + if (!hasThemeIcon && m_path.isEmpty()) m_pixmapLabel->setPixmap(m_defaultPixmap); } @@ -408,6 +521,10 @@ void PixmapEditor::contextMenuEvent(QContextMenuEvent *event) void PixmapEditor::defaultActionActivated() { + if (m_iconThemeModeEnabled && QIcon::hasThemeIcon(m_theme)) { + themeActionActivated(); + return; + } // Default to resource const PropertySheetPixmapValue::PixmapSource ps = m_path.isEmpty() ? PropertySheetPixmapValue::ResourcePixmap : PropertySheetPixmapValue::getPixmapSource(m_core, m_path); switch (ps) { @@ -426,6 +543,7 @@ void PixmapEditor::resourceActionActivated() const QString oldPath = m_path; const QString newPath = IconSelector::choosePixmapResource(m_core, m_core->resourceModel(), oldPath, this); if (!newPath.isEmpty() && newPath != oldPath) { + setTheme(QString()); setPath(newPath); emit pathChanged(newPath); } @@ -435,15 +553,30 @@ void PixmapEditor::fileActionActivated() { const QString newPath = IconSelector::choosePixmapFile(m_path, m_core->dialogGui(), this); if (!newPath.isEmpty() && newPath != m_path) { + setTheme(QString()); setPath(newPath); emit pathChanged(newPath); } } +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); + } +} + void PixmapEditor::copyActionActivated() { QClipboard *clipboard = QApplication::clipboard(); - clipboard->setText(m_path); + if (m_iconThemeModeEnabled && QIcon::hasThemeIcon(m_theme)) + clipboard->setText(m_theme); + else + clipboard->setText(m_path); } void PixmapEditor::pasteActionActivated() @@ -455,8 +588,15 @@ void PixmapEditor::pasteActionActivated() QStringList list = text.split(QLatin1Char('\n')); if (list.size() > 0) { text = list.at(0); - setPath(text); - emit pathChanged(text); + if (m_iconThemeModeEnabled && QIcon::hasThemeIcon(text)) { + setTheme(text); + setPath(QString()); + emit themeChanged(text); + } else { + setPath(text); + setTheme(QString()); + emit pathChanged(text); + } } } } @@ -807,8 +947,13 @@ void DesignerPropertyManager::slotValueChanged(QtProperty *property, const QVari } else if (QtProperty *iProperty = m_iconSubPropertyToProperty.value(property, 0)) { QtVariantProperty *iconProperty = variantProperty(iProperty); PropertySheetIconValue icon = qvariant_cast<PropertySheetIconValue>(iconProperty->value()); - QPair<QIcon::Mode, QIcon::State> pair = m_iconSubPropertyToState.value(property); - icon.setPixmap(pair.first, pair.second, qvariant_cast<PropertySheetPixmapValue>(value)); + QMap<QtProperty *, QPair<QIcon::Mode, QIcon::State> >::ConstIterator itState = m_iconSubPropertyToState.constFind(property); + if (itState != m_iconSubPropertyToState.constEnd()) { + QPair<QIcon::Mode, QIcon::State> pair = m_iconSubPropertyToState.value(property); + icon.setPixmap(pair.first, pair.second, qvariant_cast<PropertySheetPixmapValue>(value)); + } else { // must be theme property + icon.setTheme(value.toString()); + } QtProperty *origSourceOfChange = m_sourceOfChange; if (!origSourceOfChange) m_sourceOfChange = property; @@ -859,12 +1004,16 @@ void DesignerPropertyManager::slotPropertyDestroyed(QtProperty *property) m_keySequenceToDisambiguation.remove(keySequenceDisambiguationProperty); m_disambiguationToKeySequence.remove(property); } else if (QtProperty *iconProperty = m_iconSubPropertyToProperty.value(property, 0)) { - QMap<QtProperty *, QMap<QPair<QIcon::Mode, QIcon::State>, QtProperty *> >::iterator it = - m_propertyToIconSubProperties.find(iconProperty); - QPair<QIcon::Mode, QIcon::State> state = m_iconSubPropertyToState.value(property); - QMap<QPair<QIcon::Mode, QIcon::State>, QtProperty *> &propertyList = it.value(); - propertyList.remove(state); - m_iconSubPropertyToState.remove(property); + if (m_propertyToTheme.value(iconProperty) == property) { + m_propertyToTheme.remove(iconProperty); + } else { + QMap<QtProperty *, QMap<QPair<QIcon::Mode, QIcon::State>, QtProperty *> >::iterator it = + m_propertyToIconSubProperties.find(iconProperty); + QPair<QIcon::Mode, QIcon::State> state = m_iconSubPropertyToState.value(property); + QMap<QPair<QIcon::Mode, QIcon::State>, QtProperty *> &propertyList = it.value(); + propertyList.remove(state); + m_iconSubPropertyToState.remove(property); + } m_iconSubPropertyToProperty.remove(property); } else { m_fontManager.slotPropertyDestroyed(property); @@ -887,6 +1036,7 @@ QStringList DesignerPropertyManager::attributes(int propertyType) const } else if (propertyType == designerStringTypeId() || propertyType == QVariant::String) { list.append(QLatin1String(validationModesAttributeC)); list.append(QLatin1String(fontAttributeC)); + list.append(QLatin1String(themeAttributeC)); } else if (propertyType == QVariant::Palette) { list.append(QLatin1String(superPaletteAttributeC)); } @@ -912,6 +1062,8 @@ int DesignerPropertyManager::attributeType(int propertyType, const QString &attr return QVariant::Int; if (attribute == QLatin1String(fontAttributeC)) return QVariant::Font; + if (attribute == QLatin1String(themeAttributeC)) + return QVariant::Bool; } if (propertyType == QVariant::Palette && attribute == QLatin1String(superPaletteAttributeC)) return QVariant::Palette; @@ -949,6 +1101,12 @@ QVariant DesignerPropertyManager::attributeValue(const QtProperty *property, con return it.value(); } + if (attribute == QLatin1String(themeAttributeC)) { + const PropertyBoolMap::const_iterator it = m_stringThemeAttributes.constFind(prop); + if (it != m_stringThemeAttributes.constEnd()) + return it.value(); + } + if (attribute == QLatin1String(superPaletteAttributeC)) { PropertyPaletteDataMap::const_iterator it = m_paletteValues.constFind(prop); if (it != m_paletteValues.constEnd()) @@ -1057,6 +1215,21 @@ void DesignerPropertyManager::setAttribute(QtProperty *property, it.value() = newValue; emit attributeChanged(property, attribute, newValue); + } else if (attribute == QLatin1String(themeAttributeC) && m_stringThemeAttributes.contains(property)) { + if (value.userType() != QVariant::Bool) + return; + + const PropertyBoolMap::iterator it = m_stringThemeAttributes.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 == QLatin1String(superPaletteAttributeC) && m_paletteValues.contains(property)) { if (value.userType() != QVariant::Palette) return; @@ -1234,7 +1407,11 @@ QString DesignerPropertyManager::valueText(const QtProperty *property) const return inherited; } if (m_iconValues.contains(const_cast<QtProperty *>(property))) { - const PropertySheetIconValue::ModeStateToPixmapMap paths = m_iconValues.value(const_cast<QtProperty *>(property)).paths(); + 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); + const PropertySheetIconValue::ModeStateToPixmapMap paths = icon.paths(); const PropertySheetIconValue::ModeStateToPixmapMap::const_iterator it = paths.constFind(qMakePair(QIcon::Normal, QIcon::Off)); if (it == paths.constEnd()) return QString(); @@ -1339,6 +1516,8 @@ QIcon DesignerPropertyManager::valueIcon(const QtProperty *property) const qdesigner_internal::FormWindowBase *fwb = qobject_cast<qdesigner_internal::FormWindowBase *>(formWindow); if (fwb) return fwb->pixmapCache()->pixmap(m_pixmapValues.value(const_cast<QtProperty *>(property))); + } else if (m_stringThemeAttributes.value(const_cast<QtProperty *>(property), false)) { + return QIcon::fromTheme(value(property).toString()); } else { QIcon rc; if (m_brushManager.valueIcon(property, &rc)) @@ -1604,6 +1783,12 @@ void DesignerPropertyManager::setValue(QtProperty *property, const QVariant &val subProperty->setAttribute(QLatin1String(defaultResourceAttributeC), defaultIcon.pixmap(16, 16, pair.first, pair.second)); } + QtVariantProperty *themeSubProperty = variantProperty(m_propertyToTheme.value(property)); + if (themeSubProperty) { + const QString theme = icon.theme(); + themeSubProperty->setModified(!theme.isEmpty()); + themeSubProperty->setValue(theme); + } emit QtVariantPropertyManager::valueChanged(property, QVariant::fromValue(icon)); emit propertyChanged(property); @@ -1766,6 +1951,7 @@ void DesignerPropertyManager::initializeProperty(QtProperty *property) case QVariant::String: m_stringAttributes[property] = ValidationSingleLine; m_stringFontAttributes[property] = QApplication::font(); + m_stringThemeAttributes[property] = false; break; case QVariant::UInt: m_uintValues[property] = 0; @@ -1820,6 +2006,13 @@ void DesignerPropertyManager::initializeProperty(QtProperty *property) m_iconValues[property] = PropertySheetIconValue(); m_defaultIcons[property] = QIcon(); + QtVariantProperty *themeProp = addProperty(QVariant::String, tr("Theme")); + themeProp->setAttribute(QLatin1String(themeAttributeC), true); + m_iconSubPropertyToProperty[themeProp] = property; + m_propertyToTheme[property] = themeProp; + m_resetMap[themeProp] = true; + property->addSubProperty(themeProp); + createIconSubProperty(property, QIcon::Normal, QIcon::Off, tr("Normal Off")); createIconSubProperty(property, QIcon::Normal, QIcon::On, tr("Normal On")); createIconSubProperty(property, QIcon::Disabled, QIcon::Off, tr("Disabled Off")); @@ -1833,6 +2026,7 @@ void DesignerPropertyManager::initializeProperty(QtProperty *property) m_stringValues[property] = val; m_stringAttributes[property] = ValidationMultiLine; m_stringFontAttributes[property] = QApplication::font(); + m_stringThemeAttributes[property] = false; QtVariantProperty *translatable = addProperty(QVariant::Bool, tr("translatable")); translatable->setValue(val.translatable()); @@ -1921,37 +2115,43 @@ void DesignerPropertyManager::uninitializeProperty(QtProperty *property) QtProperty *stringComment = m_stringToComment.value(property); if (stringComment) { delete stringComment; - m_stringToComment.remove(stringComment); + m_commentToString.remove(stringComment); } QtProperty *stringTranslatable = m_stringToTranslatable.value(property); if (stringTranslatable) { delete stringTranslatable; - m_stringToTranslatable.remove(stringTranslatable); + m_translatableToString.remove(stringTranslatable); } QtProperty *stringDisambiguation = m_stringToDisambiguation.value(property); if (stringDisambiguation) { delete stringDisambiguation; - m_stringToDisambiguation.remove(stringDisambiguation); + m_disambiguationToString.remove(stringDisambiguation); } QtProperty *keySequenceComment = m_keySequenceToComment.value(property); if (keySequenceComment) { delete keySequenceComment; - m_keySequenceToComment.remove(keySequenceComment); + m_commentToKeySequence.remove(keySequenceComment); } QtProperty *keySequenceTranslatable = m_keySequenceToTranslatable.value(property); if (keySequenceTranslatable) { delete keySequenceTranslatable; - m_keySequenceToTranslatable.remove(keySequenceTranslatable); + m_translatableToKeySequence.remove(keySequenceTranslatable); } QtProperty *keySequenceDisambiguation = m_keySequenceToDisambiguation.value(property); if (keySequenceDisambiguation) { delete keySequenceDisambiguation; - m_keySequenceToDisambiguation.remove(keySequenceDisambiguation); + m_disambiguationToKeySequence.remove(keySequenceDisambiguation); + } + + QtProperty *iconTheme = m_propertyToTheme.value(property); + if (iconTheme) { + delete iconTheme; + m_iconSubPropertyToProperty.remove(iconTheme); } m_propertyToAlignH.remove(property); @@ -2010,15 +2210,20 @@ bool DesignerPropertyManager::resetFontSubProperty(QtProperty *property) bool DesignerPropertyManager::resetIconSubProperty(QtProperty *property) { - if (!m_iconSubPropertyToProperty.contains(property)) - return false; - - if (!m_pixmapValues.contains(property)) + QtProperty *iconProperty = m_iconSubPropertyToProperty.value(property); + if (!iconProperty) return false; - QtVariantProperty *pixmapProperty = variantProperty(property); - pixmapProperty->setValue(QVariant::fromValue(PropertySheetPixmapValue())); - return true; + if (m_pixmapValues.contains(property)) { + QtVariantProperty *pixmapProperty = variantProperty(property); + pixmapProperty->setValue(QVariant::fromValue(PropertySheetPixmapValue())); + return true; + } else if (m_propertyToTheme.contains(iconProperty)) { + QtVariantProperty *themeProperty = variantProperty(property); + themeProperty->setValue(QString()); + return true; + } + return false; } // -------- DesignerEditorFactory @@ -2116,6 +2321,10 @@ void DesignerEditorFactory::slotAttributeChanged(QtProperty *property, const QSt const QFont font = qvariant_cast<QFont>(value); applyToEditors(m_stringPropertyToEditors.value(property), &TextEditor::setRichTextDefaultFont, font); } + if (attribute == QLatin1String(themeAttributeC)) { + const bool themeEnabled = value.toBool(); + applyToEditors(m_stringPropertyToEditors.value(property), &TextEditor::setIconThemeModeEnabled, themeEnabled); + } } else if (type == QVariant::Palette && attribute == QLatin1String(superPaletteAttributeC)) { const QPalette palette = qvariant_cast<QPalette>(value); applyToEditors(m_palettePropertyToEditors.value(property), &PaletteEditorButton::setSuperPalette, palette); @@ -2174,14 +2383,18 @@ void DesignerEditorFactory::slotValueChanged(QtProperty *property, const QVarian applyToEditors(m_stringListPropertyToEditors.value(property), &StringListEditorButton::setStringList, value.toStringList()); break; default: - if (type == DesignerPropertyManager::designerIconTypeId()) - applyToEditors(m_iconPropertyToEditors.value(property), &PixmapEditor::setPath, qvariant_cast<PropertySheetIconValue>(value).pixmap(QIcon::Normal, QIcon::Off).path()); - else if (type == DesignerPropertyManager::designerPixmapTypeId()) + if (type == DesignerPropertyManager::designerIconTypeId()) { + PropertySheetIconValue iconValue = qvariant_cast<PropertySheetIconValue>(value); + const QString theme = iconValue.theme(); + applyToEditors(m_iconPropertyToEditors.value(property), &PixmapEditor::setTheme, iconValue.theme()); + 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()); - else if (type == DesignerPropertyManager::designerStringTypeId()) + } else if (type == DesignerPropertyManager::designerStringTypeId()) { applyToEditors(m_stringPropertyToEditors.value(property), &TextEditor::setText, qvariant_cast<PropertySheetStringValue>(value).value()); - else if (type == DesignerPropertyManager::designerKeySequenceTypeId()) + } else if (type == DesignerPropertyManager::designerKeySequenceTypeId()) { applyToEditors(m_keySequencePropertyToEditors.value(property), &QtKeySequenceEdit::setKeySequence, qvariant_cast<PropertySheetKeySequenceValue>(value).value()); + } break; } } @@ -2215,6 +2428,8 @@ QWidget *DesignerEditorFactory::createEditor(QtVariantPropertyManager *manager, const QVariant richTextDefaultFont = manager->attributeValue(property, QLatin1String(fontAttributeC)); if (richTextDefaultFont.type() == QVariant::Font) ed->setRichTextDefaultFont(qvariant_cast<QFont>(richTextDefaultFont)); + const bool themeEnabled = manager->attributeValue(property, QLatin1String(themeAttributeC)).toBool(); + ed->setIconThemeModeEnabled(themeEnabled); m_stringPropertyToEditors[property].append(ed); m_editorToStringProperty[ed] = property; connect(ed, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*))); @@ -2308,7 +2523,9 @@ QWidget *DesignerEditorFactory::createEditor(QtVariantPropertyManager *manager, } else if (type == DesignerPropertyManager::designerIconTypeId()) { PixmapEditor *ed = new PixmapEditor(m_core, parent); ed->setPixmapCache(m_fwb->pixmapCache()); + ed->setIconThemeModeEnabled(true); PropertySheetIconValue value = qvariant_cast<PropertySheetIconValue>(manager->value(property)); + ed->setTheme(value.theme()); ed->setPath(value.pixmap(QIcon::Normal, QIcon::Off).path()); QPixmap defaultPixmap; if (!property->isModified()) @@ -2321,6 +2538,7 @@ QWidget *DesignerEditorFactory::createEditor(QtVariantPropertyManager *manager, m_editorToIconProperty[ed] = property; connect(ed, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*))); connect(ed, SIGNAL(pathChanged(QString)), this, SLOT(slotIconChanged(QString))); + connect(ed, SIGNAL(themeChanged(QString)), this, SLOT(slotIconThemeChanged(QString))); editor = ed; } else if (type == DesignerPropertyManager::designerStringTypeId()) { const TextPropertyValidationMode tvm = static_cast<TextPropertyValidationMode>(manager->attributeValue(property, QLatin1String(validationModesAttributeC)).toInt()); @@ -2512,6 +2730,14 @@ void DesignerEditorFactory::slotIconChanged(const QString &value) QVariant::fromValue(PropertySheetIconValue(PropertySheetPixmapValue(value)))); } +void DesignerEditorFactory::slotIconThemeChanged(const QString &value) +{ + PropertySheetIconValue icon; + icon.setTheme(value); + updateManager(this, &m_changingPropertyValue, m_editorToIconProperty, qobject_cast<QWidget *>(sender()), + QVariant::fromValue(icon)); +} + void DesignerEditorFactory::slotStringListChanged(const QStringList &value) { updateManager(this, &m_changingPropertyValue, m_editorToStringListProperty, qobject_cast<QWidget *>(sender()), QVariant::fromValue(value)); |