Fixed FacebookLoginBrowser::destroyed() signal handling
[situare] / src / ui / listitemcontextbuttonbar.h
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Sami Rämö - sami.ramo@ixonos.com
6
7     Situare is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License
9     version 2 as published by the Free Software Foundation.
10
11     Situare 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
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with Situare; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
19     USA.
20 */
21
22 #ifndef LISTITEMCONTEXTBUTTONBAR_H
23 #define LISTITEMCONTEXTBUTTONBAR_H
24
25 #include <QWidget>
26
27 class QHBoxLayout;
28 class QPropertyAnimation;
29
30 /**
31  * @brief Button bar for list item relatex context buttons
32  *
33  * @author Sami Rämö - sami.ramo (at) ixonos.com
34  */
35 class ListItemContextButtonBar : public QWidget
36 {
37     Q_OBJECT
38 public:
39     /**
40       * @brief Constructor
41       *
42       * @param parent Parent
43       */
44     explicit ListItemContextButtonBar(QWidget *parent = 0);
45
46     /**
47       * @brief Destructor
48       *
49       * Deletes images.
50       */
51     ~ListItemContextButtonBar();
52
53 /*******************************************************************************
54  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
55  ******************************************************************************/
56 private:
57     /**
58       * @brief Paint the background of the item
59       *
60       * @param event Paint event
61       */
62     void paintEvent(QPaintEvent *event);
63
64 /*******************************************************************************
65  * MEMBER FUNCTIONS AND SLOTS
66  ******************************************************************************/
67 public:
68     /**
69       * @brief Start hiding animation
70       */
71     void hideContextButtonBar();
72
73     /**
74      * @brief Set new context buttons
75      *
76      * If bar is hidden, then changeButtons() is called. Otherwise pointer to new buttons is saved
77      * and hideContextButtonBar() is called.
78      *
79      * @param contextButtons Pointer to new context buttons
80      */
81     void setContextButtons(QWidget *contextButtons);
82
83     /**
84       * @brief Start showing animation
85       *
86       * Animation is started only if the bar contains buttons.
87       */
88     void showContextButtonBar();
89
90 public slots:
91     /**
92       * @brief Shows and hides the bar when item selection is changed
93       *
94       * Calls showContextButtonBar() or hideContextButtonBar() if changing the state of the bar is
95       * required. If there is a pointer to new buttons, then request is remembered instead of
96       * changing the state immediately.
97       *
98       * @param itemIsSelected True is any item is selected
99       */
100     void onListItemSelectionChanged(bool itemIsSelected);
101
102 private:
103     /**
104       * @brief Do the actual changing of the buttons
105       *
106       * Does also re-sizing and re-positioning of the bar and sets new values for animation.
107       */
108     void changeButtons();
109
110 private slots:
111     /**
112       * @brief
113       *
114       * If bar was just hidden, then calls changeButtons() if there is a pointer to new buttons
115       * saved. If changing the buttons was done, then also checks if showing the bar was requested
116       * and calls showContextButtonBar() if needed.
117       */
118     void onAnimationFinished();
119
120 /*******************************************************************************
121  * DATA MEMBERS
122  ******************************************************************************/
123 private:
124     /**
125       * @brief States for the animation
126       *
127       * @enum AnimationState
128       */
129     enum AnimationState {
130         StateHidden,
131         StateOpening,
132         StateClosing,
133         StateVisible
134     };
135
136     bool m_waitForOpen;                 ///< Is showing requested while chaging buttons is not ready
137
138     QHBoxLayout *m_barLayout;           ///< Main layout of this widget
139
140     QPixmap *m_backgroundLeft;          ///< Background picture, left part
141     QPixmap *m_backgroundMiddle;        ///< Background picture, center part
142     QPixmap *m_backgroundRight;         ///< Background picture, right part
143
144     QPropertyAnimation *m_animation;    ///< Sliding animation for show/hide
145
146     QWidget *m_contextButtons;          ///< Widget for context buttons
147     QWidget *m_newContextButtons;       ///< Temporary pointer for new context buttons
148
149     AnimationState m_state;             ///< Current state of the animation
150 };
151
152 #endif // LISTITEMCONTEXTBUTTONBAR_H