diff --git a/src/plugins/coreplugin/welcomepagehelper.cpp b/src/plugins/coreplugin/welcomepagehelper.cpp index 4826984d3d9..1d13b1a8c6b 100644 --- a/src/plugins/coreplugin/welcomepagehelper.cpp +++ b/src/plugins/coreplugin/welcomepagehelper.cpp @@ -158,6 +158,26 @@ void SectionGridView::wheelEvent(QWheelEvent *e) GridView::wheelEvent(e); } +bool SectionGridView::event(QEvent *e) +{ + if (e->type() == QEvent::Resize) { + const auto itemsFit = [this](const QSize &size) { + const int maxColumns = std::max(size.width() / ListItemDelegate::GridItemWidth, 1); + const int maxRows = std::max(size.height() / ListItemDelegate::GridItemHeight, 1); + const int maxItems = maxColumns * maxRows; + const int items = model()->rowCount(); + return maxItems >= items; + }; + auto resizeEvent = static_cast(e); + const bool itemsCurrentyFit = itemsFit(size()); + if (!resizeEvent->oldSize().isValid() + || itemsFit(resizeEvent->oldSize()) != itemsCurrentyFit) { + emit itemsFitChanged(itemsCurrentyFit); + } + } + return GridView::event(e); +} + const QSize ListModel::defaultImageSize(214, 160); ListModel::ListModel(QObject *parent) @@ -754,7 +774,14 @@ ListModel *SectionedGridView::addSection(const Section §ion, const QList" + Tr::tr("Show All") + " >", this); - seeAllLink->setVisible(gridView->maxRows().has_value()); + if (gridView->maxRows().has_value()) { + seeAllLink->setVisible(true); + connect(gridView, &SectionGridView::itemsFitChanged, seeAllLink, [seeAllLink](bool fits) { + seeAllLink->setVisible(!fits); + }); + } else { + seeAllLink->setVisible(false); + } connect(seeAllLink, &QLabel::linkActivated, this, [this, section] { zoomInSection(section); }); QWidget *sectionLabel = Row{section.name, createSeparator(this), seeAllLink, Space(HSpacing)} .emerge(Layouting::WithoutMargins); diff --git a/src/plugins/coreplugin/welcomepagehelper.h b/src/plugins/coreplugin/welcomepagehelper.h index 8308d65311b..9baa341011d 100644 --- a/src/plugins/coreplugin/welcomepagehelper.h +++ b/src/plugins/coreplugin/welcomepagehelper.h @@ -48,6 +48,8 @@ protected: class CORE_EXPORT SectionGridView : public GridView { + Q_OBJECT + public: explicit SectionGridView(QWidget *parent); @@ -58,6 +60,10 @@ public: int heightForWidth(int width) const override; void wheelEvent(QWheelEvent *e) override; + bool event(QEvent *e) override; + +signals: + void itemsFitChanged(bool fit); private: std::optional m_maxRows;