Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
iconselector.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
// Qt-Security score:significant reason:default
4
5
#
include
"iconselector_p.h"
6
#
include
"qdesigner_utils_p.h"
7
#
include
"qtresourcemodel_p.h"
8
#
include
"qtresourceview_p.h"
9
#
include
"iconloader_p.h"
10
#
include
"formwindowbase_p.h"
11
12
#
include
<
abstractdialoggui_p
.
h
>
13
#
include
<
QtDesigner
/
abstractformeditor
.
h
>
14
#
include
<
QtDesigner
/
abstractresourcebrowser
.
h
>
15
#
include
<
QtDesigner
/
abstractlanguage
.
h
>
16
#
include
<
QtDesigner
/
abstractintegration
.
h
>
17
#
include
<
QtDesigner
/
qextensionmanager
.
h
>
18
#
include
<
QtDesigner
/
private
/
resourcebuilder_p
.
h
>
19
20
#
include
<
QtWidgets
/
qabstractitemview
.
h
>
21
#
include
<
QtWidgets
/
qtoolbutton
.
h
>
22
#
include
<
QtWidgets
/
qcombobox
.
h
>
23
#
include
<
QtWidgets
/
qdialogbuttonbox
.
h
>
24
#
include
<
QtWidgets
/
qpushbutton
.
h
>
25
#
include
<
QtWidgets
/
qdialog
.
h
>
26
#
include
<
QtWidgets
/
qmenu
.
h
>
27
#
include
<
QtWidgets
/
qapplication
.
h
>
28
#
include
<
QtWidgets
/
qboxlayout
.
h
>
29
#
include
<
QtGui
/
qimagereader
.
h
>
30
#
include
<
QtWidgets
/
qdialogbuttonbox
.
h
>
31
#
include
<
QtWidgets
/
qlineedit
.
h
>
32
#
include
<
QtWidgets
/
qlabel
.
h
>
33
34
#
include
<
QtGui
/
qaction
.
h
>
35
#
include
<
QtGui
/
qvalidator
.
h
>
36
37
#
include
<
QtCore
/
qdebug
.
h
>
38
#
include
<
QtCore
/
qlist
.
h
>
39
40
#
include
<
utility
>
41
42
QT_BEGIN_NAMESPACE
43
44
using
namespace
Qt::StringLiterals;
45
46
namespace
qdesigner_internal
{
47
48
using
ThemeIconEnumEntry
=
std
::
pair
<
QString
,
QIcon
>;
49
50
static
const
QList
<
ThemeIconEnumEntry
> &
themeEnumIcons
()
51
{
52
static
QList<ThemeIconEnumEntry> result;
53
if
(result.isEmpty()) {
54
const
QStringList &names = QResourceBuilder::themeIconNames();
55
result.reserve(names.size());
56
for
(qsizetype i = 0, size = names.size(); i < size; ++i)
57
result.append({names.at(i), QIcon::fromTheme(QIcon::ThemeIcon(i))});
58
}
59
return
result;
60
}
61
62
static
void
initThemeCombo
(QComboBox *cb)
63
{
64
cb->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
65
66
for
(
const
auto
&te : themeEnumIcons())
67
cb->addItem(te.second, te.first);
68
69
cb->setCurrentIndex(-1);
70
}
71
72
// Validator for theme line edit, accepts empty or non-blank strings.
73
class
BlankSuppressingValidator
:
public
QValidator
{
74
public
:
75
explicit
BlankSuppressingValidator
(QObject * parent =
nullptr
) :
QValidator
(
parent
) {}
76
State
validate
(QString &input,
int
&pos)
const
override
77
{
78
const
auto
blankPos = input.indexOf(u' ');
79
if
(blankPos != -1) {
80
pos = blankPos;
81
return
Invalid;
82
}
83
return
Acceptable;
84
}
85
};
86
87
// -------------------- LanguageResourceDialogPrivate
88
class
LanguageResourceDialogPrivate
{
89
LanguageResourceDialog *q_ptr;
90
Q_DECLARE_PUBLIC(LanguageResourceDialog)
91
92
public
:
93
LanguageResourceDialogPrivate
(
QDesignerResourceBrowserInterface
*
rb
);
94
void
init
(LanguageResourceDialog *p);
95
96
void
setCurrentPath
(
const
QString &filePath);
97
QString
currentPath
()
const
;
98
99
void
slotAccepted
();
100
void
slotPathChanged
(
const
QString &);
101
102
private
:
103
void
setOkButtonEnabled(
bool
v) { m_dialogButtonBox->button(QDialogButtonBox::Ok)->setEnabled(v); }
104
static
bool
checkPath(
const
QString &p);
105
106
QDesignerResourceBrowserInterface *m_browser;
107
QDialogButtonBox *m_dialogButtonBox;
108
};
109
110
LanguageResourceDialogPrivate
::LanguageResourceDialogPrivate(QDesignerResourceBrowserInterface *rb) :
111
q_ptr(
nullptr
),
112
m_browser(rb),
113
m_dialogButtonBox(
new
QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel))
114
{
115
setOkButtonEnabled(
false
);
116
}
117
118
void
LanguageResourceDialogPrivate
::init(
LanguageResourceDialog
*
p
)
119
{
120
q_ptr
=
p
;
121
QLayout
*
layout
=
new
QVBoxLayout
(
p
);
122
layout
->
addWidget
(
m_browser
);
123
layout
->
addWidget
(
m_dialogButtonBox
);
124
QObject
::
connect
(
m_dialogButtonBox
, &
QDialogButtonBox
::
accepted
,
p
, [
this
] {
slotAccepted
(); });
125
QObject
::
connect
(
m_dialogButtonBox
, &
QDialogButtonBox
::
rejected
,
p
, &
QDialog
::
reject
);
126
QObject
::
connect
(
m_browser
, &
QDesignerResourceBrowserInterface
::
currentPathChanged
,
127
p
, [
this
](
const
QString
&
fileName
) {
slotPathChanged
(
fileName
); });
128
QObject
::
connect
(
m_browser
, &
QDesignerResourceBrowserInterface
::
pathActivated
,
129
p
, [
this
] {
slotAccepted
(); });
130
p
->
setModal
(
true
);
131
p
->
setWindowTitle
(
LanguageResourceDialog
::
tr
(
"Choose Resource"
));
132
setOkButtonEnabled
(
false
);
133
}
134
135
void
LanguageResourceDialogPrivate
::
setCurrentPath
(
const
QString &filePath)
136
{
137
m_browser->setCurrentPath(filePath);
138
setOkButtonEnabled(checkPath(filePath));
139
}
140
141
QString
LanguageResourceDialogPrivate
::
currentPath
()
const
142
{
143
return
m_browser->currentPath();
144
}
145
146
bool
LanguageResourceDialogPrivate
::checkPath(
const
QString &p)
147
{
148
return
p.isEmpty() ?
false
: IconSelector::checkPixmap(p, IconSelector::CheckFast);
149
}
150
151
void
LanguageResourceDialogPrivate
::
slotAccepted
()
152
{
153
if
(checkPath(currentPath()))
154
q_ptr->accept();
155
}
156
157
void
LanguageResourceDialogPrivate
::
slotPathChanged
(
const
QString &p)
158
{
159
setOkButtonEnabled(checkPath(p));
160
}
161
162
// ------------ LanguageResourceDialog
163
LanguageResourceDialog
::
LanguageResourceDialog
(
QDesignerResourceBrowserInterface
*
rb
,
QWidget
*
parent
) :
164
QDialog
(
parent
),
165
d_ptr
(
new
LanguageResourceDialogPrivate
(
rb
))
166
{
167
d_ptr
->
init
(
this
);
168
}
169
170
LanguageResourceDialog
::~
LanguageResourceDialog
() =
default
;
171
172
void
LanguageResourceDialog
::
setCurrentPath
(
const
QString
&
filePath
)
173
{
174
d_ptr
->
setCurrentPath
(
filePath
);
175
}
176
177
QString
LanguageResourceDialog
::
currentPath
()
const
178
{
179
return
d_ptr
->
currentPath
();
180
}
181
182
LanguageResourceDialog
*
LanguageResourceDialog
::
create
(
QDesignerFormEditorInterface
*
core
,
QWidget
*
parent
)
183
{
184
if
(
QDesignerLanguageExtension
*
lang
=
qt_extension
<
QDesignerLanguageExtension
*>(
core
->
extensionManager
(),
core
))
185
if
(
QDesignerResourceBrowserInterface
*
rb
=
lang
->
createResourceBrowser
(
nullptr
))
186
return
new
LanguageResourceDialog
(
rb
,
parent
);
187
if
(
QDesignerResourceBrowserInterface
*
rb
=
core
->
integration
()->
createResourceBrowser
(
nullptr
))
188
return
new
LanguageResourceDialog
(
rb
,
parent
);
189
return
nullptr
;
190
}
191
192
// ------------ IconSelectorPrivate
193
194
struct
QIconStateName
195
{
196
std
::
pair
<
QIcon
::
Mode
,
QIcon
::
State
>
state
;
197
const
char
*
name
;
198
};
199
200
constexpr
QIconStateName
stateToName
[] = {
201
{{
QIcon
::
Normal
,
QIcon
::
Off
},
QT_TRANSLATE_NOOP
(
"IconSelector"
,
"Normal Off"
)},
202
{{
QIcon
::
Normal
,
QIcon
::
On
},
QT_TRANSLATE_NOOP
(
"IconSelector"
,
"Normal On"
)},
203
{{
QIcon
::
Disabled
,
QIcon
::
Off
},
QT_TRANSLATE_NOOP
(
"IconSelector"
,
"Disabled Off"
)},
204
{{
QIcon
::
Disabled
,
QIcon
::
On
},
QT_TRANSLATE_NOOP
(
"IconSelector"
,
"Disabled On"
)},
205
{{
QIcon
::
Active
,
QIcon
::
Off
},
QT_TRANSLATE_NOOP
(
"IconSelector"
,
"Active Off"
)},
206
{{
QIcon
::
Active
,
QIcon
::
On
},
QT_TRANSLATE_NOOP
(
"IconSelector"
,
"Active On"
)},
207
{{
QIcon
::
Selected
,
QIcon
::
Off
},
QT_TRANSLATE_NOOP
(
"IconSelector"
,
"Selected Off"
)},
208
{{
QIcon
::
Selected
,
QIcon
::
On
},
QT_TRANSLATE_NOOP
(
"IconSelector"
,
"Selected On"
)}
209
};
210
211
constexpr
int
stateToNameSize
=
int
(
sizeof
(
stateToName
) /
sizeof
(
stateToName
[0]));
212
213
class
IconSelectorPrivate
214
{
215
IconSelector *q_ptr =
nullptr
;
216
Q_DECLARE_PUBLIC(IconSelector)
217
public
:
218
IconSelectorPrivate
() =
default
;
219
220
void
slotStateActivated
();
221
void
slotSetActivated
();
222
void
slotSetResourceActivated
();
223
void
slotSetFileActivated
();
224
void
slotResetActivated
();
225
void
slotResetAllActivated
();
226
void
slotUpdate
();
227
228
std
::
pair
<
QIcon
::
Mode
,
QIcon
::
State
>
currentState
()
const
229
{
230
const
int
i =
m_stateComboBox
->currentIndex();
231
return
i >= 0 && i <
stateToNameSize
232
? stateToName[i].state : std::pair<QIcon::Mode, QIcon::State>{};
233
}
234
235
const
QIcon
m_emptyIcon
;
236
QComboBox *
m_stateComboBox
=
nullptr
;
237
QToolButton
*
m_iconButton
=
nullptr
;
238
QAction
*
m_resetAction
=
nullptr
;
239
QAction
*
m_resetAllAction
=
nullptr
;
240
PropertySheetIconValue
m_icon
;
241
DesignerIconCache *
m_iconCache
=
nullptr
;
242
QtResourceModel *
m_resourceModel
=
nullptr
;
243
QDesignerFormEditorInterface *
m_core
=
nullptr
;
244
};
245
246
void
IconSelectorPrivate
::
slotUpdate
()
247
{
248
QIcon icon;
249
if
(
m_iconCache
)
250
icon =
m_iconCache
->icon(m_icon);
251
252
const
auto
&paths = m_icon.paths();
253
for
(
int
index = 0; index <
stateToNameSize
; ++index) {
254
const
auto
&state =
stateToName
[index].state;
255
const
PropertySheetPixmapValue pixmap = paths.value(state);
256
QIcon pixmapIcon = QIcon(icon.pixmap(16, 16, state.first, state.second));
257
if
(pixmapIcon.isNull())
258
pixmapIcon = m_emptyIcon;
259
m_stateComboBox
->setItemIcon(index, pixmapIcon);
260
QFont font = q_ptr->font();
261
if
(!pixmap.path().isEmpty())
262
font.setBold(
true
);
263
m_stateComboBox
->setItemData(index, font, Qt::FontRole);
264
}
265
266
PropertySheetPixmapValue
currentPixmap = paths.value(currentState());
267
m_resetAction->setEnabled(!currentPixmap.path().isEmpty());
268
m_resetAllAction->setEnabled(!paths.isEmpty());
269
m_stateComboBox
->update();
270
}
271
272
void
IconSelectorPrivate
::
slotStateActivated
()
273
{
274
slotUpdate
(
)
;
275
}
276
277
void
IconSelectorPrivate
::
slotSetActivated
()
278
{
279
const
auto
state = currentState();
280
const
PropertySheetPixmapValue pixmap = m_icon.pixmap(state.first, state.second);
281
// Default to resource
282
const
PropertySheetPixmapValue::PixmapSource ps = pixmap.path().isEmpty() ? PropertySheetPixmapValue::ResourcePixmap : pixmap.pixmapSource(m_core);
283
switch
(ps) {
284
case
PropertySheetPixmapValue::LanguageResourcePixmap:
285
case
PropertySheetPixmapValue::ResourcePixmap:
286
slotSetResourceActivated
(
)
;
287
break
;
288
case
PropertySheetPixmapValue::FilePixmap:
289
slotSetFileActivated
(
)
;
290
break
;
291
}
292
}
293
294
// Choose a pixmap from resource; use language-dependent resource browser if present
295
QString
IconSelector
::
choosePixmapResource
(
QDesignerFormEditorInterface
*
core
,
QtResourceModel
*
resourceModel
,
const
QString
&
oldPath
,
QWidget
*
parent
)
296
{
297
Q_UNUSED
(
resourceModel
);
298
QString
rc
;
299
300
if
(
LanguageResourceDialog
*
ldlg
=
LanguageResourceDialog
::
create
(
core
,
parent
)) {
301
ldlg
->
setCurrentPath
(
oldPath
);
302
if
(
ldlg
->
exec
() ==
QDialog
::
Accepted
)
303
rc
=
ldlg
->
currentPath
();
304
delete
ldlg
;
305
}
else
{
306
QtResourceViewDialog
dlg
(
core
,
parent
);
307
dlg
.
setResourceEditingEnabled
(
core
->
integration
()->
hasFeature
(
QDesignerIntegration
::
ResourceEditorFeature
));
308
309
dlg
.
selectResource
(
oldPath
);
310
if
(
dlg
.
exec
() ==
QDialog
::
Accepted
)
311
rc
=
dlg
.
selectedResource
();
312
}
313
return
rc
;
314
}
315
316
void
IconSelectorPrivate
::
slotSetResourceActivated
()
317
{
318
const
auto
state = currentState();
319
320
PropertySheetPixmapValue
pixmap = m_icon.pixmap(state.first, state.second);
321
const
QString oldPath = pixmap.path();
322
const
QString newPath = IconSelector::choosePixmapResource(m_core, m_resourceModel, oldPath, q_ptr);
323
if
(newPath.isEmpty() || newPath == oldPath)
324
return
;
325
const
PropertySheetPixmapValue newPixmap = PropertySheetPixmapValue(newPath);
326
if
(newPixmap != pixmap) {
327
m_icon.setPixmap(state.first, state.second, newPixmap);
328
slotUpdate
(
)
;
329
emit q_ptr->iconChanged(m_icon);
330
}
331
}
332
333
// Helpers for choosing image files: Check for valid image.
334
bool
IconSelector
::
checkPixmap
(
const
QString
&
fileName
,
CheckMode
cm
,
QString
*
errorMessage
)
335
{
336
const
QFileInfo
fi
(
fileName
);
337
if
(!
fi
.
exists
() || !
fi
.
isFile
() || !
fi
.
isReadable
()) {
338
if
(
errorMessage
)
339
*
errorMessage
=
tr
(
"The pixmap file '%1' cannot be read."
).
arg
(
fileName
);
340
return
false
;
341
}
342
QImageReader
reader
(
fileName
);
343
if
(!
reader
.
canRead
()) {
344
if
(
errorMessage
)
345
*
errorMessage
=
tr
(
"The file '%1' does not appear to be a valid pixmap file: %2"
)
346
.
arg
(
fileName
,
reader
.
errorString
());
347
return
false
;
348
}
349
if
(
cm
==
CheckFast
)
350
return
true
;
351
352
const
QImage
image
=
reader
.
read
();
353
if
(
image
.
isNull
()) {
354
if
(
errorMessage
)
355
*
errorMessage
=
tr
(
"The file '%1' could not be read: %2"
)
356
.
arg
(
fileName
,
reader
.
errorString
());
357
return
false
;
358
}
359
return
true
;
360
}
361
362
// Helpers for choosing image files: Return an image filter for QFileDialog, courtesy of StyledButton
363
static
QString
imageFilter
()
364
{
365
QString filter = QApplication::translate(
"IconSelector"
,
"All Pixmaps ("
);
366
const
auto
supportedImageFormats = QImageReader::supportedImageFormats();
367
const
qsizetype count = supportedImageFormats.size();
368
for
(qsizetype i = 0; i < count; ++i) {
369
if
(i)
370
filter += u' ';
371
filter +=
"*."_L1
;
372
const
QString outputFormat = QString::fromUtf8(supportedImageFormats.at(i));
373
if
(outputFormat !=
"JPEG"_L1
)
374
filter += outputFormat.toLower();
375
else
376
filter +=
"jpg *.jpeg"_L1
;
377
}
378
filter += u')';
379
return
filter;
380
}
381
382
// Helpers for choosing image files: Choose a file
383
QString
IconSelector
::
choosePixmapFile
(
const
QString
&
directory
,
QDesignerDialogGuiInterface
*
dlgGui
,
QWidget
*
parent
)
384
{
385
QString
errorMessage
;
386
QString
newPath
;
387
do
{
388
const
QString
title
=
tr
(
"Choose a Pixmap"
);
389
static
const
QString
filter
=
imageFilter
();
390
newPath
=
dlgGui
->
getOpenImageFileName
(
parent
,
title
,
directory
,
filter
);
391
if
(
newPath
.
isEmpty
())
392
break
;
393
if
(
checkPixmap
(
newPath
,
CheckFully
, &
errorMessage
))
394
break
;
395
dlgGui
->
message
(
parent
,
QDesignerDialogGuiInterface
::
ResourceEditorMessage
,
QMessageBox
::
Warning
,
tr
(
"Pixmap Read Error"
),
errorMessage
);
396
}
while
(
true
);
397
return
newPath
;
398
}
399
400
void
IconSelectorPrivate
::
slotSetFileActivated
()
401
{
402
const
auto
state = currentState();
403
404
PropertySheetPixmapValue
pixmap = m_icon.pixmap(state.first, state.second);
405
const
QString newPath = IconSelector::choosePixmapFile(pixmap.path(), m_core->dialogGui(), q_ptr);
406
if
(!newPath.isEmpty()) {
407
const
PropertySheetPixmapValue newPixmap = PropertySheetPixmapValue(newPath);
408
if
(!(newPixmap == pixmap)) {
409
m_icon.setPixmap(state.first, state.second, newPixmap);
410
slotUpdate
(
)
;
411
emit q_ptr->iconChanged(m_icon);
412
}
413
}
414
}
415
416
void
IconSelectorPrivate
::
slotResetActivated
()
417
{
418
const
auto
state = currentState();
419
420
PropertySheetPixmapValue
pixmap = m_icon.pixmap(state.first, state.second);
421
const
PropertySheetPixmapValue newPixmap;
422
if
(!(newPixmap == pixmap)) {
423
m_icon.setPixmap(state.first, state.second, newPixmap);
424
slotUpdate
(
)
;
425
emit q_ptr->iconChanged(m_icon);
426
}
427
}
428
429
void
IconSelectorPrivate
::
slotResetAllActivated
()
430
{
431
const
PropertySheetIconValue newIcon;
432
if
(!(m_icon == newIcon)) {
433
m_icon = newIcon;
434
slotUpdate
(
)
;
435
emit q_ptr->iconChanged(m_icon);
436
}
437
}
438
439
// ------------- IconSelector
440
IconSelector
::
IconSelector
(
QWidget
*
parent
) :
441
QWidget
(
parent
),
d_ptr
(
new
IconSelectorPrivate
())
442
{
443
d_ptr
->
q_ptr
=
this
;
444
445
d_ptr
->
m_stateComboBox
=
new
QComboBox
(
this
);
446
447
QHBoxLayout
*
l
=
new
QHBoxLayout
(
this
);
448
d_ptr
->
m_iconButton
=
new
QToolButton
(
this
);
449
d_ptr
->
m_iconButton
->
setText
(
tr
(
"..."
));
450
d_ptr
->
m_iconButton
->
setPopupMode
(
QToolButton
::
MenuButtonPopup
);
451
l
->
addWidget
(
d_ptr
->
m_stateComboBox
);
452
l
->
addWidget
(
d_ptr
->
m_iconButton
);
453
l
->
setContentsMargins
(
QMargins
());
454
455
QMenu
*
setMenu
=
new
QMenu
(
this
);
456
457
QAction
*
setResourceAction
=
new
QAction
(
tr
(
"Choose Resource..."
),
this
);
458
QAction
*
setFileAction
=
new
QAction
(
tr
(
"Choose File..."
),
this
);
459
d_ptr
->
m_resetAction
=
new
QAction
(
tr
(
"Reset"
),
this
);
460
d_ptr
->
m_resetAllAction
=
new
QAction
(
tr
(
"Reset All"
),
this
);
461
d_ptr
->
m_resetAction
->
setEnabled
(
false
);
462
d_ptr
->
m_resetAllAction
->
setEnabled
(
false
);
463
//d_ptr->m_resetAction->setIcon(createIconSet("resetproperty.png"_L1));
464
465
setMenu
->
addAction
(
setResourceAction
);
466
setMenu
->
addAction
(
setFileAction
);
467
setMenu
->
addSeparator
();
468
setMenu
->
addAction
(
d_ptr
->
m_resetAction
);
469
setMenu
->
addAction
(
d_ptr
->
m_resetAllAction
);
470
471
for
(
const
auto
&
item
:
stateToName
)
472
d_ptr
->
m_stateComboBox
->
addItem
(
tr
(
item
.
name
));
473
474
d_ptr
->
m_iconButton
->
setMenu
(
setMenu
);
475
476
connect
(
d_ptr
->
m_stateComboBox
, &
QComboBox
::
activated
,
477
this
, [
this
] {
d_ptr
->
slotStateActivated
(); });
478
connect
(
d_ptr
->
m_iconButton
, &
QAbstractButton
::
clicked
,
479
this
, [
this
] {
d_ptr
->
slotSetActivated
(); });
480
connect
(
setResourceAction
, &
QAction
::
triggered
,
481
this
, [
this
] {
d_ptr
->
slotSetResourceActivated
(); });
482
connect
(
setFileAction
, &
QAction
::
triggered
,
483
this
, [
this
] {
d_ptr
->
slotSetFileActivated
(); });
484
connect
(
d_ptr
->
m_resetAction
, &
QAction
::
triggered
,
485
this
, [
this
] {
d_ptr
->
slotResetActivated
(); });
486
connect
(
d_ptr
->
m_resetAllAction
, &
QAction
::
triggered
,
487
this
, [
this
] {
d_ptr
->
slotResetAllActivated
(); });
488
d_ptr
->
slotUpdate
();
489
}
490
491
IconSelector
::~
IconSelector
() =
default
;
492
493
void
IconSelector
::
setIcon
(
const
PropertySheetIconValue
&
icon
)
494
{
495
if
(
d_ptr
->
m_icon
==
icon
)
496
return
;
497
498
d_ptr
->
m_icon
=
icon
;
499
d_ptr
->
slotUpdate
();
500
}
501
502
PropertySheetIconValue
IconSelector
::
icon
()
const
503
{
504
return
d_ptr
->
m_icon
;
505
}
506
507
void
IconSelector
::
setFormEditor
(
QDesignerFormEditorInterface
*
core
)
508
{
509
d_ptr
->
m_core
=
core
;
510
d_ptr
->
m_resourceModel
=
core
->
resourceModel
();
511
d_ptr
->
slotUpdate
();
512
}
513
514
void
IconSelector
::
setIconCache
(
DesignerIconCache
*
iconCache
)
515
{
516
d_ptr
->
m_iconCache
=
iconCache
;
517
connect
(
iconCache
, &
DesignerIconCache
::
reloaded
,
this
, [
this
] {
d_ptr
->
slotUpdate
(); });
518
d_ptr
->
slotUpdate
();
519
}
520
521
// --- IconThemeEditor
522
523
static
const
QMap
<
QString
,
QIcon
> &
themeIcons
()
524
{
525
static
QMap<QString, QIcon> result;
526
if
(result.isEmpty()) {
527
QFile file(u":/qt-project.org/designer/icon-naming-spec.txt"_s);
528
if
(file.open(QIODevice::ReadOnly)) {
529
while
(!file.atEnd()) {
530
const
auto
line = file.readLine().trimmed();
531
if
(line.isEmpty() || line.startsWith(
'#'
))
532
continue
;
533
const
auto
iconName = QString::fromUtf8(line);
534
result.insert(iconName, QIcon::fromTheme(iconName));
535
}
536
file.close();
537
}
538
}
539
return
result;
540
}
541
542
struct
IconThemeEditorPrivate
{
543
void
create
(
QWidget
*topLevel,
bool
wantResetButton);
544
545
QComboBox *
m_themeComboBox
{};
546
QToolButton
*
m_themeResetButton
{};
547
};
548
549
void
IconThemeEditorPrivate
::
create
(
QWidget
*topLevel,
bool
wantResetButton)
550
{
551
m_themeComboBox
=
new
QComboBox();
552
QHBoxLayout *mainHLayout =
new
QHBoxLayout(topLevel);
553
mainHLayout->setContentsMargins({});
554
mainHLayout->addWidget(
m_themeComboBox
);
555
if
(wantResetButton) {
556
m_themeResetButton =
new
QToolButton;
557
m_themeResetButton->setIcon(createIconSet(
"resetproperty.png"_L1
));
558
mainHLayout->addWidget(m_themeResetButton);
559
}
560
topLevel->setFocusProxy(
m_themeComboBox
);
561
}
562
563
IconThemeEditor
::
IconThemeEditor
(
QWidget
*
parent
,
bool
wantResetButton
) :
564
QWidget
(
parent
),
d
(
new
IconThemeEditorPrivate
)
565
{
566
d
->
create
(
this
,
wantResetButton
);
567
d
->
m_themeComboBox
->
setEditable
(
true
);
568
569
const
auto
icons
=
themeIcons
();
570
for
(
auto
i
=
icons
.
constBegin
();
i
!=
icons
.
constEnd
(); ++
i
)
571
d
->
m_themeComboBox
->
addItem
(
i
.
value
(),
i
.
key
());
572
d
->
m_themeComboBox
->
setCurrentIndex
(-1);
573
d
->
m_themeComboBox
->
lineEdit
()->
setValidator
(
new
BlankSuppressingValidator
(
this
));
574
connect
(
d
->
m_themeComboBox
, &
QComboBox
::
currentTextChanged
,
this
, &
IconThemeEditor
::
edited
);
575
if
(
wantResetButton
)
576
connect
(
d
->
m_themeResetButton
, &
QAbstractButton
::
clicked
,
this
, &
IconThemeEditor
::
reset
);
577
}
578
579
IconThemeEditor
::~
IconThemeEditor
() =
default
;
580
581
void
IconThemeEditor
::
reset
()
582
{
583
d
->
m_themeComboBox
->
setCurrentIndex
(-1);
584
emit
edited
(
QString
());
585
}
586
587
QString
IconThemeEditor
::
theme
()
const
588
{
589
return
d
->
m_themeComboBox
->
currentText
();
590
}
591
592
void
IconThemeEditor
::
setTheme
(
const
QString
&
t
)
593
{
594
d
->
m_themeComboBox
->
setCurrentText
(
t
);
595
}
596
597
IconThemeEnumEditor
::
IconThemeEnumEditor
(
QWidget
*
parent
,
bool
wantResetButton
) :
598
QWidget
(
parent
),
d
(
new
IconThemeEditorPrivate
)
599
{
600
d
->
create
(
this
,
wantResetButton
);
601
initThemeCombo
(
d
->
m_themeComboBox
);
602
603
connect
(
d
->
m_themeComboBox
, &
QComboBox
::
currentIndexChanged
,
604
this
, &
IconThemeEnumEditor
::
edited
);
605
if
(
wantResetButton
)
606
connect
(
d
->
m_themeResetButton
, &
QAbstractButton
::
clicked
,
this
, &
IconThemeEnumEditor
::
reset
);
607
}
608
609
IconThemeEnumEditor
::~
IconThemeEnumEditor
() =
default
;
610
611
void
IconThemeEnumEditor
::
reset
()
612
{
613
d
->
m_themeComboBox
->
setCurrentIndex
(-1);
614
emit
edited
(-1);
615
}
616
617
int
IconThemeEnumEditor
::
themeEnum
()
const
618
{
619
return
d
->
m_themeComboBox
->
currentIndex
();
620
}
621
622
void
IconThemeEnumEditor
::
setThemeEnum
(
int
t
)
623
{
624
Q_ASSERT
(
t
>= -1 &&
t
<
int
(
QIcon
::
ThemeIcon
::
NThemeIcons
));
625
d
->
m_themeComboBox
->
setCurrentIndex
(
t
);
626
}
627
628
QString
IconThemeEnumEditor
::
iconName
(
int
e
)
629
{
630
return
QResourceBuilder
::
themeIconNames
().
value
(
e
);
631
}
632
633
QComboBox
*
IconThemeEnumEditor
::
createComboBox
(
QWidget
*
parent
)
634
{
635
auto
*
result
=
new
QComboBox
(
parent
);
636
initThemeCombo
(
result
);
637
return
result
;
638
}
639
640
}
// qdesigner_internal
641
642
QT_END_NAMESPACE
643
644
#
include
"moc_iconselector_p.cpp"
QPainter::QWidget
friend class QWidget
Definition
qpainter.h:432
qdesigner_internal::BlankSuppressingValidator
Definition
iconselector.cpp:73
qdesigner_internal::BlankSuppressingValidator::validate
State validate(QString &input, int &pos) const override
This virtual function returns \l Invalid if input is invalid according to this validator's rules,...
Definition
iconselector.cpp:76
qdesigner_internal::BlankSuppressingValidator::BlankSuppressingValidator
BlankSuppressingValidator(QObject *parent=nullptr)
Definition
iconselector.cpp:75
qdesigner_internal::IconSelectorPrivate
Definition
iconselector.cpp:214
qdesigner_internal::IconSelectorPrivate::slotSetResourceActivated
void slotSetResourceActivated()
Definition
iconselector.cpp:316
qdesigner_internal::IconSelectorPrivate::m_resourceModel
QtResourceModel * m_resourceModel
Definition
iconselector.cpp:242
qdesigner_internal::IconSelectorPrivate::slotUpdate
void slotUpdate()
Definition
iconselector.cpp:246
qdesigner_internal::IconSelectorPrivate::currentState
std::pair< QIcon::Mode, QIcon::State > currentState() const
Definition
iconselector.cpp:228
qdesigner_internal::IconSelectorPrivate::m_icon
PropertySheetIconValue m_icon
Definition
iconselector.cpp:240
qdesigner_internal::IconSelectorPrivate::m_iconCache
DesignerIconCache * m_iconCache
Definition
iconselector.cpp:241
qdesigner_internal::IconSelectorPrivate::slotSetActivated
void slotSetActivated()
Definition
iconselector.cpp:277
qdesigner_internal::IconSelectorPrivate::slotStateActivated
void slotStateActivated()
Definition
iconselector.cpp:272
qdesigner_internal::IconSelectorPrivate::slotResetAllActivated
void slotResetAllActivated()
Definition
iconselector.cpp:429
qdesigner_internal::IconSelectorPrivate::m_resetAllAction
QAction * m_resetAllAction
Definition
iconselector.cpp:239
qdesigner_internal::IconSelectorPrivate::m_stateComboBox
QComboBox * m_stateComboBox
Definition
iconselector.cpp:236
qdesigner_internal::IconSelectorPrivate::slotResetActivated
void slotResetActivated()
Definition
iconselector.cpp:416
qdesigner_internal::IconSelectorPrivate::slotSetFileActivated
void slotSetFileActivated()
Definition
iconselector.cpp:400
qdesigner_internal::IconSelectorPrivate::m_core
QDesignerFormEditorInterface * m_core
Definition
iconselector.cpp:243
qdesigner_internal::IconSelectorPrivate::m_iconButton
QToolButton * m_iconButton
Definition
iconselector.cpp:237
qdesigner_internal::IconSelectorPrivate::m_resetAction
QAction * m_resetAction
Definition
iconselector.cpp:238
qdesigner_internal::IconSelectorPrivate::m_emptyIcon
const QIcon m_emptyIcon
Definition
iconselector.cpp:235
qdesigner_internal::LanguageResourceDialogPrivate
Definition
iconselector.cpp:88
qdesigner_internal::LanguageResourceDialogPrivate::slotPathChanged
void slotPathChanged(const QString &)
Definition
iconselector.cpp:157
qdesigner_internal::LanguageResourceDialogPrivate::currentPath
QString currentPath() const
Definition
iconselector.cpp:141
qdesigner_internal::LanguageResourceDialogPrivate::init
void init(LanguageResourceDialog *p)
Definition
iconselector.cpp:118
qdesigner_internal::LanguageResourceDialogPrivate::setCurrentPath
void setCurrentPath(const QString &filePath)
Definition
iconselector.cpp:135
qdesigner_internal::LanguageResourceDialogPrivate::slotAccepted
void slotAccepted()
Definition
iconselector.cpp:151
qdesigner_internal::PropertySheetPixmapValue
Definition
qdesigner_utils_p.h:236
qdesigner_internal
Auxiliary methods to store/retrieve settings.
Definition
buddyeditor.cpp:67
qdesigner_internal::themeEnumIcons
static const QList< ThemeIconEnumEntry > & themeEnumIcons()
Definition
iconselector.cpp:50
qdesigner_internal::initThemeCombo
static void initThemeCombo(QComboBox *cb)
Definition
iconselector.cpp:62
qdesigner_internal::stateToName
constexpr QIconStateName stateToName[]
Definition
iconselector.cpp:200
qdesigner_internal::themeIcons
static const QMap< QString, QIcon > & themeIcons()
Definition
iconselector.cpp:523
qdesigner_internal::stateToNameSize
constexpr int stateToNameSize
Definition
iconselector.cpp:211
qdesigner_internal::imageFilter
static QString imageFilter()
Definition
iconselector.cpp:363
qdesigner_internal::IconThemeEditorPrivate
Definition
iconselector.cpp:542
qdesigner_internal::IconThemeEditorPrivate::m_themeResetButton
QToolButton * m_themeResetButton
Definition
iconselector.cpp:546
qdesigner_internal::IconThemeEditorPrivate::create
void create(QWidget *topLevel, bool wantResetButton)
Definition
iconselector.cpp:549
qdesigner_internal::IconThemeEditorPrivate::m_themeComboBox
QComboBox * m_themeComboBox
Definition
iconselector.cpp:545
qdesigner_internal::QIconStateName
Definition
iconselector.cpp:195
qdesigner_internal::QIconStateName::name
const char * name
Definition
iconselector.cpp:197
qdesigner_internal::QIconStateName::state
std::pair< QIcon::Mode, QIcon::State > state
Definition
iconselector.cpp:196
qttools
src
designer
src
lib
shared
iconselector.cpp
Generated on
for Qt by
1.18.0