File indexing completed on 2024-09-01 03:52:59
0001 /* 0002 SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef BUTTON_H 0008 #define BUTTON_H 0009 0010 #include <QIcon> 0011 #include <QFont> 0012 #include <QSize> 0013 #include <QPointer> 0014 #include <QWidget> 0015 #include <QGraphicsItem> 0016 0017 #include "welcomescreen.h" 0018 #include "animation.h" 0019 0020 class ButtonAnimation; 0021 0022 class Button : public QGraphicsObject 0023 { 0024 Q_OBJECT 0025 enum { 0026 BRIGHTNESS_NORMAL = 0, 0027 BRIGHTNESS_HOVER = 120, 0028 BRIGHTNESS_DOWN = 180 0029 }; 0030 QIcon m_icon; 0031 QFont m_font; 0032 QString m_text; 0033 QSize m_size; 0034 int m_text_width; 0035 0036 bool m_fixed_width; 0037 bool m_down; 0038 bool m_hover; 0039 double m_brightness; 0040 QPointer<ButtonAnimation> m_animation; 0041 0042 QWidget* m_editor; 0043 0044 void computeSize(); 0045 public: 0046 Button(QGraphicsItem* parent, const QIcon& icon, 0047 const QFont& font, const QString& text); 0048 ~Button() override; 0049 0050 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override; 0051 QRectF boundingRect() const override; 0052 0053 QSize size() const; 0054 0055 void onMousePress(); 0056 void onMouseRelease(); 0057 void onMouseMove(); 0058 void onMouseLeave(); 0059 bool onClicked(); 0060 0061 void setText(const QString& text); 0062 void setBrightness(double value); 0063 double brightness() const; 0064 0065 void setWidth(int width); 0066 Q_SIGNALS: 0067 void clicked(); 0068 void needsUpdate(); 0069 }; 0070 0071 class ButtonAnimation : public Animation 0072 { 0073 Q_OBJECT 0074 public: 0075 Button* m_button; 0076 int m_brightness; 0077 static double m_speed; 0078 int m_last; 0079 public: 0080 ButtonAnimation(Button* button, int brightness); 0081 ~ButtonAnimation() override; 0082 void start(int t) override; 0083 bool step(int t) override; 0084 virtual void abort(); 0085 0086 void setBrightness(int value); 0087 }; 0088 0089 #endif // BUTTON_H