Core: Turn QLabel *tfLabel() into applyTf(QLabel *label)

Decorating an existing label is more flexible than creating a decorated
one.

This turns
  QLabel *tfLabel(const TextFormat &tf, ...)
into
  applyTf(QLabel *label, const TextFormat &tf, ...)

And adapts the current callers, accordingly.

Change-Id: Ib42ca5ed1670bba9df11bb28837040537512131f
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Alessandro Portale
2024-11-21 23:33:11 +01:00
parent 2099f5bb98
commit a18e24f94f
5 changed files with 46 additions and 34 deletions

View File

@@ -88,9 +88,8 @@ QWidget *createRule(Qt::Orientation orientation, QWidget *parent)
return rule; return rule;
} }
QLabel *tfLabel(const TextFormat &tf, bool singleLine) void applyTf(QLabel *label, const TextFormat &tf, bool singleLine)
{ {
QLabel *label = singleLine ? new Utils::ElidingLabel : new QLabel;
if (singleLine) if (singleLine)
label->setFixedHeight(tf.lineHeight()); label->setFixedHeight(tf.lineHeight());
label->setFont(tf.font()); label->setFont(tf.font());
@@ -100,8 +99,6 @@ QLabel *tfLabel(const TextFormat &tf, bool singleLine)
QPalette pal = label->palette(); QPalette pal = label->palette();
pal.setColor(QPalette::WindowText, tf.color()); pal.setColor(QPalette::WindowText, tf.color());
label->setPalette(pal); label->setPalette(pal);
return label;
} }
} // namespace WelcomePageHelpers } // namespace WelcomePageHelpers
@@ -1271,8 +1268,8 @@ void SectionedGridView::setSearchString(const QString &searchString)
static QLabel *createTitleLabel(const QString &text) static QLabel *createTitleLabel(const QString &text)
{ {
constexpr TextFormat headerTitleTF {Theme::Token_Text_Muted, StyleHelper::UiElementH4}; constexpr TextFormat headerTitleTF {Theme::Token_Text_Muted, StyleHelper::UiElementH4};
auto label = tfLabel(headerTitleTF); auto label = new ElidingLabel(text);
label->setText(text); applyTf(label, headerTitleTF);
label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
return label; return label;
} }
@@ -1308,8 +1305,8 @@ ListModel *SectionedGridView::addSection(const Section &section, const QList<Lis
const auto it = m_gridViews.insert(section, gridView); const auto it = m_gridViews.insert(section, gridView);
constexpr TextFormat headerTitleTF {Theme::Token_Text_Muted, StyleHelper::UiElementH4}; constexpr TextFormat headerTitleTF {Theme::Token_Text_Muted, StyleHelper::UiElementH4};
auto sectionNameLabel = WelcomePageHelpers::tfLabel(headerTitleTF); auto sectionNameLabel = new ElidingLabel(section.name);
sectionNameLabel->setText(section.name); applyTf(sectionNameLabel, headerTitleTF);
QLabel *seeAllLink = createLinkLabel(Tr::tr("Show All") + " &gt;", this); QLabel *seeAllLink = createLinkLabel(Tr::tr("Show All") + " &gt;", this);
if (gridView->maxRows().has_value()) { if (gridView->maxRows().has_value()) {

View File

@@ -67,7 +67,7 @@ CORE_EXPORT void drawCardBackground(QPainter *painter, const QRectF &rect,
const QBrush &fill, const QPen &pen = QPen(Qt::NoPen), const QBrush &fill, const QPen &pen = QPen(Qt::NoPen),
qreal rounding = defaultCardBackgroundRounding); qreal rounding = defaultCardBackgroundRounding);
CORE_EXPORT QWidget *createRule(Qt::Orientation orientation, QWidget *parent = nullptr); CORE_EXPORT QWidget *createRule(Qt::Orientation orientation, QWidget *parent = nullptr);
CORE_EXPORT QLabel *tfLabel(const TextFormat &tf, bool singleLine = true); CORE_EXPORT void applyTf(QLabel *label, const TextFormat &tf, bool singleLine = true);
} // namespace WelcomePageHelpers } // namespace WelcomePageHelpers

View File

@@ -67,8 +67,8 @@ constexpr TextFormat h6CapitalTF
static QLabel *sectionTitle(const TextFormat &tf, const QString &title) static QLabel *sectionTitle(const TextFormat &tf, const QString &title)
{ {
QLabel *label = tfLabel(tf, true); auto *label = new ElidingLabel(title);
label->setText(title); applyTf(label, tf);
return label; return label;
}; };
@@ -134,7 +134,8 @@ public:
static const TextFormat detailsTF static const TextFormat detailsTF
{titleTF.themeColor, Utils::StyleHelper::UiElementCaption}; {titleTF.themeColor, Utils::StyleHelper::UiElementCaption};
m_title = tfLabel(titleTF); m_title = new ElidingLabel;
applyTf(m_title, titleTF);
m_vendor = new Button({}, Button::SmallLink); m_vendor = new Button({}, Button::SmallLink);
m_vendor->setContentsMargins({}); m_vendor->setContentsMargins({});
m_divider = new QLabel; m_divider = new QLabel;
@@ -144,9 +145,11 @@ public:
const QPixmap dlIcon = Icon({{":/extensionmanager/images/download.png", dlTF.themeColor}}, const QPixmap dlIcon = Icon({{":/extensionmanager/images/download.png", dlTF.themeColor}},
Icon::Tint).pixmap(); Icon::Tint).pixmap();
m_dlIcon->setPixmap(dlIcon); m_dlIcon->setPixmap(dlIcon);
m_dlCount = tfLabel(dlTF); m_dlCount = new ElidingLabel;
applyTf(m_dlCount, dlTF);
m_dlCount->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); m_dlCount->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
m_details = tfLabel(detailsTF); m_details = new ElidingLabel;
applyTf(m_details, detailsTF);
installButton = new Button(Tr::tr("Install..."), Button::MediumPrimary); installButton = new Button(Tr::tr("Install..."), Button::MediumPrimary);
installButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); installButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
installButton->hide(); installButton->hide();
@@ -428,12 +431,12 @@ static QWidget *descriptionPlaceHolder()
static const TextFormat tF { static const TextFormat tF {
Theme::Token_Text_Muted, UiElement::UiElementH4 Theme::Token_Text_Muted, UiElement::UiElementH4
}; };
auto title = tfLabel(tF); auto title = new ElidingLabel(Tr::tr("No details to show"));
applyTf(title, tF);
title->setAlignment(Qt::AlignCenter); title->setAlignment(Qt::AlignCenter);
title->setText(Tr::tr("No details to show")); auto text = new QLabel(Tr::tr("Select an extension to see more information about it."));
auto text = tfLabel(tF, false); applyTf(text, tF, false);
text->setAlignment(Qt::AlignCenter); text->setAlignment(Qt::AlignCenter);
text->setText(Tr::tr("Select an extension to see more information about it."));
text->setFont({}); text->setFont({});
using namespace Layouting; using namespace Layouting;
// clang-format off // clang-format off
@@ -475,15 +478,19 @@ ExtensionManagerWidget::ExtensionManagerWidget()
m_description->setMargins({verticalPadding, 0, verticalPadding, 0}); m_description->setMargins({verticalPadding, 0, verticalPadding, 0});
m_dateUpdatedTitle = sectionTitle(h6TF, Tr::tr("Last Update")); m_dateUpdatedTitle = sectionTitle(h6TF, Tr::tr("Last Update"));
m_dateUpdated = tfLabel(contentTF, false); m_dateUpdated = new QLabel;
applyTf(m_dateUpdated, contentTF, false);
m_tagsTitle = sectionTitle(h6TF, Tr::tr("Tags")); m_tagsTitle = sectionTitle(h6TF, Tr::tr("Tags"));
m_tags = new TagList; m_tags = new TagList;
m_platformsTitle = sectionTitle(h6TF, Tr::tr("Platforms")); m_platformsTitle = sectionTitle(h6TF, Tr::tr("Platforms"));
m_platforms = tfLabel(contentTF, false); m_platforms = new QLabel;
applyTf(m_platforms, contentTF, false);
m_dependenciesTitle = sectionTitle(h6TF, Tr::tr("Dependencies")); m_dependenciesTitle = sectionTitle(h6TF, Tr::tr("Dependencies"));
m_dependencies = tfLabel(contentTF, false); m_dependencies = new QLabel;
applyTf(m_dependencies, contentTF, false);
m_packExtensionsTitle = sectionTitle(h6TF, Tr::tr("Extensions in pack")); m_packExtensionsTitle = sectionTitle(h6TF, Tr::tr("Extensions in pack"));
m_packExtensions = tfLabel(contentTF, false); m_packExtensions = new QLabel;
applyTf(m_packExtensions, contentTF, false);
m_pluginStatus = new PluginStatusWidget; m_pluginStatus = new PluginStatusWidget;
auto secondary = new QWidget; auto secondary = new QWidget;

View File

@@ -209,20 +209,26 @@ public:
m_iconLabel = new QLabel; m_iconLabel = new QLabel;
m_iconLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); m_iconLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
m_itemNameLabel = tfLabel(itemNameTF); m_itemNameLabel = new ElidingLabel;
applyTf(m_itemNameLabel, itemNameTF);
m_itemNameLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); m_itemNameLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
m_releaseStatus = tfLabel(releaseStatusTF, false); m_releaseStatus = new QLabel;
applyTf(m_releaseStatus, releaseStatusTF, false);
m_releaseStatus->setAlignment(Qt::AlignLeft); m_releaseStatus->setAlignment(Qt::AlignLeft);
m_releaseStatus->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); m_releaseStatus->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
m_installStateLabel = tfLabel(stateActiveTF, false); m_installStateLabel = new QLabel;
applyTf(m_installStateLabel, stateActiveTF, false);
m_installStateLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); m_installStateLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
m_installStateIcon = new QLabel; m_installStateIcon = new QLabel;
m_installStateIcon->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); m_installStateIcon->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
m_vendorLabel = tfLabel(vendorTF); m_vendorLabel = new ElidingLabel;
applyTf(m_vendorLabel, vendorTF);
m_downloadDividerLabel = new QLabel; m_downloadDividerLabel = new QLabel;
m_downloadIconLabel = new QLabel; m_downloadIconLabel = new QLabel;
m_downloadCountLabel = tfLabel(countTF); m_downloadCountLabel = new QLabel;
m_shortDescriptionLabel = tfLabel(descriptionTF); applyTf(m_downloadCountLabel, countTF);
m_shortDescriptionLabel = new ElidingLabel;
applyTf(m_shortDescriptionLabel, descriptionTF);
using namespace Layouting; using namespace Layouting;
Row { Row {
@@ -514,7 +520,8 @@ public:
static QWidget *extensionViewPlaceHolder() static QWidget *extensionViewPlaceHolder()
{ {
static const TextFormat tF {Theme::Token_Text_Muted, UiElementH4}; static const TextFormat tF {Theme::Token_Text_Muted, UiElementH4};
auto text = tfLabel(tF, false); auto text = new QLabel;
applyTf(text, tF, false);
text->setAlignment(Qt::AlignCenter); text->setAlignment(Qt::AlignCenter);
text->setText(Tr::tr("No extension found!")); text->setText(Tr::tr("No extension found!"));
text->setWordWrap(true); text->setWordWrap(true);
@@ -540,8 +547,8 @@ ExtensionsBrowser::ExtensionsBrowser(ExtensionsModel *model, QWidget *parent)
static const TextFormat titleTF static const TextFormat titleTF
{Theme::Token_Text_Default, UiElementH2}; {Theme::Token_Text_Default, UiElementH2};
QLabel *titleLabel = tfLabel(titleTF); auto titleLabel = new ElidingLabel(Tr::tr("Manage Extensions"));
titleLabel->setText(Tr::tr("Manage Extensions")); applyTf(titleLabel, titleTF);
d->searchBox = new SearchBox; d->searchBox = new SearchBox;
d->searchBox->setPlaceholderText(Tr::tr("Search")); d->searchBox->setPlaceholderText(Tr::tr("Search"));

View File

@@ -19,6 +19,7 @@
#include <coreplugin/welcomepagehelper.h> #include <coreplugin/welcomepagehelper.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/elidinglabel.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <utils/icon.h> #include <utils/icon.h>
@@ -75,9 +76,9 @@ public:
ideIconLabel->setFixedHeight(lineHeight); ideIconLabel->setFixedHeight(lineHeight);
} }
auto welcomeLabel = tfLabel(welcomeTF); auto welcomeLabel = new ElidingLabel(Tr::tr("Welcome to %1")
welcomeLabel->setText(Tr::tr("Welcome to %1")
.arg(QGuiApplication::applicationDisplayName())); .arg(QGuiApplication::applicationDisplayName()));
applyTf(welcomeLabel, welcomeTF);
welcomeLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); welcomeLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
using namespace Layouting; using namespace Layouting;