1 /***********************************************************************
2 *
3 * Copyright (C) 2010, 2011, 2012, 2018 Graeme Gott <graeme@gottcode.org>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 ***********************************************************************/
19
20 #ifndef ALERT_H
21 #define ALERT_H
22
23 #include <QWidget>
24 class QGraphicsOpacityEffect;
25 class QLabel;
26 class QTimeLine;
27 class QToolButton;
28
29 class Alert : public QWidget
30 {
31 Q_OBJECT
32
33 public:
34 enum Icon {
35 NoIcon = 0,
36 Information,
37 Warning,
38 Critical,
39 Question
40 };
41
42 Alert(QWidget* parent = 0);
43 Alert(Icon icon, const QString& text, const QStringList& details, bool expandable, QWidget* parent = 0);
44
45 bool underMouse() const;
46
47 void fadeIn();
48 void setExpandable(bool expandable);
49 void setIcon(Icon icon);
50 void setIcon(const QPixmap& pixmap);
51 void setText(const QString& text, const QStringList& details);
52
53 bool eventFilter(QObject* watched, QEvent* event);
54
55 protected:
56 void enterEvent(QEvent* event);
57 void leaveEvent(QEvent* event);
58 void paintEvent(QPaintEvent* event);
59
60 private slots:
61 void expanderToggled();
62 void fadeInFinished();
63 void fadeOut();
64
65 private:
66 void init();
67
68 private:
69 QToolButton* m_expander;
70 QLabel* m_pixmap;
71 QLabel* m_text;
72 QString m_short_text;
73 QString m_long_text;
74 QTimeLine* m_fade_timer;
75 QGraphicsOpacityEffect* m_fade_effect;
76 bool m_expanded;
77 bool m_always_expanded;
78 bool m_under_mouse;
79 };
80
underMouse()81 inline bool Alert::underMouse() const
82 {
83 return m_under_mouse;
84 }
85
86 #endif
87