]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.hpp
Fullscreen controller
[vlc] / modules / gui / qt4 / components / interface_widgets.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 _INTFWIDGETS_H_
27 #define _INTFWIDGETS_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 #include <vlc_aout.h>
36
37 #include "qt4.hpp"
38 #include "main_interface.hpp"
39 #include "input_manager.hpp"
40
41 #include <QWidget>
42 #include <QFrame>
43 #define VOLUME_MAX 200
44
45 /* on WIN32 hide() for fullscreen controller doesnt work, so it have to be
46    done by trick with setting the opacity of window */
47 #ifdef WIN32
48     #define WIN32TRICK
49 #endif
50
51 /* to trying transparency with fullscreen controller on windows enable that */
52 /* #define TRANSPARENCY */
53
54 /* it can be enabled on non windows systems,
55    but it will be transparent only with composite manager */
56 #ifndef WIN32
57     #define TRANSPARENCY
58 #endif
59
60
61 class ResizeEvent;
62 class QPalette;
63 class QPixmap;
64 class QLabel;
65 class QHBoxLayout;
66
67 /******************** Video Widget ****************/
68 class VideoWidget : public QFrame
69 {
70     Q_OBJECT
71 friend class MainInterface;
72
73 public:
74     VideoWidget( intf_thread_t * );
75     virtual ~VideoWidget();
76
77     void *request( vout_thread_t *, int *, int *,
78                    unsigned int *, unsigned int * );
79     void  release( void * );
80     int   control( void *, int, va_list );
81
82     virtual QSize sizeHint() const;
83 private:
84     intf_thread_t *p_intf;
85     vout_thread_t *p_vout;
86
87     vlc_mutex_t lock;
88     QSize videoSize;
89
90 signals:
91     void askVideoWidgetToShow();
92     //void askResize();
93
94 public slots:
95     void SetSizing( unsigned int, unsigned int );
96 };
97
98 /******************** Background Widget ****************/
99 class BackgroundWidget : public QWidget
100 {
101     Q_OBJECT
102 public:
103     BackgroundWidget( intf_thread_t * );
104     virtual ~BackgroundWidget();
105
106 private:
107     QPalette plt;
108     QLabel *label;
109     virtual void contextMenuEvent( QContextMenuEvent *event );
110     intf_thread_t *p_intf;
111     virtual void resizeEvent( QResizeEvent * event );
112 public slots:
113     void toggle(){ TOGGLEV( this ); }
114     void updateArt( QString );
115 };
116
117 class VisualSelector : public QFrame
118 {
119     Q_OBJECT
120 public:
121     VisualSelector( intf_thread_t *);
122     virtual ~VisualSelector();
123 private:
124     intf_thread_t *p_intf;
125     QLabel *current;
126 private slots:
127     void prev();
128     void next();
129 };
130
131 /* Advanced Button Bar */
132 class QPushButton;
133 class AdvControlsWidget : public QFrame
134 {
135     Q_OBJECT
136 public:
137     AdvControlsWidget( intf_thread_t *);
138     virtual ~AdvControlsWidget();
139
140     void enableInput( bool );
141     void enableVideo( bool );
142
143 private:
144     intf_thread_t *p_intf;
145     QPushButton *recordButton, *ABButton;
146     QPushButton *snapshotButton, *frameButton;
147
148     mtime_t timeA, timeB;
149
150 private slots:
151     void snapshot();
152 #if 0
153     void frame();
154 #endif
155     void fromAtoB();
156     void record();
157     void AtoBLoop( float, int, int );
158 };
159
160 /* Button Bar */
161 class InputSlider;
162 class QSlider;
163 class QGridLayout;
164 class VolumeClickHandler;
165 class SoundSlider;
166 class QAbstractSlider;
167 class QToolButton;
168
169 class ControlsWidget : public QFrame
170 {
171     Q_OBJECT
172 public:
173     /* p_intf, advanced control visible or not, blingbling or not */
174     ControlsWidget( intf_thread_t *_p_i, MainInterface *_p_mi,
175         bool b_advControls, bool b_shiny, bool b_fsCreation = false);
176     virtual ~ControlsWidget();
177
178     QPushButton *playlistButton;
179     void setStatus( int );
180     void enableInput( bool );
181     void enableVideo( bool );
182 public slots:
183     void setNavigation( int );
184 protected:
185     friend class MainInterface;
186     friend class VolumeClickHandler;
187 protected:
188     intf_thread_t       *p_intf;
189     QWidget             *discFrame;
190     QWidget             *telexFrame;
191     QGridLayout         *controlLayout;
192     InputSlider         *slider;
193     QPushButton         *prevSectionButton, *nextSectionButton, *menuButton;
194     QPushButton         *playButton, *fullscreenButton, *extSettingsButton;
195     QToolButton         *slowerButton, *fasterButton;
196     QHBoxLayout         *controlButLayout;
197     AdvControlsWidget   *advControls;
198     QLabel              *volMuteLabel;
199     QAbstractSlider     *volumeSlider;
200     VolumeClickHandler  *hVolLabel;
201
202     bool                 b_advancedVisible;
203 protected slots:
204     void play();
205     void stop();
206     void prev();
207     void next();
208     void updateVolume( int );
209     void updateVolume( void );
210     void updateInput();
211     void fullscreen();
212     void extSettings();
213     void faster();
214     void slower();
215     void toggleAdvanced();
216 signals:
217     void advancedControlsToggled( bool );
218 };
219
220 /***********************************
221  * Fullscreen controller
222  ***********************************/
223
224 static int showFullscreenControllCallback(vlc_object_t *vlc_object, const char *variable, vlc_value_t old_val,
225     vlc_value_t new_val, void *data);
226
227 static int regMouseMoveCallback(vlc_object_t *vlc_object, const char *variable, vlc_value_t old_val,
228     vlc_value_t new_val, void *data);
229
230 class FullscreenControllerWidget : public ControlsWidget
231 {
232     Q_OBJECT
233 public:
234     FullscreenControllerWidget( intf_thread_t *, MainInterface*, bool, bool );
235     virtual ~FullscreenControllerWidget();
236
237     void SetHideTimeout( int hideTimeout ) { i_hideTimeout = hideTimeout; }
238     void regFullscreenCallback( vout_thread_t *p_vout );
239
240     bool isFSCHidden();
241
242 public slots:
243     void unregFullscreenCallback();
244
245 protected:
246     friend class MainInterface;
247     friend class VolumeClickHandler;
248
249     virtual void mouseMoveEvent( QMouseEvent *event );
250     virtual void mousePressEvent( QMouseEvent *event );
251     virtual void enterEvent( QEvent *event );
252     virtual void leaveEvent( QEvent *event );
253     virtual void keyPressEvent( QKeyEvent *event );
254
255 private slots:
256     void hideFSControllerWidget();
257
258     #ifdef TRANSPARENCY
259     void slowHideFSC();
260     #endif
261
262 private:
263     QTimer *p_hideTimer;
264
265     #ifdef TRANSPARENCY
266     QTimer *p_slowHideTimer;
267     #endif
268
269     int i_lastPosX;
270     int i_lastPosY;
271     int i_hideTimeout;  /* FSC hiding timeout, same as mouse hiding timeout */
272     bool b_mouseIsOver;
273
274     #ifdef WIN32TRICK
275     bool fscHidden;
276     #endif
277
278     virtual void customEvent( QEvent *event );
279 };
280
281
282
283 class VolumeClickHandler : public QObject
284 {
285 public:
286     VolumeClickHandler( intf_thread_t *_p_intf, ControlsWidget *_m ) :QObject(_m)
287     {m = _m; p_intf = _p_intf; }
288     virtual ~VolumeClickHandler() {};
289     bool eventFilter( QObject *obj, QEvent *e )
290     {
291         if (e->type() == QEvent::MouseButtonPress  )
292         {
293             aout_VolumeMute( p_intf, NULL );
294             audio_volume_t i_volume;
295             aout_VolumeGet( p_intf, &i_volume );
296             m->updateVolume( i_volume *  VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
297             return true;
298         }
299         return false;
300     }
301 private:
302     ControlsWidget *m;
303     intf_thread_t *p_intf;
304 };
305
306 #include <QLabel>
307 #include <QMouseEvent>
308 class TimeLabel : public QLabel
309 {
310     Q_OBJECT
311     void mousePressEvent( QMouseEvent *event )
312     {
313         emit timeLabelClicked();
314     }
315     void mouseDoubleClickEvent( QMouseEvent *event )
316     {
317         emit timeLabelDoubleClicked();
318     }
319 signals:
320     void timeLabelClicked();
321     void timeLabelDoubleClicked();
322 };
323
324 class SpeedLabel : public QLabel
325 {
326     Q_OBJECT
327 public:
328     SpeedLabel( intf_thread_t *_p_intf, const QString text ): QLabel( text)
329     { p_intf = _p_intf; }
330
331 protected:
332     virtual void mouseDoubleClickEvent ( QMouseEvent * event )
333     {
334         THEMIM->getIM()->setRate( INPUT_RATE_DEFAULT );
335     }
336 private:
337     intf_thread_t *p_intf;
338 };
339
340 /******************** Speed Control Widgets ****************/
341 class SpeedControlWidget : public QFrame
342 {
343     Q_OBJECT
344 public:
345     SpeedControlWidget( intf_thread_t *);
346     virtual ~SpeedControlWidget();
347     void updateControls( int );
348 private:
349     intf_thread_t *p_intf;
350     QSlider *speedSlider;
351 public slots:
352     void setEnable( bool );
353 private slots:
354     void updateRate( int );
355     void resetRate();
356 };
357
358 #endif