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