Warning, file /plasma/oxygen/kdecoration/oxygenbutton.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 0023 class Button : public KDecoration2::DecorationButton 0024 { 0025 Q_OBJECT 0026 0027 //* declare active state opacity 0028 Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity) 0029 0030 public: 0031 //* constructor 0032 explicit Button(QObject *parent, const QVariantList &args); 0033 0034 //* button creation 0035 static Button *create(KDecoration2::DecorationButtonType type, KDecoration2::Decoration *decoration, QObject *parent); 0036 0037 //* render 0038 void paint(QPainter *painter, const QRect &repaintRegion) override; 0039 0040 //* flag 0041 enum Flag { FlagNone, FlagStandalone, FlagFirstInList, FlagLastInList }; 0042 0043 //* flag 0044 void setFlag(Flag value) 0045 { 0046 m_flag = value; 0047 } 0048 0049 //* standalone buttons 0050 bool isStandAlone() const 0051 { 0052 return m_flag == FlagStandalone; 0053 } 0054 0055 //* offset 0056 void setOffset(const QPointF &value) 0057 { 0058 m_offset = value; 0059 } 0060 0061 //* horizontal offset, for rendering 0062 void setHorizontalOffset(qreal value) 0063 { 0064 m_offset.setX(value); 0065 } 0066 0067 //* vertical offset, for rendering 0068 void setVerticalOffset(qreal value) 0069 { 0070 m_offset.setY(value); 0071 } 0072 0073 //* set icon size 0074 void setIconSize(const QSize &value) 0075 { 0076 m_iconSize = value; 0077 } 0078 0079 //*@name active state change animation 0080 //@{ 0081 void setOpacity(qreal value) 0082 { 0083 if (m_opacity == value) 0084 return; 0085 m_opacity = value; 0086 update(); 0087 } 0088 0089 qreal opacity(void) const 0090 { 0091 return m_opacity; 0092 } 0093 0094 //@} 0095 0096 private Q_SLOTS: 0097 0098 //* apply configuration changes 0099 void reconfigure(); 0100 0101 //* animation state 0102 void updateAnimationState(bool); 0103 0104 private: 0105 //* draw icon 0106 void drawIcon(QPainter *); 0107 0108 //*@name colors 0109 //@{ 0110 0111 QColor foregroundColor(const QPalette &) const; 0112 QColor foregroundColor(const QPalette &palette, bool active) const; 0113 0114 QColor backgroundColor(const QPalette &) const; 0115 QColor backgroundColor(const QPalette &palette, bool active) const; 0116 0117 //@} 0118 0119 //* true if animation is in progress 0120 bool isAnimated(void) const 0121 { 0122 return m_animation->state() == QPropertyAnimation::Running; 0123 } 0124 0125 //* true if button is active 0126 bool isActive(void) const; 0127 0128 //*@name button properties 0129 //@{ 0130 0131 //* true if button if of menu type 0132 bool isMenuButton(void) const 0133 { 0134 return type() == KDecoration2::DecorationButtonType::Menu || type() == KDecoration2::DecorationButtonType::ApplicationMenu; 0135 } 0136 0137 //* true if button is of toggle type 0138 bool isToggleButton(void) const 0139 { 0140 return type() == KDecoration2::DecorationButtonType::OnAllDesktops || type() == KDecoration2::DecorationButtonType::KeepAbove 0141 || type() == KDecoration2::DecorationButtonType::KeepBelow; 0142 } 0143 0144 //* true if button if of close type 0145 bool isCloseButton(void) const 0146 { 0147 return type() == KDecoration2::DecorationButtonType::Close; 0148 } 0149 0150 //* true if button has decoration 0151 bool hasDecoration(void) const 0152 { 0153 return !isMenuButton(); 0154 } 0155 0156 //@} 0157 0158 //* private constructor 0159 explicit Button(KDecoration2::DecorationButtonType type, Decoration *decoration, QObject *parent); 0160 0161 Flag m_flag = FlagNone; 0162 0163 //* glow animation 0164 QPropertyAnimation *m_animation; 0165 0166 //* vertical offset (for rendering) 0167 QPointF m_offset; 0168 0169 //* icon size 0170 QSize m_iconSize; 0171 0172 //* glow intensity 0173 qreal m_opacity; 0174 }; 0175 0176 } // namespace 0177 0178 #endif