]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/controller.hpp
[Qt] Parsing of generic toolbars and auto-creation of those bars.
[vlc] / modules / gui / qt4 / components / controller.hpp
1 /*****************************************************************************
2  * interface_widgets.hpp : Custom widgets for the main interface
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Clément Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *          Rafaël Carré <funman@videolanorg>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #ifndef _CONTROLLER_H_
27 #define _CONTROLLER_H_
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <vlc_common.h>
34 #include <vlc_interface.h>
35
36 #include "qt4.hpp"
37 #include "main_interface.hpp"
38 #include "input_manager.hpp"
39
40 #include <QWidget>
41 #include <QFrame>
42 #include <QToolButton>
43
44 class QPixmap;
45 class QLabel;
46 class QGridLayout;
47
48 class InputSlider;
49 class QAbstractSlider;
50
51 class QAbstractButton;
52
53 class VolumeClickHandler;
54 class QSignalMapper;
55
56 class QTimer;
57
58 typedef enum buttonType_e
59 {
60     PLAY_BUTTON,
61     PAUSE_BUTTON,
62     STOP_BUTTON,
63     OPEN_BUTTON,
64     PREVIOUS_BUTTON,
65     NEXT_BUTTON,
66     SLOWER_BUTTON,
67     FASTER_BUTTON,
68     FULLSCREEN_BUTTON,
69     DEFULLSCREEN_BUTTON,
70     EXTENDED_BUTTON,
71     PLAYLIST_BUTTON,
72     SNAPSHOT_BUTTON,
73     RECORD_BUTTON,
74     ATOB_BUTTON,
75     FRAME_BUTTON,
76     INPUT_SLIDER,
77     VOLUME_SLIDER,
78     MENU_BUTTONS,
79     TELETEXT_BUTTONS,
80     VOLUME,
81     WIDGET_SPACER,
82     WIDGET_SPACER_EXTEND,
83     TIME_LABEL,
84     SPLITTER,
85     ADVANCED_CONTROLLER,
86 } buttonType_e;
87
88 typedef enum actionType_e
89 {
90     PLAY_ACTION,
91     PAUSE_ACTION,
92     STOP_ACTION,
93     PREVIOUS_ACTION,
94     NEXT_ACTION,
95     SLOWER_ACTION,
96     FASTER_ACTION,
97     FULLSCREEN_ACTION,
98     EXTENDED_ACTION,
99     PLAYLIST_ACTION,
100     SNAPSHOT_ACTION,
101     RECORD_ACTION,
102     FRAME_ACTION,
103     ATOB_ACTION
104 } actionType_e;
105
106 enum
107 {
108    WIDGET_NORMAL = 0x0,
109    WIDGET_FLAT   = 0x1,
110    WIDGET_BIG    = 0x2,
111    WIDGET_SHINY  = 0x4,
112 };
113
114 class AbstractController : public QFrame
115 {
116     Q_OBJECT
117 public:
118     AbstractController( intf_thread_t  *_p_i );
119     int getWidth() { return controlLayout->columnCount(); }
120
121 protected:
122     intf_thread_t       *p_intf;
123
124     QSignalMapper       *toolbarActionsMapper;
125     QGridLayout         *controlLayout;
126
127     AdvControlsWidget   *advControls;
128
129     void parseAndCreateLine( QString config, int i_line );
130
131 private:
132     QWidget *createWidget( buttonType_e, int *i_size,
133                            int options = WIDGET_NORMAL );
134     void setupButton( QAbstractButton * );
135     QWidget *discFrame();
136     QWidget *telexFrame();
137
138 private slots:
139     void doAction( int );
140
141 protected slots:
142     void play();
143     void stop();
144     void prev();
145     void next();
146     void fullscreen();
147     void extSettings();
148     void faster();
149     void slower();
150     void playlist();
151     void snapshot();
152     void record();
153     void frame();
154
155     virtual void setStatus( int );
156
157 signals:
158     void inputExists( bool ); /// This might be usefull in the IM ?
159     void inputPlaying( bool ); /// This might be usefull in the IM ?
160     void inputIsRecordable( bool ); /// same ?
161 };
162
163 /**
164  * SPECIAL Widgets that are a bit more than just a ToolButton
165  * and have an icon/behaviour that changes depending on the context:
166  * - playButton
167  * - A->B Button
168  * - Teletext group buttons
169  * - Sound Widget group
170  **/
171 class PlayButton : public QToolButton
172 {
173     Q_OBJECT
174 private slots:
175     void updateButton( bool );
176 };
177
178 class AtoB_Button : public QToolButton
179 {
180     Q_OBJECT
181 private slots:
182     void setIcons( bool, bool );
183 };
184
185 class TeletextController : public QWidget
186 {
187     Q_OBJECT
188     friend class AbstractController;
189 private:
190     QToolButton         *telexTransparent, *telexOn;
191     QSpinBox            *telexPage;
192
193 private slots:
194     void enableTeletextButtons( bool );
195     void toggleTeletextTransparency( bool );
196 };
197
198 class SoundWidget : public QWidget
199 {
200     Q_OBJECT
201     friend class VolumeClickHandler;
202
203 public:
204     SoundWidget( intf_thread_t  *_p_i, bool );
205
206 private:
207     intf_thread_t       *p_intf;
208     QLabel              *volMuteLabel;
209     QAbstractSlider     *volumeSlider;
210     VolumeClickHandler  *hVolLabel;
211     bool                 b_my_volume;
212
213 protected slots:
214     void updateVolume( int );
215     void updateVolume( void );
216 };
217
218 /* Advanced Button Bar */
219 class AdvControlsWidget : public AbstractController
220 {
221     Q_OBJECT
222 public:
223     AdvControlsWidget( intf_thread_t * );
224 };
225
226 /* Slider Bar */
227 class InputControlsWidget : public AbstractController
228 {
229     Q_OBJECT
230 public:
231     InputControlsWidget( intf_thread_t * );
232 };
233
234 /* Button Bar */
235 class ControlsWidget : public AbstractController
236 {
237     Q_OBJECT
238 public:
239     /* p_intf, advanced control visible or not, blingbling or not */
240     ControlsWidget( intf_thread_t *_p_i, bool b_advControls );
241     virtual ~ControlsWidget();
242
243 protected:
244     friend class MainInterface;
245
246     bool                 b_advancedVisible;
247
248 protected slots:
249     void toggleAdvanced();
250
251 signals:
252     void advancedControlsToggled( bool );
253 };
254
255 /* on WIN32 hide() for fullscreen controller doesnt work, so it have to be
256    done by trick with setting the opacity of window */
257 #ifdef WIN32
258     #define WIN32TRICK
259 #endif
260
261 /* to trying transparency with fullscreen controller on windows enable that */
262 /* it can be enabled on-non windows systems,
263    but it will be transparent only with composite manager */
264 #ifndef WIN32
265     #define HAVE_TRANSPARENCY 1
266 #else
267     #define HAVE_TRANSPARENCY 0
268 #endif
269
270 /* Default value of opacity for FS controller */
271 #define DEFAULT_OPACITY 0.75
272
273 /***********************************
274  * Fullscreen controller
275  ***********************************/
276 class FullscreenControllerWidget : public AbstractController
277 {
278     Q_OBJECT
279 public:
280     FullscreenControllerWidget( intf_thread_t * );
281     virtual ~FullscreenControllerWidget();
282
283     /* Vout */
284     vout_thread_t *p_vout;
285     void attachVout( vout_thread_t *p_vout );
286     void detachVout();
287     void fullscreenChanged( vout_thread_t *, bool b_fs, int i_timeout );
288
289     int i_mouse_last_move_x;
290     int i_mouse_last_move_y;
291
292 protected:
293     friend class MainInterface;
294
295     virtual void mouseMoveEvent( QMouseEvent *event );
296     virtual void mousePressEvent( QMouseEvent *event );
297     virtual void enterEvent( QEvent *event );
298     virtual void leaveEvent( QEvent *event );
299     virtual void keyPressEvent( QKeyEvent *event );
300
301 private slots:
302     void showFSC();
303     void planHideFSC();
304     void hideFSC();
305     void slowHideFSC();
306
307 private:
308     virtual void customEvent( QEvent *event );
309
310     QTimer *p_hideTimer;
311 #if HAVE_TRANSPARENCY
312     QTimer *p_slowHideTimer;
313     bool b_slow_hide_begin;
314     int  i_slow_hide_timeout;
315 #endif
316
317     int i_mouse_last_x, i_mouse_last_y;
318     bool b_mouse_over;
319     int i_screennumber;
320
321 #ifdef WIN32TRICK
322     bool b_fscHidden;
323 #endif
324
325     /* Shared variable between FSC and VLC (protected by a lock) */
326     vlc_mutex_t lock;
327     bool        b_fullscreen;
328     int         i_hide_timeout;  /* FSC hiding timeout, same as mouse hiding timeout */
329 };
330
331 #endif