Changeset View
Changeset View
Standalone View
Standalone View
examples/window.cpp
1 | /* This file is part of the KDE project | 1 | /* This file is part of the KDE project | ||
---|---|---|---|---|---|
2 | Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr> | 2 | Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr> | ||
3 | Copyright (C) 2008-2016 Jarosław Staniek <staniek@kde.org> | 3 | Copyright (C) 2008-2017 Jarosław Staniek <staniek@kde.org> | ||
4 | 4 | | |||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. | ||
9 | 9 | | |||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | 67 | if (fontSize > 0 && ok) { | |||
69 | f.setPointSize(fontSize); | 69 | f.setPointSize(fontSize); | ||
70 | setFont(f); | 70 | setFont(f); | ||
71 | } | 71 | } | ||
72 | 72 | | |||
73 | /* First, create a KPropertySet which will hold the properties. */ | 73 | /* First, create a KPropertySet which will hold the properties. */ | ||
74 | KProperty *p = 0; | 74 | KProperty *p = 0; | ||
75 | m_set.setReadOnly(m_parser.isSet(m_roOption)); | 75 | m_set.setReadOnly(m_parser.isSet(m_roOption)); | ||
76 | QByteArray group; | 76 | QByteArray group; | ||
77 | if (!m_parser.isSet(m_flatOption)) { | 77 | const bool addGroups = !m_parser.isSet(m_flatOption); | ||
78 | if (addGroups) { | ||||
78 | group = "SimpleGroup"; | 79 | group = "SimpleGroup"; | ||
79 | m_set.setGroupCaption(group, "Simple Group"); | 80 | m_set.setGroupCaption(group, "Simple Group"); | ||
80 | } | 81 | } | ||
81 | if (singleProperty.isEmpty() || singleProperty=="String") { | 82 | if (singleProperty.isEmpty() || singleProperty=="String") { | ||
82 | m_set.addProperty(p = new KProperty("String", "String"), group); | 83 | m_set.addProperty(p = new KProperty("String", "String"), group); | ||
83 | p->setAutoSync(1); | 84 | p->setValueSyncPolicy(KProperty::ValueSyncPolicy::Auto); | ||
84 | p->setReadOnly(false); // this should not work: | 85 | p->setReadOnly(false); // this should not work: | ||
85 | // - not needed if the property set is read-write | 86 | // - not needed if the property set is read-write | ||
86 | // - ignored if the property set is read-only | 87 | // - ignored if the property set is read-only | ||
87 | } | 88 | } | ||
88 | if (singleProperty.isEmpty() || singleProperty=="MultiLine") { | 89 | if (singleProperty.isEmpty() || singleProperty=="MultiLine") { | ||
89 | m_set.addProperty(p = new KProperty("MultiLine", "Multi\nLine\nContent"), group); | 90 | m_set.addProperty(p = new KProperty("MultiLine", "Multi\nLine\nContent"), group); | ||
90 | p->setAutoSync(1); | 91 | p->setValueSyncPolicy(KProperty::ValueSyncPolicy::Auto); | ||
91 | p->setOption("multiLine", true); | 92 | p->setOption("multiLine", true); | ||
92 | } | 93 | } | ||
93 | 94 | | |||
94 | if (singleProperty.isEmpty() || singleProperty=="Int") { | 95 | if (singleProperty.isEmpty() || singleProperty=="Int") { | ||
95 | m_set.addProperty(new KProperty("Int", 2, "Int"), group); | 96 | m_set.addProperty(new KProperty("Int", 2, "Int"), group); | ||
96 | } | 97 | } | ||
97 | if (singleProperty.isEmpty() || singleProperty=="Double") { | 98 | if (singleProperty.isEmpty() || singleProperty=="Double") { | ||
98 | m_set.addProperty(p = new KProperty("Double", 3.14159, "Double"), group); | 99 | m_set.addProperty(p = new KProperty("Double", 3.14159, "Double"), group); | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 139 | if (singleProperty.isEmpty() || singleProperty=="List2") { | |||
141 | keys.append(1); | 142 | keys.append(1); | ||
142 | keys.append(2); | 143 | keys.append(2); | ||
143 | keys.append(3); | 144 | keys.append(3); | ||
144 | KPropertyListData *listData = new KPropertyListData(keys, name_list); | 145 | KPropertyListData *listData = new KPropertyListData(keys, name_list); | ||
145 | m_set.addProperty(new KProperty("List2", listData, 3, "List 2"), group); | 146 | m_set.addProperty(new KProperty("List2", listData, 3, "List 2"), group); | ||
146 | } | 147 | } | ||
147 | 148 | | |||
148 | // Complex | 149 | // Complex | ||
149 | if (!m_parser.isSet(m_flatOption)) { | 150 | if (addGroups) { | ||
150 | group = "ComplexGroup"; | 151 | group = "ComplexGroup"; | ||
151 | m_set.setGroupCaption(group, "Complex Group"); | 152 | m_set.setGroupCaption(group, "Complex Group"); | ||
152 | } | 153 | } | ||
153 | if (singleProperty.isEmpty() || singleProperty=="Rect") { | 154 | if (singleProperty.isEmpty() || singleProperty=="Rect") { | ||
154 | m_set.addProperty(new KProperty("Rect", QRect(5,11,100,200), "Rect"), group); | 155 | m_set.addProperty(new KProperty("Rect", QRect(5,11,100,200), "Rect"), group); | ||
155 | } | 156 | } | ||
156 | if (singleProperty.isEmpty() || singleProperty=="Point") { | 157 | if (singleProperty.isEmpty() || singleProperty=="Point") { | ||
157 | m_set.addProperty(new KProperty("Point", QPoint(3, 4), "Point"), group); | 158 | m_set.addProperty(new KProperty("Point", QPoint(3, 4), "Point"), group); | ||
158 | } | 159 | } | ||
159 | if (singleProperty.isEmpty() || singleProperty=="Size") { | 160 | if (singleProperty.isEmpty() || singleProperty=="Size") { | ||
160 | m_set.addProperty(new KProperty("Size", QSize(10, 20), "Size"), group); | 161 | m_set.addProperty(new KProperty("Size", QSize(10, 20), "Size"), group); | ||
161 | } | 162 | } | ||
162 | if (singleProperty.isEmpty() || singleProperty=="RectF") { | 163 | if (singleProperty.isEmpty() || singleProperty=="RectF") { | ||
163 | m_set.addProperty(new KProperty("RectF", QRectF(0.1, 0.5, 10.72, 18.21), "RectF"), group); | 164 | m_set.addProperty(new KProperty("RectF", QRectF(0.1, 0.5, 10.72, 18.21), "RectF"), group); | ||
164 | } | 165 | } | ||
165 | if (singleProperty.isEmpty() || singleProperty=="PointF") { | 166 | if (singleProperty.isEmpty() || singleProperty=="PointF") { | ||
166 | m_set.addProperty(new KProperty("PointF", QPointF(3.14, 4.15), "PointF"), group); | 167 | m_set.addProperty(new KProperty("PointF", QPointF(3.14, 4.15), "PointF"), group); | ||
167 | } | 168 | } | ||
168 | if (singleProperty.isEmpty() || singleProperty=="SizeF") { | 169 | if (singleProperty.isEmpty() || singleProperty=="SizeF") { | ||
169 | m_set.addProperty(new KProperty("SizeF", QSizeF(1.1, 2.45), "SizeF"), group); | 170 | m_set.addProperty(new KProperty("SizeF", QSizeF(1.1, 2.45), "SizeF"), group); | ||
170 | } | 171 | } | ||
171 | 172 | | |||
172 | // Appearance | 173 | // Appearance | ||
173 | if (!m_parser.isSet(m_flatOption)) { | 174 | if (addGroups) { | ||
174 | group = "Appearance Group"; | 175 | group = "Appearance Group"; | ||
175 | m_set.setGroupCaption(group, "Appearance Group"); | 176 | m_set.setGroupCaption(group, "Appearance Group"); | ||
176 | m_set.setGroupIconName(group, "appearance"); | 177 | m_set.setGroupIconName(group, "appearance"); | ||
177 | } | 178 | } | ||
178 | if (singleProperty.isEmpty() || singleProperty=="Color") { | 179 | if (singleProperty.isEmpty() || singleProperty=="Color") { | ||
179 | m_set.addProperty(new KProperty("Color", palette().color(QPalette::Active, QPalette::Background), "Color"), group); | 180 | m_set.addProperty(new KProperty("Color", palette().color(QPalette::Active, QPalette::Background), "Color"), group); | ||
180 | } | 181 | } | ||
181 | if (singleProperty.isEmpty() || singleProperty=="Pixmap") { | 182 | if (singleProperty.isEmpty() || singleProperty=="Pixmap") { | ||
Show All 40 Lines | 222 | if (singleProperty.isEmpty() || singleProperty=="Dir") { | |||
222 | m_set.addProperty(p = new KProperty("Dir", QUrl::fromLocalFile(QDir::homePath()), "Dir"), group); | 223 | m_set.addProperty(p = new KProperty("Dir", QUrl::fromLocalFile(QDir::homePath()), "Dir"), group); | ||
223 | p->setOption("fileMode", "dirsOnly"); | 224 | p->setOption("fileMode", "dirsOnly"); | ||
224 | } | 225 | } | ||
225 | if (singleProperty.isEmpty() || singleProperty=="ReadOnly") { | 226 | if (singleProperty.isEmpty() || singleProperty=="ReadOnly") { | ||
226 | m_set.addProperty(p = new KProperty("Read-Only", "Read-only string"), group); | 227 | m_set.addProperty(p = new KProperty("Read-Only", "Read-only string"), group); | ||
227 | p->setReadOnly(true); | 228 | p->setReadOnly(true); | ||
228 | } | 229 | } | ||
229 | 230 | | |||
230 | // qDebug() << m_set.groupNames(); | | |||
231 | QVBoxLayout *lyr = new QVBoxLayout(this); | 231 | QVBoxLayout *lyr = new QVBoxLayout(this); | ||
232 | m_editorView = new KPropertyEditorView(this); | 232 | m_editorView = new KPropertyEditorView(this); | ||
233 | lyr->addWidget(m_editorView); | 233 | lyr->addWidget(m_editorView); | ||
234 | m_editorView->changeSet(&m_set, KPropertyEditorView::ExpandChildItems); | 234 | m_editorView->changeSet(&m_set); | ||
235 | lyr->addSpacing(lyr->spacing()); | 235 | lyr->addSpacing(lyr->spacing()); | ||
236 | 236 | | |||
237 | QHBoxLayout *hlyr = new QHBoxLayout; | 237 | QHBoxLayout *hlyr = new QHBoxLayout; | ||
238 | lyr->addLayout(hlyr); | 238 | lyr->addLayout(hlyr); | ||
239 | 239 | | |||
240 | m_showGrid = new QCheckBox("Show grid"); | 240 | QCheckBox *showGrid = new QCheckBox("Show grid"); | ||
241 | m_showGrid->setChecked(true); | 241 | showGrid->setChecked(true); | ||
242 | connect(m_showGrid, &QCheckBox::stateChanged, this, &Window::showGrid); | 242 | connect(showGrid, &QCheckBox::stateChanged, this, &Window::showGrid); | ||
243 | hlyr->addWidget(m_showGrid); | 243 | hlyr->addWidget(showGrid); | ||
244 | 244 | | |||
245 | m_showFrame = new QCheckBox("Show frame"); | 245 | QCheckBox *showFrame = new QCheckBox("Show frame"); | ||
246 | m_showFrame->setChecked(true); | 246 | showFrame->setChecked(true); | ||
247 | connect(m_showFrame, &QCheckBox::stateChanged, this, &Window::showFrame); | 247 | connect(showFrame, &QCheckBox::stateChanged, this, &Window::showFrame); | ||
248 | hlyr->addWidget(m_showFrame); | 248 | hlyr->addWidget(showFrame); | ||
249 | | ||||
250 | QCheckBox *showGroups = new QCheckBox("Show groups"); | ||||
251 | if (addGroups) { | ||||
252 | connect(showGroups, &QCheckBox::toggled, m_editorView, &KPropertyEditorView::setGroupsVisible); | ||||
253 | showGroups->setChecked(m_editorView->groupsVisible()); | ||||
254 | } else { | ||||
255 | showGroups->setEnabled(false); | ||||
256 | } | ||||
257 | hlyr->addWidget(showGroups); | ||||
249 | 258 | | |||
250 | QCheckBox *readOnly = new QCheckBox("Read-only"); | 259 | QCheckBox *readOnly = new QCheckBox("Read-only"); | ||
251 | connect(readOnly, &QCheckBox::toggled, &m_set, &KPropertySet::setReadOnly); | 260 | connect(readOnly, &QCheckBox::toggled, &m_set, &KPropertySet::setReadOnly); | ||
252 | readOnly->setChecked(m_set.isReadOnly()); | 261 | readOnly->setChecked(m_set.isReadOnly()); | ||
253 | hlyr->addWidget(readOnly); | 262 | hlyr->addWidget(readOnly); | ||
254 | 263 | | |||
255 | hlyr->addStretch(1); | 264 | hlyr->addStretch(1); | ||
256 | resize(400, qApp->desktop()->height() - 200); | 265 | resize(400, qApp->desktop()->height() - 200); | ||
Show All 27 Lines |