]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/controller.hpp
Qt4: allow speedlabel in toolbars
[vlc] / modules / gui / qt4 / components / controller.hpp
1 /*****************************************************************************
2  * controller.hpp : Controller for the main interface
3  ****************************************************************************
4  * Copyright (C) 2006-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Jean-Baptiste Kempf <jb@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifndef QVLC_CONTROLLER_H_
25 #define QVLC_CONTROLLER_H_
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include "qt4.hpp"
32
33 #include <QFrame>
34 #include <QString>
35 #include <QSizeGrip>
36
37 #define MAIN_TB1_DEFAULT "64;39;64;38;65"
38 #define MAIN_TB2_DEFAULT "0-2;64;3;1;4;64;7;9;64;10;20;19;64-4;37;65;35-4"
39 #define ADV_TB_DEFAULT "12;11;13;14"
40 #define INPT_TB_DEFAULT "5-1;15-1;33;6-1"
41 #define FSC_TB_DEFAULT "0-2;64;3;1;4;64;37;64;38;64;8;65;25;35-4;34"
42
43 #define I_PLAY_TOOLTIP N_("Play\nIf the playlist is empty, open a medium")
44
45 class QPixmap;
46 class QLabel;
47
48 class QGridLayout;
49 class QHBoxLayout;
50 class QBoxLayout;
51
52 class QAbstractSlider;
53 class QAbstractButton;
54 class SeekSlider;
55 class QToolButton;
56
57 class VolumeClickHandler;
58 class WidgetListing;
59
60 class QSignalMapper;
61 class QTimer;
62
63 typedef enum buttonType_e
64 {
65     PLAY_BUTTON,
66     STOP_BUTTON,
67     OPEN_BUTTON,
68     PREV_SLOW_BUTTON,
69     NEXT_FAST_BUTTON,
70     SLOWER_BUTTON,
71     FASTER_BUTTON,
72     FULLSCREEN_BUTTON,
73     DEFULLSCREEN_BUTTON,
74     EXTENDED_BUTTON,
75     PLAYLIST_BUTTON,
76     SNAPSHOT_BUTTON,
77     RECORD_BUTTON,
78     ATOB_BUTTON,
79     FRAME_BUTTON,
80     REVERSE_BUTTON,
81     SKIP_BACK_BUTTON,
82     SKIP_FW_BUTTON,
83     QUIT_BUTTON,
84     RANDOM_BUTTON,
85     LOOP_BUTTON,
86     INFO_BUTTON,
87     PREVIOUS_BUTTON,
88     NEXT_BUTTON,
89     OPEN_SUB_BUTTON,
90     FULLWIDTH_BUTTON,
91     BUTTON_MAX,
92
93     SPLITTER = 0x20,
94     INPUT_SLIDER,
95     TIME_LABEL,
96     VOLUME,
97     VOLUME_SPECIAL,
98     MENU_BUTTONS,
99     TELETEXT_BUTTONS,
100     ADVANCED_CONTROLLER,
101     PLAYBACK_BUTTONS,
102     ASPECT_RATIO_COMBOBOX,
103     SPEED_LABEL,
104     SPECIAL_MAX,
105
106     WIDGET_SPACER = 0x40,
107     WIDGET_SPACER_EXTEND,
108     WIDGET_MAX,
109 } buttonType_e;
110
111
112 static const char* const nameL[BUTTON_MAX] = { N_("Play"), N_("Stop"), N_("Open"),
113     N_("Previous / Backward"), N_("Next / Forward"), N_("Slower"), N_("Faster"), N_("Fullscreen"),
114     N_("De-Fullscreen"), N_("Extended panel"), N_("Playlist"), N_("Snapshot"),
115     N_("Record"), N_("A->B Loop"), N_("Frame By Frame"), N_("Trickplay Reverse"),
116     N_("Step backward" ), N_("Step forward"), N_("Quit"), N_("Random"),
117     N_("Loop / Repeat"), N_("Information"), N_("Previous"), N_("Next"),
118     N_("Open subtitles"), N_("Dock fullscreen controller")
119 };
120 static const char* const tooltipL[BUTTON_MAX] = { I_PLAY_TOOLTIP,
121     N_("Stop playback"), N_("Open a medium"),
122     N_("Previous media in the playlist, skip backward when keep-pressed"),
123     N_("Next media in the playlist, skip forward when keep-pressed"), N_("Slower"), N_("Faster"),
124     N_("Toggle the video in fullscreen"), N_("Toggle the video out fullscreen"),
125     N_("Show extended settings" ), N_( "Show playlist" ),
126     N_( "Take a snapshot" ), N_( "Record" ),
127     N_( "Loop from point A to point B continuously." ), N_("Frame by frame"),
128     N_("Reverse"), N_("Step backward"), N_("Step forward"), N_("Quit"),
129     N_("Random"), N_("Change the loop and repeat modes"), N_("Information"),
130     N_("Previous media in the playlist"), N_("Next media in the playlist"),
131     N_("Open subtitles file"),
132     N_("Dock/undock fullscreen controller to/from bottom of screen")
133 };
134 static const QString iconL[BUTTON_MAX] ={ ":/toolbar/play_b", ":/toolbar/stop_b",
135     ":/toolbar/eject", ":/toolbar/previous_b", ":/toolbar/next_b",
136     ":/toolbar/slower", ":/toolbar/faster", ":/toolbar/fullscreen",
137     ":/toolbar/defullscreen", ":/toolbar/extended", ":/toolbar/playlist",
138     ":/toolbar/snapshot", ":/toolbar/record", ":/toolbar/atob_nob",
139     ":/toolbar/frame", ":/toolbar/reverse", ":/toolbar/skip_back",
140     ":/toolbar/skip_fw", ":/toolbar/clear", ":/buttons/playlist/shuffle_on",
141     ":/buttons/playlist/repeat_all", ":/menu/info",
142     ":/toolbar/previous_b", ":/toolbar/next_b", ":/toolbar/eject", ":/toolbar/space"
143 };
144
145 enum
146 {
147    WIDGET_NORMAL = 0x0,
148    WIDGET_FLAT   = 0x1,
149    WIDGET_BIG    = 0x2,
150    WIDGET_SHINY  = 0x4,
151 };
152
153 class AdvControlsWidget;
154 class AbstractController : public QFrame
155 {
156     friend class WidgetListing; /* For ToolBar Edition HACKS */
157
158     Q_OBJECT
159 public:
160     AbstractController( intf_thread_t  *_p_i, QWidget *_parent = 0 );
161
162 protected:
163     intf_thread_t       *p_intf;
164
165     QSignalMapper       *toolbarActionsMapper;
166     QHBoxLayout         *controlLayout;
167     /* Change to BoxLayout if both dir are needed */
168
169     AdvControlsWidget   *advControls;
170
171     void parseAndCreate( const QString& config, QBoxLayout *controlLayout );
172
173     virtual void createAndAddWidget( QBoxLayout *controlLayout, int i_index,
174                                      buttonType_e i_type, int i_option );
175
176     QWidget *createWidget( buttonType_e, int options = WIDGET_NORMAL );
177 private:
178     static void setupButton( QAbstractButton * );
179     QFrame *discFrame();
180     QFrame *telexFrame();
181     void applyAttributes( QToolButton *, bool b_flat, bool b_big );
182
183     QHBoxLayout         *buttonGroupLayout;
184 protected slots:
185     virtual void setStatus( int );
186
187 signals:
188     void inputExists( bool ); /// This might be useful in the IM ?
189     void inputPlaying( bool ); /// This might be useful in the IM ?
190     void inputIsRecordable( bool ); /// same ?
191     void inputIsTrickPlayable( bool ); /// same ?
192 };
193
194 /* Advanced Button Bar */
195 class AdvControlsWidget : public AbstractController
196 {
197     Q_OBJECT
198 public:
199     AdvControlsWidget( intf_thread_t *, QWidget *_parent = 0 );
200 };
201
202 /* Slider Bar */
203 class InputControlsWidget : public AbstractController
204 {
205     Q_OBJECT
206 public:
207     InputControlsWidget( intf_thread_t * , QWidget *_parent = 0 );
208 };
209
210 /* Button Bar */
211 class ControlsWidget : public AbstractController
212 {
213     Q_OBJECT
214 public:
215     /* p_intf, advanced control visible or not, blingbling or not */
216     ControlsWidget( intf_thread_t *_p_i, bool b_advControls,
217                     QWidget *_parent = 0 );
218
219     void setGripVisible( bool b_visible )
220     { grip->setVisible( b_visible ); }
221
222 protected:
223     friend class MainInterface;
224
225     bool b_advancedVisible;
226
227 private:
228     QSizeGrip *grip;
229
230 protected slots:
231     void toggleAdvanced();
232
233 signals:
234     void advancedControlsToggled( bool );
235 };
236
237
238 /* to trying transparency with fullscreen controller on windows enable that */
239 /* it can be enabled on-non windows systems,
240    but it will be transparent only with composite manager */
241 #define HAVE_TRANSPARENCY 1
242
243 /* Default value of opacity for FS controller */
244 #define DEFAULT_OPACITY 0.70
245
246 /* Used to restore the minimum width after a full-width switch */
247 #define FSC_WIDTH 800
248
249 #define FSC_HEIGHT 72
250
251 /***********************************
252  * Fullscreen controller
253  ***********************************/
254 class FullscreenControllerWidget : public AbstractController
255 {
256     Q_OBJECT
257 public:
258     FullscreenControllerWidget( intf_thread_t *, QWidget *_parent = 0  );
259     virtual ~FullscreenControllerWidget();
260
261     /* Vout */
262     void fullscreenChanged( vout_thread_t *, bool b_fs, int i_timeout );
263     void mouseChanged( vout_thread_t *, int i_mousex, int i_mousey );
264     void toggleFullwidth();
265     void updateFullwidthGeometry( int number );
266     int targetScreen();
267
268 signals:
269     void keyPressed( QKeyEvent * );
270
271 public slots:
272     void setVoutList( vout_thread_t **, int );
273
274 protected:
275     friend class MainInterface;
276
277     virtual void mouseMoveEvent( QMouseEvent *event );
278     virtual void mousePressEvent( QMouseEvent *event );
279     virtual void mouseReleaseEvent( QMouseEvent *event );
280     virtual void enterEvent( QEvent *event );
281     virtual void leaveEvent( QEvent *event );
282     virtual void keyPressEvent( QKeyEvent *event );
283
284     virtual void customEvent( QEvent *event );
285
286 private slots:
287     void showFSC();
288     void planHideFSC();
289     void hideFSC() { hide(); }
290     void slowHideFSC();
291     void restoreFSC();
292     void centerFSC( int );
293
294 private:
295     QTimer *p_hideTimer;
296 #if HAVE_TRANSPARENCY
297     QTimer *p_slowHideTimer;
298     bool b_slow_hide_begin;
299     int  i_slow_hide_timeout;
300     float f_opacity;
301 #endif
302
303     int i_mouse_last_x, i_mouse_last_y;
304     bool b_mouse_over;
305     int i_screennumber;
306     QRect screenRes;
307     QRect previousScreenRes;
308     QPoint previousPosition;
309
310     /* List of vouts currently tracked */
311     QList<vout_thread_t *> vout;
312
313     /* Shared variable between FSC and VLC (protected by a lock) */
314     vlc_mutex_t lock;
315     bool        b_fullscreen;
316     int         i_hide_timeout;  /* FSC hiding timeout, same as mouse hiding timeout */
317     int i_mouse_last_move_x;
318     int i_mouse_last_move_y;
319
320     bool isWideFSC;
321 };
322
323 #endif