78void TranslatablePropertyManager<PropertySheetValue>::initialize(QtVariantPropertyManager *m,
80 const PropertySheetValue &value)
82 m_values.insert(property, value);
84 QtVariantProperty *translatable = m->addProperty(QMetaType::Bool, DesignerPropertyManager::tr(
"translatable"));
85 translatable->setValue(value.translatable());
86 m_valueToTranslatable.insert(property, translatable);
87 m_translatableToValue.insert(translatable, property);
88 property->addSubProperty(translatable);
90 if (!DesignerPropertyManager::useIdBasedTranslations()) {
91 QtVariantProperty *disambiguation =
92 m->addProperty(QMetaType::QString, DesignerPropertyManager::tr(
"disambiguation"));
93 disambiguation->setValue(value.disambiguation());
94 m_valueToDisambiguation.insert(property, disambiguation);
95 m_disambiguationToValue.insert(disambiguation, property);
96 property->addSubProperty(disambiguation);
99 QtVariantProperty *comment = m->addProperty(QMetaType::QString, DesignerPropertyManager::tr(
"comment"));
100 comment->setValue(value.comment());
101 m_valueToComment.insert(property, comment);
102 m_commentToValue.insert(comment, property);
103 property->addSubProperty(comment);
105 if (DesignerPropertyManager::useIdBasedTranslations()) {
106 QtVariantProperty *id = m->addProperty(QMetaType::QString, DesignerPropertyManager::tr(
"id"));
107 id->setValue(value.id());
108 m_valueToId.insert(property, id);
109 m_idToValue.insert(id, property);
110 property->addSubProperty(id);
114template <
class PropertySheetValue>
115bool TranslatablePropertyManager<PropertySheetValue>::uninitialize(QtProperty *property)
117 if (QtProperty *comment = m_valueToComment.value(property)) {
119 m_commentToValue.remove(comment);
123 if (QtProperty *translatable = m_valueToTranslatable.value(property)) {
125 m_translatableToValue.remove(translatable);
127 if (QtProperty *disambiguation = m_valueToDisambiguation.value(property)) {
128 delete disambiguation;
129 m_disambiguationToValue.remove(disambiguation);
131 if (QtProperty *id = m_valueToId.value(property)) {
133 m_idToValue.remove(id);
136 m_values.remove(property);
137 m_valueToComment.remove(property);
138 m_valueToTranslatable.remove(property);
139 m_valueToDisambiguation.remove(property);
140 m_valueToId.remove(property);
144template <
class PropertySheetValue>
145bool TranslatablePropertyManager<PropertySheetValue>::destroy(QtProperty *subProperty)
147 const auto commentToValueIt = m_commentToValue.find(subProperty);
148 if (commentToValueIt != m_commentToValue.end()) {
149 m_valueToComment.remove(commentToValueIt.value());
150 m_commentToValue.erase(commentToValueIt);
153 const auto translatableToValueIt = m_translatableToValue.find(subProperty);
154 if (translatableToValueIt != m_translatableToValue.end()) {
155 m_valueToTranslatable.remove(translatableToValueIt.value());
156 m_translatableToValue.erase(translatableToValueIt);
159 const auto disambiguationToValueIt = m_disambiguationToValue.find(subProperty);
160 if (disambiguationToValueIt != m_disambiguationToValue.end()) {
161 m_valueToDisambiguation.remove(disambiguationToValueIt.value());
162 m_disambiguationToValue.erase(disambiguationToValueIt);
165 const auto idToValueIt = m_idToValue.find(subProperty);
166 if (idToValueIt != m_idToValue.end()) {
167 m_valueToId.remove(idToValueIt.value());
168 m_idToValue.erase(idToValueIt);
174template <
class PropertySheetValue>
175int TranslatablePropertyManager<PropertySheetValue>::valueChanged(QtVariantPropertyManager *m,
176 QtProperty *propertyIn,
177 const QVariant &value)
179 if (QtProperty *property = m_translatableToValue.value(propertyIn, 0)) {
180 const PropertySheetValue oldValue = m_values.value(property);
181 PropertySheetValue newValue = oldValue;
182 newValue.setTranslatable(value.toBool());
183 if (newValue != oldValue) {
184 m->variantProperty(property)->setValue(QVariant::fromValue(newValue));
185 return DesignerPropertyManager::Changed;
187 return DesignerPropertyManager::Unchanged;
189 if (QtProperty *property = m_commentToValue.value(propertyIn)) {
190 const PropertySheetValue oldValue = m_values.value(property);
191 PropertySheetValue newValue = oldValue;
192 newValue.setComment(value.toString());
193 if (newValue != oldValue) {
194 m->variantProperty(property)->setValue(QVariant::fromValue(newValue));
195 return DesignerPropertyManager::Changed;
197 return DesignerPropertyManager::Unchanged;
199 if (QtProperty *property = m_disambiguationToValue.value(propertyIn, 0)) {
200 const PropertySheetValue oldValue = m_values.value(property);
201 PropertySheetValue newValue = oldValue;
202 newValue.setDisambiguation(value.toString());
203 if (newValue != oldValue) {
204 m->variantProperty(property)->setValue(QVariant::fromValue(newValue));
205 return DesignerPropertyManager::Changed;
207 return DesignerPropertyManager::Unchanged;
209 if (QtProperty *property = m_idToValue.value(propertyIn)) {
210 const PropertySheetValue oldValue = m_values.value(property);
211 PropertySheetValue newValue = oldValue;
212 newValue.setId(value.toString());
213 if (newValue != oldValue) {
214 m->variantProperty(property)->setValue(QVariant::fromValue(newValue));
215 return DesignerPropertyManager::Changed;
217 return DesignerPropertyManager::Unchanged;
219 return DesignerPropertyManager::NoMatch;
222template <
class PropertySheetValue>
223int TranslatablePropertyManager<PropertySheetValue>::setValue(QtVariantPropertyManager *m,
224 QtProperty *property,
226 const QVariant &variantValue)
228 const auto it = m_values.find(property);
229 if (it == m_values.end())
230 return DesignerPropertyManager::NoMatch;
231 if (variantValue.userType() != expectedTypeId)
232 return DesignerPropertyManager::NoMatch;
233 const PropertySheetValue value = qvariant_cast<PropertySheetValue>(variantValue);
234 if (value == it.value())
235 return DesignerPropertyManager::Unchanged;
236 if (QtVariantProperty *comment = m->variantProperty(m_valueToComment.value(property)))
237 comment->setValue(value.comment());
238 if (QtVariantProperty *translatable = m->variantProperty(m_valueToTranslatable.value(property)))
239 translatable->setValue(value.translatable());
240 if (QtVariantProperty *disambiguation = m->variantProperty(m_valueToDisambiguation.value(property)))
241 disambiguation->setValue(value.disambiguation());
242 if (QtVariantProperty *id = m->variantProperty(m_valueToId.value(property)))
243 id->setValue(value.id());
245 return DesignerPropertyManager::Changed;
248template <
class PropertySheetValue>
249bool TranslatablePropertyManager<PropertySheetValue>::value(
const QtProperty *property, QVariant *rc)
const
251 const auto it = m_values.constFind(property);
252 if (it == m_values.constEnd())
254 *rc = QVariant::fromValue(it.value());
259class TextEditor :
public QWidget
263 TextEditor(QDesignerFormEditorInterface *core, QWidget *parent);
265 TextPropertyValidationMode textPropertyValidationMode()
const;
266 void setTextPropertyValidationMode(TextPropertyValidationMode vm);
268 void setRichTextDefaultFont(
const QFont &font) { m_richTextDefaultFont = font; }
269 QFont richTextDefaultFont()
const {
return m_richTextDefaultFont; }
271 void setSpacing(
int spacing);
273 TextPropertyEditor::UpdateMode updateMode()
const {
return m_editor->updateMode(); }
274 void setUpdateMode(TextPropertyEditor::UpdateMode um) { m_editor->setUpdateMode(um); }
276 void setIconThemeModeEnabled(
bool enable);
279 void setText(
const QString &text);
282 void textChanged(
const QString &text);
285 void buttonClicked();
286 void resourceActionActivated();
287 void fileActionActivated();
289 TextPropertyEditor *m_editor;
290 IconThemeEditor *m_themeEditor;
291 bool m_iconThemeModeEnabled;
292 QFont m_richTextDefaultFont;
293 QToolButton *m_button;
295 QAction *m_resourceAction;
296 QAction *m_fileAction;
297 QHBoxLayout *m_layout;
298 QDesignerFormEditorInterface *m_core;
301TextEditor::TextEditor(QDesignerFormEditorInterface *core, QWidget *parent) :
303 m_editor(
new TextPropertyEditor(
this)),
304 m_themeEditor(
new IconThemeEditor(
this,
false)),
305 m_iconThemeModeEnabled(
false),
306 m_richTextDefaultFont(QApplication::font()),
307 m_button(
new QToolButton(
this)),
308 m_menu(
new QMenu(
this)),
309 m_resourceAction(
new QAction(tr(
"Choose Resource..."),
this)),
310 m_fileAction(
new QAction(tr(
"Choose File..."),
this)),
311 m_layout(
new QHBoxLayout(
this)),
314 m_themeEditor->setVisible(
false);
315 m_button->setVisible(
false);
317 m_layout->addWidget(m_editor);
318 m_layout->addWidget(m_themeEditor);
319 m_button->setText(tr(
"..."));
320 m_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored);
321 m_button->setFixedWidth(20);
322 m_layout->addWidget(m_button);
323 m_layout->setContentsMargins(QMargins());
324 m_layout->setSpacing(0);
326 connect(m_resourceAction, &QAction::triggered,
this, &TextEditor::resourceActionActivated);
327 connect(m_fileAction, &QAction::triggered,
this, &TextEditor::fileActionActivated);
328 connect(m_editor, &TextPropertyEditor::textChanged,
this, &TextEditor::textChanged);
329 connect(m_themeEditor, &IconThemeEditor::edited,
this, &TextEditor::textChanged);
330 connect(m_button, &QAbstractButton::clicked,
this, &TextEditor::buttonClicked);
332 setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
333 setFocusProxy(m_editor);
335 m_menu->addAction(m_resourceAction);
336 m_menu->addAction(m_fileAction);
339void TextEditor::setSpacing(
int spacing)
341 m_layout->setSpacing(spacing);
344void TextEditor::setIconThemeModeEnabled(
bool enable)
346 if (m_iconThemeModeEnabled == enable)
348 m_iconThemeModeEnabled = enable;
349 m_editor->setVisible(!enable);
350 m_themeEditor->setVisible(enable);
352 m_themeEditor->setTheme(m_editor->text());
353 setFocusProxy(m_themeEditor);
355 m_editor->setText(m_themeEditor->theme());
356 setFocusProxy(m_editor);
360TextPropertyValidationMode TextEditor::textPropertyValidationMode()
const
362 return m_editor->textPropertyValidationMode();
365void TextEditor::setTextPropertyValidationMode(TextPropertyValidationMode vm)
367 m_editor->setTextPropertyValidationMode(vm);
368 if (vm == ValidationURL) {
369 m_button->setMenu(m_menu);
370 m_button->setFixedWidth(30);
371 m_button->setPopupMode(QToolButton::MenuButtonPopup);
373 m_button->setMenu(
nullptr);
374 m_button->setFixedWidth(20);
375 m_button->setPopupMode(QToolButton::DelayedPopup);
377 m_button->setVisible(vm == ValidationStyleSheet || vm == ValidationRichText || vm == ValidationMultiLine || vm == ValidationURL);
380void TextEditor::setText(
const QString &text)
382 if (m_iconThemeModeEnabled)
383 m_themeEditor->setTheme(text);
385 m_editor->setText(text);
388void TextEditor::buttonClicked()
390 const QString oldText = m_editor->text();
392 switch (textPropertyValidationMode()) {
393 case ValidationStyleSheet: {
394 StyleSheetEditorDialog dlg(m_core,
this);
395 dlg.setText(oldText);
396 if (dlg.exec() != QDialog::Accepted)
398 newText = dlg.text();
401 case ValidationRichText: {
402 RichTextEditorDialog dlg(m_core,
this);
403 dlg.setDefaultFont(m_richTextDefaultFont);
404 dlg.setText(oldText);
405 if (dlg.showDialog() != QDialog::Accepted)
407 newText = dlg.text(Qt::AutoText);
410 case ValidationMultiLine: {
411 PlainTextEditorDialog dlg(m_core,
this);
412 dlg.setDefaultFont(m_richTextDefaultFont);
413 dlg.setText(oldText);
414 if (dlg.showDialog() != QDialog::Accepted)
416 newText = dlg.text();
420 if (oldText.isEmpty() || oldText.startsWith(
"qrc:"_L1))
421 resourceActionActivated();
423 fileActionActivated();
428 if (newText != oldText) {
429 m_editor->setText(newText);
430 emit textChanged(newText);
434void TextEditor::resourceActionActivated()
436 QString oldPath = m_editor->text();
437 if (oldPath.startsWith(
"qrc:"_L1))
438 oldPath.remove(0, 4);
440 QString newPath = IconSelector::choosePixmapResource(m_core, m_core->resourceModel(), oldPath,
this);
441 if (newPath.startsWith(u':'))
442 newPath.remove(0, 1);
443 if (newPath.isEmpty() || newPath == oldPath)
445 const QString newText =
"qrc:"_L1 + newPath;
446 m_editor->setText(newText);
447 emit textChanged(newText);
450void TextEditor::fileActionActivated()
452 QString oldPath = m_editor->text();
453 if (oldPath.startsWith(
"file:"_L1))
454 oldPath = oldPath.mid(5);
455 const QString newPath = m_core->dialogGui()->getOpenFileName(
this, tr(
"Choose a File"), oldPath);
456 if (newPath.isEmpty() || newPath == oldPath)
458 const QString newText = QUrl::fromLocalFile(newPath).toString();
459 m_editor->setText(newText);
460 emit textChanged(newText);
464class ResetWidget :
public QWidget
468 ResetWidget(QtProperty *property, QWidget *parent =
nullptr);
470 void setWidget(QWidget *widget);
471 void setResetEnabled(
bool enabled);
472 void setValueText(
const QString &text);
473 void setValueIcon(
const QIcon &icon);
474 void setSpacing(
int spacing);
476 void resetProperty(QtProperty *property);
480 QtProperty *m_property;
483 QToolButton *m_button;
487ResetWidget::ResetWidget(QtProperty *property, QWidget *parent) :
489 m_property(property),
490 m_textLabel(
new QLabel(
this)),
491 m_iconLabel(
new QLabel(
this)),
492 m_button(
new QToolButton(
this)),
495 m_textLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed));
496 m_iconLabel->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
497 m_button->setToolButtonStyle(Qt::ToolButtonIconOnly);
498 m_button->setIcon(createIconSet(
"resetproperty.png"_L1));
499 m_button->setIconSize(QSize(8,8));
500 m_button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding));
501 connect(m_button, &QAbstractButton::clicked,
this, &ResetWidget::slotClicked);
502 QLayout *layout =
new QHBoxLayout(
this);
503 layout->setContentsMargins(QMargins());
504 layout->setSpacing(m_spacing);
505 layout->addWidget(m_iconLabel);
506 layout->addWidget(m_textLabel);
507 layout->addWidget(m_button);
508 setFocusProxy(m_textLabel);
509 setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
512void ResetWidget::setSpacing(
int spacing)
515 layout()->setSpacing(m_spacing);
518void ResetWidget::setWidget(QWidget *widget)
522 m_textLabel =
nullptr;
526 m_iconLabel =
nullptr;
529 QLayout *layout =
new QHBoxLayout(
this);
530 layout->setContentsMargins(QMargins());
531 layout->setSpacing(m_spacing);
532 layout->addWidget(widget);
533 layout->addWidget(m_button);
534 setFocusProxy(widget);
537void ResetWidget::setResetEnabled(
bool enabled)
539 m_button->setEnabled(enabled);
542void ResetWidget::setValueText(
const QString &text)
545 m_textLabel->setText(text);
548void ResetWidget::setValueIcon(
const QIcon &icon)
550 QPixmap pix = icon.pixmap(QSize(16, 16));
552 m_iconLabel->setVisible(!pix.isNull());
553 m_iconLabel->setPixmap(pix);
557void ResetWidget::slotClicked()
559 emit resetProperty(m_property);
565DesignerPropertyManager::DesignerPropertyManager(QDesignerFormEditorInterface *core, QObject *parent) :
566 QtVariantPropertyManager(parent),
567 m_changingSubValue(
false),
570 m_sourceOfChange(
nullptr)
572 connect(
this, &QtVariantPropertyManager::valueChanged,
573 this, &DesignerPropertyManager::slotValueChanged);
574 connect(
this, & QtAbstractPropertyManager::propertyDestroyed,
575 this, &DesignerPropertyManager::slotPropertyDestroyed);
578DesignerPropertyManager::~DesignerPropertyManager()
583bool DesignerPropertyManager::m_IdBasedTranslations =
false;
586static int bitCount(IntT mask)
589 for (; mask; count++)
594int DesignerPropertyManager::alignToIndexH(uint align)
const
596 if (align & Qt::AlignLeft)
598 if (align & Qt::AlignHCenter)
600 if (align & Qt::AlignRight)
602 if (align & Qt::AlignJustify)
607int DesignerPropertyManager::alignToIndexV(uint align)
const
609 if (align & Qt::AlignTop)
611 if (align & Qt::AlignVCenter)
613 if (align & Qt::AlignBottom)
618uint DesignerPropertyManager::indexHToAlign(
int idx)
const
621 case 0:
return Qt::AlignLeft;
622 case 1:
return Qt::AlignHCenter;
623 case 2:
return Qt::AlignRight;
624 case 3:
return Qt::AlignJustify;
627 return Qt::AlignLeft;
630uint DesignerPropertyManager::indexVToAlign(
int idx)
const
633 case 0:
return Qt::AlignTop;
634 case 1:
return Qt::AlignVCenter;
635 case 2:
return Qt::AlignBottom;
638 return Qt::AlignVCenter;
641QString DesignerPropertyManager::indexHToString(
int idx)
const
644 case 0:
return tr(
"AlignLeft");
645 case 1:
return tr(
"AlignHCenter");
646 case 2:
return tr(
"AlignRight");
647 case 3:
return tr(
"AlignJustify");
650 return tr(
"AlignLeft");
653QString DesignerPropertyManager::indexVToString(
int idx)
const
656 case 0:
return tr(
"AlignTop");
657 case 1:
return tr(
"AlignVCenter");
658 case 2:
return tr(
"AlignBottom");
661 return tr(
"AlignVCenter");
664void DesignerPropertyManager::slotValueChanged(QtProperty *property,
const QVariant &value)
666 if (m_changingSubValue)
668 bool enableSubPropertyHandling =
true;
671 int subResult = m_stringManager.valueChanged(
this, property, value);
672 if (subResult == NoMatch)
673 subResult = m_keySequenceManager.valueChanged(
this, property, value);
674 if (subResult == NoMatch)
675 subResult = m_stringListManager.valueChanged(
this, property, value);
676 if (subResult == NoMatch)
677 subResult = m_brushManager.valueChanged(
this, property, value);
678 if (subResult == NoMatch)
679 subResult = m_fontManager.valueChanged(
this, property, value);
680 if (subResult != NoMatch) {
681 if (subResult == Changed)
682 emit valueChanged(property, value, enableSubPropertyHandling);
686 if (QtProperty *flagProperty = m_flagToProperty.value(property, 0)) {
687 const auto subFlags = m_propertyToFlags.value(flagProperty);
688 const qsizetype subFlagCount = subFlags.size();
690 const bool subValue = variantProperty(property)->value().toBool();
691 const qsizetype subIndex = subFlags.indexOf(property);
697 m_changingSubValue =
true;
699 FlagData data = m_flagValues.value(flagProperty);
700 const auto values = data.values;
702 if (values.at(subIndex) == 0) {
703 for (qsizetype i = 0; i < subFlagCount; ++i) {
704 QtVariantProperty *subFlag = variantProperty(subFlags.at(i));
705 subFlag->setValue(i == subIndex);
709 newValue = values.at(subIndex);
710 for (qsizetype i = 0; i < subFlagCount; ++i) {
711 QtVariantProperty *subFlag = variantProperty(subFlags.at(i));
712 if (subFlag->value().toBool() && bitCount(values.at(i)) == 1)
713 newValue |= values.at(i);
717 for (qsizetype i = 0; i < subFlagCount; ++i) {
718 QtVariantProperty *subFlag = variantProperty(subFlags.at(i));
719 subFlag->setValue(values.at(i) == 0);
721 }
else if (newValue == data.val) {
722 if (!subValue && bitCount(values.at(subIndex)) > 1) {
724 variantProperty(property)->setValue(
true);
728 for (qsizetype i = 0; i < subFlagCount; ++i) {
729 QtVariantProperty *subFlag = variantProperty(subFlags.at(i));
730 if (values.at(i) == 0)
731 subFlag->setValue(
false);
736 for (qsizetype i = 0; i < subFlagCount; ++i) {
737 QtVariantProperty *subFlag = variantProperty(subFlags.at(i));
738 const uint vi = values.at(i);
739 if ((vi != 0) && ((vi & newValue) == vi) && !subFlag->value().toBool())
740 subFlag->setValue(
true);
744 for (qsizetype i = 0; i < subFlagCount; ++i) {
745 QtVariantProperty *subFlag = variantProperty(subFlags.at(i));
746 const uint vi = values.at(i);
747 if (subFlag->value().toBool() && ((vi & newValue) != vi))
748 subFlag->setValue(
false);
753 m_changingSubValue =
false;
756 v.setValue(data.val);
757 variantProperty(flagProperty)->setValue(v);
758 }
else if (QtProperty *alignProperty = m_alignHToProperty.value(property, 0)) {
759 const uint v = m_alignValues.value(alignProperty);
760 const uint newValue = indexHToAlign(value.toInt()) | indexVToAlign(alignToIndexV(v));
764 variantProperty(alignProperty)->setValue(newValue);
765 }
else if (QtProperty *alignProperty = m_alignVToProperty.value(property, 0)) {
766 const uint v = m_alignValues.value(alignProperty);
767 const uint newValue = indexVToAlign(value.toInt()) | indexHToAlign(alignToIndexH(v));
771 variantProperty(alignProperty)->setValue(newValue);
772 }
else if (QtProperty *iProperty = m_iconSubPropertyToProperty.value(property, 0)) {
773 QtVariantProperty *iconProperty = variantProperty(iProperty);
774 PropertySheetIconValue icon = qvariant_cast<PropertySheetIconValue>(iconProperty->value());
775 const auto itState = m_iconSubPropertyToState.constFind(property);
776 if (itState != m_iconSubPropertyToState.constEnd()) {
777 const auto pair = m_iconSubPropertyToState.value(property);
778 icon.setPixmap(pair.first, pair.second, qvariant_cast<PropertySheetPixmapValue>(value));
779 }
else if (attributeValue(property, themeEnumAttributeC).toBool()) {
780 icon.setThemeEnum(value.toInt());
782 icon.setTheme(value.toString());
784 QtProperty *origSourceOfChange = m_sourceOfChange;
785 if (!origSourceOfChange)
786 m_sourceOfChange = property;
787 iconProperty->setValue(QVariant::fromValue(icon));
788 if (!origSourceOfChange)
789 m_sourceOfChange = origSourceOfChange;
790 }
else if (m_iconValues.contains(property)) {
791 enableSubPropertyHandling = m_sourceOfChange;
793 emit valueChanged(property, value, enableSubPropertyHandling);
796void DesignerPropertyManager::slotPropertyDestroyed(QtProperty *property)
798 if (QtProperty *flagProperty = m_flagToProperty.value(property, 0)) {
799 const auto it = m_propertyToFlags.find(flagProperty);
800 auto &propertyList = it.value();
801 propertyList.replace(propertyList.indexOf(property), 0);
802 m_flagToProperty.remove(property);
803 }
else if (QtProperty *alignProperty = m_alignHToProperty.value(property, 0)) {
804 m_propertyToAlignH.remove(alignProperty);
805 m_alignHToProperty.remove(property);
806 }
else if (QtProperty *alignProperty = m_alignVToProperty.value(property, 0)) {
807 m_propertyToAlignV.remove(alignProperty);
808 m_alignVToProperty.remove(property);
809 }
else if (m_stringManager.destroy(property)
810 || m_stringListManager.destroy(property)
811 || m_keySequenceManager.destroy(property)) {
812 }
else if (QtProperty *iconProperty = m_iconSubPropertyToProperty.value(property, 0)) {
813 if (m_propertyToTheme.value(iconProperty) == property) {
814 m_propertyToTheme.remove(iconProperty);
815 }
else if (m_propertyToThemeEnum.value(iconProperty) == property) {
816 m_propertyToThemeEnum.remove(iconProperty);
818 const auto it = m_propertyToIconSubProperties.find(iconProperty);
819 const auto state = m_iconSubPropertyToState.value(property);
820 auto &propertyList = it.value();
821 propertyList.remove(state);
822 m_iconSubPropertyToState.remove(property);
824 m_iconSubPropertyToProperty.remove(property);
826 m_fontManager.slotPropertyDestroyed(property);
827 m_brushManager.slotPropertyDestroyed(property);
829 m_alignDefault.remove(property);
832QStringList DesignerPropertyManager::attributes(
int propertyType)
const
834 if (!isPropertyTypeSupported(propertyType))
835 return QStringList();
837 QStringList list = QtVariantPropertyManager::attributes(propertyType);
838 if (propertyType == designerFlagTypeId()) {
839 list.append(flagsAttributeC);
840 }
else if (propertyType == designerPixmapTypeId()) {
841 list.append(defaultResourceAttributeC);
842 }
else if (propertyType == designerIconTypeId()) {
843 list.append(defaultResourceAttributeC);
844 }
else if (propertyType == designerStringTypeId() || propertyType == QMetaType::QString) {
845 list.append(validationModesAttributeC);
846 list.append(fontAttributeC);
847 list.append(themeAttributeC);
848 }
else if (propertyType == QMetaType::QPalette) {
849 list.append(superPaletteAttributeC);
850 }
else if (propertyType == QMetaType::Int) {
851 list.append(themeEnumAttributeC);
853 list.append(resettableAttributeC);
857int DesignerPropertyManager::attributeType(
int propertyType,
const QString &attribute)
const
859 if (!isPropertyTypeSupported(propertyType))
862 if (propertyType == designerFlagTypeId() && attribute == flagsAttributeC)
863 return designerFlagListTypeId();
864 if (propertyType == designerPixmapTypeId() && attribute == defaultResourceAttributeC)
865 return QMetaType::QPixmap;
866 if (propertyType == designerIconTypeId() && attribute == defaultResourceAttributeC)
867 return QMetaType::QIcon;
868 if (attribute == resettableAttributeC)
869 return QMetaType::Bool;
870 if (propertyType == designerStringTypeId() || propertyType == QMetaType::QString) {
871 if (attribute == validationModesAttributeC)
872 return QMetaType::Int;
873 if (attribute == fontAttributeC)
874 return QMetaType::QFont;
875 if (attribute == themeAttributeC)
876 return QMetaType::Bool;
878 if (propertyType == QMetaType::QPalette && attribute == superPaletteAttributeC)
879 return QMetaType::QPalette;
881 return QtVariantPropertyManager::attributeType(propertyType, attribute);
884QVariant DesignerPropertyManager::attributeValue(
const QtProperty *property,
const QString &attribute)
const
886 if (attribute == resettableAttributeC) {
887 const auto it = m_resetMap.constFind(property);
888 if (it != m_resetMap.constEnd())
892 if (attribute == flagsAttributeC) {
893 const auto it = m_flagValues.constFind(property);
894 if (it != m_flagValues.constEnd()) {
896 v.setValue(it.value().flags);
900 if (attribute == validationModesAttributeC) {
901 const auto it = m_stringAttributes.constFind(property);
902 if (it != m_stringAttributes.constEnd())
906 if (attribute == fontAttributeC) {
907 const auto it = m_stringFontAttributes.constFind(property);
908 if (it != m_stringFontAttributes.constEnd())
912 if (attribute == themeAttributeC) {
913 const auto it = m_stringThemeAttributes.constFind(property);
914 if (it != m_stringThemeAttributes.constEnd())
918 if (attribute == themeEnumAttributeC) {
919 const auto it = m_intThemeEnumAttributes.constFind(property);
920 if (it != m_intThemeEnumAttributes.constEnd())
924 if (attribute == superPaletteAttributeC) {
925 const auto it = m_paletteValues.constFind(property);
926 if (it != m_paletteValues.cend())
927 return it.value().superPalette;
930 if (attribute == defaultResourceAttributeC) {
931 const auto itPix = m_defaultPixmaps.constFind(property);
932 if (itPix != m_defaultPixmaps.constEnd())
933 return itPix.value();
935 const auto itIcon = m_defaultIcons.constFind(property);
936 if (itIcon != m_defaultIcons.constEnd())
937 return itIcon.value();
940 if (attribute == alignDefaultAttribute()) {
941 Qt::Alignment v = m_alignDefault.value(property,
942 Qt::Alignment(Qt::AlignLeading | Qt::AlignHCenter));
943 return QVariant(uint(v));
946 return QtVariantPropertyManager::attributeValue(property, attribute);
949void DesignerPropertyManager::setAttribute(QtProperty *property,
950 const QString &attribute,
const QVariant &value)
952 if (attribute == resettableAttributeC && m_resetMap.contains(property)) {
953 if (value.userType() != QMetaType::Bool)
955 const bool val = value.toBool();
956 const auto it = m_resetMap.find(property);
957 if (it.value() == val)
960 emit attributeChanged(variantProperty(property), attribute, value);
963 if (attribute == flagsAttributeC && m_flagValues.contains(property)) {
964 if (value.userType() != designerFlagListTypeId())
967 const DesignerFlagList flags = qvariant_cast<DesignerFlagList>(value);
968 const auto fit = m_flagValues.find(property);
969 FlagData data = fit.value();
970 if (data.flags == flags)
973 const auto pfit = m_propertyToFlags.find(property);
974 for (QtProperty *prop : std::as_const(pfit.value())) {
977 m_flagToProperty.remove(prop);
980 pfit.value().clear();
984 for (
const auto &pair : flags) {
985 const QString flagName = pair.first;
986 QtProperty *prop = addProperty(QMetaType::Bool);
987 prop->setPropertyName(flagName);
988 property->addSubProperty(prop);
989 m_propertyToFlags[property].append(prop);
990 m_flagToProperty[prop] = property;
991 values.append(pair.second);
996 data.values = values;
1002 emit attributeChanged(property, attribute, v);
1004 emit propertyChanged(property);
1005 emit QtVariantPropertyManager::valueChanged(property, data.val);
1006 }
else if (attribute == validationModesAttributeC && m_stringAttributes.contains(property)) {
1007 if (value.userType() != QMetaType::Int)
1010 const auto it = m_stringAttributes.find(property);
1011 const int oldValue = it.value();
1013 const int newValue = value.toInt();
1015 if (oldValue == newValue)
1018 it.value() = newValue;
1020 emit attributeChanged(property, attribute, newValue);
1021 }
else if (attribute == fontAttributeC && m_stringFontAttributes.contains(property)) {
1022 if (value.userType() != QMetaType::QFont)
1025 const auto it = m_stringFontAttributes.find(property);
1026 const QFont oldValue = it.value();
1028 const QFont newValue = qvariant_cast<QFont>(value);
1030 if (oldValue == newValue)
1033 it.value() = newValue;
1035 emit attributeChanged(property, attribute, newValue);
1036 }
else if (attribute == themeAttributeC && m_stringThemeAttributes.contains(property)) {
1037 if (value.userType() != QMetaType::Bool)
1040 const auto it = m_stringThemeAttributes.find(property);
1041 const bool oldValue = it.value();
1043 const bool newValue = value.toBool();
1045 if (oldValue == newValue)
1048 it.value() = newValue;
1050 emit attributeChanged(property, attribute, newValue);
1051 }
else if (attribute == themeEnumAttributeC && m_intThemeEnumAttributes.contains(property)) {
1052 if (value.userType() != QMetaType::Bool)
1055 const auto it = m_intThemeEnumAttributes.find(property);
1056 const bool oldValue = it.value();
1058 const bool newValue = value.toBool();
1060 if (oldValue == newValue)
1063 it.value() = newValue;
1065 emit attributeChanged(property, attribute, newValue);
1066 }
else if (attribute == superPaletteAttributeC && m_paletteValues.contains(property)) {
1067 if (value.userType() != QMetaType::QPalette)
1070 QPalette superPalette = qvariant_cast<QPalette>(value);
1072 const auto it = m_paletteValues.find(property);
1073 PaletteData data = it.value();
1074 if (data.superPalette == superPalette)
1077 data.superPalette = superPalette;
1079 const auto mask = data.val.resolveMask();
1080 data.val = data.val.resolve(superPalette);
1081 data.val.setResolveMask(mask);
1086 v.setValue(superPalette);
1087 emit attributeChanged(property, attribute, v);
1089 emit propertyChanged(property);
1090 emit QtVariantPropertyManager::valueChanged(property, data.val);
1091 }
else if (attribute == defaultResourceAttributeC && m_defaultPixmaps.contains(property)) {
1092 if (value.userType() != QMetaType::QPixmap)
1095 QPixmap defaultPixmap = qvariant_cast<QPixmap>(value);
1097 const auto it = m_defaultPixmaps.find(property);
1098 QPixmap oldDefaultPixmap = it.value();
1099 if (defaultPixmap.cacheKey() == oldDefaultPixmap.cacheKey())
1102 it.value() = defaultPixmap;
1104 QVariant v = QVariant::fromValue(defaultPixmap);
1105 emit attributeChanged(property, attribute, v);
1107 emit propertyChanged(property);
1108 }
else if (attribute == defaultResourceAttributeC && m_defaultIcons.contains(property)) {
1109 if (value.userType() != QMetaType::QIcon)
1112 QIcon defaultIcon = qvariant_cast<QIcon>(value);
1114 const auto it = m_defaultIcons.find(property);
1115 QIcon oldDefaultIcon = it.value();
1116 if (defaultIcon.cacheKey() == oldDefaultIcon.cacheKey())
1119 it.value() = defaultIcon;
1121 qdesigner_internal::PropertySheetIconValue icon = m_iconValues.value(property);
1122 if (icon.paths().isEmpty()) {
1123 const auto &subIconProperties = m_propertyToIconSubProperties.value(property);
1124 for (
auto itSub = subIconProperties.cbegin(), end = subIconProperties.cend(); itSub != end; ++itSub) {
1125 const auto pair = itSub.key();
1126 QtProperty *subProp = itSub.value();
1127 setAttribute(subProp, defaultResourceAttributeC,
1128 defaultIcon.pixmap(16, 16, pair.first, pair.second));
1132 QVariant v = QVariant::fromValue(defaultIcon);
1133 emit attributeChanged(property, attribute, v);
1135 emit propertyChanged(property);
1136 }
else if (attribute == alignDefaultAttribute()) {
1137 m_alignDefault[property] = Qt::Alignment(value.toUInt());
1139 QtVariantPropertyManager::setAttribute(property, attribute, value);
1142int DesignerPropertyManager::designerFlagTypeId()
1144 static const int rc = qMetaTypeId<DesignerFlagPropertyType>();
1148int DesignerPropertyManager::designerFlagListTypeId()
1150 static const int rc = qMetaTypeId<DesignerFlagList>();
1154int DesignerPropertyManager::designerAlignmentTypeId()
1156 static const int rc = qMetaTypeId<DesignerAlignmentPropertyType>();
1160int DesignerPropertyManager::designerPixmapTypeId()
1162 return qMetaTypeId<PropertySheetPixmapValue>();
1165int DesignerPropertyManager::designerIconTypeId()
1167 return qMetaTypeId<PropertySheetIconValue>();
1170int DesignerPropertyManager::designerStringTypeId()
1172 return qMetaTypeId<PropertySheetStringValue>();
1175int DesignerPropertyManager::designerStringListTypeId()
1177 return qMetaTypeId<PropertySheetStringListValue>();
1180int DesignerPropertyManager::designerKeySequenceTypeId()
1182 return qMetaTypeId<PropertySheetKeySequenceValue>();
1185QString DesignerPropertyManager::alignDefaultAttribute()
1187 return u"alignDefault"_s;
1190uint DesignerPropertyManager::alignDefault(
const QtVariantProperty *prop)
1192 return prop->attributeValue(DesignerPropertyManager::alignDefaultAttribute()).toUInt();
1195bool DesignerPropertyManager::isPropertyTypeSupported(
int propertyType)
const
1197 switch (propertyType) {
1198 case QMetaType::QPalette:
1199 case QMetaType::UInt:
1200 case QMetaType::LongLong:
1201 case QMetaType::ULongLong:
1202 case QMetaType::QUrl:
1203 case QMetaType::QByteArray:
1204 case QMetaType::QStringList:
1205 case QMetaType::QBrush:
1211 if (propertyType == designerFlagTypeId())
1213 if (propertyType == designerAlignmentTypeId())
1215 if (propertyType == designerPixmapTypeId())
1217 if (propertyType == designerIconTypeId())
1219 if (propertyType == designerStringTypeId() || propertyType == designerStringListTypeId())
1221 if (propertyType == designerKeySequenceTypeId())
1224 return QtVariantPropertyManager::isPropertyTypeSupported(propertyType);
1227QString DesignerPropertyManager::valueText(
const QtProperty *property)
const
1229 if (m_flagValues.contains(property)) {
1230 const FlagData data = m_flagValues.value(property);
1231 const uint v = data.val;
1233 for (
const DesignerIntPair &p : data.flags) {
1234 const uint val = p.second;
1235 const bool checked = (val == 0) ? (v == 0) : ((val & v) == val);
1237 if (!valueStr.isEmpty())
1239 valueStr += p.first;
1244 if (m_alignValues.contains(property)) {
1245 const uint v = m_alignValues.value(property);
1246 return tr(
"%1, %2").arg(indexHToString(alignToIndexH(v)),
1247 indexVToString(alignToIndexV(v)));
1249 if (m_paletteValues.contains(property)) {
1250 const PaletteData data = m_paletteValues.value(property);
1251 const auto mask = data.val.resolveMask();
1253 return tr(
"Customized (%n roles)",
nullptr, bitCount(mask));
1254 static const QString inherited = tr(
"Inherited");
1257 if (m_iconValues.contains(property))
1258 return PixmapEditor::displayText(m_iconValues.value(property));
1259 if (m_pixmapValues.contains(property)) {
1260 const QString path = m_pixmapValues.value(property).path();
1263 return QFileInfo(path).fileName();
1265 if (m_intValues.contains(property)) {
1266 const auto value = m_intValues.value(property);
1267 if (m_intThemeEnumAttributes.value(property))
1268 return IconThemeEnumEditor::iconName(value);
1269 return QString::number(value);
1271 if (m_uintValues.contains(property))
1272 return QString::number(m_uintValues.value(property));
1273 if (m_longLongValues.contains(property))
1274 return QString::number(m_longLongValues.value(property));
1275 if (m_uLongLongValues.contains(property))
1276 return QString::number(m_uLongLongValues.value(property));
1277 if (m_urlValues.contains(property))
1278 return m_urlValues.value(property).toString();
1279 if (m_byteArrayValues.contains(property))
1280 return QString::fromUtf8(m_byteArrayValues.value(property));
1281 const int vType = QtVariantPropertyManager::valueType(property);
1282 if (vType == QMetaType::QString || vType == designerStringTypeId()) {
1283 const QString str = (QtVariantPropertyManager::valueType(property) == QMetaType::QString)
1284 ? value(property).toString() : qvariant_cast<PropertySheetStringValue>(value(property)).value();
1285 const int validationMode = attributeValue(property, validationModesAttributeC).toInt();
1286 return TextPropertyEditor::stringToEditorString(str,
static_cast<TextPropertyValidationMode>(validationMode));
1288 if (vType == QMetaType::QStringList || vType == designerStringListTypeId()) {
1289 QVariant v = value(property);
1290 const QStringList list = v.metaType().id() == QMetaType::QStringList
1291 ? v.toStringList() : qvariant_cast<PropertySheetStringListValue>(v).value();
1292 return list.join(
"; "_L1);
1294 if (vType == designerKeySequenceTypeId()) {
1295 return qvariant_cast<PropertySheetKeySequenceValue>(value(property)).value().toString(QKeySequence::NativeText);
1297 if (vType == QMetaType::Bool) {
1302 if (m_brushManager.valueText(property, &rc))
1304 return QtVariantPropertyManager::valueText(property);
1307void DesignerPropertyManager::reloadResourceProperties()
1309 DesignerIconCache *iconCache =
nullptr;
1310 for (
auto itIcon = m_iconValues.cbegin(), end = m_iconValues.cend(); itIcon!= end; ++itIcon) {
1311 auto *property = itIcon.key();
1312 const PropertySheetIconValue &icon = itIcon.value();
1314 QIcon defaultIcon = m_defaultIcons.value(property);
1315 if (!icon.paths().isEmpty()) {
1317 QDesignerFormWindowInterface *formWindow = QDesignerFormWindowInterface::findFormWindow(m_object);
1318 qdesigner_internal::FormWindowBase *fwb = qobject_cast<qdesigner_internal::FormWindowBase *>(formWindow);
1319 iconCache = fwb->iconCache();
1322 defaultIcon = iconCache->icon(icon);
1325 const auto &subProperties = m_propertyToIconSubProperties.value(property);
1326 for (
auto itSub = subProperties.cbegin(), end = subProperties.cend(); itSub != end; ++itSub) {
1327 const auto pair = itSub.key();
1328 QtVariantProperty *subProperty = variantProperty(itSub.value());
1329 subProperty->setAttribute(defaultResourceAttributeC,
1330 defaultIcon.pixmap(16, 16, pair.first, pair.second));
1333 auto *ncProperty =
const_cast<QtProperty *>(property);
1334 emit propertyChanged(ncProperty);
1335 emit QtVariantPropertyManager::valueChanged(ncProperty, QVariant::fromValue(itIcon.value()));
1337 for (
auto itPix = m_pixmapValues.cbegin(), end = m_pixmapValues.cend(); itPix != end; ++itPix) {
1338 auto *property =
const_cast<QtProperty *>(itPix.key());
1339 emit propertyChanged(property);
1340 emit QtVariantPropertyManager::valueChanged(property, QVariant::fromValue(itPix.value()));
1344QIcon DesignerPropertyManager::valueIcon(
const QtProperty *property)
const
1346 if (m_iconValues.contains(property)) {
1347 if (!property->isModified())
1348 return m_defaultIcons.value(property).pixmap(16, 16);
1349 QDesignerFormWindowInterface *formWindow = QDesignerFormWindowInterface::findFormWindow(m_object);
1350 qdesigner_internal::FormWindowBase *fwb = qobject_cast<qdesigner_internal::FormWindowBase *>(formWindow);
1352 return fwb->iconCache()->icon(m_iconValues.value(property)).pixmap(16, 16);
1353 }
else if (m_pixmapValues.contains(property)) {
1354 if (!property->isModified())
1355 return m_defaultPixmaps.value(property);
1356 QDesignerFormWindowInterface *formWindow = QDesignerFormWindowInterface::findFormWindow(m_object);
1357 qdesigner_internal::FormWindowBase *fwb = qobject_cast<qdesigner_internal::FormWindowBase *>(formWindow);
1359 return fwb->pixmapCache()->pixmap(m_pixmapValues.value(property));
1360 }
else if (m_stringThemeAttributes.value(property,
false)) {
1361 return QIcon::fromTheme(value(property).toString());
1364 if (m_brushManager.valueIcon(property, &rc))
1368 return QtVariantPropertyManager::valueIcon(property);
1371QVariant DesignerPropertyManager::value(
const QtProperty *property)
const
1373 if (m_flagValues.contains(property))
1374 return m_flagValues.value(property).val;
1375 if (m_alignValues.contains(property))
1376 return m_alignValues.value(property);
1377 if (m_paletteValues.contains(property))
1378 return m_paletteValues.value(property).val;
1379 if (m_iconValues.contains(property))
1380 return QVariant::fromValue(m_iconValues.value(property));
1381 if (m_pixmapValues.contains(property))
1382 return QVariant::fromValue(m_pixmapValues.value(property));
1384 if (m_stringManager.value(property, &rc)
1385 || m_keySequenceManager.value(property, &rc)
1386 || m_stringListManager.value(property, &rc)
1387 || m_brushManager.value(property, &rc))
1389 if (m_intValues.contains(property))
1390 return m_intValues.value(property);
1391 if (m_uintValues.contains(property))
1392 return m_uintValues.value(property);
1393 if (m_longLongValues.contains(property))
1394 return m_longLongValues.value(property);
1395 if (m_uLongLongValues.contains(property))
1396 return m_uLongLongValues.value(property);
1397 if (m_urlValues.contains(property))
1398 return m_urlValues.value(property);
1399 if (m_byteArrayValues.contains(property))
1400 return m_byteArrayValues.value(property);
1402 return QtVariantPropertyManager::value(property);
1405int DesignerPropertyManager::valueType(
int propertyType)
const
1407 switch (propertyType) {
1408 case QMetaType::QPalette:
1409 case QMetaType::UInt:
1410 case QMetaType::LongLong:
1411 case QMetaType::ULongLong:
1412 case QMetaType::QUrl:
1413 case QMetaType::QByteArray:
1414 case QMetaType::QStringList:
1415 case QMetaType::QBrush:
1416 return propertyType;
1420 if (propertyType == designerFlagTypeId())
1421 return QMetaType::UInt;
1422 if (propertyType == designerAlignmentTypeId())
1423 return QMetaType::UInt;
1424 if (propertyType == designerPixmapTypeId())
1425 return propertyType;
1426 if (propertyType == designerIconTypeId())
1427 return propertyType;
1428 if (propertyType == designerStringTypeId() || propertyType == designerStringListTypeId())
1429 return propertyType;
1430 if (propertyType == designerKeySequenceTypeId())
1431 return propertyType;
1432 return QtVariantPropertyManager::valueType(propertyType);
1435void DesignerPropertyManager::setValue(QtProperty *property,
const QVariant &value)
1437 int subResult = m_stringManager.setValue(
this, property, designerStringTypeId(), value);
1438 if (subResult == NoMatch)
1439 subResult = m_stringListManager.setValue(
this, property, designerStringListTypeId(), value);
1440 if (subResult == NoMatch)
1441 subResult = m_keySequenceManager.setValue(
this, property, designerKeySequenceTypeId(), value);
1442 if (subResult == NoMatch)
1443 subResult = m_brushManager.setValue(
this, property, value);
1444 if (subResult != NoMatch) {
1445 if (subResult == Changed) {
1446 emit QtVariantPropertyManager::valueChanged(property, value);
1447 emit propertyChanged(property);
1452 const auto fit = m_flagValues.find(property);
1454 if (fit != m_flagValues.end()) {
1455 if (value.metaType().id() != QMetaType::UInt && !value.canConvert<uint>())
1458 const uint v = value.toUInt();
1460 FlagData data = fit.value();
1466 const auto values = data.values;
1467 const auto subFlags = m_propertyToFlags.value(property);
1468 const qsizetype subFlagCount = subFlags.size();
1469 for (qsizetype i = 0; i < subFlagCount; ++i) {
1470 QtVariantProperty *subFlag = variantProperty(subFlags.at(i));
1471 const uint val = values.at(i);
1472 const bool checked = (val == 0) ? (v == 0) : ((val & v) == val);
1473 subFlag->setValue(checked);
1476 for (qsizetype i = 0; i < subFlagCount; ++i) {
1477 QtVariantProperty *subFlag = variantProperty(subFlags.at(i));
1478 const uint val = values.at(i);
1479 const bool checked = (val == 0) ? (v == 0) : ((val & v) == val);
1480 bool enabled =
true;
1484 }
else if (bitCount(val) > 1) {
1486 uint currentMask = 0;
1487 for (qsizetype j = 0; j < subFlagCount; ++j) {
1488 QtVariantProperty *subFlag = variantProperty(subFlags.at(j));
1489 if (bitCount(values.at(j)) == 1)
1490 currentMask |= subFlag->value().toBool() ? values.at(j) : 0;
1492 if ((currentMask & values.at(i)) == values.at(i))
1495 subFlag->setEnabled(enabled);
1501 emit QtVariantPropertyManager::valueChanged(property, data.val);
1502 emit propertyChanged(property);
1506 if (m_alignValues.contains(property)) {
1507 if (value.metaType().id() != QMetaType::UInt && !value.canConvert<uint>())
1510 const uint v = value.toUInt();
1512 uint val = m_alignValues.value(property);
1517 QtVariantProperty *alignH = variantProperty(m_propertyToAlignH.value(property));
1518 QtVariantProperty *alignV = variantProperty(m_propertyToAlignV.value(property));
1521 alignH->setValue(alignToIndexH(v));
1523 alignV->setValue(alignToIndexV(v));
1525 m_alignValues[property] = v;
1527 emit QtVariantPropertyManager::valueChanged(property, v);
1528 emit propertyChanged(property);
1532 if (m_paletteValues.contains(property)) {
1533 if (value.metaType().id() != QMetaType::QPalette && !value.canConvert<QPalette>())
1536 QPalette p = qvariant_cast<QPalette>(value);
1538 PaletteData data = m_paletteValues.value(property);
1540 const auto mask = p.resolveMask();
1541 p = p.resolve(data.superPalette);
1542 p.setResolveMask(mask);
1544 if (data.val == p && data.val.resolveMask() == p.resolveMask())
1548 m_paletteValues[property] = data;
1550 emit QtVariantPropertyManager::valueChanged(property, data.val);
1551 emit propertyChanged(property);
1555 if (m_iconValues.contains(property)) {
1556 if (value.userType() != designerIconTypeId())
1559 const PropertySheetIconValue icon = qvariant_cast<PropertySheetIconValue>(value);
1561 const PropertySheetIconValue oldIcon = m_iconValues.value(property);
1562 if (icon == oldIcon)
1565 m_iconValues[property] = icon;
1567 QIcon defaultIcon = m_defaultIcons.value(property);
1568 if (!icon.paths().isEmpty()) {
1569 QDesignerFormWindowInterface *formWindow = QDesignerFormWindowInterface::findFormWindow(m_object);
1570 qdesigner_internal::FormWindowBase *fwb = qobject_cast<qdesigner_internal::FormWindowBase *>(formWindow);
1572 defaultIcon = fwb->iconCache()->icon(icon);
1575 const auto &iconPaths = icon.paths();
1577 const auto &subProperties = m_propertyToIconSubProperties.value(property);
1578 for (
auto itSub = subProperties.cbegin(), end = subProperties.cend(); itSub != end; ++itSub) {
1579 const auto pair = itSub.key();
1580 QtVariantProperty *subProperty = variantProperty(itSub.value());
1581 bool hasPath = iconPaths.contains(pair);
1582 subProperty->setModified(hasPath);
1583 subProperty->setValue(QVariant::fromValue(iconPaths.value(pair)));
1584 subProperty->setAttribute(defaultResourceAttributeC,
1585 defaultIcon.pixmap(16, 16, pair.first, pair.second));
1587 QtVariantProperty *themeSubProperty = variantProperty(m_propertyToTheme.value(property));
1588 if (themeSubProperty) {
1589 const QString theme = icon.theme();
1590 themeSubProperty->setModified(!theme.isEmpty());
1591 themeSubProperty->setValue(theme);
1593 QtVariantProperty *themeEnumSubProperty = variantProperty(m_propertyToThemeEnum.value(property));
1594 if (themeEnumSubProperty) {
1595 const int themeEnum = icon.themeEnum();
1596 themeEnumSubProperty->setModified(themeEnum != -1);
1597 themeEnumSubProperty->setValue(QVariant(themeEnum));
1600 emit QtVariantPropertyManager::valueChanged(property, QVariant::fromValue(icon));
1601 emit propertyChanged(property);
1604 const auto itNormalOff = iconPaths.constFind({QIcon::Normal, QIcon::Off});
1605 if (itNormalOff != iconPaths.constEnd())
1606 toolTip = itNormalOff.value().path();
1608 property->setToolTip(QDir::toNativeSeparators(toolTip));
1612 if (m_pixmapValues.contains(property)) {
1613 if (value.userType() != designerPixmapTypeId())
1616 const PropertySheetPixmapValue pixmap = qvariant_cast<PropertySheetPixmapValue>(value);
1618 const PropertySheetPixmapValue oldPixmap = m_pixmapValues.value(property);
1619 if (pixmap == oldPixmap)
1622 m_pixmapValues[property] = pixmap;
1624 emit QtVariantPropertyManager::valueChanged(property, QVariant::fromValue(pixmap));
1625 emit propertyChanged(property);
1628 property->setToolTip(QDir::toNativeSeparators(pixmap.path()));
1632 if (m_intValues.contains(property)) {
1633 if (value.metaType().id() != QMetaType::Int && !value.canConvert<
int>())
1636 const int v = value.toInt(
nullptr);
1638 const int oldValue = m_intValues.value(property);
1642 m_intValues[property] = v;
1644 emit QtVariantPropertyManager::valueChanged(property, v);
1645 emit propertyChanged(property);
1649 if (m_uintValues.contains(property)) {
1650 if (value.metaType().id() != QMetaType::UInt && !value.canConvert<uint>())
1653 const uint v = value.toUInt(
nullptr);
1655 const uint oldValue = m_uintValues.value(property);
1659 m_uintValues[property] = v;
1661 emit QtVariantPropertyManager::valueChanged(property, v);
1662 emit propertyChanged(property);
1666 if (m_longLongValues.contains(property)) {
1667 if (value.metaType().id() != QMetaType::LongLong && !value.canConvert<qlonglong>())
1670 const qlonglong v = value.toLongLong(
nullptr);
1672 const qlonglong oldValue = m_longLongValues.value(property);
1676 m_longLongValues[property] = v;
1678 emit QtVariantPropertyManager::valueChanged(property, v);
1679 emit propertyChanged(property);
1683 if (m_uLongLongValues.contains(property)) {
1684 if (value.metaType().id() != QMetaType::ULongLong && !value.canConvert<qulonglong>())
1687 qulonglong v = value.toULongLong(
nullptr);
1689 qulonglong oldValue = m_uLongLongValues.value(property);
1693 m_uLongLongValues[property] = v;
1695 emit QtVariantPropertyManager::valueChanged(property, v);
1696 emit propertyChanged(property);
1700 if (m_urlValues.contains(property)) {
1701 if (value.metaType().id() != QMetaType::QUrl && !value.canConvert<QUrl>())
1704 const QUrl v = value.toUrl();
1706 const QUrl oldValue = m_urlValues.value(property);
1710 m_urlValues[property] = v;
1712 emit QtVariantPropertyManager::valueChanged(property, v);
1713 emit propertyChanged(property);
1717 if (m_byteArrayValues.contains(property)) {
1718 if (value.metaType().id() != QMetaType::QByteArray && !value.canConvert<QByteArray>())
1721 const QByteArray v = value.toByteArray();
1723 const QByteArray oldValue = m_byteArrayValues.value(property);
1727 m_byteArrayValues[property] = v;
1729 emit QtVariantPropertyManager::valueChanged(property, v);
1730 emit propertyChanged(property);
1734 m_fontManager.setValue(
this, property, value);
1735 QtVariantPropertyManager::setValue(property, value);
1736 if (QtVariantPropertyManager::valueType(property) == QMetaType::Bool)
1737 property->setToolTip(QtVariantPropertyManager::valueText(property));
1740void DesignerPropertyManager::initializeProperty(QtProperty *property)
1742 static bool creatingIconProperties =
false;
1744 m_resetMap[property] =
false;
1746 const int type = propertyType(property);
1747 m_fontManager.preInitializeProperty(property, type, m_resetMap);
1749 case QMetaType::QPalette:
1750 m_paletteValues[property] = PaletteData();
1752 case QMetaType::QString:
1753 m_stringAttributes[property] = ValidationSingleLine;
1754 m_stringFontAttributes[property] = QApplication::font();
1755 m_stringThemeAttributes[property] =
false;
1757 case QMetaType::Int:
1758 if (creatingIconProperties) {
1759 m_intValues[property] = 0;
1760 m_intThemeEnumAttributes[property] =
false;
1763 case QMetaType::UInt:
1764 m_uintValues[property] = 0;
1766 case QMetaType::LongLong:
1767 m_longLongValues[property] = 0;
1769 case QMetaType::ULongLong:
1770 m_uLongLongValues[property] = 0;
1772 case QMetaType::QUrl:
1773 m_urlValues[property] = QUrl();
1775 case QMetaType::QByteArray:
1776 m_byteArrayValues[property] = QByteArray();
1778 case QMetaType::QBrush:
1779 m_brushManager.initializeProperty(
this, property, enumTypeId());
1782 if (type == designerFlagTypeId()) {
1783 m_flagValues[property] = FlagData();
1784 m_propertyToFlags[property] = QList<QtProperty *>();
1785 }
else if (type == designerAlignmentTypeId()) {
1786 const uint align = Qt::AlignLeft | Qt::AlignVCenter;
1787 m_alignValues[property] = align;
1789 QtVariantProperty *alignH = addProperty(enumTypeId(), tr(
"Horizontal"));
1791 namesH << indexHToString(0) << indexHToString(1) << indexHToString(2) << indexHToString(3);
1792 alignH->setAttribute(u"enumNames"_s, namesH);
1793 alignH->setValue(alignToIndexH(align));
1794 m_propertyToAlignH[property] = alignH;
1795 m_alignHToProperty[alignH] = property;
1796 property->addSubProperty(alignH);
1798 QtVariantProperty *alignV = addProperty(enumTypeId(), tr(
"Vertical"));
1800 namesV << indexVToString(0) << indexVToString(1) << indexVToString(2);
1801 alignV->setAttribute(u"enumNames"_s, namesV);
1802 alignV->setValue(alignToIndexV(align));
1803 m_propertyToAlignV[property] = alignV;
1804 m_alignVToProperty[alignV] = property;
1805 property->addSubProperty(alignV);
1806 }
else if (type == designerPixmapTypeId()) {
1807 m_pixmapValues[property] = PropertySheetPixmapValue();
1808 m_defaultPixmaps[property] = QPixmap();
1809 }
else if (type == designerIconTypeId()) {
1810 creatingIconProperties =
true;
1811 m_iconValues[property] = PropertySheetIconValue();
1812 m_defaultIcons[property] = QIcon();
1814 QtVariantProperty *themeEnumProp = addProperty(QMetaType::Int, tr(
"Theme"));
1815 m_intValues[themeEnumProp] = -1;
1816 themeEnumProp->setAttribute(themeEnumAttributeC,
true);
1817 m_iconSubPropertyToProperty[themeEnumProp] = property;
1818 m_propertyToThemeEnum[property] = themeEnumProp;
1819 m_resetMap[themeEnumProp] =
true;
1820 property->addSubProperty(themeEnumProp);
1822 QtVariantProperty *themeProp = addProperty(QMetaType::QString, tr(
"XDG Theme"));
1823 themeProp->setAttribute(themeAttributeC,
true);
1824 m_iconSubPropertyToProperty[themeProp] = property;
1825 m_propertyToTheme[property] = themeProp;
1826 m_resetMap[themeProp] =
true;
1827 property->addSubProperty(themeProp);
1829 createIconSubProperty(property, QIcon::Normal, QIcon::Off, tr(
"Normal Off"));
1830 createIconSubProperty(property, QIcon::Normal, QIcon::On, tr(
"Normal On"));
1831 createIconSubProperty(property, QIcon::Disabled, QIcon::Off, tr(
"Disabled Off"));
1832 createIconSubProperty(property, QIcon::Disabled, QIcon::On, tr(
"Disabled On"));
1833 createIconSubProperty(property, QIcon::Active, QIcon::Off, tr(
"Active Off"));
1834 createIconSubProperty(property, QIcon::Active, QIcon::On, tr(
"Active On"));
1835 createIconSubProperty(property, QIcon::Selected, QIcon::Off, tr(
"Selected Off"));
1836 createIconSubProperty(property, QIcon::Selected, QIcon::On, tr(
"Selected On"));
1837 creatingIconProperties =
false;
1838 }
else if (type == designerStringTypeId()) {
1839 m_stringManager.initialize(
this, property, PropertySheetStringValue());
1840 m_stringAttributes.insert(property, ValidationMultiLine);
1841 m_stringFontAttributes.insert(property, QApplication::font());
1842 m_stringThemeAttributes.insert(property,
false);
1843 }
else if (type == designerStringListTypeId()) {
1844 m_stringListManager.initialize(
this, property, PropertySheetStringListValue());
1845 }
else if (type == designerKeySequenceTypeId()) {
1846 m_keySequenceManager.initialize(
this, property, PropertySheetKeySequenceValue());
1850 QtVariantPropertyManager::initializeProperty(property);
1851 m_fontManager.postInitializeProperty(
this, property, type, DesignerPropertyManager::enumTypeId());
1852 if (type == QMetaType::Double)
1853 setAttribute(property, u"decimals"_s, 6);
1856void DesignerPropertyManager::createIconSubProperty(QtProperty *iconProperty, QIcon::Mode mode, QIcon::State state,
const QString &subName)
1858 const auto pair = std::make_pair(mode, state);
1859 QtVariantProperty *subProp = addProperty(DesignerPropertyManager::designerPixmapTypeId(), subName);
1860 m_propertyToIconSubProperties[iconProperty][pair] = subProp;
1861 m_iconSubPropertyToState[subProp] = pair;
1862 m_iconSubPropertyToProperty[subProp] = iconProperty;
1863 m_resetMap[subProp] =
true;
1864 iconProperty->addSubProperty(subProp);
1867void DesignerPropertyManager::uninitializeProperty(QtProperty *property)
1869 m_resetMap.remove(property);
1871 const auto propList = m_propertyToFlags.value(property);
1872 for (QtProperty *prop : propList) {
1875 m_flagToProperty.remove(prop);
1878 m_propertyToFlags.remove(property);
1879 m_flagValues.remove(property);
1881 QtProperty *alignH = m_propertyToAlignH.value(property);
1884 m_alignHToProperty.remove(alignH);
1886 QtProperty *alignV = m_propertyToAlignV.value(property);
1889 m_alignVToProperty.remove(alignV);
1892 m_stringManager.uninitialize(property);
1893 m_stringListManager.uninitialize(property);
1894 m_keySequenceManager.uninitialize(property);
1896 if (QtProperty *iconTheme = m_propertyToTheme.value(property)) {
1898 m_iconSubPropertyToProperty.remove(iconTheme);
1901 if (QtProperty *iconThemeEnum = m_propertyToThemeEnum.value(property)) {
1902 delete iconThemeEnum;
1903 m_iconSubPropertyToProperty.remove(iconThemeEnum);
1906 m_propertyToAlignH.remove(property);
1907 m_propertyToAlignV.remove(property);
1909 m_stringAttributes.remove(property);
1910 m_stringFontAttributes.remove(property);
1912 m_paletteValues.remove(property);
1914 m_iconValues.remove(property);
1915 m_defaultIcons.remove(property);
1917 m_pixmapValues.remove(property);
1918 m_defaultPixmaps.remove(property);
1920 const auto &iconSubProperties = m_propertyToIconSubProperties.value(property);
1921 for (
auto itIcon = iconSubProperties.cbegin(), end = iconSubProperties.cend(); itIcon != end; ++itIcon) {
1922 QtProperty *subIcon = itIcon.value();
1924 m_iconSubPropertyToState.remove(subIcon);
1925 m_iconSubPropertyToProperty.remove(subIcon);
1927 m_propertyToIconSubProperties.remove(property);
1928 m_iconSubPropertyToState.remove(property);
1929 m_iconSubPropertyToProperty.remove(property);
1931 m_intValues.remove(property);
1932 m_uintValues.remove(property);
1933 m_longLongValues.remove(property);
1934 m_uLongLongValues.remove(property);
1935 m_urlValues.remove(property);
1936 m_byteArrayValues.remove(property);
1938 m_fontManager.uninitializeProperty(property);
1939 m_brushManager.uninitializeProperty(property);
1941 QtVariantPropertyManager::uninitializeProperty(property);
1944bool DesignerPropertyManager::resetTextAlignmentProperty(QtProperty *property)
1946 const auto it = m_alignDefault.constFind(property);
1947 if (it == m_alignDefault.cend())
1949 QtVariantProperty *alignProperty = variantProperty(property);
1950 alignProperty->setValue(DesignerPropertyManager::alignDefault(alignProperty));
1951 alignProperty->setModified(
false);
1955bool DesignerPropertyManager::resetFontSubProperty(QtProperty *property)
1957 return m_fontManager.resetFontSubProperty(
this, property);
1960bool DesignerPropertyManager::resetIconSubProperty(QtProperty *property)
1962 QtProperty *iconProperty = m_iconSubPropertyToProperty.value(property);
1966 if (m_pixmapValues.contains(property)) {
1967 QtVariantProperty *pixmapProperty = variantProperty(property);
1968 pixmapProperty->setValue(QVariant::fromValue(PropertySheetPixmapValue()));
1971 if (attributeValue(property, themeAttributeC).toBool()) {
1972 QtVariantProperty *themeProperty = variantProperty(property);
1973 themeProperty->setValue(QString());
1976 if (attributeValue(property, themeEnumAttributeC).toBool()) {
1977 QtVariantProperty *themeEnumProperty = variantProperty(property);
1978 themeEnumProperty->setValue(-1);
1986DesignerEditorFactory::DesignerEditorFactory(QDesignerFormEditorInterface *core, QObject *parent) :
1987 QtVariantEditorFactory(parent),
1988 m_resetDecorator(
new ResetDecorator(core,
this)),
1991 connect(m_resetDecorator, &ResetDecorator::resetProperty,
1992 this, &DesignerEditorFactory::resetProperty);
1995DesignerEditorFactory::~DesignerEditorFactory() =
default;
1997void DesignerEditorFactory::setSpacing(
int spacing)
1999 m_spacing = spacing;
2000 m_resetDecorator->setSpacing(spacing);
2003void DesignerEditorFactory::setFormWindowBase(qdesigner_internal::FormWindowBase *fwb)
2006 DesignerPixmapCache *cache =
nullptr;
2008 cache = fwb->pixmapCache();
2009 for (
auto it = m_editorToPixmapProperty.cbegin(), end = m_editorToPixmapProperty.cend(); it != end; ++it)
2010 it.key()->setPixmapCache(cache);
2011 for (
auto it = m_editorToIconProperty.cbegin(), end = m_editorToIconProperty.cend(); it != end; ++it)
2012 it.key()->setPixmapCache(cache);
2015void DesignerEditorFactory::connectPropertyManager(QtVariantPropertyManager *manager)
2017 m_resetDecorator->connectPropertyManager(manager);
2018 connect(manager, &QtVariantPropertyManager::attributeChanged,
2019 this, &DesignerEditorFactory::slotAttributeChanged);
2020 connect(manager, &QtVariantPropertyManager::valueChanged,
2021 this, &DesignerEditorFactory::slotValueChanged);
2022 connect(manager, &QtVariantPropertyManager::propertyChanged,
2023 this, &DesignerEditorFactory::slotPropertyChanged);
2024 QtVariantEditorFactory::connectPropertyManager(manager);
2027void DesignerEditorFactory::disconnectPropertyManager(QtVariantPropertyManager *manager)
2029 m_resetDecorator->disconnectPropertyManager(manager);
2030 disconnect(manager, &QtVariantPropertyManager::attributeChanged,
2031 this, &DesignerEditorFactory::slotAttributeChanged);
2032 disconnect(manager, &QtVariantPropertyManager::valueChanged,
2033 this, &DesignerEditorFactory::slotValueChanged);
2034 disconnect(manager, &QtVariantPropertyManager::propertyChanged,
2035 this, &DesignerEditorFactory::slotPropertyChanged);
2036 QtVariantEditorFactory::disconnectPropertyManager(manager);
2041template <
class EditorContainer,
class Editor,
class SetterParameter,
class Value>
2042static inline void applyToEditors(
const EditorContainer &list,
void (Editor::*setter)(SetterParameter),
const Value &value)
2044 if (list.isEmpty()) {
2047 for (
auto it = list.constBegin(), end = list.constEnd(); it != end; ++it) {
2048 Editor &editor = *(*it);
2049 (editor.*setter)(value);
2053void DesignerEditorFactory::slotAttributeChanged(QtProperty *property,
const QString &attribute,
const QVariant &value)
2055 QtVariantPropertyManager *manager = propertyManager(property);
2056 const int type = manager->propertyType(property);
2057 if (type == DesignerPropertyManager::designerPixmapTypeId() && attribute == defaultResourceAttributeC) {
2058 const QPixmap pixmap = qvariant_cast<QPixmap>(value);
2059 applyToEditors(m_pixmapPropertyToEditors.value(property), &PixmapEditor::setDefaultPixmap, pixmap);
2060 }
else if (type == DesignerPropertyManager::designerStringTypeId() || type == QMetaType::QString) {
2061 if (attribute == validationModesAttributeC) {
2062 const TextPropertyValidationMode validationMode =
static_cast<TextPropertyValidationMode>(value.toInt());
2063 applyToEditors(m_stringPropertyToEditors.value(property), &TextEditor::setTextPropertyValidationMode, validationMode);
2065 if (attribute == fontAttributeC) {
2066 const QFont font = qvariant_cast<QFont>(value);
2067 applyToEditors(m_stringPropertyToEditors.value(property), &TextEditor::setRichTextDefaultFont, font);
2069 if (attribute == themeAttributeC) {
2070 const bool themeEnabled = value.toBool();
2071 applyToEditors(m_stringPropertyToEditors.value(property), &TextEditor::setIconThemeModeEnabled, themeEnabled);
2073 }
else if (type == QMetaType::QPalette && attribute == superPaletteAttributeC) {
2074 const QPalette palette = qvariant_cast<QPalette>(value);
2075 applyToEditors(m_palettePropertyToEditors.value(property), &PaletteEditorButton::setSuperPalette, palette);
2079void DesignerEditorFactory::slotPropertyChanged(QtProperty *property)
2081 QtVariantPropertyManager *manager = propertyManager(property);
2082 const int type = manager->propertyType(property);
2083 if (type == DesignerPropertyManager::designerIconTypeId()) {
2084 QIcon defaultPixmap;
2085 if (!property->isModified()) {
2086 const auto attributeValue = manager->attributeValue(property, defaultResourceAttributeC);
2087 defaultPixmap = attributeValue.value<QIcon>();
2089 const auto value = manager->value(property);
2090 defaultPixmap = m_fwb->iconCache()->icon(value.value<PropertySheetIconValue>());
2092 const auto editors = m_iconPropertyToEditors.value(property);
2093 for (PixmapEditor *editor : editors)
2094 editor->setDefaultPixmapIcon(defaultPixmap);
2098void DesignerEditorFactory::slotValueChanged(QtProperty *property,
const QVariant &value)
2100 if (m_changingPropertyValue)
2103 QtVariantPropertyManager *manager = propertyManager(property);
2104 const int type = manager->propertyType(property);
2106 case QMetaType::QString:
2107 applyToEditors(m_stringPropertyToEditors.value(property), &TextEditor::setText, value.toString());
2109 case QMetaType::QPalette:
2110 applyToEditors(m_palettePropertyToEditors.value(property), &PaletteEditorButton::setPalette, qvariant_cast<QPalette>(value));
2112 case QMetaType::Int: {
2113 auto it = m_intPropertyToComboEditors.constFind(property);
2114 if (it != m_intPropertyToComboEditors.cend())
2115 applyToEditors(it.value(), &QComboBox::setCurrentIndex, value.toInt());
2118 case QMetaType::UInt:
2119 applyToEditors(m_uintPropertyToEditors.value(property), &QLineEdit::setText, QString::number(value.toUInt()));
2121 case QMetaType::LongLong:
2122 applyToEditors(m_longLongPropertyToEditors.value(property), &QLineEdit::setText, QString::number(value.toLongLong()));
2124 case QMetaType::ULongLong:
2125 applyToEditors(m_uLongLongPropertyToEditors.value(property), &QLineEdit::setText, QString::number(value.toULongLong()));
2127 case QMetaType::QUrl:
2128 applyToEditors(m_urlPropertyToEditors.value(property), &TextEditor::setText, value.toUrl().toString());
2130 case QMetaType::QByteArray:
2131 applyToEditors(m_byteArrayPropertyToEditors.value(property), &TextEditor::setText, QString::fromUtf8(value.toByteArray()));
2133 case QMetaType::QStringList:
2134 applyToEditors(m_stringListPropertyToEditors.value(property), &StringListEditorButton::setStringList, value.toStringList());
2137 if (type == DesignerPropertyManager::designerIconTypeId()) {
2138 PropertySheetIconValue iconValue = qvariant_cast<PropertySheetIconValue>(value);
2139 applyToEditors(m_iconPropertyToEditors.value(property), &PixmapEditor::setTheme, iconValue.theme());
2140 applyToEditors(m_iconPropertyToEditors.value(property), &PixmapEditor::setThemeEnum, iconValue.themeEnum());
2141 applyToEditors(m_iconPropertyToEditors.value(property), &PixmapEditor::setPath, iconValue.pixmap(QIcon::Normal, QIcon::Off).path());
2142 }
else if (type == DesignerPropertyManager::designerPixmapTypeId()) {
2143 applyToEditors(m_pixmapPropertyToEditors.value(property), &PixmapEditor::setPath, qvariant_cast<PropertySheetPixmapValue>(value).path());
2144 }
else if (type == DesignerPropertyManager::designerStringTypeId()) {
2145 applyToEditors(m_stringPropertyToEditors.value(property), &TextEditor::setText, qvariant_cast<PropertySheetStringValue>(value).value());
2146 }
else if (type == DesignerPropertyManager::designerStringListTypeId()) {
2147 applyToEditors(m_stringListPropertyToEditors.value(property), &StringListEditorButton::setStringList, qvariant_cast<PropertySheetStringListValue>(value).value());
2148 }
else if (type == DesignerPropertyManager::designerKeySequenceTypeId()) {
2149 applyToEditors(m_keySequencePropertyToEditors.value(property), &QKeySequenceEdit::setKeySequence, qvariant_cast<PropertySheetKeySequenceValue>(value).value());
2155TextEditor *DesignerEditorFactory::createTextEditor(QWidget *parent, TextPropertyValidationMode vm,
const QString &value)
2157 TextEditor *rc =
new TextEditor(m_core, parent);
2159 rc->setSpacing(m_spacing);
2160 rc->setTextPropertyValidationMode(vm);
2161 connect(rc, &QObject::destroyed,
this, &DesignerEditorFactory::slotEditorDestroyed);
2165QWidget *DesignerEditorFactory::createEditor(QtVariantPropertyManager *manager, QtProperty *property,
2168 QWidget *editor =
nullptr;
2169 const int type = manager->propertyType(property);
2171 case QMetaType::Bool: {
2172 editor = QtVariantEditorFactory::createEditor(manager, property, parent);
2173 QtBoolEdit *boolEdit = qobject_cast<QtBoolEdit *>(editor);
2175 boolEdit->setTextVisible(
false);
2178 case QMetaType::QString: {
2179 const int itvm = manager->attributeValue(property, validationModesAttributeC).toInt();
2180 const auto tvm =
static_cast<TextPropertyValidationMode>(itvm);
2181 TextEditor *ed = createTextEditor(parent, tvm, manager->value(property).toString());
2182 const QVariant richTextDefaultFont = manager->attributeValue(property, fontAttributeC);
2183 if (richTextDefaultFont.metaType().id() == QMetaType::QFont)
2184 ed->setRichTextDefaultFont(qvariant_cast<QFont>(richTextDefaultFont));
2185 const bool themeEnabled = manager->attributeValue(property, themeAttributeC).toBool();
2186 ed->setIconThemeModeEnabled(themeEnabled);
2187 m_stringPropertyToEditors[property].append(ed);
2188 m_editorToStringProperty[ed] = property;
2189 connect(ed, &QObject::destroyed,
this, &DesignerEditorFactory::slotEditorDestroyed);
2190 connect(ed, &TextEditor::textChanged,
this, &DesignerEditorFactory::slotStringTextChanged);
2194 case QMetaType::QPalette: {
2195 PaletteEditorButton *ed =
new PaletteEditorButton(m_core, qvariant_cast<QPalette>(manager->value(property)), parent);
2196 ed->setSuperPalette(qvariant_cast<QPalette>(manager->attributeValue(property, superPaletteAttributeC)));
2197 m_palettePropertyToEditors[property].append(ed);
2198 m_editorToPaletteProperty[ed] = property;
2199 connect(ed, &QObject::destroyed,
this, &DesignerEditorFactory::slotEditorDestroyed);
2200 connect(ed, &PaletteEditorButton::paletteChanged,
this, &DesignerEditorFactory::slotPaletteChanged);
2204 case QMetaType::Int:
2205 if (manager->attributeValue(property, themeEnumAttributeC).toBool()) {
2206 auto *ed = IconThemeEnumEditor::createComboBox(parent);
2207 ed->setCurrentIndex(manager->value(property).toInt());
2208 connect(ed, &QComboBox::currentIndexChanged,
this,
2209 &DesignerEditorFactory::slotIntChanged);
2210 connect(ed, &QObject::destroyed,
this, &DesignerEditorFactory::slotEditorDestroyed);
2211 m_intPropertyToComboEditors[property].append(ed);
2212 m_comboEditorToIntProperty.insert(ed, property);
2215 editor = QtVariantEditorFactory::createEditor(manager, property, parent);
2218 case QMetaType::UInt: {
2219 QLineEdit *ed =
new QLineEdit(parent);
2220 ed->setValidator(
new QULongLongValidator(0, UINT_MAX, ed));
2221 ed->setText(QString::number(manager->value(property).toUInt()));
2222 m_uintPropertyToEditors[property].append(ed);
2223 m_editorToUintProperty[ed] = property;
2224 connect(ed, &QObject::destroyed,
this, &DesignerEditorFactory::slotEditorDestroyed);
2225 connect(ed, &QLineEdit::textChanged,
this, &DesignerEditorFactory::slotUintChanged);
2229 case QMetaType::LongLong: {
2230 QLineEdit *ed =
new QLineEdit(parent);
2231 ed->setValidator(
new QLongLongValidator(ed));
2232 ed->setText(QString::number(manager->value(property).toLongLong()));
2233 m_longLongPropertyToEditors[property].append(ed);
2234 m_editorToLongLongProperty[ed] = property;
2235 connect(ed, &QObject::destroyed,
this, &DesignerEditorFactory::slotEditorDestroyed);
2236 connect(ed, &QLineEdit::textChanged,
this, &DesignerEditorFactory::slotLongLongChanged);
2240 case QMetaType::ULongLong: {
2241 QLineEdit *ed =
new QLineEdit(parent);
2242 ed->setValidator(
new QULongLongValidator(ed));
2243 ed->setText(QString::number(manager->value(property).toULongLong()));
2244 m_uLongLongPropertyToEditors[property].append(ed);
2245 m_editorToULongLongProperty[ed] = property;
2246 connect(ed, &QObject::destroyed,
this, &DesignerEditorFactory::slotEditorDestroyed);
2247 connect(ed, &QLineEdit::textChanged,
this, &DesignerEditorFactory::slotULongLongChanged);
2251 case QMetaType::QUrl: {
2252 TextEditor *ed = createTextEditor(parent, ValidationURL, manager->value(property).toUrl().toString());
2253 ed->setUpdateMode(TextPropertyEditor::UpdateOnFinished);
2254 m_urlPropertyToEditors[property].append(ed);
2255 m_editorToUrlProperty[ed] = property;
2256 connect(ed, &QObject::destroyed,
this, &DesignerEditorFactory::slotEditorDestroyed);
2257 connect(ed, &TextEditor::textChanged,
this, &DesignerEditorFactory::slotUrlChanged);
2261 case QMetaType::QByteArray: {
2262 TextEditor *ed = createTextEditor(parent, ValidationMultiLine, QString::fromUtf8(manager->value(property).toByteArray()));
2263 m_byteArrayPropertyToEditors[property].append(ed);
2264 m_editorToByteArrayProperty[ed] = property;
2265 connect(ed, &QObject::destroyed,
this, &DesignerEditorFactory::slotEditorDestroyed);
2266 connect(ed, &TextEditor::textChanged,
this, &DesignerEditorFactory::slotByteArrayChanged);
2271 if (type == DesignerPropertyManager::designerPixmapTypeId()) {
2272 PixmapEditor *ed =
new PixmapEditor(m_core, parent);
2273 ed->setPixmapCache(m_fwb->pixmapCache());
2274 ed->setPath(qvariant_cast<PropertySheetPixmapValue>(manager->value(property)).path());
2275 ed->setDefaultPixmap(qvariant_cast<QPixmap>(manager->attributeValue(property, defaultResourceAttributeC)));
2276 ed->setSpacing(m_spacing);
2277 m_pixmapPropertyToEditors[property].append(ed);
2278 m_editorToPixmapProperty[ed] = property;
2279 connect(ed, &QObject::destroyed,
this, &DesignerEditorFactory::slotEditorDestroyed);
2280 connect(ed, &PixmapEditor::pathChanged,
this, &DesignerEditorFactory::slotPixmapChanged);
2282 }
else if (type == DesignerPropertyManager::designerIconTypeId()) {
2283 PixmapEditor *ed =
new PixmapEditor(m_core, parent);
2284 ed->setPixmapCache(m_fwb->pixmapCache());
2285 ed->setIconThemeModeEnabled(
true);
2286 PropertySheetIconValue value = qvariant_cast<PropertySheetIconValue>(manager->value(property));
2287 ed->setTheme(value.theme());
2288 ed->setThemeEnum(value.themeEnum());
2289 ed->setPath(value.pixmap(QIcon::Normal, QIcon::Off).path());
2290 QIcon defaultPixmap;
2291 if (!property->isModified())
2292 defaultPixmap = qvariant_cast<QIcon>(manager->attributeValue(property, defaultResourceAttributeC));
2294 defaultPixmap = m_fwb->iconCache()->icon(value);
2295 ed->setDefaultPixmapIcon(defaultPixmap);
2296 ed->setSpacing(m_spacing);
2297 m_iconPropertyToEditors[property].append(ed);
2298 m_editorToIconProperty[ed] = property;
2299 connect(ed, &QObject::destroyed,
this, &DesignerEditorFactory::slotEditorDestroyed);
2300 connect(ed, &PixmapEditor::pathChanged,
this, &DesignerEditorFactory::slotIconChanged);
2301 connect(ed, &PixmapEditor::themeChanged,
this, &DesignerEditorFactory::slotIconThemeChanged);
2302 connect(ed, &PixmapEditor::themeEnumChanged,
this, &DesignerEditorFactory::slotIconThemeEnumChanged);
2304 }
else if (type == DesignerPropertyManager::designerStringTypeId()) {
2305 const TextPropertyValidationMode tvm =
static_cast<TextPropertyValidationMode>(manager->attributeValue(property, validationModesAttributeC).toInt());
2306 TextEditor *ed = createTextEditor(parent, tvm, qvariant_cast<PropertySheetStringValue>(manager->value(property)).value());
2307 const QVariant richTextDefaultFont = manager->attributeValue(property, fontAttributeC);
2308 if (richTextDefaultFont.metaType().id() == QMetaType::QFont)
2309 ed->setRichTextDefaultFont(qvariant_cast<QFont>(richTextDefaultFont));
2310 m_stringPropertyToEditors[property].append(ed);
2311 m_editorToStringProperty[ed] = property;
2312 connect(ed, &QObject::destroyed,
this, &DesignerEditorFactory::slotEditorDestroyed);
2313 connect(ed, &TextEditor::textChanged,
this, &DesignerEditorFactory::slotStringTextChanged);
2315 }
else if (type == DesignerPropertyManager::designerStringListTypeId() || type == QMetaType::QStringList) {
2316 const QVariant variantValue = manager->value(property);
2317 const QStringList value = type == QMetaType::QStringList
2318 ? variantValue.toStringList() : qvariant_cast<PropertySheetStringListValue>(variantValue).value();
2319 StringListEditorButton *ed =
new StringListEditorButton(value, parent);
2320 m_stringListPropertyToEditors[property].append(ed);
2321 m_editorToStringListProperty.insert(ed, property);
2322 connect(ed, &QObject::destroyed,
this, &DesignerEditorFactory::slotEditorDestroyed);
2323 connect(ed, &StringListEditorButton::stringListChanged,
this, &DesignerEditorFactory::slotStringListChanged);
2325 }
else if (type == DesignerPropertyManager::designerKeySequenceTypeId()) {
2326 QKeySequenceEdit *ed =
new QKeySequenceEdit(parent);
2327 ed->setKeySequence(qvariant_cast<PropertySheetKeySequenceValue>(manager->value(property)).value());
2328 m_keySequencePropertyToEditors[property].append(ed);
2329 m_editorToKeySequenceProperty[ed] = property;
2330 connect(ed, &QObject::destroyed,
this, &DesignerEditorFactory::slotEditorDestroyed);
2331 connect(ed, &QKeySequenceEdit::keySequenceChanged,
this, &DesignerEditorFactory::slotKeySequenceChanged);
2334 editor = QtVariantEditorFactory::createEditor(manager, property, parent);
2338 return m_resetDecorator->editor(editor,
2339 manager->variantProperty(property)->attributeValue(resettableAttributeC).toBool(),
2340 manager, property, parent);
2343template <
class Editor>
2344bool removeEditor(QObject *object,
2345 QHash<
const QtProperty *, QList<Editor>> *propertyToEditors,
2346 QHash<Editor, QtProperty *> *editorToProperty)
2348 if (!propertyToEditors)
2350 if (!editorToProperty)
2352 for (
auto e2pIt = editorToProperty->begin(), end = editorToProperty->end(); e2pIt != end; ++e2pIt) {
2353 Editor editor = e2pIt.key();
2354 if (editor == object) {
2355 const auto p2eIt = propertyToEditors->find(e2pIt.value());
2356 if (p2eIt != propertyToEditors->end()) {
2357 p2eIt.value().removeAll(editor);
2358 if (p2eIt.value().isEmpty())
2359 propertyToEditors->erase(p2eIt);
2361 editorToProperty->erase(e2pIt);
2368void DesignerEditorFactory::slotEditorDestroyed(QObject *object)
2370 if (removeEditor(object, &m_stringPropertyToEditors, &m_editorToStringProperty))
2372 if (removeEditor(object, &m_keySequencePropertyToEditors, &m_editorToKeySequenceProperty))
2374 if (removeEditor(object, &m_palettePropertyToEditors, &m_editorToPaletteProperty))
2376 if (removeEditor(object, &m_pixmapPropertyToEditors, &m_editorToPixmapProperty))
2378 if (removeEditor(object, &m_iconPropertyToEditors, &m_editorToIconProperty))
2380 if (removeEditor(object, &m_uintPropertyToEditors, &m_editorToUintProperty))
2382 if (removeEditor(object, &m_longLongPropertyToEditors, &m_editorToLongLongProperty))
2384 if (removeEditor(object, &m_intPropertyToComboEditors, &m_comboEditorToIntProperty))
2386 if (removeEditor(object, &m_uLongLongPropertyToEditors, &m_editorToULongLongProperty))
2388 if (removeEditor(object, &m_urlPropertyToEditors, &m_editorToUrlProperty))
2390 if (removeEditor(object, &m_byteArrayPropertyToEditors, &m_editorToByteArrayProperty))
2392 if (removeEditor(object, &m_stringListPropertyToEditors, &m_editorToStringListProperty))
2396template<
class Editor>
2397bool updateManager(QtVariantEditorFactory *factory,
bool *changingPropertyValue,
2398 const QHash<Editor, QtProperty *> &editorToProperty, QWidget *editor,
const QVariant &value)
2402 for (
auto it = editorToProperty.cbegin(), end = editorToProperty.cend(); it != end; ++it) {
2403 if (it.key() == editor) {
2404 QtProperty *prop = it.value();
2405 QtVariantPropertyManager *manager = factory->propertyManager(prop);
2406 *changingPropertyValue =
true;
2407 manager->variantProperty(prop)->setValue(value);
2408 *changingPropertyValue =
false;
2415void DesignerEditorFactory::slotUintChanged(
const QString &value)
2417 updateManager(
this, &m_changingPropertyValue, m_editorToUintProperty, qobject_cast<QWidget *>(sender()), value.toUInt());
2420void DesignerEditorFactory::slotLongLongChanged(
const QString &value)
2422 updateManager(
this, &m_changingPropertyValue, m_editorToLongLongProperty, qobject_cast<QWidget *>(sender()), value.toLongLong());
2425void DesignerEditorFactory::slotIntChanged(
int v)
2427 updateManager(
this, &m_changingPropertyValue, m_comboEditorToIntProperty,
2428 qobject_cast<QWidget *>(sender()), v);
2431void DesignerEditorFactory::slotULongLongChanged(
const QString &value)
2433 updateManager(
this, &m_changingPropertyValue, m_editorToULongLongProperty, qobject_cast<QWidget *>(sender()), value.toULongLong());
2436void DesignerEditorFactory::slotUrlChanged(
const QString &value)
2438 updateManager(
this, &m_changingPropertyValue, m_editorToUrlProperty, qobject_cast<QWidget *>(sender()), QUrl(value));
2441void DesignerEditorFactory::slotByteArrayChanged(
const QString &value)
2443 updateManager(
this, &m_changingPropertyValue, m_editorToByteArrayProperty, qobject_cast<QWidget *>(sender()), value.toUtf8());
2446template <
class Editor>
2447QtProperty *findPropertyForEditor(
const QHash<Editor *, QtProperty *> &editorMap,
2448 const QObject *sender)
2450 for (
auto it = editorMap.constBegin(), cend = editorMap.constEnd(); it != cend; ++it)
2451 if (it.key() == sender)
2456void DesignerEditorFactory::slotStringTextChanged(
const QString &value)
2458 if (QtProperty *prop = findPropertyForEditor(m_editorToStringProperty, sender())) {
2459 QtVariantPropertyManager *manager = propertyManager(prop);
2460 QtVariantProperty *varProp = manager->variantProperty(prop);
2461 QVariant val = varProp->value();
2462 if (val.userType() == DesignerPropertyManager::designerStringTypeId()) {
2463 PropertySheetStringValue strVal = qvariant_cast<PropertySheetStringValue>(val);
2464 strVal.setValue(value);
2466 if (varProp->subProperties().isEmpty())
2467 strVal.setTranslatable(
false);
2468 val = QVariant::fromValue(strVal);
2470 val = QVariant(value);
2472 m_changingPropertyValue =
true;
2473 manager->variantProperty(prop)->setValue(val);
2474 m_changingPropertyValue =
false;
2478void DesignerEditorFactory::slotKeySequenceChanged(
const QKeySequence &value)
2480 if (QtProperty *prop = findPropertyForEditor(m_editorToKeySequenceProperty, sender())) {
2481 QtVariantPropertyManager *manager = propertyManager(prop);
2482 QtVariantProperty *varProp = manager->variantProperty(prop);
2483 QVariant val = varProp->value();
2484 if (val.userType() == DesignerPropertyManager::designerKeySequenceTypeId()) {
2485 PropertySheetKeySequenceValue keyVal = qvariant_cast<PropertySheetKeySequenceValue>(val);
2486 keyVal.setValue(value);
2487 val = QVariant::fromValue(keyVal);
2489 val = QVariant::fromValue(value);
2491 m_changingPropertyValue =
true;
2492 manager->variantProperty(prop)->setValue(val);
2493 m_changingPropertyValue =
false;
2497void DesignerEditorFactory::slotPaletteChanged(
const QPalette &value)
2499 updateManager(
this, &m_changingPropertyValue, m_editorToPaletteProperty, qobject_cast<QWidget *>(sender()), QVariant::fromValue(value));
2502void DesignerEditorFactory::slotPixmapChanged(
const QString &value)
2504 updateManager(
this, &m_changingPropertyValue, m_editorToPixmapProperty, qobject_cast<QWidget *>(sender()),
2505 QVariant::fromValue(PropertySheetPixmapValue(value)));
2508void DesignerEditorFactory::slotIconChanged(
const QString &value)
2510 updateManager(
this, &m_changingPropertyValue, m_editorToIconProperty, qobject_cast<QWidget *>(sender()),
2511 QVariant::fromValue(PropertySheetIconValue(PropertySheetPixmapValue(value))));
2514void DesignerEditorFactory::slotIconThemeChanged(
const QString &value)
2516 PropertySheetIconValue icon;
2517 icon.setTheme(value);
2518 updateManager(
this, &m_changingPropertyValue, m_editorToIconProperty, qobject_cast<QWidget *>(sender()),
2519 QVariant::fromValue(icon));
2522void DesignerEditorFactory::slotIconThemeEnumChanged(
int value)
2524 PropertySheetIconValue icon;
2525 icon.setThemeEnum(value);
2526 updateManager(
this, &m_changingPropertyValue, m_editorToIconProperty,
2527 qobject_cast<QWidget *>(sender()), QVariant::fromValue(icon));
2530void DesignerEditorFactory::slotStringListChanged(
const QStringList &value)
2532 if (QtProperty *prop = findPropertyForEditor(m_editorToStringListProperty, sender())) {
2533 QtVariantPropertyManager *manager = propertyManager(prop);
2534 QtVariantProperty *varProp = manager->variantProperty(prop);
2535 QVariant val = varProp->value();
2536 if (val.userType() == DesignerPropertyManager::designerStringListTypeId()) {
2537 PropertySheetStringListValue listValue = qvariant_cast<PropertySheetStringListValue>(val);
2538 listValue.setValue(value);
2540 if (varProp->subProperties().isEmpty())
2541 listValue.setTranslatable(
false);
2542 val = QVariant::fromValue(listValue);
2544 val = QVariant(value);
2546 m_changingPropertyValue =
true;
2547 manager->variantProperty(prop)->setValue(val);
2548 m_changingPropertyValue =
false;
2552ResetDecorator::ResetDecorator(
const QDesignerFormEditorInterface *core, QObject *parent)
2559ResetDecorator::~ResetDecorator()
2561 const auto editors = m_resetWidgetToProperty.keys();
2562 qDeleteAll(editors);
2565void ResetDecorator::connectPropertyManager(QtAbstractPropertyManager *manager)
2567 connect(manager, &QtAbstractPropertyManager::propertyChanged,
2568 this, &ResetDecorator::slotPropertyChanged);
2571void ResetDecorator::disconnectPropertyManager(QtAbstractPropertyManager *manager)
2573 disconnect(manager, &QtAbstractPropertyManager::propertyChanged,
2574 this, &ResetDecorator::slotPropertyChanged);
2577void ResetDecorator::setSpacing(
int spacing)
2579 m_spacing = spacing;
2582static inline bool isModifiedInMultiSelection(
const QDesignerFormEditorInterface *core,
2583 const QString &propertyName)
2585 const QDesignerFormWindowInterface *form = core->formWindowManager()->activeFormWindow();
2588 const QDesignerFormWindowCursorInterface *cursor = form->cursor();
2589 const int selectionSize = cursor->selectedWidgetCount();
2590 if (selectionSize < 2)
2592 for (
int i = 0; i < selectionSize; ++i) {
2593 const QDesignerPropertySheetExtension *sheet =
2594 qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(),
2595 cursor->selectedWidget(i));
2596 const int index = sheet->indexOf(propertyName);
2597 if (index >= 0 && sheet->isChanged(index))
2603QWidget *ResetDecorator::editor(QWidget *subEditor,
bool resettable, QtAbstractPropertyManager *manager, QtProperty *property,
2608 ResetWidget *resetWidget =
nullptr;
2610 resetWidget =
new ResetWidget(property, parent);
2611 resetWidget->setSpacing(m_spacing);
2612 resetWidget->setResetEnabled(property->isModified() || isModifiedInMultiSelection(m_core, property->propertyName()));
2613 resetWidget->setValueText(property->valueText());
2614 resetWidget->setValueIcon(property->valueIcon());
2615 resetWidget->setAutoFillBackground(
true);
2616 connect(resetWidget, &QObject::destroyed,
this, &ResetDecorator::slotEditorDestroyed);
2617 connect(resetWidget, &ResetWidget::resetProperty,
this, &ResetDecorator::resetProperty);
2618 m_createdResetWidgets[property].append(resetWidget);
2619 m_resetWidgetToProperty[resetWidget] = property;
2623 subEditor->setParent(resetWidget);
2624 resetWidget->setWidget(subEditor);
2632void ResetDecorator::slotPropertyChanged(QtProperty *property)
2634 const auto prIt = m_createdResetWidgets.constFind(property);
2635 if (prIt == m_createdResetWidgets.constEnd())
2638 for (ResetWidget *widget : prIt.value()) {
2639 widget->setResetEnabled(property->isModified() || isModifiedInMultiSelection(m_core, property->propertyName()));
2640 widget->setValueText(property->valueText());
2641 widget->setValueIcon(property->valueIcon());
2645void ResetDecorator::slotEditorDestroyed(QObject *object)
2647 for (
auto itEditor = m_resetWidgetToProperty.cbegin(), cend = m_resetWidgetToProperty.cend(); itEditor != cend; ++itEditor) {
2648 if (itEditor.key() == object) {
2649 ResetWidget *editor = itEditor.key();
2650 QtProperty *property = itEditor.value();
2651 m_resetWidgetToProperty.remove(editor);
2652 m_createdResetWidgets[property].removeAll(editor);
2653 if (m_createdResetWidgets[property].isEmpty())
2654 m_createdResetWidgets.remove(property);
2664#include "designerpropertymanager.moc"