]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.hpp
6150a01b8476b130452d99476e28c9f8c562d888
[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 #if 0
127 class VisualSelector : public QFrame
128 {
129     Q_OBJECT
130 public:
131     VisualSelector( intf_thread_t *);
132     virtual ~VisualSelector();
133 private:
134     intf_thread_t *p_intf;
135     QLabel *current;
136 private slots:
137     void prev();
138     void next();
139 };
140 #endif
141
142 /* Advanced Button Bar */
143 class QPushButton;
144 class AdvControlsWidget : public QFrame
145 {
146     Q_OBJECT
147 public:
148     AdvControlsWidget( intf_thread_t *, bool );
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     static 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     void setIcon();
170
171 signals:
172     void timeChanged();
173 };
174
175 /* Button Bar */
176 class InputSlider;
177 class QSlider;
178 class QGridLayout;
179 class VolumeClickHandler;
180 class SoundSlider;
181 class QAbstractSlider;
182 class QToolButton;
183
184 class ControlsWidget : public QFrame
185 {
186     Q_OBJECT
187 public:
188     /* p_intf, advanced control visible or not, blingbling or not */
189     ControlsWidget( intf_thread_t *_p_i, MainInterface *_p_mi,
190         bool b_advControls, bool b_shiny, bool b_fsCreation = false);
191     virtual ~ControlsWidget();
192
193     QPushButton *playlistButton;
194     void setStatus( int );
195     void enableInput( bool );
196     void enableVideo( bool );
197 public slots:
198     void setNavigation( int );
199 protected:
200     friend class MainInterface;
201     friend class VolumeClickHandler;
202 protected:
203     intf_thread_t       *p_intf;
204     QWidget             *discFrame;
205     QWidget             *telexFrame;
206     QGridLayout         *controlLayout;
207     InputSlider         *slider;
208     QPushButton         *prevSectionButton, *nextSectionButton, *menuButton;
209     QPushButton         *playButton, *fullscreenButton, *extSettingsButton;
210     QPushButton         *telexTransparent, *telexOn;
211     QSpinBox            *telexPage;
212     QToolButton         *slowerButton, *fasterButton;
213     QHBoxLayout         *controlButLayout;
214     AdvControlsWidget   *advControls;
215     QLabel              *volMuteLabel;
216     QAbstractSlider     *volumeSlider;
217     VolumeClickHandler  *hVolLabel;
218
219     bool                 b_advancedVisible;
220     bool                 b_telexTransparent;
221     bool                 b_telexEnabled;
222 protected slots:
223     void play();
224     void stop();
225     void prev();
226     void next();
227     void updateVolume( int );
228     void updateVolume( void );
229     void updateInput();
230     void fullscreen();
231     void extSettings();
232     void faster();
233     void slower();
234     void toggleAdvanced();
235     void toggleTeletext();
236     void toggleTeletextTransparency();
237     void enableTeletext( bool );
238 signals:
239     void advancedControlsToggled( bool );
240 };
241
242 /***********************************
243  * Fullscreen controller
244  ***********************************/
245 class FullscreenControllerWidget : public ControlsWidget
246 {
247     Q_OBJECT
248 public:
249     FullscreenControllerWidget( intf_thread_t *, MainInterface*, bool, bool );
250     virtual ~FullscreenControllerWidget();
251
252     /* */
253     void attachVout( vout_thread_t *p_vout );
254     void detachVout();
255     void fullscreenChanged( vout_thread_t *, bool b_fs, int i_timeout );
256
257 protected:
258     friend class MainInterface;
259     friend class VolumeClickHandler;
260
261     virtual void mouseMoveEvent( QMouseEvent *event );
262     virtual void mousePressEvent( QMouseEvent *event );
263     virtual void enterEvent( QEvent *event );
264     virtual void leaveEvent( QEvent *event );
265     virtual void keyPressEvent( QKeyEvent *event );
266
267 private slots:
268     void showFSC();
269     void planHideFSC();
270     void hideFSC();
271
272     void slowHideFSC();
273
274
275 private:
276     QTimer *p_hideTimer;
277 #if HAVE_TRANSPARENCY
278     QTimer *p_slowHideTimer;
279 #endif
280
281     int i_mouse_last_x;
282     int i_mouse_last_y;
283
284     bool b_mouse_over;
285
286     bool b_slow_hide_begin;
287     int  i_slow_hide_timeout;
288
289 #ifdef WIN32TRICK
290     bool fscHidden;
291 #endif
292
293     virtual void customEvent( QEvent *event );
294
295     vout_thread_t *p_vout;
296
297     /* Shared variable between FSC and VLC (protected by a lock) */
298     vlc_mutex_t lock;
299     bool        b_fullscreen;
300     int         i_hide_timeout;  /* FSC hiding timeout, same as mouse hiding timeout */
301 };
302
303
304
305 class VolumeClickHandler : public QObject
306 {
307 public:
308     VolumeClickHandler( intf_thread_t *_p_intf, ControlsWidget *_m ) :QObject(_m)
309     {m = _m; p_intf = _p_intf; }
310     virtual ~VolumeClickHandler() {};
311     bool eventFilter( QObject *obj, QEvent *e )
312     {
313         if (e->type() == QEvent::MouseButtonPress  )
314         {
315             aout_VolumeMute( p_intf, NULL );
316             audio_volume_t i_volume;
317             aout_VolumeGet( p_intf, &i_volume );
318             m->updateVolume( i_volume *  VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
319             return true;
320         }
321         return false;
322     }
323 private:
324     ControlsWidget *m;
325     intf_thread_t *p_intf;
326 };
327
328 #include <QLabel>
329 #include <QMouseEvent>
330 class TimeLabel : public QLabel
331 {
332     Q_OBJECT
333     void mousePressEvent( QMouseEvent *event )
334     {
335         emit timeLabelClicked();
336     }
337     void mouseDoubleClickEvent( QMouseEvent *event )
338     {
339         emit timeLabelDoubleClicked();
340     }
341 signals:
342     void timeLabelClicked();
343     void timeLabelDoubleClicked();
344 };
345
346 class SpeedLabel : public QLabel
347 {
348     Q_OBJECT
349 public:
350     SpeedLabel( intf_thread_t *_p_intf, const QString text ): QLabel( text)
351     { p_intf = _p_intf; }
352
353 protected:
354     virtual void mouseDoubleClickEvent ( QMouseEvent * event )
355     {
356         THEMIM->getIM()->setRate( INPUT_RATE_DEFAULT );
357     }
358 private:
359     intf_thread_t *p_intf;
360 };
361
362 /******************** Speed Control Widgets ****************/
363 class SpeedControlWidget : public QFrame
364 {
365     Q_OBJECT
366 public:
367     SpeedControlWidget( intf_thread_t *);
368     virtual ~SpeedControlWidget();
369     void updateControls( int );
370 private:
371     intf_thread_t *p_intf;
372     QSlider *speedSlider;
373 public slots:
374     void setEnable( bool );
375 private slots:
376     void updateRate( int );
377     void resetRate();
378 };
379
380 #endif