Changeset View
Changeset View
Standalone View
Standalone View
examples/window.cpp
Show All 16 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | * Boston, MA 02110-1301, USA. | 18 | * Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "window.h" | 21 | #include "window.h" | ||
22 | 22 | | |||
23 | #include <KProperty> | 23 | #include <KProperty> | ||
24 | #include <KPropertyEditorView> | 24 | #include <KPropertyEditorView> | ||
25 | #include <KPropertyUnit_p.h> | | |||
26 | 25 | | |||
27 | #include <QDate> | 26 | #include <QDate> | ||
28 | #include <QDateTime> | 27 | #include <QDateTime> | ||
29 | #include <QPixmap> | 28 | #include <QPixmap> | ||
30 | #include <QStringList> | 29 | #include <QStringList> | ||
31 | #include <QCursor> | 30 | #include <QCursor> | ||
32 | #include <QApplication> | 31 | #include <QApplication> | ||
33 | #include <QDesktopWidget> | 32 | #include <QDesktopWidget> | ||
Show All 37 Lines | 55 | { | |||
71 | } | 70 | } | ||
72 | 71 | | |||
73 | /* First, create a KPropertySet which will hold the properties. */ | 72 | /* First, create a KPropertySet which will hold the properties. */ | ||
74 | KProperty *p = 0; | 73 | KProperty *p = 0; | ||
75 | m_set.setReadOnly(m_parser.isSet(m_roOption)); | 74 | m_set.setReadOnly(m_parser.isSet(m_roOption)); | ||
76 | QByteArray group; | 75 | QByteArray group; | ||
77 | const bool addGroups = !m_parser.isSet(m_flatOption); | 76 | const bool addGroups = !m_parser.isSet(m_flatOption); | ||
78 | if (addGroups) { | 77 | if (addGroups) { | ||
79 | group = "SimpleGroup"; | 78 | group = "BasicGroup"; | ||
80 | m_set.setGroupCaption(group, "Simple Group"); | 79 | m_set.setGroupCaption(group, "Basic Properties"); | ||
81 | } | 80 | } | ||
82 | if (singleProperty.isEmpty() || singleProperty=="String") { | 81 | if (singleProperty.isEmpty() || singleProperty=="String") { | ||
83 | m_set.addProperty(p = new KProperty("String", "String"), group); | 82 | m_set.addProperty(p = new KProperty("String", "String"), group); | ||
84 | p->setValueSyncPolicy(KProperty::ValueSyncPolicy::Auto); | 83 | p->setValueSyncPolicy(KProperty::ValueSyncPolicy::Auto); | ||
85 | p->setReadOnly(false); // this should not work: | 84 | p->setReadOnly(false); // this should not work: | ||
86 | // - not needed if the property set is read-write | 85 | // - not needed if the property set is read-write | ||
87 | // - ignored if the property set is read-only | 86 | // - ignored if the property set is read-only | ||
88 | } | 87 | } | ||
89 | if (singleProperty.isEmpty() || singleProperty=="MultiLine") { | 88 | if (singleProperty.isEmpty() || singleProperty=="MultiLine") { | ||
90 | m_set.addProperty(p = new KProperty("MultiLine", "Multi\nLine\nContent"), group); | 89 | m_set.addProperty(p = new KProperty("MultiLine", "Multi\nLine\nContent"), group); | ||
91 | p->setValueSyncPolicy(KProperty::ValueSyncPolicy::Auto); | 90 | p->setValueSyncPolicy(KProperty::ValueSyncPolicy::Auto); | ||
92 | p->setOption("multiLine", true); | 91 | p->setOption("multiLine", true); | ||
93 | } | 92 | } | ||
94 | 93 | | |||
95 | if (singleProperty.isEmpty() || singleProperty=="Int") { | 94 | if (singleProperty.isEmpty() || singleProperty=="Int") { | ||
96 | m_set.addProperty(new KProperty("Int", 2, "Int"), group); | 95 | m_set.addProperty(new KProperty("Int", 2, "Int"), group); | ||
97 | } | 96 | } | ||
98 | if (singleProperty.isEmpty() || singleProperty=="Double") { | 97 | if (singleProperty.isEmpty() || singleProperty=="Double") { | ||
99 | m_set.addProperty(p = new KProperty("Double", 3.14159, "Double"), group); | 98 | m_set.addProperty(p = new KProperty("Double", 3.14159, "Double"), group); | ||
100 | p->setOption("precision", 4); // will round to 3.1416 | 99 | p->setOption("precision", 4); // will round to 3.1416 | ||
101 | } | 100 | } | ||
102 | if (singleProperty.isEmpty() || singleProperty=="cm") { | | |||
103 | const qreal cm = 1.0; // 28.3465058 points | | |||
104 | const qreal points = KPropertyUnit(KPropertyUnit::Type::Centimeter).fromUserValue(cm); | | |||
105 | m_set.addProperty(p = new KProperty("cm", points, "Double cm"), group); | | |||
106 | p->setOption("unit", "cm"); | | |||
107 | // default precision == 2 | | |||
108 | } | | |||
109 | if (singleProperty.isEmpty() || singleProperty=="Bool") { | 101 | if (singleProperty.isEmpty() || singleProperty=="Bool") { | ||
110 | m_set.addProperty(new KProperty("Bool", QVariant(true), "Bool"), group); | 102 | m_set.addProperty(new KProperty("Bool", QVariant(true), "Bool"), group); | ||
111 | } | 103 | } | ||
112 | if (singleProperty.isEmpty() || singleProperty=="NullBool") { | 104 | if (singleProperty.isEmpty() || singleProperty=="NullBool") { | ||
113 | m_set.addProperty(new KProperty("NullBool", QVariant(), "Null Bool", QString(), KProperty::Bool), group); | 105 | m_set.addProperty(new KProperty("NullBool", QVariant(), "Null Bool", QString(), KProperty::Bool), group); | ||
114 | } | 106 | } | ||
115 | if (singleProperty.isEmpty() || singleProperty=="3-State") { | 107 | if (singleProperty.isEmpty() || singleProperty=="3-State") { | ||
116 | m_set.addProperty(p = new KProperty("3-State", QVariant(), "3 States", QString(), | 108 | m_set.addProperty(p = new KProperty("3-State", QVariant(), "3 States", QString(), | ||
Show All 26 Lines | 131 | if (singleProperty.isEmpty() || singleProperty=="List2") { | |||
143 | keys.append(2); | 135 | keys.append(2); | ||
144 | keys.append(3); | 136 | keys.append(3); | ||
145 | KPropertyListData *listData = new KPropertyListData(keys, name_list); | 137 | KPropertyListData *listData = new KPropertyListData(keys, name_list); | ||
146 | m_set.addProperty(new KProperty("List2", listData, 3, "List 2"), group); | 138 | m_set.addProperty(new KProperty("List2", listData, 3, "List 2"), group); | ||
147 | } | 139 | } | ||
148 | 140 | | |||
149 | // Complex | 141 | // Complex | ||
150 | if (addGroups) { | 142 | if (addGroups) { | ||
151 | group = "ComplexGroup"; | 143 | group = "ComposedGroup"; | ||
152 | m_set.setGroupCaption(group, "Complex Group"); | 144 | m_set.setGroupCaption(group, "Composed Properties"); | ||
153 | } | | |||
154 | if (singleProperty.isEmpty() || singleProperty=="Rect") { | | |||
155 | m_set.addProperty(new KProperty("Rect", QRect(5,11,100,200), "Rect"), group); | | |||
156 | } | 145 | } | ||
157 | if (singleProperty.isEmpty() || singleProperty=="Point") { | 146 | if (singleProperty.isEmpty() || singleProperty=="Point") { | ||
158 | m_set.addProperty(new KProperty("Point", QPoint(3, 4), "Point"), group); | 147 | m_set.addProperty(new KProperty("Point", QPoint(3, 4), "Point"), group); | ||
159 | } | 148 | } | ||
160 | if (singleProperty.isEmpty() || singleProperty=="Size") { | 149 | if (singleProperty.isEmpty() || singleProperty=="Size") { | ||
161 | m_set.addProperty(new KProperty("Size", QSize(10, 20), "Size"), group); | 150 | m_set.addProperty(new KProperty("Size", QSize(10, 20), "Size"), group); | ||
162 | } | 151 | } | ||
163 | if (singleProperty.isEmpty() || singleProperty=="RectF") { | 152 | if (singleProperty.isEmpty() || singleProperty=="Rect") { | ||
164 | m_set.addProperty(new KProperty("RectF", QRectF(0.1, 0.5, 10.72, 18.21), "RectF"), group); | 153 | m_set.addProperty(new KProperty("Rect", QRect(5,11,100,200), "Rect"), group); | ||
165 | } | 154 | } | ||
166 | if (singleProperty.isEmpty() || singleProperty=="PointF") { | 155 | if (singleProperty.isEmpty() || singleProperty=="PointF") { | ||
167 | m_set.addProperty(new KProperty("PointF", QPointF(3.14, 4.15), "PointF"), group); | 156 | m_set.addProperty(new KProperty("PointF", QPointF(3.14, 4.15), "PointF"), group); | ||
168 | } | 157 | } | ||
169 | if (singleProperty.isEmpty() || singleProperty=="SizeF") { | 158 | if (singleProperty.isEmpty() || singleProperty=="SizeF") { | ||
170 | m_set.addProperty(new KProperty("SizeF", QSizeF(1.1, 2.45), "SizeF"), group); | 159 | m_set.addProperty(new KProperty("SizeF", QSizeF(1.1, 2.45), "SizeF"), group); | ||
171 | } | 160 | } | ||
161 | if (singleProperty.isEmpty() || singleProperty == "RectF") { | ||||
162 | m_set.addProperty( | ||||
163 | new KProperty("RectF", QRectF(0.1, 0.5, 10.72, 18.21), "RectF"), group); | ||||
164 | } | ||||
165 | | ||||
166 | // With suffixes and prefixes | ||||
167 | if (addGroups) { | ||||
168 | group = "PrefixesSuffixesGroup"; | ||||
169 | m_set.setGroupCaption(group, "Prefixes & Suffixes"); | ||||
170 | } | ||||
171 | if (singleProperty.isEmpty() || singleProperty=="dollars") { | ||||
172 | m_set.addProperty(p = new KProperty("dollars", 100, "Dollars"), group); | ||||
173 | p->setOption("prefix", "$"); | ||||
174 | } | ||||
175 | if (singleProperty.isEmpty() || singleProperty == "billions") { | ||||
176 | m_set.addProperty(p = new KProperty("billions", 5.0, "Billions"), group); | ||||
177 | p->setOption("prefix", "£"); | ||||
178 | p->setOption("suffix", "bn"); | ||||
179 | // default precision == 2 and step == 0.01 | ||||
180 | } | ||||
181 | if (singleProperty.isEmpty() || singleProperty == "PointF-mm") { | ||||
182 | m_set.addProperty( | ||||
183 | p = new KProperty("PointF-mm", QPointF(2.5, 3.5), "PointF [mm]"), group); | ||||
184 | p->setOption("suffix", "mm"); | ||||
185 | p->setOption("step", 0.1); | ||||
186 | p->setOption("precision", 2); | ||||
187 | } | ||||
188 | if (singleProperty.isEmpty() || singleProperty == "SizeF-dm") { | ||||
189 | m_set.addProperty( | ||||
190 | p = new KProperty("SizeF-dm", QSizeF(7.0, 6.5), "SizeF [dm]"), group); | ||||
191 | p->setOption("suffix", "dm"); | ||||
192 | p->setOption("step", 0.001); | ||||
193 | p->setOption("precision", 3); | ||||
194 | } | ||||
195 | if (singleProperty.isEmpty() || singleProperty=="RectF-px") { | ||||
196 | m_set.addProperty( | ||||
197 | p = new KProperty("RectF-px", QRectF(21.2, 22.2, 9.1, 1.0), "RectF [px]"), | ||||
198 | group); | ||||
199 | p->setOption("suffix", "px"); | ||||
200 | p->setOption("step", 0.1); | ||||
201 | p->setOption("precision", 1); | ||||
202 | } | ||||
172 | 203 | | |||
173 | // Appearance | 204 | // Appearance | ||
174 | if (addGroups) { | 205 | if (addGroups) { | ||
175 | group = "Appearance Group"; | 206 | group = "AppearanceGroup"; | ||
176 | m_set.setGroupCaption(group, "Appearance Group"); | 207 | m_set.setGroupCaption(group, "Appearance Group"); | ||
177 | m_set.setGroupIconName(group, "appearance"); | 208 | m_set.setGroupIconName(group, "appearance"); | ||
178 | } | 209 | } | ||
179 | if (singleProperty.isEmpty() || singleProperty=="Color") { | 210 | if (singleProperty.isEmpty() || singleProperty=="Color") { | ||
180 | m_set.addProperty(new KProperty("Color", palette().color(QPalette::Active, QPalette::Background), "Color"), group); | 211 | m_set.addProperty(new KProperty("Color", palette().color(QPalette::Active, QPalette::Background), "Color"), group); | ||
181 | } | 212 | } | ||
182 | if (singleProperty.isEmpty() || singleProperty=="Pixmap") { | 213 | if (singleProperty.isEmpty() || singleProperty=="Pixmap") { | ||
183 | QPixmap pm(QIcon::fromTheme("network-wired").pixmap(QSize(16,16))); | 214 | QPixmap pm(QIcon::fromTheme("network-wired").pixmap(QSize(16,16))); | ||
▲ Show 20 Lines • Show All 109 Lines • Show Last 20 Lines |