]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.hpp
Warning killing.
[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     QToolButton         *slowerButton, *fasterButton;
199     QHBoxLayout         *controlButLayout;
200     AdvControlsWidget   *advControls;
201     QLabel              *volMuteLabel;
202     QAbstractSlider     *volumeSlider;
203     VolumeClickHandler  *hVolLabel;
204
205     bool                 b_advancedVisible;
206 protected slots:
207     void play();
208     void stop();
209     void prev();
210     void next();
211     void updateVolume( int );
212     void updateVolume( void );
213     void updateInput();
214     void fullscreen();
215     void extSettings();
216     void faster();
217     void slower();
218     void toggleAdvanced();
219 signals:
220     void advancedControlsToggled( bool );
221 };
222
223 /***********************************
224  * Fullscreen controller
225  ***********************************/
226
227 static int showFullscreenControllCallback(vlc_object_t *vlc_object, const char *variable, vlc_value_t old_val,
228     vlc_value_t new_val, void *data);
229
230 static int regMouseMoveCallback(vlc_object_t *vlc_object, const char *variable, vlc_value_t old_val,
231     vlc_value_t new_val, void *data);
232
233 class FullscreenControllerWidget : public ControlsWidget
234 {
235     Q_OBJECT
236 public:
237     FullscreenControllerWidget( intf_thread_t *, MainInterface*, bool, bool );
238     virtual ~FullscreenControllerWidget();
239
240     void SetHideTimeout( int hideTimeout ) { i_hideTimeout = hideTimeout; }
241     void regFullscreenCallback( vout_thread_t *p_vout );
242
243     bool isFSCHidden();
244
245 public slots:
246     void unregFullscreenCallback();
247
248 protected:
249     friend class MainInterface;
250     friend class VolumeClickHandler;
251
252     virtual void mouseMoveEvent( QMouseEvent *event );
253     virtual void mousePressEvent( QMouseEvent *event );
254     virtual void enterEvent( QEvent *event );
255     virtual void leaveEvent( QEvent *event );
256     virtual void keyPressEvent( QKeyEvent *event );
257
258 private slots:
259     void hideFSControllerWidget();
260     void slowHideFSC();
261
262 private:
263     QTimer *p_hideTimer;
264
265 #if HAVE_TRANSPARENCY
266     QTimer *p_slowHideTimer;
267 #endif
268
269     int i_lastPosX;
270     int i_lastPosY;
271     int i_hideTimeout;  /* FSC hiding timeout, same as mouse hiding timeout */
272     bool b_mouseIsOver;
273
274 #ifdef WIN32TRICK
275     bool fscHidden;
276 #endif
277
278     virtual void customEvent( QEvent *event );
279 };
280
281
282
283 class VolumeClickHandler : public QObject
284 {
285 public:
286     VolumeClickHandler( intf_thread_t *_p_intf, ControlsWidget *_m ) :QObject(_m)
287     {m = _m; p_intf = _p_intf; }
288     virtual ~VolumeClickHandler() {};
289     bool eventFilter( QObject *obj, QEvent *e )
290     {
291         if (e->type() == QEvent::MouseButtonPress  )
292         {
293             aout_VolumeMute( p_intf, NULL );
294             audio_volume_t i_volume;
295             aout_VolumeGet( p_intf, &i_volume );
296             m->updateVolume( i_volume *  VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
297             return true;
298         }
299         return false;
300     }
301 private:
302     ControlsWidget *m;
303     intf_thread_t *p_intf;
304 };
305
306 #include <QLabel>
307 #include <QMouseEvent>
308 class TimeLabel : public QLabel
309 {
310     Q_OBJECT
311     void mousePressEvent( QMouseEvent *event )
312     {
313         emit timeLabelClicked();
314     }
315     void mouseDoubleClickEvent( QMouseEvent *event )
316     {
317         emit timeLabelDoubleClicked();
318     }
319 signals:
320     void timeLabelClicked();
321     void timeLabelDoubleClicked();
322 };
323
324 class SpeedLabel : public QLabel
325 {
326     Q_OBJECT
327 public:
328     SpeedLabel( intf_thread_t *_p_intf, const QString text ): QLabel( text)
329     { p_intf = _p_intf; }
330
331 protected:
332     virtual void mouseDoubleClickEvent ( QMouseEvent * event )
333     {
334         THEMIM->getIM()->setRate( INPUT_RATE_DEFAULT );
335     }
336 private:
337     intf_thread_t *p_intf;
338 };
339
340 /******************** Speed Control Widgets ****************/
341 class SpeedControlWidget : public QFrame
342 {
343     Q_OBJECT
344 public:
345     SpeedControlWidget( intf_thread_t *);
346     virtual ~SpeedControlWidget();
347     void updateControls( int );
348 private:
349     intf_thread_t *p_intf;
350     QSlider *speedSlider;
351 public slots:
352     void setEnable( bool );
353 private slots:
354     void updateRate( int );
355     void resetRate();
356 };
357
358 #endif