File indexing completed on 2024-05-05 05:35:16
0001 #ifndef oxygenbutton_h 0002 #define oxygenbutton_h 0003 0004 /* 0005 * SPDX-FileCopyrightText: 2006, 2007 Riccardo Iaconelli <riccardo@kde.org> 0006 * SPDX-FileCopyrightText: 2006, 2007 Casper Boemann <cbr@boemann.dk> 0007 * SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr> 0008 * SPDX-FileCopyrightText: 2015 David Edmundson <davidedmundson@kde.org> 0009 * 0010 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0011 */ 0012 0013 #include "oxygen.h" 0014 #include "oxygenanimation.h" 0015 #include "oxygendecohelper.h" 0016 #include "oxygendecoration.h" 0017 0018 #include <KDecoration2/DecorationButton> 0019 0020 namespace Oxygen 0021 { 0022 class Button : public KDecoration2::DecorationButton 0023 { 0024 Q_OBJECT 0025 0026 //* declare active state opacity 0027 Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity) 0028 0029 public: 0030 //* constructor 0031 explicit Button(QObject *parent, const QVariantList &args); 0032 0033 //* button creation 0034 static Button *create(KDecoration2::DecorationButtonType type, KDecoration2::Decoration *decoration, QObject *parent); 0035 0036 //* render 0037 void paint(QPainter *painter, const QRect &repaintRegion) override; 0038 0039 //* flag 0040 enum Flag { FlagNone, FlagStandalone, FlagFirstInList, FlagLastInList }; 0041 0042 //* flag 0043 void setFlag(Flag value) 0044 { 0045 m_flag = value; 0046 } 0047 0048 //* standalone buttons 0049 bool isStandAlone() const 0050 { 0051 return m_flag == FlagStandalone; 0052 } 0053 0054 //* offset 0055 void setOffset(const QPointF &value) 0056 { 0057 m_offset = value; 0058 } 0059 0060 //* horizontal offset, for rendering 0061 void setHorizontalOffset(qreal value) 0062 { 0063 m_offset.setX(value); 0064 } 0065 0066 //* vertical offset, for rendering 0067 void setVerticalOffset(qreal value) 0068 { 0069 m_offset.setY(value); 0070 } 0071 0072 //* set icon size 0073 void setIconSize(const QSize &value) 0074 { 0075 m_iconSize = value; 0076 } 0077 0078 //*@name active state change animation 0079 //@{ 0080 void setOpacity(qreal value) 0081 { 0082 if (m_opacity == value) 0083 return; 0084 m_opacity = value; 0085 update(); 0086 } 0087 0088 qreal opacity(void) const 0089 { 0090 return m_opacity; 0091 } 0092 0093 //@} 0094 0095 private Q_SLOTS: 0096 0097 //* apply configuration changes 0098 void reconfigure(); 0099 0100 //* animation state 0101 void updateAnimationState(bool); 0102 0103 private: 0104 //* draw icon 0105 void drawIcon(QPainter *); 0106 0107 //*@name colors 0108 //@{ 0109 0110 QColor foregroundColor(const QPalette &) const; 0111 QColor foregroundColor(const QPalette &palette, bool active) const; 0112 0113 QColor backgroundColor(const QPalette &) const; 0114 QColor backgroundColor(const QPalette &palette, bool active) const; 0115 0116 //@} 0117 0118 //* true if animation is in progress 0119 bool isAnimated(void) const 0120 { 0121 return m_animation->state() == QPropertyAnimation::Running; 0122 } 0123 0124 //* true if button is active 0125 bool isActive(void) const; 0126 0127 //*@name button properties 0128 //@{ 0129 0130 //* true if button if of menu type 0131 bool isMenuButton(void) const 0132 { 0133 return type() == KDecoration2::DecorationButtonType::Menu || type() == KDecoration2::DecorationButtonType::ApplicationMenu; 0134 } 0135 0136 //* true if button is of toggle type 0137 bool isToggleButton(void) const 0138 { 0139 return type() == KDecoration2::DecorationButtonType::OnAllDesktops || type() == KDecoration2::DecorationButtonType::KeepAbove 0140 || type() == KDecoration2::DecorationButtonType::KeepBelow; 0141 } 0142 0143 //* true if button if of close type 0144 bool isCloseButton(void) const 0145 { 0146 return type() == KDecoration2::DecorationButtonType::Close; 0147 } 0148 0149 //* true if button has decoration 0150 bool hasDecoration(void) const 0151 { 0152 return !isMenuButton(); 0153 } 0154 0155 //@} 0156 0157 //* private constructor 0158 explicit Button(KDecoration2::DecorationButtonType type, Decoration *decoration, QObject *parent); 0159 0160 Flag m_flag = FlagNone; 0161 0162 //* glow animation 0163 QPropertyAnimation *m_animation; 0164 0165 //* vertical offset (for rendering) 0166 QPointF m_offset; 0167 0168 //* icon size 0169 QSize m_iconSize; 0170 0171 //* glow intensity 0172 qreal m_opacity; 0173 }; 0174 0175 } // namespace 0176 0177 #endif