File indexing completed on 2024-11-10 04:56:48
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/DecorationSettings> 0009 #include <KDecoration2/Private/DecorationSettingsPrivate> 0010 #include <QAbstractListModel> 0011 #include <QObject> 0012 #include <QPointer> 0013 0014 namespace KDecoration2 0015 { 0016 0017 namespace Preview 0018 { 0019 class ButtonsModel; 0020 class PreviewBridge; 0021 0022 class BorderSizesModel : public QAbstractListModel 0023 { 0024 Q_OBJECT 0025 public: 0026 explicit BorderSizesModel(QObject *parent = nullptr); 0027 ~BorderSizesModel() override; 0028 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0029 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0030 QHash<int, QByteArray> roleNames() const override; 0031 0032 private: 0033 QList<BorderSize> m_borders = QList<BorderSize>({BorderSize::None, 0034 BorderSize::NoSides, 0035 BorderSize::Tiny, 0036 BorderSize::Normal, 0037 BorderSize::Large, 0038 BorderSize::VeryLarge, 0039 BorderSize::Huge, 0040 BorderSize::VeryHuge, 0041 BorderSize::Oversized}); 0042 }; 0043 0044 class PreviewSettings : public QObject, public DecorationSettingsPrivate 0045 { 0046 Q_OBJECT 0047 Q_PROPERTY(bool onAllDesktopsAvailable READ isOnAllDesktopsAvailable WRITE setOnAllDesktopsAvailable NOTIFY onAllDesktopsAvailableChanged) 0048 Q_PROPERTY(bool alphaChannelSupported READ isAlphaChannelSupported WRITE setAlphaChannelSupported NOTIFY alphaChannelSupportedChanged) 0049 Q_PROPERTY(bool closeOnDoubleClickOnMenu READ isCloseOnDoubleClickOnMenu WRITE setCloseOnDoubleClickOnMenu NOTIFY closeOnDoubleClickOnMenuChanged) 0050 Q_PROPERTY(QAbstractItemModel *leftButtonsModel READ leftButtonsModel CONSTANT) 0051 Q_PROPERTY(QAbstractItemModel *rightButtonsModel READ rightButtonsModel CONSTANT) 0052 Q_PROPERTY(QAbstractItemModel *availableButtonsModel READ availableButtonsModel CONSTANT) 0053 Q_PROPERTY(QAbstractItemModel *borderSizesModel READ borderSizesModel CONSTANT) 0054 Q_PROPERTY(int borderSizesIndex READ borderSizesIndex WRITE setBorderSizesIndex NOTIFY borderSizesIndexChanged) 0055 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) 0056 public: 0057 explicit PreviewSettings(DecorationSettings *parent); 0058 ~PreviewSettings() override; 0059 bool isAlphaChannelSupported() const override; 0060 bool isOnAllDesktopsAvailable() const override; 0061 bool isCloseOnDoubleClickOnMenu() const override 0062 { 0063 return m_closeOnDoubleClick; 0064 } 0065 BorderSize borderSize() const override; 0066 0067 void setOnAllDesktopsAvailable(bool available); 0068 void setAlphaChannelSupported(bool supported); 0069 void setCloseOnDoubleClickOnMenu(bool enabled); 0070 0071 QAbstractItemModel *leftButtonsModel() const; 0072 QAbstractItemModel *rightButtonsModel() const; 0073 QAbstractItemModel *availableButtonsModel() const; 0074 QAbstractItemModel *borderSizesModel() const 0075 { 0076 return m_borderSizes; 0077 } 0078 0079 QList<DecorationButtonType> decorationButtonsLeft() const override; 0080 QList<DecorationButtonType> decorationButtonsRight() const override; 0081 0082 Q_INVOKABLE void addButtonToLeft(int row); 0083 Q_INVOKABLE void addButtonToRight(int row); 0084 0085 int borderSizesIndex() const 0086 { 0087 return m_borderSize; 0088 } 0089 void setBorderSizesIndex(int index); 0090 0091 QFont font() const override 0092 { 0093 return m_font; 0094 } 0095 void setFont(const QFont &font); 0096 0097 Q_SIGNALS: 0098 void onAllDesktopsAvailableChanged(bool); 0099 void alphaChannelSupportedChanged(bool); 0100 void closeOnDoubleClickOnMenuChanged(bool); 0101 void borderSizesIndexChanged(int); 0102 void fontChanged(const QFont &); 0103 0104 private: 0105 bool m_alphaChannelSupported; 0106 bool m_onAllDesktopsAvailable; 0107 bool m_closeOnDoubleClick; 0108 ButtonsModel *m_leftButtons; 0109 ButtonsModel *m_rightButtons; 0110 ButtonsModel *m_availableButtons; 0111 BorderSizesModel *m_borderSizes; 0112 int m_borderSize; 0113 QFont m_font; 0114 }; 0115 0116 class Settings : public QObject 0117 { 0118 Q_OBJECT 0119 Q_PROPERTY(KDecoration2::Preview::PreviewBridge *bridge READ bridge WRITE setBridge NOTIFY bridgeChanged) 0120 Q_PROPERTY(KDecoration2::DecorationSettings *settings READ settingsPointer NOTIFY settingsChanged) 0121 Q_PROPERTY(int borderSizesIndex READ borderSizesIndex WRITE setBorderSizesIndex NOTIFY borderSizesIndexChanged) 0122 public: 0123 explicit Settings(QObject *parent = nullptr); 0124 ~Settings() override; 0125 0126 PreviewBridge *bridge() const; 0127 void setBridge(PreviewBridge *bridge); 0128 0129 std::shared_ptr<DecorationSettings> settings() const; 0130 DecorationSettings *settingsPointer() const; 0131 int borderSizesIndex() const 0132 { 0133 return m_borderSize; 0134 } 0135 void setBorderSizesIndex(int index); 0136 0137 Q_SIGNALS: 0138 void bridgeChanged(); 0139 void settingsChanged(); 0140 void borderSizesIndexChanged(int); 0141 0142 private: 0143 void createSettings(); 0144 QPointer<PreviewBridge> m_bridge; 0145 std::shared_ptr<KDecoration2::DecorationSettings> m_settings; 0146 PreviewSettings *m_previewSettings = nullptr; 0147 int m_borderSize = 3; 0148 }; 0149 0150 } 0151 }