mirror of
https://github.com/stenzek/duckstation.git
synced 2025-06-07 12:05:52 +00:00
Qt: Center icons in grid view
This commit is contained in:
parent
f494cb47c4
commit
426cdd1611
@ -1196,7 +1196,9 @@ void GameListWidget::initialize()
|
|||||||
m_list_view->setContextMenuPolicy(Qt::CustomContextMenu);
|
m_list_view->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
m_list_view->setFrameStyle(QFrame::NoFrame);
|
m_list_view->setFrameStyle(QFrame::NoFrame);
|
||||||
m_list_view->setVerticalScrollMode(QAbstractItemView::ScrollMode::ScrollPerPixel);
|
m_list_view->setVerticalScrollMode(QAbstractItemView::ScrollMode::ScrollPerPixel);
|
||||||
|
m_list_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||||
m_list_view->verticalScrollBar()->setSingleStep(15);
|
m_list_view->verticalScrollBar()->setSingleStep(15);
|
||||||
|
|
||||||
onCoverScaleChanged();
|
onCoverScaleChanged();
|
||||||
|
|
||||||
connect(m_list_view->selectionModel(), &QItemSelectionModel::currentChanged, this,
|
connect(m_list_view->selectionModel(), &QItemSelectionModel::currentChanged, this,
|
||||||
@ -1441,10 +1443,13 @@ void GameListWidget::onCoverScaleChanged()
|
|||||||
m_model->updateCacheSize(width(), height());
|
m_model->updateCacheSize(width(), height());
|
||||||
|
|
||||||
m_list_view->setSpacing(m_model->getCoverArtSpacing());
|
m_list_view->setSpacing(m_model->getCoverArtSpacing());
|
||||||
|
m_list_view->setIconSize(QSize(m_model->getCoverArtWidth(), m_model->getCoverArtHeight()));
|
||||||
|
|
||||||
QFont font;
|
QFont font;
|
||||||
font.setPointSizeF(20.0f * m_model->getCoverScale());
|
font.setPointSizeF(20.0f * m_model->getCoverScale());
|
||||||
m_list_view->setFont(font);
|
m_list_view->setFont(font);
|
||||||
|
|
||||||
|
m_list_view->updateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameListWidget::listZoom(float delta)
|
void GameListWidget::listZoom(float delta)
|
||||||
@ -1784,3 +1789,29 @@ void GameListGridListView::wheelEvent(QWheelEvent* e)
|
|||||||
|
|
||||||
QListView::wheelEvent(e);
|
QListView::wheelEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameListGridListView::resizeEvent(QResizeEvent* e)
|
||||||
|
{
|
||||||
|
updateLayout();
|
||||||
|
QListView::resizeEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameListGridListView::updateLayout()
|
||||||
|
{
|
||||||
|
const int scrollbar_width = verticalScrollBar()->width();
|
||||||
|
const int item_spacing = spacing();
|
||||||
|
const int icon_margin = style()->pixelMetric(QStyle::PM_FocusFrameHMargin, nullptr, this) * 2;
|
||||||
|
|
||||||
|
// I hate this +2. Not sure what's not being accounted for, but without it the calculation is off by 2 pixels...
|
||||||
|
const int icon_width = iconSize().width() + icon_margin + item_spacing + 2;
|
||||||
|
const int available_width = width() - scrollbar_width - item_spacing - icon_margin;
|
||||||
|
const int items_per_row = available_width / icon_width;
|
||||||
|
const int margin = (available_width - (items_per_row * icon_width)) / 2;
|
||||||
|
|
||||||
|
m_horizontal_offset = margin;
|
||||||
|
}
|
||||||
|
|
||||||
|
int GameListGridListView::horizontalOffset() const
|
||||||
|
{
|
||||||
|
return QListView::horizontalOffset() - m_horizontal_offset;
|
||||||
|
}
|
||||||
|
@ -152,22 +152,29 @@ private:
|
|||||||
mutable LRUCache<std::string, QPixmap> m_memcard_pixmap_cache;
|
mutable LRUCache<std::string, QPixmap> m_memcard_pixmap_cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GameListGridListView : public QListView
|
class GameListGridListView final : public QListView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GameListGridListView(QWidget* parent = nullptr);
|
GameListGridListView(QWidget* parent = nullptr);
|
||||||
|
|
||||||
|
void updateLayout();
|
||||||
|
int horizontalOffset() const override;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void zoomOut();
|
void zoomOut();
|
||||||
void zoomIn();
|
void zoomIn();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void wheelEvent(QWheelEvent* e);
|
void wheelEvent(QWheelEvent* e) override;
|
||||||
|
void resizeEvent(QResizeEvent* e) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_horizontal_offset = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GameListWidget : public QWidget
|
class GameListWidget final : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user