forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -144,10 +144,10 @@ bool SectionGridView::hasHeightForWidth() const
|
|||||||
|
|
||||||
int SectionGridView::heightForWidth(int width) 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 rowCount = (model()->rowCount() + columnCount - 1) / columnCount;
|
||||||
const int maxRowCount = m_maxRows ? std::min(*m_maxRows, rowCount) : rowCount;
|
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)
|
void SectionGridView::wheelEvent(QWheelEvent *e)
|
||||||
@@ -162,8 +162,8 @@ bool SectionGridView::event(QEvent *e)
|
|||||||
{
|
{
|
||||||
if (e->type() == QEvent::Resize) {
|
if (e->type() == QEvent::Resize) {
|
||||||
const auto itemsFit = [this](const QSize &size) {
|
const auto itemsFit = [this](const QSize &size) {
|
||||||
const int maxColumns = std::max(size.width() / ListItemDelegate::GridItemWidth, 1);
|
const int maxColumns = std::max(size.width() / WelcomePageHelpers::GridItemWidth, 1);
|
||||||
const int maxRows = std::max(size.height() / ListItemDelegate::GridItemHeight, 1);
|
const int maxRows = std::max(size.height() / WelcomePageHelpers::GridItemHeight, 1);
|
||||||
const int maxItems = maxColumns * maxRows;
|
const int maxItems = maxColumns * maxRows;
|
||||||
const int items = model()->rowCount();
|
const int items = model()->rowCount();
|
||||||
return maxItems >= items;
|
return maxItems >= items;
|
||||||
@@ -178,8 +178,6 @@ bool SectionGridView::event(QEvent *e)
|
|||||||
return GridView::event(e);
|
return GridView::event(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QSize ListModel::defaultImageSize(214, 160);
|
|
||||||
|
|
||||||
ListModel::ListModel(QObject *parent)
|
ListModel::ListModel(QObject *parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
{
|
{
|
||||||
@@ -459,13 +457,14 @@ void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
|||||||
|
|
||||||
const QRect rc = option.rect;
|
const QRect rc = option.rect;
|
||||||
const QRect tileRect(0, 0, rc.width() - GridItemGap, rc.height() - GridItemGap);
|
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,
|
const QRect thumbnailBgRect((tileRect.width() - thumbnailBgSize.width()) / 2, GridItemGap,
|
||||||
thumbnailBgSize.width(), thumbnailBgSize.height());
|
thumbnailBgSize.width(), thumbnailBgSize.height());
|
||||||
const QRect textArea = tileRect.adjusted(GridItemGap, GridItemGap, -GridItemGap, -GridItemGap);
|
const QRect textArea = tileRect.adjusted(GridItemGap, GridItemGap, -GridItemGap, -GridItemGap);
|
||||||
|
|
||||||
const bool hovered = option.state & QStyle::State_MouseOver;
|
const bool hovered = option.state & QStyle::State_MouseOver;
|
||||||
|
|
||||||
|
constexpr int TagsSeparatorY = GridItemHeight - GridItemGap - 52;
|
||||||
constexpr int tagsBase = TagsSeparatorY + 17;
|
constexpr int tagsBase = TagsSeparatorY + 17;
|
||||||
constexpr int shiftY = TagsSeparatorY - 16;
|
constexpr int shiftY = TagsSeparatorY - 16;
|
||||||
constexpr int nameY = TagsSeparatorY - 20;
|
constexpr int nameY = TagsSeparatorY - 20;
|
||||||
|
|||||||
@@ -24,6 +24,12 @@ namespace WelcomePageHelpers {
|
|||||||
|
|
||||||
constexpr int HSpacing = 20;
|
constexpr int HSpacing = 20;
|
||||||
constexpr int ItemGap = 4;
|
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 QFont brandFont();
|
||||||
CORE_EXPORT QWidget *panelBar(QWidget *parent = nullptr);
|
CORE_EXPORT QWidget *panelBar(QWidget *parent = nullptr);
|
||||||
|
|
||||||
@@ -99,8 +105,6 @@ public:
|
|||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
void setPixmapFunction(const PixmapFunction &fetchPixmapAndUpdatePixmapCache);
|
void setPixmapFunction(const PixmapFunction &fetchPixmapAndUpdatePixmapCache);
|
||||||
|
|
||||||
static const QSize defaultImageSize;
|
|
||||||
|
|
||||||
void setOwnsItems(bool owns);
|
void setOwnsItems(bool owns);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -142,11 +146,6 @@ public:
|
|||||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||||
const QModelIndex &index) const override;
|
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:
|
signals:
|
||||||
void tagClicked(const QString &tag);
|
void tagClicked(const QString &tag);
|
||||||
|
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ void SectionedProducts::onImageDownloadFinished(QNetworkReply *reply)
|
|||||||
if (pixmap.loadFromData(data, imageFormat.toLatin1())) {
|
if (pixmap.loadFromData(data, imageFormat.toLatin1())) {
|
||||||
const QString url = imageUrl.toString();
|
const QString url = imageUrl.toString();
|
||||||
const int dpr = qApp->devicePixelRatio();
|
const int dpr = qApp->devicePixelRatio();
|
||||||
pixmap = pixmap.scaled(ListModel::defaultImageSize * dpr,
|
pixmap = pixmap.scaled(WelcomePageHelpers::GridItemImageSize * dpr,
|
||||||
Qt::KeepAspectRatio,
|
Qt::KeepAspectRatio,
|
||||||
Qt::SmoothTransformation);
|
Qt::SmoothTransformation);
|
||||||
pixmap.setDevicePixelRatio(dpr);
|
pixmap.setDevicePixelRatio(dpr);
|
||||||
|
|||||||
@@ -255,7 +255,8 @@ static QPixmap fetchPixmapAndUpdatePixmapCache(const QString &url)
|
|||||||
img.convertTo(QImage::Format_RGB32);
|
img.convertTo(QImage::Format_RGB32);
|
||||||
const int dpr = qApp->devicePixelRatio();
|
const int dpr = qApp->devicePixelRatio();
|
||||||
// boundedTo -> don't scale thumbnails up
|
// 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(
|
pixmap = QPixmap::fromImage(
|
||||||
img.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
img.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||||
pixmap.setDevicePixelRatio(dpr);
|
pixmap.setDevicePixelRatio(dpr);
|
||||||
|
|||||||
@@ -280,8 +280,8 @@ public:
|
|||||||
// for macOS dark mode
|
// for macOS dark mode
|
||||||
pal.setColor(QPalette::Text, Utils::creatorTheme()->color(Theme::Welcome_TextColor));
|
pal.setColor(QPalette::Text, Utils::creatorTheme()->color(Theme::Welcome_TextColor));
|
||||||
exampleSetSelector->setPalette(pal);
|
exampleSetSelector->setPalette(pal);
|
||||||
exampleSetSelector->setMinimumWidth(Core::ListItemDelegate::GridItemWidth);
|
exampleSetSelector->setMinimumWidth(Core::WelcomePageHelpers::GridItemWidth);
|
||||||
exampleSetSelector->setMaximumWidth(Core::ListItemDelegate::GridItemWidth);
|
exampleSetSelector->setMaximumWidth(Core::WelcomePageHelpers::GridItemWidth);
|
||||||
exampleSetSelector->setModel(s_exampleSetModel);
|
exampleSetSelector->setModel(s_exampleSetModel);
|
||||||
exampleSetSelector->setCurrentIndex(s_exampleSetModel->selectedExampleSet());
|
exampleSetSelector->setCurrentIndex(s_exampleSetModel->selectedExampleSet());
|
||||||
connect(exampleSetSelector,
|
connect(exampleSetSelector,
|
||||||
|
|||||||
Reference in New Issue
Block a user