aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlessandro Portale <alessandro.portale@qt.io>2025-04-28 12:40:17 +0200
committerAlessandro Portale <alessandro.portale@qt.io>2025-04-29 08:52:43 +0000
commit4a37a93583cb7de76f54cf6a17dad4e508fd3c2c (patch)
treedef0cc1de5269270ae5f563e2a0eb4208754b436
parenta174aa2b2212672b5962146966eb9f1ebc989ddd (diff)
Utils: Move components from core/welcomepagehelpers to qtcwidgets
This also provides the widgets with the class name prefix "Qtc", in order to disambiguate them and the Layouting classes. The LayoutHelper "CoreButton" is renamed to Utils::QtcWidgets::Button and exposed to Lua as "QtcWidget". Change-Id: I2ed7e5f7cee91d1505c8dd13003a91f785e58c53 Reviewed-by: hjk <hjk@qt.io>
-rw-r--r--src/libs/utils/CMakeLists.txt1
-rw-r--r--src/libs/utils/qtcwidgets.cpp559
-rw-r--r--src/libs/utils/qtcwidgets.h133
-rw-r--r--src/libs/utils/utils.qbs2
-rw-r--r--src/plugins/coreplugin/welcomepagehelper.cpp525
-rw-r--r--src/plugins/coreplugin/welcomepagehelper.h131
-rw-r--r--src/plugins/extensionmanager/extensionmanagerwidget.cpp18
-rw-r--r--src/plugins/extensionmanager/extensionsbrowser.cpp5
-rw-r--r--src/plugins/extensionmanager/extensionsbrowser.h4
-rw-r--r--src/plugins/learning/qtacademywelcomepage.cpp3
-rw-r--r--src/plugins/lua/bindings/gui.cpp21
-rw-r--r--src/plugins/projectexplorer/projectwelcomepage.cpp16
-rw-r--r--src/plugins/qtsupport/gettingstartedwelcomepage.cpp6
-rw-r--r--src/plugins/welcome/welcomeplugin.cpp13
-rw-r--r--tests/manual/widgets/components/tst_manual_widgets_components.cpp45
-rw-r--r--tests/manual/widgets/layoutbuilder/tst_manual_widgets_layoutbuilder.cpp39
16 files changed, 782 insertions, 739 deletions
diff --git a/src/libs/utils/CMakeLists.txt b/src/libs/utils/CMakeLists.txt
index eb3a5fa0f28..66a4a22060d 100644
--- a/src/libs/utils/CMakeLists.txt
+++ b/src/libs/utils/CMakeLists.txt
@@ -140,6 +140,7 @@ add_qtc_library(Utils
qtcolorbutton.cpp qtcolorbutton.h
qtcprocess.cpp qtcprocess.h
qtcsettings.cpp qtcsettings.h
+ qtcwidgets.cpp qtcwidgets.h
ranges.h
reloadpromptutils.cpp reloadpromptutils.h
removefiledialog.cpp removefiledialog.h
diff --git a/src/libs/utils/qtcwidgets.cpp b/src/libs/utils/qtcwidgets.cpp
new file mode 100644
index 00000000000..a2e4acaa267
--- /dev/null
+++ b/src/libs/utils/qtcwidgets.cpp
@@ -0,0 +1,559 @@
+// Copyright (C) 2023 Tasuku Suzuki <tasuku.suzuki@signal-slot.co.jp>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#include "qtcwidgets.h"
+
+#include "hostosinfo.h"
+#include "icon.h"
+
+#include <QEvent>
+#include <QGuiApplication>
+#include <QPaintEvent>
+#include <QPainter>
+#include <QWidget>
+
+namespace Utils {
+
+using namespace StyleHelper::SpacingTokens;
+
+const qreal disabledIconOpacity = 0.3;
+
+QColor TextFormat::color() const
+{
+ return Utils::creatorColor(themeColor);
+}
+
+QFont TextFormat::font(bool underlined) const
+{
+ QFont result = Utils::StyleHelper::uiFont(uiElement);
+ result.setUnderline(underlined);
+ return result;
+}
+
+int TextFormat::lineHeight() const
+{
+ return Utils::StyleHelper::uiFontLineHeight(uiElement);
+}
+
+void applyTf(QLabel *label, const TextFormat &tf, bool singleLine)
+{
+ if (singleLine)
+ label->setFixedHeight(tf.lineHeight());
+ label->setFont(tf.font());
+ label->setAlignment(Qt::Alignment(tf.drawTextFlags));
+ label->setTextInteractionFlags(Qt::TextSelectableByMouse);
+
+ QPalette pal = label->palette();
+ pal.setColor(QPalette::WindowText, tf.color());
+ label->setPalette(pal);
+}
+
+enum WidgetState {
+ WidgetStateDefault,
+ WidgetStateChecked,
+ WidgetStateHovered,
+};
+
+static const TextFormat &buttonTF(QtcButton::Role role, WidgetState state)
+{
+ static const TextFormat largePrimaryTF
+ {Theme::Token_Basic_White, StyleHelper::UiElement::UiElementButtonMedium,
+ Qt::AlignCenter | Qt::TextDontClip | Qt::TextShowMnemonic};
+ static const TextFormat largeSecondaryTF
+ {Theme::Token_Text_Default, largePrimaryTF.uiElement, largePrimaryTF.drawTextFlags};
+ static const TextFormat smallPrimaryTF
+ {largePrimaryTF.themeColor, StyleHelper::UiElement::UiElementButtonSmall,
+ largePrimaryTF.drawTextFlags};
+ static const TextFormat smallSecondaryTF
+ {largeSecondaryTF.themeColor, smallPrimaryTF.uiElement, smallPrimaryTF.drawTextFlags};
+ static const TextFormat smallListDefaultTF
+ {Theme::Token_Text_Default, StyleHelper::UiElement::UiElementIconStandard,
+ Qt::AlignLeft | Qt::AlignVCenter | Qt::TextDontClip | Qt::TextShowMnemonic};
+ static const TextFormat smallListCheckedTF = smallListDefaultTF;
+ static const TextFormat smallLinkDefaultTF
+ {Theme::Token_Text_Default, StyleHelper::UiElement::UiElementIconStandard,
+ smallListDefaultTF.drawTextFlags};
+ static const TextFormat smallLinkHoveredTF
+ {Theme::Token_Text_Accent, smallLinkDefaultTF.uiElement,
+ smallLinkDefaultTF.drawTextFlags};
+ static const TextFormat tagDefaultTF
+ {Theme::Token_Text_Muted, StyleHelper::UiElement::UiElementLabelMedium};
+ static const TextFormat tagHoverTF
+ {Theme::Token_Text_Default, tagDefaultTF.uiElement};
+
+ switch (role) {
+ case QtcButton::LargePrimary: return largePrimaryTF;
+ case QtcButton::LargeSecondary:
+ case QtcButton::LargeTertiary:
+ return largeSecondaryTF;
+ case QtcButton::SmallPrimary: return smallPrimaryTF;
+ case QtcButton::SmallSecondary:
+ case QtcButton::SmallTertiary:
+ return smallSecondaryTF;
+ case QtcButton::SmallList: return (state == WidgetStateDefault) ? smallListDefaultTF
+ : smallListCheckedTF;
+ case QtcButton::SmallLink: return (state == WidgetStateDefault) ? smallLinkDefaultTF
+ : smallLinkHoveredTF;
+ case QtcButton::Tag: return (state == WidgetStateDefault) ? tagDefaultTF
+ : tagHoverTF;
+ }
+ return largePrimaryTF;
+}
+
+QtcButton::QtcButton(const QString &text, Role role, QWidget *parent)
+ : QAbstractButton(parent)
+ , m_role(role)
+{
+ setText(text);
+ setAttribute(Qt::WA_Hover);
+
+ updateMargins();
+ if (m_role == SmallList)
+ setCheckable(true);
+ else if (m_role == SmallLink)
+ setCursor(Qt::PointingHandCursor);
+}
+
+QSize QtcButton::minimumSizeHint() const
+{
+ int maxTextWidth = 0;
+ for (WidgetState state : {WidgetStateDefault, WidgetStateChecked, WidgetStateHovered} ) {
+ const TextFormat &tf = buttonTF(m_role, state);
+ const QFontMetrics fm(tf.font());
+ const QSize textS = fm.size(Qt::TextShowMnemonic, text());
+ maxTextWidth = qMax(maxTextWidth, textS.width());
+ }
+ const TextFormat &tf = buttonTF(m_role, WidgetStateDefault);
+ const QMargins margins = contentsMargins();
+ return {margins.left() + maxTextWidth + margins.right(),
+ margins.top() + tf.lineHeight() + margins.bottom()};
+}
+
+void QtcButton::paintEvent(QPaintEvent *event)
+{
+ // Without pixmap
+ // +----------------+----------------+----------------+
+ // | |(VPadding[S|XS])| |
+ // | +----------------+----------------+
+ // |(HPadding[S|XS])| <label> |(HPadding[S|XS])|
+ // | +----------------+----------------+
+ // | |(VPadding[S|XS])| |
+ // +----------------+---------------------------------+
+ //
+ // With pixmap
+ // +--------+------------+---------------------------------+
+ // | | |(VPadding[S|XS])| |
+ // | | +----------------+ |
+ // |<pixmap>|(HGap[S|XS])| <label> |(HPadding[S|XS])|
+ // | | +----------------+ |
+ // | | |(VPadding[S|XS])| |
+ // +--------+------------+----------------+----------------+
+
+ const bool hovered = underMouse();
+ const WidgetState state = isChecked() ? WidgetStateChecked : hovered ? WidgetStateHovered
+ : WidgetStateDefault;
+ const TextFormat &tf = buttonTF(m_role, state);
+ const QMargins margins = contentsMargins();
+ const QRect bgR = rect();
+
+ QPainter p(this);
+
+ const qreal brRectRounding = 3.75;
+ switch (m_role) {
+ case LargePrimary:
+ case SmallPrimary: {
+ const Theme::Color color = isEnabled() ? (isDown()
+ ? Theme::Token_Accent_Subtle
+ : (hovered ? Theme::Token_Accent_Muted
+ : Theme::Token_Accent_Default))
+ : Theme::Token_Foreground_Subtle;
+ const QBrush fill(creatorColor(color));
+ StyleHelper::drawCardBg(&p, bgR, fill, QPen(Qt::NoPen), brRectRounding);
+ break;
+ }
+ case LargeSecondary:
+ case SmallSecondary: {
+ const Theme::Color color = isEnabled() ? Theme::Token_Stroke_Strong
+ : Theme::Token_Stroke_Subtle;
+ const qreal width = hovered ? 2.0 : 1.0;
+ const QPen outline(creatorColor(color), width);
+ StyleHelper::drawCardBg(&p, bgR, QBrush(Qt::NoBrush), outline, brRectRounding);
+ break;
+ }
+ case LargeTertiary:
+ case SmallTertiary: {
+ const Theme::Color border = isDown() ? Theme::Token_Stroke_Muted
+ : Theme::Token_Stroke_Subtle;
+ const Theme::Color bg = isEnabled() ? (isDown() ? Theme::Token_Foreground_Default
+ : (hovered ? Theme::Token_Foreground_Muted
+ : Theme::Token_Foreground_Subtle))
+ : Theme::Token_Foreground_Subtle;
+ StyleHelper::drawCardBg(&p, bgR, creatorColor(bg), creatorColor(border), brRectRounding);
+ break;
+ }
+ case SmallList: {
+ if (isChecked() || hovered) {
+ const QBrush fill(creatorColor(isChecked() ? Theme::Token_Foreground_Muted
+ : Theme::Token_Foreground_Subtle));
+ StyleHelper::drawCardBg(&p, bgR, fill, QPen(Qt::NoPen), brRectRounding);
+ }
+ break;
+ }
+ case SmallLink:
+ break;
+ case Tag: {
+ const QBrush fill(hovered ? creatorColor(Theme::Token_Foreground_Subtle)
+ : QBrush(Qt::NoBrush));
+ const QPen outline(hovered ? QPen(Qt::NoPen) : creatorColor(Theme::Token_Stroke_Subtle));
+ StyleHelper::drawCardBg(&p, bgR, fill, outline, brRectRounding);
+ break;
+ }
+ }
+
+ if (!m_pixmap.isNull()) {
+ const int pixmapHeight = int(m_pixmap.deviceIndependentSize().height());
+ const int pixmapY = (bgR.height() - pixmapHeight) / 2;
+ p.drawPixmap(0, pixmapY, m_pixmap);
+ }
+
+ const int availableLabelWidth = event->rect().width() - margins.left() - margins.right();
+ const QFont font = tf.font();
+ const QFontMetrics fm(font);
+ const QString elidedLabelText = fm.elidedText(text(), Qt::ElideRight, availableLabelWidth);
+ const QRect labelR(margins.left(), margins.top(), availableLabelWidth, tf.lineHeight());
+ p.setFont(font);
+ const QColor textColor = isEnabled() ? tf.color() : creatorColor(Theme::Token_Text_Subtle);
+ p.setPen(textColor);
+ p.drawText(labelR, tf.drawTextFlags, elidedLabelText);
+}
+
+void QtcButton::setPixmap(const QPixmap &pixmap)
+{
+ m_pixmap = pixmap;
+ updateMargins();
+}
+
+void QtcButton::setRole(Role role)
+{
+ m_role = role;
+ updateMargins();
+}
+
+void QtcButton::updateMargins()
+{
+ if (m_role == Tag) {
+ setContentsMargins(HPaddingXs, VPaddingXxs, HPaddingXs, VPaddingXxs);
+ return;
+ }
+ const bool tokenSizeS = m_role == LargePrimary || m_role == LargeSecondary
+ || m_role == SmallList || m_role == SmallLink;
+ const int gap = tokenSizeS ? HGapS : HGapXs;
+ const int hPaddingR = tokenSizeS ? HPaddingS : HPaddingXs;
+ const int hPaddingL = m_pixmap.isNull() ? hPaddingR
+ : int(m_pixmap.deviceIndependentSize().width()) + gap;
+ const int vPadding = tokenSizeS ? VPaddingS : VPaddingXs;
+ setContentsMargins(hPaddingL, vPadding, hPaddingR, vPadding);
+}
+
+QtcLabel::QtcLabel(const QString &text, Role role, QWidget *parent)
+ : QLabel(text, parent)
+ , m_role(role)
+{
+ static const TextFormat primaryTF
+ {Theme::Token_Text_Muted, StyleHelper::UiElement::UiElementH3};
+ static const TextFormat secondaryTF
+ {primaryTF.themeColor, StyleHelper::UiElement::UiElementH6Capital};
+
+ const TextFormat &tF = m_role == Primary ? primaryTF : secondaryTF;
+ const int vPadding = m_role == Primary ? ExPaddingGapM : VPaddingS;
+
+ setFixedHeight(vPadding + tF.lineHeight() + vPadding);
+ setFont(tF.font());
+ QPalette pal = palette();
+ pal.setColor(QPalette::Active, QPalette::WindowText, tF.color());
+ pal.setColor(QPalette::Disabled, QPalette::WindowText, creatorColor(Theme::Token_Text_Subtle));
+ setPalette(pal);
+}
+
+constexpr TextFormat searchBoxTextTF
+ {Theme::Token_Text_Default, StyleHelper::UiElement::UiElementBody2};
+constexpr TextFormat searchBoxPlaceholderTF
+ {Theme::Token_Text_Muted, searchBoxTextTF.uiElement};
+
+static const QPixmap &searchBoxIcon()
+{
+ static const QPixmap icon = Icon({{FilePath::fromString(":/core/images/search.png"),
+ Theme::Token_Text_Muted}}, Icon::Tint).pixmap();
+ return icon;
+}
+
+QtcSearchBox::QtcSearchBox(QWidget *parent)
+ : Utils::FancyLineEdit(parent)
+{
+ setAttribute(Qt::WA_MacShowFocusRect, false);
+ setAutoFillBackground(false);
+ setFont(searchBoxTextTF.font());
+ setFrame(false);
+ setMouseTracking(true);
+
+ QPalette pal = palette();
+ pal.setColor(QPalette::Base, Qt::transparent);
+ pal.setColor(QPalette::Active, QPalette::PlaceholderText, searchBoxPlaceholderTF.color());
+ pal.setColor(QPalette::Disabled, QPalette::PlaceholderText,
+ creatorColor(Theme::Token_Text_Subtle));
+ pal.setColor(QPalette::Text, searchBoxTextTF.color());
+ setPalette(pal);
+
+ setContentsMargins({HPaddingXs, ExPaddingGapM, 0, ExPaddingGapM});
+ setFixedHeight(ExPaddingGapM + searchBoxTextTF.lineHeight() + ExPaddingGapM);
+ setFiltering(true);
+}
+
+QSize QtcSearchBox::minimumSizeHint() const
+{
+ const QFontMetrics fm(searchBoxTextTF.font());
+ const QSize textS = fm.size(Qt::TextSingleLine, text());
+ const QMargins margins = contentsMargins();
+ return {margins.left() + textS.width() + margins.right(),
+ margins.top() + searchBoxTextTF.lineHeight() + margins.bottom()};
+}
+
+void QtcSearchBox::enterEvent(QEnterEvent *event)
+{
+ QLineEdit::enterEvent(event);
+ update();
+}
+
+void QtcSearchBox::leaveEvent(QEvent *event)
+{
+ QLineEdit::leaveEvent(event);
+ update();
+}
+
+static void paintCommonBackground(QPainter *p, const QRectF &rect, const QWidget *w)
+{
+ const QBrush fill(creatorColor(Theme::Token_Background_Muted));
+ const Theme::Color c =
+ w->isEnabled() ? (w->hasFocus() ? Theme::Token_Stroke_Strong
+ : (w->underMouse() ? Theme::Token_Stroke_Muted
+ : Theme::Token_Stroke_Subtle))
+ : Theme::Token_Foreground_Subtle;
+ const QPen pen(creatorColor(c));
+ StyleHelper::drawCardBg(p, rect, fill, pen);
+}
+
+void QtcSearchBox::paintEvent(QPaintEvent *event)
+{
+ // +------------+---------------+------------+------+------------+
+ // | |(ExPaddingGapM)| | | |
+ // | +---------------+ | | |
+ // |(HPaddingXs)| <lineEdit> |(HPaddingXs)|<icon>|(HPaddingXs)|
+ // | +---------------+ | | |
+ // | |(ExPaddingGapM)| | | |
+ // +------------+---------------+------------+------+------------+
+
+ QPainter p(this);
+
+ paintCommonBackground(&p, rect(), this);
+ if (text().isEmpty()) {
+ const QPixmap icon = searchBoxIcon();
+ const QSize iconS = icon.deviceIndependentSize().toSize();
+ const QPoint iconPos(width() - HPaddingXs - iconS.width(), (height() - iconS.height()) / 2);
+ if (!isEnabled())
+ p.setOpacity(disabledIconOpacity);
+ p.drawPixmap(iconPos, icon);
+ }
+
+ QLineEdit::paintEvent(event);
+}
+
+constexpr TextFormat ComboBoxTf
+ {Theme::Token_Text_Muted, StyleHelper::UiElementIconActive,
+ Qt::AlignLeft | Qt::AlignVCenter | Qt::TextDontClip};
+
+static const QPixmap &comboBoxIcon()
+{
+ static const QPixmap icon = Icon({{FilePath::fromString(":/core/images/expandarrow.png"),
+ ComboBoxTf.themeColor}}, Icon::Tint).pixmap();
+ return icon;
+}
+
+QtcComboBox::QtcComboBox(QWidget *parent)
+ : QComboBox(parent)
+{
+ setFont(ComboBoxTf.font());
+ setMouseTracking(true);
+
+ const QSize iconSize = comboBoxIcon().deviceIndependentSize().toSize();
+ setContentsMargins({HPaddingXs, VPaddingXs,
+ HGapXxs + iconSize.width() + HPaddingXs, VPaddingXs});
+}
+
+QSize QtcComboBox::sizeHint() const
+{
+ const QSize parentS = QComboBox::sizeHint();
+ const QMargins margins = contentsMargins();
+ return {margins.left() + parentS.width() + margins.right(),
+ margins.top() + ComboBoxTf.lineHeight() + margins.bottom()};
+}
+
+void QtcComboBox::enterEvent(QEnterEvent *event)
+{
+ QComboBox::enterEvent(event);
+ update();
+}
+
+void QtcComboBox::leaveEvent(QEvent *event)
+{
+ QComboBox::leaveEvent(event);
+ update();
+}
+
+void QtcComboBox::paintEvent(QPaintEvent *)
+{
+ // +------------+-------------+---------+-------+------------+
+ // | | (VPaddingXs)| | | |
+ // | +-------------+ | | |
+ // |(HPaddingXs)|<currentItem>|(HGapXxs)|<arrow>|(HPaddingXs)|
+ // | +-------------+ | | |
+ // | | (VPaddingXs)| | | |
+ // +------------+-------------+---------+-------+------------+
+
+ QPainter p(this);
+ paintCommonBackground(&p, rect(), this);
+
+ const QMargins margins = contentsMargins();
+ const QRect textR(margins.left(), margins.top(),
+ width() - margins.right(), ComboBoxTf.lineHeight());
+ p.setFont(ComboBoxTf.font());
+ const QColor color = isEnabled() ? ComboBoxTf.color() : creatorColor(Theme::Token_Text_Subtle);
+ p.setPen(color);
+ p.drawText(textR, ComboBoxTf.drawTextFlags, currentText());
+
+ const QPixmap icon = comboBoxIcon();
+ const QSize iconS = icon.deviceIndependentSize().toSize();
+ const QPoint iconPos(width() - HPaddingXs - iconS.width(), (height() - iconS.height()) / 2);
+ if (!isEnabled())
+ p.setOpacity(disabledIconOpacity);
+ p.drawPixmap(iconPos, icon);
+}
+
+constexpr TextFormat SwitchLabelTf
+ {Theme::Token_Text_Default, StyleHelper::UiElementLabelMedium};
+constexpr QSize switchTrackS(32, 16);
+
+QtcSwitch::QtcSwitch(const QString &text, QWidget *parent)
+ : QAbstractButton(parent)
+{
+ setText(text);
+ setCheckable(true);
+ setAttribute(Qt::WA_Hover);
+ setLayoutDirection(Qt::RightToLeft); // Switch right, label left
+}
+
+QSize QtcSwitch::sizeHint() const
+{
+ const QFontMetrics fm(SwitchLabelTf.font());
+ const int textWidth = fm.size(Qt::TextShowMnemonic, text()).width();
+ const int width = switchTrackS.width() + HGapS + textWidth;
+ return {width, ExPaddingGapM + SwitchLabelTf.lineHeight() + ExPaddingGapM};
+}
+
+QSize QtcSwitch::minimumSizeHint() const
+{
+ return switchTrackS;
+}
+
+void QtcSwitch::paintEvent([[maybe_unused]] QPaintEvent *event)
+{
+ const bool ltr = layoutDirection() == Qt::LeftToRight;
+ const int trackX = ltr ? 0 : width() - switchTrackS.width();
+ const int trackY = (height() - switchTrackS.height()) / 2;
+ const QRect trackR(QPoint(trackX, trackY), switchTrackS);
+ const int trackRounding = trackR.height() / 2;
+ const bool checkedEnabled = isChecked() && isEnabled();
+ QPainter p(this);
+
+ { // track
+ const bool hovered = underMouse();
+ const QBrush fill = creatorColor(checkedEnabled ? (hovered ? Theme::Token_Accent_Subtle
+ : Theme::Token_Accent_Default)
+ : Theme::Token_Foreground_Subtle);
+ const QPen outline = checkedEnabled ? QPen(Qt::NoPen)
+ : creatorColor(hovered ? Theme::Token_Stroke_Muted
+ : Theme::Token_Stroke_Subtle);
+ StyleHelper::drawCardBg(&p, trackR, fill, outline, trackRounding);
+ }
+ { // track label
+ const QColor color = creatorColor(isEnabled() ? (isChecked() ? Theme::Token_Basic_White
+ : Theme::Token_Text_Muted)
+ : Theme::Token_Text_Subtle);
+ const int labelS = 6;
+ const int labelY = (height() - labelS) / 2;
+ if (isChecked()) {
+ const QRect onLabelR(trackX + 8, labelY, 1, labelS);
+ p.fillRect(onLabelR, color);
+ } else {
+ const QRect offLabelR(trackX + switchTrackS.width() - trackRounding - labelS / 2 - 1,
+ labelY, labelS, labelS);
+ StyleHelper::drawCardBg(&p, offLabelR, Qt::NoBrush, color, labelS / 2);
+ }
+ }
+ { // knob
+ const int thumbPadding = checkedEnabled ? 3 : 2;
+ const int thumbH = switchTrackS.height() - thumbPadding - thumbPadding;
+ const int thumbW = isDown() ? (checkedEnabled ? 17 : 19)
+ : thumbH;
+ const int thumbRounding = thumbH / 2;
+ const int thumbX = trackX + (isChecked() ? switchTrackS.width() - thumbW - thumbPadding
+ : thumbPadding);
+ const QRect thumbR(thumbX, trackY + thumbPadding, thumbW, thumbH);
+ const QBrush fill = creatorColor(isEnabled() ? Theme::Token_Basic_White
+ : Theme::Token_Foreground_Default);
+ const QPen outline = checkedEnabled ? QPen(Qt::NoPen)
+ : creatorColor(Theme::Token_Stroke_Subtle);
+ StyleHelper::drawCardBg(&p, thumbR, fill, outline, thumbRounding);
+ }
+ { // switch text label
+ const int switchAndGapWidth = switchTrackS.width() + HGapS;
+ const QRect textR(ltr ? switchAndGapWidth : 0, 0, width() - switchAndGapWidth,
+ trackY + switchTrackS.height());
+ p.setFont(SwitchLabelTf.font());
+ p.setPen(isEnabled() ? SwitchLabelTf.color() : creatorColor(Theme::Token_Text_Subtle));
+ const QString elidedLabel =
+ p.fontMetrics().elidedText(text(), Qt::ElideRight, textR.width());
+ p.drawText(textR, SwitchLabelTf.drawTextFlags, elidedLabel);
+ }
+}
+
+namespace QtcWidgets {
+
+Button::Button()
+{
+ ptr = new Implementation("", QtcButton::LargePrimary, nullptr);
+}
+
+Button::Button(std::initializer_list<I> ps)
+{
+ ptr = new Implementation("", QtcButton::LargePrimary, nullptr);
+ Layouting::Tools::apply(this, ps);
+}
+
+void Button::setText(const QString &text)
+{
+ Layouting::Tools::access(this)->setText(text);
+}
+
+void Button::setIcon(const Icon &icon)
+{
+ Layouting::Tools::access(this)->setPixmap(icon.pixmap());
+}
+
+void Button::setRole(QtcButton::Role role)
+{
+ Layouting::Tools::access(this)->setRole(role);
+}
+
+} // namespace QtcWidgets
+
+} // namespace Utils
diff --git a/src/libs/utils/qtcwidgets.h b/src/libs/utils/qtcwidgets.h
new file mode 100644
index 00000000000..04cb6e0567c
--- /dev/null
+++ b/src/libs/utils/qtcwidgets.h
@@ -0,0 +1,133 @@
+// Copyright (C) 2023 Tasuku Suzuki <tasuku.suzuki@signal-slot.co.jp>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#pragma once
+
+#include "utils_global.h"
+
+#include "fancylineedit.h"
+#include "layoutbuilder.h"
+#include "stylehelper.h"
+#include "theme/theme.h"
+
+#include <QAbstractButton>
+#include <QComboBox>
+#include <QLabel>
+
+namespace Utils {
+
+class QTCREATOR_UTILS_EXPORT TextFormat
+{
+public:
+ QColor color() const;
+ QFont font(bool underlined = false) const;
+ int lineHeight() const;
+
+ const Theme::Color themeColor;
+ const StyleHelper::UiElement uiElement;
+ const int drawTextFlags = Qt::AlignLeft | Qt::AlignBottom | Qt::TextDontClip
+ | Qt::TextShowMnemonic;
+};
+
+QTCREATOR_UTILS_EXPORT void applyTf(QLabel *label, const TextFormat &tf, bool singleLine = true);
+
+class QTCREATOR_UTILS_EXPORT QtcButton : public QAbstractButton
+{
+public:
+ enum Role {
+ LargePrimary,
+ LargeSecondary,
+ LargeTertiary,
+ SmallPrimary,
+ SmallSecondary,
+ SmallTertiary,
+ SmallList,
+ SmallLink,
+ Tag,
+ };
+ Q_ENUM(Role)
+
+ explicit QtcButton(const QString &text, Role role, QWidget *parent = nullptr);
+ QSize minimumSizeHint() const override;
+ void setPixmap(const QPixmap &newPixmap);
+ void setRole(Role role);
+
+protected:
+ void paintEvent(QPaintEvent *event) override;
+
+private:
+ void updateMargins();
+
+ Role m_role = LargePrimary;
+ QPixmap m_pixmap;
+};
+
+class QTCREATOR_UTILS_EXPORT QtcLabel : public QLabel
+{
+public:
+ enum Role {
+ Primary,
+ Secondary,
+ };
+ explicit QtcLabel(const QString &text, Role role, QWidget *parent = nullptr);
+
+private:
+ const Role m_role = Primary;
+};
+
+class QTCREATOR_UTILS_EXPORT QtcSearchBox : public Utils::FancyLineEdit
+{
+public:
+ explicit QtcSearchBox(QWidget *parent = nullptr);
+ QSize minimumSizeHint() const override;
+
+protected:
+ void paintEvent(QPaintEvent *event) override;
+ void enterEvent(QEnterEvent *event) override;
+ void leaveEvent(QEvent *event) override;
+};
+
+class QTCREATOR_UTILS_EXPORT QtcComboBox : public QComboBox
+{
+public:
+ explicit QtcComboBox(QWidget *parent = nullptr);
+ QSize sizeHint() const override;
+
+protected:
+ void paintEvent(QPaintEvent *event) override;
+
+protected:
+ void enterEvent(QEnterEvent *event) override;
+ void leaveEvent(QEvent *event) override;
+};
+
+class QTCREATOR_UTILS_EXPORT QtcSwitch : public QAbstractButton
+{
+public:
+ explicit QtcSwitch(const QString &text, QWidget *parent = nullptr);
+ QSize sizeHint() const override;
+ QSize minimumSizeHint() const override;
+
+protected:
+ void paintEvent(QPaintEvent *event) override;
+};
+
+namespace QtcWidgets {
+
+class QTCREATOR_UTILS_EXPORT Button : public Layouting::Widget
+{
+public:
+ using Implementation = QtcButton;
+ using I = Building::BuilderItem<Button>;
+ Button();
+ Button(std::initializer_list<I> ps);
+ void setText(const QString &text);
+ void setIcon(const Utils::Icon &icon);
+ void setRole(QtcButton::Role role);
+};
+
+} // namespace QtcWidgets
+
+QTC_DEFINE_BUILDER_SETTER(role, setRole);
+
+} // namespace Utils
diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs
index 43c30b4894b..96a5e2648a8 100644
--- a/src/libs/utils/utils.qbs
+++ b/src/libs/utils/utils.qbs
@@ -281,6 +281,8 @@ QtcLibrary {
"qtcolorbutton.h",
"qtcsettings.cpp",
"qtcsettings.h",
+ "qtcwidgets.cpp",
+ "qtcwidgets.h",
"ranges.h",
"reloadpromptutils.cpp",
"reloadpromptutils.h",
diff --git a/src/plugins/coreplugin/welcomepagehelper.cpp b/src/plugins/coreplugin/welcomepagehelper.cpp
index ea3e699b1af..00c40f4e0d4 100644
--- a/src/plugins/coreplugin/welcomepagehelper.cpp
+++ b/src/plugins/coreplugin/welcomepagehelper.cpp
@@ -11,6 +11,7 @@
#include <utils/icon.h>
#include <utils/layoutbuilder.h>
#include <utils/qtcassert.h>
+#include <utils/qtcwidgets.h>
#include <utils/stylehelper.h>
#include <utils/theme/theme.h>
@@ -40,8 +41,6 @@ namespace Core {
using namespace WelcomePageHelpers;
using namespace StyleHelper::SpacingTokens;
-const qreal disabledIconOpacity = 0.3;
-
static QColor themeColor(Theme::Color role)
{
return creatorColor(role);
@@ -71,502 +70,8 @@ QWidget *createRule(Qt::Orientation orientation, QWidget *parent)
return rule;
}
-void applyTf(QLabel *label, const TextFormat &tf, bool singleLine)
-{
- if (singleLine)
- label->setFixedHeight(tf.lineHeight());
- label->setFont(tf.font());
- label->setAlignment(Qt::Alignment(tf.drawTextFlags));
- label->setTextInteractionFlags(Qt::TextSelectableByMouse);
-
- QPalette pal = label->palette();
- pal.setColor(QPalette::WindowText, tf.color());
- label->setPalette(pal);
-}
-
} // namespace WelcomePageHelpers
-enum WidgetState {
- WidgetStateDefault,
- WidgetStateChecked,
- WidgetStateHovered,
-};
-
-static const TextFormat &buttonTF(Button::Role role, WidgetState state)
-{
- using namespace WelcomePageHelpers;
- static const TextFormat largePrimaryTF
- {Theme::Token_Basic_White, StyleHelper::UiElement::UiElementButtonMedium,
- Qt::AlignCenter | Qt::TextDontClip | Qt::TextShowMnemonic};
- static const TextFormat largeSecondaryTF
- {Theme::Token_Text_Default, largePrimaryTF.uiElement, largePrimaryTF.drawTextFlags};
- static const TextFormat smallPrimaryTF
- {largePrimaryTF.themeColor, StyleHelper::UiElement::UiElementButtonSmall,
- largePrimaryTF.drawTextFlags};
- static const TextFormat smallSecondaryTF
- {largeSecondaryTF.themeColor, smallPrimaryTF.uiElement, smallPrimaryTF.drawTextFlags};
- static const TextFormat smallListDefaultTF
- {Theme::Token_Text_Default, StyleHelper::UiElement::UiElementIconStandard,
- Qt::AlignLeft | Qt::AlignVCenter | Qt::TextDontClip | Qt::TextShowMnemonic};
- static const TextFormat smallListCheckedTF = smallListDefaultTF;
- static const TextFormat smallLinkDefaultTF
- {Theme::Token_Text_Default, StyleHelper::UiElement::UiElementIconStandard,
- smallListDefaultTF.drawTextFlags};
- static const TextFormat smallLinkHoveredTF
- {Theme::Token_Text_Accent, smallLinkDefaultTF.uiElement,
- smallLinkDefaultTF.drawTextFlags};
- static const TextFormat tagDefaultTF
- {Theme::Token_Text_Muted, StyleHelper::UiElement::UiElementLabelMedium};
- static const TextFormat tagHoverTF
- {Theme::Token_Text_Default, tagDefaultTF.uiElement};
-
- switch (role) {
- case Button::LargePrimary: return largePrimaryTF;
- case Button::LargeSecondary:
- case Button::LargeTertiary:
- return largeSecondaryTF;
- case Button::SmallPrimary: return smallPrimaryTF;
- case Button::SmallSecondary:
- case Button::SmallTertiary:
- return smallSecondaryTF;
- case Button::SmallList: return (state == WidgetStateDefault) ? smallListDefaultTF
- : smallListCheckedTF;
- case Button::SmallLink: return (state == WidgetStateDefault) ? smallLinkDefaultTF
- : smallLinkHoveredTF;
- case Button::Tag: return (state == WidgetStateDefault) ? tagDefaultTF
- : tagHoverTF;
- }
- return largePrimaryTF;
-}
-
-Button::Button(const QString &text, Role role, QWidget *parent)
- : QAbstractButton(parent)
- , m_role(role)
-{
- setText(text);
- setAttribute(Qt::WA_Hover);
-
- updateMargins();
- if (m_role == SmallList)
- setCheckable(true);
- else if (m_role == SmallLink)
- setCursor(Qt::PointingHandCursor);
-}
-
-QSize Button::minimumSizeHint() const
-{
- int maxTextWidth = 0;
- for (WidgetState state : {WidgetStateDefault, WidgetStateChecked, WidgetStateHovered} ) {
- const TextFormat &tf = buttonTF(m_role, state);
- const QFontMetrics fm(tf.font());
- const QSize textS = fm.size(Qt::TextShowMnemonic, text());
- maxTextWidth = qMax(maxTextWidth, textS.width());
- }
- const TextFormat &tf = buttonTF(m_role, WidgetStateDefault);
- const QMargins margins = contentsMargins();
- return {margins.left() + maxTextWidth + margins.right(),
- margins.top() + tf.lineHeight() + margins.bottom()};
-}
-
-void Button::paintEvent(QPaintEvent *event)
-{
- // Without pixmap
- // +----------------+----------------+----------------+
- // | |(VPadding[S|XS])| |
- // | +----------------+----------------+
- // |(HPadding[S|XS])| <label> |(HPadding[S|XS])|
- // | +----------------+----------------+
- // | |(VPadding[S|XS])| |
- // +----------------+---------------------------------+
- //
- // With pixmap
- // +--------+------------+---------------------------------+
- // | | |(VPadding[S|XS])| |
- // | | +----------------+ |
- // |<pixmap>|(HGap[S|XS])| <label> |(HPadding[S|XS])|
- // | | +----------------+ |
- // | | |(VPadding[S|XS])| |
- // +--------+------------+----------------+----------------+
-
- using namespace WelcomePageHelpers;
- const bool hovered = underMouse();
- const WidgetState state = isChecked() ? WidgetStateChecked : hovered ? WidgetStateHovered
- : WidgetStateDefault;
- const TextFormat &tf = buttonTF(m_role, state);
- const QMargins margins = contentsMargins();
- const QRect bgR = rect();
-
- QPainter p(this);
-
- const qreal brRectRounding = 3.75;
- switch (m_role) {
- case LargePrimary:
- case SmallPrimary: {
- const Theme::Color color = isEnabled() ? (isDown()
- ? Theme::Token_Accent_Subtle
- : (hovered ? Theme::Token_Accent_Muted
- : Theme::Token_Accent_Default))
- : Theme::Token_Foreground_Subtle;
- const QBrush fill(creatorColor(color));
- StyleHelper::drawCardBg(&p, bgR, fill, QPen(Qt::NoPen), brRectRounding);
- break;
- }
- case LargeSecondary:
- case SmallSecondary: {
- const Theme::Color color = isEnabled() ? Theme::Token_Stroke_Strong
- : Theme::Token_Stroke_Subtle;
- const qreal width = hovered ? 2.0 : 1.0;
- const QPen outline(creatorColor(color), width);
- StyleHelper::drawCardBg(&p, bgR, QBrush(Qt::NoBrush), outline, brRectRounding);
- break;
- }
- case LargeTertiary:
- case SmallTertiary: {
- const Theme::Color border = isDown() ? Theme::Token_Stroke_Muted
- : Theme::Token_Stroke_Subtle;
- const Theme::Color bg = isEnabled() ? (isDown() ? Theme::Token_Foreground_Default
- : (hovered ? Theme::Token_Foreground_Muted
- : Theme::Token_Foreground_Subtle))
- : Theme::Token_Foreground_Subtle;
- StyleHelper::drawCardBg(&p, bgR, creatorColor(bg), creatorColor(border), brRectRounding);
- break;
- }
- case SmallList: {
- if (isChecked() || hovered) {
- const QBrush fill(creatorColor(isChecked() ? Theme::Token_Foreground_Muted
- : Theme::Token_Foreground_Subtle));
- StyleHelper::drawCardBg(&p, bgR, fill, QPen(Qt::NoPen), brRectRounding);
- }
- break;
- }
- case SmallLink:
- break;
- case Tag: {
- const QBrush fill(hovered ? creatorColor(Theme::Token_Foreground_Subtle)
- : QBrush(Qt::NoBrush));
- const QPen outline(hovered ? QPen(Qt::NoPen) : creatorColor(Theme::Token_Stroke_Subtle));
- StyleHelper::drawCardBg(&p, bgR, fill, outline, brRectRounding);
- break;
- }
- }
-
- if (!m_pixmap.isNull()) {
- const int pixmapHeight = int(m_pixmap.deviceIndependentSize().height());
- const int pixmapY = (bgR.height() - pixmapHeight) / 2;
- p.drawPixmap(0, pixmapY, m_pixmap);
- }
-
- const int availableLabelWidth = event->rect().width() - margins.left() - margins.right();
- const QFont font = tf.font();
- const QFontMetrics fm(font);
- const QString elidedLabelText = fm.elidedText(text(), Qt::ElideRight, availableLabelWidth);
- const QRect labelR(margins.left(), margins.top(), availableLabelWidth, tf.lineHeight());
- p.setFont(font);
- const QColor textColor = isEnabled() ? tf.color() : creatorColor(Theme::Token_Text_Subtle);
- p.setPen(textColor);
- p.drawText(labelR, tf.drawTextFlags, elidedLabelText);
-}
-
-void Button::setPixmap(const QPixmap &pixmap)
-{
- m_pixmap = pixmap;
- updateMargins();
-}
-
-void Button::setRole(Role role)
-{
- m_role = role;
- updateMargins();
-}
-
-void Button::updateMargins()
-{
- if (m_role == Tag) {
- setContentsMargins(HPaddingXs, VPaddingXxs, HPaddingXs, VPaddingXxs);
- return;
- }
- const bool tokenSizeS = m_role == LargePrimary || m_role == LargeSecondary
- || m_role == SmallList || m_role == SmallLink;
- const int gap = tokenSizeS ? HGapS : HGapXs;
- const int hPaddingR = tokenSizeS ? HPaddingS : HPaddingXs;
- const int hPaddingL = m_pixmap.isNull() ? hPaddingR
- : int(m_pixmap.deviceIndependentSize().width()) + gap;
- const int vPadding = tokenSizeS ? VPaddingS : VPaddingXs;
- setContentsMargins(hPaddingL, vPadding, hPaddingR, vPadding);
-}
-
-Label::Label(const QString &text, Role role, QWidget *parent)
- : QLabel(text, parent)
- , m_role(role)
-{
- using namespace WelcomePageHelpers;
- static const TextFormat primaryTF
- {Theme::Token_Text_Muted, StyleHelper::UiElement::UiElementH3};
- static const TextFormat secondaryTF
- {primaryTF.themeColor, StyleHelper::UiElement::UiElementH6Capital};
-
- const TextFormat &tF = m_role == Primary ? primaryTF : secondaryTF;
- const int vPadding = m_role == Primary ? ExPaddingGapM : VPaddingS;
-
- setFixedHeight(vPadding + tF.lineHeight() + vPadding);
- setFont(tF.font());
- QPalette pal = palette();
- pal.setColor(QPalette::Active, QPalette::WindowText, tF.color());
- pal.setColor(QPalette::Disabled, QPalette::WindowText, creatorColor(Theme::Token_Text_Subtle));
- setPalette(pal);
-}
-
-constexpr TextFormat searchBoxTextTF
- {Theme::Token_Text_Default, StyleHelper::UiElement::UiElementBody2};
-constexpr TextFormat searchBoxPlaceholderTF
- {Theme::Token_Text_Muted, searchBoxTextTF.uiElement};
-
-static const QPixmap &searchBoxIcon()
-{
- static const QPixmap icon = Icon({{FilePath::fromString(":/core/images/search.png"),
- Theme::Token_Text_Muted}}, Icon::Tint).pixmap();
- return icon;
-}
-
-SearchBox::SearchBox(QWidget *parent)
- : Utils::FancyLineEdit(parent)
-{
- setAttribute(Qt::WA_MacShowFocusRect, false);
- setAutoFillBackground(false);
- setFont(searchBoxTextTF.font());
- setFrame(false);
- setMouseTracking(true);
-
- QPalette pal = palette();
- pal.setColor(QPalette::Base, Qt::transparent);
- pal.setColor(QPalette::Active, QPalette::PlaceholderText, searchBoxPlaceholderTF.color());
- pal.setColor(QPalette::Disabled, QPalette::PlaceholderText,
- creatorColor(Theme::Token_Text_Subtle));
- pal.setColor(QPalette::Text, searchBoxTextTF.color());
- setPalette(pal);
-
- setContentsMargins({HPaddingXs, ExPaddingGapM, 0, ExPaddingGapM});
- setFixedHeight(ExPaddingGapM + searchBoxTextTF.lineHeight() + ExPaddingGapM);
- setFiltering(true);
-}
-
-QSize SearchBox::minimumSizeHint() const
-{
- const QFontMetrics fm(searchBoxTextTF.font());
- const QSize textS = fm.size(Qt::TextSingleLine, text());
- const QMargins margins = contentsMargins();
- return {margins.left() + textS.width() + margins.right(),
- margins.top() + searchBoxTextTF.lineHeight() + margins.bottom()};
-}
-
-void SearchBox::enterEvent(QEnterEvent *event)
-{
- QLineEdit::enterEvent(event);
- update();
-}
-
-void SearchBox::leaveEvent(QEvent *event)
-{
- QLineEdit::leaveEvent(event);
- update();
-}
-
-static void paintCommonBackground(QPainter *p, const QRectF &rect, const QWidget *w)
-{
- const QBrush fill(creatorColor(Theme::Token_Background_Muted));
- const Theme::Color c =
- w->isEnabled() ? (w->hasFocus() ? Theme::Token_Stroke_Strong
- : (w->underMouse() ? Theme::Token_Stroke_Muted
- : Theme::Token_Stroke_Subtle))
- : Theme::Token_Foreground_Subtle;
- const QPen pen(creatorColor(c));
- StyleHelper::drawCardBg(p, rect, fill, pen);
-}
-
-void SearchBox::paintEvent(QPaintEvent *event)
-{
- // +------------+---------------+------------+------+------------+
- // | |(ExPaddingGapM)| | | |
- // | +---------------+ | | |
- // |(HPaddingXs)| <lineEdit> |(HPaddingXs)|<icon>|(HPaddingXs)|
- // | +---------------+ | | |
- // | |(ExPaddingGapM)| | | |
- // +------------+---------------+------------+------+------------+
-
- QPainter p(this);
-
- paintCommonBackground(&p, rect(), this);
- if (text().isEmpty()) {
- const QPixmap icon = searchBoxIcon();
- const QSize iconS = icon.deviceIndependentSize().toSize();
- const QPoint iconPos(width() - HPaddingXs - iconS.width(), (height() - iconS.height()) / 2);
- if (!isEnabled())
- p.setOpacity(disabledIconOpacity);
- p.drawPixmap(iconPos, icon);
- }
-
- QLineEdit::paintEvent(event);
-}
-
-constexpr TextFormat ComboBoxTf
- {Theme::Token_Text_Muted, StyleHelper::UiElementIconActive,
- Qt::AlignLeft | Qt::AlignVCenter | Qt::TextDontClip};
-
-static const QPixmap &comboBoxIcon()
-{
- static const QPixmap icon = Icon({{FilePath::fromString(":/core/images/expandarrow.png"),
- ComboBoxTf.themeColor}}, Icon::Tint).pixmap();
- return icon;
-}
-
-ComboBox::ComboBox(QWidget *parent)
- : QComboBox(parent)
-{
- setFont(ComboBoxTf.font());
- setMouseTracking(true);
-
- const QSize iconSize = comboBoxIcon().deviceIndependentSize().toSize();
- setContentsMargins({HPaddingXs, VPaddingXs,
- HGapXxs + iconSize.width() + HPaddingXs, VPaddingXs});
-}
-
-QSize ComboBox::sizeHint() const
-{
- const QSize parentS = QComboBox::sizeHint();
- const QMargins margins = contentsMargins();
- return {margins.left() + parentS.width() + margins.right(),
- margins.top() + ComboBoxTf.lineHeight() + margins.bottom()};
-}
-
-void ComboBox::enterEvent(QEnterEvent *event)
-{
- QComboBox::enterEvent(event);
- update();
-}
-
-void ComboBox::leaveEvent(QEvent *event)
-{
- QComboBox::leaveEvent(event);
- update();
-}
-
-void ComboBox::paintEvent(QPaintEvent *)
-{
- // +------------+-------------+---------+-------+------------+
- // | | (VPaddingXs)| | | |
- // | +-------------+ | | |
- // |(HPaddingXs)|<currentItem>|(HGapXxs)|<arrow>|(HPaddingXs)|
- // | +-------------+ | | |
- // | | (VPaddingXs)| | | |
- // +------------+-------------+---------+-------+------------+
-
- QPainter p(this);
- paintCommonBackground(&p, rect(), this);
-
- const QMargins margins = contentsMargins();
- const QRect textR(margins.left(), margins.top(),
- width() - margins.right(), ComboBoxTf.lineHeight());
- p.setFont(ComboBoxTf.font());
- const QColor color = isEnabled() ? ComboBoxTf.color() : creatorColor(Theme::Token_Text_Subtle);
- p.setPen(color);
- p.drawText(textR, ComboBoxTf.drawTextFlags, currentText());
-
- const QPixmap icon = comboBoxIcon();
- const QSize iconS = icon.deviceIndependentSize().toSize();
- const QPoint iconPos(width() - HPaddingXs - iconS.width(), (height() - iconS.height()) / 2);
- if (!isEnabled())
- p.setOpacity(disabledIconOpacity);
- p.drawPixmap(iconPos, icon);
-}
-
-constexpr TextFormat SwitchLabelTf
- {Theme::Token_Text_Default, StyleHelper::UiElementLabelMedium};
-constexpr QSize switchTrackS(32, 16);
-
-Switch::Switch(const QString &text, QWidget *parent)
- : QAbstractButton(parent)
-{
- setText(text);
- setCheckable(true);
- setAttribute(Qt::WA_Hover);
- setLayoutDirection(Qt::RightToLeft); // Switch right, label left
-}
-
-QSize Switch::sizeHint() const
-{
- const QFontMetrics fm(SwitchLabelTf.font());
- const int textWidth = fm.size(Qt::TextShowMnemonic, text()).width();
- const int width = switchTrackS.width() + HGapS + textWidth;
- return {width, ExPaddingGapM + SwitchLabelTf.lineHeight() + ExPaddingGapM};
-}
-
-QSize Switch::minimumSizeHint() const
-{
- return switchTrackS;
-}
-
-void Switch::paintEvent([[maybe_unused]] QPaintEvent *event)
-{
- const bool ltr = layoutDirection() == Qt::LeftToRight;
- const int trackX = ltr ? 0 : width() - switchTrackS.width();
- const int trackY = (height() - switchTrackS.height()) / 2;
- const QRect trackR(QPoint(trackX, trackY), switchTrackS);
- const int trackRounding = trackR.height() / 2;
- const bool checkedEnabled = isChecked() && isEnabled();
- QPainter p(this);
-
- { // track
- const bool hovered = underMouse();
- const QBrush fill = creatorColor(checkedEnabled ? (hovered ? Theme::Token_Accent_Subtle
- : Theme::Token_Accent_Default)
- : Theme::Token_Foreground_Subtle);
- const QPen outline = checkedEnabled ? QPen(Qt::NoPen)
- : creatorColor(hovered ? Theme::Token_Stroke_Muted
- : Theme::Token_Stroke_Subtle);
- StyleHelper::drawCardBg(&p, trackR, fill, outline, trackRounding);
- }
- { // track label
- const QColor color = creatorColor(isEnabled() ? (isChecked() ? Theme::Token_Basic_White
- : Theme::Token_Text_Muted)
- : Theme::Token_Text_Subtle);
- const int labelS = 6;
- const int labelY = (height() - labelS) / 2;
- if (isChecked()) {
- const QRect onLabelR(trackX + 8, labelY, 1, labelS);
- p.fillRect(onLabelR, color);
- } else {
- const QRect offLabelR(trackX + switchTrackS.width() - trackRounding - labelS / 2 - 1,
- labelY, labelS, labelS);
- StyleHelper::drawCardBg(&p, offLabelR, Qt::NoBrush, color, labelS / 2);
- }
- }
- { // knob
- const int thumbPadding = checkedEnabled ? 3 : 2;
- const int thumbH = switchTrackS.height() - thumbPadding - thumbPadding;
- const int thumbW = isDown() ? (checkedEnabled ? 17 : 19)
- : thumbH;
- const int thumbRounding = thumbH / 2;
- const int thumbX = trackX + (isChecked() ? switchTrackS.width() - thumbW - thumbPadding
- : thumbPadding);
- const QRect thumbR(thumbX, trackY + thumbPadding, thumbW, thumbH);
- const QBrush fill = creatorColor(isEnabled() ? Theme::Token_Basic_White
- : Theme::Token_Foreground_Default);
- const QPen outline = checkedEnabled ? QPen(Qt::NoPen)
- : creatorColor(Theme::Token_Stroke_Subtle);
- StyleHelper::drawCardBg(&p, thumbR, fill, outline, thumbRounding);
- }
- { // switch text label
- const int switchAndGapWidth = switchTrackS.width() + HGapS;
- const QRect textR(ltr ? switchAndGapWidth : 0, 0, width() - switchAndGapWidth,
- trackY + switchTrackS.height());
- p.setFont(SwitchLabelTf.font());
- p.setPen(isEnabled() ? SwitchLabelTf.color() : creatorColor(Theme::Token_Text_Subtle));
- const QString elidedLabel =
- p.fontMetrics().elidedText(text(), Qt::ElideRight, textR.width());
- p.drawText(textR, SwitchLabelTf.drawTextFlags, elidedLabel);
- }
-}
-
GridView::GridView(QWidget *parent)
: QListView(parent)
{
@@ -1450,32 +955,4 @@ void ResizeSignallingWidget::resizeEvent(QResizeEvent *event)
emit resized(event->size(), event->oldSize());
}
-// CoreButton
-
-CoreButton::CoreButton()
-{
- ptr = new Implementation("", Core::Button::LargePrimary, nullptr);
-}
-
-CoreButton::CoreButton(std::initializer_list<I> ps)
-{
- ptr = new Implementation("", Core::Button::LargePrimary, nullptr);
- Layouting::Tools::apply(this, ps);
-}
-
-void CoreButton::setText(const QString &text)
-{
- Layouting::Tools::access(this)->setText(text);
-}
-
-void CoreButton::setIcon(const Icon &icon)
-{
- Layouting::Tools::access(this)->setPixmap(icon.pixmap());
-}
-
-void CoreButton::setRole(Button::Role role)
-{
- Layouting::Tools::access(this)->setRole(role);
-}
-
} // namespace Core
diff --git a/src/plugins/coreplugin/welcomepagehelper.h b/src/plugins/coreplugin/welcomepagehelper.h
index 45f0ed74941..d3846e787dc 100644
--- a/src/plugins/coreplugin/welcomepagehelper.h
+++ b/src/plugins/coreplugin/welcomepagehelper.h
@@ -33,146 +33,15 @@ namespace WelcomePageHelpers {
constexpr QSize WelcomeThumbnailSize(214, 160);
-class CORE_EXPORT TextFormat
-{
-public:
- QColor color() const
- {
- return Utils::creatorColor(themeColor);
- }
-
- QFont font(bool underlined = false) const
- {
- QFont result = Utils::StyleHelper::uiFont(uiElement);
- result.setUnderline(underlined);
- return result;
- }
-
- int lineHeight() const
- {
- return Utils::StyleHelper::uiFontLineHeight(uiElement);
- }
-
- const Utils::Theme::Color themeColor;
- const Utils::StyleHelper::UiElement uiElement;
- const int drawTextFlags = Qt::AlignLeft | Qt::AlignBottom | Qt::TextDontClip
- | Qt::TextShowMnemonic;
-};
-
CORE_EXPORT void setBackgroundColor(QWidget *widget, Utils::Theme::Color colorRole);
constexpr Utils::Theme::Color cardDefaultBackground = Utils::Theme::Token_Background_Muted;
constexpr Utils::Theme::Color cardDefaultStroke = Utils::Theme::Token_Stroke_Subtle;
constexpr Utils::Theme::Color cardHoverBackground = Utils::Theme::Token_Background_Subtle;
constexpr Utils::Theme::Color cardHoverStroke = cardDefaultStroke;
CORE_EXPORT QWidget *createRule(Qt::Orientation orientation, QWidget *parent = nullptr);
-CORE_EXPORT void applyTf(QLabel *label, const TextFormat &tf, bool singleLine = true);
} // namespace WelcomePageHelpers
-class CORE_EXPORT Button : public QAbstractButton
-{
- Q_OBJECT
-public:
- enum Role {
- LargePrimary,
- LargeSecondary,
- LargeTertiary,
- SmallPrimary,
- SmallSecondary,
- SmallTertiary,
- SmallList,
- SmallLink,
- Tag,
- };
- Q_ENUM(Role)
-
- explicit Button(const QString &text, Role role, QWidget *parent = nullptr);
-
- QSize minimumSizeHint() const override;
-
- void setPixmap(const QPixmap &newPixmap);
- void setRole(Role role);
-
-protected:
- void paintEvent(QPaintEvent *event) override;
-
-private:
- void updateMargins();
-
- Role m_role = LargePrimary;
- QPixmap m_pixmap;
-};
-
-class CORE_EXPORT CoreButton : public Layouting::Widget
-{
-public:
- using Implementation = Core::Button;
- using I = Building::BuilderItem<CoreButton>;
-
- CoreButton();
- CoreButton(std::initializer_list<I> ps);
-
- void setText(const QString &text);
- void setIcon(const Utils::Icon &icon);
- void setRole(Core::Button::Role role);
-};
-
-QTC_DEFINE_BUILDER_SETTER(role, setRole);
-
-class CORE_EXPORT Label : public QLabel
-{
-public:
- enum Role {
- Primary,
- Secondary,
- };
-
- explicit Label(const QString &text, Role role, QWidget *parent = nullptr);
-
-private:
- const Role m_role = Primary;
-};
-
-class CORE_EXPORT SearchBox : public Utils::FancyLineEdit
-{
-public:
- explicit SearchBox(QWidget *parent = nullptr);
-
- QSize minimumSizeHint() const override;
-
-protected:
- void paintEvent(QPaintEvent *event) override;
- void enterEvent(QEnterEvent *event) override;
- void leaveEvent(QEvent *event) override;
-};
-
-class CORE_EXPORT ComboBox : public QComboBox
-{
-public:
- explicit ComboBox(QWidget *parent = nullptr);
-
- QSize sizeHint() const override;
-
-protected:
- void paintEvent(QPaintEvent *event) override;
-
-protected:
- void enterEvent(QEnterEvent *event) override;
- void leaveEvent(QEvent *event) override;
-};
-
-class CORE_EXPORT Switch : public QAbstractButton
-{
-public:
- explicit Switch(const QString &text, QWidget *parent = nullptr);
-
- QSize sizeHint() const override;
- QSize minimumSizeHint() const override;
-
-protected:
- void paintEvent(QPaintEvent *event) override;
-};
-
class CORE_EXPORT GridView : public QListView
{
public:
diff --git a/src/plugins/extensionmanager/extensionmanagerwidget.cpp b/src/plugins/extensionmanager/extensionmanagerwidget.cpp
index 3bb27e68f2e..26d43a6ab5c 100644
--- a/src/plugins/extensionmanager/extensionmanagerwidget.cpp
+++ b/src/plugins/extensionmanager/extensionmanagerwidget.cpp
@@ -38,6 +38,7 @@
#include <utils/mimeutils.h>
#include <utils/networkaccessmanager.h>
#include <utils/progressdialog.h>
+#include <utils/qtcwidgets.h>
#include <utils/stringutils.h>
#include <utils/styledbar.h>
#include <utils/stylehelper.h>
@@ -57,7 +58,6 @@
using namespace Core;
using namespace Utils;
using namespace StyleHelper;
-using namespace WelcomePageHelpers;
using namespace ExtensionSystem;
namespace ExtensionManager::Internal {
@@ -248,7 +248,7 @@ public:
m_title = new ElidingLabel;
applyTf(m_title, titleTF);
- m_vendor = new Button({}, Button::SmallLink);
+ m_vendor = new QtcButton({}, QtcButton::SmallLink);
m_vendor->setContentsMargins({});
m_divider = new QLabel;
m_divider->setFixedSize(1, dividerH);
@@ -262,7 +262,7 @@ public:
m_dlCount->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
m_details = new ElidingLabel;
applyTf(m_details, detailsTF);
- installButton = new Button(Tr::tr("Install..."), Button::LargePrimary);
+ installButton = new QtcButton(Tr::tr("Install..."), QtcButton::LargePrimary);
installButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
installButton->hide();
connect(
@@ -271,7 +271,7 @@ public:
this,
&HeadingWidget::pluginInstallationRequested);
- removeButton = new Button(Tr::tr("Remove..."), Button::SmallSecondary);
+ removeButton = new QtcButton(Tr::tr("Remove..."), QtcButton::SmallSecondary);
removeButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
removeButton->hide();
connect(removeButton, &QAbstractButton::pressed, this, [this]() {
@@ -279,7 +279,7 @@ public:
requestRestart();
});
- updateButton = new Button(Tr::tr("Update..."), Button::LargePrimary);
+ updateButton = new QtcButton(Tr::tr("Update..."), QtcButton::LargePrimary);
updateButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
updateButton->hide();
connect(updateButton, &QAbstractButton::pressed, this, &HeadingWidget::pluginUpdateRequested);
@@ -427,7 +427,7 @@ signals:
private:
QLabel *m_icon;
QLabel *m_title;
- Button *m_vendor;
+ QtcButton *m_vendor;
QLabel *m_divider;
QLabel *m_dlIcon;
QLabel *m_dlCount;
@@ -449,7 +449,7 @@ public:
{
m_label = new InfoLabel;
m_label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
- m_switch = new Switch(Tr::tr("Active"));
+ m_switch = new QtcSwitch(Tr::tr("Active"));
m_pluginView.hide();
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
@@ -516,7 +516,7 @@ private:
}
InfoLabel *m_label;
- Switch *m_switch;
+ QtcSwitch *m_switch;
QString m_pluginId;
PluginView m_pluginView{this};
};
@@ -535,7 +535,7 @@ public:
if (!tags.empty()) {
const auto tagToButton = [this](const QString &tag) {
- auto btn = new Button(tag, Button::Tag);
+ auto btn = new QtcButton(tag, QtcButton::Tag);
connect(btn, &QAbstractButton::clicked, [tag, this] { emit tagSelected(tag); });
return btn;
};
diff --git a/src/plugins/extensionmanager/extensionsbrowser.cpp b/src/plugins/extensionmanager/extensionsbrowser.cpp
index f81b3e9ea23..fd63c3a131c 100644
--- a/src/plugins/extensionmanager/extensionsbrowser.cpp
+++ b/src/plugins/extensionmanager/extensionsbrowser.cpp
@@ -35,6 +35,7 @@
#include <utils/layoutbuilder.h>
#include <utils/networkaccessmanager.h>
#include <utils/qtcprocess.h>
+#include <utils/qtcwidgets.h>
#include <utils/stylehelper.h>
#include <utils/unarchiver.h>
#include <utils/utilsicons.h>
@@ -541,14 +542,14 @@ ExtensionsBrowser::ExtensionsBrowser(ExtensionsModel *model, QWidget *parent)
auto titleLabel = new ElidingLabel(Tr::tr("Manage Extensions"));
applyTf(titleLabel, titleTF);
- auto externalRepoSwitch = new Switch("Use external repository");
+ auto externalRepoSwitch = new QtcSwitch("Use external repository");
externalRepoSwitch->setEnabled(settings().useExternalRepo.isEnabled());
if (settings().useExternalRepo.isEnabled())
externalRepoSwitch->setToolTip("<html>" + externalRepoWarningNote());
else
externalRepoSwitch->setToolTip(settings().useExternalRepo.toolTip());
- d->searchBox = new SearchBox;
+ d->searchBox = new QtcSearchBox;
d->searchBox->setPlaceholderText(Tr::tr("Search"));
d->searchProxyModel = new QSortFilterProxyModel(this);
diff --git a/src/plugins/extensionmanager/extensionsbrowser.h b/src/plugins/extensionmanager/extensionsbrowser.h
index ff3dacac7b8..03f89ecf653 100644
--- a/src/plugins/extensionmanager/extensionsbrowser.h
+++ b/src/plugins/extensionmanager/extensionsbrowser.h
@@ -7,10 +7,6 @@
QT_FORWARD_DECLARE_CLASS(QLabel)
-namespace Core::WelcomePageHelpers {
-class TextFormat;
-}
-
namespace ExtensionManager::Internal {
class ExtensionsModel;
diff --git a/src/plugins/learning/qtacademywelcomepage.cpp b/src/plugins/learning/qtacademywelcomepage.cpp
index d3551341676..ab6f63e70c0 100644
--- a/src/plugins/learning/qtacademywelcomepage.cpp
+++ b/src/plugins/learning/qtacademywelcomepage.cpp
@@ -15,6 +15,7 @@
#include <utils/fileutils.h>
#include <utils/layoutbuilder.h>
#include <utils/networkaccessmanager.h>
+#include <utils/qtcwidgets.h>
#include <QApplication>
#include <QDesktopServices>
@@ -114,7 +115,7 @@ class QtAcademyWelcomePageWidget final : public QWidget
public:
QtAcademyWelcomePageWidget()
{
- m_searcher = new SearchBox(this);
+ m_searcher = new QtcSearchBox(this);
m_searcher->setPlaceholderText(Tr::tr("Search in Qt Academy Courses..."));
m_model = new ListModel;
diff --git a/src/plugins/lua/bindings/gui.cpp b/src/plugins/lua/bindings/gui.cpp
index 6f191ae068f..0a043b5fe45 100644
--- a/src/plugins/lua/bindings/gui.cpp
+++ b/src/plugins/lua/bindings/gui.cpp
@@ -6,11 +6,10 @@
#include "inheritance.h"
#include "utils.h"
-#include <coreplugin/welcomepagehelper.h>
-
#include <utils/aspects.h>
#include <utils/filepath.h>
#include <utils/layoutbuilder.h>
+#include <utils/qtcwidgets.h>
#include <QMetaEnum>
#include <QCompleter>
@@ -140,7 +139,7 @@ CREATE_HAS_FUNC(setCursor, Qt::CursorShape())
CREATE_HAS_FUNC(setMinimumWidth, int());
CREATE_HAS_FUNC(setEnableCodeCopyButton, bool());
CREATE_HAS_FUNC(setDefaultAction, nullptr);
-CREATE_HAS_FUNC(setRole, Core::Button::Role());
+CREATE_HAS_FUNC(setRole, QtcButton::Role());
template<class T>
void setProperties(std::unique_ptr<T> &item, const sol::table &children, QObject *guard)
@@ -377,7 +376,7 @@ void setProperties(std::unique_ptr<T> &item, const sol::table &children, QObject
item->setOpenExternalLinks(*openExternalLinks);
}
if constexpr (has_setRole<T>) {
- sol::optional<Core::Button::Role> role = children.get<sol::optional<Core::Button::Role>>(
+ sol::optional<QtcButton::Role> role = children.get<sol::optional<QtcButton::Role>>(
"role"sv);
if (role)
item->setRole(*role);
@@ -580,18 +579,18 @@ void setupGuiModule()
sol::base_classes,
sol::bases<Widget, Object, Thing>());
- gui.new_usertype<Core::CoreButton>(
- "CoreButton",
+ gui.new_usertype<Utils::QtcWidgets::Button>(
+ "QtcButton",
sol::call_constructor,
sol::factories([](const sol::table &children) {
- return constructWidgetType<Core::CoreButton>(children, nullptr);
+ return constructWidgetType<Utils::QtcWidgets::Button>(children, nullptr);
}),
"setText",
- &Core::CoreButton::setText,
+ &Utils::QtcWidgets::Button::setText,
"setIcon",
- &Core::CoreButton::setIcon,
+ &Utils::QtcWidgets::Button::setIcon,
"setRole",
- &Core::CoreButton::setRole,
+ &Utils::QtcWidgets::Button::setRole,
sol::base_classes,
sol::bases<Widget, Object, Thing>());
@@ -646,7 +645,7 @@ void setupGuiModule()
mirrorEnum(gui, QMetaEnum::fromType<Qt::TextFormat>());
mirrorEnum(gui, QMetaEnum::fromType<Qt::TextInteractionFlag>());
mirrorEnum(gui, QMetaEnum::fromType<Qt::CursorShape>());
- mirrorEnum(gui, QMetaEnum::fromType<Core::Button::Role>());
+ mirrorEnum(gui, QMetaEnum::fromType<QtcButton::Role>());
auto sizePolicy = gui.create_named("QSizePolicy");
mirrorEnum(sizePolicy, QMetaEnum::fromType<QSizePolicy::Policy>());
diff --git a/src/plugins/projectexplorer/projectwelcomepage.cpp b/src/plugins/projectexplorer/projectwelcomepage.cpp
index 959bf3d5f06..3de1e0eff32 100644
--- a/src/plugins/projectexplorer/projectwelcomepage.cpp
+++ b/src/plugins/projectexplorer/projectwelcomepage.cpp
@@ -26,6 +26,7 @@
#include <utils/layoutbuilder.h>
#include <utils/persistentsettings.h>
#include <utils/qtcassert.h>
+#include <utils/qtcwidgets.h>
#include <utils/stringutils.h>
#include <utils/stylehelper.h>
#include <utils/theme/theme.h>
@@ -341,9 +342,9 @@ public:
m_sessionType->setSizePolicy(m_sessionNameLabel->sizePolicy());
m_sessionType->setTextInteractionFlags(Qt::NoTextInteraction);
- m_clone = new Button(Tr::tr("Clone"), Button::SmallTertiary);
- m_rename = new Button(Tr::tr("Rename"), Button::SmallTertiary);
- m_delete = new Button(Tr::tr("Delete"), Button::SmallTertiary);
+ m_clone = new QtcButton(Tr::tr("Clone"), QtcButton::SmallTertiary);
+ m_rename = new QtcButton(Tr::tr("Rename"), QtcButton::SmallTertiary);
+ m_delete = new QtcButton(Tr::tr("Delete"), QtcButton::SmallTertiary);
auto buttonGroup = new QButtonGroup;
buttonGroup->addButton(m_clone, ActionClone);
@@ -728,8 +729,9 @@ public:
auto sessions = new QWidget;
{
- auto sessionsLabel = new Core::Label(Tr::tr("Sessions"), Core::Label::Primary);
- auto manageSessionsButton = new Button(Tr::tr("Manage..."), Button::LargeSecondary);
+ auto sessionsLabel = new QtcLabel(Tr::tr("Sessions"), QtcLabel::Primary);
+ auto manageSessionsButton = new QtcButton(Tr::tr("Manage..."),
+ QtcButton::LargeSecondary);
m_sessionList = new TreeView(this, "Sessions");
m_sessionList->setModel(m_projectWelcomePage->m_sessionModel);
m_sessionList->header()->setSectionHidden(1, true); // The "last modified" column.
@@ -748,7 +750,7 @@ public:
spacing(ExPaddingGapL),
customMargins(ExVPaddingGapXl, ExVPaddingGapXl, 0, 0),
}.attachTo(sessions);
- connect(manageSessionsButton, &Button::clicked,
+ connect(manageSessionsButton, &QtcButton::clicked,
this, &SessionManager::showSessionManager);
connect(m_projectWelcomePage->m_sessionModel, &QAbstractItemModel::modelReset,
this, &SessionsPage::syncModelView);
@@ -756,7 +758,7 @@ public:
auto projects = new QWidget;
{
- auto projectsLabel = new Core::Label(Tr::tr("Projects"), Core::Label::Primary);
+ auto projectsLabel = new QtcLabel(Tr::tr("Projects"), QtcLabel::Primary);
auto projectsList = new TreeView(this, "Recent Projects");
projectsList->setUniformRowHeights(true);
projectsList->setModel(projectWelcomePage->m_projectModel);
diff --git a/src/plugins/qtsupport/gettingstartedwelcomepage.cpp b/src/plugins/qtsupport/gettingstartedwelcomepage.cpp
index 9b6a017a702..e58635a38c5 100644
--- a/src/plugins/qtsupport/gettingstartedwelcomepage.cpp
+++ b/src/plugins/qtsupport/gettingstartedwelcomepage.cpp
@@ -24,6 +24,7 @@
#include <utils/layoutbuilder.h>
#include <utils/pathchooser.h>
#include <utils/qtcassert.h>
+#include <utils/qtcwidgets.h>
#include <utils/shutdownguard.h>
#include <utils/stylehelper.h>
#include <utils/theme/theme.h>
@@ -277,18 +278,17 @@ public:
m_exampleDelegate.setShowExamples(isExamples);
using namespace StyleHelper::SpacingTokens;
-
using namespace Layouting;
Row titleRow {
customMargins(0, 0, ExVPaddingGapXl, 0),
spacing(ExVPaddingGapXl),
};
- m_searcher = new SearchBox;
+ m_searcher = new QtcSearchBox;
if (m_isExamples) {
m_searcher->setPlaceholderText(Tr::tr("Search in Examples..."));
- auto exampleSetSelector = new ComboBox;
+ auto exampleSetSelector = new QtcComboBox;
exampleSetSelector->setSizeAdjustPolicy(QComboBox::AdjustToContents);
exampleSetSelector->setMinimumWidth(ListItemDelegate::itemSize().width()
- ExVPaddingGapXl);
diff --git a/src/plugins/welcome/welcomeplugin.cpp b/src/plugins/welcome/welcomeplugin.cpp
index e0ad1df51ea..4083ca37b03 100644
--- a/src/plugins/welcome/welcomeplugin.cpp
+++ b/src/plugins/welcome/welcomeplugin.cpp
@@ -26,6 +26,7 @@
#include <utils/icon.h>
#include <utils/layoutbuilder.h>
#include <utils/qtcassert.h>
+#include <utils/qtcwidgets.h>
#include <utils/styledbar.h>
#include <utils/stylehelper.h>
#include <utils/theme/theme.h>
@@ -85,8 +86,8 @@ public:
m_pluginButtons->setSpacing(VGapL);
m_pluginButtons->setContentsMargins({});
- auto newButton = new Button(Tr::tr("Create Project..."), Button::LargePrimary);
- auto openButton = new Button(Tr::tr("Open Project..."), Button::LargeSecondary);
+ auto newButton = new QtcButton(Tr::tr("Create Project..."), QtcButton::LargePrimary);
+ auto openButton = new QtcButton(Tr::tr("Open Project..."), QtcButton::LargeSecondary);
using namespace Layouting;
Column {
@@ -105,11 +106,11 @@ public:
noMargin, spacing(0),
}.attachTo(this);
- connect(openButton, &Button::clicked, this, [] {
+ connect(openButton, &QtcButton::clicked, this, [] {
QAction *openAction = ActionManager::command(Core::Constants::OPEN)->action();
openAction->trigger();
});
- connect(newButton, &Button::clicked, this, [] {
+ connect(newButton, &QtcButton::clicked, this, [] {
QAction *openAction = ActionManager::command(Core::Constants::NEW)->action();
openAction->trigger();
});
@@ -189,7 +190,7 @@ public:
if (m_pluginList.at(idx)->priority() >= pagePriority)
break;
}
- auto pageButton = new Button(page->title(), Button::SmallList, m_topArea);
+ auto pageButton = new QtcButton(page->title(), QtcButton::SmallList, m_topArea);
auto pageId = page->id();
pageButton->setText(page->title());
@@ -216,7 +217,7 @@ public:
m_pageStack->setCurrentWidget(stackPage);
};
- connect(pageButton, &Button::clicked, this, onClicked);
+ connect(pageButton, &QtcButton::clicked, this, onClicked);
if (pageId == m_activePage) {
onClicked();
pageButton->setChecked(true);
diff --git a/tests/manual/widgets/components/tst_manual_widgets_components.cpp b/tests/manual/widgets/components/tst_manual_widgets_components.cpp
index 8cf6b4d742b..2c0ec9dd250 100644
--- a/tests/manual/widgets/components/tst_manual_widgets_components.cpp
+++ b/tests/manual/widgets/components/tst_manual_widgets_components.cpp
@@ -6,59 +6,60 @@
#include <QApplication>
#include <utils/layoutbuilder.h>
-
-#include <coreplugin/welcomepagehelper.h>
+#include <utils/qtcwidgets.h>
QWidget *widgets()
{
+ using namespace Utils;
+
auto widget = new QWidget;
- auto comboBox = new Core::ComboBox;
+ auto comboBox = new QtcComboBox;
const QStringList content = QColor::colorNames();
comboBox->addItems(content.first(8));
- auto switchOn = new Core::Switch("Qt::RightToLeft");
+ auto switchOn = new QtcSwitch("Qt::RightToLeft");
switchOn->setChecked(true);
- auto switchOff = new Core::Switch("Qt::LeftToRight");
+ auto switchOff = new QtcSwitch("Qt::LeftToRight");
switchOff->setLayoutDirection(Qt::LeftToRight);
using namespace Layouting;
Column {
Group {
- title("Core::Button"),
+ title("Button"),
Column {
- new Core::Button("LargePrimary", Core::Button::LargePrimary),
- new Core::Button("LargeSecondary", Core::Button::LargeSecondary),
- new Core::Button("LargeTertiary", Core::Button::LargeTertiary),
- new Core::Button("SmallPrimary", Core::Button::SmallPrimary),
- new Core::Button("SmallSecondary", Core::Button::SmallSecondary),
- new Core::Button("SmallTertiary", Core::Button::SmallTertiary),
- new Core::Button("SmallList", Core::Button::SmallList),
- new Core::Button("SmallLink", Core::Button::SmallLink),
- new Core::Button("Tag", Core::Button::Tag),
+ new QtcButton("LargePrimary", QtcButton::LargePrimary),
+ new QtcButton("LargeSecondary", QtcButton::LargeSecondary),
+ new QtcButton("LargeTertiary", QtcButton::LargeTertiary),
+ new QtcButton("SmallPrimary", QtcButton::SmallPrimary),
+ new QtcButton("SmallSecondary", QtcButton::SmallSecondary),
+ new QtcButton("SmallTertiary", QtcButton::SmallTertiary),
+ new QtcButton("SmallList", QtcButton::SmallList),
+ new QtcButton("SmallLink", QtcButton::SmallLink),
+ new QtcButton("Tag", QtcButton::Tag),
},
},
Group {
- title("Core::Label"),
+ title("Label"),
Column {
- new Core::Label("Primary", Core::Label::Primary),
- new Core::Label("Secondary", Core::Label::Secondary),
+ new QtcLabel("Primary", QtcLabel::Primary),
+ new QtcLabel("Secondary", QtcLabel::Secondary),
},
},
Group {
- title("Core::SearchBox"),
+ title("SearchBox"),
Column {
- new Core::SearchBox,
+ new QtcSearchBox,
},
},
Group {
- title("Core::ComboBox"),
+ title("ComboBox"),
Column {
comboBox,
},
},
Group {
- title("Core::Switch"),
+ title("Switch"),
Column {
switchOn,
switchOff,
diff --git a/tests/manual/widgets/layoutbuilder/tst_manual_widgets_layoutbuilder.cpp b/tests/manual/widgets/layoutbuilder/tst_manual_widgets_layoutbuilder.cpp
index e2c89dc7d05..40e4cb1546e 100644
--- a/tests/manual/widgets/layoutbuilder/tst_manual_widgets_layoutbuilder.cpp
+++ b/tests/manual/widgets/layoutbuilder/tst_manual_widgets_layoutbuilder.cpp
@@ -4,6 +4,7 @@
#include "../common/themeselector.h"
#include <utils/layoutbuilder.h>
+#include <utils/qtcwidgets.h>
#include <utils/theme/theme.h>
#include <utils/theme/theme_p.h>
@@ -16,7 +17,7 @@
#include <QToolButton>
using namespace Layouting;
-using CoreButton = Core::CoreButton;
+using QtcButton = Utils::QtcWidgets::Button;
int main(int argc, char *argv[])
{
@@ -106,41 +107,41 @@ int main(int argc, char *argv[])
Label { text("Core Button:") },
new ManualTest::ThemeSelector,
Flow {
- CoreButton {
+ QtcButton {
text("Large Primary"),
- role(Core::Button::Role::LargePrimary)
+ role(Utils::QtcButton::Role::LargePrimary)
},
- CoreButton {
+ QtcButton {
text("Large Secondary"),
- role(Core::Button::Role::LargeSecondary)
+ role(Utils::QtcButton::Role::LargeSecondary)
},
- CoreButton {
+ QtcButton {
text("Large Tertiary"),
- role(Core::Button::Role::LargeTertiary)
+ role(Utils::QtcButton::Role::LargeTertiary)
},
- CoreButton {
+ QtcButton {
text("Small Primary"),
- role(Core::Button::Role::SmallPrimary)
+ role(Utils::QtcButton::Role::SmallPrimary)
},
- CoreButton {
+ QtcButton {
text("Small Secondary"),
- role(Core::Button::Role::SmallSecondary)
+ role(Utils::QtcButton::Role::SmallSecondary)
},
- CoreButton {
+ QtcButton {
text("Small Tertiary"),
- role(Core::Button::Role::SmallTertiary)
+ role(Utils::QtcButton::Role::SmallTertiary)
},
- CoreButton {
+ QtcButton {
text("Small List"),
- role(Core::Button::Role::SmallList)
+ role(Utils::QtcButton::Role::SmallList)
},
- CoreButton {
+ QtcButton {
text("Small Link"),
- role(Core::Button::Role::SmallLink)
+ role(Utils::QtcButton::Role::SmallLink)
},
- CoreButton {
+ QtcButton {
text("Tag"),
- role(Core::Button::Role::Tag)
+ role(Utils::QtcButton::Role::Tag)
},
},
st