From a18e24f94fae2979ebb5d27a5b45c2d280881de9 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Thu, 21 Nov 2024 23:33:11 +0100 Subject: [PATCH] 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 --- src/plugins/coreplugin/welcomepagehelper.cpp | 13 +++----- src/plugins/coreplugin/welcomepagehelper.h | 2 +- .../extensionmanagerwidget.cpp | 33 +++++++++++-------- .../extensionmanager/extensionsbrowser.cpp | 25 +++++++++----- src/plugins/welcome/welcomeplugin.cpp | 7 ++-- 5 files changed, 46 insertions(+), 34 deletions(-) diff --git a/src/plugins/coreplugin/welcomepagehelper.cpp b/src/plugins/coreplugin/welcomepagehelper.cpp index 967952e02df..478bb0249e3 100644 --- a/src/plugins/coreplugin/welcomepagehelper.cpp +++ b/src/plugins/coreplugin/welcomepagehelper.cpp @@ -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 §ion, const QListsetText(section.name); + auto sectionNameLabel = new ElidingLabel(section.name); + applyTf(sectionNameLabel, headerTitleTF); QLabel *seeAllLink = createLinkLabel(Tr::tr("Show All") + " >", this); if (gridView->maxRows().has_value()) { diff --git a/src/plugins/coreplugin/welcomepagehelper.h b/src/plugins/coreplugin/welcomepagehelper.h index 7de554e84a9..8ee3f50b371 100644 --- a/src/plugins/coreplugin/welcomepagehelper.h +++ b/src/plugins/coreplugin/welcomepagehelper.h @@ -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 diff --git a/src/plugins/extensionmanager/extensionmanagerwidget.cpp b/src/plugins/extensionmanager/extensionmanagerwidget.cpp index a6a284d80fd..2f2fa4131ca 100644 --- a/src/plugins/extensionmanager/extensionmanagerwidget.cpp +++ b/src/plugins/extensionmanager/extensionmanagerwidget.cpp @@ -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; diff --git a/src/plugins/extensionmanager/extensionsbrowser.cpp b/src/plugins/extensionmanager/extensionsbrowser.cpp index a3e542a9905..420bb0344fb 100644 --- a/src/plugins/extensionmanager/extensionsbrowser.cpp +++ b/src/plugins/extensionmanager/extensionsbrowser.cpp @@ -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")); diff --git a/src/plugins/welcome/welcomeplugin.cpp b/src/plugins/welcome/welcomeplugin.cpp index 1f5b279dd5d..d364519bd3a 100644 --- a/src/plugins/welcome/welcomeplugin.cpp +++ b/src/plugins/welcome/welcomeplugin.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -75,9 +76,9 @@ public: ideIconLabel->setFixedHeight(lineHeight); } - auto welcomeLabel = tfLabel(welcomeTF); - welcomeLabel->setText(Tr::tr("Welcome to %1") - .arg(QGuiApplication::applicationDisplayName())); + auto welcomeLabel = new ElidingLabel(Tr::tr("Welcome to %1") + .arg(QGuiApplication::applicationDisplayName())); + applyTf(welcomeLabel, welcomeTF); welcomeLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); using namespace Layouting;