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 tools applications of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
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 Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qteditorfactory.h" |
41 | #include "qtpropertybrowserutils_p.h" |
42 | #include <QtWidgets/QSpinBox> |
43 | #include <QtWidgets/QScrollBar> |
44 | #include <QtWidgets/QComboBox> |
45 | #include <QtWidgets/QAbstractItemView> |
46 | #include <QtWidgets/QLineEdit> |
47 | #include <QtWidgets/QDateTimeEdit> |
48 | #include <QtWidgets/QHBoxLayout> |
49 | #include <QtWidgets/QMenu> |
50 | #include <QtGui/QKeyEvent> |
51 | #include <QtWidgets/QApplication> |
52 | #include <QtWidgets/QLabel> |
53 | #include <QtWidgets/QToolButton> |
54 | #include <QtWidgets/QColorDialog> |
55 | #include <QtWidgets/QFontDialog> |
56 | #include <QtWidgets/QSpacerItem> |
57 | #include <QtWidgets/QKeySequenceEdit> |
58 | #include <QtCore/QMap> |
59 | |
60 | #if defined(Q_CC_MSVC) |
61 | # pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */ |
62 | #endif |
63 | |
64 | QT_BEGIN_NAMESPACE |
65 | |
66 | // Set a hard coded left margin to account for the indentation |
67 | // of the tree view icon when switching to an editor |
68 | |
69 | static inline void setupTreeViewEditorMargin(QLayout *lt) |
70 | { |
71 | enum { DecorationMargin = 4 }; |
72 | if (QApplication::layoutDirection() == Qt::LeftToRight) |
73 | lt->setContentsMargins(left: DecorationMargin, top: 0, right: 0, bottom: 0); |
74 | else |
75 | lt->setContentsMargins(left: 0, top: 0, right: DecorationMargin, bottom: 0); |
76 | } |
77 | |
78 | // ---------- EditorFactoryPrivate : |
79 | // Base class for editor factory private classes. Manages mapping of properties to editors and vice versa. |
80 | |
81 | template <class Editor> |
82 | class EditorFactoryPrivate |
83 | { |
84 | public: |
85 | |
86 | typedef QList<Editor *> EditorList; |
87 | typedef QMap<QtProperty *, EditorList> PropertyToEditorListMap; |
88 | typedef QMap<Editor *, QtProperty *> EditorToPropertyMap; |
89 | |
90 | Editor *createEditor(QtProperty *property, QWidget *parent); |
91 | void initializeEditor(QtProperty *property, Editor *e); |
92 | void slotEditorDestroyed(QObject *object); |
93 | |
94 | PropertyToEditorListMap m_createdEditors; |
95 | EditorToPropertyMap m_editorToProperty; |
96 | }; |
97 | |
98 | template <class Editor> |
99 | Editor *EditorFactoryPrivate<Editor>::createEditor(QtProperty *property, QWidget *parent) |
100 | { |
101 | Editor *editor = new Editor(parent); |
102 | initializeEditor(property, e: editor); |
103 | return editor; |
104 | } |
105 | |
106 | template <class Editor> |
107 | void EditorFactoryPrivate<Editor>::initializeEditor(QtProperty *property, Editor *editor) |
108 | { |
109 | typename PropertyToEditorListMap::iterator it = m_createdEditors.find(property); |
110 | if (it == m_createdEditors.end()) |
111 | it = m_createdEditors.insert(property, EditorList()); |
112 | it.value().append(editor); |
113 | m_editorToProperty.insert(editor, property); |
114 | } |
115 | |
116 | template <class Editor> |
117 | void EditorFactoryPrivate<Editor>::slotEditorDestroyed(QObject *object) |
118 | { |
119 | const typename EditorToPropertyMap::iterator ecend = m_editorToProperty.end(); |
120 | for (typename EditorToPropertyMap::iterator itEditor = m_editorToProperty.begin(); itEditor != ecend; ++itEditor) { |
121 | if (itEditor.key() == object) { |
122 | Editor *editor = itEditor.key(); |
123 | QtProperty *property = itEditor.value(); |
124 | const typename PropertyToEditorListMap::iterator pit = m_createdEditors.find(property); |
125 | if (pit != m_createdEditors.end()) { |
126 | pit.value().removeAll(editor); |
127 | if (pit.value().isEmpty()) |
128 | m_createdEditors.erase(pit); |
129 | } |
130 | m_editorToProperty.erase(itEditor); |
131 | return; |
132 | } |
133 | } |
134 | } |
135 | |
136 | // ------------ QtSpinBoxFactory |
137 | |
138 | class QtSpinBoxFactoryPrivate : public EditorFactoryPrivate<QSpinBox> |
139 | { |
140 | QtSpinBoxFactory *q_ptr; |
141 | Q_DECLARE_PUBLIC(QtSpinBoxFactory) |
142 | public: |
143 | |
144 | void slotPropertyChanged(QtProperty *property, int value); |
145 | void slotRangeChanged(QtProperty *property, int min, int max); |
146 | void slotSingleStepChanged(QtProperty *property, int step); |
147 | void slotSetValue(int value); |
148 | }; |
149 | |
150 | void QtSpinBoxFactoryPrivate::slotPropertyChanged(QtProperty *property, int value) |
151 | { |
152 | const auto it = m_createdEditors.constFind(akey: property); |
153 | if (it == m_createdEditors.cend()) |
154 | return; |
155 | for (QSpinBox *editor : it.value()) { |
156 | if (editor->value() != value) { |
157 | editor->blockSignals(b: true); |
158 | editor->setValue(value); |
159 | editor->blockSignals(b: false); |
160 | } |
161 | } |
162 | } |
163 | |
164 | void QtSpinBoxFactoryPrivate::slotRangeChanged(QtProperty *property, int min, int max) |
165 | { |
166 | const auto it = m_createdEditors.constFind(akey: property); |
167 | if (it == m_createdEditors.cend()) |
168 | return; |
169 | |
170 | QtIntPropertyManager *manager = q_ptr->propertyManager(property); |
171 | if (!manager) |
172 | return; |
173 | |
174 | for (QSpinBox *editor : it.value()) { |
175 | editor->blockSignals(b: true); |
176 | editor->setRange(min, max); |
177 | editor->setValue(manager->value(property)); |
178 | editor->blockSignals(b: false); |
179 | } |
180 | } |
181 | |
182 | void QtSpinBoxFactoryPrivate::slotSingleStepChanged(QtProperty *property, int step) |
183 | { |
184 | const auto it = m_createdEditors.constFind(akey: property); |
185 | if (it == m_createdEditors.cend()) |
186 | return; |
187 | for (QSpinBox *editor : it.value()) { |
188 | editor->blockSignals(b: true); |
189 | editor->setSingleStep(step); |
190 | editor->blockSignals(b: false); |
191 | } |
192 | } |
193 | |
194 | void QtSpinBoxFactoryPrivate::slotSetValue(int value) |
195 | { |
196 | QObject *object = q_ptr->sender(); |
197 | const QMap<QSpinBox *, QtProperty *>::ConstIterator ecend = m_editorToProperty.constEnd(); |
198 | for (QMap<QSpinBox *, QtProperty *>::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) { |
199 | if (itEditor.key() == object) { |
200 | QtProperty *property = itEditor.value(); |
201 | QtIntPropertyManager *manager = q_ptr->propertyManager(property); |
202 | if (!manager) |
203 | return; |
204 | manager->setValue(property, val: value); |
205 | return; |
206 | } |
207 | } |
208 | } |
209 | |
210 | /*! |
211 | \class QtSpinBoxFactory |
212 | \internal |
213 | \inmodule QtDesigner |
214 | \since 4.4 |
215 | |
216 | \brief The QtSpinBoxFactory class provides QSpinBox widgets for |
217 | properties created by QtIntPropertyManager objects. |
218 | |
219 | \sa QtAbstractEditorFactory, QtIntPropertyManager |
220 | */ |
221 | |
222 | /*! |
223 | Creates a factory with the given \a parent. |
224 | */ |
225 | QtSpinBoxFactory::QtSpinBoxFactory(QObject *parent) |
226 | : QtAbstractEditorFactory<QtIntPropertyManager>(parent), d_ptr(new QtSpinBoxFactoryPrivate()) |
227 | { |
228 | d_ptr->q_ptr = this; |
229 | |
230 | } |
231 | |
232 | /*! |
233 | Destroys this factory, and all the widgets it has created. |
234 | */ |
235 | QtSpinBoxFactory::~QtSpinBoxFactory() |
236 | { |
237 | qDeleteAll(c: d_ptr->m_editorToProperty.keys()); |
238 | } |
239 | |
240 | /*! |
241 | \internal |
242 | |
243 | Reimplemented from the QtAbstractEditorFactory class. |
244 | */ |
245 | void QtSpinBoxFactory::connectPropertyManager(QtIntPropertyManager *manager) |
246 | { |
247 | connect(sender: manager, SIGNAL(valueChanged(QtProperty*,int)), |
248 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,int))); |
249 | connect(sender: manager, SIGNAL(rangeChanged(QtProperty*,int,int)), |
250 | receiver: this, SLOT(slotRangeChanged(QtProperty*,int,int))); |
251 | connect(sender: manager, SIGNAL(singleStepChanged(QtProperty*,int)), |
252 | receiver: this, SLOT(slotSingleStepChanged(QtProperty*,int))); |
253 | } |
254 | |
255 | /*! |
256 | \internal |
257 | |
258 | Reimplemented from the QtAbstractEditorFactory class. |
259 | */ |
260 | QWidget *QtSpinBoxFactory::createEditor(QtIntPropertyManager *manager, QtProperty *property, |
261 | QWidget *parent) |
262 | { |
263 | QSpinBox *editor = d_ptr->createEditor(property, parent); |
264 | editor->setSingleStep(manager->singleStep(property)); |
265 | editor->setRange(min: manager->minimum(property), max: manager->maximum(property)); |
266 | editor->setValue(manager->value(property)); |
267 | editor->setKeyboardTracking(false); |
268 | |
269 | connect(sender: editor, SIGNAL(valueChanged(int)), receiver: this, SLOT(slotSetValue(int))); |
270 | connect(sender: editor, SIGNAL(destroyed(QObject*)), |
271 | receiver: this, SLOT(slotEditorDestroyed(QObject*))); |
272 | return editor; |
273 | } |
274 | |
275 | /*! |
276 | \internal |
277 | |
278 | Reimplemented from the QtAbstractEditorFactory class. |
279 | */ |
280 | void QtSpinBoxFactory::disconnectPropertyManager(QtIntPropertyManager *manager) |
281 | { |
282 | disconnect(sender: manager, SIGNAL(valueChanged(QtProperty*,int)), |
283 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,int))); |
284 | disconnect(sender: manager, SIGNAL(rangeChanged(QtProperty*,int,int)), |
285 | receiver: this, SLOT(slotRangeChanged(QtProperty*,int,int))); |
286 | disconnect(sender: manager, SIGNAL(singleStepChanged(QtProperty*,int)), |
287 | receiver: this, SLOT(slotSingleStepChanged(QtProperty*,int))); |
288 | } |
289 | |
290 | // QtSliderFactory |
291 | |
292 | class QtSliderFactoryPrivate : public EditorFactoryPrivate<QSlider> |
293 | { |
294 | QtSliderFactory *q_ptr; |
295 | Q_DECLARE_PUBLIC(QtSliderFactory) |
296 | public: |
297 | void slotPropertyChanged(QtProperty *property, int value); |
298 | void slotRangeChanged(QtProperty *property, int min, int max); |
299 | void slotSingleStepChanged(QtProperty *property, int step); |
300 | void slotSetValue(int value); |
301 | }; |
302 | |
303 | void QtSliderFactoryPrivate::slotPropertyChanged(QtProperty *property, int value) |
304 | { |
305 | const auto it = m_createdEditors.constFind(akey: property); |
306 | if (it == m_createdEditors.cend()) |
307 | return; |
308 | for (QSlider *editor : it.value()) { |
309 | editor->blockSignals(b: true); |
310 | editor->setValue(value); |
311 | editor->blockSignals(b: false); |
312 | } |
313 | } |
314 | |
315 | void QtSliderFactoryPrivate::slotRangeChanged(QtProperty *property, int min, int max) |
316 | { |
317 | const auto it = m_createdEditors.constFind(akey: property); |
318 | if (it == m_createdEditors.cend()) |
319 | return; |
320 | |
321 | QtIntPropertyManager *manager = q_ptr->propertyManager(property); |
322 | if (!manager) |
323 | return; |
324 | |
325 | for (QSlider *editor : it.value()) { |
326 | editor->blockSignals(b: true); |
327 | editor->setRange(min, max); |
328 | editor->setValue(manager->value(property)); |
329 | editor->blockSignals(b: false); |
330 | } |
331 | } |
332 | |
333 | void QtSliderFactoryPrivate::slotSingleStepChanged(QtProperty *property, int step) |
334 | { |
335 | const auto it = m_createdEditors.constFind(akey: property); |
336 | if (it == m_createdEditors.cend()) |
337 | return; |
338 | for (QSlider *editor : it.value()) { |
339 | editor->blockSignals(b: true); |
340 | editor->setSingleStep(step); |
341 | editor->blockSignals(b: false); |
342 | } |
343 | } |
344 | |
345 | void QtSliderFactoryPrivate::slotSetValue(int value) |
346 | { |
347 | QObject *object = q_ptr->sender(); |
348 | const QMap<QSlider *, QtProperty *>::ConstIterator ecend = m_editorToProperty.constEnd(); |
349 | for (QMap<QSlider *, QtProperty *>::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor ) { |
350 | if (itEditor.key() == object) { |
351 | QtProperty *property = itEditor.value(); |
352 | QtIntPropertyManager *manager = q_ptr->propertyManager(property); |
353 | if (!manager) |
354 | return; |
355 | manager->setValue(property, val: value); |
356 | return; |
357 | } |
358 | } |
359 | } |
360 | |
361 | /*! |
362 | \class QtSliderFactory |
363 | \internal |
364 | \inmodule QtDesigner |
365 | \since 4.4 |
366 | |
367 | \brief The QtSliderFactory class provides QSlider widgets for |
368 | properties created by QtIntPropertyManager objects. |
369 | |
370 | \sa QtAbstractEditorFactory, QtIntPropertyManager |
371 | */ |
372 | |
373 | /*! |
374 | Creates a factory with the given \a parent. |
375 | */ |
376 | QtSliderFactory::QtSliderFactory(QObject *parent) |
377 | : QtAbstractEditorFactory<QtIntPropertyManager>(parent), d_ptr(new QtSliderFactoryPrivate()) |
378 | { |
379 | d_ptr->q_ptr = this; |
380 | |
381 | } |
382 | |
383 | /*! |
384 | Destroys this factory, and all the widgets it has created. |
385 | */ |
386 | QtSliderFactory::~QtSliderFactory() |
387 | { |
388 | qDeleteAll(c: d_ptr->m_editorToProperty.keys()); |
389 | } |
390 | |
391 | /*! |
392 | \internal |
393 | |
394 | Reimplemented from the QtAbstractEditorFactory class. |
395 | */ |
396 | void QtSliderFactory::connectPropertyManager(QtIntPropertyManager *manager) |
397 | { |
398 | connect(sender: manager, SIGNAL(valueChanged(QtProperty*,int)), |
399 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,int))); |
400 | connect(sender: manager, SIGNAL(rangeChanged(QtProperty*,int,int)), |
401 | receiver: this, SLOT(slotRangeChanged(QtProperty*,int,int))); |
402 | connect(sender: manager, SIGNAL(singleStepChanged(QtProperty*,int)), |
403 | receiver: this, SLOT(slotSingleStepChanged(QtProperty*,int))); |
404 | } |
405 | |
406 | /*! |
407 | \internal |
408 | |
409 | Reimplemented from the QtAbstractEditorFactory class. |
410 | */ |
411 | QWidget *QtSliderFactory::createEditor(QtIntPropertyManager *manager, QtProperty *property, |
412 | QWidget *parent) |
413 | { |
414 | QSlider *editor = new QSlider(Qt::Horizontal, parent); |
415 | d_ptr->initializeEditor(property, editor); |
416 | editor->setSingleStep(manager->singleStep(property)); |
417 | editor->setRange(min: manager->minimum(property), max: manager->maximum(property)); |
418 | editor->setValue(manager->value(property)); |
419 | |
420 | connect(sender: editor, SIGNAL(valueChanged(int)), receiver: this, SLOT(slotSetValue(int))); |
421 | connect(sender: editor, SIGNAL(destroyed(QObject*)), |
422 | receiver: this, SLOT(slotEditorDestroyed(QObject*))); |
423 | return editor; |
424 | } |
425 | |
426 | /*! |
427 | \internal |
428 | |
429 | Reimplemented from the QtAbstractEditorFactory class. |
430 | */ |
431 | void QtSliderFactory::disconnectPropertyManager(QtIntPropertyManager *manager) |
432 | { |
433 | disconnect(sender: manager, SIGNAL(valueChanged(QtProperty*,int)), |
434 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,int))); |
435 | disconnect(sender: manager, SIGNAL(rangeChanged(QtProperty*,int,int)), |
436 | receiver: this, SLOT(slotRangeChanged(QtProperty*,int,int))); |
437 | disconnect(sender: manager, SIGNAL(singleStepChanged(QtProperty*,int)), |
438 | receiver: this, SLOT(slotSingleStepChanged(QtProperty*,int))); |
439 | } |
440 | |
441 | // QtSliderFactory |
442 | |
443 | class QtScrollBarFactoryPrivate : public EditorFactoryPrivate<QScrollBar> |
444 | { |
445 | QtScrollBarFactory *q_ptr; |
446 | Q_DECLARE_PUBLIC(QtScrollBarFactory) |
447 | public: |
448 | void slotPropertyChanged(QtProperty *property, int value); |
449 | void slotRangeChanged(QtProperty *property, int min, int max); |
450 | void slotSingleStepChanged(QtProperty *property, int step); |
451 | void slotSetValue(int value); |
452 | }; |
453 | |
454 | void QtScrollBarFactoryPrivate::slotPropertyChanged(QtProperty *property, int value) |
455 | { |
456 | const auto it = m_createdEditors.constFind(akey: property); |
457 | if (it == m_createdEditors.cend()) |
458 | return; |
459 | |
460 | for (QScrollBar *editor : it.value()) { |
461 | editor->blockSignals(b: true); |
462 | editor->setValue(value); |
463 | editor->blockSignals(b: false); |
464 | } |
465 | } |
466 | |
467 | void QtScrollBarFactoryPrivate::slotRangeChanged(QtProperty *property, int min, int max) |
468 | { |
469 | const auto it = m_createdEditors.constFind(akey: property); |
470 | if (it == m_createdEditors.cend()) |
471 | return; |
472 | |
473 | QtIntPropertyManager *manager = q_ptr->propertyManager(property); |
474 | if (!manager) |
475 | return; |
476 | |
477 | for (QScrollBar *editor : it.value()) { |
478 | editor->blockSignals(b: true); |
479 | editor->setRange(min, max); |
480 | editor->setValue(manager->value(property)); |
481 | editor->blockSignals(b: false); |
482 | } |
483 | } |
484 | |
485 | void QtScrollBarFactoryPrivate::slotSingleStepChanged(QtProperty *property, int step) |
486 | { |
487 | const auto it = m_createdEditors.constFind(akey: property); |
488 | if (it == m_createdEditors.cend()) |
489 | return; |
490 | for (QScrollBar *editor : it.value()) { |
491 | editor->blockSignals(b: true); |
492 | editor->setSingleStep(step); |
493 | editor->blockSignals(b: false); |
494 | } |
495 | } |
496 | |
497 | void QtScrollBarFactoryPrivate::slotSetValue(int value) |
498 | { |
499 | QObject *object = q_ptr->sender(); |
500 | const QMap<QScrollBar *, QtProperty *>::ConstIterator ecend = m_editorToProperty.constEnd(); |
501 | for (QMap<QScrollBar *, QtProperty *>::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) |
502 | if (itEditor.key() == object) { |
503 | QtProperty *property = itEditor.value(); |
504 | QtIntPropertyManager *manager = q_ptr->propertyManager(property); |
505 | if (!manager) |
506 | return; |
507 | manager->setValue(property, val: value); |
508 | return; |
509 | } |
510 | } |
511 | |
512 | /*! |
513 | \class QtScrollBarFactory |
514 | \internal |
515 | \inmodule QtDesigner |
516 | \since 4.4 |
517 | |
518 | \brief The QtScrollBarFactory class provides QScrollBar widgets for |
519 | properties created by QtIntPropertyManager objects. |
520 | |
521 | \sa QtAbstractEditorFactory, QtIntPropertyManager |
522 | */ |
523 | |
524 | /*! |
525 | Creates a factory with the given \a parent. |
526 | */ |
527 | QtScrollBarFactory::QtScrollBarFactory(QObject *parent) |
528 | : QtAbstractEditorFactory<QtIntPropertyManager>(parent), d_ptr(new QtScrollBarFactoryPrivate()) |
529 | { |
530 | d_ptr->q_ptr = this; |
531 | |
532 | } |
533 | |
534 | /*! |
535 | Destroys this factory, and all the widgets it has created. |
536 | */ |
537 | QtScrollBarFactory::~QtScrollBarFactory() |
538 | { |
539 | qDeleteAll(c: d_ptr->m_editorToProperty.keys()); |
540 | } |
541 | |
542 | /*! |
543 | \internal |
544 | |
545 | Reimplemented from the QtAbstractEditorFactory class. |
546 | */ |
547 | void QtScrollBarFactory::connectPropertyManager(QtIntPropertyManager *manager) |
548 | { |
549 | connect(sender: manager, SIGNAL(valueChanged(QtProperty*,int)), |
550 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,int))); |
551 | connect(sender: manager, SIGNAL(rangeChanged(QtProperty*,int,int)), |
552 | receiver: this, SLOT(slotRangeChanged(QtProperty*,int,int))); |
553 | connect(sender: manager, SIGNAL(singleStepChanged(QtProperty*,int)), |
554 | receiver: this, SLOT(slotSingleStepChanged(QtProperty*,int))); |
555 | } |
556 | |
557 | /*! |
558 | \internal |
559 | |
560 | Reimplemented from the QtAbstractEditorFactory class. |
561 | */ |
562 | QWidget *QtScrollBarFactory::createEditor(QtIntPropertyManager *manager, QtProperty *property, |
563 | QWidget *parent) |
564 | { |
565 | QScrollBar *editor = new QScrollBar(Qt::Horizontal, parent); |
566 | d_ptr->initializeEditor(property, editor); |
567 | editor->setSingleStep(manager->singleStep(property)); |
568 | editor->setRange(min: manager->minimum(property), max: manager->maximum(property)); |
569 | editor->setValue(manager->value(property)); |
570 | connect(sender: editor, SIGNAL(valueChanged(int)), receiver: this, SLOT(slotSetValue(int))); |
571 | connect(sender: editor, SIGNAL(destroyed(QObject*)), |
572 | receiver: this, SLOT(slotEditorDestroyed(QObject*))); |
573 | return editor; |
574 | } |
575 | |
576 | /*! |
577 | \internal |
578 | |
579 | Reimplemented from the QtAbstractEditorFactory class. |
580 | */ |
581 | void QtScrollBarFactory::disconnectPropertyManager(QtIntPropertyManager *manager) |
582 | { |
583 | disconnect(sender: manager, SIGNAL(valueChanged(QtProperty*,int)), |
584 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,int))); |
585 | disconnect(sender: manager, SIGNAL(rangeChanged(QtProperty*,int,int)), |
586 | receiver: this, SLOT(slotRangeChanged(QtProperty*,int,int))); |
587 | disconnect(sender: manager, SIGNAL(singleStepChanged(QtProperty*,int)), |
588 | receiver: this, SLOT(slotSingleStepChanged(QtProperty*,int))); |
589 | } |
590 | |
591 | // QtCheckBoxFactory |
592 | |
593 | class QtCheckBoxFactoryPrivate : public EditorFactoryPrivate<QtBoolEdit> |
594 | { |
595 | QtCheckBoxFactory *q_ptr; |
596 | Q_DECLARE_PUBLIC(QtCheckBoxFactory) |
597 | public: |
598 | void slotPropertyChanged(QtProperty *property, bool value); |
599 | void slotSetValue(bool value); |
600 | }; |
601 | |
602 | void QtCheckBoxFactoryPrivate::slotPropertyChanged(QtProperty *property, bool value) |
603 | { |
604 | const auto it = m_createdEditors.constFind(akey: property); |
605 | if (it == m_createdEditors.cend()) |
606 | return; |
607 | |
608 | for (QtBoolEdit *editor : it.value()) { |
609 | editor->blockCheckBoxSignals(block: true); |
610 | editor->setChecked(value); |
611 | editor->blockCheckBoxSignals(block: false); |
612 | } |
613 | } |
614 | |
615 | void QtCheckBoxFactoryPrivate::slotSetValue(bool value) |
616 | { |
617 | QObject *object = q_ptr->sender(); |
618 | |
619 | const QMap<QtBoolEdit *, QtProperty *>::ConstIterator ecend = m_editorToProperty.constEnd(); |
620 | for (QMap<QtBoolEdit *, QtProperty *>::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) |
621 | if (itEditor.key() == object) { |
622 | QtProperty *property = itEditor.value(); |
623 | QtBoolPropertyManager *manager = q_ptr->propertyManager(property); |
624 | if (!manager) |
625 | return; |
626 | manager->setValue(property, val: value); |
627 | return; |
628 | } |
629 | } |
630 | |
631 | /*! |
632 | \class QtCheckBoxFactory |
633 | \internal |
634 | \inmodule QtDesigner |
635 | \since 4.4 |
636 | |
637 | \brief The QtCheckBoxFactory class provides QCheckBox widgets for |
638 | properties created by QtBoolPropertyManager objects. |
639 | |
640 | \sa QtAbstractEditorFactory, QtBoolPropertyManager |
641 | */ |
642 | |
643 | /*! |
644 | Creates a factory with the given \a parent. |
645 | */ |
646 | QtCheckBoxFactory::QtCheckBoxFactory(QObject *parent) |
647 | : QtAbstractEditorFactory<QtBoolPropertyManager>(parent), d_ptr(new QtCheckBoxFactoryPrivate()) |
648 | { |
649 | d_ptr->q_ptr = this; |
650 | |
651 | } |
652 | |
653 | /*! |
654 | Destroys this factory, and all the widgets it has created. |
655 | */ |
656 | QtCheckBoxFactory::~QtCheckBoxFactory() |
657 | { |
658 | qDeleteAll(c: d_ptr->m_editorToProperty.keys()); |
659 | } |
660 | |
661 | /*! |
662 | \internal |
663 | |
664 | Reimplemented from the QtAbstractEditorFactory class. |
665 | */ |
666 | void QtCheckBoxFactory::connectPropertyManager(QtBoolPropertyManager *manager) |
667 | { |
668 | connect(sender: manager, SIGNAL(valueChanged(QtProperty*,bool)), |
669 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,bool))); |
670 | } |
671 | |
672 | /*! |
673 | \internal |
674 | |
675 | Reimplemented from the QtAbstractEditorFactory class. |
676 | */ |
677 | QWidget *QtCheckBoxFactory::createEditor(QtBoolPropertyManager *manager, QtProperty *property, |
678 | QWidget *parent) |
679 | { |
680 | QtBoolEdit *editor = d_ptr->createEditor(property, parent); |
681 | editor->setChecked(manager->value(property)); |
682 | |
683 | connect(sender: editor, SIGNAL(toggled(bool)), receiver: this, SLOT(slotSetValue(bool))); |
684 | connect(sender: editor, SIGNAL(destroyed(QObject*)), |
685 | receiver: this, SLOT(slotEditorDestroyed(QObject*))); |
686 | return editor; |
687 | } |
688 | |
689 | /*! |
690 | \internal |
691 | |
692 | Reimplemented from the QtAbstractEditorFactory class. |
693 | */ |
694 | void QtCheckBoxFactory::disconnectPropertyManager(QtBoolPropertyManager *manager) |
695 | { |
696 | disconnect(sender: manager, SIGNAL(valueChanged(QtProperty*,bool)), |
697 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,bool))); |
698 | } |
699 | |
700 | // QtDoubleSpinBoxFactory |
701 | |
702 | class QtDoubleSpinBoxFactoryPrivate : public EditorFactoryPrivate<QDoubleSpinBox> |
703 | { |
704 | QtDoubleSpinBoxFactory *q_ptr; |
705 | Q_DECLARE_PUBLIC(QtDoubleSpinBoxFactory) |
706 | public: |
707 | |
708 | void slotPropertyChanged(QtProperty *property, double value); |
709 | void slotRangeChanged(QtProperty *property, double min, double max); |
710 | void slotSingleStepChanged(QtProperty *property, double step); |
711 | void slotDecimalsChanged(QtProperty *property, int prec); |
712 | void slotSetValue(double value); |
713 | }; |
714 | |
715 | void QtDoubleSpinBoxFactoryPrivate::slotPropertyChanged(QtProperty *property, double value) |
716 | { |
717 | const auto it = m_createdEditors.constFind(akey: property); |
718 | if (it == m_createdEditors.cend()) |
719 | return; |
720 | for (QDoubleSpinBox *editor : it.value()) { |
721 | if (editor->value() != value) { |
722 | editor->blockSignals(b: true); |
723 | editor->setValue(value); |
724 | editor->blockSignals(b: false); |
725 | } |
726 | } |
727 | } |
728 | |
729 | void QtDoubleSpinBoxFactoryPrivate::slotRangeChanged(QtProperty *property, |
730 | double min, double max) |
731 | { |
732 | const auto it = m_createdEditors.constFind(akey: property); |
733 | if (it == m_createdEditors.cend()) |
734 | return; |
735 | |
736 | QtDoublePropertyManager *manager = q_ptr->propertyManager(property); |
737 | if (!manager) |
738 | return; |
739 | |
740 | for (QDoubleSpinBox *editor : it.value()) { |
741 | editor->blockSignals(b: true); |
742 | editor->setRange(min, max); |
743 | editor->setValue(manager->value(property)); |
744 | editor->blockSignals(b: false); |
745 | } |
746 | } |
747 | |
748 | void QtDoubleSpinBoxFactoryPrivate::slotSingleStepChanged(QtProperty *property, double step) |
749 | { |
750 | const auto it = m_createdEditors.constFind(akey: property); |
751 | if (it == m_createdEditors.cend()) |
752 | return; |
753 | |
754 | QtDoublePropertyManager *manager = q_ptr->propertyManager(property); |
755 | if (!manager) |
756 | return; |
757 | |
758 | for (QDoubleSpinBox *editor : it.value()) { |
759 | editor->blockSignals(b: true); |
760 | editor->setSingleStep(step); |
761 | editor->blockSignals(b: false); |
762 | } |
763 | } |
764 | |
765 | void QtDoubleSpinBoxFactoryPrivate::slotDecimalsChanged(QtProperty *property, int prec) |
766 | { |
767 | const auto it = m_createdEditors.constFind(akey: property); |
768 | if (it == m_createdEditors.constEnd()) |
769 | return; |
770 | |
771 | QtDoublePropertyManager *manager = q_ptr->propertyManager(property); |
772 | if (!manager) |
773 | return; |
774 | |
775 | for (QDoubleSpinBox *editor : it.value()) { |
776 | editor->blockSignals(b: true); |
777 | editor->setDecimals(prec); |
778 | editor->setValue(manager->value(property)); |
779 | editor->blockSignals(b: false); |
780 | } |
781 | } |
782 | |
783 | void QtDoubleSpinBoxFactoryPrivate::slotSetValue(double value) |
784 | { |
785 | QObject *object = q_ptr->sender(); |
786 | const QMap<QDoubleSpinBox *, QtProperty *>::ConstIterator itcend = m_editorToProperty.constEnd(); |
787 | for (QMap<QDoubleSpinBox *, QtProperty *>::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != itcend; ++itEditor) { |
788 | if (itEditor.key() == object) { |
789 | QtProperty *property = itEditor.value(); |
790 | QtDoublePropertyManager *manager = q_ptr->propertyManager(property); |
791 | if (!manager) |
792 | return; |
793 | manager->setValue(property, val: value); |
794 | return; |
795 | } |
796 | } |
797 | } |
798 | |
799 | /*! \class QtDoubleSpinBoxFactory |
800 | \internal |
801 | \inmodule QtDesigner |
802 | \since 4.4 |
803 | |
804 | \brief The QtDoubleSpinBoxFactory class provides QDoubleSpinBox |
805 | widgets for properties created by QtDoublePropertyManager objects. |
806 | |
807 | \sa QtAbstractEditorFactory, QtDoublePropertyManager |
808 | */ |
809 | |
810 | /*! |
811 | Creates a factory with the given \a parent. |
812 | */ |
813 | QtDoubleSpinBoxFactory::QtDoubleSpinBoxFactory(QObject *parent) |
814 | : QtAbstractEditorFactory<QtDoublePropertyManager>(parent), d_ptr(new QtDoubleSpinBoxFactoryPrivate()) |
815 | { |
816 | d_ptr->q_ptr = this; |
817 | |
818 | } |
819 | |
820 | /*! |
821 | Destroys this factory, and all the widgets it has created. |
822 | */ |
823 | QtDoubleSpinBoxFactory::~QtDoubleSpinBoxFactory() |
824 | { |
825 | qDeleteAll(c: d_ptr->m_editorToProperty.keys()); |
826 | } |
827 | |
828 | /*! |
829 | \internal |
830 | |
831 | Reimplemented from the QtAbstractEditorFactory class. |
832 | */ |
833 | void QtDoubleSpinBoxFactory::connectPropertyManager(QtDoublePropertyManager *manager) |
834 | { |
835 | connect(sender: manager, SIGNAL(valueChanged(QtProperty*,double)), |
836 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,double))); |
837 | connect(sender: manager, SIGNAL(rangeChanged(QtProperty*,double,double)), |
838 | receiver: this, SLOT(slotRangeChanged(QtProperty*,double,double))); |
839 | connect(sender: manager, SIGNAL(singleStepChanged(QtProperty*,double)), |
840 | receiver: this, SLOT(slotSingleStepChanged(QtProperty*,double))); |
841 | connect(sender: manager, SIGNAL(decimalsChanged(QtProperty*,int)), |
842 | receiver: this, SLOT(slotDecimalsChanged(QtProperty*,int))); |
843 | } |
844 | |
845 | /*! |
846 | \internal |
847 | |
848 | Reimplemented from the QtAbstractEditorFactory class. |
849 | */ |
850 | QWidget *QtDoubleSpinBoxFactory::createEditor(QtDoublePropertyManager *manager, |
851 | QtProperty *property, QWidget *parent) |
852 | { |
853 | QDoubleSpinBox *editor = d_ptr->createEditor(property, parent); |
854 | editor->setSingleStep(manager->singleStep(property)); |
855 | editor->setDecimals(manager->decimals(property)); |
856 | editor->setRange(min: manager->minimum(property), max: manager->maximum(property)); |
857 | editor->setValue(manager->value(property)); |
858 | editor->setKeyboardTracking(false); |
859 | |
860 | connect(sender: editor, SIGNAL(valueChanged(double)), receiver: this, SLOT(slotSetValue(double))); |
861 | connect(sender: editor, SIGNAL(destroyed(QObject*)), |
862 | receiver: this, SLOT(slotEditorDestroyed(QObject*))); |
863 | return editor; |
864 | } |
865 | |
866 | /*! |
867 | \internal |
868 | |
869 | Reimplemented from the QtAbstractEditorFactory class. |
870 | */ |
871 | void QtDoubleSpinBoxFactory::disconnectPropertyManager(QtDoublePropertyManager *manager) |
872 | { |
873 | disconnect(sender: manager, SIGNAL(valueChanged(QtProperty*,double)), |
874 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,double))); |
875 | disconnect(sender: manager, SIGNAL(rangeChanged(QtProperty*,double,double)), |
876 | receiver: this, SLOT(slotRangeChanged(QtProperty*,double,double))); |
877 | disconnect(sender: manager, SIGNAL(singleStepChanged(QtProperty*,double)), |
878 | receiver: this, SLOT(slotSingleStepChanged(QtProperty*,double))); |
879 | disconnect(sender: manager, SIGNAL(decimalsChanged(QtProperty*,int)), |
880 | receiver: this, SLOT(slotDecimalsChanged(QtProperty*,int))); |
881 | } |
882 | |
883 | // QtLineEditFactory |
884 | |
885 | class QtLineEditFactoryPrivate : public EditorFactoryPrivate<QLineEdit> |
886 | { |
887 | QtLineEditFactory *q_ptr; |
888 | Q_DECLARE_PUBLIC(QtLineEditFactory) |
889 | public: |
890 | |
891 | void slotPropertyChanged(QtProperty *property, const QString &value); |
892 | void slotRegExpChanged(QtProperty *property, const QRegExp ®Exp); |
893 | void slotSetValue(const QString &value); |
894 | }; |
895 | |
896 | void QtLineEditFactoryPrivate::slotPropertyChanged(QtProperty *property, |
897 | const QString &value) |
898 | { |
899 | const auto it = m_createdEditors.constFind(akey: property); |
900 | if (it == m_createdEditors.constEnd()) |
901 | return; |
902 | |
903 | for (QLineEdit *editor : it.value()) { |
904 | if (editor->text() != value) |
905 | editor->setText(value); |
906 | } |
907 | } |
908 | |
909 | void QtLineEditFactoryPrivate::slotRegExpChanged(QtProperty *property, |
910 | const QRegExp ®Exp) |
911 | { |
912 | const auto it = m_createdEditors.constFind(akey: property); |
913 | if (it == m_createdEditors.constEnd()) |
914 | return; |
915 | |
916 | QtStringPropertyManager *manager = q_ptr->propertyManager(property); |
917 | if (!manager) |
918 | return; |
919 | |
920 | for (QLineEdit *editor : it.value()) { |
921 | editor->blockSignals(b: true); |
922 | const QValidator *oldValidator = editor->validator(); |
923 | QValidator *newValidator = 0; |
924 | if (regExp.isValid()) { |
925 | newValidator = new QRegExpValidator(regExp, editor); |
926 | } |
927 | editor->setValidator(newValidator); |
928 | if (oldValidator) |
929 | delete oldValidator; |
930 | editor->blockSignals(b: false); |
931 | } |
932 | } |
933 | |
934 | void QtLineEditFactoryPrivate::slotSetValue(const QString &value) |
935 | { |
936 | QObject *object = q_ptr->sender(); |
937 | const QMap<QLineEdit *, QtProperty *>::ConstIterator ecend = m_editorToProperty.constEnd(); |
938 | for (QMap<QLineEdit *, QtProperty *>::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) |
939 | if (itEditor.key() == object) { |
940 | QtProperty *property = itEditor.value(); |
941 | QtStringPropertyManager *manager = q_ptr->propertyManager(property); |
942 | if (!manager) |
943 | return; |
944 | manager->setValue(property, val: value); |
945 | return; |
946 | } |
947 | } |
948 | |
949 | /*! |
950 | \class QtLineEditFactory |
951 | \internal |
952 | \inmodule QtDesigner |
953 | \since 4.4 |
954 | |
955 | \brief The QtLineEditFactory class provides QLineEdit widgets for |
956 | properties created by QtStringPropertyManager objects. |
957 | |
958 | \sa QtAbstractEditorFactory, QtStringPropertyManager |
959 | */ |
960 | |
961 | /*! |
962 | Creates a factory with the given \a parent. |
963 | */ |
964 | QtLineEditFactory::QtLineEditFactory(QObject *parent) |
965 | : QtAbstractEditorFactory<QtStringPropertyManager>(parent), d_ptr(new QtLineEditFactoryPrivate()) |
966 | { |
967 | d_ptr->q_ptr = this; |
968 | |
969 | } |
970 | |
971 | /*! |
972 | Destroys this factory, and all the widgets it has created. |
973 | */ |
974 | QtLineEditFactory::~QtLineEditFactory() |
975 | { |
976 | qDeleteAll(c: d_ptr->m_editorToProperty.keys()); |
977 | } |
978 | |
979 | /*! |
980 | \internal |
981 | |
982 | Reimplemented from the QtAbstractEditorFactory class. |
983 | */ |
984 | void QtLineEditFactory::connectPropertyManager(QtStringPropertyManager *manager) |
985 | { |
986 | connect(sender: manager, SIGNAL(valueChanged(QtProperty*,QString)), |
987 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,QString))); |
988 | connect(sender: manager, SIGNAL(regExpChanged(QtProperty*,QRegExp)), |
989 | receiver: this, SLOT(slotRegExpChanged(QtProperty*,QRegExp))); |
990 | } |
991 | |
992 | /*! |
993 | \internal |
994 | |
995 | Reimplemented from the QtAbstractEditorFactory class. |
996 | */ |
997 | QWidget *QtLineEditFactory::createEditor(QtStringPropertyManager *manager, |
998 | QtProperty *property, QWidget *parent) |
999 | { |
1000 | |
1001 | QLineEdit *editor = d_ptr->createEditor(property, parent); |
1002 | QRegExp regExp = manager->regExp(property); |
1003 | if (regExp.isValid()) { |
1004 | QValidator *validator = new QRegExpValidator(regExp, editor); |
1005 | editor->setValidator(validator); |
1006 | } |
1007 | editor->setText(manager->value(property)); |
1008 | |
1009 | connect(sender: editor, SIGNAL(textEdited(QString)), |
1010 | receiver: this, SLOT(slotSetValue(QString))); |
1011 | connect(sender: editor, SIGNAL(destroyed(QObject*)), |
1012 | receiver: this, SLOT(slotEditorDestroyed(QObject*))); |
1013 | return editor; |
1014 | } |
1015 | |
1016 | /*! |
1017 | \internal |
1018 | |
1019 | Reimplemented from the QtAbstractEditorFactory class. |
1020 | */ |
1021 | void QtLineEditFactory::disconnectPropertyManager(QtStringPropertyManager *manager) |
1022 | { |
1023 | disconnect(sender: manager, SIGNAL(valueChanged(QtProperty*,QString)), |
1024 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,QString))); |
1025 | disconnect(sender: manager, SIGNAL(regExpChanged(QtProperty*,QRegExp)), |
1026 | receiver: this, SLOT(slotRegExpChanged(QtProperty*,QRegExp))); |
1027 | } |
1028 | |
1029 | // QtDateEditFactory |
1030 | |
1031 | class QtDateEditFactoryPrivate : public EditorFactoryPrivate<QDateEdit> |
1032 | { |
1033 | QtDateEditFactory *q_ptr; |
1034 | Q_DECLARE_PUBLIC(QtDateEditFactory) |
1035 | public: |
1036 | |
1037 | void slotPropertyChanged(QtProperty *property, const QDate &value); |
1038 | void slotRangeChanged(QtProperty *property, const QDate &min, const QDate &max); |
1039 | void slotSetValue(const QDate &value); |
1040 | }; |
1041 | |
1042 | void QtDateEditFactoryPrivate::slotPropertyChanged(QtProperty *property, const QDate &value) |
1043 | { |
1044 | const auto it = m_createdEditors.constFind(akey: property); |
1045 | if (it == m_createdEditors.constEnd()) |
1046 | return; |
1047 | for (QDateEdit *editor : it.value()) { |
1048 | editor->blockSignals(b: true); |
1049 | editor->setDate(value); |
1050 | editor->blockSignals(b: false); |
1051 | } |
1052 | } |
1053 | |
1054 | void QtDateEditFactoryPrivate::slotRangeChanged(QtProperty *property, |
1055 | const QDate &min, const QDate &max) |
1056 | { |
1057 | const auto it = m_createdEditors.constFind(akey: property); |
1058 | if (it == m_createdEditors.constEnd()) |
1059 | return; |
1060 | |
1061 | QtDatePropertyManager *manager = q_ptr->propertyManager(property); |
1062 | if (!manager) |
1063 | return; |
1064 | |
1065 | for (QDateEdit *editor : it.value()) { |
1066 | editor->blockSignals(b: true); |
1067 | editor->setDateRange(min, max); |
1068 | editor->setDate(manager->value(property)); |
1069 | editor->blockSignals(b: false); |
1070 | } |
1071 | } |
1072 | |
1073 | void QtDateEditFactoryPrivate::slotSetValue(const QDate &value) |
1074 | { |
1075 | QObject *object = q_ptr->sender(); |
1076 | const QMap<QDateEdit *, QtProperty *>::ConstIterator ecend = m_editorToProperty.constEnd(); |
1077 | for (QMap<QDateEdit *, QtProperty *>::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) |
1078 | if (itEditor.key() == object) { |
1079 | QtProperty *property = itEditor.value(); |
1080 | QtDatePropertyManager *manager = q_ptr->propertyManager(property); |
1081 | if (!manager) |
1082 | return; |
1083 | manager->setValue(property, val: value); |
1084 | return; |
1085 | } |
1086 | } |
1087 | |
1088 | /*! |
1089 | \class QtDateEditFactory |
1090 | \internal |
1091 | \inmodule QtDesigner |
1092 | \since 4.4 |
1093 | |
1094 | \brief The QtDateEditFactory class provides QDateEdit widgets for |
1095 | properties created by QtDatePropertyManager objects. |
1096 | |
1097 | \sa QtAbstractEditorFactory, QtDatePropertyManager |
1098 | */ |
1099 | |
1100 | /*! |
1101 | Creates a factory with the given \a parent. |
1102 | */ |
1103 | QtDateEditFactory::QtDateEditFactory(QObject *parent) |
1104 | : QtAbstractEditorFactory<QtDatePropertyManager>(parent), d_ptr(new QtDateEditFactoryPrivate()) |
1105 | { |
1106 | d_ptr->q_ptr = this; |
1107 | |
1108 | } |
1109 | |
1110 | /*! |
1111 | Destroys this factory, and all the widgets it has created. |
1112 | */ |
1113 | QtDateEditFactory::~QtDateEditFactory() |
1114 | { |
1115 | qDeleteAll(c: d_ptr->m_editorToProperty.keys()); |
1116 | } |
1117 | |
1118 | /*! |
1119 | \internal |
1120 | |
1121 | Reimplemented from the QtAbstractEditorFactory class. |
1122 | */ |
1123 | void QtDateEditFactory::connectPropertyManager(QtDatePropertyManager *manager) |
1124 | { |
1125 | connect(sender: manager, SIGNAL(valueChanged(QtProperty*,QDate)), |
1126 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,QDate))); |
1127 | connect(sender: manager, SIGNAL(rangeChanged(QtProperty*,QDate,QDate)), |
1128 | receiver: this, SLOT(slotRangeChanged(QtProperty*,QDate,QDate))); |
1129 | } |
1130 | |
1131 | /*! |
1132 | \internal |
1133 | |
1134 | Reimplemented from the QtAbstractEditorFactory class. |
1135 | */ |
1136 | QWidget *QtDateEditFactory::createEditor(QtDatePropertyManager *manager, QtProperty *property, |
1137 | QWidget *parent) |
1138 | { |
1139 | QDateEdit *editor = d_ptr->createEditor(property, parent); |
1140 | editor->setDisplayFormat(QtPropertyBrowserUtils::dateFormat()); |
1141 | editor->setCalendarPopup(true); |
1142 | editor->setDateRange(min: manager->minimum(property), max: manager->maximum(property)); |
1143 | editor->setDate(manager->value(property)); |
1144 | |
1145 | connect(sender: editor, SIGNAL(dateChanged(QDate)), |
1146 | receiver: this, SLOT(slotSetValue(QDate))); |
1147 | connect(sender: editor, SIGNAL(destroyed(QObject*)), |
1148 | receiver: this, SLOT(slotEditorDestroyed(QObject*))); |
1149 | return editor; |
1150 | } |
1151 | |
1152 | /*! |
1153 | \internal |
1154 | |
1155 | Reimplemented from the QtAbstractEditorFactory class. |
1156 | */ |
1157 | void QtDateEditFactory::disconnectPropertyManager(QtDatePropertyManager *manager) |
1158 | { |
1159 | disconnect(sender: manager, SIGNAL(valueChanged(QtProperty*,QDate)), |
1160 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,QDate))); |
1161 | disconnect(sender: manager, SIGNAL(rangeChanged(QtProperty*,QDate,QDate)), |
1162 | receiver: this, SLOT(slotRangeChanged(QtProperty*,QDate,QDate))); |
1163 | } |
1164 | |
1165 | // QtTimeEditFactory |
1166 | |
1167 | class QtTimeEditFactoryPrivate : public EditorFactoryPrivate<QTimeEdit> |
1168 | { |
1169 | QtTimeEditFactory *q_ptr; |
1170 | Q_DECLARE_PUBLIC(QtTimeEditFactory) |
1171 | public: |
1172 | |
1173 | void slotPropertyChanged(QtProperty *property, const QTime &value); |
1174 | void slotSetValue(const QTime &value); |
1175 | }; |
1176 | |
1177 | void QtTimeEditFactoryPrivate::slotPropertyChanged(QtProperty *property, const QTime &value) |
1178 | { |
1179 | const auto it = m_createdEditors.constFind(akey: property); |
1180 | if (it == m_createdEditors.constEnd()) |
1181 | return; |
1182 | for (QTimeEdit *editor : it.value()) { |
1183 | editor->blockSignals(b: true); |
1184 | editor->setTime(value); |
1185 | editor->blockSignals(b: false); |
1186 | } |
1187 | } |
1188 | |
1189 | void QtTimeEditFactoryPrivate::slotSetValue(const QTime &value) |
1190 | { |
1191 | QObject *object = q_ptr->sender(); |
1192 | const QMap<QTimeEdit *, QtProperty *>::ConstIterator ecend = m_editorToProperty.constEnd(); |
1193 | for (QMap<QTimeEdit *, QtProperty *>::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) |
1194 | if (itEditor.key() == object) { |
1195 | QtProperty *property = itEditor.value(); |
1196 | QtTimePropertyManager *manager = q_ptr->propertyManager(property); |
1197 | if (!manager) |
1198 | return; |
1199 | manager->setValue(property, val: value); |
1200 | return; |
1201 | } |
1202 | } |
1203 | |
1204 | /*! |
1205 | \class QtTimeEditFactory |
1206 | \internal |
1207 | \inmodule QtDesigner |
1208 | \since 4.4 |
1209 | |
1210 | \brief The QtTimeEditFactory class provides QTimeEdit widgets for |
1211 | properties created by QtTimePropertyManager objects. |
1212 | |
1213 | \sa QtAbstractEditorFactory, QtTimePropertyManager |
1214 | */ |
1215 | |
1216 | /*! |
1217 | Creates a factory with the given \a parent. |
1218 | */ |
1219 | QtTimeEditFactory::QtTimeEditFactory(QObject *parent) |
1220 | : QtAbstractEditorFactory<QtTimePropertyManager>(parent), d_ptr(new QtTimeEditFactoryPrivate()) |
1221 | { |
1222 | d_ptr->q_ptr = this; |
1223 | |
1224 | } |
1225 | |
1226 | /*! |
1227 | Destroys this factory, and all the widgets it has created. |
1228 | */ |
1229 | QtTimeEditFactory::~QtTimeEditFactory() |
1230 | { |
1231 | qDeleteAll(c: d_ptr->m_editorToProperty.keys()); |
1232 | } |
1233 | |
1234 | /*! |
1235 | \internal |
1236 | |
1237 | Reimplemented from the QtAbstractEditorFactory class. |
1238 | */ |
1239 | void QtTimeEditFactory::connectPropertyManager(QtTimePropertyManager *manager) |
1240 | { |
1241 | connect(sender: manager, SIGNAL(valueChanged(QtProperty*,QTime)), |
1242 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,QTime))); |
1243 | } |
1244 | |
1245 | /*! |
1246 | \internal |
1247 | |
1248 | Reimplemented from the QtAbstractEditorFactory class. |
1249 | */ |
1250 | QWidget *QtTimeEditFactory::createEditor(QtTimePropertyManager *manager, QtProperty *property, |
1251 | QWidget *parent) |
1252 | { |
1253 | QTimeEdit *editor = d_ptr->createEditor(property, parent); |
1254 | editor->setDisplayFormat(QtPropertyBrowserUtils::timeFormat()); |
1255 | editor->setTime(manager->value(property)); |
1256 | |
1257 | connect(sender: editor, SIGNAL(timeChanged(QTime)), |
1258 | receiver: this, SLOT(slotSetValue(QTime))); |
1259 | connect(sender: editor, SIGNAL(destroyed(QObject*)), |
1260 | receiver: this, SLOT(slotEditorDestroyed(QObject*))); |
1261 | return editor; |
1262 | } |
1263 | |
1264 | /*! |
1265 | \internal |
1266 | |
1267 | Reimplemented from the QtAbstractEditorFactory class. |
1268 | */ |
1269 | void QtTimeEditFactory::disconnectPropertyManager(QtTimePropertyManager *manager) |
1270 | { |
1271 | disconnect(sender: manager, SIGNAL(valueChanged(QtProperty*,QTime)), |
1272 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,QTime))); |
1273 | } |
1274 | |
1275 | // QtDateTimeEditFactory |
1276 | |
1277 | class QtDateTimeEditFactoryPrivate : public EditorFactoryPrivate<QDateTimeEdit> |
1278 | { |
1279 | QtDateTimeEditFactory *q_ptr; |
1280 | Q_DECLARE_PUBLIC(QtDateTimeEditFactory) |
1281 | public: |
1282 | |
1283 | void slotPropertyChanged(QtProperty *property, const QDateTime &value); |
1284 | void slotSetValue(const QDateTime &value); |
1285 | |
1286 | }; |
1287 | |
1288 | void QtDateTimeEditFactoryPrivate::slotPropertyChanged(QtProperty *property, |
1289 | const QDateTime &value) |
1290 | { |
1291 | const auto it = m_createdEditors.constFind(akey: property); |
1292 | if (it == m_createdEditors.constEnd()) |
1293 | return; |
1294 | |
1295 | for (QDateTimeEdit *editor : it.value()) { |
1296 | editor->blockSignals(b: true); |
1297 | editor->setDateTime(value); |
1298 | editor->blockSignals(b: false); |
1299 | } |
1300 | } |
1301 | |
1302 | void QtDateTimeEditFactoryPrivate::slotSetValue(const QDateTime &value) |
1303 | { |
1304 | QObject *object = q_ptr->sender(); |
1305 | const QMap<QDateTimeEdit *, QtProperty *>::ConstIterator ecend = m_editorToProperty.constEnd(); |
1306 | for (QMap<QDateTimeEdit *, QtProperty *>::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) |
1307 | if (itEditor.key() == object) { |
1308 | QtProperty *property = itEditor.value(); |
1309 | QtDateTimePropertyManager *manager = q_ptr->propertyManager(property); |
1310 | if (!manager) |
1311 | return; |
1312 | manager->setValue(property, val: value); |
1313 | return; |
1314 | } |
1315 | } |
1316 | |
1317 | /*! |
1318 | \class QtDateTimeEditFactory |
1319 | \internal |
1320 | \inmodule QtDesigner |
1321 | \since 4.4 |
1322 | |
1323 | \brief The QtDateTimeEditFactory class provides QDateTimeEdit |
1324 | widgets for properties created by QtDateTimePropertyManager objects. |
1325 | |
1326 | \sa QtAbstractEditorFactory, QtDateTimePropertyManager |
1327 | */ |
1328 | |
1329 | /*! |
1330 | Creates a factory with the given \a parent. |
1331 | */ |
1332 | QtDateTimeEditFactory::QtDateTimeEditFactory(QObject *parent) |
1333 | : QtAbstractEditorFactory<QtDateTimePropertyManager>(parent), d_ptr(new QtDateTimeEditFactoryPrivate()) |
1334 | { |
1335 | d_ptr->q_ptr = this; |
1336 | |
1337 | } |
1338 | |
1339 | /*! |
1340 | Destroys this factory, and all the widgets it has created. |
1341 | */ |
1342 | QtDateTimeEditFactory::~QtDateTimeEditFactory() |
1343 | { |
1344 | qDeleteAll(c: d_ptr->m_editorToProperty.keys()); |
1345 | } |
1346 | |
1347 | /*! |
1348 | \internal |
1349 | |
1350 | Reimplemented from the QtAbstractEditorFactory class. |
1351 | */ |
1352 | void QtDateTimeEditFactory::connectPropertyManager(QtDateTimePropertyManager *manager) |
1353 | { |
1354 | connect(sender: manager, SIGNAL(valueChanged(QtProperty*,QDateTime)), |
1355 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,QDateTime))); |
1356 | } |
1357 | |
1358 | /*! |
1359 | \internal |
1360 | |
1361 | Reimplemented from the QtAbstractEditorFactory class. |
1362 | */ |
1363 | QWidget *QtDateTimeEditFactory::createEditor(QtDateTimePropertyManager *manager, |
1364 | QtProperty *property, QWidget *parent) |
1365 | { |
1366 | QDateTimeEdit *editor = d_ptr->createEditor(property, parent); |
1367 | editor->setDisplayFormat(QtPropertyBrowserUtils::dateTimeFormat()); |
1368 | editor->setDateTime(manager->value(property)); |
1369 | |
1370 | connect(sender: editor, SIGNAL(dateTimeChanged(QDateTime)), |
1371 | receiver: this, SLOT(slotSetValue(QDateTime))); |
1372 | connect(sender: editor, SIGNAL(destroyed(QObject*)), |
1373 | receiver: this, SLOT(slotEditorDestroyed(QObject*))); |
1374 | return editor; |
1375 | } |
1376 | |
1377 | /*! |
1378 | \internal |
1379 | |
1380 | Reimplemented from the QtAbstractEditorFactory class. |
1381 | */ |
1382 | void QtDateTimeEditFactory::disconnectPropertyManager(QtDateTimePropertyManager *manager) |
1383 | { |
1384 | disconnect(sender: manager, SIGNAL(valueChanged(QtProperty*,QDateTime)), |
1385 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,QDateTime))); |
1386 | } |
1387 | |
1388 | // QtKeySequenceEditorFactory |
1389 | |
1390 | class QtKeySequenceEditorFactoryPrivate : public EditorFactoryPrivate<QKeySequenceEdit> |
1391 | { |
1392 | QtKeySequenceEditorFactory *q_ptr; |
1393 | Q_DECLARE_PUBLIC(QtKeySequenceEditorFactory) |
1394 | public: |
1395 | |
1396 | void slotPropertyChanged(QtProperty *property, const QKeySequence &value); |
1397 | void slotSetValue(const QKeySequence &value); |
1398 | }; |
1399 | |
1400 | void QtKeySequenceEditorFactoryPrivate::slotPropertyChanged(QtProperty *property, |
1401 | const QKeySequence &value) |
1402 | { |
1403 | const auto it = m_createdEditors.constFind(akey: property); |
1404 | if (it == m_createdEditors.constEnd()) |
1405 | return; |
1406 | |
1407 | for (QKeySequenceEdit *editor : it.value()) { |
1408 | editor->blockSignals(b: true); |
1409 | editor->setKeySequence(value); |
1410 | editor->blockSignals(b: false); |
1411 | } |
1412 | } |
1413 | |
1414 | void QtKeySequenceEditorFactoryPrivate::slotSetValue(const QKeySequence &value) |
1415 | { |
1416 | QObject *object = q_ptr->sender(); |
1417 | const QMap<QKeySequenceEdit *, QtProperty *>::ConstIterator ecend = m_editorToProperty.constEnd(); |
1418 | for (QMap<QKeySequenceEdit *, QtProperty *>::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) |
1419 | if (itEditor.key() == object) { |
1420 | QtProperty *property = itEditor.value(); |
1421 | QtKeySequencePropertyManager *manager = q_ptr->propertyManager(property); |
1422 | if (!manager) |
1423 | return; |
1424 | manager->setValue(property, val: value); |
1425 | return; |
1426 | } |
1427 | } |
1428 | |
1429 | /*! |
1430 | \class QtKeySequenceEditorFactory |
1431 | \internal |
1432 | \inmodule QtDesigner |
1433 | \since 4.4 |
1434 | |
1435 | \brief The QtKeySequenceEditorFactory class provides editor |
1436 | widgets for properties created by QtKeySequencePropertyManager objects. |
1437 | |
1438 | \sa QtAbstractEditorFactory |
1439 | */ |
1440 | |
1441 | /*! |
1442 | Creates a factory with the given \a parent. |
1443 | */ |
1444 | QtKeySequenceEditorFactory::QtKeySequenceEditorFactory(QObject *parent) |
1445 | : QtAbstractEditorFactory<QtKeySequencePropertyManager>(parent), d_ptr(new QtKeySequenceEditorFactoryPrivate()) |
1446 | { |
1447 | d_ptr->q_ptr = this; |
1448 | |
1449 | } |
1450 | |
1451 | /*! |
1452 | Destroys this factory, and all the widgets it has created. |
1453 | */ |
1454 | QtKeySequenceEditorFactory::~QtKeySequenceEditorFactory() |
1455 | { |
1456 | qDeleteAll(c: d_ptr->m_editorToProperty.keys()); |
1457 | } |
1458 | |
1459 | /*! |
1460 | \internal |
1461 | |
1462 | Reimplemented from the QtAbstractEditorFactory class. |
1463 | */ |
1464 | void QtKeySequenceEditorFactory::connectPropertyManager(QtKeySequencePropertyManager *manager) |
1465 | { |
1466 | connect(sender: manager, SIGNAL(valueChanged(QtProperty*,QKeySequence)), |
1467 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,QKeySequence))); |
1468 | } |
1469 | |
1470 | /*! |
1471 | \internal |
1472 | |
1473 | Reimplemented from the QtAbstractEditorFactory class. |
1474 | */ |
1475 | QWidget *QtKeySequenceEditorFactory::createEditor(QtKeySequencePropertyManager *manager, |
1476 | QtProperty *property, QWidget *parent) |
1477 | { |
1478 | QKeySequenceEdit *editor = d_ptr->createEditor(property, parent); |
1479 | editor->setKeySequence(manager->value(property)); |
1480 | |
1481 | connect(sender: editor, SIGNAL(keySequenceChanged(QKeySequence)), |
1482 | receiver: this, SLOT(slotSetValue(QKeySequence))); |
1483 | connect(sender: editor, SIGNAL(destroyed(QObject*)), |
1484 | receiver: this, SLOT(slotEditorDestroyed(QObject*))); |
1485 | return editor; |
1486 | } |
1487 | |
1488 | /*! |
1489 | \internal |
1490 | |
1491 | Reimplemented from the QtAbstractEditorFactory class. |
1492 | */ |
1493 | void QtKeySequenceEditorFactory::disconnectPropertyManager(QtKeySequencePropertyManager *manager) |
1494 | { |
1495 | disconnect(sender: manager, SIGNAL(valueChanged(QtProperty*,QKeySequence)), |
1496 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,QKeySequence))); |
1497 | } |
1498 | |
1499 | // QtCharEdit |
1500 | |
1501 | class QtCharEdit : public QWidget |
1502 | { |
1503 | Q_OBJECT |
1504 | public: |
1505 | QtCharEdit(QWidget *parent = 0); |
1506 | |
1507 | QChar value() const; |
1508 | bool eventFilter(QObject *o, QEvent *e); |
1509 | public Q_SLOTS: |
1510 | void setValue(const QChar &value); |
1511 | Q_SIGNALS: |
1512 | void valueChanged(const QChar &value); |
1513 | protected: |
1514 | void focusInEvent(QFocusEvent *e); |
1515 | void focusOutEvent(QFocusEvent *e); |
1516 | void keyPressEvent(QKeyEvent *e); |
1517 | void keyReleaseEvent(QKeyEvent *e); |
1518 | bool event(QEvent *e); |
1519 | private slots: |
1520 | void slotClearChar(); |
1521 | private: |
1522 | void handleKeyEvent(QKeyEvent *e); |
1523 | |
1524 | QChar m_value; |
1525 | QLineEdit *m_lineEdit; |
1526 | }; |
1527 | |
1528 | QtCharEdit::QtCharEdit(QWidget *parent) |
1529 | : QWidget(parent), m_lineEdit(new QLineEdit(this)) |
1530 | { |
1531 | QHBoxLayout *layout = new QHBoxLayout(this); |
1532 | layout->addWidget(m_lineEdit); |
1533 | layout->setContentsMargins(QMargins()); |
1534 | m_lineEdit->installEventFilter(filterObj: this); |
1535 | m_lineEdit->setReadOnly(true); |
1536 | m_lineEdit->setFocusProxy(this); |
1537 | setFocusPolicy(m_lineEdit->focusPolicy()); |
1538 | setAttribute(Qt::WA_InputMethodEnabled); |
1539 | } |
1540 | |
1541 | bool QtCharEdit::eventFilter(QObject *o, QEvent *e) |
1542 | { |
1543 | if (o == m_lineEdit && e->type() == QEvent::ContextMenu) { |
1544 | QContextMenuEvent *c = static_cast<QContextMenuEvent *>(e); |
1545 | QMenu * = m_lineEdit->createStandardContextMenu(); |
1546 | const auto actions = menu->actions(); |
1547 | for (QAction *action : actions) { |
1548 | action->setShortcut(QKeySequence()); |
1549 | QString actionString = action->text(); |
1550 | const int pos = actionString.lastIndexOf(c: QLatin1Char('\t')); |
1551 | if (pos > 0) |
1552 | actionString = actionString.remove(i: pos, len: actionString.length() - pos); |
1553 | action->setText(actionString); |
1554 | } |
1555 | QAction *actionBefore = 0; |
1556 | if (actions.count() > 0) |
1557 | actionBefore = actions[0]; |
1558 | QAction *clearAction = new QAction(tr(s: "Clear Char" ), menu); |
1559 | menu->insertAction(before: actionBefore, action: clearAction); |
1560 | menu->insertSeparator(before: actionBefore); |
1561 | clearAction->setEnabled(!m_value.isNull()); |
1562 | connect(sender: clearAction, SIGNAL(triggered()), receiver: this, SLOT(slotClearChar())); |
1563 | menu->exec(pos: c->globalPos()); |
1564 | delete menu; |
1565 | e->accept(); |
1566 | return true; |
1567 | } |
1568 | |
1569 | return QWidget::eventFilter(watched: o, event: e); |
1570 | } |
1571 | |
1572 | void QtCharEdit::slotClearChar() |
1573 | { |
1574 | if (m_value.isNull()) |
1575 | return; |
1576 | setValue(QChar()); |
1577 | emit valueChanged(value: m_value); |
1578 | } |
1579 | |
1580 | void QtCharEdit::handleKeyEvent(QKeyEvent *e) |
1581 | { |
1582 | const int key = e->key(); |
1583 | switch (key) { |
1584 | case Qt::Key_Control: |
1585 | case Qt::Key_Shift: |
1586 | case Qt::Key_Meta: |
1587 | case Qt::Key_Alt: |
1588 | case Qt::Key_Super_L: |
1589 | case Qt::Key_Return: |
1590 | return; |
1591 | default: |
1592 | break; |
1593 | } |
1594 | |
1595 | const QString text = e->text(); |
1596 | if (text.count() != 1) |
1597 | return; |
1598 | |
1599 | const QChar c = text.at(i: 0); |
1600 | if (!c.isPrint()) |
1601 | return; |
1602 | |
1603 | if (m_value == c) |
1604 | return; |
1605 | |
1606 | m_value = c; |
1607 | const QString str = m_value.isNull() ? QString() : QString(m_value); |
1608 | m_lineEdit->setText(str); |
1609 | e->accept(); |
1610 | emit valueChanged(value: m_value); |
1611 | } |
1612 | |
1613 | void QtCharEdit::setValue(const QChar &value) |
1614 | { |
1615 | if (value == m_value) |
1616 | return; |
1617 | |
1618 | m_value = value; |
1619 | QString str = value.isNull() ? QString() : QString(value); |
1620 | m_lineEdit->setText(str); |
1621 | } |
1622 | |
1623 | QChar QtCharEdit::value() const |
1624 | { |
1625 | return m_value; |
1626 | } |
1627 | |
1628 | void QtCharEdit::focusInEvent(QFocusEvent *e) |
1629 | { |
1630 | m_lineEdit->event(e); |
1631 | m_lineEdit->selectAll(); |
1632 | QWidget::focusInEvent(event: e); |
1633 | } |
1634 | |
1635 | void QtCharEdit::focusOutEvent(QFocusEvent *e) |
1636 | { |
1637 | m_lineEdit->event(e); |
1638 | QWidget::focusOutEvent(event: e); |
1639 | } |
1640 | |
1641 | void QtCharEdit::keyPressEvent(QKeyEvent *e) |
1642 | { |
1643 | handleKeyEvent(e); |
1644 | e->accept(); |
1645 | } |
1646 | |
1647 | void QtCharEdit::keyReleaseEvent(QKeyEvent *e) |
1648 | { |
1649 | m_lineEdit->event(e); |
1650 | } |
1651 | |
1652 | bool QtCharEdit::event(QEvent *e) |
1653 | { |
1654 | switch(e->type()) { |
1655 | case QEvent::Shortcut: |
1656 | case QEvent::ShortcutOverride: |
1657 | case QEvent::KeyRelease: |
1658 | e->accept(); |
1659 | return true; |
1660 | default: |
1661 | break; |
1662 | } |
1663 | return QWidget::event(event: e); |
1664 | } |
1665 | |
1666 | // QtCharEditorFactory |
1667 | |
1668 | class QtCharEditorFactoryPrivate : public EditorFactoryPrivate<QtCharEdit> |
1669 | { |
1670 | QtCharEditorFactory *q_ptr; |
1671 | Q_DECLARE_PUBLIC(QtCharEditorFactory) |
1672 | public: |
1673 | |
1674 | void slotPropertyChanged(QtProperty *property, const QChar &value); |
1675 | void slotSetValue(const QChar &value); |
1676 | |
1677 | }; |
1678 | |
1679 | void QtCharEditorFactoryPrivate::slotPropertyChanged(QtProperty *property, |
1680 | const QChar &value) |
1681 | { |
1682 | const auto it = m_createdEditors.constFind(akey: property); |
1683 | if (it == m_createdEditors.constEnd()) |
1684 | return; |
1685 | |
1686 | for (QtCharEdit *editor : it.value()) { |
1687 | editor->blockSignals(b: true); |
1688 | editor->setValue(value); |
1689 | editor->blockSignals(b: false); |
1690 | } |
1691 | } |
1692 | |
1693 | void QtCharEditorFactoryPrivate::slotSetValue(const QChar &value) |
1694 | { |
1695 | QObject *object = q_ptr->sender(); |
1696 | const QMap<QtCharEdit *, QtProperty *>::ConstIterator ecend = m_editorToProperty.constEnd(); |
1697 | for (QMap<QtCharEdit *, QtProperty *>::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) |
1698 | if (itEditor.key() == object) { |
1699 | QtProperty *property = itEditor.value(); |
1700 | QtCharPropertyManager *manager = q_ptr->propertyManager(property); |
1701 | if (!manager) |
1702 | return; |
1703 | manager->setValue(property, val: value); |
1704 | return; |
1705 | } |
1706 | } |
1707 | |
1708 | /*! |
1709 | \class QtCharEditorFactory |
1710 | \internal |
1711 | \inmodule QtDesigner |
1712 | \since 4.4 |
1713 | |
1714 | \brief The QtCharEditorFactory class provides editor |
1715 | widgets for properties created by QtCharPropertyManager objects. |
1716 | |
1717 | \sa QtAbstractEditorFactory |
1718 | */ |
1719 | |
1720 | /*! |
1721 | Creates a factory with the given \a parent. |
1722 | */ |
1723 | QtCharEditorFactory::QtCharEditorFactory(QObject *parent) |
1724 | : QtAbstractEditorFactory<QtCharPropertyManager>(parent), d_ptr(new QtCharEditorFactoryPrivate()) |
1725 | { |
1726 | d_ptr->q_ptr = this; |
1727 | |
1728 | } |
1729 | |
1730 | /*! |
1731 | Destroys this factory, and all the widgets it has created. |
1732 | */ |
1733 | QtCharEditorFactory::~QtCharEditorFactory() |
1734 | { |
1735 | qDeleteAll(c: d_ptr->m_editorToProperty.keys()); |
1736 | } |
1737 | |
1738 | /*! |
1739 | \internal |
1740 | |
1741 | Reimplemented from the QtAbstractEditorFactory class. |
1742 | */ |
1743 | void QtCharEditorFactory::connectPropertyManager(QtCharPropertyManager *manager) |
1744 | { |
1745 | connect(sender: manager, SIGNAL(valueChanged(QtProperty*,QChar)), |
1746 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,QChar))); |
1747 | } |
1748 | |
1749 | /*! |
1750 | \internal |
1751 | |
1752 | Reimplemented from the QtAbstractEditorFactory class. |
1753 | */ |
1754 | QWidget *QtCharEditorFactory::createEditor(QtCharPropertyManager *manager, |
1755 | QtProperty *property, QWidget *parent) |
1756 | { |
1757 | QtCharEdit *editor = d_ptr->createEditor(property, parent); |
1758 | editor->setValue(manager->value(property)); |
1759 | |
1760 | connect(sender: editor, SIGNAL(valueChanged(QChar)), |
1761 | receiver: this, SLOT(slotSetValue(QChar))); |
1762 | connect(sender: editor, SIGNAL(destroyed(QObject*)), |
1763 | receiver: this, SLOT(slotEditorDestroyed(QObject*))); |
1764 | return editor; |
1765 | } |
1766 | |
1767 | /*! |
1768 | \internal |
1769 | |
1770 | Reimplemented from the QtAbstractEditorFactory class. |
1771 | */ |
1772 | void QtCharEditorFactory::disconnectPropertyManager(QtCharPropertyManager *manager) |
1773 | { |
1774 | disconnect(sender: manager, SIGNAL(valueChanged(QtProperty*,QChar)), |
1775 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,QChar))); |
1776 | } |
1777 | |
1778 | // QtEnumEditorFactory |
1779 | |
1780 | class QtEnumEditorFactoryPrivate : public EditorFactoryPrivate<QComboBox> |
1781 | { |
1782 | QtEnumEditorFactory *q_ptr; |
1783 | Q_DECLARE_PUBLIC(QtEnumEditorFactory) |
1784 | public: |
1785 | |
1786 | void slotPropertyChanged(QtProperty *property, int value); |
1787 | void slotEnumNamesChanged(QtProperty *property, const QStringList &); |
1788 | void slotEnumIconsChanged(QtProperty *property, const QMap<int, QIcon> &); |
1789 | void slotSetValue(int value); |
1790 | }; |
1791 | |
1792 | void QtEnumEditorFactoryPrivate::slotPropertyChanged(QtProperty *property, int value) |
1793 | { |
1794 | const auto it = m_createdEditors.constFind(akey: property); |
1795 | if (it == m_createdEditors.constEnd()) |
1796 | return; |
1797 | |
1798 | for (QComboBox *editor : it.value()) { |
1799 | editor->blockSignals(b: true); |
1800 | editor->setCurrentIndex(value); |
1801 | editor->blockSignals(b: false); |
1802 | } |
1803 | } |
1804 | |
1805 | void QtEnumEditorFactoryPrivate::slotEnumNamesChanged(QtProperty *property, |
1806 | const QStringList &enumNames) |
1807 | { |
1808 | const auto it = m_createdEditors.constFind(akey: property); |
1809 | if (it == m_createdEditors.constEnd()) |
1810 | return; |
1811 | |
1812 | QtEnumPropertyManager *manager = q_ptr->propertyManager(property); |
1813 | if (!manager) |
1814 | return; |
1815 | |
1816 | QMap<int, QIcon> enumIcons = manager->enumIcons(property); |
1817 | |
1818 | for (QComboBox *editor : it.value()) { |
1819 | editor->blockSignals(b: true); |
1820 | editor->clear(); |
1821 | editor->addItems(texts: enumNames); |
1822 | const int nameCount = enumNames.count(); |
1823 | for (int i = 0; i < nameCount; i++) |
1824 | editor->setItemIcon(index: i, icon: enumIcons.value(akey: i)); |
1825 | editor->setCurrentIndex(manager->value(property)); |
1826 | editor->blockSignals(b: false); |
1827 | } |
1828 | } |
1829 | |
1830 | void QtEnumEditorFactoryPrivate::slotEnumIconsChanged(QtProperty *property, |
1831 | const QMap<int, QIcon> &enumIcons) |
1832 | { |
1833 | const auto it = m_createdEditors.constFind(akey: property); |
1834 | if (it == m_createdEditors.constEnd()) |
1835 | return; |
1836 | |
1837 | QtEnumPropertyManager *manager = q_ptr->propertyManager(property); |
1838 | if (!manager) |
1839 | return; |
1840 | |
1841 | const QStringList enumNames = manager->enumNames(property); |
1842 | for (QComboBox *editor : it.value()) { |
1843 | editor->blockSignals(b: true); |
1844 | const int nameCount = enumNames.count(); |
1845 | for (int i = 0; i < nameCount; i++) |
1846 | editor->setItemIcon(index: i, icon: enumIcons.value(akey: i)); |
1847 | editor->setCurrentIndex(manager->value(property)); |
1848 | editor->blockSignals(b: false); |
1849 | } |
1850 | } |
1851 | |
1852 | void QtEnumEditorFactoryPrivate::slotSetValue(int value) |
1853 | { |
1854 | QObject *object = q_ptr->sender(); |
1855 | const QMap<QComboBox *, QtProperty *>::ConstIterator ecend = m_editorToProperty.constEnd(); |
1856 | for (QMap<QComboBox *, QtProperty *>::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) |
1857 | if (itEditor.key() == object) { |
1858 | QtProperty *property = itEditor.value(); |
1859 | QtEnumPropertyManager *manager = q_ptr->propertyManager(property); |
1860 | if (!manager) |
1861 | return; |
1862 | manager->setValue(property, val: value); |
1863 | return; |
1864 | } |
1865 | } |
1866 | |
1867 | /*! |
1868 | \class QtEnumEditorFactory |
1869 | \internal |
1870 | \inmodule QtDesigner |
1871 | \since 4.4 |
1872 | |
1873 | \brief The QtEnumEditorFactory class provides QComboBox widgets for |
1874 | properties created by QtEnumPropertyManager objects. |
1875 | |
1876 | \sa QtAbstractEditorFactory, QtEnumPropertyManager |
1877 | */ |
1878 | |
1879 | /*! |
1880 | Creates a factory with the given \a parent. |
1881 | */ |
1882 | QtEnumEditorFactory::QtEnumEditorFactory(QObject *parent) |
1883 | : QtAbstractEditorFactory<QtEnumPropertyManager>(parent), d_ptr(new QtEnumEditorFactoryPrivate()) |
1884 | { |
1885 | d_ptr->q_ptr = this; |
1886 | |
1887 | } |
1888 | |
1889 | /*! |
1890 | Destroys this factory, and all the widgets it has created. |
1891 | */ |
1892 | QtEnumEditorFactory::~QtEnumEditorFactory() |
1893 | { |
1894 | qDeleteAll(c: d_ptr->m_editorToProperty.keys()); |
1895 | } |
1896 | |
1897 | /*! |
1898 | \internal |
1899 | |
1900 | Reimplemented from the QtAbstractEditorFactory class. |
1901 | */ |
1902 | void QtEnumEditorFactory::connectPropertyManager(QtEnumPropertyManager *manager) |
1903 | { |
1904 | connect(sender: manager, SIGNAL(valueChanged(QtProperty*,int)), |
1905 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,int))); |
1906 | connect(sender: manager, SIGNAL(enumNamesChanged(QtProperty*,QStringList)), |
1907 | receiver: this, SLOT(slotEnumNamesChanged(QtProperty*,QStringList))); |
1908 | } |
1909 | |
1910 | /*! |
1911 | \internal |
1912 | |
1913 | Reimplemented from the QtAbstractEditorFactory class. |
1914 | */ |
1915 | QWidget *QtEnumEditorFactory::createEditor(QtEnumPropertyManager *manager, QtProperty *property, |
1916 | QWidget *parent) |
1917 | { |
1918 | QComboBox *editor = d_ptr->createEditor(property, parent); |
1919 | editor->setSizePolicy(hor: QSizePolicy::Ignored, ver: QSizePolicy::Fixed); |
1920 | editor->view()->setTextElideMode(Qt::ElideRight); |
1921 | QStringList enumNames = manager->enumNames(property); |
1922 | editor->addItems(texts: enumNames); |
1923 | QMap<int, QIcon> enumIcons = manager->enumIcons(property); |
1924 | const int enumNamesCount = enumNames.count(); |
1925 | for (int i = 0; i < enumNamesCount; i++) |
1926 | editor->setItemIcon(index: i, icon: enumIcons.value(akey: i)); |
1927 | editor->setCurrentIndex(manager->value(property)); |
1928 | |
1929 | connect(sender: editor, SIGNAL(currentIndexChanged(int)), receiver: this, SLOT(slotSetValue(int))); |
1930 | connect(sender: editor, SIGNAL(destroyed(QObject*)), |
1931 | receiver: this, SLOT(slotEditorDestroyed(QObject*))); |
1932 | return editor; |
1933 | } |
1934 | |
1935 | /*! |
1936 | \internal |
1937 | |
1938 | Reimplemented from the QtAbstractEditorFactory class. |
1939 | */ |
1940 | void QtEnumEditorFactory::disconnectPropertyManager(QtEnumPropertyManager *manager) |
1941 | { |
1942 | disconnect(sender: manager, SIGNAL(valueChanged(QtProperty*,int)), |
1943 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,int))); |
1944 | disconnect(sender: manager, SIGNAL(enumNamesChanged(QtProperty*,QStringList)), |
1945 | receiver: this, SLOT(slotEnumNamesChanged(QtProperty*,QStringList))); |
1946 | } |
1947 | |
1948 | // QtCursorEditorFactory |
1949 | |
1950 | Q_GLOBAL_STATIC(QtCursorDatabase, cursorDatabase) |
1951 | |
1952 | class QtCursorEditorFactoryPrivate |
1953 | { |
1954 | QtCursorEditorFactory *q_ptr; |
1955 | Q_DECLARE_PUBLIC(QtCursorEditorFactory) |
1956 | public: |
1957 | QtCursorEditorFactoryPrivate(); |
1958 | |
1959 | void slotPropertyChanged(QtProperty *property, const QCursor &cursor); |
1960 | void slotEnumChanged(QtProperty *property, int value); |
1961 | void slotEditorDestroyed(QObject *object); |
1962 | |
1963 | QtEnumEditorFactory *m_enumEditorFactory; |
1964 | QtEnumPropertyManager *m_enumPropertyManager; |
1965 | |
1966 | QMap<QtProperty *, QtProperty *> m_propertyToEnum; |
1967 | QMap<QtProperty *, QtProperty *> m_enumToProperty; |
1968 | QMap<QtProperty *, QWidgetList > m_enumToEditors; |
1969 | QMap<QWidget *, QtProperty *> m_editorToEnum; |
1970 | bool m_updatingEnum; |
1971 | }; |
1972 | |
1973 | QtCursorEditorFactoryPrivate::QtCursorEditorFactoryPrivate() |
1974 | : m_updatingEnum(false) |
1975 | { |
1976 | |
1977 | } |
1978 | |
1979 | void QtCursorEditorFactoryPrivate::slotPropertyChanged(QtProperty *property, const QCursor &cursor) |
1980 | { |
1981 | // update enum property |
1982 | QtProperty *enumProp = m_propertyToEnum.value(akey: property); |
1983 | if (!enumProp) |
1984 | return; |
1985 | |
1986 | m_updatingEnum = true; |
1987 | m_enumPropertyManager->setValue(property: enumProp, val: cursorDatabase()->cursorToValue(cursor)); |
1988 | m_updatingEnum = false; |
1989 | } |
1990 | |
1991 | void QtCursorEditorFactoryPrivate::slotEnumChanged(QtProperty *property, int value) |
1992 | { |
1993 | if (m_updatingEnum) |
1994 | return; |
1995 | // update cursor property |
1996 | QtProperty *prop = m_enumToProperty.value(akey: property); |
1997 | if (!prop) |
1998 | return; |
1999 | QtCursorPropertyManager *cursorManager = q_ptr->propertyManager(property: prop); |
2000 | if (!cursorManager) |
2001 | return; |
2002 | #ifndef QT_NO_CURSOR |
2003 | cursorManager->setValue(property: prop, val: QCursor(cursorDatabase()->valueToCursor(value))); |
2004 | #endif |
2005 | } |
2006 | |
2007 | void QtCursorEditorFactoryPrivate::slotEditorDestroyed(QObject *object) |
2008 | { |
2009 | // remove from m_editorToEnum map; |
2010 | // remove from m_enumToEditors map; |
2011 | // if m_enumToEditors doesn't contains more editors delete enum property; |
2012 | const QMap<QWidget *, QtProperty *>::ConstIterator ecend = m_editorToEnum.constEnd(); |
2013 | for (QMap<QWidget *, QtProperty *>::ConstIterator itEditor = m_editorToEnum.constBegin(); itEditor != ecend; ++itEditor) |
2014 | if (itEditor.key() == object) { |
2015 | QWidget *editor = itEditor.key(); |
2016 | QtProperty *enumProp = itEditor.value(); |
2017 | m_editorToEnum.remove(akey: editor); |
2018 | m_enumToEditors[enumProp].removeAll(t: editor); |
2019 | if (m_enumToEditors[enumProp].isEmpty()) { |
2020 | m_enumToEditors.remove(akey: enumProp); |
2021 | QtProperty *property = m_enumToProperty.value(akey: enumProp); |
2022 | m_enumToProperty.remove(akey: enumProp); |
2023 | m_propertyToEnum.remove(akey: property); |
2024 | delete enumProp; |
2025 | } |
2026 | return; |
2027 | } |
2028 | } |
2029 | |
2030 | /*! |
2031 | \class QtCursorEditorFactory |
2032 | \internal |
2033 | \inmodule QtDesigner |
2034 | \since 4.4 |
2035 | |
2036 | \brief The QtCursorEditorFactory class provides QComboBox widgets for |
2037 | properties created by QtCursorPropertyManager objects. |
2038 | |
2039 | \sa QtAbstractEditorFactory, QtCursorPropertyManager |
2040 | */ |
2041 | |
2042 | /*! |
2043 | Creates a factory with the given \a parent. |
2044 | */ |
2045 | QtCursorEditorFactory::QtCursorEditorFactory(QObject *parent) |
2046 | : QtAbstractEditorFactory<QtCursorPropertyManager>(parent), d_ptr(new QtCursorEditorFactoryPrivate()) |
2047 | { |
2048 | d_ptr->q_ptr = this; |
2049 | |
2050 | d_ptr->m_enumEditorFactory = new QtEnumEditorFactory(this); |
2051 | d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this); |
2052 | connect(sender: d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty*,int)), |
2053 | receiver: this, SLOT(slotEnumChanged(QtProperty*,int))); |
2054 | d_ptr->m_enumEditorFactory->addPropertyManager(manager: d_ptr->m_enumPropertyManager); |
2055 | } |
2056 | |
2057 | /*! |
2058 | Destroys this factory, and all the widgets it has created. |
2059 | */ |
2060 | QtCursorEditorFactory::~QtCursorEditorFactory() |
2061 | { |
2062 | } |
2063 | |
2064 | /*! |
2065 | \internal |
2066 | |
2067 | Reimplemented from the QtAbstractEditorFactory class. |
2068 | */ |
2069 | void QtCursorEditorFactory::connectPropertyManager(QtCursorPropertyManager *manager) |
2070 | { |
2071 | connect(sender: manager, SIGNAL(valueChanged(QtProperty*,QCursor)), |
2072 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,QCursor))); |
2073 | } |
2074 | |
2075 | /*! |
2076 | \internal |
2077 | |
2078 | Reimplemented from the QtAbstractEditorFactory class. |
2079 | */ |
2080 | QWidget *QtCursorEditorFactory::createEditor(QtCursorPropertyManager *manager, QtProperty *property, |
2081 | QWidget *parent) |
2082 | { |
2083 | QtProperty *enumProp = 0; |
2084 | if (d_ptr->m_propertyToEnum.contains(akey: property)) { |
2085 | enumProp = d_ptr->m_propertyToEnum[property]; |
2086 | } else { |
2087 | enumProp = d_ptr->m_enumPropertyManager->addProperty(name: property->propertyName()); |
2088 | d_ptr->m_enumPropertyManager->setEnumNames(property: enumProp, names: cursorDatabase()->cursorShapeNames()); |
2089 | d_ptr->m_enumPropertyManager->setEnumIcons(property: enumProp, icons: cursorDatabase()->cursorShapeIcons()); |
2090 | #ifndef QT_NO_CURSOR |
2091 | d_ptr->m_enumPropertyManager->setValue(property: enumProp, val: cursorDatabase()->cursorToValue(cursor: manager->value(property))); |
2092 | #endif |
2093 | d_ptr->m_propertyToEnum[property] = enumProp; |
2094 | d_ptr->m_enumToProperty[enumProp] = property; |
2095 | } |
2096 | QtAbstractEditorFactoryBase *af = d_ptr->m_enumEditorFactory; |
2097 | QWidget *editor = af->createEditor(property: enumProp, parent); |
2098 | d_ptr->m_enumToEditors[enumProp].append(t: editor); |
2099 | d_ptr->m_editorToEnum[editor] = enumProp; |
2100 | connect(sender: editor, SIGNAL(destroyed(QObject*)), |
2101 | receiver: this, SLOT(slotEditorDestroyed(QObject*))); |
2102 | return editor; |
2103 | } |
2104 | |
2105 | /*! |
2106 | \internal |
2107 | |
2108 | Reimplemented from the QtAbstractEditorFactory class. |
2109 | */ |
2110 | void QtCursorEditorFactory::disconnectPropertyManager(QtCursorPropertyManager *manager) |
2111 | { |
2112 | disconnect(sender: manager, SIGNAL(valueChanged(QtProperty*,QCursor)), |
2113 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,QCursor))); |
2114 | } |
2115 | |
2116 | // QtColorEditWidget |
2117 | |
2118 | class QtColorEditWidget : public QWidget { |
2119 | Q_OBJECT |
2120 | |
2121 | public: |
2122 | QtColorEditWidget(QWidget *parent); |
2123 | |
2124 | bool eventFilter(QObject *obj, QEvent *ev); |
2125 | |
2126 | public Q_SLOTS: |
2127 | void setValue(const QColor &value); |
2128 | |
2129 | private Q_SLOTS: |
2130 | void buttonClicked(); |
2131 | |
2132 | Q_SIGNALS: |
2133 | void valueChanged(const QColor &value); |
2134 | |
2135 | private: |
2136 | QColor m_color; |
2137 | QLabel *m_pixmapLabel; |
2138 | QLabel *m_label; |
2139 | QToolButton *m_button; |
2140 | }; |
2141 | |
2142 | QtColorEditWidget::QtColorEditWidget(QWidget *parent) : |
2143 | QWidget(parent), |
2144 | m_pixmapLabel(new QLabel), |
2145 | m_label(new QLabel), |
2146 | m_button(new QToolButton) |
2147 | { |
2148 | QHBoxLayout *lt = new QHBoxLayout(this); |
2149 | setupTreeViewEditorMargin(lt); |
2150 | lt->setSpacing(0); |
2151 | lt->addWidget(m_pixmapLabel); |
2152 | lt->addWidget(m_label); |
2153 | lt->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored)); |
2154 | |
2155 | m_button->setSizePolicy(hor: QSizePolicy::Fixed, ver: QSizePolicy::Ignored); |
2156 | m_button->setFixedWidth(20); |
2157 | setFocusProxy(m_button); |
2158 | setFocusPolicy(m_button->focusPolicy()); |
2159 | m_button->setText(tr(s: "..." )); |
2160 | m_button->installEventFilter(filterObj: this); |
2161 | connect(sender: m_button, SIGNAL(clicked()), receiver: this, SLOT(buttonClicked())); |
2162 | lt->addWidget(m_button); |
2163 | m_pixmapLabel->setPixmap(QtPropertyBrowserUtils::brushValuePixmap(b: QBrush(m_color))); |
2164 | m_label->setText(QtPropertyBrowserUtils::colorValueText(c: m_color)); |
2165 | } |
2166 | |
2167 | void QtColorEditWidget::setValue(const QColor &c) |
2168 | { |
2169 | if (m_color != c) { |
2170 | m_color = c; |
2171 | m_pixmapLabel->setPixmap(QtPropertyBrowserUtils::brushValuePixmap(b: QBrush(c))); |
2172 | m_label->setText(QtPropertyBrowserUtils::colorValueText(c)); |
2173 | } |
2174 | } |
2175 | |
2176 | void QtColorEditWidget::buttonClicked() |
2177 | { |
2178 | const QColor newColor = QColorDialog::getColor(initial: m_color, parent: this, title: QString(), options: QColorDialog::ShowAlphaChannel); |
2179 | if (newColor.isValid() && newColor != m_color) { |
2180 | setValue(newColor); |
2181 | emit valueChanged(value: m_color); |
2182 | } |
2183 | } |
2184 | |
2185 | bool QtColorEditWidget::eventFilter(QObject *obj, QEvent *ev) |
2186 | { |
2187 | if (obj == m_button) { |
2188 | switch (ev->type()) { |
2189 | case QEvent::KeyPress: |
2190 | case QEvent::KeyRelease: { // Prevent the QToolButton from handling Enter/Escape meant control the delegate |
2191 | switch (static_cast<const QKeyEvent*>(ev)->key()) { |
2192 | case Qt::Key_Escape: |
2193 | case Qt::Key_Enter: |
2194 | case Qt::Key_Return: |
2195 | ev->ignore(); |
2196 | return true; |
2197 | default: |
2198 | break; |
2199 | } |
2200 | } |
2201 | break; |
2202 | default: |
2203 | break; |
2204 | } |
2205 | } |
2206 | return QWidget::eventFilter(watched: obj, event: ev); |
2207 | } |
2208 | |
2209 | // QtColorEditorFactoryPrivate |
2210 | |
2211 | class QtColorEditorFactoryPrivate : public EditorFactoryPrivate<QtColorEditWidget> |
2212 | { |
2213 | QtColorEditorFactory *q_ptr; |
2214 | Q_DECLARE_PUBLIC(QtColorEditorFactory) |
2215 | public: |
2216 | |
2217 | void slotPropertyChanged(QtProperty *property, const QColor &value); |
2218 | void slotSetValue(const QColor &value); |
2219 | }; |
2220 | |
2221 | void QtColorEditorFactoryPrivate::slotPropertyChanged(QtProperty *property, |
2222 | const QColor &value) |
2223 | { |
2224 | const PropertyToEditorListMap::const_iterator it = m_createdEditors.constFind(akey: property); |
2225 | if (it == m_createdEditors.constEnd()) |
2226 | return; |
2227 | |
2228 | for (QtColorEditWidget *e : it.value()) |
2229 | e->setValue(value); |
2230 | } |
2231 | |
2232 | void QtColorEditorFactoryPrivate::slotSetValue(const QColor &value) |
2233 | { |
2234 | QObject *object = q_ptr->sender(); |
2235 | const EditorToPropertyMap::ConstIterator ecend = m_editorToProperty.constEnd(); |
2236 | for (EditorToPropertyMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) |
2237 | if (itEditor.key() == object) { |
2238 | QtProperty *property = itEditor.value(); |
2239 | QtColorPropertyManager *manager = q_ptr->propertyManager(property); |
2240 | if (!manager) |
2241 | return; |
2242 | manager->setValue(property, val: value); |
2243 | return; |
2244 | } |
2245 | } |
2246 | |
2247 | /*! |
2248 | \class QtColorEditorFactory |
2249 | \internal |
2250 | \inmodule QtDesigner |
2251 | \since 4.4 |
2252 | |
2253 | \brief The QtColorEditorFactory class provides color editing for |
2254 | properties created by QtColorPropertyManager objects. |
2255 | |
2256 | \sa QtAbstractEditorFactory, QtColorPropertyManager |
2257 | */ |
2258 | |
2259 | /*! |
2260 | Creates a factory with the given \a parent. |
2261 | */ |
2262 | QtColorEditorFactory::QtColorEditorFactory(QObject *parent) : |
2263 | QtAbstractEditorFactory<QtColorPropertyManager>(parent), |
2264 | d_ptr(new QtColorEditorFactoryPrivate()) |
2265 | { |
2266 | d_ptr->q_ptr = this; |
2267 | } |
2268 | |
2269 | /*! |
2270 | Destroys this factory, and all the widgets it has created. |
2271 | */ |
2272 | QtColorEditorFactory::~QtColorEditorFactory() |
2273 | { |
2274 | qDeleteAll(c: d_ptr->m_editorToProperty.keys()); |
2275 | } |
2276 | |
2277 | /*! |
2278 | \internal |
2279 | |
2280 | Reimplemented from the QtAbstractEditorFactory class. |
2281 | */ |
2282 | void QtColorEditorFactory::connectPropertyManager(QtColorPropertyManager *manager) |
2283 | { |
2284 | connect(sender: manager, SIGNAL(valueChanged(QtProperty*,QColor)), |
2285 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,QColor))); |
2286 | } |
2287 | |
2288 | /*! |
2289 | \internal |
2290 | |
2291 | Reimplemented from the QtAbstractEditorFactory class. |
2292 | */ |
2293 | QWidget *QtColorEditorFactory::createEditor(QtColorPropertyManager *manager, |
2294 | QtProperty *property, QWidget *parent) |
2295 | { |
2296 | QtColorEditWidget *editor = d_ptr->createEditor(property, parent); |
2297 | editor->setValue(manager->value(property)); |
2298 | connect(sender: editor, SIGNAL(valueChanged(QColor)), receiver: this, SLOT(slotSetValue(QColor))); |
2299 | connect(sender: editor, SIGNAL(destroyed(QObject*)), receiver: this, SLOT(slotEditorDestroyed(QObject*))); |
2300 | return editor; |
2301 | } |
2302 | |
2303 | /*! |
2304 | \internal |
2305 | |
2306 | Reimplemented from the QtAbstractEditorFactory class. |
2307 | */ |
2308 | void QtColorEditorFactory::disconnectPropertyManager(QtColorPropertyManager *manager) |
2309 | { |
2310 | disconnect(sender: manager, SIGNAL(valueChanged(QtProperty*,QColor)), receiver: this, SLOT(slotPropertyChanged(QtProperty*,QColor))); |
2311 | } |
2312 | |
2313 | // QtFontEditWidget |
2314 | |
2315 | class QtFontEditWidget : public QWidget { |
2316 | Q_OBJECT |
2317 | |
2318 | public: |
2319 | QtFontEditWidget(QWidget *parent); |
2320 | |
2321 | bool eventFilter(QObject *obj, QEvent *ev); |
2322 | |
2323 | public Q_SLOTS: |
2324 | void setValue(const QFont &value); |
2325 | |
2326 | private Q_SLOTS: |
2327 | void buttonClicked(); |
2328 | |
2329 | Q_SIGNALS: |
2330 | void valueChanged(const QFont &value); |
2331 | |
2332 | private: |
2333 | QFont m_font; |
2334 | QLabel *m_pixmapLabel; |
2335 | QLabel *m_label; |
2336 | QToolButton *m_button; |
2337 | }; |
2338 | |
2339 | QtFontEditWidget::QtFontEditWidget(QWidget *parent) : |
2340 | QWidget(parent), |
2341 | m_pixmapLabel(new QLabel), |
2342 | m_label(new QLabel), |
2343 | m_button(new QToolButton) |
2344 | { |
2345 | QHBoxLayout *lt = new QHBoxLayout(this); |
2346 | setupTreeViewEditorMargin(lt); |
2347 | lt->setSpacing(0); |
2348 | lt->addWidget(m_pixmapLabel); |
2349 | lt->addWidget(m_label); |
2350 | lt->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored)); |
2351 | |
2352 | m_button->setSizePolicy(hor: QSizePolicy::Fixed, ver: QSizePolicy::Ignored); |
2353 | m_button->setFixedWidth(20); |
2354 | setFocusProxy(m_button); |
2355 | setFocusPolicy(m_button->focusPolicy()); |
2356 | m_button->setText(tr(s: "..." )); |
2357 | m_button->installEventFilter(filterObj: this); |
2358 | connect(sender: m_button, SIGNAL(clicked()), receiver: this, SLOT(buttonClicked())); |
2359 | lt->addWidget(m_button); |
2360 | m_pixmapLabel->setPixmap(QtPropertyBrowserUtils::fontValuePixmap(f: m_font)); |
2361 | m_label->setText(QtPropertyBrowserUtils::fontValueText(f: m_font)); |
2362 | } |
2363 | |
2364 | void QtFontEditWidget::setValue(const QFont &f) |
2365 | { |
2366 | if (m_font != f) { |
2367 | m_font = f; |
2368 | m_pixmapLabel->setPixmap(QtPropertyBrowserUtils::fontValuePixmap(f)); |
2369 | m_label->setText(QtPropertyBrowserUtils::fontValueText(f)); |
2370 | } |
2371 | } |
2372 | |
2373 | void QtFontEditWidget::buttonClicked() |
2374 | { |
2375 | bool ok = false; |
2376 | QFont newFont = QFontDialog::getFont(ok: &ok, initial: m_font, parent: this, title: tr(s: "Select Font" )); |
2377 | if (ok && newFont != m_font) { |
2378 | QFont f = m_font; |
2379 | // prevent mask for unchanged attributes, don't change other attributes (like kerning, etc...) |
2380 | if (m_font.family() != newFont.family()) |
2381 | f.setFamily(newFont.family()); |
2382 | if (m_font.pointSize() != newFont.pointSize()) |
2383 | f.setPointSize(newFont.pointSize()); |
2384 | if (m_font.bold() != newFont.bold()) |
2385 | f.setBold(newFont.bold()); |
2386 | if (m_font.italic() != newFont.italic()) |
2387 | f.setItalic(newFont.italic()); |
2388 | if (m_font.underline() != newFont.underline()) |
2389 | f.setUnderline(newFont.underline()); |
2390 | if (m_font.strikeOut() != newFont.strikeOut()) |
2391 | f.setStrikeOut(newFont.strikeOut()); |
2392 | setValue(f); |
2393 | emit valueChanged(value: m_font); |
2394 | } |
2395 | } |
2396 | |
2397 | bool QtFontEditWidget::eventFilter(QObject *obj, QEvent *ev) |
2398 | { |
2399 | if (obj == m_button) { |
2400 | switch (ev->type()) { |
2401 | case QEvent::KeyPress: |
2402 | case QEvent::KeyRelease: { // Prevent the QToolButton from handling Enter/Escape meant control the delegate |
2403 | switch (static_cast<const QKeyEvent*>(ev)->key()) { |
2404 | case Qt::Key_Escape: |
2405 | case Qt::Key_Enter: |
2406 | case Qt::Key_Return: |
2407 | ev->ignore(); |
2408 | return true; |
2409 | default: |
2410 | break; |
2411 | } |
2412 | } |
2413 | break; |
2414 | default: |
2415 | break; |
2416 | } |
2417 | } |
2418 | return QWidget::eventFilter(watched: obj, event: ev); |
2419 | } |
2420 | |
2421 | // QtFontEditorFactoryPrivate |
2422 | |
2423 | class QtFontEditorFactoryPrivate : public EditorFactoryPrivate<QtFontEditWidget> |
2424 | { |
2425 | QtFontEditorFactory *q_ptr; |
2426 | Q_DECLARE_PUBLIC(QtFontEditorFactory) |
2427 | public: |
2428 | |
2429 | void slotPropertyChanged(QtProperty *property, const QFont &value); |
2430 | void slotSetValue(const QFont &value); |
2431 | }; |
2432 | |
2433 | void QtFontEditorFactoryPrivate::slotPropertyChanged(QtProperty *property, |
2434 | const QFont &value) |
2435 | { |
2436 | const PropertyToEditorListMap::const_iterator it = m_createdEditors.constFind(akey: property); |
2437 | if (it == m_createdEditors.constEnd()) |
2438 | return; |
2439 | |
2440 | for (QtFontEditWidget *e : it.value()) |
2441 | e->setValue(value); |
2442 | } |
2443 | |
2444 | void QtFontEditorFactoryPrivate::slotSetValue(const QFont &value) |
2445 | { |
2446 | QObject *object = q_ptr->sender(); |
2447 | const EditorToPropertyMap::ConstIterator ecend = m_editorToProperty.constEnd(); |
2448 | for (EditorToPropertyMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) |
2449 | if (itEditor.key() == object) { |
2450 | QtProperty *property = itEditor.value(); |
2451 | QtFontPropertyManager *manager = q_ptr->propertyManager(property); |
2452 | if (!manager) |
2453 | return; |
2454 | manager->setValue(property, val: value); |
2455 | return; |
2456 | } |
2457 | } |
2458 | |
2459 | /*! |
2460 | \class QtFontEditorFactory |
2461 | \internal |
2462 | \inmodule QtDesigner |
2463 | \since 4.4 |
2464 | |
2465 | \brief The QtFontEditorFactory class provides font editing for |
2466 | properties created by QtFontPropertyManager objects. |
2467 | |
2468 | \sa QtAbstractEditorFactory, QtFontPropertyManager |
2469 | */ |
2470 | |
2471 | /*! |
2472 | Creates a factory with the given \a parent. |
2473 | */ |
2474 | QtFontEditorFactory::QtFontEditorFactory(QObject *parent) : |
2475 | QtAbstractEditorFactory<QtFontPropertyManager>(parent), |
2476 | d_ptr(new QtFontEditorFactoryPrivate()) |
2477 | { |
2478 | d_ptr->q_ptr = this; |
2479 | } |
2480 | |
2481 | /*! |
2482 | Destroys this factory, and all the widgets it has created. |
2483 | */ |
2484 | QtFontEditorFactory::~QtFontEditorFactory() |
2485 | { |
2486 | qDeleteAll(c: d_ptr->m_editorToProperty.keys()); |
2487 | } |
2488 | |
2489 | /*! |
2490 | \internal |
2491 | |
2492 | Reimplemented from the QtAbstractEditorFactory class. |
2493 | */ |
2494 | void QtFontEditorFactory::connectPropertyManager(QtFontPropertyManager *manager) |
2495 | { |
2496 | connect(sender: manager, SIGNAL(valueChanged(QtProperty*,QFont)), |
2497 | receiver: this, SLOT(slotPropertyChanged(QtProperty*,QFont))); |
2498 | } |
2499 | |
2500 | /*! |
2501 | \internal |
2502 | |
2503 | Reimplemented from the QtAbstractEditorFactory class. |
2504 | */ |
2505 | QWidget *QtFontEditorFactory::createEditor(QtFontPropertyManager *manager, |
2506 | QtProperty *property, QWidget *parent) |
2507 | { |
2508 | QtFontEditWidget *editor = d_ptr->createEditor(property, parent); |
2509 | editor->setValue(manager->value(property)); |
2510 | connect(sender: editor, SIGNAL(valueChanged(QFont)), receiver: this, SLOT(slotSetValue(QFont))); |
2511 | connect(sender: editor, SIGNAL(destroyed(QObject*)), receiver: this, SLOT(slotEditorDestroyed(QObject*))); |
2512 | return editor; |
2513 | } |
2514 | |
2515 | /*! |
2516 | \internal |
2517 | |
2518 | Reimplemented from the QtAbstractEditorFactory class. |
2519 | */ |
2520 | void QtFontEditorFactory::disconnectPropertyManager(QtFontPropertyManager *manager) |
2521 | { |
2522 | disconnect(sender: manager, SIGNAL(valueChanged(QtProperty*,QFont)), receiver: this, SLOT(slotPropertyChanged(QtProperty*,QFont))); |
2523 | } |
2524 | |
2525 | QT_END_NAMESPACE |
2526 | |
2527 | #include "moc_qteditorfactory.cpp" |
2528 | #include "qteditorfactory.moc" |
2529 | |