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