Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made cat scalable #1127

Merged
merged 4 commits into from Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 2 additions & 15 deletions launcher/ui/MainWindow.cpp
Expand Up @@ -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)
Expand Down
26 changes: 25 additions & 1 deletion launcher/ui/instanceview/InstanceView.cpp
Expand Up @@ -48,6 +48,7 @@
#include <QAccessible>

#include "VisualGroup.h"
#include "ui/themes/ThemeManager.h"
#include <QDebug>

#include <Application.h>
Expand All @@ -73,6 +74,7 @@ InstanceView::InstanceView(QWidget *parent)
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setAcceptDrops(true);
setAutoScroll(true);
setPaintCat(APPLICATION->settings()->get("TheCat").toBool());
}

InstanceView::~InstanceView()
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions launcher/ui/instanceview/InstanceView.h
Expand Up @@ -85,10 +85,8 @@ class InstanceView : public QAbstractItemView

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;
Expand Down Expand Up @@ -139,6 +137,8 @@ protected slots:
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;
Expand Down