diff options
author | Tayou <31988415+TayouVR@users.noreply.github.com> | 2023-07-03 15:46:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-03 15:46:56 +0200 |
commit | dedc9e4edc2769c62f33b6564f3009414245d9f3 (patch) | |
tree | 372a664d21adc6641a305cbeafc32c6b67ed7d40 | |
parent | 43e6f05ed5931180f04681f8c7cb255b23f293bd (diff) | |
parent | 0008b22d8b352e3591ee7ba7c6d9313ed23cbd4a (diff) | |
download | PrismLauncher-dedc9e4edc2769c62f33b6564f3009414245d9f3.tar.gz PrismLauncher-dedc9e4edc2769c62f33b6564f3009414245d9f3.tar.bz2 PrismLauncher-dedc9e4edc2769c62f33b6564f3009414245d9f3.zip |
Merge pull request #1127 from Trial97/scale_cat
-rw-r--r-- | launcher/ui/MainWindow.cpp | 17 | ||||
-rw-r--r-- | launcher/ui/instanceview/InstanceView.cpp | 26 | ||||
-rw-r--r-- | launcher/ui/instanceview/InstanceView.h | 8 |
3 files changed, 31 insertions, 20 deletions
diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 496738e3..515abf07 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -927,21 +927,8 @@ void MainWindow::onCatToggled(bool state) void MainWindow::setCatBackground(bool enabled) { - if (enabled) { - view->setStyleSheet(QString(R"( -InstanceView -{ - background-image: url(:/backgrounds/%1); - background-attachment: fixed; - background-clip: padding; - background-position: bottom right; - background-repeat: none; - background-color:palette(base); -})") - .arg(ThemeManager::getCatImage())); - } else { - view->setStyleSheet(QString()); - } + view->setPaintCat(enabled); + view->viewport()->repaint(); } void MainWindow::runModalTask(Task *task) diff --git a/launcher/ui/instanceview/InstanceView.cpp b/launcher/ui/instanceview/InstanceView.cpp index fbeffe35..1911dd59 100644 --- a/launcher/ui/instanceview/InstanceView.cpp +++ b/launcher/ui/instanceview/InstanceView.cpp @@ -48,6 +48,7 @@ #include <QAccessible> #include "VisualGroup.h" +#include "ui/themes/ThemeManager.h" #include <QDebug> #include <Application.h> @@ -73,6 +74,7 @@ InstanceView::InstanceView(QWidget *parent) setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); setAcceptDrops(true); setAutoScroll(true); + setPaintCat(APPLICATION->settings()->get("TheCat").toBool()); } InstanceView::~InstanceView() @@ -498,12 +500,34 @@ void InstanceView::mouseDoubleClickEvent(QMouseEvent *event) } } -void InstanceView::paintEvent(QPaintEvent *event) +void InstanceView::setPaintCat(bool visible) +{ + m_catVisible = visible; + if (visible) + m_catPixmap.load(QString(":/backgrounds/%1").arg(ThemeManager::getCatImage())); + else + m_catPixmap = QPixmap(); +} + +void InstanceView::paintEvent(QPaintEvent* event) { executeDelayedItemsLayout(); QPainter painter(this->viewport()); + if (m_catVisible) { + 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); + QRect rectOfPixmap = pixmap.rect(); + rectOfPixmap.moveBottomRight(this->viewport()->rect().bottomRight()); + painter.drawPixmap(rectOfPixmap.topLeft(), pixmap); + } + #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) QStyleOptionViewItem option; initViewItemOption(&option); diff --git a/launcher/ui/instanceview/InstanceView.h b/launcher/ui/instanceview/InstanceView.h index ac338274..36405675 100644 --- a/launcher/ui/instanceview/InstanceView.h +++ b/launcher/ui/instanceview/InstanceView.h @@ -85,10 +85,8 @@ public: virtual QRegion visualRegionForSelection(const QItemSelection &selection) const override; - int spacing() const - { - return m_spacing; - }; + int spacing() const { return m_spacing; }; + void setPaintCat(bool visible); public slots: virtual void updateGeometries() override; @@ -139,6 +137,8 @@ private: int m_currentItemsPerRow = -1; int m_currentCursorColumn= -1; mutable QCache<int, QRect> geometryCache; + bool m_catVisible = false; + QPixmap m_catPixmap; // point where the currently active mouse action started in geometry coordinates QPoint m_pressedPosition; |