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