qteditorfactory.cpp 86 KB

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