aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--launcher/Application.cpp3
-rw-r--r--launcher/ui/pages/global/LauncherPage.ui2
-rw-r--r--launcher/ui/pages/modplatform/ModModel.cpp8
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp58
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp4
-rw-r--r--launcher/ui/themes/BrightTheme.cpp26
-rw-r--r--launcher/ui/themes/DarkTheme.cpp14
-rw-r--r--launcher/ui/widgets/InfoFrame.cpp63
-rw-r--r--launcher/ui/widgets/ProjectItem.cpp37
9 files changed, 130 insertions, 85 deletions
diff --git a/launcher/Application.cpp b/launcher/Application.cpp
index e08ea7f4..968dd08e 100644
--- a/launcher/Application.cpp
+++ b/launcher/Application.cpp
@@ -859,12 +859,13 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
qDebug() << "<> Application theme set.";
}
+ updateCapabilities();
+
if(createSetupWizard())
{
return;
}
- updateCapabilities();
performMainStartupAction();
}
diff --git a/launcher/ui/pages/global/LauncherPage.ui b/launcher/ui/pages/global/LauncherPage.ui
index 645f7ef6..0d14f147 100644
--- a/launcher/ui/pages/global/LauncherPage.ui
+++ b/launcher/ui/pages/global/LauncherPage.ui
@@ -176,7 +176,7 @@
<item>
<widget class="QLabel" name="metadataWarningLabel">
<property name="text">
- <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600; color:#f5c211;&quot;&gt;Warning&lt;/span&gt;&lt;span style=&quot; color:#f5c211;&quot;&gt;: Disabling mod metadata may also disable some upcoming QoL features, such as mod updating!&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600; color:#f5c211;&quot;&gt;Warning&lt;/span&gt;&lt;span style=&quot; color:#f5c211;&quot;&gt;: Disabling mod metadata may also disable some QoL features, such as mod updating!&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
diff --git a/launcher/ui/pages/modplatform/ModModel.cpp b/launcher/ui/pages/modplatform/ModModel.cpp
index 029e2be0..8961fadd 100644
--- a/launcher/ui/pages/modplatform/ModModel.cpp
+++ b/launcher/ui/pages/modplatform/ModModel.cpp
@@ -62,11 +62,7 @@ auto ListModel::data(const QModelIndex& index, int role) const -> QVariant
}
case Qt::DecorationRole: {
if (m_logoMap.contains(pack.logoName)) {
- auto icon = m_logoMap.value(pack.logoName);
- // 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;
+ return m_logoMap.value(pack.logoName);
}
QIcon icon = APPLICATION->getThemedIcon("screenshot-placeholder");
// un-const-ify this
@@ -175,7 +171,7 @@ void ListModel::getLogo(const QString& logo, const QString& logoUrl, LogoCallbac
void ListModel::requestLogo(QString logo, QString url)
{
- if (m_loadingLogos.contains(logo) || m_failedLogos.contains(logo)) {
+ if (m_loadingLogos.contains(logo) || m_failedLogos.contains(logo) || url.isEmpty()) {
return;
}
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
index 614be434..fd7a3537 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
@@ -41,6 +41,7 @@
#include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h"
#include "ui/dialogs/ModDownloadDialog.h"
+#include "ui/widgets/ProjectItem.h"
#include <QMessageBox>
@@ -74,31 +75,40 @@ auto ModpackListModel::data(const QModelIndex& index, int role) const -> QVarian
}
Modrinth::Modpack pack = modpacks.at(pos);
- if (role == Qt::DisplayRole) {
- return pack.name;
- } else if (role == Qt::ToolTipRole) {
- if (pack.description.length() > 100) {
- // some magic to prevent to long tooltips and replace html linebreaks
- QString edit = pack.description.left(97);
- edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("...");
- return edit;
+ switch (role) {
+ case Qt::ToolTipRole: {
+ if (pack.description.length() > 100) {
+ // some magic to prevent to long tooltips and replace html linebreaks
+ QString edit = pack.description.left(97);
+ edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("...");
+ return edit;
+ }
+ return pack.description;
}
- return pack.description;
- } else if (role == Qt::DecorationRole) {
- if (m_logoMap.contains(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;
+ case Qt::DecorationRole: {
+ if (m_logoMap.contains(pack.iconName))
+ return m_logoMap.value(pack.iconName);
+
+ QIcon icon = APPLICATION->getThemedIcon("screenshot-placeholder");
+ ((ModpackListModel*)this)->requestLogo(pack.iconName, pack.iconUrl.toString());
+ return icon;
+ }
+ case Qt::UserRole: {
+ QVariant v;
+ v.setValue(pack);
+ return v;
}
- QIcon icon = APPLICATION->getThemedIcon("screenshot-placeholder");
- ((ModpackListModel*)this)->requestLogo(pack.iconName, pack.iconUrl.toString());
- return icon;
- } else if (role == Qt::UserRole) {
- QVariant v;
- v.setValue(pack);
- return v;
+ case Qt::SizeHintRole:
+ 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 {};
@@ -217,7 +227,7 @@ void ModpackListModel::getLogo(const QString& logo, const QString& logoUrl, Logo
void ModpackListModel::requestLogo(QString logo, QString url)
{
- if (m_loadingLogos.contains(logo) || m_failedLogos.contains(logo)) {
+ if (m_loadingLogos.contains(logo) || m_failedLogos.contains(logo) || url.isEmpty()) {
return;
}
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
index 16fec82c..cea6cdee 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
@@ -43,6 +43,8 @@
#include "InstanceImportTask.h"
#include "Json.h"
+#include "ui/widgets/ProjectItem.h"
+
#include <HoeDown.h>
#include <QComboBox>
@@ -70,6 +72,8 @@ ModrinthPage::ModrinthPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget
connect(ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthPage::onSelectionChanged);
connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthPage::onVersionSelectionChanged);
+
+ ui->packView->setItemDelegate(new ProjectItemDelegate(this));
}
ModrinthPage::~ModrinthPage()
diff --git a/launcher/ui/themes/BrightTheme.cpp b/launcher/ui/themes/BrightTheme.cpp
index 7469edfc..696ffdfb 100644
--- a/launcher/ui/themes/BrightTheme.cpp
+++ b/launcher/ui/themes/BrightTheme.cpp
@@ -20,19 +20,19 @@ bool BrightTheme::hasColorScheme()
QPalette BrightTheme::colorScheme()
{
QPalette brightPalette;
- brightPalette.setColor(QPalette::Window, QColor(239,240,241));
- brightPalette.setColor(QPalette::WindowText, QColor(49,54,59));
- brightPalette.setColor(QPalette::Base, QColor(252,252,252));
- brightPalette.setColor(QPalette::AlternateBase, QColor(239,240,241));
- brightPalette.setColor(QPalette::ToolTipBase, QColor(49,54,59));
- brightPalette.setColor(QPalette::ToolTipText, QColor(239,240,241));
- brightPalette.setColor(QPalette::Text, QColor(49,54,59));
- brightPalette.setColor(QPalette::Button, QColor(239,240,241));
- brightPalette.setColor(QPalette::ButtonText, QColor(49,54,59));
+ brightPalette.setColor(QPalette::Window, QColor(255,255,255));
+ brightPalette.setColor(QPalette::WindowText, QColor(17,17,17));
+ brightPalette.setColor(QPalette::Base, QColor(250,250,250));
+ brightPalette.setColor(QPalette::AlternateBase, QColor(240,240,240));
+ brightPalette.setColor(QPalette::ToolTipBase, QColor(17,17,17));
+ brightPalette.setColor(QPalette::ToolTipText, QColor(255,255,255));
+ brightPalette.setColor(QPalette::Text, Qt::black);
+ brightPalette.setColor(QPalette::Button, QColor(249,249,249));
+ brightPalette.setColor(QPalette::ButtonText, Qt::black);
brightPalette.setColor(QPalette::BrightText, Qt::red);
- brightPalette.setColor(QPalette::Link, QColor(41, 128, 185));
- brightPalette.setColor(QPalette::Highlight, QColor(61, 174, 233));
- brightPalette.setColor(QPalette::HighlightedText, QColor(239,240,241));
+ brightPalette.setColor(QPalette::Link, QColor(37,137,164));
+ brightPalette.setColor(QPalette::Highlight, QColor(137,207,84));
+ brightPalette.setColor(QPalette::HighlightedText, Qt::black);
return fadeInactive(brightPalette, fadeAmount(), fadeColor());
}
@@ -43,7 +43,7 @@ double BrightTheme::fadeAmount()
QColor BrightTheme::fadeColor()
{
- return QColor(239,240,241);
+ return QColor(255,255,255);
}
bool BrightTheme::hasStyleSheet()
diff --git a/launcher/ui/themes/DarkTheme.cpp b/launcher/ui/themes/DarkTheme.cpp
index c2a6a8df..07a2efd2 100644
--- a/launcher/ui/themes/DarkTheme.cpp
+++ b/launcher/ui/themes/DarkTheme.cpp
@@ -20,18 +20,18 @@ bool DarkTheme::hasColorScheme()
QPalette DarkTheme::colorScheme()
{
QPalette darkPalette;
- darkPalette.setColor(QPalette::Window, QColor(49,54,59));
+ darkPalette.setColor(QPalette::Window, QColor(49,49,49));
darkPalette.setColor(QPalette::WindowText, Qt::white);
- darkPalette.setColor(QPalette::Base, QColor(35,38,41));
- darkPalette.setColor(QPalette::AlternateBase, QColor(49,54,59));
+ darkPalette.setColor(QPalette::Base, QColor(34,34,34));
+ darkPalette.setColor(QPalette::AlternateBase, QColor(42,42,42));
darkPalette.setColor(QPalette::ToolTipBase, Qt::white);
darkPalette.setColor(QPalette::ToolTipText, Qt::white);
darkPalette.setColor(QPalette::Text, Qt::white);
- darkPalette.setColor(QPalette::Button, QColor(49,54,59));
+ darkPalette.setColor(QPalette::Button, QColor(48,48,48));
darkPalette.setColor(QPalette::ButtonText, Qt::white);
darkPalette.setColor(QPalette::BrightText, Qt::red);
- darkPalette.setColor(QPalette::Link, QColor(42, 130, 218));
- darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218));
+ darkPalette.setColor(QPalette::Link, QColor(47,163,198));
+ darkPalette.setColor(QPalette::Highlight, QColor(145,205,92));
darkPalette.setColor(QPalette::HighlightedText, Qt::black);
darkPalette.setColor(QPalette::PlaceholderText, Qt::darkGray);
return fadeInactive(darkPalette, fadeAmount(), fadeColor());
@@ -44,7 +44,7 @@ double DarkTheme::fadeAmount()
QColor DarkTheme::fadeColor()
{
- return QColor(49,54,59);
+ return QColor(49,49,49);
}
bool DarkTheme::hasStyleSheet()
diff --git a/launcher/ui/widgets/InfoFrame.cpp b/launcher/ui/widgets/InfoFrame.cpp
index f78dbe16..fdc581b4 100644
--- a/launcher/ui/widgets/InfoFrame.cpp
+++ b/launcher/ui/widgets/InfoFrame.cpp
@@ -97,14 +97,6 @@ void InfoFrame::updateWithResource(const Resource& resource)
setImage();
}
-// https://www.sportskeeda.com/minecraft-wiki/color-codes
-static const QMap<QChar, QString> s_value_to_color = {
- {'0', "#000000"}, {'1', "#0000AA"}, {'2', "#00AA00"}, {'3', "#00AAAA"}, {'4', "#AA0000"},
- {'5', "#AA00AA"}, {'6', "#FFAA00"}, {'7', "#AAAAAA"}, {'8', "#555555"}, {'9', "#5555FF"},
- {'a', "#55FF55"}, {'b', "#55FFFF"}, {'c', "#FF5555"}, {'d', "#FF55FF"}, {'e', "#FFFF55"},
- {'f', "#FFFFFF"}
-};
-
QString InfoFrame::renderColorCodes(QString input) {
// We have to manually set the colors for use.
//
@@ -113,32 +105,53 @@ QString InfoFrame::renderColorCodes(QString input) {
// We traverse the description and, when one of those is found, we create
// a span element with that color set.
//
- // TODO: Make the same logic for font formatting too.
// TODO: Wrap links inside <a> tags
+ // https://minecraft.fandom.com/wiki/Formatting_codes#Color_codes
+ const QMap<QChar, QString> color_codes_map = {
+ {'0', "#000000"}, {'1', "#0000AA"}, {'2', "#00AA00"}, {'3', "#00AAAA"}, {'4', "#AA0000"},
+ {'5', "#AA00AA"}, {'6', "#FFAA00"}, {'7', "#AAAAAA"}, {'8', "#555555"}, {'9', "#5555FF"},
+ {'a', "#55FF55"}, {'b', "#55FFFF"}, {'c', "#FF5555"}, {'d', "#FF55FF"}, {'e', "#FFFF55"},
+ {'f', "#FFFFFF"}
+ };
+ // https://minecraft.fandom.com/wiki/Formatting_codes#Formatting_codes
+ const QMap<QChar, QString> formatting_codes_map = {
+ {'l', "b"}, {'m', "s"}, {'n', "u"}, {'o', "i"}
+ };
+
QString html("<html>");
- bool in_div = false;
+ QList<QString> tags{};
auto it = input.constBegin();
while (it != input.constEnd()) {
- if (*it == u'§') {
- if (in_div)
- html += "</span>";
-
- auto const& num = *(++it);
- html += QString("<span style=\"color: %1;\">").arg(s_value_to_color.constFind(num).value());
+ // is current char § and is there a following char
+ if (*it == u'§' && (it + 1) != input.constEnd()) {
+ auto const& code = *(++it); // incrementing here!
- in_div = true;
+ auto const color_entry = color_codes_map.constFind(code);
+ auto const tag_entry = formatting_codes_map.constFind(code);
- it++;
+ if (color_entry != color_codes_map.constEnd()) { // color code
+ html += QString("<span style=\"color: %1;\">").arg(color_entry.value());
+ tags << "span";
+ } else if (tag_entry != formatting_codes_map.constEnd()) { // formatting code
+ html += QString("<%1>").arg(tag_entry.value());
+ tags << tag_entry.value();
+ } else if (code == 'r') { // reset all formatting
+ while (!tags.isEmpty()) {
+ html += QString("</%1>").arg(tags.takeLast());
+ }
+ } else { // pass unknown codes through
+ html += QString("§%1").arg(code);
+ }
+ } else {
+ html += *it;
}
-
- html += *it;
it++;
}
-
- if (in_div)
- html += "</span>";
+ while (!tags.isEmpty()) {
+ html += QString("</%1>").arg(tags.takeLast());
+ }
html += "</html>";
html.replace("\n", "<br>");
@@ -147,14 +160,14 @@ QString InfoFrame::renderColorCodes(QString input) {
void InfoFrame::updateWithResourcePack(ResourcePack& resource_pack)
{
- setName(resource_pack.name());
+ setName(renderColorCodes(resource_pack.name()));
setDescription(renderColorCodes(resource_pack.description()));
setImage(resource_pack.image({64, 64}));
}
void InfoFrame::updateWithTexturePack(TexturePack& texture_pack)
{
- setName(texture_pack.name());
+ setName(renderColorCodes(texture_pack.name()));
setDescription(renderColorCodes(texture_pack.description()));
setImage(texture_pack.image({64, 64}));
}
diff --git a/launcher/ui/widgets/ProjectItem.cpp b/launcher/ui/widgets/ProjectItem.cpp
index 56ae35fb..01be88d9 100644
--- a/launcher/ui/widgets/ProjectItem.cpp
+++ b/launcher/ui/widgets/ProjectItem.cpp
@@ -14,9 +14,7 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
QStyleOptionViewItem opt(option);
initStyleOption(&opt, index);
- auto& rect = opt.rect;
- auto icon_width = rect.height(), icon_height = rect.height();
- auto remaining_width = rect.width() - icon_width;
+ auto rect = opt.rect;
if (opt.state & QStyle::State_Selected) {
painter->fillRect(rect, opt.palette.highlight());
@@ -25,11 +23,34 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
painter->fillRect(rect, opt.palette.window());
}
- { // Icon painting
- // Square-sized, occupying the left portion
- opt.icon.paint(painter, rect.x(), rect.y(), icon_width, icon_height);
+ // The default icon size will be a square (and height is usually the lower value).
+ auto icon_width = rect.height(), icon_height = rect.height();
+ int icon_x_margin = (rect.height() - icon_width) / 2;
+ int icon_y_margin = (rect.height() - icon_height) / 2;
+
+ if (!opt.icon.isNull()) { // Icon painting
+ {
+ auto icon_size = opt.decorationSize;
+ icon_width = icon_size.width();
+ icon_height = icon_size.height();
+
+ icon_x_margin = (rect.height() - icon_width) / 2;
+ icon_y_margin = (rect.height() - icon_height) / 2;
+ }
+
+ // Centralize icon with a margin to separate from the other elements
+ int x = rect.x() + icon_x_margin;
+ int y = rect.y() + icon_y_margin;
+
+ // Prevent 'scaling null pixmap' warnings
+ if (icon_width > 0 && icon_height > 0)
+ opt.icon.paint(painter, x, y, icon_width, icon_height);
}
+ // Change the rect so that funther painting is easier
+ auto remaining_width = rect.width() - icon_width - 2 * icon_x_margin;
+ rect.setRect(rect.x() + icon_width + 2 * icon_x_margin, rect.y(), remaining_width, rect.height());
+
{ // Title painting
auto title = index.data(UserDataTypes::TITLE).toString();
@@ -46,7 +67,7 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
painter->setFont(font);
// On the top, aligned to the left after the icon
- painter->drawText(rect.x() + icon_width, rect.y() + QFontMetrics(font).height(), title);
+ painter->drawText(rect.x(), rect.y() + QFontMetrics(font).height(), title);
painter->restore();
}
@@ -70,7 +91,7 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
}
// On the bottom, aligned to the left after the icon, and featuring at most two lines of text (with some margin space to spare)
- painter->drawText(rect.x() + icon_width, rect.y() + rect.height() - 2.2 * opt.fontMetrics.height(), remaining_width,
+ painter->drawText(rect.x(), rect.y() + rect.height() - 2.2 * opt.fontMetrics.height(), remaining_width,
2 * opt.fontMetrics.height(), Qt::TextWordWrap, description);
}