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

View File

@@ -67,8 +67,8 @@ constexpr TextFormat h6CapitalTF
static QLabel *sectionTitle(const TextFormat &tf, const QString &title)
{
QLabel *label = tfLabel(tf, true);
label->setText(title);
auto *label = new ElidingLabel(title);
applyTf(label, tf);
return label;
};
@@ -134,7 +134,8 @@ public:
static const TextFormat detailsTF
{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->setContentsMargins({});
m_divider = new QLabel;
@@ -144,9 +145,11 @@ public:
const QPixmap dlIcon = Icon({{":/extensionmanager/images/download.png", dlTF.themeColor}},
Icon::Tint).pixmap();
m_dlIcon->setPixmap(dlIcon);
m_dlCount = tfLabel(dlTF);
m_dlCount = new ElidingLabel;
applyTf(m_dlCount, dlTF);
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->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
installButton->hide();
@@ -428,12 +431,12 @@ static QWidget *descriptionPlaceHolder()
static const TextFormat tF {
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->setText(Tr::tr("No details to show"));
auto text = tfLabel(tF, false);
auto text = new QLabel(Tr::tr("Select an extension to see more information about it."));
applyTf(text, tF, false);
text->setAlignment(Qt::AlignCenter);
text->setText(Tr::tr("Select an extension to see more information about it."));
text->setFont({});
using namespace Layouting;
// clang-format off
@@ -475,15 +478,19 @@ ExtensionManagerWidget::ExtensionManagerWidget()
m_description->setMargins({verticalPadding, 0, verticalPadding, 0});
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_tags = new TagList;
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_dependencies = tfLabel(contentTF, false);
m_dependencies = new QLabel;
applyTf(m_dependencies, contentTF, false);
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;
auto secondary = new QWidget;

View File

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

View File

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