feat: change project item delegate for modrinth modpacks

more info! \ ^-^/

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2022-07-28 23:00:00 -03:00
parent ee4a829293
commit 3df8594f19
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
2 changed files with 36 additions and 22 deletions

View File

@ -41,6 +41,7 @@
#include "minecraft/MinecraftInstance.h" #include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h" #include "minecraft/PackProfile.h"
#include "ui/dialogs/ModDownloadDialog.h" #include "ui/dialogs/ModDownloadDialog.h"
#include "ui/widgets/ProjectItem.h"
#include <QMessageBox> #include <QMessageBox>
@ -74,31 +75,40 @@ auto ModpackListModel::data(const QModelIndex& index, int role) const -> QVarian
} }
Modrinth::Modpack pack = modpacks.at(pos); Modrinth::Modpack pack = modpacks.at(pos);
if (role == Qt::DisplayRole) { switch (role) {
return pack.name; case Qt::ToolTipRole: {
} else if (role == Qt::ToolTipRole) { if (pack.description.length() > 100) {
if (pack.description.length() > 100) { // some magic to prevent to long tooltips and replace html linebreaks
// some magic to prevent to long tooltips and replace html linebreaks QString edit = pack.description.left(97);
QString edit = pack.description.left(97); edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("...");
edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("..."); return edit;
return edit; }
return pack.description;
} }
return pack.description; case Qt::DecorationRole: {
} else if (role == Qt::DecorationRole) { if (m_logoMap.contains(pack.iconName))
if (m_logoMap.contains(pack.iconName)) { return m_logoMap.value(pack.iconName);
auto icon = m_logoMap.value(pack.iconName);
// FIXME: This doesn't really belong here, but Qt doesn't offer a good way right now ;(
auto icon_scaled = QIcon(icon.pixmap(48, 48).scaledToWidth(48));
return icon_scaled; QIcon icon = APPLICATION->getThemedIcon("screenshot-placeholder");
((ModpackListModel*)this)->requestLogo(pack.iconName, pack.iconUrl.toString());
return icon;
} }
QIcon icon = APPLICATION->getThemedIcon("screenshot-placeholder"); case Qt::UserRole: {
((ModpackListModel*)this)->requestLogo(pack.iconName, pack.iconUrl.toString()); QVariant v;
return icon; v.setValue(pack);
} else if (role == Qt::UserRole) { return v;
QVariant v; }
v.setValue(pack); case Qt::SizeHintRole:
return v; return QSize(0, 58);
// Custom data
case UserDataTypes::TITLE:
return pack.name;
case UserDataTypes::DESCRIPTION:
return pack.description;
case UserDataTypes::SELECTED:
return false;
default:
break;
} }
return {}; return {};

View File

@ -43,6 +43,8 @@
#include "InstanceImportTask.h" #include "InstanceImportTask.h"
#include "Json.h" #include "Json.h"
#include "ui/widgets/ProjectItem.h"
#include <HoeDown.h> #include <HoeDown.h>
#include <QComboBox> #include <QComboBox>
@ -70,6 +72,8 @@ ModrinthPage::ModrinthPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget
connect(ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch())); connect(ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthPage::onSelectionChanged); connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthPage::onSelectionChanged);
connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthPage::onVersionSelectionChanged); connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthPage::onVersionSelectionChanged);
ui->packView->setItemDelegate(new ProjectItemDelegate(this));
} }
ModrinthPage::~ModrinthPage() ModrinthPage::~ModrinthPage()