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