File indexing completed on 2024-11-10 04:56:47
0001 /* 0002 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 #pragma once 0007 0008 #include <QPointer> 0009 #include <QQuickPaintedItem> 0010 0011 namespace KDecoration2 0012 { 0013 class Decoration; 0014 class DecorationShadow; 0015 class DecorationSettings; 0016 0017 namespace Preview 0018 { 0019 class PreviewBridge; 0020 class PreviewClient; 0021 class Settings; 0022 0023 class PreviewItem : public QQuickPaintedItem 0024 { 0025 Q_OBJECT 0026 Q_PROPERTY(KDecoration2::Decoration *decoration READ decoration NOTIFY decorationChanged) 0027 Q_PROPERTY(KDecoration2::Preview::PreviewBridge *bridge READ bridge WRITE setBridge NOTIFY bridgeChanged) 0028 Q_PROPERTY(KDecoration2::Preview::Settings *settings READ settings WRITE setSettings NOTIFY settingsChanged) 0029 Q_PROPERTY(KDecoration2::Preview::PreviewClient *client READ client) 0030 Q_PROPERTY(KDecoration2::DecorationShadow *shadow READ shadow NOTIFY shadowChanged) 0031 Q_PROPERTY(QColor windowColor READ windowColor WRITE setWindowColor NOTIFY windowColorChanged) 0032 Q_PROPERTY(bool drawBackground READ isDrawingBackground WRITE setDrawingBackground NOTIFY drawingBackgroundChanged) 0033 public: 0034 PreviewItem(QQuickItem *parent = nullptr); 0035 ~PreviewItem() override; 0036 void paint(QPainter *painter) override; 0037 0038 KDecoration2::Decoration *decoration() const; 0039 void setDecoration(KDecoration2::Decoration *deco); 0040 0041 QColor windowColor() const; 0042 void setWindowColor(const QColor &color); 0043 0044 bool isDrawingBackground() const; 0045 void setDrawingBackground(bool set); 0046 0047 PreviewBridge *bridge() const; 0048 void setBridge(PreviewBridge *bridge); 0049 0050 Settings *settings() const; 0051 void setSettings(Settings *settings); 0052 0053 PreviewClient *client(); 0054 DecorationShadow *shadow() const; 0055 0056 Q_SIGNALS: 0057 void decorationChanged(KDecoration2::Decoration *deco); 0058 void windowColorChanged(const QColor &color); 0059 void drawingBackgroundChanged(bool); 0060 void bridgeChanged(); 0061 void settingsChanged(); 0062 void shadowChanged(); 0063 0064 protected: 0065 void mouseDoubleClickEvent(QMouseEvent *event) override; 0066 void mouseMoveEvent(QMouseEvent *event) override; 0067 void mousePressEvent(QMouseEvent *event) override; 0068 void mouseReleaseEvent(QMouseEvent *event) override; 0069 void hoverEnterEvent(QHoverEvent *event) override; 0070 void hoverLeaveEvent(QHoverEvent *event) override; 0071 void hoverMoveEvent(QHoverEvent *event) override; 0072 void componentComplete() override; 0073 0074 private: 0075 void paintShadow(QPainter *painter, int &paddingLeft, int &paddingRight, int &paddingTop, int &paddingBottom); 0076 template <typename E> 0077 void proxyPassEvent(E *event) const; 0078 void syncSize(); 0079 void createDecoration(); 0080 Decoration *m_decoration; 0081 QColor m_windowColor; 0082 bool m_drawBackground = true; 0083 QPointer<KDecoration2::Preview::PreviewBridge> m_bridge; 0084 QPointer<KDecoration2::Preview::Settings> m_settings; 0085 QPointer<KDecoration2::Preview::PreviewClient> m_client; 0086 }; 0087 0088 } // Preview 0089 } // KDecoration2