]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.hpp
Qt4: apprently fix the embedded video
[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 QPaintEngine *paintEngine() const
107     {
108         return NULL;
109     }
110
111     virtual void paintEvent(QPaintEvent *);
112 };
113
114 /******************** Background Widget ****************/
115 class BackgroundWidget : public QWidget
116 {
117     Q_OBJECT
118 public:
119     BackgroundWidget( intf_thread_t * );
120     virtual ~BackgroundWidget();
121
122 private:
123     QPalette plt;
124     QLabel *label;
125     virtual void contextMenuEvent( QContextMenuEvent *event );
126     intf_thread_t *p_intf;
127     virtual void resizeEvent( QResizeEvent * event );
128 public slots:
129     void toggle(){ TOGGLEV( this ); }
130     void updateArt( QString );
131 };
132
133 class VisualSelector : public QFrame
134 {
135     Q_OBJECT
136 public:
137     VisualSelector( intf_thread_t *);
138     virtual ~VisualSelector();
139 private:
140     intf_thread_t *p_intf;
141     QLabel *current;
142 private slots:
143     void prev();
144     void next();
145 };
146
147 /* Advanced Button Bar */
148 class QPushButton;
149 class AdvControlsWidget : public QFrame
150 {
151     Q_OBJECT
152 public:
153     AdvControlsWidget( intf_thread_t *);
154     virtual ~AdvControlsWidget();
155
156     void enableInput( bool );
157     void enableVideo( bool );
158
159 private:
160     intf_thread_t *p_intf;
161     QPushButton *recordButton, *ABButton;
162     QPushButton *snapshotButton, *frameButton;
163
164     mtime_t timeA, timeB;
165
166 private slots:
167     void snapshot();
168 #if 0
169     void frame();
170 #endif
171     void fromAtoB();
172     void record();
173     void AtoBLoop( float, int, int );
174 };
175
176 /* Button Bar */
177 class InputSlider;
178 class QSlider;
179 class QGridLayout;
180 class VolumeClickHandler;
181 class SoundSlider;
182 class QAbstractSlider;
183 class QToolButton;
184
185 class ControlsWidget : public QFrame
186 {
187     Q_OBJECT
188 public:
189     /* p_intf, advanced control visible or not, blingbling or not */
190     ControlsWidget( intf_thread_t *_p_i, MainInterface *_p_mi,
191         bool b_advControls, bool b_shiny, bool b_fsCreation = false);
192     virtual ~ControlsWidget();
193
194     QPushButton *playlistButton;
195     void setStatus( int );
196     void enableInput( bool );
197     void enableVideo( bool );
198 public slots:
199     void setNavigation( int );
200 protected:
201     friend class MainInterface;
202     friend class VolumeClickHandler;
203 protected:
204     intf_thread_t       *p_intf;
205     QWidget             *discFrame;
206     QWidget             *telexFrame;
207     QGridLayout         *controlLayout;
208     InputSlider         *slider;
209     QPushButton         *prevSectionButton, *nextSectionButton, *menuButton;
210     QPushButton         *playButton, *fullscreenButton, *extSettingsButton;
211     QPushButton         *telexTransparent;
212     QSpinBox            *telexPage;
213     QToolButton         *slowerButton, *fasterButton;
214     QHBoxLayout         *controlButLayout;
215     AdvControlsWidget   *advControls;
216     QLabel              *volMuteLabel;
217     QAbstractSlider     *volumeSlider;
218     VolumeClickHandler  *hVolLabel;
219
220     bool                 b_advancedVisible;
221     bool                 b_telexTransparent;
222     bool                 b_telexEnabled;
223 protected slots:
224     void play();
225     void stop();
226     void prev();
227     void next();
228     void updateVolume( int );
229     void updateVolume( void );
230     void updateInput();
231     void fullscreen();
232     void extSettings();
233     void faster();
234     void slower();
235     void toggleAdvanced();
236     void toggleTeletext();
237     void toggleTeletextTransparency();
238 signals:
239     void advancedControlsToggled( bool );
240 };
241
242 /***********************************
243  * Fullscreen controller
244  ***********************************/
245
246 static int showFullscreenControllCallback(vlc_object_t *vlc_object, const char *variable, vlc_value_t old_val,
247     vlc_value_t new_val, void *data);
248
249 static int regMouseMoveCallback(vlc_object_t *vlc_object, const char *variable, vlc_value_t old_val,
250     vlc_value_t new_val, void *data);
251
252 class FullscreenControllerWidget : public ControlsWidget
253 {
254     Q_OBJECT
255 public:
256     FullscreenControllerWidget( intf_thread_t *, MainInterface*, bool, bool );
257     virtual ~FullscreenControllerWidget();
258
259     void SetHideTimeout( int hideTimeout ) { i_hideTimeout = hideTimeout; }
260     void regFullscreenCallback( vout_thread_t *p_vout );
261
262     bool isFSCHidden();
263
264 public slots:
265     void unregFullscreenCallback();
266
267 protected:
268     friend class MainInterface;
269     friend class VolumeClickHandler;
270
271     virtual void mouseMoveEvent( QMouseEvent *event );
272     virtual void mousePressEvent( QMouseEvent *event );
273     virtual void enterEvent( QEvent *event );
274     virtual void leaveEvent( QEvent *event );
275     virtual void keyPressEvent( QKeyEvent *event );
276
277 private slots:
278     void hideFSControllerWidget();
279     void slowHideFSC();
280
281 private:
282     QTimer *p_hideTimer;
283
284 #if HAVE_TRANSPARENCY
285     QTimer *p_slowHideTimer;
286 #endif
287
288     int i_lastPosX;
289     int i_lastPosY;
290     int i_hideTimeout;  /* FSC hiding timeout, same as mouse hiding timeout */
291     bool b_mouseIsOver;
292
293 #ifdef WIN32TRICK
294     bool fscHidden;
295 #endif
296
297     virtual void customEvent( QEvent *event );
298 };
299
300
301
302 class VolumeClickHandler : public QObject
303 {
304 public:
305     VolumeClickHandler( intf_thread_t *_p_intf, ControlsWidget *_m ) :QObject(_m)
306     {m = _m; p_intf = _p_intf; }
307     virtual ~VolumeClickHandler() {};
308     bool eventFilter( QObject *obj, QEvent *e )
309     {
310         if (e->type() == QEvent::MouseButtonPress  )
311         {
312             aout_VolumeMute( p_intf, NULL );
313             audio_volume_t i_volume;
314             aout_VolumeGet( p_intf, &i_volume );
315             m->updateVolume( i_volume *  VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
316             return true;
317         }
318         return false;
319     }
320 private:
321     ControlsWidget *m;
322     intf_thread_t *p_intf;
323 };
324
325 #include <QLabel>
326 #include <QMouseEvent>
327 class TimeLabel : public QLabel
328 {
329     Q_OBJECT
330     void mousePressEvent( QMouseEvent *event )
331     {
332         emit timeLabelClicked();
333     }
334     void mouseDoubleClickEvent( QMouseEvent *event )
335     {
336         emit timeLabelDoubleClicked();
337     }
338 signals:
339     void timeLabelClicked();
340     void timeLabelDoubleClicked();
341 };
342
343 class SpeedLabel : public QLabel
344 {
345     Q_OBJECT
346 public:
347     SpeedLabel( intf_thread_t *_p_intf, const QString text ): QLabel( text)
348     { p_intf = _p_intf; }
349
350 protected:
351     virtual void mouseDoubleClickEvent ( QMouseEvent * event )
352     {
353         THEMIM->getIM()->setRate( INPUT_RATE_DEFAULT );
354     }
355 private:
356     intf_thread_t *p_intf;
357 };
358
359 /******************** Speed Control Widgets ****************/
360 class SpeedControlWidget : public QFrame
361 {
362     Q_OBJECT
363 public:
364     SpeedControlWidget( intf_thread_t *);
365     virtual ~SpeedControlWidget();
366     void updateControls( int );
367 private:
368     intf_thread_t *p_intf;
369     QSlider *speedSlider;
370 public slots:
371     void setEnable( bool );
372 private slots:
373     void updateRate( int );
374     void resetRate();
375 };
376
377 #endif