Salome HOME
0023564: [EDF] AsterStudy: introduce a feature to show popup notifications
[modules/gui.git] / src / Qtx / QtxNotify.h
1 // Copyright (C) 2007-2018  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef QTXNOTIFY_H
24 #define QTXNOTIFY_H
25
26 #include <QWidget>
27
28 #include <QList>
29 #include <QAbstractAnimation>
30
31 class QTimer;
32
33 class QtxNotify : public QObject
34 {
35     Q_OBJECT
36
37     class NotifyWidget;
38
39 public:
40     typedef enum {
41         TopToBottom,
42         BottomToTop
43     } PlacementPolicy;
44
45     Q_ENUM(PlacementPolicy)
46
47 public:
48     QtxNotify(QObject* = 0);
49     QtxNotify(QWidget*, QObject* = 0);
50     virtual ~QtxNotify();
51
52     int             showNotification(const QString&, const QString&, int timeout = -1);
53     void            hideNotification(const QString& = QString());
54     void            hideNotification(const int);
55
56     QWidget*        window() const;
57     void            setWindow(QWidget* window);
58
59     double          notificationSize() const;
60     void            setNotificationSize(const double);
61
62     int             animationTime() const;
63     void            setAnimationTime(const int);
64
65     PlacementPolicy placementPolicy() const;
66     void            setPlacementPolicy(const PlacementPolicy&);
67
68     int             alignment() const;
69     void            setAlignment(const int);
70
71     virtual bool    eventFilter(QObject*, QEvent*);
72
73 private Q_SLOTS:
74     void            onArrangeTimeout();
75     void            onAnimationDestroyed(QObject*);
76
77 private:
78     void            triggerArrange();
79     void            updateArrangement();
80     void            arrangeNotifications(bool = true);
81
82     NotifyWidget*   notification(const int);
83     NotifyWidget*   notification(const QString&);
84     void            removeNotification(NotifyWidget*);
85
86     int             generateId() const;
87
88     bool            isAnimated() const;
89
90     bool            hasAcitveAnimation() const;
91     void            startAnimation(QAbstractAnimation*);
92     void            stopAnimation(QAbstractAnimation*);
93
94     QPoint          referencePoint() const;
95     int             notificationWidth() const;
96
97 private:
98     typedef QList<QtxNotify::NotifyWidget*> NotifyList;
99     typedef QList<QAbstractAnimation*>      AnimationList;
100
101 private:
102     double          mySize;
103     QWidget*        myWindow;
104     PlacementPolicy myPlacement;
105     int             myAlignment;
106     QTimer*         myArrangeTimer;
107
108     int             myAnimTime;
109     bool            myAnimBlock;
110     AnimationList   myAnimations;
111
112     NotifyList      myNotifications;
113
114     friend class QtxNotify::NotifyWidget;
115 };
116
117 #endif // QTXNOTIFY_H