forked from qt-creator/qt-creator
Core: Consolidate setter of icon and text in IWizardFactory
Make setting the icon and the text atomic, and move the text drawing code to iwizardfactory.cpp. That simplifies things such as setting the fallback icon. Also, it enables the upcoming theming of wizard icons. Change-Id: Ieb803eba52a659b3278b29db32838d9b41d73cb6 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -255,9 +255,6 @@ void NewDialogWidget::setWizardFactories(QList<IWizardFactory *> factories,
|
||||
parentItem->appendRow(projectKindItem);
|
||||
parentItem->appendRow(filesKindItem);
|
||||
|
||||
if (m_dummyIcon.isNull())
|
||||
m_dummyIcon = QIcon(":/utils/images/wizardicon-file.png");
|
||||
|
||||
const QSet<Id> availablePlatforms = IWizardFactory::allAvailablePlatforms();
|
||||
|
||||
const bool allowAllTemplates = ICore::settings()->value(ALLOW_ALL_TEMPLATES, true).toBool();
|
||||
@@ -360,28 +357,6 @@ IWizardFactory *NewDialogWidget::currentWizardFactory() const
|
||||
return factoryOfItem(m_model->itemFromIndex(index));
|
||||
}
|
||||
|
||||
static QIcon iconWithText(const QIcon &icon, const QString &text)
|
||||
{
|
||||
if (text.isEmpty())
|
||||
return icon;
|
||||
QIcon iconWithText;
|
||||
for (const QSize &pixmapSize : icon.availableSizes()) {
|
||||
QPixmap pixmap = icon.pixmap(pixmapSize);
|
||||
const int fontSize = pixmap.height() / 4;
|
||||
const int margin = pixmap.height() / 8;
|
||||
QFont font;
|
||||
font.setPixelSize(fontSize);
|
||||
font.setStretch(85);
|
||||
QPainter p(&pixmap);
|
||||
p.setFont(font);
|
||||
QTextOption textOption(Qt::AlignHCenter | Qt::AlignBottom);
|
||||
textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
|
||||
p.drawText(pixmap.rect().adjusted(margin, margin, -margin, -margin), text, textOption);
|
||||
iconWithText.addPixmap(pixmap);
|
||||
}
|
||||
return iconWithText;
|
||||
}
|
||||
|
||||
void NewDialogWidget::addItem(QStandardItem *topLevelCategoryItem, IWizardFactory *factory)
|
||||
{
|
||||
const QString categoryName = factory->category();
|
||||
@@ -399,15 +374,7 @@ void NewDialogWidget::addItem(QStandardItem *topLevelCategoryItem, IWizardFactor
|
||||
categoryItem->setData(factory->category(), Qt::UserRole);
|
||||
}
|
||||
|
||||
QStandardItem *wizardItem = new QStandardItem(factory->displayName());
|
||||
QIcon wizardIcon;
|
||||
|
||||
// spacing hack. Add proper icons instead
|
||||
if (factory->icon().isNull())
|
||||
wizardIcon = m_dummyIcon;
|
||||
else
|
||||
wizardIcon = factory->icon();
|
||||
wizardItem->setIcon(iconWithText(wizardIcon, factory->iconText()));
|
||||
QStandardItem *wizardItem = new QStandardItem(factory->icon(), factory->displayName());
|
||||
wizardItem->setData(QVariant::fromValue(WizardFactoryContainer(factory, 0)), Qt::UserRole);
|
||||
wizardItem->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable);
|
||||
categoryItem->appendRow(wizardItem);
|
||||
|
@@ -86,7 +86,6 @@ private:
|
||||
QStandardItemModel *m_model;
|
||||
QSortFilterProxyModel *m_filterProxyModel;
|
||||
QPushButton *m_okButton = nullptr;
|
||||
QIcon m_dummyIcon;
|
||||
QList<QStandardItem *> m_categoryItems;
|
||||
Utils::FilePath m_defaultLocation;
|
||||
QVariantMap m_extraVariables;
|
||||
|
@@ -423,6 +423,39 @@ void IWizardFactory::initialize()
|
||||
ActionManager::registerAction(s_inspectWizardAction, "Wizard.Inspect");
|
||||
}
|
||||
|
||||
static QIcon iconWithText(const QIcon &icon, const QString &text)
|
||||
{
|
||||
if (icon.isNull()) {
|
||||
static const QIcon fallBack(":/utils/images/wizardicon-file.png");
|
||||
return iconWithText(fallBack, text);
|
||||
}
|
||||
|
||||
if (text.isEmpty())
|
||||
return icon;
|
||||
|
||||
QIcon iconWithText;
|
||||
for (const QSize &pixmapSize : icon.availableSizes()) {
|
||||
QPixmap pixmap = icon.pixmap(pixmapSize);
|
||||
const int fontSize = pixmap.height() / 4;
|
||||
const int margin = pixmap.height() / 8;
|
||||
QFont font;
|
||||
font.setPixelSize(fontSize);
|
||||
font.setStretch(85);
|
||||
QPainter p(&pixmap);
|
||||
p.setFont(font);
|
||||
QTextOption textOption(Qt::AlignHCenter | Qt::AlignBottom);
|
||||
textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
|
||||
p.drawText(pixmap.rect().adjusted(margin, margin, -margin, -margin), text, textOption);
|
||||
iconWithText.addPixmap(pixmap);
|
||||
}
|
||||
return iconWithText;
|
||||
}
|
||||
|
||||
void IWizardFactory::setIcon(const QIcon &icon, const QString &iconText)
|
||||
{
|
||||
m_icon = iconWithText(icon, iconText);
|
||||
}
|
||||
|
||||
void IWizardFactory::setDetailsPageQmlPath(const QString &filePath)
|
||||
{
|
||||
if (filePath.isEmpty())
|
||||
|
@@ -64,7 +64,6 @@ public:
|
||||
Utils::Id id() const { return m_id; }
|
||||
WizardKind kind() const { return m_supportedProjectTypes.isEmpty() ? FileWizard : ProjectWizard; }
|
||||
QIcon icon() const { return m_icon; }
|
||||
QString iconText() const { return m_iconText; }
|
||||
QString description() const { return m_description; }
|
||||
QString displayName() const { return m_displayName; }
|
||||
QString category() const { return m_category; }
|
||||
@@ -78,8 +77,7 @@ public:
|
||||
|
||||
void setId(const Utils::Id id) { m_id = id; }
|
||||
void setSupportedProjectTypes(const QSet<Utils::Id> &projectTypes) { m_supportedProjectTypes = projectTypes; }
|
||||
void setIcon(const QIcon &icon) { m_icon = icon; }
|
||||
void setIconText(const QString &iconText) { m_iconText = iconText; }
|
||||
void setIcon(const QIcon &icon, const QString &iconText = {});
|
||||
void setDescription(const QString &description) { m_description = description; }
|
||||
void setDisplayName(const QString &displayName) { m_displayName = displayName; }
|
||||
void setCategory(const QString &category) { m_category = category; }
|
||||
@@ -135,7 +133,6 @@ private:
|
||||
|
||||
QAction *m_action = nullptr;
|
||||
QIcon m_icon;
|
||||
QString m_iconText;
|
||||
QString m_description;
|
||||
QString m_displayName;
|
||||
QString m_category;
|
||||
|
@@ -91,7 +91,7 @@ bool FormEditorPlugin::initialize(const QStringList &arguments, QString *error)
|
||||
wizard->setCategory(Core::Constants::WIZARD_CATEGORY_QT);
|
||||
wizard->setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::WIZARD_TR_CATEGORY_QT));
|
||||
wizard->setDisplayName(tr("Qt Designer Form Class"));
|
||||
wizard->setIconText("ui/h");
|
||||
wizard->setIcon({}, "ui/h");
|
||||
wizard->setId("C.FormClass");
|
||||
wizard->setDescription(tr("Creates a Qt Designer form along with a matching class (C++ header and source file) "
|
||||
"for implementation purposes. You can add the form and class to an existing Qt Widget Project."));
|
||||
|
@@ -588,12 +588,9 @@ bool JsonWizardFactory::initialize(const QVariantMap &data, const QDir &baseDir,
|
||||
*errorMessage = tr("Icon file \"%1\" not found.").arg(QDir::toNativeSeparators(strVal));
|
||||
return false;
|
||||
}
|
||||
setIcon(QIcon(strVal));
|
||||
}
|
||||
|
||||
strVal = data.value(QLatin1String(ICON_TEXT_KEY)).toString();
|
||||
if (!strVal.isEmpty())
|
||||
setIconText(strVal);
|
||||
const QString iconText = data.value(QLatin1String(ICON_TEXT_KEY)).toString();
|
||||
setIcon(iconText.isEmpty() ? QIcon() : QIcon(strVal), iconText);
|
||||
|
||||
strVal = data.value(QLatin1String(IMAGE_KEY)).toString();
|
||||
if (!strVal.isEmpty()) {
|
||||
|
Reference in New Issue
Block a user