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 <KDecoration2/DecorationButton>
0009 #include <QColor>
0010 #include <QPointer>
0011 #include <QQuickPaintedItem>
0012 
0013 namespace KDecoration2
0014 {
0015 class Decoration;
0016 
0017 namespace Preview
0018 {
0019 class PreviewBridge;
0020 class Settings;
0021 
0022 class PreviewButtonItem : public QQuickPaintedItem
0023 {
0024     Q_OBJECT
0025     Q_PROPERTY(KDecoration2::Preview::PreviewBridge *bridge READ bridge WRITE setBridge NOTIFY bridgeChanged)
0026     Q_PROPERTY(KDecoration2::Preview::Settings *settings READ settings WRITE setSettings NOTIFY settingsChanged)
0027     Q_PROPERTY(int type READ typeAsInt WRITE setType NOTIFY typeChanged)
0028     Q_PROPERTY(QColor color READ color WRITE setColor)
0029 
0030 public:
0031     explicit PreviewButtonItem(QQuickItem *parent = nullptr);
0032     ~PreviewButtonItem() override;
0033     void paint(QPainter *painter) override;
0034 
0035     PreviewBridge *bridge() const;
0036     void setBridge(PreviewBridge *bridge);
0037 
0038     Settings *settings() const;
0039     void setSettings(Settings *settings);
0040 
0041     KDecoration2::DecorationButtonType type() const;
0042     int typeAsInt() const;
0043     void setType(KDecoration2::DecorationButtonType type);
0044     void setType(int type);
0045 
0046     const QColor &color() const
0047     {
0048         return m_color;
0049     }
0050     void setColor(const QColor &color);
0051 
0052 Q_SIGNALS:
0053     void bridgeChanged();
0054     void typeChanged();
0055     void settingsChanged();
0056 
0057 protected:
0058     void componentComplete() override;
0059 
0060 private:
0061     void createButton();
0062     void syncGeometry();
0063     QColor m_color;
0064     QPointer<KDecoration2::Preview::PreviewBridge> m_bridge;
0065     QPointer<KDecoration2::Preview::Settings> m_settings;
0066     KDecoration2::Decoration *m_decoration = nullptr;
0067     KDecoration2::DecorationButton *m_button = nullptr;
0068     KDecoration2::DecorationButtonType m_type = KDecoration2::DecorationButtonType::Custom;
0069 };
0070 
0071 } // Preview
0072 } // KDecoration2