]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.hpp
911eb89bac5e70d016315b43bfc8565b1655a46c
[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 /* it can be enabled on-non windows systems,
54    but it will be transparent only with composite manager */
55 #ifndef WIN32
56     #define HAVE_TRANSPARENCY 1
57 #else
58     #define HAVE_TRANSPARENCY 0
59 #endif
60
61 /* Default value of opacity for FS controller */
62 #define DEFAULT_OPACITY 0.75
63
64 class ResizeEvent;
65 class QPalette;
66 class QPixmap;
67 class QLabel;
68 class QHBoxLayout;
69
70 /******************** Video Widget ****************/
71 class VideoWidget : public QFrame
72 {
73     Q_OBJECT
74 friend class MainInterface;
75
76 public:
77     VideoWidget( intf_thread_t * );
78     virtual ~VideoWidget();
79
80     void *request( vout_thread_t *, int *, int *,
81                    unsigned int *, unsigned int * );
82     void  release( void * );
83     int   control( void *, int, va_list );
84
85     virtual QSize sizeHint() const;
86 private:
87     intf_thread_t *p_intf;
88     int i_vout;
89
90     QSize videoSize;
91
92 signals:
93     void askVideoWidgetToShow( unsigned int, unsigned int );
94
95 public slots:
96     void SetSizing( unsigned int, unsigned int );
97
98 protected:
99     virtual QPaintEngine *paintEngine() const
100     {
101         return NULL;
102     }
103
104     virtual void paintEvent(QPaintEvent *);
105 };
106
107 /******************** Background Widget ****************/
108 class BackgroundWidget : public QWidget
109 {
110     Q_OBJECT
111 public:
112     BackgroundWidget( intf_thread_t * );
113     virtual ~BackgroundWidget();
114
115 private:
116     QPalette plt;
117     QLabel *label;
118     virtual void contextMenuEvent( QContextMenuEvent *event );
119     intf_thread_t *p_intf;
120     virtual void resizeEvent( QResizeEvent * event );
121 public slots:
122     void toggle(){ TOGGLEV( this ); }
123     void updateArt( QString );
124 };
125
126 class VisualSelector : public QFrame
127 {
128     Q_OBJECT
129 public:
130     VisualSelector( intf_thread_t *);
131     virtual ~VisualSelector();
132 private:
133     intf_thread_t *p_intf;
134     QLabel *current;
135 private slots:
136     void prev();
137     void next();
138 };
139
140 /* Advanced Button Bar */
141 class QPushButton;
142 class AdvControlsWidget : public QFrame
143 {
144     Q_OBJECT
145 public:
146     AdvControlsWidget( intf_thread_t *);
147     virtual ~AdvControlsWidget();
148
149     void enableInput( bool );
150     void enableVideo( bool );
151
152 private:
153     intf_thread_t *p_intf;
154     QPushButton *recordButton, *ABButton;
155     QPushButton *snapshotButton, *frameButton;
156
157     mtime_t timeA, timeB;
158
159 private slots:
160     void snapshot();
161 #if 0
162     void frame();
163 #endif
164     void fromAtoB();
165     void record();
166     void AtoBLoop( float, int, int );
167 };
168
169 /* Button Bar */
170 class InputSlider;
171 class QSlider;
172 class QGridLayout;
173 class VolumeClickHandler;
174 class SoundSlider;
175 class QAbstractSlider;
176 class QToolButton;
177
178 class ControlsWidget : public QFrame
179 {
180     Q_OBJECT
181 public:
182     /* p_intf, advanced control visible or not, blingbling or not */
183     ControlsWidget( intf_thread_t *_p_i, MainInterface *_p_mi,
184         bool b_advControls, bool b_shiny, bool b_fsCreation = false);
185     virtual ~ControlsWidget();
186
187     QPushButton *playlistButton;
188     void setStatus( int );
189     void enableInput( bool );
190     void enableVideo( bool );
191 public slots:
192     void setNavigation( int );
193 protected:
194     friend class MainInterface;
195     friend class VolumeClickHandler;
196 protected:
197     intf_thread_t       *p_intf;
198     QWidget             *discFrame;
199     QWidget             *telexFrame;
200     QGridLayout         *controlLayout;
201     InputSlider         *slider;
202     QPushButton         *prevSectionButton, *nextSectionButton, *menuButton;
203     QPushButton         *playButton, *fullscreenButton, *extSettingsButton;
204     QPushButton         *telexTransparent, *telexOn;
205     QSpinBox            *telexPage;
206     QToolButton         *slowerButton, *fasterButton;
207     QHBoxLayout         *controlButLayout;
208     AdvControlsWidget   *advControls;
209     QLabel              *volMuteLabel;
210     QAbstractSlider     *volumeSlider;
211     VolumeClickHandler  *hVolLabel;
212
213     bool                 b_advancedVisible;
214     bool                 b_telexTransparent;
215     bool                 b_telexEnabled;
216 protected slots:
217     void play();
218     void stop();
219     void prev();
220     void next();
221     void updateVolume( int );
222     void updateVolume( void );
223     void updateInput();
224     void fullscreen();
225     void extSettings();
226     void faster();
227     void slower();
228     void toggleAdvanced();
229     void toggleTeletext();
230     void toggleTeletextTransparency();
231     void enableTeletext( bool );
232 signals:
233     void advancedControlsToggled( bool );
234 };
235
236 /***********************************
237  * Fullscreen controller
238  ***********************************/
239 class FullscreenControllerWidget : public ControlsWidget
240 {
241     Q_OBJECT
242 public:
243     FullscreenControllerWidget( intf_thread_t *, MainInterface*, bool, bool );
244     virtual ~FullscreenControllerWidget();
245
246     /* */
247     void attachVout( vout_thread_t *p_vout );
248     void detachVout( vout_thread_t *p_vout );
249     void fullscreenChanged( vout_thread_t *, bool b_fs, int i_timeout );
250
251 protected:
252     friend class MainInterface;
253     friend class VolumeClickHandler;
254
255     virtual void mouseMoveEvent( QMouseEvent *event );
256     virtual void mousePressEvent( QMouseEvent *event );
257     virtual void enterEvent( QEvent *event );
258     virtual void leaveEvent( QEvent *event );
259     virtual void keyPressEvent( QKeyEvent *event );
260
261 private slots:
262     void showFSC();
263     void planHideFSC();
264     void hideFSC();
265
266     void slowHideFSC();
267
268
269 private:
270     QTimer *p_hideTimer;
271 #if HAVE_TRANSPARENCY
272     QTimer *p_slowHideTimer;
273 #endif
274
275     int i_mouse_last_x;
276     int i_mouse_last_y;
277
278     bool b_mouse_over;
279
280     bool b_slow_hide_begin;
281     int  i_slow_hide_timeout;
282
283 #ifdef WIN32TRICK
284     bool fscHidden;
285 #endif
286
287     virtual void customEvent( QEvent *event );
288
289     /* Shared variable between FSC and VLC (protected by a lock) */
290     vlc_mutex_t lock;
291     bool        b_fullscreen;
292     int         i_hide_timeout;  /* FSC hiding timeout, same as mouse hiding timeout */
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