qteditorfactory.cpp 76 KB

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