1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Designer of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #ifndef FONTPROPERTYMANAGER_H |
30 | #define FONTPROPERTYMANAGER_H |
31 | |
32 | #include <QtCore/qmap.h> |
33 | #include <QtCore/qstringlist.h> |
34 | #include <QtGui/qfont.h> |
35 | |
36 | QT_BEGIN_NAMESPACE |
37 | |
38 | class QtProperty; |
39 | class QtVariantPropertyManager; |
40 | |
41 | class QString; |
42 | class QVariant; |
43 | |
44 | namespace qdesigner_internal { |
45 | |
46 | /* FontPropertyManager: A mixin for DesignerPropertyManager that manages font |
47 | * properties. Adds an antialiasing subproperty and reset flags/mask handling |
48 | * for the other subproperties. It also modifies the font family |
49 | * enumeration names, which it reads from an XML mapping file that |
50 | * contains annotations indicating the platform the font is available on. */ |
51 | |
52 | class FontPropertyManager { |
53 | Q_DISABLE_COPY_MOVE(FontPropertyManager) |
54 | |
55 | public: |
56 | FontPropertyManager(); |
57 | |
58 | using ResetMap = QMap<QtProperty *, bool>; |
59 | using NameMap = QMap<QString, QString>; |
60 | |
61 | // Call before QtVariantPropertyManager::initializeProperty. |
62 | void preInitializeProperty(QtProperty *property, int type, ResetMap &resetMap); |
63 | // Call after QtVariantPropertyManager::initializeProperty. This will trigger |
64 | // a recursion for the sub properties |
65 | void postInitializeProperty(QtVariantPropertyManager *vm, QtProperty *property, int type, int enumTypeId); |
66 | |
67 | bool uninitializeProperty(QtProperty *property); |
68 | |
69 | // Call from QtPropertyManager's propertyDestroyed signal |
70 | void slotPropertyDestroyed(QtProperty *property); |
71 | |
72 | bool resetFontSubProperty(QtVariantPropertyManager *vm, QtProperty *subProperty); |
73 | |
74 | // Call from slotValueChanged(), returns DesignerPropertyManager::ValueChangedResult |
75 | int valueChanged(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value); |
76 | |
77 | // Call from setValue() before calling setValue() on QtVariantPropertyManager. |
78 | void setValue(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value); |
79 | |
80 | static bool readFamilyMapping(NameMap *rc, QString *errorMessage); |
81 | |
82 | private: |
83 | using PropertyToPropertyMap = QMap<QtProperty *, QtProperty *>; |
84 | using PropertyList = QList<QtProperty *>; |
85 | using PropertyToSubPropertiesMap = QMap<QtProperty *, PropertyList>; |
86 | |
87 | void removeAntialiasingProperty(QtProperty *); |
88 | void updateModifiedState(QtProperty *property, const QVariant &value); |
89 | static int antialiasingToIndex(QFont::StyleStrategy antialias); |
90 | static QFont::StyleStrategy indexToAntialiasing(int idx); |
91 | static unsigned fontFlag(int idx); |
92 | |
93 | PropertyToPropertyMap m_propertyToAntialiasing; |
94 | PropertyToPropertyMap m_antialiasingToProperty; |
95 | |
96 | PropertyToSubPropertiesMap m_propertyToFontSubProperties; |
97 | QMap<QtProperty *, int> m_fontSubPropertyToFlag; |
98 | PropertyToPropertyMap m_fontSubPropertyToProperty; |
99 | QtProperty *m_createdFontProperty = nullptr; |
100 | QStringList m_aliasingEnumNames; |
101 | // Font families with Designer annotations |
102 | QStringList m_designerFamilyNames; |
103 | NameMap m_familyMappings; |
104 | }; |
105 | |
106 | } |
107 | |
108 | QT_END_NAMESPACE |
109 | |
110 | #endif // FONTPROPERTYMANAGER_H |
111 | |