]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/controller.hpp
4b2515f8286588dce792911894aebdf05b5c5885
[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     REVERSE_BUTTON,
87 } buttonType_e;
88
89 typedef enum actionType_e
90 {
91     PLAY_ACTION,
92     PAUSE_ACTION,
93     STOP_ACTION,
94     PREVIOUS_ACTION,
95     NEXT_ACTION,
96     SLOWER_ACTION,
97     FASTER_ACTION,
98     FULLSCREEN_ACTION,
99     EXTENDED_ACTION,
100     PLAYLIST_ACTION,
101     SNAPSHOT_ACTION,
102     RECORD_ACTION,
103     FRAME_ACTION,
104     ATOB_ACTION,
105     REVERSE_ACTION,
106 } actionType_e;
107
108 enum
109 {
110    WIDGET_NORMAL = 0x0,
111    WIDGET_FLAT   = 0x1,
112    WIDGET_BIG    = 0x2,
113    WIDGET_SHINY  = 0x4,
114 };
115
116 class AbstractController : public QFrame
117 {
118     Q_OBJECT
119 public:
120     AbstractController( intf_thread_t  *_p_i );
121     int getWidth() { return controlLayout->columnCount(); }
122
123 protected:
124     intf_thread_t       *p_intf;
125
126     QSignalMapper       *toolbarActionsMapper;
127     QGridLayout         *controlLayout;
128
129     AdvControlsWidget   *advControls;
130
131     void parseAndCreateLine( QString config, int i_line );
132
133 private:
134     QWidget *createWidget( buttonType_e, int *i_size,
135                            int options = WIDGET_NORMAL );
136     void setupButton( QAbstractButton * );
137     QWidget *discFrame();
138     QWidget *telexFrame();
139
140 private slots:
141     void doAction( int );
142
143 protected slots:
144     void play();
145     void stop();
146     void prev();
147     void next();
148     void fullscreen();
149     void extSettings();
150     void faster();
151     void slower();
152     void reverse();
153     void playlist();
154     void snapshot();
155     void record();
156     void frame();
157
158     virtual void setStatus( int );
159
160 signals:
161     void inputExists( bool ); /// This might be usefull in the IM ?
162     void inputPlaying( bool ); /// This might be usefull in the IM ?
163     void inputIsRecordable( bool ); /// same ?
164 };
165
166 /**
167  * SPECIAL Widgets that are a bit more than just a ToolButton
168  * and have an icon/behaviour that changes depending on the context:
169  * - playButton
170  * - A->B Button
171  * - Teletext group buttons
172  * - Sound Widget group
173  **/
174 class PlayButton : public QToolButton
175 {
176     Q_OBJECT
177 private slots:
178     void updateButton( bool );
179 };
180
181 class AtoB_Button : public QToolButton
182 {
183     Q_OBJECT
184 private slots:
185     void setIcons( bool, bool );
186 };
187
188 class TeletextController : public QWidget
189 {
190     Q_OBJECT
191     friend class AbstractController;
192 private:
193     QToolButton         *telexTransparent, *telexOn;
194     QSpinBox            *telexPage;
195
196 private slots:
197     void enableTeletextButtons( bool );
198     void toggleTeletextTransparency( bool );
199 };
200
201 class SoundWidget : public QWidget
202 {
203     Q_OBJECT
204     friend class VolumeClickHandler;
205
206 public:
207     SoundWidget( intf_thread_t  *_p_i, bool );
208
209 private:
210     intf_thread_t       *p_intf;
211     QLabel              *volMuteLabel;
212     QAbstractSlider     *volumeSlider;
213     VolumeClickHandler  *hVolLabel;
214     bool                 b_my_volume;
215
216 protected slots:
217     void updateVolume( int );
218     void updateVolume( void );
219 };
220
221 /* Advanced Button Bar */
222 class AdvControlsWidget : public AbstractController
223 {
224     Q_OBJECT
225 public:
226     AdvControlsWidget( intf_thread_t * );
227 };
228
229 /* Slider Bar */
230 class InputControlsWidget : public AbstractController
231 {
232     Q_OBJECT
233 public:
234     InputControlsWidget( intf_thread_t * );
235 };
236
237 /* Button Bar */
238 class ControlsWidget : public AbstractController
239 {
240     Q_OBJECT
241 public:
242     /* p_intf, advanced control visible or not, blingbling or not */
243     ControlsWidget( intf_thread_t *_p_i, bool b_advControls );
244     virtual ~ControlsWidget();
245
246 protected:
247     friend class MainInterface;
248
249     bool                 b_advancedVisible;
250
251 protected slots:
252     void toggleAdvanced();
253
254 signals:
255     void advancedControlsToggled( bool );
256 };
257
258 /* on WIN32 hide() for fullscreen controller doesnt work, so it have to be
259    done by trick with setting the opacity of window */
260 #ifdef WIN32
261     #define WIN32TRICK
262 #endif
263
264 /* to trying transparency with fullscreen controller on windows enable that */
265 /* it can be enabled on-non windows systems,
266    but it will be transparent only with composite manager */
267 #ifndef WIN32
268     #define HAVE_TRANSPARENCY 1
269 #else
270     #define HAVE_TRANSPARENCY 0
271 #endif
272
273 /* Default value of opacity for FS controller */
274 #define DEFAULT_OPACITY 0.75
275
276 /***********************************
277  * Fullscreen controller
278  ***********************************/
279 class FullscreenControllerWidget : public AbstractController
280 {
281     Q_OBJECT
282 public:
283     FullscreenControllerWidget( intf_thread_t * );
284     virtual ~FullscreenControllerWidget();
285
286     /* Vout */
287     vout_thread_t *p_vout;
288     void attachVout( vout_thread_t *p_vout );
289     void detachVout();
290     void fullscreenChanged( vout_thread_t *, bool b_fs, int i_timeout );
291
292     int i_mouse_last_move_x;
293     int i_mouse_last_move_y;
294
295 protected:
296     friend class MainInterface;
297
298     virtual void mouseMoveEvent( QMouseEvent *event );
299     virtual void mousePressEvent( QMouseEvent *event );
300     virtual void enterEvent( QEvent *event );
301     virtual void leaveEvent( QEvent *event );
302     virtual void keyPressEvent( QKeyEvent *event );
303
304 private slots:
305     void showFSC();
306     void planHideFSC();
307     void hideFSC();
308     void slowHideFSC();
309
310 private:
311     virtual void customEvent( QEvent *event );
312
313     QTimer *p_hideTimer;
314 #if HAVE_TRANSPARENCY
315     QTimer *p_slowHideTimer;
316     bool b_slow_hide_begin;
317     int  i_slow_hide_timeout;
318 #endif
319
320     int i_mouse_last_x, i_mouse_last_y;
321     bool b_mouse_over;
322     int i_screennumber;
323
324 #ifdef WIN32TRICK
325     bool b_fscHidden;
326 #endif
327
328     /* Shared variable between FSC and VLC (protected by a lock) */
329     vlc_mutex_t lock;
330     bool        b_fullscreen;
331     int         i_hide_timeout;  /* FSC hiding timeout, same as mouse hiding timeout */
332 };
333
334 #endif