summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlessandro Portale <alessandro.portale@qt.io>2023-05-02 18:28:12 +0200
committerAlessandro Portale <alessandro.portale@qt.io>2023-05-03 19:55:22 +0000
commit765e8a65eaeb2ec01cd87970a44fd84bab08d59a (patch)
tree7d090581e457f5cc62414648b0592e3d980c4659 /src
parent2a5f2961a75bd26acadc9ab514a8875d9eaade4c (diff)
downloadqt-creator-765e8a65eaeb2ec01cd87970a44fd84bab08d59a.tar.gz
Examples: Centralize constants in one place
Having all constants in WelcomePageHelpers makes reading the welcome scren code a bit less interesting. Change-Id: Idc2e402f33042b49d041c43ecc78a6e8d2d3536a Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/coreplugin/welcomepagehelper.cpp13
-rw-r--r--src/plugins/coreplugin/welcomepagehelper.h13
-rw-r--r--src/plugins/marketplace/productlistmodel.cpp2
-rw-r--r--src/plugins/qtsupport/exampleslistmodel.cpp3
-rw-r--r--src/plugins/qtsupport/gettingstartedwelcomepage.cpp4
5 files changed, 17 insertions, 18 deletions
diff --git a/src/plugins/coreplugin/welcomepagehelper.cpp b/src/plugins/coreplugin/welcomepagehelper.cpp
index ad7c586747..cba0d6c033 100644
--- a/src/plugins/coreplugin/welcomepagehelper.cpp
+++ b/src/plugins/coreplugin/welcomepagehelper.cpp
@@ -144,10 +144,10 @@ bool SectionGridView::hasHeightForWidth() const
int SectionGridView::heightForWidth(int width) const
{
- const int columnCount = width / Core::ListItemDelegate::GridItemWidth;
+ const int columnCount = width / Core::WelcomePageHelpers::GridItemWidth;
const int rowCount = (model()->rowCount() + columnCount - 1) / columnCount;
const int maxRowCount = m_maxRows ? std::min(*m_maxRows, rowCount) : rowCount;
- return maxRowCount * Core::ListItemDelegate::GridItemHeight;
+ return maxRowCount * Core::WelcomePageHelpers::GridItemHeight;
}
void SectionGridView::wheelEvent(QWheelEvent *e)
@@ -162,8 +162,8 @@ 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 maxColumns = std::max(size.width() / WelcomePageHelpers::GridItemWidth, 1);
+ const int maxRows = std::max(size.height() / WelcomePageHelpers::GridItemHeight, 1);
const int maxItems = maxColumns * maxRows;
const int items = model()->rowCount();
return maxItems >= items;
@@ -178,8 +178,6 @@ bool SectionGridView::event(QEvent *e)
return GridView::event(e);
}
-const QSize ListModel::defaultImageSize(214, 160);
-
ListModel::ListModel(QObject *parent)
: QAbstractListModel(parent)
{
@@ -459,13 +457,14 @@ void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
const QRect rc = option.rect;
const QRect tileRect(0, 0, rc.width() - GridItemGap, rc.height() - GridItemGap);
- const QSize thumbnailBgSize = ListModel::defaultImageSize.grownBy(QMargins(1, 1, 1, 1));
+ const QSize thumbnailBgSize = GridItemImageSize.grownBy(QMargins(1, 1, 1, 1));
const QRect thumbnailBgRect((tileRect.width() - thumbnailBgSize.width()) / 2, GridItemGap,
thumbnailBgSize.width(), thumbnailBgSize.height());
const QRect textArea = tileRect.adjusted(GridItemGap, GridItemGap, -GridItemGap, -GridItemGap);
const bool hovered = option.state & QStyle::State_MouseOver;
+ constexpr int TagsSeparatorY = GridItemHeight - GridItemGap - 52;
constexpr int tagsBase = TagsSeparatorY + 17;
constexpr int shiftY = TagsSeparatorY - 16;
constexpr int nameY = TagsSeparatorY - 20;
diff --git a/src/plugins/coreplugin/welcomepagehelper.h b/src/plugins/coreplugin/welcomepagehelper.h
index 641ce5983d..f997b2539a 100644
--- a/src/plugins/coreplugin/welcomepagehelper.h
+++ b/src/plugins/coreplugin/welcomepagehelper.h
@@ -24,6 +24,12 @@ namespace WelcomePageHelpers {
constexpr int HSpacing = 20;
constexpr int ItemGap = 4;
+
+constexpr int GridItemGap = 3 * ItemGap;
+constexpr int GridItemWidth = 240 + GridItemGap;
+constexpr int GridItemHeight = GridItemWidth;
+constexpr QSize GridItemImageSize(214, 160);
+
CORE_EXPORT QFont brandFont();
CORE_EXPORT QWidget *panelBar(QWidget *parent = nullptr);
@@ -99,8 +105,6 @@ public:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
void setPixmapFunction(const PixmapFunction &fetchPixmapAndUpdatePixmapCache);
- static const QSize defaultImageSize;
-
void setOwnsItems(bool owns);
private:
@@ -142,11 +146,6 @@ public:
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
- static constexpr int GridItemGap = 3 * WelcomePageHelpers::ItemGap;
- static constexpr int GridItemWidth = 240 + GridItemGap;
- static constexpr int GridItemHeight = GridItemWidth;
- static constexpr int TagsSeparatorY = GridItemHeight - GridItemGap - 52;
-
signals:
void tagClicked(const QString &tag);
diff --git a/src/plugins/marketplace/productlistmodel.cpp b/src/plugins/marketplace/productlistmodel.cpp
index cdfb8d79e5..36b047abc2 100644
--- a/src/plugins/marketplace/productlistmodel.cpp
+++ b/src/plugins/marketplace/productlistmodel.cpp
@@ -269,7 +269,7 @@ void SectionedProducts::onImageDownloadFinished(QNetworkReply *reply)
if (pixmap.loadFromData(data, imageFormat.toLatin1())) {
const QString url = imageUrl.toString();
const int dpr = qApp->devicePixelRatio();
- pixmap = pixmap.scaled(ListModel::defaultImageSize * dpr,
+ pixmap = pixmap.scaled(WelcomePageHelpers::GridItemImageSize * dpr,
Qt::KeepAspectRatio,
Qt::SmoothTransformation);
pixmap.setDevicePixelRatio(dpr);
diff --git a/src/plugins/qtsupport/exampleslistmodel.cpp b/src/plugins/qtsupport/exampleslistmodel.cpp
index 3478634815..ebb90381c7 100644
--- a/src/plugins/qtsupport/exampleslistmodel.cpp
+++ b/src/plugins/qtsupport/exampleslistmodel.cpp
@@ -255,7 +255,8 @@ static QPixmap fetchPixmapAndUpdatePixmapCache(const QString &url)
img.convertTo(QImage::Format_RGB32);
const int dpr = qApp->devicePixelRatio();
// boundedTo -> don't scale thumbnails up
- const QSize scaledSize = Core::ListModel::defaultImageSize.boundedTo(img.size()) * dpr;
+ const QSize scaledSize =
+ WelcomePageHelpers::GridItemImageSize.boundedTo(img.size()) * dpr;
pixmap = QPixmap::fromImage(
img.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
pixmap.setDevicePixelRatio(dpr);
diff --git a/src/plugins/qtsupport/gettingstartedwelcomepage.cpp b/src/plugins/qtsupport/gettingstartedwelcomepage.cpp
index bf19233c21..7bc7192185 100644
--- a/src/plugins/qtsupport/gettingstartedwelcomepage.cpp
+++ b/src/plugins/qtsupport/gettingstartedwelcomepage.cpp
@@ -280,8 +280,8 @@ public:
// for macOS dark mode
pal.setColor(QPalette::Text, Utils::creatorTheme()->color(Theme::Welcome_TextColor));
exampleSetSelector->setPalette(pal);
- exampleSetSelector->setMinimumWidth(Core::ListItemDelegate::GridItemWidth);
- exampleSetSelector->setMaximumWidth(Core::ListItemDelegate::GridItemWidth);
+ exampleSetSelector->setMinimumWidth(Core::WelcomePageHelpers::GridItemWidth);
+ exampleSetSelector->setMaximumWidth(Core::WelcomePageHelpers::GridItemWidth);
exampleSetSelector->setModel(s_exampleSetModel);
exampleSetSelector->setCurrentIndex(s_exampleSetModel->selectedExampleSet());
connect(exampleSetSelector,