File indexing completed on 2024-04-28 16:55:25
0001 /* 0002 * kwin_smaragd.h - Emerald window decoration for KDE 0003 * 0004 * Copyright (c) 2010 Christoph Feck <christoph@maxiom.de> 0005 * 0006 * This program is free software; you can redistribute it and/or modify 0007 * it under the terms of the GNU General Public License as published by 0008 * the Free Software Foundation; either version 2 of the License, or 0009 * (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program; if not, write to the Free Software 0018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 0019 * 0020 */ 0021 0022 #ifndef KWIN_SMARAGD_H 0023 #define KWIN_SMARAGD_H 1 0024 0025 #include <KDecoration2/Decoration> 0026 #include <KDecoration2/DecorationButton> 0027 0028 #include <QVariantList> 0029 0030 #include "shadowengine.h" 0031 0032 namespace KDecoration2 { class DecorationButtonGroup; } 0033 class QPropertyAnimation; 0034 0035 extern "C" 0036 { 0037 typedef struct _window_settings window_settings; 0038 } 0039 0040 namespace Smaragd 0041 { 0042 0043 class Config 0044 { 0045 public: 0046 bool useKWinTextColors; 0047 bool useKWinShadows; 0048 int hoverDuration; 0049 0050 ShadowSettings shadowSettings; 0051 QImage shadowImage; 0052 }; 0053 0054 class DecorationFactory 0055 { 0056 public: 0057 DecorationFactory(); 0058 ~DecorationFactory(); 0059 0060 public: 0061 window_settings *windowSettings() const { return ws; } 0062 const Config *config() const { return &m_config; } 0063 0064 QRegion cornerShape(int corner) const; 0065 QImage decorationImage(const QSize &size, bool active, int state, const QRect &titleRect = QRect()) const; 0066 QImage buttonImage(const QSize &size, bool active, int button, int state) const; 0067 0068 void setFontHeight(int fontHeight); 0069 0070 private: 0071 window_settings *ws; // must be first entry because of inline method to access it 0072 Config m_config; 0073 0074 QRegion cornerRegion[4]; 0075 }; 0076 0077 class Decoration : public KDecoration2::Decoration 0078 { 0079 Q_OBJECT 0080 0081 public: 0082 explicit Decoration(QObject *parent = Q_NULLPTR, const QVariantList &args = QVariantList()); 0083 ~Decoration() Q_DECL_OVERRIDE; 0084 0085 public: 0086 DecorationFactory *factory() { return &m_factory; } 0087 void init() Q_DECL_OVERRIDE; 0088 void paint(QPainter *painter, const QRect &repaintArea) Q_DECL_OVERRIDE; 0089 0090 void parseButtonLayout(char *p); 0091 0092 private Q_SLOTS: 0093 void updateLayout(); 0094 0095 public: 0096 int buttonGlyph(KDecoration2::DecorationButtonType type) const; 0097 0098 private: 0099 DecorationFactory m_factory; 0100 KDecoration2::DecorationButtonGroup *m_buttonGroup[3]; 0101 int m_titleLeft; 0102 int m_titleRight; 0103 }; 0104 0105 class DecorationButton : public KDecoration2::DecorationButton 0106 { 0107 Q_OBJECT 0108 Q_PROPERTY(qreal hoverProgress READ hoverProgress WRITE setHoverProgress); 0109 0110 public: 0111 DecorationButton(KDecoration2::DecorationButtonType type, Decoration *parent); 0112 ~DecorationButton(); 0113 0114 qreal hoverProgress() const; 0115 void setHoverProgress(qreal hoverProgress); 0116 0117 void paintGlow(QPainter *painter, const QRect &repaintArea); 0118 0119 protected: 0120 void paint(QPainter *painter, const QRect &repaintArea) Q_DECL_OVERRIDE; 0121 void hoverEnterEvent(QHoverEvent *event) Q_DECL_OVERRIDE; 0122 void hoverLeaveEvent(QHoverEvent *event) Q_DECL_OVERRIDE; 0123 0124 private: 0125 void startHoverAnimation(qreal endValue); 0126 0127 private: 0128 QPointer<QPropertyAnimation> m_hoverAnimation; 0129 qreal m_hoverProgress; 0130 }; 0131 0132 }; // namespace Smaragd 0133 0134 #endif 0135