File indexing completed on 2024-11-10 04:56:52
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2011, 2014 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include "thumbnailitem.h" 0011 // Qt 0012 #include <QDebug> 0013 #include <QQuickWindow> 0014 #include <QSGImageNode> 0015 #include <QStandardPaths> 0016 0017 namespace KWin 0018 { 0019 0020 WindowThumbnailItem::WindowThumbnailItem(QQuickItem *parent) 0021 : QQuickItem(parent) 0022 , m_wId(0) 0023 , m_image() 0024 , m_sourceSize(QSize()) 0025 { 0026 setFlag(ItemHasContents); 0027 } 0028 0029 WindowThumbnailItem::~WindowThumbnailItem() 0030 { 0031 } 0032 0033 void WindowThumbnailItem::setWId(qulonglong wId) 0034 { 0035 m_wId = wId; 0036 Q_EMIT wIdChanged(wId); 0037 findImage(); 0038 } 0039 0040 void WindowThumbnailItem::findImage() 0041 { 0042 QString imagePath; 0043 switch (m_wId) { 0044 case Konqueror: 0045 imagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kwin/kcm_kwintabbox/falkon.png"); 0046 break; 0047 case Systemsettings: 0048 imagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kwin/kcm_kwintabbox/systemsettings.png"); 0049 break; 0050 case KMail: 0051 imagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kwin/kcm_kwintabbox/kmail.png"); 0052 break; 0053 case Dolphin: 0054 imagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kwin/kcm_kwintabbox/dolphin.png"); 0055 break; 0056 case Desktop: 0057 imagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "wallpapers/Next/contents/images/1280x800.png"); 0058 if (imagePath.isNull()) { 0059 imagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kwin/kcm_kwintabbox/desktop.png"); 0060 } 0061 break; 0062 default: 0063 // ignore 0064 break; 0065 } 0066 if (imagePath.isNull()) { 0067 m_image = QImage(); 0068 } else { 0069 m_image = QImage(imagePath); 0070 } 0071 0072 setImplicitSize(m_image.width(), m_image.height()); 0073 } 0074 0075 QSGNode *WindowThumbnailItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) 0076 { 0077 auto *node = static_cast<QSGImageNode *>(oldNode); 0078 if (!node) { 0079 node = window()->createImageNode(); 0080 node->setOwnsTexture(true); 0081 qsgnode_set_description(node, QStringLiteral("windowthumbnail")); 0082 node->setFiltering(QSGTexture::Linear); 0083 } 0084 0085 node->setTexture(window()->createTextureFromImage(m_image)); 0086 0087 const QSize size(m_image.size().scaled(boundingRect().size().toSize(), Qt::KeepAspectRatio)); 0088 const qreal x = boundingRect().x() + (boundingRect().width() - size.width()) / 2; 0089 const qreal y = boundingRect().y() + (boundingRect().height() - size.height()) / 2; 0090 0091 node->setRect(QRectF(QPointF(x, y), size)); 0092 0093 return node; 0094 } 0095 0096 QSize WindowThumbnailItem::sourceSize() const 0097 { 0098 return m_sourceSize; 0099 } 0100 0101 void WindowThumbnailItem::setSourceSize(const QSize &size) 0102 { 0103 if (m_sourceSize == size) { 0104 return; 0105 } 0106 m_sourceSize = size; 0107 update(); 0108 Q_EMIT sourceSizeChanged(); 0109 } 0110 0111 } // namespace KWin 0112 0113 #include "moc_thumbnailitem.cpp"