Commit 5a0d7a0a authored by Alessandro Portale's avatar Alessandro Portale

Core: Enable text overlay for "New File/Project" icons

Change-Id: I6f206b2c97f7435b4de3a06c32b3933f3519181a
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 15e6ec45
......@@ -369,6 +369,26 @@ IWizardFactory *NewDialog::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);
QFont font;
font.setPixelSize(qMin(pixmap.height(), pixmap.width()) / 5);
QPainter p(&pixmap);
p.setPen(qRgb(0x6b, 0x70, 0x80));
p.setFont(font);
QTextOption textOption(Qt::AlignHCenter | Qt::AlignBottom);
textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
p.drawText(pixmap.rect().adjusted(9, 10, -9, -10), text, textOption);
iconWithText.addPixmap(pixmap);
}
return iconWithText;
}
void NewDialog::addItem(QStandardItem *topLevelCategoryItem, IWizardFactory *factory)
{
const QString categoryName = factory->category();
......@@ -394,7 +414,7 @@ void NewDialog::addItem(QStandardItem *topLevelCategoryItem, IWizardFactory *fac
wizardIcon = m_dummyIcon;
else
wizardIcon = factory->icon();
wizardItem->setIcon(wizardIcon);
wizardItem->setIcon(iconWithText(wizardIcon, factory->iconText()));
wizardItem->setData(QVariant::fromValue(WizardFactoryContainer(factory, 0)), Qt::UserRole);
wizardItem->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable);
categoryItem->appendRow(wizardItem);
......
......@@ -60,6 +60,7 @@ public:
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; }
......@@ -72,6 +73,7 @@ public:
void setId(const Id id) { m_id = id; }
void setSupportedProjectTypes(const QSet<Id> &projectTypes) { m_supportedProjectTypes = projectTypes; }
void setIcon(const QIcon &icon) { m_icon = icon; }
void setIconText(const QString &iconText) { m_iconText = 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; }
......@@ -123,6 +125,7 @@ private:
QAction *m_action = 0;
QIcon m_icon;
QString m_iconText;
QString m_description;
QString m_displayName;
QString m_category;
......
......@@ -70,6 +70,7 @@ static const char CATEGORY_KEY[] = "category";
static const char CATEGORY_NAME_KEY[] = "trDisplayCategory";
static const char DISPLAY_NAME_KEY[] = "trDisplayName";
static const char ICON_KEY[] = "icon";
static const char ICON_TEXT_KEY[] = "iconText";
static const char IMAGE_KEY[] = "image";
static const char DESCRIPTION_KEY[] = "trDescription";
static const char REQUIRED_FEATURES_KEY[] = "featuresRequired";
......@@ -559,6 +560,10 @@ bool JsonWizardFactory::initialize(const QVariantMap &data, const QDir &baseDir,
setIcon(QIcon(strVal));
}
strVal = data.value(QLatin1String(ICON_TEXT_KEY)).toString();
if (!strVal.isEmpty())
setIconText(strVal);
strVal = data.value(QLatin1String(IMAGE_KEY)).toString();
if (!strVal.isEmpty()) {
strVal = baseDir.absoluteFilePath(strVal);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment