Documentation
[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 QPropertyAnimation;
28
29 /**
30  * @brief Button bar for list item relatex context buttons
31  *
32  * @author Sami Rämö - sami.ramo (at) ixonos.com
33  */
34 class ListItemContextButtonBar : public QWidget
35 {
36     Q_OBJECT
37 public:
38     /**
39       * @brief Constructor
40       *
41       * @param parent Parent
42       */
43     explicit ListItemContextButtonBar(QWidget *parent = 0);
44
45     /**
46       * @brief Destructor
47       *
48       * Deletes images.
49       */
50     ~ListItemContextButtonBar();
51
52 /*******************************************************************************
53  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
54  ******************************************************************************/
55 private:
56     /**
57       * @brief Paint the background of the item
58       *
59       * @param event Paint event
60       */
61     void paintEvent(QPaintEvent *event);
62
63 /*******************************************************************************
64  * MEMBER FUNCTIONS AND SLOTS
65  ******************************************************************************/
66 public:
67     /**
68       * @brief Start hiding animation
69       */
70     void hideContextButtonBar();
71
72     /**
73      * @brief Set new context buttons
74      *
75      * If bar is hidden, then changeButtons() is called. Otherwise pointer to new buttons is saved
76      * and hideContextButtonBar() is called.
77      *
78      * @param contextButtons Pointer to new context buttons
79      */
80     void setContextButtons(QWidget *contextButtons);
81
82     /**
83       * @brief Start showing animation
84       *
85       * Animation is started only if the bar contains buttons.
86       */
87     void showContextButtonBar();
88
89 public slots:
90     /**
91       * @brief Shows and hides the bar when item selection is changed
92       *
93       * Calls showContextButtonBar() or hideContextButtonBar() if changing the state of the bar is
94       * required. If there is a pointer to new buttons, then request is remembered instead of
95       * changing the state immediately.
96       *
97       * @param itemIsSelected True is any item is selected
98       */
99     void onListItemSelectionChanged(bool itemIsSelected);
100
101 private:
102     /**
103       * @brief Do the actual changing of the buttons
104       *
105       * Does also re-sizing and re-positioning of the bar and sets new values for animation.
106       */
107     void changeButtons();
108
109 private slots:
110     /**
111       * @brief
112       *
113       * If bar was just hidden, then calls changeButtons() if there is a pointer to new buttons
114       * saved. If changing the buttons was done, then also checks if showing the bar was requested
115       * and calls showContextButtonBar() if needed.
116       */
117     void onAnimationFinished();
118
119 /*******************************************************************************
120  * DATA MEMBERS
121  ******************************************************************************/
122 private:
123     /**
124       * @brief States for the animation
125       *
126       * @enum AnimationState
127       */
128     enum AnimationState {
129         StateHidden,
130         StateOpening,
131         StateClosing,
132         StateVisible
133     };
134
135     bool m_waitForOpen;                 ///< Is showing requested while chaging buttons is not ready
136
137     QPixmap *m_backgroundLeft;          ///< Background picture, left part
138     QPixmap *m_backgroundMiddle;        ///< Background picture, center part
139     QPixmap *m_backgroundRight;         ///< Background picture, right part
140
141     QPropertyAnimation *m_animation;    ///< Sliding animation for show/hide
142
143     QWidget *m_contextButtons;          ///< Widget for context buttons
144     QWidget *m_newContextButtons;       ///< Temporary pointer for new context buttons
145
146     AnimationState m_state;             ///< Current state of the animation
147 };
148
149 #endif // LISTITEMCONTEXTBUTTONBAR_H