source: trunk/tools/designer/src/components/propertyeditor/designerpropertymanager.cpp@ 651

Last change on this file since 651 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 102.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the Qt Designer of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "designerpropertymanager.h"
43#include "qtpropertymanager.h"
44#include "paletteeditorbutton.h"
45#include "qlonglongvalidator.h"
46#include "stringlisteditorbutton.h"
47#include "qtresourceview_p.h"
48#include "qtpropertybrowserutils_p.h"
49
50#include <formwindowbase_p.h>
51#include <textpropertyeditor_p.h>
52#include <stylesheeteditor_p.h>
53#include <richtexteditor_p.h>
54#include <plaintexteditor_p.h>
55#include <iconloader_p.h>
56#include <iconselector_p.h>
57#include <abstractdialoggui_p.h>
58
59#include <QtDesigner/QDesignerIconCacheInterface>
60
61#include <QtGui/QLabel>
62#include <QtGui/QToolButton>
63#include <QtGui/QHBoxLayout>
64#include <QtCore/QFileInfo>
65#include <QtGui/QClipboard>
66#include <QtGui/QLineEdit>
67#include <QtGui/QDialogButtonBox>
68#include <QtGui/QPushButton>
69#include <QtGui/QFileDialog>
70#include <QtGui/QAction>
71#include <QtGui/QMenu>
72#include <QtGui/QContextMenuEvent>
73#include <QtGui/QApplication>
74#include <QtCore/QUrl>
75
76#include <QtCore/QDebug>
77
78QT_BEGIN_NAMESPACE
79
80static const char *resettableAttributeC = "resettable";
81static const char *flagsAttributeC = "flags";
82static const char *validationModesAttributeC = "validationMode";
83static const char *superPaletteAttributeC = "superPalette";
84static const char *defaultResourceAttributeC = "defaultResource";
85static const char *fontAttributeC = "font";
86
87class DesignerFlagPropertyType
88{
89};
90
91
92class DesignerAlignmentPropertyType
93{
94};
95
96QT_END_NAMESPACE
97
98Q_DECLARE_METATYPE(DesignerFlagPropertyType)
99Q_DECLARE_METATYPE(DesignerAlignmentPropertyType)
100
101QT_BEGIN_NAMESPACE
102
103namespace qdesigner_internal {
104
105// ------------ TextEditor
106class TextEditor : public QWidget
107{
108 Q_OBJECT
109public:
110 TextEditor(QDesignerFormEditorInterface *core, QWidget *parent);
111
112 TextPropertyValidationMode textPropertyValidationMode() const;
113 void setTextPropertyValidationMode(TextPropertyValidationMode vm);
114
115 void setRichTextDefaultFont(const QFont &font) { m_richTextDefaultFont = font; }
116 QFont richTextDefaultFont() const { return m_richTextDefaultFont; }
117
118 void setSpacing(int spacing);
119
120 TextPropertyEditor::UpdateMode updateMode() const { return m_editor->updateMode(); }
121 void setUpdateMode(TextPropertyEditor::UpdateMode um) { m_editor->setUpdateMode(um); }
122
123public slots:
124 void setText(const QString &text);
125
126signals:
127 void textChanged(const QString &text);
128
129private slots:
130 void buttonClicked();
131 void resourceActionActivated();
132 void fileActionActivated();
133private:
134 TextPropertyEditor *m_editor;
135 QFont m_richTextDefaultFont;
136 QToolButton *m_button;
137 QMenu *m_menu;
138 QAction *m_resourceAction;
139 QAction *m_fileAction;
140 QHBoxLayout *m_layout;
141 QDesignerFormEditorInterface *m_core;
142};
143
144TextEditor::TextEditor(QDesignerFormEditorInterface *core, QWidget *parent) :
145 QWidget(parent),
146 m_editor(new TextPropertyEditor(this)),
147 m_richTextDefaultFont(QApplication::font()),
148 m_button(new QToolButton(this)),
149 m_menu(new QMenu(this)),
150 m_resourceAction(new QAction(tr("Choose Resource..."), this)),
151 m_fileAction(new QAction(tr("Choose File..."), this)),
152 m_layout(new QHBoxLayout(this)),
153 m_core(core)
154{
155 m_layout->addWidget(m_editor);
156 m_button->setText(tr("..."));
157 m_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored);
158 m_button->setFixedWidth(20);
159 m_layout->addWidget(m_button);
160 m_layout->setMargin(0);
161 m_layout->setSpacing(0);
162
163 connect(m_resourceAction, SIGNAL(triggered()), this, SLOT(resourceActionActivated()));
164 connect(m_fileAction, SIGNAL(triggered()), this, SLOT(fileActionActivated()));
165 connect(m_editor, SIGNAL(textChanged(QString)), this, SIGNAL(textChanged(QString)));
166 connect(m_button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
167 setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
168 m_button->setVisible(false);
169 setFocusProxy(m_editor);
170
171 m_menu->addAction(m_resourceAction);
172 m_menu->addAction(m_fileAction);
173}
174
175void TextEditor::setSpacing(int spacing)
176{
177 m_layout->setSpacing(spacing);
178}
179
180TextPropertyValidationMode TextEditor::textPropertyValidationMode() const
181{
182 return m_editor->textPropertyValidationMode();
183}
184
185void TextEditor::setTextPropertyValidationMode(TextPropertyValidationMode vm)
186{
187 m_editor->setTextPropertyValidationMode(vm);
188 if (vm == ValidationURL) {
189 m_button->setMenu(m_menu);
190 m_button->setFixedWidth(30);
191 m_button->setPopupMode(QToolButton::MenuButtonPopup);
192 } else {
193 m_button->setMenu(0);
194 m_button->setFixedWidth(20);
195 m_button->setPopupMode(QToolButton::DelayedPopup);
196 }
197 m_button->setVisible(vm == ValidationStyleSheet || vm == ValidationRichText || vm == ValidationMultiLine || vm == ValidationURL);
198}
199
200void TextEditor::setText(const QString &text)
201{
202 m_editor->setText(text);
203}
204
205void TextEditor::buttonClicked()
206{
207 const QString oldText = m_editor->text();
208 QString newText;
209 switch (textPropertyValidationMode()) {
210 case ValidationStyleSheet: {
211 StyleSheetEditorDialog dlg(m_core, this);
212 dlg.setText(oldText);
213 if (dlg.exec() != QDialog::Accepted)
214 return;
215 newText = dlg.text();
216 }
217 break;
218 case ValidationRichText: {
219 RichTextEditorDialog dlg(m_core, this);
220 dlg.setDefaultFont(m_richTextDefaultFont);
221 dlg.setText(oldText);
222 if (dlg.showDialog() != QDialog::Accepted)
223 return;
224 newText = dlg.text(Qt::AutoText);
225 }
226 break;
227 case ValidationMultiLine: {
228 PlainTextEditorDialog dlg(m_core, this);
229 dlg.setDefaultFont(m_richTextDefaultFont);
230 dlg.setText(oldText);
231 if (dlg.showDialog() != QDialog::Accepted)
232 return;
233 newText = dlg.text();
234 }
235 break;
236 case ValidationURL: {
237 QString oldPath = oldText;
238 if (oldPath.isEmpty() || oldPath.startsWith(QLatin1String("qrc:")))
239 resourceActionActivated();
240 else
241 fileActionActivated();
242 }
243 return;
244 default:
245 return;
246 }
247 if (newText != oldText) {
248 m_editor->setText(newText);
249 emit textChanged(newText);
250 }
251}
252
253void TextEditor::resourceActionActivated()
254{
255 QString oldPath = m_editor->text();
256 if (oldPath.startsWith(QLatin1String("qrc:")))
257 oldPath.remove(0, 4);
258 // returns ':/file'
259 QString newPath = IconSelector::choosePixmapResource(m_core, m_core->resourceModel(), oldPath, this);
260 if (newPath.startsWith(QLatin1Char(':')))
261 newPath.remove(0, 1);
262 if (newPath.isEmpty() || newPath == oldPath)
263 return;
264 const QString newText = QLatin1String("qrc:") + newPath;
265 m_editor->setText(newText);
266 emit textChanged(newText);
267}
268
269void TextEditor::fileActionActivated()
270{
271 QString oldPath = m_editor->text();
272 if (oldPath.startsWith(QLatin1String("file:")))
273 oldPath = oldPath.mid(5);
274 const QString newPath = m_core->dialogGui()->getOpenFileName(this, tr("Choose a File"), oldPath);
275 if (newPath.isEmpty() || newPath == oldPath)
276 return;
277 const QString newText = QUrl::fromLocalFile(newPath).toString();
278 m_editor->setText(newText);
279 emit textChanged(newText);
280}
281
282// ------------ PixmapEditor
283class PixmapEditor : public QWidget
284{
285 Q_OBJECT
286public:
287 PixmapEditor(QDesignerFormEditorInterface *core, QWidget *parent);
288
289 void setSpacing(int spacing);
290 void setPixmapCache(DesignerPixmapCache *cache);
291public slots:
292 void setPath(const QString &path);
293 void setDefaultPixmap(const QPixmap &pixmap);
294
295signals:
296 void pathChanged(const QString &path);
297
298protected:
299 void contextMenuEvent(QContextMenuEvent *event);
300
301private slots:
302 void defaultActionActivated();
303 void resourceActionActivated();
304 void fileActionActivated();
305 void copyActionActivated();
306 void pasteActionActivated();
307 void clipboardDataChanged();
308private:
309 QDesignerFormEditorInterface *m_core;
310 QLabel *m_pixmapLabel;
311 QLabel *m_pathLabel;
312 QToolButton *m_button;
313 QAction *m_resourceAction;
314 QAction *m_fileAction;
315 QAction *m_copyAction;
316 QAction *m_pasteAction;
317 QHBoxLayout *m_layout;
318 QPixmap m_defaultPixmap;
319 QString m_path;
320 DesignerPixmapCache *m_pixmapCache;
321};
322
323PixmapEditor::PixmapEditor(QDesignerFormEditorInterface *core, QWidget *parent) :
324 QWidget(parent),
325 m_core(core),
326 m_pixmapLabel(new QLabel(this)),
327 m_pathLabel(new QLabel(this)),
328 m_button(new QToolButton(this)),
329 m_resourceAction(new QAction(tr("Choose Resource..."), this)),
330 m_fileAction(new QAction(tr("Choose File..."), this)),
331 m_copyAction(new QAction(createIconSet(QLatin1String("editcopy.png")), tr("Copy Path"), this)),
332 m_pasteAction(new QAction(createIconSet(QLatin1String("editpaste.png")), tr("Paste Path"), this)),
333 m_layout(new QHBoxLayout(this)),
334 m_pixmapCache(0)
335{
336 m_layout->addWidget(m_pixmapLabel);
337 m_layout->addWidget(m_pathLabel);
338 m_button->setText(tr("..."));
339 m_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored);
340 m_button->setFixedWidth(30);
341 m_button->setPopupMode(QToolButton::MenuButtonPopup);
342 m_layout->addWidget(m_button);
343 m_layout->setMargin(0);
344 m_layout->setSpacing(0);
345 m_pixmapLabel->setFixedWidth(16);
346 m_pixmapLabel->setAlignment(Qt::AlignCenter);
347 m_pathLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed));
348
349 QMenu *menu = new QMenu(this);
350 menu->addAction(m_resourceAction);
351 menu->addAction(m_fileAction);
352
353 m_button->setMenu(menu);
354 m_button->setText(tr("..."));
355
356 connect(m_button, SIGNAL(clicked()), this, SLOT(defaultActionActivated()));
357 connect(m_resourceAction, SIGNAL(triggered()), this, SLOT(resourceActionActivated()));
358 connect(m_fileAction, SIGNAL(triggered()), this, SLOT(fileActionActivated()));
359 connect(m_copyAction, SIGNAL(triggered()), this, SLOT(copyActionActivated()));
360 connect(m_pasteAction, SIGNAL(triggered()), this, SLOT(pasteActionActivated()));
361 setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored));
362 setFocusProxy(m_button);
363
364 connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
365 clipboardDataChanged();
366}
367
368void PixmapEditor::setPixmapCache(DesignerPixmapCache *cache)
369{
370 m_pixmapCache = cache;
371}
372
373void PixmapEditor::setSpacing(int spacing)
374{
375 m_layout->setSpacing(spacing);
376}
377
378void PixmapEditor::setPath(const QString &path)
379{
380 m_path = path;
381 if (m_path.isEmpty()) {
382 m_pathLabel->setText(path);
383 m_pixmapLabel->setPixmap(m_defaultPixmap);
384 m_copyAction->setEnabled(false);
385 } else {
386 m_pathLabel->setText(QFileInfo(m_path).fileName());
387 if (m_pixmapCache)
388 m_pixmapLabel->setPixmap(QIcon(m_pixmapCache->pixmap(PropertySheetPixmapValue(path))).pixmap(16, 16));
389 m_copyAction->setEnabled(true);
390 }
391}
392
393void PixmapEditor::setDefaultPixmap(const QPixmap &pixmap)
394{
395 m_defaultPixmap = QIcon(pixmap).pixmap(16, 16);
396 if (m_path.isEmpty())
397 m_pixmapLabel->setPixmap(m_defaultPixmap);
398}
399
400void PixmapEditor::contextMenuEvent(QContextMenuEvent *event)
401{
402 QMenu menu(this);
403 menu.addAction(m_copyAction);
404 menu.addAction(m_pasteAction);
405 menu.exec(event->globalPos());
406 event->accept();
407}
408
409void PixmapEditor::defaultActionActivated()
410{
411 // Default to resource
412 const PropertySheetPixmapValue::PixmapSource ps = m_path.isEmpty() ? PropertySheetPixmapValue::ResourcePixmap : PropertySheetPixmapValue::getPixmapSource(m_core, m_path);
413 switch (ps) {
414 case PropertySheetPixmapValue::LanguageResourcePixmap:
415 case PropertySheetPixmapValue::ResourcePixmap:
416 resourceActionActivated();
417 break;
418 case PropertySheetPixmapValue::FilePixmap:
419 fileActionActivated();
420 break;
421 }
422}
423
424void PixmapEditor::resourceActionActivated()
425{
426 const QString oldPath = m_path;
427 const QString newPath = IconSelector::choosePixmapResource(m_core, m_core->resourceModel(), oldPath, this);
428 if (!newPath.isEmpty() && newPath != oldPath) {
429 setPath(newPath);
430 emit pathChanged(newPath);
431 }
432}
433
434void PixmapEditor::fileActionActivated()
435{
436 const QString newPath = IconSelector::choosePixmapFile(m_path, m_core->dialogGui(), this);
437 if (!newPath.isEmpty() && newPath != m_path) {
438 setPath(newPath);
439 emit pathChanged(newPath);
440 }
441}
442
443void PixmapEditor::copyActionActivated()
444{
445 QClipboard *clipboard = QApplication::clipboard();
446 clipboard->setText(m_path);
447}
448
449void PixmapEditor::pasteActionActivated()
450{
451 QClipboard *clipboard = QApplication::clipboard();
452 QString subtype = QLatin1String("plain");
453 QString text = clipboard->text(subtype);
454 if (!text.isNull()) {
455 QStringList list = text.split(QLatin1Char('\n'));
456 if (list.size() > 0) {
457 text = list.at(0);
458 setPath(text);
459 emit pathChanged(text);
460 }
461 }
462}
463
464void PixmapEditor::clipboardDataChanged()
465{
466 QClipboard *clipboard = QApplication::clipboard();
467 QString subtype = QLatin1String("plain");
468 const QString text = clipboard->text(subtype);
469 m_pasteAction->setEnabled(!text.isNull());
470}
471
472// --------------- ResetWidget
473class ResetWidget : public QWidget
474{
475 Q_OBJECT
476public:
477 ResetWidget(QtProperty *property, QWidget *parent = 0);
478
479 void setWidget(QWidget *widget);
480 void setResetEnabled(bool enabled);
481 void setValueText(const QString &text);
482 void setValueIcon(const QIcon &icon);
483 void setSpacing(int spacing);
484signals:
485 void resetProperty(QtProperty *property);
486private slots:
487 void slotClicked();
488private:
489 QtProperty *m_property;
490 QLabel *m_textLabel;
491 QLabel *m_iconLabel;
492 QToolButton *m_button;
493 int m_spacing;
494};
495
496ResetWidget::ResetWidget(QtProperty *property, QWidget *parent) :
497 QWidget(parent),
498 m_property(property),
499 m_textLabel(new QLabel(this)),
500 m_iconLabel(new QLabel(this)),
501 m_button(new QToolButton(this)),
502 m_spacing(-1)
503{
504 m_textLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed));
505 m_iconLabel->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
506 m_button->setToolButtonStyle(Qt::ToolButtonIconOnly);
507 m_button->setIcon(createIconSet(QLatin1String("resetproperty.png")));
508 m_button->setIconSize(QSize(8,8));
509 m_button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding));
510 connect(m_button, SIGNAL(clicked()), this, SLOT(slotClicked()));
511 QLayout *layout = new QHBoxLayout(this);
512 layout->setMargin(0);
513 layout->setSpacing(m_spacing);
514 layout->addWidget(m_iconLabel);
515 layout->addWidget(m_textLabel);
516 layout->addWidget(m_button);
517 setFocusProxy(m_textLabel);
518 setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
519}
520
521void ResetWidget::setSpacing(int spacing)
522{
523 m_spacing = spacing;
524 layout()->setSpacing(m_spacing);
525}
526
527void ResetWidget::setWidget(QWidget *widget)
528{
529 if (m_textLabel) {
530 delete m_textLabel;
531 m_textLabel = 0;
532 }
533 if (m_iconLabel) {
534 delete m_iconLabel;
535 m_iconLabel = 0;
536 }
537 delete layout();
538 QLayout *layout = new QHBoxLayout(this);
539 layout->setMargin(0);
540 layout->setSpacing(m_spacing);
541 layout->addWidget(widget);
542 layout->addWidget(m_button);
543 setFocusProxy(widget);
544}
545
546void ResetWidget::setResetEnabled(bool enabled)
547{
548 m_button->setEnabled(enabled);
549}
550
551void ResetWidget::setValueText(const QString &text)
552{
553 if (m_textLabel)
554 m_textLabel->setText(text);
555}
556
557void ResetWidget::setValueIcon(const QIcon &icon)
558{
559 QPixmap pix = icon.pixmap(QSize(16, 16));
560 if (m_iconLabel) {
561 m_iconLabel->setVisible(!pix.isNull());
562 m_iconLabel->setPixmap(pix);
563 }
564}
565
566void ResetWidget::slotClicked()
567{
568 emit resetProperty(m_property);
569}
570
571
572// ------------ DesignerPropertyManager:
573
574DesignerPropertyManager::DesignerPropertyManager(QDesignerFormEditorInterface *core, QObject *parent) :
575 QtVariantPropertyManager(parent),
576 m_changingSubValue(false),
577 m_core(core),
578 m_sourceOfChange(0)
579{
580 connect(this, SIGNAL(valueChanged(QtProperty*,QVariant)), this, SLOT(slotValueChanged(QtProperty*,QVariant)));
581 connect(this, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*)));
582}
583
584DesignerPropertyManager::~DesignerPropertyManager()
585{
586 clear();
587}
588
589int DesignerPropertyManager::bitCount(int mask) const
590{
591 int count = 0;
592 for (; mask; count++)
593 mask &= mask - 1; // clear the least significant bit set
594 return count;
595}
596
597int DesignerPropertyManager::alignToIndexH(uint align) const
598{
599 if (align & Qt::AlignLeft)
600 return 0;
601 if (align & Qt::AlignHCenter)
602 return 1;
603 if (align & Qt::AlignRight)
604 return 2;
605 if (align & Qt::AlignJustify)
606 return 3;
607 return 0;
608}
609
610int DesignerPropertyManager::alignToIndexV(uint align) const
611{
612 if (align & Qt::AlignTop)
613 return 0;
614 if (align & Qt::AlignVCenter)
615 return 1;
616 if (align & Qt::AlignBottom)
617 return 2;
618 return 1;
619}
620
621uint DesignerPropertyManager::indexHToAlign(int idx) const
622{
623 switch (idx) {
624 case 0: return Qt::AlignLeft;
625 case 1: return Qt::AlignHCenter;
626 case 2: return Qt::AlignRight;
627 case 3: return Qt::AlignJustify;
628 default: break;
629 }
630 return Qt::AlignLeft;
631}
632
633uint DesignerPropertyManager::indexVToAlign(int idx) const
634{
635 switch (idx) {
636 case 0: return Qt::AlignTop;
637 case 1: return Qt::AlignVCenter;
638 case 2: return Qt::AlignBottom;
639 default: break;
640 }
641 return Qt::AlignVCenter;
642}
643
644QString DesignerPropertyManager::indexHToString(int idx) const
645{
646 switch (idx) {
647 case 0: return tr("AlignLeft");
648 case 1: return tr("AlignHCenter");
649 case 2: return tr("AlignRight");
650 case 3: return tr("AlignJustify");
651 default: break;
652 }
653 return tr("AlignLeft");
654}
655
656QString DesignerPropertyManager::indexVToString(int idx) const
657{
658 switch (idx) {
659 case 0: return tr("AlignTop");
660 case 1: return tr("AlignVCenter");
661 case 2: return tr("AlignBottom");
662 default: break;
663 }
664 return tr("AlignVCenter");
665}
666
667void DesignerPropertyManager::slotValueChanged(QtProperty *property, const QVariant &value)
668{
669 if (m_changingSubValue)
670 return;
671 bool enableSubPropertyHandling = true;
672
673 if (QtProperty *flagProperty = m_flagToProperty.value(property, 0)) {
674 const QList<QtProperty *> subFlags = m_propertyToFlags.value(flagProperty);
675 const int subFlagCount = subFlags.count();
676 // flag changed
677 const bool subValue = variantProperty(property)->value().toBool();
678 const int subIndex = subFlags.indexOf(property);
679 if (subIndex < 0)
680 return;
681
682 uint newValue = 0;
683
684 m_changingSubValue = true;
685
686 FlagData data = m_flagValues.value(flagProperty);
687 const QList<uint> values = data.values;
688 // Compute new value, without including (additional) supermasks
689 if (values.at(subIndex) == 0) {
690 for (int i = 0; i < subFlagCount; ++i) {
691 QtVariantProperty *subFlag = variantProperty(subFlags.at(i));
692 subFlag->setValue(i == subIndex);
693 }
694 } else {
695 if (subValue)
696 newValue = values.at(subIndex); // value mask of subValue
697 for (int i = 0; i < subFlagCount; ++i) {
698 QtVariantProperty *subFlag = variantProperty(subFlags.at(i));
699 if (subFlag->value().toBool() && bitCount(values.at(i)) == 1)
700 newValue |= values.at(i);
701 }
702 if (newValue == 0) {
703 // Uncheck all items except 0-mask
704 for (int i = 0; i < subFlagCount; ++i) {
705 QtVariantProperty *subFlag = variantProperty(subFlags.at(i));
706 subFlag->setValue(values.at(i) == 0);
707 }
708 } else if (newValue == data.val) {
709 if (!subValue && bitCount(values.at(subIndex)) > 1) {
710 // We unchecked something, but the original value still holds
711 variantProperty(property)->setValue(true);
712 }
713 } else {
714 // Make sure 0-mask is not selected
715 for (int i = 0; i < subFlagCount; ++i) {
716 QtVariantProperty *subFlag = variantProperty(subFlags.at(i));
717 if (values.at(i) == 0)
718 subFlag->setValue(false);
719 }
720 // Check/uncheck proper masks
721 if (subValue) {
722 // Make sure submasks and supermasks are selected
723 for (int i = 0; i < subFlagCount; ++i) {
724 QtVariantProperty *subFlag = variantProperty(subFlags.at(i));
725 const uint vi = values.at(i);
726 if ((vi != 0) && ((vi & newValue) == vi) && !subFlag->value().toBool())
727 subFlag->setValue(true);
728 }
729 } else {
730 // Make sure supermasks are not selected if they're no longer valid
731 for (int i = 0; i < subFlagCount; ++i) {
732 QtVariantProperty *subFlag = variantProperty(subFlags.at(i));
733 const uint vi = values.at(i);
734 if (subFlag->value().toBool() && ((vi & newValue) != vi))
735 subFlag->setValue(false);
736 }
737 }
738 }
739 }
740 m_changingSubValue = false;
741 data.val = newValue;
742 QVariant v;
743 qVariantSetValue(v, data.val);
744 variantProperty(flagProperty)->setValue(v);
745 } else if (QtProperty *alignProperty = m_alignHToProperty.value(property, 0)) {
746 const uint v = m_alignValues.value(alignProperty);
747 const uint newValue = indexHToAlign(value.toInt()) | indexVToAlign(alignToIndexV(v));
748 if (v == newValue)
749 return;
750
751 variantProperty(alignProperty)->setValue(newValue);
752 } else if (QtProperty *alignProperty = m_alignVToProperty.value(property, 0)) {
753 const uint v = m_alignValues.value(alignProperty);
754 const uint newValue = indexVToAlign(value.toInt()) | indexHToAlign(alignToIndexH(v));
755 if (v == newValue)
756 return;
757
758 variantProperty(alignProperty)->setValue(newValue);
759 } else if (QtProperty *stringProperty = m_commentToString.value(property, 0)) {
760 const PropertySheetStringValue v = m_stringValues.value(stringProperty);
761 PropertySheetStringValue newValue = v;
762 newValue.setComment(value.toString());
763 if (v == newValue)
764 return;
765
766 variantProperty(stringProperty)->setValue(qVariantFromValue(newValue));
767 } else if (QtProperty *stringProperty = m_translatableToString.value(property, 0)) {
768 const PropertySheetStringValue v = m_stringValues.value(stringProperty);
769 PropertySheetStringValue newValue = v;
770 newValue.setTranslatable(value.toBool());
771 if (v == newValue)
772 return;
773
774 variantProperty(stringProperty)->setValue(qVariantFromValue(newValue));
775 } else if (QtProperty *stringProperty = m_disambiguationToString.value(property, 0)) {
776 const PropertySheetStringValue v = m_stringValues.value(stringProperty);
777 PropertySheetStringValue newValue = v;
778 newValue.setDisambiguation(value.toString());
779 if (v == newValue)
780 return;
781
782 variantProperty(stringProperty)->setValue(qVariantFromValue(newValue));
783 } else if (QtProperty *keySequenceProperty = m_commentToKeySequence.value(property, 0)) {
784 const PropertySheetKeySequenceValue v = m_keySequenceValues.value(keySequenceProperty);
785 PropertySheetKeySequenceValue newValue = v;
786 newValue.setComment(value.toString());
787 if (v == newValue)
788 return;
789
790 variantProperty(keySequenceProperty)->setValue(qVariantFromValue(newValue));
791 } else if (QtProperty *keySequenceProperty = m_translatableToKeySequence.value(property, 0)) {
792 const PropertySheetKeySequenceValue v = m_keySequenceValues.value(keySequenceProperty);
793 PropertySheetKeySequenceValue newValue = v;
794 newValue.setTranslatable(value.toBool());
795 if (v == newValue)
796 return;
797
798 variantProperty(keySequenceProperty)->setValue(qVariantFromValue(newValue));
799 } else if (QtProperty *keySequenceProperty = m_disambiguationToKeySequence.value(property, 0)) {
800 const PropertySheetKeySequenceValue v = m_keySequenceValues.value(keySequenceProperty);
801 PropertySheetKeySequenceValue newValue = v;
802 newValue.setDisambiguation(value.toString());
803 if (v == newValue)
804 return;
805
806 variantProperty(keySequenceProperty)->setValue(qVariantFromValue(newValue));
807 } else if (QtProperty *iProperty = m_iconSubPropertyToProperty.value(property, 0)) {
808 QtVariantProperty *iconProperty = variantProperty(iProperty);
809 PropertySheetIconValue icon = qVariantValue<PropertySheetIconValue>(iconProperty->value());
810 QPair<QIcon::Mode, QIcon::State> pair = m_iconSubPropertyToState.value(property);
811 icon.setPixmap(pair.first, pair.second, qVariantValue<PropertySheetPixmapValue>(value));
812 QtProperty *origSourceOfChange = m_sourceOfChange;
813 if (!origSourceOfChange)
814 m_sourceOfChange = property;
815 iconProperty->setValue(qVariantFromValue(icon));
816 if (!origSourceOfChange)
817 m_sourceOfChange = origSourceOfChange;
818 } else if (m_iconValues.contains(property)) {
819 enableSubPropertyHandling = m_sourceOfChange;
820 } else {
821 if (m_brushManager.valueChanged(this, property, value) == BrushPropertyManager::Unchanged)
822 return;
823 if (m_fontManager.valueChanged(this, property, value) == FontPropertyManager::Unchanged)
824 return;
825 }
826
827 emit valueChanged(property, value, enableSubPropertyHandling);
828}
829
830void DesignerPropertyManager::slotPropertyDestroyed(QtProperty *property)
831{
832 if (QtProperty *flagProperty = m_flagToProperty.value(property, 0)) {
833 PropertyToPropertyListMap::iterator it = m_propertyToFlags.find(flagProperty);
834 QList<QtProperty *> &propertyList = it.value();
835 propertyList.replace(propertyList.indexOf(property), 0);
836 m_flagToProperty.remove(property);
837 } else if (QtProperty *alignProperty = m_alignHToProperty.value(property, 0)) {
838 m_propertyToAlignH.remove(alignProperty);
839 m_alignHToProperty.remove(property);
840 } else if (QtProperty *alignProperty = m_alignVToProperty.value(property, 0)) {
841 m_propertyToAlignV.remove(alignProperty);
842 m_alignVToProperty.remove(property);
843 } else if (QtProperty *stringCommentProperty = m_commentToString.value(property, 0)) {
844 m_stringToComment.remove(stringCommentProperty);
845 m_commentToString.remove(property);
846 } else if (QtProperty *stringTranslatableProperty = m_translatableToString.value(property, 0)) {
847 m_stringToTranslatable.remove(stringTranslatableProperty);
848 m_translatableToString.remove(property);
849 } else if (QtProperty *stringDisambiguationProperty = m_disambiguationToString.value(property, 0)) {
850 m_stringToDisambiguation.remove(stringDisambiguationProperty);
851 m_disambiguationToString.remove(property);
852 } else if (QtProperty *keySequenceCommentProperty = m_commentToKeySequence.value(property, 0)) {
853 m_keySequenceToComment.remove(keySequenceCommentProperty);
854 m_commentToKeySequence.remove(property);
855 } else if (QtProperty *keySequenceTranslatableProperty = m_translatableToKeySequence.value(property, 0)) {
856 m_keySequenceToTranslatable.remove(keySequenceTranslatableProperty);
857 m_translatableToKeySequence.remove(property);
858 } else if (QtProperty *keySequenceDisambiguationProperty = m_disambiguationToKeySequence.value(property, 0)) {
859 m_keySequenceToDisambiguation.remove(keySequenceDisambiguationProperty);
860 m_disambiguationToKeySequence.remove(property);
861 } else if (QtProperty *iconProperty = m_iconSubPropertyToProperty.value(property, 0)) {
862 QMap<QtProperty *, QMap<QPair<QIcon::Mode, QIcon::State>, QtProperty *> >::iterator it =
863 m_propertyToIconSubProperties.find(iconProperty);
864 QPair<QIcon::Mode, QIcon::State> state = m_iconSubPropertyToState.value(property);
865 QMap<QPair<QIcon::Mode, QIcon::State>, QtProperty *> &propertyList = it.value();
866 propertyList.remove(state);
867 m_iconSubPropertyToState.remove(property);
868 m_iconSubPropertyToProperty.remove(property);
869 } else {
870 m_fontManager.slotPropertyDestroyed(property);
871 m_brushManager.slotPropertyDestroyed(property);
872 }
873}
874
875QStringList DesignerPropertyManager::attributes(int propertyType) const
876{
877 if (!isPropertyTypeSupported(propertyType))
878 return QStringList();
879
880 QStringList list = QtVariantPropertyManager::attributes(propertyType);
881 if (propertyType == designerFlagTypeId()) {
882 list.append(QLatin1String(flagsAttributeC));
883 } else if (propertyType == designerPixmapTypeId()) {
884 list.append(QLatin1String(defaultResourceAttributeC));
885 } else if (propertyType == designerIconTypeId()) {
886 list.append(QLatin1String(defaultResourceAttributeC));
887 } else if (propertyType == designerStringTypeId() || propertyType == QVariant::String) {
888 list.append(QLatin1String(validationModesAttributeC));
889 list.append(QLatin1String(fontAttributeC));
890 } else if (propertyType == QVariant::Palette) {
891 list.append(QLatin1String(superPaletteAttributeC));
892 }
893 list.append(QLatin1String(resettableAttributeC));
894 return list;
895}
896
897int DesignerPropertyManager::attributeType(int propertyType, const QString &attribute) const
898{
899 if (!isPropertyTypeSupported(propertyType))
900 return 0;
901
902 if (propertyType == designerFlagTypeId() && attribute == QLatin1String(flagsAttributeC))
903 return designerFlagListTypeId();
904 if (propertyType == designerPixmapTypeId() && attribute == QLatin1String(defaultResourceAttributeC))
905 return QVariant::Pixmap;
906 if (propertyType == designerIconTypeId() && attribute == QLatin1String(defaultResourceAttributeC))
907 return QVariant::Icon;
908 if (attribute == QLatin1String(resettableAttributeC))
909 return QVariant::Bool;
910 if (propertyType == designerStringTypeId() || propertyType == QVariant::String) {
911 if (attribute == QLatin1String(validationModesAttributeC))
912 return QVariant::Int;
913 if (attribute == QLatin1String(fontAttributeC))
914 return QVariant::Font;
915 }
916 if (propertyType == QVariant::Palette && attribute == QLatin1String(superPaletteAttributeC))
917 return QVariant::Palette;
918
919 return QtVariantPropertyManager::attributeType(propertyType, attribute);
920}
921
922QVariant DesignerPropertyManager::attributeValue(const QtProperty *property, const QString &attribute) const
923{
924 QtProperty *prop = const_cast<QtProperty *>(property);
925
926 if (attribute == QLatin1String(resettableAttributeC)) {
927 const PropertyBoolMap::const_iterator it = m_resetMap.constFind(prop);
928 if (it != m_resetMap.constEnd())
929 return it.value();
930 }
931
932 if (attribute == QLatin1String(flagsAttributeC)) {
933 PropertyFlagDataMap::const_iterator it = m_flagValues.constFind(prop);
934 if (it != m_flagValues.constEnd()) {
935 QVariant v;
936 qVariantSetValue(v, it.value().flags);
937 return v;
938 }
939 }
940 if (attribute == QLatin1String(validationModesAttributeC)) {
941 const PropertyIntMap::const_iterator it = m_stringAttributes.constFind(prop);
942 if (it != m_stringAttributes.constEnd())
943 return it.value();
944 }
945
946 if (attribute == QLatin1String(fontAttributeC)) {
947 const PropertyFontMap::const_iterator it = m_stringFontAttributes.constFind(prop);
948 if (it != m_stringFontAttributes.constEnd())
949 return it.value();
950 }
951
952 if (attribute == QLatin1String(superPaletteAttributeC)) {
953 PropertyPaletteDataMap::const_iterator it = m_paletteValues.constFind(prop);
954 if (it != m_paletteValues.constEnd())
955 return it.value().superPalette;
956 }
957
958 if (attribute == QLatin1String(defaultResourceAttributeC)) {
959 QMap<QtProperty *, QPixmap>::const_iterator itPix = m_defaultPixmaps.constFind(prop);
960 if (itPix != m_defaultPixmaps.constEnd())
961 return itPix.value();
962
963 QMap<QtProperty *, QIcon>::const_iterator itIcon = m_defaultIcons.constFind(prop);
964 if (itIcon != m_defaultIcons.constEnd())
965 return itIcon.value();
966 }
967
968 return QtVariantPropertyManager::attributeValue(property, attribute);
969}
970
971void DesignerPropertyManager::setAttribute(QtProperty *property,
972 const QString &attribute, const QVariant &value)
973{
974 if (attribute == QLatin1String(resettableAttributeC) && m_resetMap.contains(property)) {
975 if (value.userType() != QVariant::Bool)
976 return;
977 const bool val = value.toBool();
978 const PropertyBoolMap::iterator it = m_resetMap.find(property);
979 if (it.value() == val)
980 return;
981 it.value() = val;
982 emit attributeChanged(variantProperty(property), attribute, value);
983 return;
984 } else if (attribute == QLatin1String(flagsAttributeC) && m_flagValues.contains(property)) {
985 if (value.userType() != designerFlagListTypeId())
986 return;
987
988 const DesignerFlagList flags = qVariantValue<DesignerFlagList>(value);
989 PropertyFlagDataMap::iterator fit = m_flagValues.find(property);
990 FlagData data = fit.value();
991 if (data.flags == flags)
992 return;
993
994 PropertyToPropertyListMap::iterator pfit = m_propertyToFlags.find(property);
995 QListIterator<QtProperty *> itProp(pfit.value());
996 while (itProp.hasNext()) {
997 if (QtProperty *prop = itProp.next()) {
998 delete prop;
999 m_flagToProperty.remove(prop);
1000 }
1001 }
1002 pfit.value().clear();
1003
1004 QList<uint> values;
1005
1006 QListIterator<QPair<QString, uint> > itFlag(flags);
1007 while (itFlag.hasNext()) {
1008 const QPair<QString, uint> pair = itFlag.next();
1009 const QString flagName = pair.first;
1010 QtProperty *prop = addProperty(QVariant::Bool);
1011 prop->setPropertyName(flagName);
1012 property->addSubProperty(prop);
1013 m_propertyToFlags[property].append(prop);
1014 m_flagToProperty[prop] = property;
1015 values.append(pair.second);
1016 }
1017
1018 data.val = 0;
1019 data.flags = flags;
1020 data.values = values;
1021
1022 fit.value() = data;
1023
1024 QVariant v;
1025 qVariantSetValue(v, flags);
1026 emit attributeChanged(property, attribute, v);
1027
1028 emit propertyChanged(property);
1029 emit QtVariantPropertyManager::valueChanged(property, data.val);
1030 } else if (attribute == QLatin1String(validationModesAttributeC) && m_stringAttributes.contains(property)) {
1031 if (value.userType() != QVariant::Int)
1032 return;
1033
1034 const PropertyIntMap::iterator it = m_stringAttributes.find(property);
1035 const int oldValue = it.value();
1036
1037 const int newValue = value.toInt();
1038
1039 if (oldValue == newValue)
1040 return;
1041
1042 it.value() = newValue;
1043
1044 emit attributeChanged(property, attribute, newValue);
1045 } else if (attribute == QLatin1String(fontAttributeC) && m_stringFontAttributes.contains(property)) {
1046 if (value.userType() != QVariant::Font)
1047 return;
1048
1049 const PropertyFontMap::iterator it = m_stringFontAttributes.find(property);
1050 const QFont oldValue = it.value();
1051
1052 const QFont newValue = qvariant_cast<QFont>(value);
1053
1054 if (oldValue == newValue)
1055 return;
1056
1057 it.value() = newValue;
1058
1059 emit attributeChanged(property, attribute, newValue);
1060 } else if (attribute == QLatin1String(superPaletteAttributeC) && m_paletteValues.contains(property)) {
1061 if (value.userType() != QVariant::Palette)
1062 return;
1063
1064 QPalette superPalette = qVariantValue<QPalette>(value);
1065
1066 const PropertyPaletteDataMap::iterator it = m_paletteValues.find(property);
1067 PaletteData data = it.value();
1068 if (data.superPalette == superPalette)
1069 return;
1070
1071 data.superPalette = superPalette;
1072 // resolve here
1073 const uint mask = data.val.resolve();
1074 data.val = data.val.resolve(superPalette);
1075 data.val.resolve(mask);
1076
1077 it.value() = data;
1078
1079 QVariant v;
1080 qVariantSetValue(v, superPalette);
1081 emit attributeChanged(property, attribute, v);
1082
1083 emit propertyChanged(property);
1084 emit QtVariantPropertyManager::valueChanged(property, data.val); // if resolve was done, this is also for consistency
1085 } else if (attribute == QLatin1String(defaultResourceAttributeC) && m_defaultPixmaps.contains(property)) {
1086 if (value.userType() != QVariant::Pixmap)
1087 return;
1088
1089 QPixmap defaultPixmap = qVariantValue<QPixmap>(value);
1090
1091 const QMap<QtProperty *, QPixmap>::iterator it = m_defaultPixmaps.find(property);
1092 QPixmap oldDefaultPixmap = it.value();
1093 if (defaultPixmap.cacheKey() == oldDefaultPixmap.cacheKey())
1094 return;
1095
1096 it.value() = defaultPixmap;
1097
1098 QVariant v = qVariantFromValue(defaultPixmap);
1099 emit attributeChanged(property, attribute, v);
1100
1101 emit propertyChanged(property);
1102 } else if (attribute == QLatin1String(defaultResourceAttributeC) && m_defaultIcons.contains(property)) {
1103 if (value.userType() != QVariant::Icon)
1104 return;
1105
1106 QIcon defaultIcon = qVariantValue<QIcon>(value);
1107
1108 const QMap<QtProperty *, QIcon>::iterator it = m_defaultIcons.find(property);
1109 QIcon oldDefaultIcon = it.value();
1110 if (defaultIcon.cacheKey() == oldDefaultIcon.cacheKey())
1111 return;
1112
1113 it.value() = defaultIcon;
1114
1115 qdesigner_internal::PropertySheetIconValue icon = m_iconValues.value(property);
1116 if (icon.paths().isEmpty()) {
1117 QMap<QPair<QIcon::Mode, QIcon::State>, QtProperty *> subIconProperties = m_propertyToIconSubProperties.value(property);
1118 QMapIterator<QPair<QIcon::Mode, QIcon::State>, QtProperty *> itSub(subIconProperties);
1119 while (itSub.hasNext()) {
1120 QPair<QIcon::Mode, QIcon::State> pair = itSub.next().key();
1121 QtProperty *subProp = itSub.value();
1122 setAttribute(subProp, QLatin1String(defaultResourceAttributeC),
1123 defaultIcon.pixmap(16, 16, pair.first, pair.second));
1124 }
1125 }
1126
1127 QVariant v = qVariantFromValue(defaultIcon);
1128 emit attributeChanged(property, attribute, v);
1129
1130 emit propertyChanged(property);
1131 }
1132 QtVariantPropertyManager::setAttribute(property, attribute, value);
1133}
1134
1135int DesignerPropertyManager::designerFlagTypeId()
1136{
1137 static const int rc = qMetaTypeId<DesignerFlagPropertyType>();
1138 return rc;
1139}
1140
1141int DesignerPropertyManager::designerFlagListTypeId()
1142{
1143 static const int rc = qMetaTypeId<DesignerFlagList>();
1144 return rc;
1145}
1146
1147int DesignerPropertyManager::designerAlignmentTypeId()
1148{
1149 static const int rc = qMetaTypeId<DesignerAlignmentPropertyType>();
1150 return rc;
1151}
1152
1153int DesignerPropertyManager::designerPixmapTypeId()
1154{
1155 return qMetaTypeId<PropertySheetPixmapValue>();
1156}
1157
1158int DesignerPropertyManager::designerIconTypeId()
1159{
1160 return qMetaTypeId<PropertySheetIconValue>();
1161}
1162
1163int DesignerPropertyManager::designerStringTypeId()
1164{
1165 return qMetaTypeId<PropertySheetStringValue>();
1166}
1167
1168int DesignerPropertyManager::designerKeySequenceTypeId()
1169{
1170 return qMetaTypeId<PropertySheetKeySequenceValue>();
1171}
1172
1173bool DesignerPropertyManager::isPropertyTypeSupported(int propertyType) const
1174{
1175 switch (propertyType) {
1176 case QVariant::Palette:
1177 case QVariant::UInt:
1178 case QVariant::LongLong:
1179 case QVariant::ULongLong:
1180 case QVariant::Url:
1181 case QVariant::ByteArray:
1182 case QVariant::StringList:
1183 case QVariant::Brush:
1184 return true;
1185 default:
1186 break;
1187 }
1188
1189 if (propertyType == designerFlagTypeId())
1190 return true;
1191 if (propertyType == designerAlignmentTypeId())
1192 return true;
1193 if (propertyType == designerPixmapTypeId())
1194 return true;
1195 if (propertyType == designerIconTypeId())
1196 return true;
1197 if (propertyType == designerStringTypeId())
1198 return true;
1199 if (propertyType == designerKeySequenceTypeId())
1200 return true;
1201 return QtVariantPropertyManager::isPropertyTypeSupported(propertyType);
1202}
1203
1204QString DesignerPropertyManager::valueText(const QtProperty *property) const
1205{
1206 if (m_flagValues.contains(const_cast<QtProperty *>(property))) {
1207 const FlagData data = m_flagValues.value(const_cast<QtProperty *>(property));
1208 const uint v = data.val;
1209 const QChar bar = QLatin1Char('|');
1210 QString valueStr;
1211 const QList<QPair<QString, uint> > flags = data.flags;
1212 const QList<QPair<QString, uint> >::const_iterator fcend = flags.constEnd();
1213 for (QList<QPair<QString, uint> >::const_iterator it = flags.constBegin(); it != fcend; ++it) {
1214 const uint val = it->second;
1215 const bool checked = (val == 0) ? (v == 0) : ((val & v) == val);
1216 if (checked) {
1217 if (!valueStr.isEmpty())
1218 valueStr += bar;
1219 valueStr += it->first;
1220 }
1221 }
1222 return valueStr;
1223 }
1224 if (m_alignValues.contains(const_cast<QtProperty *>(property))) {
1225 const uint v = m_alignValues.value(const_cast<QtProperty *>(property));
1226 return tr("%1, %2").arg(indexHToString(alignToIndexH(v))).arg(indexVToString(alignToIndexV(v)));
1227 }
1228 if (m_paletteValues.contains(const_cast<QtProperty *>(property))) {
1229 const PaletteData data = m_paletteValues.value(const_cast<QtProperty *>(property));
1230 const uint mask = data.val.resolve();
1231 if (mask)
1232 return tr("Customized (%n roles)", 0, bitCount(mask));
1233 static const QString inherited = tr("Inherited");
1234 return inherited;
1235 }
1236 if (m_iconValues.contains(const_cast<QtProperty *>(property))) {
1237 const PropertySheetIconValue::ModeStateToPixmapMap paths = m_iconValues.value(const_cast<QtProperty *>(property)).paths();
1238 const PropertySheetIconValue::ModeStateToPixmapMap::const_iterator it = paths.constFind(qMakePair(QIcon::Normal, QIcon::Off));
1239 if (it == paths.constEnd())
1240 return QString();
1241 return QFileInfo(it.value().path()).fileName();
1242 }
1243 if (m_pixmapValues.contains(const_cast<QtProperty *>(property))) {
1244 const QString path = m_pixmapValues.value(const_cast<QtProperty *>(property)).path();
1245 if (path.isEmpty())
1246 return QString();
1247 return QFileInfo(path).fileName();
1248 }
1249 if (m_uintValues.contains(const_cast<QtProperty *>(property))) {
1250 return QString::number(m_uintValues.value(const_cast<QtProperty *>(property)));
1251 }
1252 if (m_longLongValues.contains(const_cast<QtProperty *>(property))) {
1253 return QString::number(m_longLongValues.value(const_cast<QtProperty *>(property)));
1254 }
1255 if (m_uLongLongValues.contains(const_cast<QtProperty *>(property))) {
1256 return QString::number(m_uLongLongValues.value(const_cast<QtProperty *>(property)));
1257 }
1258 if (m_urlValues.contains(const_cast<QtProperty *>(property))) {
1259 return m_urlValues.value(const_cast<QtProperty *>(property)).toString();
1260 }
1261 if (m_byteArrayValues.contains(const_cast<QtProperty *>(property))) {
1262 return QString::fromUtf8(m_byteArrayValues.value(const_cast<QtProperty *>(property)));
1263 }
1264 if (m_stringListValues.contains(const_cast<QtProperty *>(property))) {
1265 return m_stringListValues.value(const_cast<QtProperty *>(property)).join(QLatin1String("; "));
1266 }
1267 if (QtVariantPropertyManager::valueType(property) == QVariant::String || QtVariantPropertyManager::valueType(property) == designerStringTypeId()) {
1268 const QString str = (QtVariantPropertyManager::valueType(property) == QVariant::String) ? value(property).toString() : qVariantValue<PropertySheetStringValue>(value(property)).value();
1269 const int validationMode = attributeValue(property, QLatin1String(validationModesAttributeC)).toInt();
1270 return TextPropertyEditor::stringToEditorString(str, static_cast<TextPropertyValidationMode>(validationMode));
1271 }
1272 if (QtVariantPropertyManager::valueType(property) == designerKeySequenceTypeId()) {
1273 return qVariantValue<PropertySheetKeySequenceValue>(value(property)).value();
1274 }
1275 if (QtVariantPropertyManager::valueType(property) == QVariant::Bool) {
1276 return QString();
1277 }
1278
1279 QString rc;
1280 if (m_brushManager.valueText(property, &rc))
1281 return rc;
1282 return QtVariantPropertyManager::valueText(property);
1283}
1284
1285void DesignerPropertyManager::reloadResourceProperties()
1286{
1287 DesignerIconCache *iconCache = 0;
1288 QMapIterator<QtProperty *, qdesigner_internal::PropertySheetIconValue> itIcon(m_iconValues);
1289 while (itIcon.hasNext()) {
1290 QtProperty *property = itIcon.next().key();
1291 PropertySheetIconValue icon = itIcon.value();
1292
1293 QIcon defaultIcon = m_defaultIcons.value(property);
1294 if (!icon.paths().isEmpty()) {
1295 if (!iconCache) {
1296 QDesignerFormWindowInterface *formWindow = QDesignerFormWindowInterface::findFormWindow(m_object);
1297 qdesigner_internal::FormWindowBase *fwb = qobject_cast<qdesigner_internal::FormWindowBase *>(formWindow);
1298 iconCache = fwb->iconCache();
1299 }
1300 if (iconCache)
1301 defaultIcon = iconCache->icon(icon);
1302 }
1303
1304 QMap<QPair<QIcon::Mode, QIcon::State>, PropertySheetPixmapValue> iconPaths = icon.paths();
1305
1306 QMap<QPair<QIcon::Mode, QIcon::State>, QtProperty *> subProperties = m_propertyToIconSubProperties.value(property);
1307 QMapIterator<QPair<QIcon::Mode, QIcon::State>, QtProperty *> itSub(subProperties);
1308 while (itSub.hasNext()) {
1309 const QPair<QIcon::Mode, QIcon::State> pair = itSub.next().key();
1310 QtVariantProperty *subProperty = variantProperty(itSub.value());
1311 subProperty->setAttribute(QLatin1String(defaultResourceAttributeC),
1312 defaultIcon.pixmap(16, 16, pair.first, pair.second));
1313 }
1314
1315 emit propertyChanged(property);
1316 emit QtVariantPropertyManager::valueChanged(property, qVariantFromValue(itIcon.value()));
1317 }
1318 QMapIterator<QtProperty *, qdesigner_internal::PropertySheetPixmapValue> itPix(m_pixmapValues);
1319 while (itPix.hasNext()) {
1320 QtProperty *property = itPix.next().key();
1321 emit propertyChanged(property);
1322 emit QtVariantPropertyManager::valueChanged(property, qVariantFromValue(itPix.value()));
1323 }
1324}
1325
1326QIcon DesignerPropertyManager::valueIcon(const QtProperty *property) const
1327{
1328 if (m_iconValues.contains(const_cast<QtProperty *>(property))) {
1329 if (!property->isModified())
1330 return m_defaultIcons.value(const_cast<QtProperty *>(property)).pixmap(16, 16);
1331 QDesignerFormWindowInterface *formWindow = QDesignerFormWindowInterface::findFormWindow(m_object);
1332 qdesigner_internal::FormWindowBase *fwb = qobject_cast<qdesigner_internal::FormWindowBase *>(formWindow);
1333 if (fwb)
1334 return fwb->iconCache()->icon(m_iconValues.value(const_cast<QtProperty *>(property))).pixmap(16, 16);
1335 } else if (m_pixmapValues.contains(const_cast<QtProperty *>(property))) {
1336 if (!property->isModified())
1337 return m_defaultPixmaps.value(const_cast<QtProperty *>(property));
1338 QDesignerFormWindowInterface *formWindow = QDesignerFormWindowInterface::findFormWindow(m_object);
1339 qdesigner_internal::FormWindowBase *fwb = qobject_cast<qdesigner_internal::FormWindowBase *>(formWindow);
1340 if (fwb)
1341 return fwb->pixmapCache()->pixmap(m_pixmapValues.value(const_cast<QtProperty *>(property)));
1342 } else {
1343 QIcon rc;
1344 if (m_brushManager.valueIcon(property, &rc))
1345 return rc;
1346 }
1347
1348 return QtVariantPropertyManager::valueIcon(property);
1349}
1350
1351QVariant DesignerPropertyManager::value(const QtProperty *property) const
1352{
1353 if (m_flagValues.contains(const_cast<QtProperty *>(property)))
1354 return m_flagValues.value(const_cast<QtProperty *>(property)).val;
1355 if (m_alignValues.contains(const_cast<QtProperty *>(property)))
1356 return m_alignValues.value(const_cast<QtProperty *>(property));
1357 if (m_paletteValues.contains(const_cast<QtProperty *>(property)))
1358 return m_paletteValues.value(const_cast<QtProperty *>(property)).val;
1359 if (m_iconValues.contains(const_cast<QtProperty *>(property)))
1360 return qVariantFromValue(m_iconValues.value(const_cast<QtProperty *>(property)));
1361 if (m_pixmapValues.contains(const_cast<QtProperty *>(property)))
1362 return qVariantFromValue(m_pixmapValues.value(const_cast<QtProperty *>(property)));
1363 if (m_stringValues.contains(const_cast<QtProperty *>(property)))
1364 return qVariantFromValue(m_stringValues.value(const_cast<QtProperty *>(property)));
1365 if (m_keySequenceValues.contains(const_cast<QtProperty *>(property)))
1366 return qVariantFromValue(m_keySequenceValues.value(const_cast<QtProperty *>(property)));
1367 if (m_uintValues.contains(const_cast<QtProperty *>(property)))
1368 return m_uintValues.value(const_cast<QtProperty *>(property));
1369 if (m_longLongValues.contains(const_cast<QtProperty *>(property)))
1370 return m_longLongValues.value(const_cast<QtProperty *>(property));
1371 if (m_uLongLongValues.contains(const_cast<QtProperty *>(property)))
1372 return m_uLongLongValues.value(const_cast<QtProperty *>(property));
1373 if (m_urlValues.contains(const_cast<QtProperty *>(property)))
1374 return m_urlValues.value(const_cast<QtProperty *>(property));
1375 if (m_byteArrayValues.contains(const_cast<QtProperty *>(property)))
1376 return m_byteArrayValues.value(const_cast<QtProperty *>(property));
1377 if (m_stringListValues.contains(const_cast<QtProperty *>(property)))
1378 return m_stringListValues.value(const_cast<QtProperty *>(property));
1379
1380 QVariant rc;
1381 if (m_brushManager.value(property, &rc))
1382 return rc;
1383 return QtVariantPropertyManager::value(property);
1384}
1385
1386int DesignerPropertyManager::valueType(int propertyType) const
1387{
1388 switch (propertyType) {
1389 case QVariant::Palette:
1390 case QVariant::UInt:
1391 case QVariant::LongLong:
1392 case QVariant::ULongLong:
1393 case QVariant::Url:
1394 case QVariant::ByteArray:
1395 case QVariant::StringList:
1396 case QVariant::Brush:
1397 return propertyType;
1398 default:
1399 break;
1400 }
1401 if (propertyType == designerFlagTypeId())
1402 return QVariant::UInt;
1403 if (propertyType == designerAlignmentTypeId())
1404 return QVariant::UInt;
1405 if (propertyType == designerPixmapTypeId())
1406 return propertyType;
1407 if (propertyType == designerIconTypeId())
1408 return propertyType;
1409 if (propertyType == designerStringTypeId())
1410 return propertyType;
1411 if (propertyType == designerKeySequenceTypeId())
1412 return propertyType;
1413 return QtVariantPropertyManager::valueType(propertyType);
1414}
1415
1416void DesignerPropertyManager::setValue(QtProperty *property, const QVariant &value)
1417{
1418 const PropertyFlagDataMap::iterator fit = m_flagValues.find(property);
1419
1420 if (fit != m_flagValues.end()) {
1421 if (value.type() != QVariant::UInt && !value.canConvert(QVariant::UInt))
1422 return;
1423
1424 const uint v = value.toUInt();
1425
1426 FlagData data = fit.value();
1427 if (data.val == v)
1428 return;
1429
1430 // set Value
1431
1432 const QList<uint> values = data.values;
1433 const QList<QtProperty *> subFlags = m_propertyToFlags.value(property);
1434 const int subFlagCount = subFlags.count();
1435 for (int i = 0; i < subFlagCount; ++i) {
1436 QtVariantProperty *subFlag = variantProperty(subFlags.at(i));
1437 const uint val = values.at(i);
1438 const bool checked = (val == 0) ? (v == 0) : ((val & v) == val);
1439 subFlag->setValue(checked);
1440 }
1441
1442 for (int i = 0; i < subFlagCount; ++i) {
1443 QtVariantProperty *subFlag = variantProperty(subFlags.at(i));
1444 const uint val = values.at(i);
1445 const bool checked = (val == 0) ? (v == 0) : ((val & v) == val);
1446 bool enabled = true;
1447 if (val == 0) {
1448 if (checked)
1449 enabled = false;
1450 } else if (bitCount(val) > 1) {
1451 // Disabled if all flags contained in the mask are checked
1452 uint currentMask = 0;
1453 for (int j = 0; j < subFlagCount; ++j) {
1454 QtVariantProperty *subFlag = variantProperty(subFlags.at(j));
1455 if (bitCount(values.at(j)) == 1)
1456 currentMask |= subFlag->value().toBool() ? values.at(j) : 0;
1457 }
1458 if ((currentMask & values.at(i)) == values.at(i))
1459 enabled = false;
1460 }
1461 subFlag->setEnabled(enabled);
1462 }
1463
1464 data.val = v;
1465 fit.value() = data;
1466
1467 emit QtVariantPropertyManager::valueChanged(property, data.val);
1468 emit propertyChanged(property);
1469
1470 return;
1471 } else if (m_alignValues.contains(property)) {
1472 if (value.type() != QVariant::UInt && !value.canConvert(QVariant::UInt))
1473 return;
1474
1475 const uint v = value.toUInt();
1476
1477 uint val = m_alignValues.value(property);
1478
1479 if (val == v)
1480 return;
1481
1482 QtVariantProperty *alignH = variantProperty(m_propertyToAlignH.value(property));
1483 QtVariantProperty *alignV = variantProperty(m_propertyToAlignV.value(property));
1484
1485 if (alignH)
1486 alignH->setValue(alignToIndexH(v));
1487 if (alignV)
1488 alignV->setValue(alignToIndexV(v));
1489
1490 m_alignValues[property] = v;
1491
1492 emit QtVariantPropertyManager::valueChanged(property, v);
1493 emit propertyChanged(property);
1494
1495 return;
1496 } else if (m_stringValues.contains(property)) {
1497 if (value.userType() != designerStringTypeId())
1498 return;
1499
1500 const PropertySheetStringValue v = qVariantValue<PropertySheetStringValue>(value);
1501
1502 const PropertySheetStringValue val = m_stringValues.value(property);
1503
1504 if (val == v)
1505 return;
1506
1507 QtVariantProperty *comment = variantProperty(m_stringToComment.value(property));
1508 QtVariantProperty *translatable = variantProperty(m_stringToTranslatable.value(property));
1509 QtVariantProperty *disambiguation = variantProperty(m_stringToDisambiguation.value(property));
1510
1511 if (comment)
1512 comment->setValue(v.comment());
1513 if (translatable)
1514 translatable->setValue(v.translatable());
1515 if (disambiguation)
1516 disambiguation->setValue(v.disambiguation());
1517
1518 m_stringValues[property] = v;
1519
1520 emit QtVariantPropertyManager::valueChanged(property, qVariantFromValue(v));
1521 emit propertyChanged(property);
1522
1523 return;
1524 } else if (m_keySequenceValues.contains(property)) {
1525 if (value.userType() != designerKeySequenceTypeId())
1526 return;
1527
1528 const PropertySheetKeySequenceValue v = qVariantValue<PropertySheetKeySequenceValue>(value);
1529
1530 const PropertySheetKeySequenceValue val = m_keySequenceValues.value(property);
1531
1532 if (val == v)
1533 return;
1534
1535 QtVariantProperty *comment = variantProperty(m_keySequenceToComment.value(property));
1536 QtVariantProperty *translatable = variantProperty(m_keySequenceToTranslatable.value(property));
1537 QtVariantProperty *disambiguation = variantProperty(m_keySequenceToDisambiguation.value(property));
1538
1539 if (comment)
1540 comment->setValue(v.comment());
1541 if (translatable)
1542 translatable->setValue(v.translatable());
1543 if (disambiguation)
1544 disambiguation->setValue(v.disambiguation());
1545
1546 m_keySequenceValues[property] = v;
1547
1548 emit QtVariantPropertyManager::valueChanged(property, qVariantFromValue(v));
1549 emit propertyChanged(property);
1550
1551 return;
1552 } else if (m_paletteValues.contains(property)) {
1553 if (value.type() != QVariant::Palette && !value.canConvert(QVariant::Palette))
1554 return;
1555
1556 QPalette p = qVariantValue<QPalette>(value);
1557
1558 PaletteData data = m_paletteValues.value(property);
1559
1560 const uint mask = p.resolve();
1561 p = p.resolve(data.superPalette);
1562 p.resolve(mask);
1563
1564 if (data.val == p && data.val.resolve() == p.resolve())
1565 return;
1566
1567 data.val = p;
1568 m_paletteValues[property] = data;
1569
1570 emit QtVariantPropertyManager::valueChanged(property, data.val);
1571 emit propertyChanged(property);
1572
1573 return;
1574 } else if (m_iconValues.contains(property)) {
1575 if (value.userType() != designerIconTypeId())
1576 return;
1577
1578 const PropertySheetIconValue icon = qVariantValue<PropertySheetIconValue>(value);
1579
1580 const PropertySheetIconValue oldIcon = m_iconValues.value(property);
1581 if (icon == oldIcon)
1582 return;
1583
1584 m_iconValues[property] = icon;
1585
1586 QIcon defaultIcon = m_defaultIcons.value(property);
1587 if (!icon.paths().isEmpty()) {
1588 QDesignerFormWindowInterface *formWindow = QDesignerFormWindowInterface::findFormWindow(m_object);
1589 qdesigner_internal::FormWindowBase *fwb = qobject_cast<qdesigner_internal::FormWindowBase *>(formWindow);
1590 if (fwb)
1591 defaultIcon = fwb->iconCache()->icon(icon);
1592 }
1593
1594 QMap<QPair<QIcon::Mode, QIcon::State>, PropertySheetPixmapValue> iconPaths = icon.paths();
1595
1596 QMap<QPair<QIcon::Mode, QIcon::State>, QtProperty *> subProperties = m_propertyToIconSubProperties.value(property);
1597 QMapIterator<QPair<QIcon::Mode, QIcon::State>, QtProperty *> itSub(subProperties);
1598 while (itSub.hasNext()) {
1599 const QPair<QIcon::Mode, QIcon::State> pair = itSub.next().key();
1600 QtVariantProperty *subProperty = variantProperty(itSub.value());
1601 bool hasPath = iconPaths.contains(pair);
1602 subProperty->setModified(hasPath);
1603 subProperty->setValue(qVariantFromValue(iconPaths.value(pair)));
1604 subProperty->setAttribute(QLatin1String(defaultResourceAttributeC),
1605 defaultIcon.pixmap(16, 16, pair.first, pair.second));
1606 }
1607
1608 emit QtVariantPropertyManager::valueChanged(property, qVariantFromValue(icon));
1609 emit propertyChanged(property);
1610
1611 QString toolTip;
1612 const QMap<QPair<QIcon::Mode, QIcon::State>, PropertySheetPixmapValue>::ConstIterator itNormalOff =
1613 iconPaths.constFind(qMakePair(QIcon::Normal, QIcon::Off));
1614 if (itNormalOff != iconPaths.constEnd())
1615 toolTip = itNormalOff.value().path();
1616 property->setToolTip(toolTip);
1617
1618 return;
1619 } else if (m_pixmapValues.contains(property)) {
1620 if (value.userType() != designerPixmapTypeId())
1621 return;
1622
1623 const PropertySheetPixmapValue pixmap = qVariantValue<PropertySheetPixmapValue>(value);
1624
1625 const PropertySheetPixmapValue oldPixmap = m_pixmapValues.value(property);
1626 if (pixmap == oldPixmap)
1627 return;
1628
1629 m_pixmapValues[property] = pixmap;
1630
1631 emit QtVariantPropertyManager::valueChanged(property, qVariantFromValue(pixmap));
1632 emit propertyChanged(property);
1633
1634 property->setToolTip(pixmap.path());
1635
1636 return;
1637 } else if (m_uintValues.contains(property)) {
1638 if (value.type() != QVariant::UInt && !value.canConvert(QVariant::UInt))
1639 return;
1640
1641 const uint v = value.toUInt(0);
1642
1643 const uint oldValue = m_uintValues.value(property);
1644 if (v == oldValue)
1645 return;
1646
1647 m_uintValues[property] = v;
1648
1649 emit QtVariantPropertyManager::valueChanged(property, v);
1650 emit propertyChanged(property);
1651
1652 return;
1653 } else if (m_longLongValues.contains(property)) {
1654 if (value.type() != QVariant::LongLong && !value.canConvert(QVariant::LongLong))
1655 return;
1656
1657 const qlonglong v = value.toLongLong(0);
1658
1659 const qlonglong oldValue = m_longLongValues.value(property);
1660 if (v == oldValue)
1661 return;
1662
1663 m_longLongValues[property] = v;
1664
1665 emit QtVariantPropertyManager::valueChanged(property, v);
1666 emit propertyChanged(property);
1667
1668 return;
1669 } else if (m_uLongLongValues.contains(property)) {
1670 if (value.type() != QVariant::ULongLong && !value.canConvert(QVariant::ULongLong))
1671 return;
1672
1673 qulonglong v = value.toULongLong(0);
1674
1675 qulonglong oldValue = m_uLongLongValues.value(property);
1676 if (v == oldValue)
1677 return;
1678
1679 m_uLongLongValues[property] = v;
1680
1681 emit QtVariantPropertyManager::valueChanged(property, v);
1682 emit propertyChanged(property);
1683
1684 return;
1685 } else if (m_urlValues.contains(property)) {
1686 if (value.type() != QVariant::Url && !value.canConvert(QVariant::Url))
1687 return;
1688
1689 const QUrl v = value.toUrl();
1690
1691 const QUrl oldValue = m_urlValues.value(property);
1692 if (v == oldValue)
1693 return;
1694
1695 m_urlValues[property] = v;
1696
1697 emit QtVariantPropertyManager::valueChanged(property, v);
1698 emit propertyChanged(property);
1699
1700 return;
1701 } else if (m_byteArrayValues.contains(property)) {
1702 if (value.type() != QVariant::ByteArray && !value.canConvert(QVariant::ByteArray))
1703 return;
1704
1705 const QByteArray v = value.toByteArray();
1706
1707 const QByteArray oldValue = m_byteArrayValues.value(property);
1708 if (v == oldValue)
1709 return;
1710
1711 m_byteArrayValues[property] = v;
1712
1713 emit QtVariantPropertyManager::valueChanged(property, v);
1714 emit propertyChanged(property);
1715
1716 return;
1717 } else if (m_stringListValues.contains(property)) {
1718 if (value.type() != QVariant::StringList && !value.canConvert(QVariant::StringList))
1719 return;
1720
1721 const QStringList v = value.toStringList();
1722
1723 const QStringList oldValue = m_stringListValues.value(property);
1724 if (v == oldValue)
1725 return;
1726
1727 m_stringListValues[property] = v;
1728
1729 emit QtVariantPropertyManager::valueChanged(property, v);
1730 emit propertyChanged(property);
1731
1732 return;
1733 }
1734 switch (m_brushManager.setValue(this, property, value)) {
1735 case BrushPropertyManager::Unchanged:
1736 return;
1737 case BrushPropertyManager::Changed:
1738 emit QtVariantPropertyManager::valueChanged(property, value);
1739 emit propertyChanged(property);
1740 return;
1741 default:
1742 break;
1743 }
1744 m_fontManager.setValue(this, property, value);
1745 QtVariantPropertyManager::setValue(property, value);
1746 if (QtVariantPropertyManager::valueType(property) == QVariant::String)
1747 property->setToolTip(DesignerPropertyManager::value(property).toString());
1748 else if (QtVariantPropertyManager::valueType(property) == designerStringTypeId())
1749 property->setToolTip(qVariantValue<PropertySheetStringValue>(DesignerPropertyManager::value(property)).value());
1750 else if (QtVariantPropertyManager::valueType(property) == designerKeySequenceTypeId())
1751 property->setToolTip(qVariantValue<PropertySheetKeySequenceValue>(DesignerPropertyManager::value(property)).value());
1752 else if (QtVariantPropertyManager::valueType(property) == QVariant::Bool)
1753 property->setToolTip(QtVariantPropertyManager::valueText(property));
1754}
1755
1756void DesignerPropertyManager::initializeProperty(QtProperty *property)
1757{
1758 m_resetMap[property] = false;
1759
1760 const int type = propertyType(property);
1761 m_fontManager.preInitializeProperty(property, type, m_resetMap);
1762 switch (type) {
1763 case QVariant::Palette:
1764 m_paletteValues[property] = PaletteData();
1765 break;
1766 case QVariant::String:
1767 m_stringAttributes[property] = ValidationSingleLine;
1768 m_stringFontAttributes[property] = QApplication::font();
1769 break;
1770 case QVariant::UInt:
1771 m_uintValues[property] = 0;
1772 break;
1773 case QVariant::LongLong:
1774 m_longLongValues[property] = 0;
1775 break;
1776 case QVariant::ULongLong:
1777 m_uLongLongValues[property] = 0;
1778 break;
1779 case QVariant::Url:
1780 m_urlValues[property] = QUrl();
1781 break;
1782 case QVariant::ByteArray:
1783 m_byteArrayValues[property] = 0;
1784 break;
1785 case QVariant::StringList:
1786 m_stringListValues[property] = QStringList();
1787 break;
1788 case QVariant::Brush:
1789 m_brushManager.initializeProperty(this, property, enumTypeId());
1790 break;
1791 default:
1792 if (type == designerFlagTypeId()) {
1793 m_flagValues[property] = FlagData();
1794 m_propertyToFlags[property] = QList<QtProperty *>();
1795 } else if (type == designerAlignmentTypeId()) {
1796 const uint align = Qt::AlignLeft | Qt::AlignVCenter;
1797 m_alignValues[property] = align;
1798
1799 QtVariantProperty *alignH = addProperty(enumTypeId(), tr("Horizontal"));
1800 QStringList namesH;
1801 namesH << indexHToString(0) << indexHToString(1) << indexHToString(2) << indexHToString(3);
1802 alignH->setAttribute(QLatin1String("enumNames"), namesH);
1803 alignH->setValue(alignToIndexH(align));
1804 m_propertyToAlignH[property] = alignH;
1805 m_alignHToProperty[alignH] = property;
1806 property->addSubProperty(alignH);
1807
1808 QtVariantProperty *alignV = addProperty(enumTypeId(), tr("Vertical"));
1809 QStringList namesV;
1810 namesV << indexVToString(0) << indexVToString(1) << indexVToString(2);
1811 alignV->setAttribute(QLatin1String("enumNames"), namesV);
1812 alignV->setValue(alignToIndexV(align));
1813 m_propertyToAlignV[property] = alignV;
1814 m_alignVToProperty[alignV] = property;
1815 property->addSubProperty(alignV);
1816 } else if (type == designerPixmapTypeId()) {
1817 m_pixmapValues[property] = PropertySheetPixmapValue();
1818 m_defaultPixmaps[property] = QPixmap();
1819 } else if (type == designerIconTypeId()) {
1820 m_iconValues[property] = PropertySheetIconValue();
1821 m_defaultIcons[property] = QIcon();
1822
1823 createIconSubProperty(property, QIcon::Normal, QIcon::Off, tr("Normal Off"));
1824 createIconSubProperty(property, QIcon::Normal, QIcon::On, tr("Normal On"));
1825 createIconSubProperty(property, QIcon::Disabled, QIcon::Off, tr("Disabled Off"));
1826 createIconSubProperty(property, QIcon::Disabled, QIcon::On, tr("Disabled On"));
1827 createIconSubProperty(property, QIcon::Active, QIcon::Off, tr("Active Off"));
1828 createIconSubProperty(property, QIcon::Active, QIcon::On, tr("Active On"));
1829 createIconSubProperty(property, QIcon::Selected, QIcon::Off, tr("Selected Off"));
1830 createIconSubProperty(property, QIcon::Selected, QIcon::On, tr("Selected On"));
1831 } else if (type == designerStringTypeId()) {
1832 PropertySheetStringValue val;
1833 m_stringValues[property] = val;
1834 m_stringAttributes[property] = ValidationMultiLine;
1835 m_stringFontAttributes[property] = QApplication::font();
1836
1837 QtVariantProperty *translatable = addProperty(QVariant::Bool, tr("translatable"));
1838 translatable->setValue(val.translatable());
1839 m_stringToTranslatable[property] = translatable;
1840 m_translatableToString[translatable] = property;
1841 property->addSubProperty(translatable);
1842
1843 QtVariantProperty *disambiguation = addProperty(QVariant::String, tr("disambiguation"));
1844 disambiguation->setValue(val.disambiguation());
1845 m_stringToDisambiguation[property] = disambiguation;
1846 m_disambiguationToString[disambiguation] = property;
1847 property->addSubProperty(disambiguation);
1848
1849 QtVariantProperty *comment = addProperty(QVariant::String, tr("comment"));
1850 comment->setValue(val.comment());
1851 m_stringToComment[property] = comment;
1852 m_commentToString[comment] = property;
1853 property->addSubProperty(comment);
1854 } else if (type == designerKeySequenceTypeId()) {
1855 PropertySheetKeySequenceValue val;
1856 m_keySequenceValues[property] = val;
1857
1858 QtVariantProperty *translatable = addProperty(QVariant::Bool, tr("translatable"));
1859 translatable->setValue(val.translatable());
1860 m_keySequenceToTranslatable[property] = translatable;
1861 m_translatableToKeySequence[translatable] = property;
1862 property->addSubProperty(translatable);
1863
1864 QtVariantProperty *disambiguation = addProperty(QVariant::String, tr("disambiguation"));
1865 disambiguation->setValue(val.disambiguation());
1866 m_keySequenceToDisambiguation[property] = disambiguation;
1867 m_disambiguationToKeySequence[disambiguation] = property;
1868 property->addSubProperty(disambiguation);
1869
1870 QtVariantProperty *comment = addProperty(QVariant::String, tr("comment"));
1871 comment->setValue(val.comment());
1872 m_keySequenceToComment[property] = comment;
1873 m_commentToKeySequence[comment] = property;
1874 property->addSubProperty(comment);
1875 }
1876 }
1877
1878 QtVariantPropertyManager::initializeProperty(property);
1879 m_fontManager.postInitializeProperty(this, property, type, DesignerPropertyManager::enumTypeId());
1880 if (type == QVariant::Double)
1881 setAttribute(property, QLatin1String("decimals"), 6);
1882}
1883
1884void DesignerPropertyManager::createIconSubProperty(QtProperty *iconProperty, QIcon::Mode mode, QIcon::State state, const QString &subName)
1885{
1886 QPair<QIcon::Mode, QIcon::State> pair = qMakePair(mode, state);
1887 QtVariantProperty *subProp = addProperty(DesignerPropertyManager::designerPixmapTypeId(), subName);
1888 m_propertyToIconSubProperties[iconProperty][pair] = subProp;
1889 m_iconSubPropertyToState[subProp] = pair;
1890 m_iconSubPropertyToProperty[subProp] = iconProperty;
1891 m_resetMap[subProp] = true;
1892 iconProperty->addSubProperty(subProp);
1893}
1894
1895void DesignerPropertyManager::uninitializeProperty(QtProperty *property)
1896{
1897 m_resetMap.remove(property);
1898
1899 QListIterator<QtProperty *> itProp(m_propertyToFlags[property]);
1900 while (itProp.hasNext()) {
1901 QtProperty *prop = itProp.next();
1902 if (prop) {
1903 delete prop;
1904 m_flagToProperty.remove(prop);
1905 }
1906 }
1907 m_propertyToFlags.remove(property);
1908 m_flagValues.remove(property);
1909
1910 QtProperty *alignH = m_propertyToAlignH.value(property);
1911 if (alignH) {
1912 delete alignH;
1913 m_alignHToProperty.remove(alignH);
1914 }
1915 QtProperty *alignV = m_propertyToAlignV.value(property);
1916 if (alignV) {
1917 delete alignV;
1918 m_alignVToProperty.remove(alignV);
1919 }
1920
1921 QtProperty *stringComment = m_stringToComment.value(property);
1922 if (stringComment) {
1923 delete stringComment;
1924 m_stringToComment.remove(stringComment);
1925 }
1926
1927 QtProperty *stringTranslatable = m_stringToTranslatable.value(property);
1928 if (stringTranslatable) {
1929 delete stringTranslatable;
1930 m_stringToTranslatable.remove(stringTranslatable);
1931 }
1932
1933 QtProperty *stringDisambiguation = m_stringToDisambiguation.value(property);
1934 if (stringDisambiguation) {
1935 delete stringDisambiguation;
1936 m_stringToDisambiguation.remove(stringDisambiguation);
1937 }
1938
1939 QtProperty *keySequenceComment = m_keySequenceToComment.value(property);
1940 if (keySequenceComment) {
1941 delete keySequenceComment;
1942 m_keySequenceToComment.remove(keySequenceComment);
1943 }
1944
1945 QtProperty *keySequenceTranslatable = m_keySequenceToTranslatable.value(property);
1946 if (keySequenceTranslatable) {
1947 delete keySequenceTranslatable;
1948 m_keySequenceToTranslatable.remove(keySequenceTranslatable);
1949 }
1950
1951 QtProperty *keySequenceDisambiguation = m_keySequenceToDisambiguation.value(property);
1952 if (keySequenceDisambiguation) {
1953 delete keySequenceDisambiguation;
1954 m_keySequenceToDisambiguation.remove(keySequenceDisambiguation);
1955 }
1956
1957 m_propertyToAlignH.remove(property);
1958 m_propertyToAlignV.remove(property);
1959
1960 m_stringToComment.remove(property);
1961 m_stringToTranslatable.remove(property);
1962 m_stringToDisambiguation.remove(property);
1963 m_stringValues.remove(property);
1964 m_stringAttributes.remove(property);
1965 m_stringFontAttributes.remove(property);
1966
1967 m_keySequenceToComment.remove(property);
1968 m_keySequenceToTranslatable.remove(property);
1969 m_keySequenceToDisambiguation.remove(property);
1970 m_keySequenceValues.remove(property);
1971
1972 m_paletteValues.remove(property);
1973
1974 m_iconValues.remove(property);
1975 m_defaultIcons.remove(property);
1976
1977 m_pixmapValues.remove(property);
1978 m_defaultPixmaps.remove(property);
1979
1980 QMap<QPair<QIcon::Mode, QIcon::State>, QtProperty *> iconSubProperties = m_propertyToIconSubProperties.value(property);
1981 QMapIterator<QPair<QIcon::Mode, QIcon::State>, QtProperty *> itIcon(iconSubProperties);
1982 while (itIcon.hasNext()) {
1983 QtProperty *subIcon = itIcon.next().value();
1984 delete subIcon;
1985 m_iconSubPropertyToState.remove(subIcon);
1986 m_iconSubPropertyToProperty.remove(subIcon);
1987 }
1988 m_propertyToIconSubProperties.remove(property);
1989 m_iconSubPropertyToState.remove(property);
1990 m_iconSubPropertyToProperty.remove(property);
1991
1992 m_uintValues.remove(property);
1993 m_longLongValues.remove(property);
1994 m_uLongLongValues.remove(property);
1995 m_urlValues.remove(property);
1996 m_byteArrayValues.remove(property);
1997 m_stringListValues.remove(property);
1998
1999 m_fontManager.uninitializeProperty(property);
2000 m_brushManager.uninitializeProperty(property);
2001
2002 QtVariantPropertyManager::uninitializeProperty(property);
2003}
2004
2005
2006bool DesignerPropertyManager::resetFontSubProperty(QtProperty *property)
2007{
2008 return m_fontManager.resetFontSubProperty(this, property);
2009}
2010
2011bool DesignerPropertyManager::resetIconSubProperty(QtProperty *property)
2012{
2013 if (!m_iconSubPropertyToProperty.contains(property))
2014 return false;
2015
2016 if (!m_pixmapValues.contains(property))
2017 return false;
2018
2019 QtVariantProperty *pixmapProperty = variantProperty(property);
2020 pixmapProperty->setValue(qVariantFromValue(PropertySheetPixmapValue()));
2021 return true;
2022}
2023
2024// -------- DesignerEditorFactory
2025DesignerEditorFactory::DesignerEditorFactory(QDesignerFormEditorInterface *core, QObject *parent) :
2026 QtVariantEditorFactory(parent),
2027 m_resetDecorator(new ResetDecorator(this)),
2028 m_changingPropertyValue(false),
2029 m_core(core),
2030 m_spacing(-1)
2031{
2032 connect(m_resetDecorator, SIGNAL(resetProperty(QtProperty*)), this, SIGNAL(resetProperty(QtProperty*)));
2033}
2034
2035DesignerEditorFactory::~DesignerEditorFactory()
2036{
2037}
2038
2039void DesignerEditorFactory::setSpacing(int spacing)
2040{
2041 m_spacing = spacing;
2042 m_resetDecorator->setSpacing(spacing);
2043}
2044
2045void DesignerEditorFactory::setFormWindowBase(qdesigner_internal::FormWindowBase *fwb)
2046{
2047 m_fwb = fwb;
2048 DesignerPixmapCache *cache = 0;
2049 if (fwb)
2050 cache = fwb->pixmapCache();
2051 QMapIterator<PixmapEditor *, QtProperty *> itPixmapEditor(m_editorToPixmapProperty);
2052 while (itPixmapEditor.hasNext()) {
2053 PixmapEditor *pe = itPixmapEditor.next().key();
2054 pe->setPixmapCache(cache);
2055 }
2056 QMapIterator<PixmapEditor *, QtProperty *> itIconEditor(m_editorToIconProperty);
2057 while (itIconEditor.hasNext()) {
2058 PixmapEditor *pe = itIconEditor.next().key();
2059 pe->setPixmapCache(cache);
2060 }
2061}
2062
2063void DesignerEditorFactory::connectPropertyManager(QtVariantPropertyManager *manager)
2064{
2065 m_resetDecorator->connectPropertyManager(manager);
2066 connect(manager, SIGNAL(attributeChanged(QtProperty*,QString,QVariant)),
2067 this, SLOT(slotAttributeChanged(QtProperty*,QString,QVariant)));
2068 connect(manager, SIGNAL(valueChanged(QtProperty*,QVariant)),
2069 this, SLOT(slotValueChanged(QtProperty*,QVariant)));
2070 connect(manager, SIGNAL(propertyChanged(QtProperty*)),
2071 this, SLOT(slotPropertyChanged(QtProperty*)));
2072 QtVariantEditorFactory::connectPropertyManager(manager);
2073}
2074
2075void DesignerEditorFactory::disconnectPropertyManager(QtVariantPropertyManager *manager)
2076{
2077 m_resetDecorator->disconnectPropertyManager(manager);
2078 disconnect(manager, SIGNAL(attributeChanged(QtProperty*,QString,QVariant)),
2079 this, SLOT(slotAttributeChanged(QtProperty*,QString,QVariant)));
2080 disconnect(manager, SIGNAL(valueChanged(QtProperty*,QVariant)),
2081 this, SLOT(slotValueChanged(QtProperty*,QVariant)));
2082 disconnect(manager, SIGNAL(propertyChanged(QtProperty*)),
2083 this, SLOT(slotPropertyChanged(QtProperty*)));
2084 QtVariantEditorFactory::disconnectPropertyManager(manager);
2085}
2086
2087// A helper that calls a setter with a value on a pointer list of editor objects.
2088// Could use QList<Editor*> instead of EditorContainer/Editor, but that crashes VS 6.
2089template <class EditorContainer, class Editor, class SetterParameter, class Value>
2090static inline void applyToEditors(const EditorContainer &list, void (Editor::*setter)(SetterParameter), const Value &value)
2091{
2092 typedef Q_TYPENAME EditorContainer::const_iterator ListIterator;
2093 if (list.empty()) {
2094 return;
2095 }
2096 const ListIterator end = list.constEnd();
2097 for (ListIterator it = list.constBegin(); it != end; ++it) {
2098 Editor &editor = *(*it);
2099 (editor.*setter)(value);
2100 }
2101}
2102
2103void DesignerEditorFactory::slotAttributeChanged(QtProperty *property, const QString &attribute, const QVariant &value)
2104{
2105 QtVariantPropertyManager *manager = propertyManager(property);
2106 const int type = manager->propertyType(property);
2107 if (type == DesignerPropertyManager::designerPixmapTypeId() && attribute == QLatin1String(defaultResourceAttributeC)) {
2108 const QPixmap pixmap = qvariant_cast<QPixmap>(value);
2109 applyToEditors(m_pixmapPropertyToEditors.value(property), &PixmapEditor::setDefaultPixmap, pixmap);
2110 } else if (type == DesignerPropertyManager::designerStringTypeId() || type == QVariant::String) {
2111 if (attribute == QLatin1String(validationModesAttributeC)) {
2112 const TextPropertyValidationMode validationMode = static_cast<TextPropertyValidationMode>(value.toInt());
2113 applyToEditors(m_stringPropertyToEditors.value(property), &TextEditor::setTextPropertyValidationMode, validationMode);
2114 }
2115 if (attribute == QLatin1String(fontAttributeC)) {
2116 const QFont font = qvariant_cast<QFont>(value);
2117 applyToEditors(m_stringPropertyToEditors.value(property), &TextEditor::setRichTextDefaultFont, font);
2118 }
2119 } else if (type == QVariant::Palette && attribute == QLatin1String(superPaletteAttributeC)) {
2120 const QPalette palette = qvariant_cast<QPalette>(value);
2121 applyToEditors(m_palettePropertyToEditors.value(property), &PaletteEditorButton::setSuperPalette, palette);
2122 }
2123}
2124
2125void DesignerEditorFactory::slotPropertyChanged(QtProperty *property)
2126{
2127 QtVariantPropertyManager *manager = propertyManager(property);
2128 const int type = manager->propertyType(property);
2129 if (type == DesignerPropertyManager::designerIconTypeId()) {
2130 QPixmap defaultPixmap;
2131 if (!property->isModified())
2132 defaultPixmap = qvariant_cast<QIcon>(manager->attributeValue(property, QLatin1String(defaultResourceAttributeC))).pixmap(16, 16);
2133 else if (m_fwb)
2134 defaultPixmap = m_fwb->iconCache()->icon(qVariantValue<PropertySheetIconValue>(manager->value(property))).pixmap(16, 16);
2135 QList<PixmapEditor *> editors = m_iconPropertyToEditors.value(property);
2136 QListIterator<PixmapEditor *> it(editors);
2137 while (it.hasNext()) {
2138 PixmapEditor *editor = it.next();
2139 editor->setDefaultPixmap(defaultPixmap);
2140 }
2141 }
2142}
2143
2144void DesignerEditorFactory::slotValueChanged(QtProperty *property, const QVariant &value)
2145{
2146 if (m_changingPropertyValue)
2147 return;
2148
2149 QtVariantPropertyManager *manager = propertyManager(property);
2150 const int type = manager->propertyType(property);
2151 switch (type) {
2152 case QVariant::String:
2153 applyToEditors(m_stringPropertyToEditors.value(property), &TextEditor::setText, value.toString());
2154 break;
2155 case QVariant::Palette:
2156 applyToEditors(m_palettePropertyToEditors.value(property), &PaletteEditorButton::setPalette, qvariant_cast<QPalette>(value));
2157 break;
2158 case QVariant::UInt:
2159 applyToEditors(m_uintPropertyToEditors.value(property), &QLineEdit::setText, QString::number(value.toUInt()));
2160 break;
2161 case QVariant::LongLong:
2162 applyToEditors(m_longLongPropertyToEditors.value(property), &QLineEdit::setText, QString::number(value.toLongLong()));
2163 break;
2164 case QVariant::ULongLong:
2165 applyToEditors(m_uLongLongPropertyToEditors.value(property), &QLineEdit::setText, QString::number(value.toULongLong()));
2166 break;
2167 case QVariant::Url:
2168 applyToEditors(m_urlPropertyToEditors.value(property), &TextEditor::setText, value.toUrl().toString());
2169 break;
2170 case QVariant::ByteArray:
2171 applyToEditors(m_byteArrayPropertyToEditors.value(property), &TextEditor::setText, QString::fromUtf8(value.toByteArray()));
2172 break;
2173 case QVariant::StringList:
2174 applyToEditors(m_stringListPropertyToEditors.value(property), &StringListEditorButton::setStringList, value.toStringList());
2175 break;
2176 default:
2177 if (type == DesignerPropertyManager::designerIconTypeId())
2178 applyToEditors(m_iconPropertyToEditors.value(property), &PixmapEditor::setPath, qVariantValue<PropertySheetIconValue>(value).pixmap(QIcon::Normal, QIcon::Off).path());
2179 else if (type == DesignerPropertyManager::designerPixmapTypeId())
2180 applyToEditors(m_pixmapPropertyToEditors.value(property), &PixmapEditor::setPath, qVariantValue<PropertySheetPixmapValue>(value).path());
2181 else if (type == DesignerPropertyManager::designerStringTypeId())
2182 applyToEditors(m_stringPropertyToEditors.value(property), &TextEditor::setText, qVariantValue<PropertySheetStringValue>(value).value());
2183 else if (type == DesignerPropertyManager::designerKeySequenceTypeId())
2184 applyToEditors(m_keySequencePropertyToEditors.value(property), &QtKeySequenceEdit::setKeySequence, qVariantValue<PropertySheetKeySequenceValue>(value).value());
2185 break;
2186 }
2187}
2188
2189TextEditor *DesignerEditorFactory::createTextEditor(QWidget *parent, TextPropertyValidationMode vm, const QString &value)
2190{
2191 TextEditor *rc = new TextEditor(m_core, parent);
2192 rc->setText(value);
2193 rc->setSpacing(m_spacing);
2194 rc->setTextPropertyValidationMode(vm);
2195 connect(rc, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*)));
2196 return rc;
2197}
2198
2199QWidget *DesignerEditorFactory::createEditor(QtVariantPropertyManager *manager, QtProperty *property,
2200 QWidget *parent)
2201{
2202 QWidget *editor = 0;
2203 const int type = manager->propertyType(property);
2204 switch (type) {
2205 case QVariant::Bool: {
2206 editor = QtVariantEditorFactory::createEditor(manager, property, parent);
2207 QtBoolEdit *boolEdit = qobject_cast<QtBoolEdit *>(editor);
2208 if (boolEdit)
2209 boolEdit->setTextVisible(false);
2210 }
2211 break;
2212 case QVariant::String: {
2213 const TextPropertyValidationMode tvm = static_cast<TextPropertyValidationMode>(manager->attributeValue(property, QLatin1String(validationModesAttributeC)).toInt());
2214 TextEditor *ed = createTextEditor(parent, tvm, manager->value(property).toString());
2215 const QVariant richTextDefaultFont = manager->attributeValue(property, QLatin1String(fontAttributeC));
2216 if (richTextDefaultFont.type() == QVariant::Font)
2217 ed->setRichTextDefaultFont(qvariant_cast<QFont>(richTextDefaultFont));
2218 m_stringPropertyToEditors[property].append(ed);
2219 m_editorToStringProperty[ed] = property;
2220 connect(ed, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*)));
2221 connect(ed, SIGNAL(textChanged(QString)), this, SLOT(slotStringTextChanged(QString)));
2222 editor = ed;
2223 }
2224 break;
2225 case QVariant::Palette: {
2226 PaletteEditorButton *ed = new PaletteEditorButton(m_core, qvariant_cast<QPalette>(manager->value(property)), parent);
2227 ed->setSuperPalette(qvariant_cast<QPalette>(manager->attributeValue(property, QLatin1String(superPaletteAttributeC))));
2228 m_palettePropertyToEditors[property].append(ed);
2229 m_editorToPaletteProperty[ed] = property;
2230 connect(ed, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*)));
2231 connect(ed, SIGNAL(paletteChanged(QPalette)), this, SLOT(slotPaletteChanged(QPalette)));
2232 editor = ed;
2233 }
2234 break;
2235 case QVariant::UInt: {
2236 QLineEdit *ed = new QLineEdit(parent);
2237 ed->setValidator(new QULongLongValidator(0, UINT_MAX, ed));
2238 ed->setText(QString::number(manager->value(property).toUInt()));
2239 m_uintPropertyToEditors[property].append(ed);
2240 m_editorToUintProperty[ed] = property;
2241 connect(ed, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*)));
2242 connect(ed, SIGNAL(textChanged(QString)), this, SLOT(slotUintChanged(QString)));
2243 editor = ed;
2244 }
2245 break;
2246 case QVariant::LongLong: {
2247 QLineEdit *ed = new QLineEdit(parent);
2248 ed->setValidator(new QLongLongValidator(ed));
2249 ed->setText(QString::number(manager->value(property).toLongLong()));
2250 m_longLongPropertyToEditors[property].append(ed);
2251 m_editorToLongLongProperty[ed] = property;
2252 connect(ed, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*)));
2253 connect(ed, SIGNAL(textChanged(QString)), this, SLOT(slotLongLongChanged(QString)));
2254 editor = ed;
2255 }
2256 break;
2257 case QVariant::ULongLong: {
2258 QLineEdit *ed = new QLineEdit(parent);
2259 ed->setValidator(new QULongLongValidator(ed));
2260 ed->setText(QString::number(manager->value(property).toULongLong()));
2261 m_uLongLongPropertyToEditors[property].append(ed);
2262 m_editorToULongLongProperty[ed] = property;
2263 connect(ed, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*)));
2264 connect(ed, SIGNAL(textChanged(QString)), this, SLOT(slotULongLongChanged(QString)));
2265 editor = ed;
2266 }
2267 break;
2268 case QVariant::Url: {
2269 TextEditor *ed = createTextEditor(parent, ValidationURL, manager->value(property).toUrl().toString());
2270 ed->setUpdateMode(TextPropertyEditor::UpdateOnFinished);
2271 m_urlPropertyToEditors[property].append(ed);
2272 m_editorToUrlProperty[ed] = property;
2273 connect(ed, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*)));
2274 connect(ed, SIGNAL(textChanged(QString)), this, SLOT(slotUrlChanged(QString)));
2275 editor = ed;
2276 }
2277 break;
2278 case QVariant::ByteArray: {
2279 TextEditor *ed = createTextEditor(parent, ValidationMultiLine, QString::fromUtf8(manager->value(property).toByteArray()));
2280 m_byteArrayPropertyToEditors[property].append(ed);
2281 m_editorToByteArrayProperty[ed] = property;
2282 connect(ed, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*)));
2283 connect(ed, SIGNAL(textChanged(QString)), this, SLOT(slotByteArrayChanged(QString)));
2284 editor = ed;
2285 }
2286 break;
2287 case QVariant::StringList: {
2288 StringListEditorButton *ed = new StringListEditorButton(manager->value(property).toStringList(), parent);
2289 m_stringListPropertyToEditors[property].append(ed);
2290 m_editorToStringListProperty[ed] = property;
2291 connect(ed, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*)));
2292 connect(ed, SIGNAL(stringListChanged(QStringList)), this, SLOT(slotStringListChanged(QStringList)));
2293 editor = ed;
2294 }
2295 break;
2296 default:
2297 if (type == DesignerPropertyManager::designerPixmapTypeId()) {
2298 PixmapEditor *ed = new PixmapEditor(m_core, parent);
2299 ed->setPixmapCache(m_fwb->pixmapCache());
2300 ed->setPath(qvariant_cast<PropertySheetPixmapValue>(manager->value(property)).path());
2301 ed->setDefaultPixmap(qvariant_cast<QPixmap>(manager->attributeValue(property, QLatin1String(defaultResourceAttributeC))));
2302 ed->setSpacing(m_spacing);
2303 m_pixmapPropertyToEditors[property].append(ed);
2304 m_editorToPixmapProperty[ed] = property;
2305 connect(ed, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*)));
2306 connect(ed, SIGNAL(pathChanged(QString)), this, SLOT(slotPixmapChanged(QString)));
2307 editor = ed;
2308 } else if (type == DesignerPropertyManager::designerIconTypeId()) {
2309 PixmapEditor *ed = new PixmapEditor(m_core, parent);
2310 ed->setPixmapCache(m_fwb->pixmapCache());
2311 PropertySheetIconValue value = qvariant_cast<PropertySheetIconValue>(manager->value(property));
2312 ed->setPath(value.pixmap(QIcon::Normal, QIcon::Off).path());
2313 QPixmap defaultPixmap;
2314 if (!property->isModified())
2315 defaultPixmap = qvariant_cast<QIcon>(manager->attributeValue(property, QLatin1String(defaultResourceAttributeC))).pixmap(16, 16);
2316 else if (m_fwb)
2317 defaultPixmap = m_fwb->iconCache()->icon(value).pixmap(16, 16);
2318 ed->setDefaultPixmap(defaultPixmap);
2319 ed->setSpacing(m_spacing);
2320 m_iconPropertyToEditors[property].append(ed);
2321 m_editorToIconProperty[ed] = property;
2322 connect(ed, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*)));
2323 connect(ed, SIGNAL(pathChanged(QString)), this, SLOT(slotIconChanged(QString)));
2324 editor = ed;
2325 } else if (type == DesignerPropertyManager::designerStringTypeId()) {
2326 const TextPropertyValidationMode tvm = static_cast<TextPropertyValidationMode>(manager->attributeValue(property, QLatin1String(validationModesAttributeC)).toInt());
2327 TextEditor *ed = createTextEditor(parent, tvm, qVariantValue<PropertySheetStringValue>(manager->value(property)).value());
2328 const QVariant richTextDefaultFont = manager->attributeValue(property, QLatin1String(fontAttributeC));
2329 if (richTextDefaultFont.type() == QVariant::Font)
2330 ed->setRichTextDefaultFont(qvariant_cast<QFont>(richTextDefaultFont));
2331 m_stringPropertyToEditors[property].append(ed);
2332 m_editorToStringProperty[ed] = property;
2333 connect(ed, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*)));
2334 connect(ed, SIGNAL(textChanged(QString)), this, SLOT(slotStringTextChanged(QString)));
2335 editor = ed;
2336 } else if (type == DesignerPropertyManager::designerKeySequenceTypeId()) {
2337 QtKeySequenceEdit *ed = new QtKeySequenceEdit(parent);
2338 ed->setKeySequence(qVariantValue<PropertySheetKeySequenceValue>(manager->value(property)).value());
2339 m_keySequencePropertyToEditors[property].append(ed);
2340 m_editorToKeySequenceProperty[ed] = property;
2341 connect(ed, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*)));
2342 connect(ed, SIGNAL(keySequenceChanged(QKeySequence)), this, SLOT(slotKeySequenceChanged(QKeySequence)));
2343 editor = ed;
2344 } else {
2345 editor = QtVariantEditorFactory::createEditor(manager, property, parent);
2346 }
2347 break;
2348 }
2349 return m_resetDecorator->editor(editor,
2350 manager->variantProperty(property)->attributeValue(QLatin1String(resettableAttributeC)).toBool(),
2351 manager, property, parent);
2352}
2353
2354template <class Editor>
2355bool removeEditor(QObject *object,
2356 QMap<QtProperty *, QList<Editor> > *propertyToEditors,
2357 QMap<Editor, QtProperty *> *editorToProperty)
2358{
2359 if (!propertyToEditors)
2360 return false;
2361 if (!editorToProperty)
2362 return false;
2363 QMapIterator<Editor, QtProperty *> it(*editorToProperty);
2364 while (it.hasNext()) {
2365 Editor editor = it.next().key();
2366 if (editor == object) {
2367 QtProperty *prop = it.value();
2368 (*propertyToEditors)[prop].removeAll(editor);
2369 if ((*propertyToEditors)[prop].count() == 0)
2370 propertyToEditors->remove(prop);
2371 editorToProperty->remove(editor);
2372 return true;
2373 }
2374 }
2375 return false;
2376}
2377
2378void DesignerEditorFactory::slotEditorDestroyed(QObject *object)
2379{
2380 if (removeEditor(object, &m_stringPropertyToEditors, &m_editorToStringProperty))
2381 return;
2382 if (removeEditor(object, &m_keySequencePropertyToEditors, &m_editorToKeySequenceProperty))
2383 return;
2384 if (removeEditor(object, &m_palettePropertyToEditors, &m_editorToPaletteProperty))
2385 return;
2386 if (removeEditor(object, &m_pixmapPropertyToEditors, &m_editorToPixmapProperty))
2387 return;
2388 if (removeEditor(object, &m_iconPropertyToEditors, &m_editorToIconProperty))
2389 return;
2390 if (removeEditor(object, &m_uintPropertyToEditors, &m_editorToUintProperty))
2391 return;
2392 if (removeEditor(object, &m_longLongPropertyToEditors, &m_editorToLongLongProperty))
2393 return;
2394 if (removeEditor(object, &m_uLongLongPropertyToEditors, &m_editorToULongLongProperty))
2395 return;
2396 if (removeEditor(object, &m_urlPropertyToEditors, &m_editorToUrlProperty))
2397 return;
2398 if (removeEditor(object, &m_byteArrayPropertyToEditors, &m_editorToByteArrayProperty))
2399 return;
2400 if (removeEditor(object, &m_stringListPropertyToEditors, &m_editorToStringListProperty))
2401 return;
2402}
2403
2404template<class Editor>
2405bool updateManager(QtVariantEditorFactory *factory, bool *changingPropertyValue,
2406 const QMap<Editor, QtProperty *> &editorToProperty, QWidget *editor, const QVariant &value)
2407{
2408 if (!editor)
2409 return false;
2410 QMapIterator<Editor, QtProperty *> it(editorToProperty);
2411 while (it.hasNext()) {
2412 if (it.next().key() == editor) {
2413 QtProperty *prop = it.value();
2414 QtVariantPropertyManager *manager = factory->propertyManager(prop);
2415 *changingPropertyValue = true;
2416 manager->variantProperty(prop)->setValue(value);
2417 *changingPropertyValue = false;
2418 return true;
2419 }
2420 }
2421 return false;
2422}
2423
2424void DesignerEditorFactory::slotUintChanged(const QString &value)
2425{
2426 updateManager(this, &m_changingPropertyValue, m_editorToUintProperty, qobject_cast<QWidget *>(sender()), value.toUInt());
2427}
2428
2429void DesignerEditorFactory::slotLongLongChanged(const QString &value)
2430{
2431 updateManager(this, &m_changingPropertyValue, m_editorToLongLongProperty, qobject_cast<QWidget *>(sender()), value.toLongLong());
2432}
2433
2434void DesignerEditorFactory::slotULongLongChanged(const QString &value)
2435{
2436 updateManager(this, &m_changingPropertyValue, m_editorToULongLongProperty, qobject_cast<QWidget *>(sender()), value.toULongLong());
2437}
2438
2439void DesignerEditorFactory::slotUrlChanged(const QString &value)
2440{
2441 updateManager(this, &m_changingPropertyValue, m_editorToUrlProperty, qobject_cast<QWidget *>(sender()), QUrl(value));
2442}
2443
2444void DesignerEditorFactory::slotByteArrayChanged(const QString &value)
2445{
2446 updateManager(this, &m_changingPropertyValue, m_editorToByteArrayProperty, qobject_cast<QWidget *>(sender()), value.toUtf8());
2447}
2448
2449void DesignerEditorFactory::slotStringTextChanged(const QString &value)
2450{
2451 QMapIterator<TextEditor *, QtProperty *> it(m_editorToStringProperty);
2452 while (it.hasNext()) {
2453 if (it.next().key() == sender()) {
2454 QtProperty *prop = it.value();
2455 QtVariantPropertyManager *manager = propertyManager(prop);
2456 QtVariantProperty *varProp = manager->variantProperty(prop);
2457 QVariant val = varProp->value();
2458 if (val.userType() == DesignerPropertyManager::designerStringTypeId()) {
2459 PropertySheetStringValue strVal = qVariantValue<PropertySheetStringValue>(val);
2460 strVal.setValue(value);
2461 // Disable translation if no translation subproperties exist.
2462 if (varProp->subProperties().empty())
2463 strVal.setTranslatable(false);
2464 val = qVariantFromValue(strVal);
2465 } else {
2466 val = QVariant(value);
2467 }
2468 m_changingPropertyValue = true;
2469 manager->variantProperty(prop)->setValue(val);
2470 m_changingPropertyValue = false;
2471 }
2472 }
2473}
2474
2475void DesignerEditorFactory::slotKeySequenceChanged(const QKeySequence &value)
2476{
2477 QMapIterator<QtKeySequenceEdit *, QtProperty *> it(m_editorToKeySequenceProperty);
2478 while (it.hasNext()) {
2479 if (it.next().key() == sender()) {
2480 QtProperty *prop = it.value();
2481 QtVariantPropertyManager *manager = propertyManager(prop);
2482 QtVariantProperty *varProp = manager->variantProperty(prop);
2483 QVariant val = varProp->value();
2484 if (val.userType() == DesignerPropertyManager::designerKeySequenceTypeId()) {
2485 PropertySheetKeySequenceValue keyVal = qVariantValue<PropertySheetKeySequenceValue>(val);
2486 keyVal.setValue(value);
2487 val = qVariantFromValue(keyVal);
2488 } else {
2489 val = qVariantFromValue(value);
2490 }
2491 m_changingPropertyValue = true;
2492 manager->variantProperty(prop)->setValue(val);
2493 m_changingPropertyValue = false;
2494 }
2495 }
2496}
2497
2498void DesignerEditorFactory::slotPaletteChanged(const QPalette &value)
2499{
2500 updateManager(this, &m_changingPropertyValue, m_editorToPaletteProperty, qobject_cast<QWidget *>(sender()), qVariantFromValue(value));
2501}
2502
2503void DesignerEditorFactory::slotPixmapChanged(const QString &value)
2504{
2505 updateManager(this, &m_changingPropertyValue, m_editorToPixmapProperty, qobject_cast<QWidget *>(sender()),
2506 qVariantFromValue(PropertySheetPixmapValue(value)));
2507}
2508
2509void DesignerEditorFactory::slotIconChanged(const QString &value)
2510{
2511 updateManager(this, &m_changingPropertyValue, m_editorToIconProperty, qobject_cast<QWidget *>(sender()),
2512 qVariantFromValue(PropertySheetIconValue(PropertySheetPixmapValue(value))));
2513}
2514
2515void DesignerEditorFactory::slotStringListChanged(const QStringList &value)
2516{
2517 updateManager(this, &m_changingPropertyValue, m_editorToStringListProperty, qobject_cast<QWidget *>(sender()), qVariantFromValue(value));
2518}
2519
2520ResetDecorator::~ResetDecorator()
2521{
2522 QList<ResetWidget *> editors = m_resetWidgetToProperty.keys();
2523 QListIterator<ResetWidget *> it(editors);
2524 while (it.hasNext())
2525 delete it.next();
2526}
2527
2528void ResetDecorator::connectPropertyManager(QtAbstractPropertyManager *manager)
2529{
2530 connect(manager, SIGNAL(propertyChanged(QtProperty*)),
2531 this, SLOT(slotPropertyChanged(QtProperty*)));
2532}
2533
2534void ResetDecorator::disconnectPropertyManager(QtAbstractPropertyManager *manager)
2535{
2536 disconnect(manager, SIGNAL(propertyChanged(QtProperty*)),
2537 this, SLOT(slotPropertyChanged(QtProperty*)));
2538}
2539
2540void ResetDecorator::setSpacing(int spacing)
2541{
2542 m_spacing = spacing;
2543}
2544
2545QWidget *ResetDecorator::editor(QWidget *subEditor, bool resettable, QtAbstractPropertyManager *manager, QtProperty *property,
2546 QWidget *parent)
2547{
2548 Q_UNUSED(manager)
2549
2550 ResetWidget *resetWidget = 0;
2551 if (resettable) {
2552 resetWidget = new ResetWidget(property, parent);
2553 resetWidget->setSpacing(m_spacing);
2554 resetWidget->setResetEnabled(property->isModified());
2555 resetWidget->setValueText(property->valueText());
2556 resetWidget->setValueIcon(property->valueIcon());
2557 resetWidget->setAutoFillBackground(true);
2558 connect(resetWidget, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*)));
2559 connect(resetWidget, SIGNAL(resetProperty(QtProperty*)), this, SIGNAL(resetProperty(QtProperty*)));
2560 m_createdResetWidgets[property].append(resetWidget);
2561 m_resetWidgetToProperty[resetWidget] = property;
2562 }
2563 if (subEditor) {
2564 if (resetWidget) {
2565 subEditor->setParent(resetWidget);
2566 resetWidget->setWidget(subEditor);
2567 }
2568 }
2569 if (resetWidget)
2570 return resetWidget;
2571 return subEditor;
2572}
2573
2574void ResetDecorator::slotPropertyChanged(QtProperty *property)
2575{
2576 QMap<QtProperty *, QList<ResetWidget *> >::ConstIterator prIt = m_createdResetWidgets.constFind(property);
2577 if (prIt == m_createdResetWidgets.constEnd())
2578 return;
2579
2580 const QList<ResetWidget *> editors = prIt.value();
2581 const QList<ResetWidget *>::ConstIterator cend = editors.constEnd();
2582 for (QList<ResetWidget *>::ConstIterator itEditor = editors.constBegin(); itEditor != cend; ++itEditor) {
2583 ResetWidget *widget = *itEditor;
2584 widget->setResetEnabled(property->isModified());
2585 widget->setValueText(property->valueText());
2586 widget->setValueIcon(property->valueIcon());
2587 }
2588}
2589
2590void ResetDecorator::slotEditorDestroyed(QObject *object)
2591{
2592 const QMap<ResetWidget *, QtProperty *>::ConstIterator rcend = m_resetWidgetToProperty.constEnd();
2593 for (QMap<ResetWidget *, QtProperty *>::ConstIterator itEditor = m_resetWidgetToProperty.constBegin(); itEditor != rcend; ++itEditor) {
2594 if (itEditor.key() == object) {
2595 ResetWidget *editor = itEditor.key();
2596 QtProperty *property = itEditor.value();
2597 m_resetWidgetToProperty.remove(editor);
2598 m_createdResetWidgets[property].removeAll(editor);
2599 if (m_createdResetWidgets[property].isEmpty())
2600 m_createdResetWidgets.remove(property);
2601 return;
2602 }
2603 }
2604}
2605
2606}
2607
2608QT_END_NAMESPACE
2609
2610#include "designerpropertymanager.moc"
Note: See TracBrowser for help on using the repository browser.