KWin
Loading...
Searching...
No Matches
thumbnailitem.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2011, 2014 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#include "thumbnailitem.h"
11// Qt
12#include <QDebug>
13#include <QQuickWindow>
14#include <QSGImageNode>
15#include <QStandardPaths>
16
17namespace KWin
18{
19
21 : QQuickItem(parent)
22 , m_wId(0)
23 , m_image()
24 , m_sourceSize(QSize())
25{
26 setFlag(ItemHasContents);
27}
28
32
33void WindowThumbnailItem::setWId(qulonglong wId)
34{
35 m_wId = wId;
36 Q_EMIT wIdChanged(wId);
37 findImage();
38}
39
40void WindowThumbnailItem::findImage()
41{
42 QString imagePath;
43 switch (m_wId) {
44 case Konqueror:
45 imagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kwin/kcm_kwintabbox/falkon.png");
46 break;
47 case Systemsettings:
48 imagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kwin/kcm_kwintabbox/systemsettings.png");
49 break;
50 case KMail:
51 imagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kwin/kcm_kwintabbox/kmail.png");
52 break;
53 case Dolphin:
54 imagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kwin/kcm_kwintabbox/dolphin.png");
55 break;
56 case Desktop:
57 imagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "wallpapers/Next/contents/images/1280x800.png");
58 if (imagePath.isNull()) {
59 imagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kwin/kcm_kwintabbox/desktop.png");
60 }
61 break;
62 default:
63 // ignore
64 break;
65 }
66 if (imagePath.isNull()) {
67 m_image = QImage();
68 } else {
69 m_image = QImage(imagePath);
70 }
71
72 setImplicitSize(m_image.width(), m_image.height());
73}
74
75QSGNode *WindowThumbnailItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
76{
77 auto *node = static_cast<QSGImageNode *>(oldNode);
78 if (!node) {
79 node = window()->createImageNode();
80 node->setOwnsTexture(true);
81 qsgnode_set_description(node, QStringLiteral("windowthumbnail"));
82 node->setFiltering(QSGTexture::Linear);
83 }
84
85 node->setTexture(window()->createTextureFromImage(m_image));
86
87 const QSize size(m_image.size().scaled(boundingRect().size().toSize(), Qt::KeepAspectRatio));
88 const qreal x = boundingRect().x() + (boundingRect().width() - size.width()) / 2;
89 const qreal y = boundingRect().y() + (boundingRect().height() - size.height()) / 2;
90
91 node->setRect(QRectF(QPointF(x, y), size));
92
93 return node;
94}
95
97{
98 return m_sourceSize;
99}
100
102{
103 if (m_sourceSize == size) {
104 return;
105 }
106 m_sourceSize = size;
107 update();
108 Q_EMIT sourceSizeChanged();
109}
110
111} // namespace KWin
112
113#include "moc_thumbnailitem.cpp"
void setWId(qulonglong wId)
QSGNode * updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) override
void setSourceSize(const QSize &size)
WindowThumbnailItem(QQuickItem *parent=nullptr)