From 39c582297e2939d5934fc417d3b20c1fe21fc11a Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sat, 1 Oct 2022 22:02:11 +0200 Subject: [PATCH] fix: algin instance icon Signed-off-by: Sefa Eyeoglu --- launcher/CMakeLists.txt | 2 ++ launcher/ui/instanceview/InstanceDelegate.cpp | 31 +++++++++++++++++++ launcher/ui/instanceview/InstanceDelegate.h | 30 ++++++++++++++++++ .../ui/instanceview/InstanceProxyModel.cpp | 2 +- launcher/ui/instanceview/InstanceView.cpp | 2 ++ 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 launcher/ui/instanceview/InstanceDelegate.cpp create mode 100644 launcher/ui/instanceview/InstanceDelegate.h diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index d45b57063..8981ba394 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -872,6 +872,8 @@ SET(LAUNCHER_SOURCES # GUI - instance group view ui/instanceview/InstanceProxyModel.cpp ui/instanceview/InstanceProxyModel.h + ui/instanceview/InstanceDelegate.h + ui/instanceview/InstanceDelegate.cpp ui/instanceview/InstanceView.h ui/instanceview/InstanceView.cpp ) diff --git a/launcher/ui/instanceview/InstanceDelegate.cpp b/launcher/ui/instanceview/InstanceDelegate.cpp new file mode 100644 index 000000000..ba0680de8 --- /dev/null +++ b/launcher/ui/instanceview/InstanceDelegate.cpp @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 Sefa Eyeoglu + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "InstanceDelegate.h" +#include "InstanceList.h" + +InstanceDelegate::InstanceDelegate(QObject* parent) : QStyledItemDelegate(parent) {} + +void InstanceDelegate::initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const +{ + QStyledItemDelegate::initStyleOption(option, index); + if (index.column() == InstanceList::Icon) { + // make decoration fill cell, subtract default margins + option->decorationSize = option->rect.size().shrunkBy(QMargins(3, 1, 3, 1)); + } +} \ No newline at end of file diff --git a/launcher/ui/instanceview/InstanceDelegate.h b/launcher/ui/instanceview/InstanceDelegate.h new file mode 100644 index 000000000..f04a6a10a --- /dev/null +++ b/launcher/ui/instanceview/InstanceDelegate.h @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 Sefa Eyeoglu + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +class InstanceDelegate : public QStyledItemDelegate { + Q_OBJECT + + public: + InstanceDelegate(QObject* parent = 0); + + void initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const override; +}; diff --git a/launcher/ui/instanceview/InstanceProxyModel.cpp b/launcher/ui/instanceview/InstanceProxyModel.cpp index 5a70f9083..d8eaf5e95 100644 --- a/launcher/ui/instanceview/InstanceProxyModel.cpp +++ b/launcher/ui/instanceview/InstanceProxyModel.cpp @@ -32,7 +32,7 @@ QVariant InstanceProxyModel::data(const QModelIndex& index, int role) const QVariant data = QSortFilterProxyModel::data(index, role); if (role == Qt::DecorationRole) { if (!data.toString().isEmpty()) - return APPLICATION->icons()->getIcon(data.toString()); // FIXME: Needs QStyledItemDelegate + return APPLICATION->icons()->getIcon(data.toString()); } switch (index.column()) { diff --git a/launcher/ui/instanceview/InstanceView.cpp b/launcher/ui/instanceview/InstanceView.cpp index 1e06a124b..be2c3d6b8 100644 --- a/launcher/ui/instanceview/InstanceView.cpp +++ b/launcher/ui/instanceview/InstanceView.cpp @@ -25,6 +25,7 @@ #include "InstanceView.h" #include "Application.h" +#include "InstanceDelegate.h" #include "InstanceList.h" #include "ui/instanceview/InstanceProxyModel.h" @@ -57,6 +58,7 @@ void InstanceView::createTable() { m_table = new QTableView(this); m_table->setModel(m_proxy); + m_table->setItemDelegate(new InstanceDelegate(this)); m_table->setTabKeyNavigation(false); m_table->setSelectionMode(QAbstractItemView::SingleSelection);