File indexing completed on 2024-05-12 16:58:21

0001 #ifndef BREEZE_BUTTONS_H
0002 #define BREEZE_BUTTONS_H
0003 
0004 /*
0005  * SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
0006  * SPDX-FileCopyrightText: 2014 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0007  *
0008  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0009  */
0010 #include "breezedecoration.h"
0011 #include <KDecoration2/DecorationButton>
0012 
0013 #include <QHash>
0014 #include <QImage>
0015 
0016 class QVariantAnimation;
0017 
0018 namespace Breeze
0019 {
0020 class Button : public KDecoration2::DecorationButton
0021 {
0022     Q_OBJECT
0023 
0024 public:
0025     //* constructor
0026     explicit Button(QObject *parent, const QVariantList &args);
0027 
0028     //* destructor
0029     virtual ~Button() = default;
0030 
0031     //* button creation
0032     static Button *create(KDecoration2::DecorationButtonType type, KDecoration2::Decoration *decoration, QObject *parent);
0033 
0034     //* render
0035     virtual void paint(QPainter *painter, const QRect &repaintRegion) override;
0036 
0037     //* flag
0038     enum Flag {
0039         FlagNone,
0040         FlagStandalone,
0041         FlagFirstInList,
0042         FlagLastInList,
0043     };
0044 
0045     //* flag
0046     void setFlag(Flag value)
0047     {
0048         m_flag = value;
0049     }
0050 
0051     //* standalone buttons
0052     bool isStandAlone() const
0053     {
0054         return m_flag == FlagStandalone;
0055     }
0056 
0057     //* offset
0058     void setOffset(const QPointF &value)
0059     {
0060         m_offset = value;
0061     }
0062 
0063     //* horizontal offset, for rendering
0064     void setHorizontalOffset(qreal value)
0065     {
0066         m_offset.setX(value);
0067     }
0068 
0069     //* vertical offset, for rendering
0070     void setVerticalOffset(qreal value)
0071     {
0072         m_offset.setY(value);
0073     }
0074 
0075     //* set icon size
0076     void setIconSize(const QSize &value)
0077     {
0078         m_iconSize = value;
0079     }
0080 
0081     //*@name active state change animation
0082     //@{
0083     void setOpacity(qreal value)
0084     {
0085         if (m_opacity == value) {
0086             return;
0087         }
0088         m_opacity = value;
0089         update();
0090     }
0091 
0092     qreal opacity() const
0093     {
0094         return m_opacity;
0095     }
0096 
0097     //@}
0098 
0099 private Q_SLOTS:
0100 
0101     //* apply configuration changes
0102     void reconfigure();
0103 
0104     //* animation state
0105     void updateAnimationState(bool);
0106 
0107 private:
0108     //* private constructor
0109     explicit Button(KDecoration2::DecorationButtonType type, Decoration *decoration, QObject *parent = nullptr);
0110 
0111     //* draw button icon
0112     void drawIcon(QPainter *) const;
0113 
0114     //*@name colors
0115     //@{
0116     QColor foregroundColor() const;
0117     QColor backgroundColor() const;
0118     //@}
0119 
0120     Flag m_flag = FlagNone;
0121 
0122     //* active state change animation
0123     QVariantAnimation *m_animation;
0124 
0125     //* vertical offset (for rendering)
0126     QPointF m_offset;
0127 
0128     //* icon size
0129     QSize m_iconSize;
0130 
0131     //* active state change opacity
0132     qreal m_opacity = 0;
0133 };
0134 
0135 } // namespace
0136 
0137 #endif