2022-10-01 22:02:11 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
|
|
|
* PolyMC - Minecraft Launcher
|
|
|
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
|
|
|
*
|
|
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "InstanceDelegate.h"
|
|
|
|
#include "InstanceList.h"
|
|
|
|
|
2022-10-02 15:00:45 +02:00
|
|
|
InstanceDelegate::InstanceDelegate(QObject* parent, int iconSize, bool isGrid)
|
|
|
|
: QStyledItemDelegate(parent), m_iconSize(iconSize), m_isGrid(isGrid)
|
|
|
|
{}
|
2022-10-01 22:02:11 +02:00
|
|
|
|
|
|
|
void InstanceDelegate::initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const
|
|
|
|
{
|
|
|
|
QStyledItemDelegate::initStyleOption(option, index);
|
2022-10-01 23:16:38 +02:00
|
|
|
if (index.column() == InstanceList::NameColumn) {
|
2022-10-02 11:40:30 +02:00
|
|
|
option->decorationSize = QSize(m_iconSize, m_iconSize);
|
2022-10-02 15:00:45 +02:00
|
|
|
if (m_isGrid) // FIXME: kinda hacky way to add vertical padding. This assumes that the icon is square in the first place
|
|
|
|
option->decorationSize.rheight() += 8;
|
2022-10-01 22:02:11 +02:00
|
|
|
}
|
2022-10-02 12:43:04 +02:00
|
|
|
}
|
2022-10-02 15:00:45 +02:00
|
|
|
|
|
|
|
QSize InstanceDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
|
|
|
|
{
|
|
|
|
QSize s = QStyledItemDelegate::sizeHint(option, index);
|
|
|
|
if (m_isGrid)
|
|
|
|
return s.expandedTo(QSize(m_iconSize * 2, m_iconSize * 2));
|
|
|
|
return s;
|
|
|
|
}
|