Krita Source Code Documentation
Loading...
Searching...
No Matches
KisSplashPreview.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#include "KisSplashPreview.h"
3#include <QPainter>
4
6 : QWidget(parent)
7{
8}
9
10void KisSplashPreview::setPixmap(const QPixmap &pixmap)
11{
12 if (pixmap.cacheKey() != m_originalPixmap.cacheKey()) {
13 m_originalPixmap = pixmap;
14 m_scaledPixmap = QPixmap();
15 update();
16 }
17}
18
19void KisSplashPreview::paintEvent(QPaintEvent *event)
20{
21 QWidget::paintEvent(event);
22
23 if (!m_originalPixmap.isNull()) {
24 qreal dpr = qMax(1.0, devicePixelRatioF());
25 int w = width();
26 int h = height();
27
28 if (m_scaledPixmap.isNull()) {
29 m_scaledPixmap = m_originalPixmap.scaled(qRound(qreal(w) * dpr),
30 qRound(qreal(h) * dpr),
31 Qt::KeepAspectRatio,
32 Qt::SmoothTransformation);
33 }
34
35 int pw = qRound(qreal(m_scaledPixmap.width()) / dpr);
36 int ph = qRound(qreal(m_scaledPixmap.height()) / dpr);
37 int x = (w - pw) / 2;
38 int y = (h - ph) / 2;
39
40 QPainter painter(this);
41 painter.drawPixmap(QRect(x, y, pw, ph), m_scaledPixmap);
42 }
43}
44
45void KisSplashPreview::resizeEvent(QResizeEvent *event)
46{
47 QWidget::resizeEvent(event);
48 m_scaledPixmap = QPixmap();
49}
void setPixmap(const QPixmap &pixmap)
KisSplashPreview(QWidget *parent=nullptr)
void paintEvent(QPaintEvent *event) override
void resizeEvent(QResizeEvent *event) override