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>{};
242 QDesignerFormEditorInterface *
m_core =
nullptr;
251 const auto &paths = m_icon.paths();
254 const PropertySheetPixmapValue pixmap = paths.value(state);
255 QIcon pixmapIcon = QIcon(icon.pixmap(16, 16, state.first, state.second));
256 if (pixmapIcon.isNull())
257 pixmapIcon = m_emptyIcon;
259 QFont font = q_ptr->font();
260 if (!pixmap.path().isEmpty())
266 m_resetAction->setEnabled(!currentPixmap.path().isEmpty());
267 m_resetAllAction->setEnabled(!paths.isEmpty());
278 const auto state = currentState();
279 const PropertySheetPixmapValue pixmap = m_icon.pixmap(state.first, state.second);
281 const PropertySheetPixmapValue::PixmapSource ps = pixmap.path().isEmpty() ? PropertySheetPixmapValue::ResourcePixmap : pixmap.pixmapSource(m_core);
283 case PropertySheetPixmapValue::LanguageResourcePixmap:
284 case PropertySheetPixmapValue::ResourcePixmap:
287 case PropertySheetPixmapValue::FilePixmap:
317 const auto state = currentState();
320 const QString oldPath = pixmap.path();
321 const QString newPath = IconSelector::choosePixmapResource(m_core, m_resourceModel, oldPath, q_ptr);
322 if (newPath.isEmpty() || newPath == oldPath)
324 const PropertySheetPixmapValue newPixmap = PropertySheetPixmapValue(newPath);
325 if (newPixmap != pixmap) {
326 m_icon.setPixmap(state.first, state.second, newPixmap);
328 emit q_ptr->iconChanged(m_icon);
344 *
errorMessage =
tr(
"The file '%1' does not appear to be a valid pixmap file: %2")
364 QString filter = QApplication::translate(
"IconSelector",
"All Pixmaps (");
365 const auto supportedImageFormats = QImageReader::supportedImageFormats();
366 const qsizetype count = supportedImageFormats.size();
367 for (qsizetype i = 0; i < count; ++i) {
371 const QString outputFormat = QString::fromUtf8(supportedImageFormats.at(i));
372 if (outputFormat !=
"JPEG"_L1)
373 filter += outputFormat.toLower();
375 filter +=
"jpg *.jpeg"_L1;
401 const auto state = currentState();
404 const QString newPath = IconSelector::choosePixmapFile(pixmap.path(), m_core->dialogGui(), q_ptr);
405 if (!newPath.isEmpty()) {
406 const PropertySheetPixmapValue newPixmap = PropertySheetPixmapValue(newPath);
407 if (!(newPixmap == pixmap)) {
408 m_icon.setPixmap(state.first, state.second, newPixmap);
410 emit q_ptr->iconChanged(m_icon);
417 const auto state = currentState();
420 const PropertySheetPixmapValue newPixmap;
421 if (!(newPixmap == pixmap)) {
422 m_icon.setPixmap(state.first, state.second, newPixmap);
424 emit q_ptr->iconChanged(m_icon);
430 const PropertySheetIconValue newIcon;
431 if (!(m_icon == newIcon)) {
434 emit q_ptr->iconChanged(m_icon);
524 static QMap<QString, QIcon> result;
525 if (result.isEmpty()) {
526 QFile file(u":/qt-project.org/designer/icon-naming-spec.txt"_s);
527 if (file.open(QIODevice::ReadOnly)) {
528 while (!file.atEnd()) {
529 const auto line = file.readLine().trimmed();
530 if (line.isEmpty() || line.startsWith(
'#'))
532 const auto iconName = QString::fromUtf8(line);
533 result.insert(iconName, QIcon::fromTheme(iconName));
550 m_themeComboBox =
new QComboBox();
551 QHBoxLayout *mainHLayout =
new QHBoxLayout(topLevel);
552 mainHLayout->setContentsMargins({});
554 if (wantResetButton) {
555 m_themeResetButton =
new QToolButton;
556 m_themeResetButton->setIcon(createIconSet(
"resetproperty.png"_L1));
557 mainHLayout->addWidget(m_themeResetButton);
643#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
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