add options to change the cat scalling (#3380)
This commit is contained in:
commit
9cdfeb5fcd
8 changed files with 187 additions and 56 deletions
|
@ -786,6 +786,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
|
|||
// The cat
|
||||
m_settings->registerSetting("TheCat", false);
|
||||
m_settings->registerSetting("CatOpacity", 100);
|
||||
m_settings->registerSetting("CatFit", "fit");
|
||||
|
||||
m_settings->registerSetting("StatusBarVisible", true);
|
||||
|
||||
|
|
|
@ -891,6 +891,8 @@ SET(LAUNCHER_SOURCES
|
|||
ui/themes/ThemeManager.h
|
||||
ui/themes/CatPack.cpp
|
||||
ui/themes/CatPack.h
|
||||
ui/themes/CatPainter.cpp
|
||||
ui/themes/CatPainter.h
|
||||
|
||||
# Processes
|
||||
LaunchController.h
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include <QtMath>
|
||||
|
||||
#include "VisualGroup.h"
|
||||
#include "ui/themes/CatPainter.h"
|
||||
#include "ui/themes/ThemeManager.h"
|
||||
|
||||
#include <Application.h>
|
||||
|
@ -78,6 +79,9 @@ InstanceView::~InstanceView()
|
|||
{
|
||||
qDeleteAll(m_groups);
|
||||
m_groups.clear();
|
||||
if (m_cat) {
|
||||
m_cat->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceView::setModel(QAbstractItemModel* model)
|
||||
|
@ -172,7 +176,7 @@ void InstanceView::updateScrollbar()
|
|||
|
||||
void InstanceView::updateGeometries()
|
||||
{
|
||||
geometryCache.clear();
|
||||
m_geometryCache.clear();
|
||||
|
||||
QMap<LocaleString, VisualGroup*> cats;
|
||||
|
||||
|
@ -186,8 +190,8 @@ void InstanceView::updateGeometries()
|
|||
cat->update();
|
||||
} else {
|
||||
auto cat = new VisualGroup(groupName, this);
|
||||
if (fVisibility) {
|
||||
cat->collapsed = fVisibility(groupName);
|
||||
if (m_fVisibility) {
|
||||
cat->collapsed = m_fVisibility(groupName);
|
||||
}
|
||||
cats.insert(groupName, cat);
|
||||
cat->update();
|
||||
|
@ -436,11 +440,15 @@ void InstanceView::mouseDoubleClickEvent(QMouseEvent* event)
|
|||
|
||||
void InstanceView::setPaintCat(bool visible)
|
||||
{
|
||||
m_catVisible = visible;
|
||||
if (visible)
|
||||
m_catPixmap.load(APPLICATION->themeManager()->getCatPack());
|
||||
else
|
||||
m_catPixmap = QPixmap();
|
||||
if (m_cat) {
|
||||
disconnect(m_cat, &CatPainter::updateFrame, this, nullptr);
|
||||
delete m_cat;
|
||||
m_cat = nullptr;
|
||||
}
|
||||
if (visible) {
|
||||
m_cat = new CatPainter(APPLICATION->themeManager()->getCatPack(), this);
|
||||
connect(m_cat, &CatPainter::updateFrame, this, [this] { viewport()->update(); });
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceView::paintEvent([[maybe_unused]] QPaintEvent* event)
|
||||
|
@ -449,19 +457,8 @@ void InstanceView::paintEvent([[maybe_unused]] QPaintEvent* event)
|
|||
|
||||
QPainter painter(this->viewport());
|
||||
|
||||
if (m_catVisible) {
|
||||
painter.setOpacity(APPLICATION->settings()->get("CatOpacity").toFloat() / 100);
|
||||
int widWidth = this->viewport()->width();
|
||||
int widHeight = this->viewport()->height();
|
||||
if (m_catPixmap.width() < widWidth)
|
||||
widWidth = m_catPixmap.width();
|
||||
if (m_catPixmap.height() < widHeight)
|
||||
widHeight = m_catPixmap.height();
|
||||
auto pixmap = m_catPixmap.scaled(widWidth, widHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
QRect rectOfPixmap = pixmap.rect();
|
||||
rectOfPixmap.moveBottomRight(this->viewport()->rect().bottomRight());
|
||||
painter.drawPixmap(rectOfPixmap.topLeft(), pixmap);
|
||||
painter.setOpacity(1.0);
|
||||
if (m_cat) {
|
||||
m_cat->paint(&painter, this->viewport()->rect());
|
||||
}
|
||||
|
||||
QStyleOptionViewItem option;
|
||||
|
@ -711,8 +708,8 @@ QRect InstanceView::geometryRect(const QModelIndex& index) const
|
|||
}
|
||||
|
||||
int row = index.row();
|
||||
if (geometryCache.contains(row)) {
|
||||
return *geometryCache[row];
|
||||
if (m_geometryCache.contains(row)) {
|
||||
return *m_geometryCache[row];
|
||||
}
|
||||
|
||||
const VisualGroup* cat = category(index);
|
||||
|
@ -727,7 +724,7 @@ QRect InstanceView::geometryRect(const QModelIndex& index) const
|
|||
out.setTop(cat->verticalPosition() + cat->headerHeight() + 5 + cat->rowTopOf(index));
|
||||
out.setLeft(m_spacing + x * (itemWidth() + m_spacing));
|
||||
out.setSize(itemDelegate()->sizeHint(option, index));
|
||||
geometryCache.insert(row, new QRect(out));
|
||||
m_geometryCache.insert(row, new QRect(out));
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include <QScrollBar>
|
||||
#include <functional>
|
||||
#include "VisualGroup.h"
|
||||
#include "ui/themes/CatPainter.h"
|
||||
|
||||
struct InstanceViewRoles {
|
||||
enum { GroupRole = Qt::UserRole, ProgressValueRole, ProgressMaximumRole };
|
||||
|
@ -56,7 +57,7 @@ class InstanceView : public QAbstractItemView {
|
|||
void setModel(QAbstractItemModel* model) override;
|
||||
|
||||
using visibilityFunction = std::function<bool(const QString&)>;
|
||||
void setSourceOfGroupCollapseStatus(visibilityFunction f) { fVisibility = f; }
|
||||
void setSourceOfGroupCollapseStatus(visibilityFunction f) { m_fVisibility = f; }
|
||||
|
||||
/// return geometry rectangle occupied by the specified model item
|
||||
QRect geometryRect(const QModelIndex& index) const;
|
||||
|
@ -116,7 +117,7 @@ class InstanceView : public QAbstractItemView {
|
|||
friend struct VisualGroup;
|
||||
QList<VisualGroup*> m_groups;
|
||||
|
||||
visibilityFunction fVisibility;
|
||||
visibilityFunction m_fVisibility;
|
||||
|
||||
// geometry
|
||||
int m_leftMargin = 5;
|
||||
|
@ -127,9 +128,8 @@ class InstanceView : public QAbstractItemView {
|
|||
int m_itemWidth = 100;
|
||||
int m_currentItemsPerRow = -1;
|
||||
int m_currentCursorColumn = -1;
|
||||
mutable QCache<int, QRect> geometryCache;
|
||||
bool m_catVisible = false;
|
||||
QPixmap m_catPixmap;
|
||||
mutable QCache<int, QRect> m_geometryCache;
|
||||
CatPainter* m_cat = nullptr;
|
||||
|
||||
// point where the currently active mouse action started in geometry coordinates
|
||||
QPoint m_pressedPosition;
|
||||
|
|
51
launcher/ui/themes/CatPainter.cpp
Normal file
51
launcher/ui/themes/CatPainter.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2025 Trial97 <alexandru.tripon97@gmail.com>
|
||||
*
|
||||
* 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 "ui/themes/CatPainter.h"
|
||||
#include <QPixmap>
|
||||
#include "Application.h"
|
||||
|
||||
CatPainter::CatPainter(const QString& path, QObject* parent) : QObject(parent)
|
||||
{
|
||||
m_image = QPixmap(path);
|
||||
}
|
||||
|
||||
void CatPainter::paint(QPainter* painter, const QRect& viewport)
|
||||
{
|
||||
QPixmap frame = m_image;
|
||||
|
||||
auto fit = APPLICATION->settings()->get("CatFit").toString();
|
||||
painter->setOpacity(APPLICATION->settings()->get("CatOpacity").toFloat() / 100);
|
||||
int widWidth = viewport.width();
|
||||
int widHeight = viewport.height();
|
||||
auto aspectMode = Qt::IgnoreAspectRatio;
|
||||
if (fit == "fill") {
|
||||
aspectMode = Qt::KeepAspectRatio;
|
||||
} else if (fit == "fit") {
|
||||
aspectMode = Qt::KeepAspectRatio;
|
||||
if (frame.width() < widWidth)
|
||||
widWidth = frame.width();
|
||||
if (frame.height() < widHeight)
|
||||
widHeight = frame.height();
|
||||
}
|
||||
auto pixmap = frame.scaled(widWidth, widHeight, aspectMode, Qt::SmoothTransformation);
|
||||
QRect rectOfPixmap = pixmap.rect();
|
||||
rectOfPixmap.moveBottomRight(viewport.bottomRight());
|
||||
painter->drawPixmap(rectOfPixmap.topLeft(), pixmap);
|
||||
painter->setOpacity(1.0);
|
||||
};
|
38
launcher/ui/themes/CatPainter.h
Normal file
38
launcher/ui/themes/CatPainter.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2025 Trial97 <alexandru.tripon97@gmail.com>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QMovie>
|
||||
#include <QPainter>
|
||||
#include <QPixmap>
|
||||
#include <QString>
|
||||
|
||||
class CatPainter : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
CatPainter(const QString& path, QObject* parent = nullptr);
|
||||
virtual ~CatPainter() = default;
|
||||
void paint(QPainter*, const QRect&);
|
||||
|
||||
signals:
|
||||
void updateFrame();
|
||||
|
||||
private:
|
||||
QPixmap m_image;
|
||||
};
|
|
@ -97,22 +97,28 @@ void AppearanceWidget::applySettings()
|
|||
settings->set("ConsoleFont", consoleFontFamily);
|
||||
settings->set("ConsoleFontSize", m_ui->fontSizeBox->value());
|
||||
settings->set("CatOpacity", m_ui->catOpacitySlider->value());
|
||||
auto catFit = m_ui->catFitComboBox->currentIndex();
|
||||
settings->set("CatFit", catFit == 0 ? "fit" : catFit == 1 ? "fill" : "strech");
|
||||
}
|
||||
|
||||
void AppearanceWidget::loadSettings()
|
||||
{
|
||||
QString fontFamily = APPLICATION->settings()->get("ConsoleFont").toString();
|
||||
SettingsObjectPtr settings = APPLICATION->settings();
|
||||
QString fontFamily = settings->get("ConsoleFont").toString();
|
||||
QFont consoleFont(fontFamily);
|
||||
m_ui->consoleFont->setCurrentFont(consoleFont);
|
||||
|
||||
bool conversionOk = true;
|
||||
int fontSize = APPLICATION->settings()->get("ConsoleFontSize").toInt(&conversionOk);
|
||||
int fontSize = settings->get("ConsoleFontSize").toInt(&conversionOk);
|
||||
if (!conversionOk) {
|
||||
fontSize = 11;
|
||||
}
|
||||
m_ui->fontSizeBox->setValue(fontSize);
|
||||
|
||||
m_ui->catOpacitySlider->setValue(APPLICATION->settings()->get("CatOpacity").toInt());
|
||||
m_ui->catOpacitySlider->setValue(settings->get("CatOpacity").toInt());
|
||||
|
||||
auto catFit = settings->get("CatFit").toString();
|
||||
m_ui->catFitComboBox->setCurrentIndex(catFit == "fit" ? 0 : catFit == "fill" ? 1 : 2);
|
||||
}
|
||||
|
||||
void AppearanceWidget::retranslateUi()
|
||||
|
@ -245,9 +251,7 @@ void AppearanceWidget::updateConsolePreview()
|
|||
workCursor.insertBlock();
|
||||
};
|
||||
|
||||
print(QString("%1 version: %2\n")
|
||||
.arg(BuildConfig.LAUNCHER_DISPLAYNAME, BuildConfig.printableVersionString()),
|
||||
MessageLevel::Launcher);
|
||||
print(QString("%1 version: %2\n").arg(BuildConfig.LAUNCHER_DISPLAYNAME, BuildConfig.printableVersionString()), MessageLevel::Launcher);
|
||||
|
||||
QDate today = QDate::currentDate();
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>700</height>
|
||||
<height>711</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
|
@ -203,6 +203,53 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="catFitLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Fit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="catFitComboBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>77</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Fit</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Fill</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Stretch</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="catOpacityLabel">
|
||||
<property name="text">
|
||||
|
@ -372,8 +419,7 @@
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="new">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
<iconset theme="new"/>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
|
@ -389,8 +435,7 @@
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="centralmods">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
<iconset theme="centralmods"/>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
|
@ -406,8 +451,7 @@
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="viewfolder">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
<iconset theme="viewfolder"/>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
|
@ -423,8 +467,7 @@
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="launch">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
<iconset theme="launch"/>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
|
@ -440,8 +483,7 @@
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="copy">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
<iconset theme="copy"/>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
|
@ -457,8 +499,7 @@
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="export">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
<iconset theme="export"/>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
|
@ -474,8 +515,7 @@
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="delete">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
<iconset theme="delete"/>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
|
@ -491,8 +531,7 @@
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="about">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
<iconset theme="about"/>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
|
@ -508,8 +547,7 @@
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="settings">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
<iconset theme="settings"/>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
|
@ -525,8 +563,7 @@
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="cat">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
<iconset theme="cat"/>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
|
@ -586,6 +623,7 @@
|
|||
<tabstop>reloadThemesButton</tabstop>
|
||||
<tabstop>consoleFont</tabstop>
|
||||
<tabstop>fontSizeBox</tabstop>
|
||||
<tabstop>catFitComboBox</tabstop>
|
||||
<tabstop>catOpacitySlider</tabstop>
|
||||
<tabstop>consolePreview</tabstop>
|
||||
</tabstops>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue