]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/controller.hpp
[Qt] Rewrite of the controller and ToolBar edition.
[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 #define I_PLAY_TOOLTIP N_("Play\nIf the playlist is empty, open a media")
45
46 class QPixmap;
47 class QLabel;
48 class QGridLayout;
49
50 class InputSlider;
51 class QAbstractSlider;
52
53 class QAbstractButton;
54
55 class VolumeClickHandler;
56 class QSignalMapper;
57
58 class QTimer;
59 class WidgetListing;
60
61 typedef enum buttonType_e
62 {
63     PLAY_BUTTON,
64     STOP_BUTTON,
65     OPEN_BUTTON,
66     PREVIOUS_BUTTON,
67     NEXT_BUTTON,
68     SLOWER_BUTTON,
69     FASTER_BUTTON,
70     FULLSCREEN_BUTTON,
71     DEFULLSCREEN_BUTTON,
72     EXTENDED_BUTTON,
73     PLAYLIST_BUTTON,
74     SNAPSHOT_BUTTON,
75     RECORD_BUTTON,
76     ATOB_BUTTON,
77     FRAME_BUTTON,
78     REVERSE_BUTTON,
79     BUTTON_MAX,
80
81     SPLITTER = 0x20,
82     INPUT_SLIDER,
83     VOLUME,
84     TIME_LABEL,
85     MENU_BUTTONS,
86     TELETEXT_BUTTONS,
87     ADVANCED_CONTROLLER,
88     SPECIAL_MAX,
89
90     WIDGET_SPACER = 0x40,
91     WIDGET_SPACER_EXTEND,
92     WIDGET_MAX,
93 } buttonType_e;
94
95 #include <QString>
96
97 static const QString nameL[BUTTON_MAX] = { "Play", "Stop", "Open",
98     "Previous", "Next", "Slower", "Faster", "Fullscreen", "De-Fullscreen",
99     "Extended panel", "Playlist", "Snapshot", "Record", "A->B Loop",
100     "Frame By Frame", "Reverse" };
101 static const QString tooltipL[BUTTON_MAX] = { I_PLAY_TOOLTIP,
102     _("Stop playback"),
103     _("Previous media in the playlist"),
104     _("Next media in the playlist"), _("Slower"), _("Faster"),
105     _("Toggle the video in fullscreen"), _("Toggle the video out fullscreen"),
106     _("Show extended settings" ), _( "Show playlist" ), _( "Take a snapshot" ),
107     _( "Record" ), _( "Loop from point A to point B continuously." ),
108     _("Frame by frame"), _("Reverse") };
109 static const QString iconL[BUTTON_MAX] ={ ":/play_b", ":/stop_b", "",
110     ":/previous_b", ":/next_b", ":/slower", ":/faster", ":/fullscreen",
111     ":/defullscreen", ":/extended", ":/playlist", ":/snapshot", ":/record",
112     ":/atob_nob", ":/frame", ":/reverse" };
113
114 typedef enum actionType_e
115 {
116     PLAY_ACTION,
117     STOP_ACTION,
118     PREVIOUS_ACTION,
119     NEXT_ACTION,
120     SLOWER_ACTION,
121     FASTER_ACTION,
122     FULLSCREEN_ACTION,
123     EXTENDED_ACTION,
124     PLAYLIST_ACTION,
125     SNAPSHOT_ACTION,
126     RECORD_ACTION,
127     FRAME_ACTION,
128     ATOB_ACTION,
129     REVERSE_ACTION,
130 } actionType_e;
131
132 enum
133 {
134    WIDGET_NORMAL = 0x0,
135    WIDGET_FLAT   = 0x1,
136    WIDGET_BIG    = 0x2,
137    WIDGET_SHINY  = 0x4,
138 };
139
140 class AbstractController : public QFrame
141 {
142     friend class WidgetListing; /* For ToolBar Edition HACKS */
143
144     Q_OBJECT
145 public:
146     AbstractController( intf_thread_t  *_p_i );
147
148 protected:
149     intf_thread_t       *p_intf;
150
151     QSignalMapper       *toolbarActionsMapper;
152     QHBoxLayout         *controlLayout;
153     /* Change to BoxLayout if both dir are needed */
154
155     AdvControlsWidget   *advControls;
156
157     void parseAndCreate( QString config, QBoxLayout *controlLayout );
158
159     virtual void createAndAddWidget( QBoxLayout *controlLayout, int i_index,
160                                      buttonType_e i_type, int i_option );
161
162     QWidget *createWidget( buttonType_e, int options = WIDGET_NORMAL );
163 private:
164     static void setupButton( QAbstractButton * );
165     QWidget *discFrame();
166     QWidget *telexFrame();
167
168 protected slots:
169     virtual void doAction( int );
170
171 protected slots:
172     void play();
173     void stop();
174     void prev();
175     void next();
176     void fullscreen();
177     void extSettings();
178     void faster();
179     void slower();
180     void reverse();
181     void playlist();
182     void snapshot();
183     void record();
184     void frame();
185
186     virtual void setStatus( int );
187
188 signals:
189     void inputExists( bool ); /// This might be usefull in the IM ?
190     void inputPlaying( bool ); /// This might be usefull in the IM ?
191     void inputIsRecordable( bool ); /// same ?
192 };
193
194 /**
195  * SPECIAL Widgets that are a bit more than just a ToolButton
196  * and have an icon/behaviour that changes depending on the context:
197  * - playButton
198  * - A->B Button
199  * - Teletext group buttons
200  * - Sound Widget group
201  **/
202 class PlayButton : public QToolButton
203 {
204     Q_OBJECT
205 private slots:
206     void updateButton( bool );
207 };
208
209 class AtoB_Button : public QToolButton
210 {
211     Q_OBJECT
212 private slots:
213     void setIcons( bool, bool );
214 };
215
216 class TeletextController : public QWidget
217 {
218     Q_OBJECT
219     friend class AbstractController;
220 private:
221     QToolButton         *telexTransparent, *telexOn;
222     QSpinBox            *telexPage;
223
224 private slots:
225     void enableTeletextButtons( bool );
226     void toggleTeletextTransparency( bool );
227 };
228
229 class SoundWidget : public QWidget
230 {
231     Q_OBJECT
232     friend class VolumeClickHandler;
233
234 public:
235     SoundWidget( QWidget *parent, intf_thread_t  *_p_i, bool );
236
237 private:
238     intf_thread_t       *p_intf;
239     QLabel              *volMuteLabel;
240     QAbstractSlider     *volumeSlider;
241     VolumeClickHandler  *hVolLabel;
242     bool                 b_my_volume;
243
244 protected slots:
245     void updateVolume( int );
246     void updateVolume( void );
247 };
248
249 /* Advanced Button Bar */
250 class AdvControlsWidget : public AbstractController
251 {
252     Q_OBJECT
253 public:
254     AdvControlsWidget( intf_thread_t * );
255 };
256
257 /* Slider Bar */
258 class InputControlsWidget : public AbstractController
259 {
260     Q_OBJECT
261 public:
262     InputControlsWidget( intf_thread_t * );
263 };
264
265 /* Button Bar */
266 class ControlsWidget : public AbstractController
267 {
268     Q_OBJECT
269 public:
270     /* p_intf, advanced control visible or not, blingbling or not */
271     ControlsWidget( intf_thread_t *_p_i, bool b_advControls );
272     virtual ~ControlsWidget();
273
274 protected:
275     friend class MainInterface;
276
277     bool                 b_advancedVisible;
278
279 protected slots:
280     void toggleAdvanced();
281
282 signals:
283     void advancedControlsToggled( bool );
284 };
285
286 /* on WIN32 hide() for fullscreen controller doesnt work, so it have to be
287    done by trick with setting the opacity of window */
288 #ifdef WIN32
289     #define WIN32TRICK
290 #endif
291
292 /* to trying transparency with fullscreen controller on windows enable that */
293 /* it can be enabled on-non windows systems,
294    but it will be transparent only with composite manager */
295 #ifndef WIN32
296     #define HAVE_TRANSPARENCY 1
297 #else
298     #define HAVE_TRANSPARENCY 0
299 #endif
300
301 /* Default value of opacity for FS controller */
302 #define DEFAULT_OPACITY 0.75
303
304 /***********************************
305  * Fullscreen controller
306  ***********************************/
307 class FullscreenControllerWidget : public AbstractController
308 {
309     Q_OBJECT
310 public:
311     FullscreenControllerWidget( intf_thread_t * );
312     virtual ~FullscreenControllerWidget();
313
314     /* Vout */
315     vout_thread_t *p_vout;
316     void attachVout( vout_thread_t *p_vout );
317     void detachVout();
318     void fullscreenChanged( vout_thread_t *, bool b_fs, int i_timeout );
319
320     int i_mouse_last_move_x;
321     int i_mouse_last_move_y;
322
323 protected:
324     friend class MainInterface;
325
326     virtual void mouseMoveEvent( QMouseEvent *event );
327     virtual void mousePressEvent( QMouseEvent *event );
328     virtual void enterEvent( QEvent *event );
329     virtual void leaveEvent( QEvent *event );
330     virtual void keyPressEvent( QKeyEvent *event );
331
332 private slots:
333     void showFSC();
334     void planHideFSC();
335     void hideFSC();
336     void slowHideFSC();
337
338 private:
339     virtual void customEvent( QEvent *event );
340
341     QTimer *p_hideTimer;
342 #if HAVE_TRANSPARENCY
343     QTimer *p_slowHideTimer;
344     bool b_slow_hide_begin;
345     int  i_slow_hide_timeout;
346 #endif
347
348     int i_mouse_last_x, i_mouse_last_y;
349     bool b_mouse_over;
350     int i_screennumber;
351
352 #ifdef WIN32TRICK
353     bool b_fscHidden;
354 #endif
355
356     /* Shared variable between FSC and VLC (protected by a lock) */
357     vlc_mutex_t lock;
358     bool        b_fullscreen;
359     int         i_hide_timeout;  /* FSC hiding timeout, same as mouse hiding timeout */
360 };
361
362 #endif