/**************************************************************************** ** ** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Designer of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ** ** ** ** ** ** ** ****************************************************************************/ #ifndef DESIGNERPROPERTYMANAGER_H #define DESIGNERPROPERTYMANAGER_H #include "qtvariantproperty.h" #include "brushpropertymanager.h" #include "fontpropertymanager.h" #include #include #include #include #include #include QT_BEGIN_NAMESPACE typedef QPair DesignerIntPair; using DesignerFlagList = QList; class QDesignerFormEditorInterface; class QLineEdit; class QUrl; class QKeySequenceEdit; namespace qdesigner_internal { class ResetWidget; class TextEditor; class PaletteEditorButton; class PixmapEditor; class StringListEditorButton; class FormWindowBase; class ResetDecorator : public QObject { Q_OBJECT public: explicit ResetDecorator(const QDesignerFormEditorInterface *core, QObject *parent = nullptr); ~ResetDecorator(); void connectPropertyManager(QtAbstractPropertyManager *manager); QWidget *editor(QWidget *subEditor, bool resettable, QtAbstractPropertyManager *manager, QtProperty *property, QWidget *parent); void disconnectPropertyManager(QtAbstractPropertyManager *manager); void setSpacing(int spacing); signals: void resetProperty(QtProperty *property); private slots: void slotPropertyChanged(QtProperty *property); void slotEditorDestroyed(QObject *object); private: QMap > m_createdResetWidgets; QMap m_resetWidgetToProperty; int m_spacing; const QDesignerFormEditorInterface *m_core; }; // Helper for handling sub-properties of properties inheriting PropertySheetTranslatableData // (translatable, disambiguation, comment). template class TranslatablePropertyManager { public: void initialize(QtVariantPropertyManager *m, QtProperty *property, const PropertySheetValue &value); bool uninitialize(QtProperty *property); bool destroy(QtProperty *subProperty); bool value(const QtProperty *property, QVariant *rc) const; int valueChanged(QtVariantPropertyManager *m, QtProperty *property, const QVariant &value); int setValue(QtVariantPropertyManager *m, QtProperty *property, int expectedTypeId, const QVariant &value); private: QHash m_values; QHash m_valueToComment; QHash m_valueToTranslatable; QHash m_valueToDisambiguation; QHash m_valueToId; QHash m_commentToValue; QHash m_translatableToValue; QHash m_disambiguationToValue; QHash m_idToValue; }; class DesignerPropertyManager : public QtVariantPropertyManager { Q_OBJECT public: enum ValueChangedResult { NoMatch, Unchanged, Changed }; explicit DesignerPropertyManager(QDesignerFormEditorInterface *core, QObject *parent = nullptr); ~DesignerPropertyManager(); QStringList attributes(int propertyType) const override; int attributeType(int propertyType, const QString &attribute) const override; QVariant attributeValue(const QtProperty *property, const QString &attribute) const override; bool isPropertyTypeSupported(int propertyType) const override; QVariant value(const QtProperty *property) const override; int valueType(int propertyType) const override; QString valueText(const QtProperty *property) const override; QIcon valueIcon(const QtProperty *property) const override; bool resetFontSubProperty(QtProperty *property); bool resetIconSubProperty(QtProperty *subProperty); void reloadResourceProperties(); static int designerFlagTypeId(); static int designerFlagListTypeId(); static int designerAlignmentTypeId(); static int designerPixmapTypeId(); static int designerIconTypeId(); static int designerStringTypeId(); static int designerStringListTypeId(); static int designerKeySequenceTypeId(); void setObject(QObject *object) { m_object = object; } static void setUseIdBasedTranslations(bool v) { m_IdBasedTranslations = v; } static bool useIdBasedTranslations() { return m_IdBasedTranslations; } public Q_SLOTS: void setAttribute(QtProperty *property, const QString &attribute, const QVariant &value) override; void setValue(QtProperty *property, const QVariant &value) override; Q_SIGNALS: // sourceOfChange - a subproperty (or just property) which caused a change //void valueChanged(QtProperty *property, const QVariant &value, QtProperty *sourceOfChange); void valueChanged(QtProperty *property, const QVariant &value, bool enableSubPropertyHandling); protected: void initializeProperty(QtProperty *property) override; void uninitializeProperty(QtProperty *property) override; private Q_SLOTS: void slotValueChanged(QtProperty *property, const QVariant &value); void slotPropertyDestroyed(QtProperty *property); private: void createIconSubProperty(QtProperty *iconProperty, QIcon::Mode mode, QIcon::State state, const QString &subName); typedef QMap PropertyBoolMap; PropertyBoolMap m_resetMap; int bitCount(int mask) const; struct FlagData { uint val{0}; DesignerFlagList flags; QList values; }; typedef QMap PropertyFlagDataMap; PropertyFlagDataMap m_flagValues; typedef QMap > PropertyToPropertyListMap; PropertyToPropertyListMap m_propertyToFlags; QMap m_flagToProperty; int alignToIndexH(uint align) const; int alignToIndexV(uint align) const; uint indexHToAlign(int idx) const; uint indexVToAlign(int idx) const; QString indexHToString(int idx) const; QString indexVToString(int idx) const; QMap m_alignValues; typedef QMap PropertyToPropertyMap; PropertyToPropertyMap m_propertyToAlignH; PropertyToPropertyMap m_propertyToAlignV; PropertyToPropertyMap m_alignHToProperty; PropertyToPropertyMap m_alignVToProperty; QMap, QtProperty *> > m_propertyToIconSubProperties; QMap > m_iconSubPropertyToState; PropertyToPropertyMap m_iconSubPropertyToProperty; PropertyToPropertyMap m_propertyToTheme; TranslatablePropertyManager m_stringManager; TranslatablePropertyManager m_keySequenceManager; TranslatablePropertyManager m_stringListManager; struct PaletteData { QPalette val; QPalette superPalette; }; typedef QMap PropertyPaletteDataMap; PropertyPaletteDataMap m_paletteValues; QMap m_pixmapValues; QMap m_iconValues; QMap m_uintValues; QMap m_longLongValues; QMap m_uLongLongValues; QMap m_urlValues; QMap m_byteArrayValues; typedef QMap PropertyIntMap; PropertyIntMap m_stringAttributes; typedef QMap PropertyFontMap; PropertyFontMap m_stringFontAttributes; PropertyBoolMap m_stringThemeAttributes; BrushPropertyManager m_brushManager; FontPropertyManager m_fontManager; QMap m_defaultPixmaps; QMap m_defaultIcons; bool m_changingSubValue; QDesignerFormEditorInterface *m_core; QObject *m_object; QtProperty *m_sourceOfChange; static bool m_IdBasedTranslations; }; class DesignerEditorFactory : public QtVariantEditorFactory { Q_OBJECT public: explicit DesignerEditorFactory(QDesignerFormEditorInterface *core, QObject *parent = nullptr); ~DesignerEditorFactory(); void setSpacing(int spacing); void setFormWindowBase(FormWindowBase *fwb); signals: void resetProperty(QtProperty *property); protected: void connectPropertyManager(QtVariantPropertyManager *manager) override; QWidget *createEditor(QtVariantPropertyManager *manager, QtProperty *property, QWidget *parent) override; void disconnectPropertyManager(QtVariantPropertyManager *manager) override; private slots: void slotEditorDestroyed(QObject *object); void slotAttributeChanged(QtProperty *property, const QString &attribute, const QVariant &value); void slotPropertyChanged(QtProperty *property); void slotValueChanged(QtProperty *property, const QVariant &value); void slotStringTextChanged(const QString &value); void slotKeySequenceChanged(const QKeySequence &value); void slotPaletteChanged(const QPalette &value); void slotPixmapChanged(const QString &value); void slotIconChanged(const QString &value); void slotIconThemeChanged(const QString &value); void slotUintChanged(const QString &value); void slotLongLongChanged(const QString &value); void slotULongLongChanged(const QString &value); void slotUrlChanged(const QString &value); void slotByteArrayChanged(const QString &value); void slotStringListChanged(const QStringList &value); private: TextEditor *createTextEditor(QWidget *parent, TextPropertyValidationMode vm, const QString &value); ResetDecorator *m_resetDecorator; bool m_changingPropertyValue; QDesignerFormEditorInterface *m_core; FormWindowBase *m_fwb; int m_spacing; QMap > m_stringPropertyToEditors; QMap m_editorToStringProperty; QMap > m_keySequencePropertyToEditors; QMap m_editorToKeySequenceProperty; QMap > m_palettePropertyToEditors; QMap m_editorToPaletteProperty; QMap > m_pixmapPropertyToEditors; QMap m_editorToPixmapProperty; QMap > m_iconPropertyToEditors; QMap m_editorToIconProperty; QMap > m_uintPropertyToEditors; QMap m_editorToUintProperty; QMap > m_longLongPropertyToEditors; QMap m_editorToLongLongProperty; QMap > m_uLongLongPropertyToEditors; QMap m_editorToULongLongProperty; QMap > m_urlPropertyToEditors; QMap m_editorToUrlProperty; QMap > m_byteArrayPropertyToEditors; QMap m_editorToByteArrayProperty; QMap > m_stringListPropertyToEditors; QMap m_editorToStringListProperty; }; } // namespace qdesigner_internal QT_END_NAMESPACE Q_DECLARE_METATYPE(DesignerIntPair) Q_DECLARE_METATYPE(DesignerFlagList) #endif