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