1 #ifndef WIDGET_H
2 #define WIDGET_H
3 
4 #include <QWidget>
5 #include <QUdpSocket>
6 #include <QLabel>
7 #include <QQueue>
8 #include "settings.h"
9 #include "message.h"
10 #include "dbusinterface.h"
11 
12 class Widget : public QWidget
13 {
14     Q_OBJECT
15 public:
16     Widget(const char* wname);
17     ~Widget();
18 
19 private slots:
20 
21     void                    init();
22     void                    onDataReceived();
23     void                    appendMessageToQueue(const Message& msg);
24     void                    processMessageQueue();
25 
26     void                    updateTopLeftAnimation(QVariant value);
27     void                    updateTopRightAnimation(QVariant value);
28     void                    updateBottomRightAnimation(QVariant value);
29     void                    updateBottomLeftAnimation(QVariant value);
30     void                    updateTopCenterAnimation(QVariant value);
31     void                    updateBottomCenterAnimation(QVariant value);
32     void                    updateCenterAnimation(QVariant value);
33     void                    startBounce();
34     void                    unbounce();
35     void                    doneBounce();
36     void                    updateBounceAnimation(QVariant value);
37     void                    reverseTrigger();
38     void                    reverseStart();
39 
40     void                    updateFinalWidth();
41 
42 
43 public slots:
44     // Called from the ShortcutGrabber
45     void                    onPrevious();
46 
47     void                    onNext();
48 
49     /*!
50       * \brief Run a command when the user activate the notification
51       */
52     void                    onActivate();
53 
54     /*!
55       * \brief Hide the notification
56       */
57     void                    onHide();
58 
59     /*!
60       * \brief Display the next notification as if the user invoqued onNext()
61       */
62     void                    autoNext();
63 
64     void                    mousePressEvent(QMouseEvent *);
65 
66     void                    wheelEvent(QWheelEvent *e);
67 
68     /*!
69      * \brief processRemoteControl Executes a command received from the client
70      * \param command the command to run [activate|hide|previous|next]
71      */
72     void                    processRemoteControl(QString command);
73 
74     /*!
75      * \brief Receive signals from DBus. Each sent signal contains deserialized Message structure.
76      * \param DBusInterface which signals receiving a new DBus message.
77      */
78     void                    connectToDBus(const DBusInterface& dbus);
79 
80 private:
81     /*!
82       * \brief Get the final width of the slide after everything is set.
83       */
84     int                     computeWidth();
85 
86     void                    setupFont();
87 
88     void                    setupColors();
89 
90     /*!
91       * \brief Create an appropriate connection according to the position parameter from Settings
92       */
93     void                    connectForPosition(QString position);
94 
95     /*!
96       * \brief Set the icon.
97       */
98     void                    setupIcon();
99 
100     /*!
101       * \brief Set the "title" widget content according to the front() Message.
102       */
103     void                    setupTitle();
104 
105     /*!
106       * \brief Set the "text" widget content according to the front() Message.
107       */
108     void                    setupContent();
109 
110     /*!
111       * \brief Load default settings for the front() Message according to the specified profile and configuration files.
112       */
113     void                    loadDefaults();
114 
115     /*!
116       * \brief Tries to load a Pixmap from pattern : from a file, from a setting value.
117       */
118     QPixmap                 loadPixmap(QString pattern);
119 
120     /*!
121       * \brief Update the message m if it's already in the queue
122       * \return true if a message has been updated
123       */
124     bool                    update(const Message& m);
125 
126     QPoint                  stringToPos(QString string);
127 
128     inline std::size_t      getHeight();
129 
130 private:
131     Settings                m_settings;
132     QUdpSocket              m_socket;
133     QMap<QString, QLabel*>  m_contentView;
134     QQueue<Message>         m_messageQueue;
135     QParallelAnimationGroup m_animation;
136     QTimer                  m_visible;
137     QStack<Message>         m_previousStack;
138     QPoint                  tmpBouncePos;
139     int                     m_computedWidth;
140 
141     std::string             m_activePositionSlot;
142 };
143 
144 #endif // WIDGET_H
145