From 822c98469ff2390394181e9f2f1873fb9146bcc1 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sat, 1 Oct 2022 23:16:38 +0200 Subject: [PATCH] refactor: merge icon into name column Signed-off-by: Sefa Eyeoglu --- launcher/InstanceList.cpp | 6 ++---- launcher/InstanceList.h | 1 - launcher/ui/instanceview/InstanceDelegate.cpp | 6 ++++-- launcher/ui/instanceview/InstanceView.cpp | 4 +--- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/launcher/InstanceList.cpp b/launcher/InstanceList.cpp index e65bc9c3f..5f8ba4691 100644 --- a/launcher/InstanceList.cpp +++ b/launcher/InstanceList.cpp @@ -144,8 +144,6 @@ QVariant InstanceList::headerData(int section, Qt::Orientation orientation, int } switch (section) { - case IconColumn: - return tr("Icon"); case NameColumn: return tr("Name"); case GameVersionColumn: @@ -167,7 +165,7 @@ QVariant InstanceList::data(const QModelIndex& index, int role) const switch (role) { case Qt::DecorationRole: { - if (index.column() == IconColumn) + if (index.column() == NameColumn) return inst->iconKey(); break; } @@ -620,7 +618,7 @@ void InstanceList::propertiesChanged(BaseInstance* inst) { int i = getInstIndex(inst); if (i != -1) { - emit dataChanged(index(i, IconColumn), index(i, ColumnCount - 1)); + emit dataChanged(index(i, NameColumn), index(i, ColumnCount - 1)); updateTotalPlayTime(); } } diff --git a/launcher/InstanceList.h b/launcher/InstanceList.h index 142a348b9..c946a063c 100644 --- a/launcher/InstanceList.h +++ b/launcher/InstanceList.h @@ -57,7 +57,6 @@ class InstanceList : public QAbstractTableModel { int columnCount(const QModelIndex& parent = QModelIndex()) const override; enum Column { - IconColumn = 0, NameColumn, GameVersionColumn, PlayTimeColumn, diff --git a/launcher/ui/instanceview/InstanceDelegate.cpp b/launcher/ui/instanceview/InstanceDelegate.cpp index cbc2aec29..1e5124891 100644 --- a/launcher/ui/instanceview/InstanceDelegate.cpp +++ b/launcher/ui/instanceview/InstanceDelegate.cpp @@ -24,8 +24,10 @@ InstanceDelegate::InstanceDelegate(QObject* parent) : QStyledItemDelegate(parent void InstanceDelegate::initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const { QStyledItemDelegate::initStyleOption(option, index); - if (index.column() == InstanceList::IconColumn) { + if (index.column() == InstanceList::NameColumn) { // make decoration fill cell, subtract default margins - option->decorationSize = option->rect.size().shrunkBy(QMargins(3, 1, 3, 1)); + QSize decorationSize = QSize(option->rect.height(), option->rect.height()); + decorationSize -= QSize(2, 2); // subtract 1px margin + option->decorationSize = decorationSize; } } \ No newline at end of file diff --git a/launcher/ui/instanceview/InstanceView.cpp b/launcher/ui/instanceview/InstanceView.cpp index 2507f0054..96f2b221c 100644 --- a/launcher/ui/instanceview/InstanceView.cpp +++ b/launcher/ui/instanceview/InstanceView.cpp @@ -80,13 +80,11 @@ void InstanceView::createTable() header->restoreState(QByteArray::fromBase64(APPLICATION->settings()->get("InstanceViewTableHeaderState").toByteArray())); header->setSectionsMovable(true); - header->setSectionResizeMode(InstanceList::IconColumn, QHeaderView::Fixed); header->setSectionResizeMode(InstanceList::NameColumn, QHeaderView::Stretch); header->setSectionResizeMode(InstanceList::GameVersionColumn, QHeaderView::Interactive); header->setSectionResizeMode(InstanceList::PlayTimeColumn, QHeaderView::Interactive); header->setSectionResizeMode(InstanceList::LastPlayedColumn, QHeaderView::Interactive); - m_table->setColumnWidth(InstanceList::IconColumn, m_rowHeight + 3 + 3); // padding left and right - m_table->verticalHeader()->setDefaultSectionSize(m_rowHeight + 1 + 1); // padding top and bottom + m_table->verticalHeader()->setDefaultSectionSize(m_rowHeight + 1 + 1); // padding top and bottom if (!APPLICATION->settings()->contains("InstanceViewTableHeaderState")) m_table->sortByColumn(InstanceList::LastPlayedColumn, Qt::AscendingOrder);