11#include <abstractdialoggui_p.h>
12#include <QtDesigner/abstractformeditor.h>
13#include <QtDesigner/abstractresourcebrowser.h>
14#include <QtDesigner/abstractlanguage.h>
15#include <QtDesigner/abstractintegration.h>
16#include <QtDesigner/qextensionmanager.h>
17#include <QtDesigner/private/resourcebuilder_p.h>
19#include <QtWidgets/qabstractitemview.h>
20#include <QtWidgets/qtoolbutton.h>
21#include <QtWidgets/qcombobox.h>
22#include <QtWidgets/qdialogbuttonbox.h>
23#include <QtWidgets/qpushbutton.h>
24#include <QtWidgets/qdialog.h>
25#include <QtWidgets/qmenu.h>
26#include <QtWidgets/qapplication.h>
27#include <QtWidgets/qboxlayout.h>
28#include <QtGui/qimagereader.h>
29#include <QtWidgets/qdialogbuttonbox.h>
30#include <QtWidgets/qlineedit.h>
31#include <QtWidgets/qlabel.h>
33#include <QtGui/qaction.h>
34#include <QtGui/qvalidator.h>
36#include <QtCore/qdebug.h>
37#include <QtCore/qlist.h>
43using namespace Qt::StringLiterals;
51 static QList<ThemeIconEnumEntry> result;
52 if (result.isEmpty()) {
53 const QStringList &names = QResourceBuilder::themeIconNames();
54 result.reserve(names.size());
55 for (qsizetype i = 0, size = names.size(); i < size; ++i)
56 result.append({names.at(i), QIcon::fromTheme(QIcon::ThemeIcon(i))});
63 cb->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
65 for (
const auto &te : themeEnumIcons())
66 cb->addItem(te.second, te.first);
68 cb->setCurrentIndex(-1);
77 const auto blankPos = input.indexOf(u' ');
88 LanguageResourceDialog *q_ptr;
89 Q_DECLARE_PUBLIC(LanguageResourceDialog)
93 void init(LanguageResourceDialog *p);
102 void setOkButtonEnabled(
bool v) { m_dialogButtonBox->button(QDialogButtonBox::Ok)->setEnabled(v); }
103 static bool checkPath(
const QString &p);
105 QDesignerResourceBrowserInterface *m_browser;
106 QDialogButtonBox *m_dialogButtonBox;
112 m_dialogButtonBox(
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel))
114 setOkButtonEnabled(
false);
136 m_browser->setCurrentPath(filePath);
137 setOkButtonEnabled(checkPath(filePath));
142 return m_browser->currentPath();
147 return p.isEmpty() ?
false : IconSelector::checkPixmap(p, IconSelector::CheckFast);
152 if (checkPath(currentPath()))
158 setOkButtonEnabled(checkPath(p));
214 IconSelector *q_ptr =
nullptr;
215 Q_DECLARE_PUBLIC(IconSelector)
230 return i >= 0 && i < stateToNameSize
231 ? stateToName[i].state : std::pair<QIcon::Mode, QIcon::State>{};
243 QDesignerFormEditorInterface *
m_core =
nullptr;
250 icon = m_iconCache->icon(m_icon);
252 const auto &paths = m_icon.paths();
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;
260 QFont font = q_ptr->font();
261 if (!pixmap.path().isEmpty())
263 m_stateComboBox->setItemData(index, font, Qt::FontRole);
267 m_resetAction->setEnabled(!currentPixmap.path().isEmpty());
268 m_resetAllAction->setEnabled(!paths.isEmpty());
279 const auto state = currentState();
280 const PropertySheetPixmapValue pixmap = m_icon.pixmap(state.first, state.second);
282 const PropertySheetPixmapValue::PixmapSource ps = pixmap.path().isEmpty() ? PropertySheetPixmapValue::ResourcePixmap : pixmap.pixmapSource(m_core);
284 case PropertySheetPixmapValue::LanguageResourcePixmap:
285 case PropertySheetPixmapValue::ResourcePixmap:
288 case PropertySheetPixmapValue::FilePixmap:
318 const auto state = currentState();
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)
325 const PropertySheetPixmapValue newPixmap = PropertySheetPixmapValue(newPath);
326 if (newPixmap != pixmap) {
327 m_icon.setPixmap(state.first, state.second, newPixmap);
329 emit q_ptr->iconChanged(m_icon);
345 *
errorMessage =
tr(
"The file '%1' does not appear to be a valid pixmap file: %2")
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) {
372 const QString outputFormat = QString::fromUtf8(supportedImageFormats.at(i));
373 if (outputFormat !=
"JPEG"_L1)
374 filter += outputFormat.toLower();
376 filter +=
"jpg *.jpeg"_L1;
402 const auto state = currentState();
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);
411 emit q_ptr->iconChanged(m_icon);
418 const auto state = currentState();
421 const PropertySheetPixmapValue newPixmap;
422 if (!(newPixmap == pixmap)) {
423 m_icon.setPixmap(state.first, state.second, newPixmap);
425 emit q_ptr->iconChanged(m_icon);
431 const PropertySheetIconValue newIcon;
432 if (!(m_icon == newIcon)) {
435 emit q_ptr->iconChanged(m_icon);
532 static QMap<QString, QIcon> result;
533 if (result.isEmpty()) {
534 QFile file(u":/qt-project.org/designer/icon-naming-spec.txt"_s);
535 if (file.open(QIODevice::ReadOnly)) {
536 while (!file.atEnd()) {
537 const auto line = file.readLine().trimmed();
538 if (line.isEmpty() || line.startsWith(
'#'))
540 const auto iconName = QString::fromUtf8(line);
541 result.insert(iconName, QIcon::fromTheme(iconName));
558 m_themeComboBox =
new QComboBox();
559 QHBoxLayout *mainHLayout =
new QHBoxLayout(topLevel);
560 mainHLayout->setContentsMargins({});
562 if (wantResetButton) {
563 m_themeResetButton =
new QToolButton;
564 m_themeResetButton->setIcon(createIconSet(
"resetproperty.png"_L1));
565 mainHLayout->addWidget(m_themeResetButton);
651#include "moc_iconselector_p.cpp"
State validate(QString &input, int &pos) const override
This virtual function returns \l Invalid if input is invalid according to this validator's rules,...
BlankSuppressingValidator(QObject *parent=nullptr)
void slotSetResourceActivated()
QtResourceModel * m_resourceModel
std::pair< QIcon::Mode, QIcon::State > currentState() const
PropertySheetIconValue m_icon
DesignerIconCache * m_iconCache
void slotStateActivated()
void slotResetAllActivated()
QAction * m_resetAllAction
DesignerPixmapCache * m_pixmapCache
QComboBox * m_stateComboBox
void slotResetActivated()
void slotSetFileActivated()
QDesignerFormEditorInterface * m_core
QToolButton * m_iconButton
void slotPathChanged(const QString &)
QString currentPath() const
void init(LanguageResourceDialog *p)
void setCurrentPath(const QString &filePath)
Auxiliary methods to store/retrieve settings.
static const QList< ThemeIconEnumEntry > & themeEnumIcons()
static void initThemeCombo(QComboBox *cb)
constexpr QIconStateName stateToName[]
static const QMap< QString, QIcon > & themeIcons()
constexpr int stateToNameSize
static QString imageFilter()
QToolButton * m_themeResetButton
void create(QWidget *topLevel, bool wantResetButton)
QComboBox * m_themeComboBox
std::pair< QIcon::Mode, QIcon::State > state