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