Examples: Use theme colors for section separator + link

Change-Id: Ia5706dd81c0494f0a7c1a1df346918462b52ba53
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Alessandro Portale
2023-04-26 09:35:52 +02:00
parent 66c0c36bc1
commit c192536b64

View File

@@ -749,9 +749,21 @@ static QWidget *createSeparator(QWidget *parent)
QSizePolicy linePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored); QSizePolicy linePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
linePolicy.setHorizontalStretch(2); linePolicy.setHorizontalStretch(2);
line->setSizePolicy(linePolicy); line->setSizePolicy(linePolicy);
QPalette pal = line->palette();
pal.setColor(QPalette::Dark, Qt::transparent);
pal.setColor(QPalette::Light, themeColor(Theme::Welcome_ForegroundSecondaryColor));
line->setPalette(pal);
return line; return line;
} }
static QLabel *createLinkLabel(const QString &text, QWidget *parent)
{
const QString linkColor = themeColor(Theme::Welcome_LinkColor).name();
auto link = new QLabel("<a href=\"link\" style=\"color: " + linkColor + ";\">"
+ text + "</a>", parent);
return link;
}
ListModel *SectionedGridView::addSection(const Section &section, const QList<ListItem *> &items) ListModel *SectionedGridView::addSection(const Section &section, const QList<ListItem *> &items)
{ {
auto model = new ListModel(this); auto model = new ListModel(this);
@@ -772,8 +784,7 @@ ListModel *SectionedGridView::addSection(const Section &section, const QList<Lis
m_sectionModels.insert(section, model); m_sectionModels.insert(section, model);
const auto it = m_gridViews.insert(section, gridView); const auto it = m_gridViews.insert(section, gridView);
using namespace Layouting; QLabel *seeAllLink = createLinkLabel(Tr::tr("Show All") + " &gt;", this);
auto seeAllLink = new QLabel("<a href=\"link\">" + Tr::tr("Show All") + " &gt;</a>", this);
if (gridView->maxRows().has_value()) { if (gridView->maxRows().has_value()) {
seeAllLink->setVisible(true); seeAllLink->setVisible(true);
connect(gridView, &SectionGridView::itemsFitChanged, seeAllLink, [seeAllLink](bool fits) { connect(gridView, &SectionGridView::itemsFitChanged, seeAllLink, [seeAllLink](bool fits) {
@@ -783,6 +794,7 @@ ListModel *SectionedGridView::addSection(const Section &section, const QList<Lis
seeAllLink->setVisible(false); seeAllLink->setVisible(false);
} }
connect(seeAllLink, &QLabel::linkActivated, this, [this, section] { zoomInSection(section); }); connect(seeAllLink, &QLabel::linkActivated, this, [this, section] { zoomInSection(section); });
using namespace Layouting;
QWidget *sectionLabel = Row{section.name, createSeparator(this), seeAllLink, Space(HSpacing)} QWidget *sectionLabel = Row{section.name, createSeparator(this), seeAllLink, Space(HSpacing)}
.emerge(Layouting::WithoutMargins); .emerge(Layouting::WithoutMargins);
m_sectionLabels.append(sectionLabel); m_sectionLabels.append(sectionLabel);
@@ -829,13 +841,13 @@ void SectionedGridView::zoomInSection(const Section &section)
layout->setContentsMargins(0, 0, 0, 0); layout->setContentsMargins(0, 0, 0, 0);
zoomedInWidget->setLayout(layout); zoomedInWidget->setLayout(layout);
using namespace Layouting; QLabel *backLink = createLinkLabel("&lt; " + Tr::tr("Back"), this);
auto backLink = new QLabel("<a href=\"link\">&lt; " + Tr::tr("Back") + "</a>", zoomedInWidget);
connect(backLink, &QLabel::linkActivated, this, [this, zoomedInWidget] { connect(backLink, &QLabel::linkActivated, this, [this, zoomedInWidget] {
removeWidget(zoomedInWidget); removeWidget(zoomedInWidget);
delete zoomedInWidget; delete zoomedInWidget;
setCurrentIndex(0); setCurrentIndex(0);
}); });
using namespace Layouting;
QWidget *sectionLabel = Row{section.name, createSeparator(this), backLink, Space(HSpacing)} QWidget *sectionLabel = Row{section.name, createSeparator(this), backLink, Space(HSpacing)}
.emerge(Layouting::WithoutMargins); .emerge(Layouting::WithoutMargins);
sectionLabel->setContentsMargins(0, ItemGap, 0, 0); sectionLabel->setContentsMargins(0, ItemGap, 0, 0);