1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
|
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Designer of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qdesigner_utils_p.h"
#include "qdesigner_propertycommand_p.h"
#include "abstractformbuilder.h"
#include "formwindowbase_p.h"
#include <QtDesigner/QDesignerFormEditorInterface>
#include <QtDesigner/QDesignerFormWindowInterface>
#include <QtDesigner/QDesignerIconCacheInterface>
#include <QtDesigner/QDesignerResourceBrowserInterface>
#include <QtDesigner/QDesignerLanguageExtension>
#include <QtDesigner/QDesignerTaskMenuExtension>
#include <QtDesigner/QExtensionManager>
#include <QtCore/QDir>
#include <QtCore/QProcess>
#include <QtCore/QLibraryInfo>
#include <QtCore/QDebug>
#include <QtCore/QQueue>
#include <QtCore/QSharedData>
#include <QtGui/QApplication>
#include <QtGui/QIcon>
#include <QtGui/QPixmap>
#include <QtGui/QListWidget>
#include <QtGui/QTreeWidget>
#include <QtGui/QTableWidget>
#include <QtGui/QComboBox>
QT_BEGIN_NAMESPACE
namespace qdesigner_internal
{
QDESIGNER_SHARED_EXPORT void designerWarning(const QString &message)
{
qWarning("Designer: %s", qPrintable(message));
}
void reloadTreeItem(DesignerIconCache *iconCache, QTreeWidgetItem *item)
{
if (!item)
return;
for (int c = 0; c < item->columnCount(); c++) {
const QVariant v = item->data(c, Qt::DecorationPropertyRole);
if (v.canConvert<PropertySheetIconValue>())
item->setIcon(c, iconCache->icon(qvariant_cast<PropertySheetIconValue>(v)));
}
}
void reloadListItem(DesignerIconCache *iconCache, QListWidgetItem *item)
{
if (!item)
return;
const QVariant v = item->data(Qt::DecorationPropertyRole);
if (v.canConvert<PropertySheetIconValue>())
item->setIcon(iconCache->icon(qvariant_cast<PropertySheetIconValue>(v)));
}
void reloadTableItem(DesignerIconCache *iconCache, QTableWidgetItem *item)
{
if (!item)
return;
const QVariant v = item->data(Qt::DecorationPropertyRole);
if (v.canConvert<PropertySheetIconValue>())
item->setIcon(iconCache->icon(qvariant_cast<PropertySheetIconValue>(v)));
}
void reloadIconResources(DesignerIconCache *iconCache, QObject *object)
{
if (QListWidget *listWidget = qobject_cast<QListWidget *>(object)) {
for (int i = 0; i < listWidget->count(); i++)
reloadListItem(iconCache, listWidget->item(i));
} else if (QComboBox *comboBox = qobject_cast<QComboBox *>(object)) {
for (int i = 0; i < comboBox->count(); i++) {
const QVariant v = comboBox->itemData(i, Qt::DecorationPropertyRole);
if (v.canConvert<PropertySheetIconValue>()) {
QIcon icon = iconCache->icon(qvariant_cast<PropertySheetIconValue>(v));
comboBox->setItemIcon(i, icon);
comboBox->setItemData(i, icon);
}
}
} else if (QTreeWidget *treeWidget = qobject_cast<QTreeWidget *>(object)) {
reloadTreeItem(iconCache, treeWidget->headerItem());
QQueue<QTreeWidgetItem *> itemsQueue;
for (int i = 0; i < treeWidget->topLevelItemCount(); i++)
itemsQueue.enqueue(treeWidget->topLevelItem(i));
while (!itemsQueue.isEmpty()) {
QTreeWidgetItem *item = itemsQueue.dequeue();
for (int i = 0; i < item->childCount(); i++)
itemsQueue.enqueue(item->child(i));
reloadTreeItem(iconCache, item);
}
} else if (QTableWidget *tableWidget = qobject_cast<QTableWidget *>(object)) {
const int columnCount = tableWidget->columnCount();
const int rowCount = tableWidget->rowCount();
for (int c = 0; c < columnCount; c++)
reloadTableItem(iconCache, tableWidget->horizontalHeaderItem(c));
for (int r = 0; r < rowCount; r++)
reloadTableItem(iconCache, tableWidget->verticalHeaderItem(r));
for (int c = 0; c < columnCount; c++)
for (int r = 0; r < rowCount; r++)
reloadTableItem(iconCache, tableWidget->item(r, c));
}
}
// ------------- DesignerMetaEnum
DesignerMetaEnum::DesignerMetaEnum(const QString &name, const QString &scope, const QString &separator) :
MetaEnum<int>(name, scope, separator)
{
}
QString DesignerMetaEnum::toString(int value, SerializationMode sm, bool *ok) const
{
// find value
bool valueOk;
const QString item = valueToKey(value, &valueOk);
if (ok)
*ok = valueOk;
if (!valueOk || sm == NameOnly)
return item;
QString qualifiedItem;
appendQualifiedName(item, qualifiedItem);
return qualifiedItem;
}
QString DesignerMetaEnum::messageToStringFailed(int value) const
{
return QCoreApplication::translate("DesignerMetaEnum", "%1 is not a valid enumeration value of '%2'.").arg(value).arg(name());
}
QString DesignerMetaEnum::messageParseFailed(const QString &s) const
{
return QCoreApplication::translate("DesignerMetaEnum", "'%1' could not be converted to an enumeration value of type '%2'.").arg(s).arg(name());
}
// -------------- DesignerMetaFlags
DesignerMetaFlags::DesignerMetaFlags(const QString &name, const QString &scope, const QString &separator) :
MetaEnum<uint>(name, scope, separator)
{
}
QStringList DesignerMetaFlags::flags(int ivalue) const
{
typedef MetaEnum<uint>::KeyToValueMap::const_iterator KeyToValueMapIterator;
QStringList rc;
const uint v = static_cast<uint>(ivalue);
const KeyToValueMapIterator cend = keyToValueMap().constEnd();
for (KeyToValueMapIterator it = keyToValueMap().constBegin();it != cend; ++it ) {
const uint itemValue = it.value();
// Check for equality first as flag values can be 0 or -1, too. Takes preference over a bitwise flag
if (v == itemValue) {
rc.clear();
rc.push_back(it.key());
return rc;
}
// Do not add 0-flags (None-flags)
if (itemValue)
if ((v & itemValue) == itemValue)
rc.push_back(it.key());
}
return rc;
}
QString DesignerMetaFlags::toString(int value, SerializationMode sm) const
{
const QStringList flagIds = flags(value);
if (flagIds.empty())
return QString();
const QChar delimiter = QLatin1Char('|');
QString rc;
const QStringList::const_iterator cend = flagIds.constEnd();
for (QStringList::const_iterator it = flagIds.constBegin(); it != cend; ++it) {
if (!rc.isEmpty())
rc += delimiter ;
if (sm == FullyQualified)
appendQualifiedName(*it, rc);
else
rc += *it;
}
return rc;
}
int DesignerMetaFlags::parseFlags(const QString &s, bool *ok) const
{
if (s.isEmpty()) {
if (ok)
*ok = true;
return 0;
}
uint flags = 0;
bool valueOk = true;
QStringList keys = s.split(QString(QLatin1Char('|')));
const QStringList::iterator cend = keys.end();
for (QStringList::iterator it = keys.begin(); it != cend; ++it) {
const uint flagValue = keyToValue(*it, &valueOk);
if (!valueOk) {
flags = 0;
break;
}
flags |= flagValue;
}
if (ok)
*ok = valueOk;
return static_cast<int>(flags);
}
QString DesignerMetaFlags::messageParseFailed(const QString &s) const
{
return QCoreApplication::translate("DesignerMetaFlags", "'%1' could not be converted to a flag value of type '%2'.").arg(s).arg(name());
}
// ---------- PropertySheetEnumValue
PropertySheetEnumValue::PropertySheetEnumValue(int v, const DesignerMetaEnum &me) :
value(v),
metaEnum(me)
{
}
PropertySheetEnumValue::PropertySheetEnumValue() :
value(0)
{
}
// ---------------- PropertySheetFlagValue
PropertySheetFlagValue::PropertySheetFlagValue(int v, const DesignerMetaFlags &mf) :
value(v),
metaFlags(mf)
{
}
PropertySheetFlagValue::PropertySheetFlagValue() :
value(0)
{
}
// ---------------- PropertySheetPixmapValue
PropertySheetPixmapValue::PropertySheetPixmapValue(const QString &path) : m_path(path)
{
}
PropertySheetPixmapValue::PropertySheetPixmapValue()
{
}
PropertySheetPixmapValue::PixmapSource PropertySheetPixmapValue::getPixmapSource(QDesignerFormEditorInterface *core, const QString & path)
{
if (const QDesignerLanguageExtension *lang = qt_extension<QDesignerLanguageExtension *>(core->extensionManager(), core))
return lang->isLanguageResource(path) ? LanguageResourcePixmap : FilePixmap;
return path.startsWith(QLatin1Char(':')) ? ResourcePixmap : FilePixmap;
}
int PropertySheetPixmapValue::compare(const PropertySheetPixmapValue &other) const
{
return m_path.compare(other.m_path);
}
QString PropertySheetPixmapValue::path() const
{
return m_path;
}
void PropertySheetPixmapValue::setPath(const QString &path)
{
if (m_path == path)
return;
m_path = path;
}
// ---------- PropertySheetIconValue
class PropertySheetIconValueData : public QSharedData {
public:
PropertySheetIconValue::ModeStateToPixmapMap m_paths;
QString m_theme;
};
PropertySheetIconValue::PropertySheetIconValue(const PropertySheetPixmapValue &pixmap) :
m_data(new PropertySheetIconValueData)
{
setPixmap(QIcon::Normal, QIcon::Off, pixmap);
}
PropertySheetIconValue::PropertySheetIconValue() :
m_data(new PropertySheetIconValueData)
{
}
PropertySheetIconValue::~PropertySheetIconValue()
{
}
PropertySheetIconValue::PropertySheetIconValue(const PropertySheetIconValue &rhs) :
m_data(rhs.m_data)
{
}
PropertySheetIconValue &PropertySheetIconValue::operator=(const PropertySheetIconValue &rhs)
{
if (this != &rhs)
m_data.operator=(rhs.m_data);
return *this;
}
bool PropertySheetIconValue::equals(const PropertySheetIconValue &rhs) const
{
return m_data->m_theme == rhs.m_data->m_theme && m_data->m_paths == rhs.m_data->m_paths;
}
bool PropertySheetIconValue::operator<(const PropertySheetIconValue &other) const
{
if (const int themeCmp = m_data->m_theme.compare(other.m_data->m_theme))
return themeCmp < 0;
QMapIterator<ModeStateKey, PropertySheetPixmapValue> itThis(m_data->m_paths);
QMapIterator<ModeStateKey, PropertySheetPixmapValue> itOther(other.m_data->m_paths);
while (itThis.hasNext() && itOther.hasNext()) {
const ModeStateKey thisPair = itThis.next().key();
const ModeStateKey otherPair = itOther.next().key();
if (thisPair < otherPair)
return true;
else if (otherPair < thisPair)
return false;
const int crc = itThis.value().compare(itOther.value());
if (crc < 0)
return true;
if (crc > 0)
return false;
}
if (itOther.hasNext())
return true;
return false;
}
bool PropertySheetIconValue::isEmpty() const
{
return m_data->m_theme.isEmpty() && m_data->m_paths.isEmpty();
}
QString PropertySheetIconValue::theme() const
{
return m_data->m_theme;
}
void PropertySheetIconValue::setTheme(const QString &t)
{
m_data->m_theme = t;
}
PropertySheetPixmapValue PropertySheetIconValue::pixmap(QIcon::Mode mode, QIcon::State state) const
{
const ModeStateKey pair = qMakePair(mode, state);
return m_data->m_paths.value(pair);
}
void PropertySheetIconValue::setPixmap(QIcon::Mode mode, QIcon::State state, const PropertySheetPixmapValue &pixmap)
{
const ModeStateKey pair = qMakePair(mode, state);
if (pixmap.path().isEmpty())
m_data->m_paths.remove(pair);
else
m_data->m_paths.insert(pair, pixmap);
}
QPixmap DesignerPixmapCache::pixmap(const PropertySheetPixmapValue &value) const
{
QMap<PropertySheetPixmapValue, QPixmap>::const_iterator it = m_cache.constFind(value);
if (it != m_cache.constEnd())
return it.value();
QPixmap pix = QPixmap(value.path());
m_cache.insert(value, pix);
return pix;
}
void DesignerPixmapCache::clear()
{
m_cache.clear();
}
DesignerPixmapCache::DesignerPixmapCache(QObject *parent)
: QObject(parent)
{
}
QIcon DesignerIconCache::icon(const PropertySheetIconValue &value) const
{
typedef PropertySheetIconValue::ModeStateToPixmapMap::const_iterator ModeStateToPixmapMapConstIt;
QMap<PropertySheetIconValue, QIcon>::const_iterator it = m_cache.constFind(value);
if (it != m_cache.constEnd())
return it.value();
// Match on the theme first if it is available.
if (!value.theme().isEmpty()) {
const QString theme = value.theme();
if (QIcon::hasThemeIcon(theme)) {
const QIcon themeIcon = QIcon::fromTheme(theme);
m_cache.insert(value, themeIcon);
return themeIcon;
}
}
QIcon icon;
const PropertySheetIconValue::ModeStateToPixmapMap &paths = value.paths();
const ModeStateToPixmapMapConstIt cend = paths.constEnd();
for (ModeStateToPixmapMapConstIt it = paths.constBegin(); it != cend; ++it) {
const QPair<QIcon::Mode, QIcon::State> pair = it.key();
icon.addFile(it.value().path(), QSize(), pair.first, pair.second);
}
m_cache.insert(value, icon);
return icon;
}
void DesignerIconCache::clear()
{
m_cache.clear();
}
DesignerIconCache::DesignerIconCache(DesignerPixmapCache *pixmapCache, QObject *parent)
: QObject(parent),
m_pixmapCache(pixmapCache)
{
}
PropertySheetStringValue::PropertySheetStringValue(const QString &value,
bool translatable, const QString &disambiguation, const QString &comment)
: m_value(value), m_translatable(translatable), m_disambiguation(disambiguation), m_comment(comment)
{ }
QString PropertySheetStringValue::value() const
{
return m_value;
}
void PropertySheetStringValue::setValue(const QString &value)
{
m_value = value;
}
bool PropertySheetStringValue::translatable() const
{
return m_translatable;
}
void PropertySheetStringValue::setTranslatable(bool translatable)
{
m_translatable = translatable;
}
QString PropertySheetStringValue::disambiguation() const
{
return m_disambiguation;
}
void PropertySheetStringValue::setDisambiguation(const QString &disambiguation)
{
m_disambiguation = disambiguation;
}
QString PropertySheetStringValue::comment() const
{
return m_comment;
}
void PropertySheetStringValue::setComment(const QString &comment)
{
m_comment = comment;
}
bool PropertySheetStringValue::equals(const PropertySheetStringValue &rhs) const
{
return (m_value == rhs.m_value) && (m_translatable == rhs.m_translatable)
&& (m_disambiguation == rhs.m_disambiguation) && (m_comment == rhs.m_comment);
}
PropertySheetKeySequenceValue::PropertySheetKeySequenceValue(const QKeySequence &value,
bool translatable, const QString &disambiguation, const QString &comment)
: m_value(value),
m_standardKey(QKeySequence::UnknownKey),
m_translatable(translatable),
m_disambiguation(disambiguation),
m_comment(comment)
{ }
PropertySheetKeySequenceValue::PropertySheetKeySequenceValue(const QKeySequence::StandardKey &standardKey,
bool translatable, const QString &disambiguation, const QString &comment)
: m_value(QKeySequence(standardKey)),
m_standardKey(standardKey),
m_translatable(translatable),
m_disambiguation(disambiguation),
m_comment(comment)
{ }
QKeySequence PropertySheetKeySequenceValue::value() const
{
return m_value;
}
void PropertySheetKeySequenceValue::setValue(const QKeySequence &value)
{
m_value = value;
m_standardKey = QKeySequence::UnknownKey;
}
QKeySequence::StandardKey PropertySheetKeySequenceValue::standardKey() const
{
return m_standardKey;
}
void PropertySheetKeySequenceValue::setStandardKey(const QKeySequence::StandardKey &standardKey)
{
m_value = QKeySequence(standardKey);
m_standardKey = standardKey;
}
bool PropertySheetKeySequenceValue::isStandardKey() const
{
return m_standardKey != QKeySequence::UnknownKey;
}
QString PropertySheetKeySequenceValue::comment() const
{
return m_comment;
}
void PropertySheetKeySequenceValue::setComment(const QString &comment)
{
m_comment = comment;
}
QString PropertySheetKeySequenceValue::disambiguation() const
{
return m_disambiguation;
}
void PropertySheetKeySequenceValue::setDisambiguation(const QString &disambiguation)
{
m_disambiguation = disambiguation;
}
bool PropertySheetKeySequenceValue::translatable() const
{
return m_translatable;
}
void PropertySheetKeySequenceValue::setTranslatable(bool translatable)
{
m_translatable = translatable;
}
bool PropertySheetKeySequenceValue::equals(const PropertySheetKeySequenceValue &rhs) const
{
return (m_value == rhs.m_value) && (m_standardKey == rhs.m_standardKey)
&& (m_translatable == rhs.m_translatable) && (m_disambiguation == rhs.m_disambiguation) && (m_comment == rhs.m_comment);
}
/* IconSubPropertyMask: Assign each icon sub-property (pixmaps for the
* various states/modes and the theme) a flag bit (see QFont) so that they
* can be handled individually when assigning property values to
* multiselections in the set-property-commands (that is, do not clobber
* other subproperties when assigning just one).
* Provide back-and-forth mapping functions for the icon states. */
enum IconSubPropertyMask {
NormalOffIconMask = 0x01,
NormalOnIconMask = 0x02,
DisabledOffIconMask = 0x04,
DisabledOnIconMask = 0x08,
ActiveOffIconMask = 0x10,
ActiveOnIconMask = 0x20,
SelectedOffIconMask = 0x40,
SelectedOnIconMask = 0x80,
ThemeIconMask = 0x10000
};
static inline uint iconStateToSubPropertyFlag(QIcon::Mode mode, QIcon::State state)
{
switch (mode) {
case QIcon::Disabled:
return state == QIcon::On ? DisabledOnIconMask : DisabledOffIconMask;
case QIcon::Active:
return state == QIcon::On ? ActiveOnIconMask : ActiveOffIconMask;
case QIcon::Selected:
return state == QIcon::On ? SelectedOnIconMask : SelectedOffIconMask;
case QIcon::Normal:
break;
}
return state == QIcon::On ? NormalOnIconMask : NormalOffIconMask;
}
static inline QPair<QIcon::Mode, QIcon::State> subPropertyFlagToIconModeState(unsigned flag)
{
switch (flag) {
case NormalOnIconMask:
return qMakePair(QIcon::Normal, QIcon::On);
case DisabledOffIconMask:
return qMakePair(QIcon::Disabled, QIcon::Off);
case DisabledOnIconMask:
return qMakePair(QIcon::Disabled, QIcon::On);
case ActiveOffIconMask:
return qMakePair(QIcon::Active, QIcon::Off);
case ActiveOnIconMask:
return qMakePair(QIcon::Active, QIcon::On);
case SelectedOffIconMask:
return qMakePair(QIcon::Selected, QIcon::Off);
case SelectedOnIconMask:
return qMakePair(QIcon::Selected, QIcon::On);
case NormalOffIconMask:
default:
break;
}
return qMakePair(QIcon::Normal, QIcon::Off);
}
uint PropertySheetIconValue::mask() const
{
typedef ModeStateToPixmapMap::const_iterator ModeStateToPixmapMapConstIt;
uint flags = 0;
const ModeStateToPixmapMapConstIt cend = m_data->m_paths.constEnd();
for (ModeStateToPixmapMapConstIt it = m_data->m_paths.constBegin(); it != cend; ++it)
flags |= iconStateToSubPropertyFlag(it.key().first, it.key().second);
if (!m_data->m_theme.isEmpty())
flags |= ThemeIconMask;
return flags;
}
uint PropertySheetIconValue::compare(const PropertySheetIconValue &other) const
{
uint diffMask = mask() | other.mask();
for (int i = 0; i < 8; i++) {
const uint flag = 1 << i;
if (diffMask & flag) { // if state is set in both icons, compare the values
const QPair<QIcon::Mode, QIcon::State> state = subPropertyFlagToIconModeState(flag);
if (pixmap(state.first, state.second) == other.pixmap(state.first, state.second))
diffMask &= ~flag;
}
}
if ((diffMask & ThemeIconMask) && theme() == other.theme())
diffMask &= ~ThemeIconMask;
return diffMask;
}
PropertySheetIconValue PropertySheetIconValue::themed() const
{
PropertySheetIconValue rc(*this);
rc.m_data->m_paths.clear();
return rc;
}
PropertySheetIconValue PropertySheetIconValue::unthemed() const
{
PropertySheetIconValue rc(*this);
rc.m_data->m_theme.clear();
return rc;
}
void PropertySheetIconValue::assign(const PropertySheetIconValue &other, uint mask)
{
for (int i = 0; i < 8; i++) {
uint flag = 1 << i;
if (mask & flag) {
const ModeStateKey state = subPropertyFlagToIconModeState(flag);
setPixmap(state.first, state.second, other.pixmap(state.first, state.second));
}
}
if (mask & ThemeIconMask)
setTheme(other.theme());
}
const PropertySheetIconValue::ModeStateToPixmapMap &PropertySheetIconValue::paths() const
{
return m_data->m_paths;
}
QDESIGNER_SHARED_EXPORT QDebug operator<<(QDebug d, const PropertySheetIconValue &p)
{
typedef PropertySheetIconValue::ModeStateToPixmapMap::const_iterator ModeStateToPixmapMapConstIt;
QDebug nospace = d.nospace();
nospace << "PropertySheetIconValue theme='" << p.theme() << "' ";
const PropertySheetIconValue::ModeStateToPixmapMap &paths = p.paths();
const ModeStateToPixmapMapConstIt cend = paths.constEnd();
for (ModeStateToPixmapMapConstIt it = paths.constBegin(); it != cend; ++it)
nospace << " mode=" << it.key().first << ",state=" << it.key().second
<< ",'" << it.value().path() << '\'';
nospace << " mask=0x" << QString::number(p.mask(), 16);
return d;
}
QDESIGNER_SHARED_EXPORT QDesignerFormWindowCommand *createTextPropertyCommand(const QString &propertyName, const QString &text, QObject *object, QDesignerFormWindowInterface *fw)
{
if (text.isEmpty()) {
ResetPropertyCommand *cmd = new ResetPropertyCommand(fw);
cmd->init(object, propertyName);
return cmd;
}
SetPropertyCommand *cmd = new SetPropertyCommand(fw);
cmd->init(object, propertyName, text);
return cmd;
}
QDESIGNER_SHARED_EXPORT QAction *preferredEditAction(QDesignerFormEditorInterface *core, QWidget *managedWidget)
{
QAction *action = 0;
if (const QDesignerTaskMenuExtension *taskMenu = qt_extension<QDesignerTaskMenuExtension*>(core->extensionManager(), managedWidget)) {
action = taskMenu->preferredEditAction();
if (!action) {
const QList<QAction *> actions = taskMenu->taskActions();
if (!actions.isEmpty())
action = actions.first();
}
}
if (!action) {
if (const QDesignerTaskMenuExtension *taskMenu = qobject_cast<QDesignerTaskMenuExtension *>(
core->extensionManager()->extension(managedWidget, QLatin1String("QDesignerInternalTaskMenuExtension")))) {
action = taskMenu->preferredEditAction();
if (!action) {
const QList<QAction *> actions = taskMenu->taskActions();
if (!actions.isEmpty())
action = actions.first();
}
}
}
return action;
}
QDESIGNER_SHARED_EXPORT bool runUIC(const QString &fileName, UIC_Mode mode, QByteArray& ba, QString &errorMessage)
{
QStringList argv;
QString binary = QLibraryInfo::location(QLibraryInfo::BinariesPath);
binary += QDir::separator();
switch (mode) {
case UIC_GenerateCode:
binary += QLatin1String("uic");
break;
case UIC_ConvertV3:
binary += QLatin1String("uic3");
argv += QLatin1String("-convert");
break;
}
argv += fileName;
QProcess uic;
uic.start(binary, argv);
if (!uic.waitForStarted()) {
errorMessage = QApplication::translate("Designer", "Unable to launch %1.").arg(binary);
return false;
}
if (!uic.waitForFinished()) {
errorMessage = QApplication::translate("Designer", "%1 timed out.").arg(binary);
return false;
}
if (uic.exitCode()) {
errorMessage = QString::fromAscii(uic.readAllStandardError());
return false;
}
ba = uic.readAllStandardOutput();
return true;
}
QDESIGNER_SHARED_EXPORT QString qtify(const QString &name)
{
QString qname = name;
Q_ASSERT(qname.isEmpty() == false);
if (qname.count() > 1 && qname.at(1).isUpper()) {
const QChar first = qname.at(0);
if (first == QLatin1Char('Q') || first == QLatin1Char('K'))
qname.remove(0, 1);
}
const int len = qname.count();
for (int i = 0; i < len && qname.at(i).isUpper(); i++)
qname[i] = qname.at(i).toLower();
return qname;
}
// --------------- UpdateBlocker
UpdateBlocker::UpdateBlocker(QWidget *w) :
m_widget(w),
m_enabled(w->updatesEnabled() && w->isVisible())
{
if (m_enabled)
m_widget->setUpdatesEnabled(false);
}
UpdateBlocker::~UpdateBlocker()
{
if (m_enabled)
m_widget->setUpdatesEnabled(true);
}
} // namespace qdesigner_internal
QT_END_NAMESPACE
|