]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.hpp
Qt: don't save A to B state when the input item changes. Also go to A if before curre...
[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     int i_last_input_id;
161
162 private slots:
163     void snapshot();
164 #if 0
165     void frame();
166 #endif
167     void fromAtoB();
168     void record();
169     void AtoBLoop( float, int, int );
170     void setIcon();
171
172 signals:
173     void timeChanged();
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, *telexOn;
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     void enableTeletext( bool );
239 signals:
240     void advancedControlsToggled( bool );
241 };
242
243 /***********************************
244  * Fullscreen controller
245  ***********************************/
246 class FullscreenControllerWidget : public ControlsWidget
247 {
248     Q_OBJECT
249 public:
250     FullscreenControllerWidget( intf_thread_t *, MainInterface*, bool, bool );
251     virtual ~FullscreenControllerWidget();
252
253     /* */
254     void attachVout( vout_thread_t *p_vout );
255     void detachVout();
256     void fullscreenChanged( vout_thread_t *, bool b_fs, int i_timeout );
257
258 protected:
259     friend class MainInterface;
260     friend class VolumeClickHandler;
261
262     virtual void mouseMoveEvent( QMouseEvent *event );
263     virtual void mousePressEvent( QMouseEvent *event );
264     virtual void enterEvent( QEvent *event );
265     virtual void leaveEvent( QEvent *event );
266     virtual void keyPressEvent( QKeyEvent *event );
267
268 private slots:
269     void showFSC();
270     void planHideFSC();
271     void hideFSC();
272
273     void slowHideFSC();
274
275
276 private:
277     QTimer *p_hideTimer;
278 #if HAVE_TRANSPARENCY
279     QTimer *p_slowHideTimer;
280 #endif
281
282     int i_mouse_last_x;
283     int i_mouse_last_y;
284
285     bool b_mouse_over;
286
287     bool b_slow_hide_begin;
288     int  i_slow_hide_timeout;
289
290 #ifdef WIN32TRICK
291     bool fscHidden;
292 #endif
293
294     virtual void customEvent( QEvent *event );
295
296     vout_thread_t *p_vout;
297
298     /* Shared variable between FSC and VLC (protected by a lock) */
299     vlc_mutex_t lock;
300     bool        b_fullscreen;
301     int         i_hide_timeout;  /* FSC hiding timeout, same as mouse hiding timeout */
302 };
303
304
305
306 class VolumeClickHandler : public QObject
307 {
308 public:
309     VolumeClickHandler( intf_thread_t *_p_intf, ControlsWidget *_m ) :QObject(_m)
310     {m = _m; p_intf = _p_intf; }
311     virtual ~VolumeClickHandler() {};
312     bool eventFilter( QObject *obj, QEvent *e )
313     {
314         if (e->type() == QEvent::MouseButtonPress  )
315         {
316             aout_VolumeMute( p_intf, NULL );
317             audio_volume_t i_volume;
318             aout_VolumeGet( p_intf, &i_volume );
319             m->updateVolume( i_volume *  VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
320             return true;
321         }
322         return false;
323     }
324 private:
325     ControlsWidget *m;
326     intf_thread_t *p_intf;
327 };
328
329 #include <QLabel>
330 #include <QMouseEvent>
331 class TimeLabel : public QLabel
332 {
333     Q_OBJECT
334     void mousePressEvent( QMouseEvent *event )
335     {
336         emit timeLabelClicked();
337     }
338     void mouseDoubleClickEvent( QMouseEvent *event )
339     {
340         emit timeLabelDoubleClicked();
341     }
342 signals:
343     void timeLabelClicked();
344     void timeLabelDoubleClicked();
345 };
346
347 class SpeedLabel : public QLabel
348 {
349     Q_OBJECT
350 public:
351     SpeedLabel( intf_thread_t *_p_intf, const QString text ): QLabel( text)
352     { p_intf = _p_intf; }
353
354 protected:
355     virtual void mouseDoubleClickEvent ( QMouseEvent * event )
356     {
357         THEMIM->getIM()->setRate( INPUT_RATE_DEFAULT );
358     }
359 private:
360     intf_thread_t *p_intf;
361 };
362
363 /******************** Speed Control Widgets ****************/
364 class SpeedControlWidget : public QFrame
365 {
366     Q_OBJECT
367 public:
368     SpeedControlWidget( intf_thread_t *);
369     virtual ~SpeedControlWidget();
370     void updateControls( int );
371 private:
372     intf_thread_t *p_intf;
373     QSlider *speedSlider;
374 public slots:
375     void setEnable( bool );
376 private slots:
377     void updateRate( int );
378     void resetRate();
379 };
380
381 #endif