]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.hpp
Qt4: Really split the TimeLabel into its own class.
[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 class ResizeEvent;
45 class QPalette;
46 class QPixmap;
47 class QLabel;
48 class QHBoxLayout;
49
50 /******************** Video Widget ****************/
51 class VideoWidget : public QFrame
52 {
53     Q_OBJECT
54 friend class MainInterface;
55
56 public:
57     VideoWidget( intf_thread_t * );
58     virtual ~VideoWidget();
59
60     void *request( vout_thread_t *, int *, int *,
61                    unsigned int *, unsigned int * );
62     void  release( void * );
63     int   control( void *, int, va_list );
64
65     virtual QSize sizeHint() const;
66 private:
67     intf_thread_t *p_intf;
68     vout_thread_t *p_vout;
69
70     QSize videoSize;
71
72 signals:
73     void askVideoWidgetToShow( unsigned int, unsigned int );
74
75 public slots:
76     void SetSizing( unsigned int, unsigned int );
77
78 protected:
79     virtual QPaintEngine *paintEngine() const
80     {
81         return NULL;
82     }
83
84     virtual void paintEvent(QPaintEvent *);
85 };
86
87 /******************** Background Widget ****************/
88 class BackgroundWidget : public QWidget
89 {
90     Q_OBJECT
91 public:
92     BackgroundWidget( intf_thread_t * );
93     virtual ~BackgroundWidget();
94
95 private:
96     QPalette plt;
97     QLabel *label;
98     virtual void contextMenuEvent( QContextMenuEvent *event );
99     intf_thread_t *p_intf;
100     virtual void resizeEvent( QResizeEvent * event );
101 public slots:
102     void toggle(){ TOGGLEV( this ); }
103     void updateArt( input_item_t* );
104 };
105
106 #if 0
107 class VisualSelector : public QFrame
108 {
109     Q_OBJECT
110 public:
111     VisualSelector( intf_thread_t *);
112     virtual ~VisualSelector();
113 private:
114     intf_thread_t *p_intf;
115     QLabel *current;
116 private slots:
117     void prev();
118     void next();
119 };
120 #endif
121
122 /* Advanced Button Bar */
123 class QPushButton;
124 class AdvControlsWidget : public QFrame
125 {
126     Q_OBJECT
127 public:
128     AdvControlsWidget( intf_thread_t *, bool );
129     virtual ~AdvControlsWidget();
130
131     void enableInput( bool );
132     void enableVideo( bool );
133
134 private:
135     intf_thread_t *p_intf;
136     QPushButton *recordButton, *ABButton;
137     QPushButton *snapshotButton, *frameButton;
138
139     static mtime_t timeA, timeB;
140     int i_last_input_id;
141
142 private slots:
143     void snapshot();
144 #if 0
145     void frame();
146 #endif
147     void fromAtoB();
148     void record();
149     void AtoBLoop( float, int, int );
150     void setIcon();
151
152 signals:
153     void timeChanged();
154 };
155
156 /* Button Bar */
157 class InputSlider;
158 class QSlider;
159 class QGridLayout;
160 class VolumeClickHandler;
161 class SoundSlider;
162 class QAbstractSlider;
163 class QToolButton;
164
165 class ControlsWidget : public QFrame
166 {
167     Q_OBJECT
168 public:
169     /* p_intf, advanced control visible or not, blingbling or not */
170     ControlsWidget( intf_thread_t *_p_i, MainInterface *_p_mi,
171         bool b_advControls, bool b_shiny, bool b_fsCreation = false);
172     virtual ~ControlsWidget();
173
174     QPushButton *playlistButton;
175     void setStatus( int );
176     void enableInput( bool );
177 public slots:
178     void setNavigation( int );
179 protected:
180     friend class MainInterface;
181     friend class VolumeClickHandler;
182 protected:
183     intf_thread_t       *p_intf;
184     QWidget             *discFrame;
185     QWidget             *telexFrame;
186     QGridLayout         *controlLayout;
187     InputSlider         *slider;
188     QPushButton         *prevSectionButton, *nextSectionButton, *menuButton;
189     QPushButton         *playButton, *fullscreenButton, *extSettingsButton;
190     QPushButton         *telexTransparent, *telexOn;
191     QSpinBox            *telexPage;
192     QToolButton         *slowerButton, *fasterButton;
193     QHBoxLayout         *controlButLayout;
194     AdvControlsWidget   *advControls;
195     QLabel              *volMuteLabel;
196     QAbstractSlider     *volumeSlider;
197     VolumeClickHandler  *hVolLabel;
198
199     bool                 b_advancedVisible;
200     bool                 b_telexTransparent;
201     bool                 b_telexEnabled;
202 protected slots:
203     void play();
204     void stop();
205     void prev();
206     void next();
207     void updateVolume( int );
208     void updateVolume( void );
209     void updateInput();
210     void fullscreen();
211     void extSettings();
212     void faster();
213     void slower();
214     void toggleAdvanced();
215     void toggleTeletext();
216     void toggleTeletextTransparency();
217     void enableTeletext( bool );
218     void enableVideo( bool );
219 signals:
220     void advancedControlsToggled( bool );
221 };
222
223 /* on WIN32 hide() for fullscreen controller doesnt work, so it have to be
224    done by trick with setting the opacity of window */
225 #ifdef WIN32
226     #define WIN32TRICK
227 #endif
228
229 /* to trying transparency with fullscreen controller on windows enable that */
230 /* it can be enabled on-non windows systems,
231    but it will be transparent only with composite manager */
232 #ifndef WIN32
233     #define HAVE_TRANSPARENCY 1
234 #else
235     #define HAVE_TRANSPARENCY 0
236 #endif
237
238 /* Default value of opacity for FS controller */
239 #define DEFAULT_OPACITY 0.75
240
241 /***********************************
242  * Fullscreen controller
243  ***********************************/
244 class FullscreenControllerWidget : public ControlsWidget
245 {
246     Q_OBJECT
247 public:
248     FullscreenControllerWidget( intf_thread_t *, MainInterface*, bool, bool );
249     virtual ~FullscreenControllerWidget();
250
251     /* */
252     void attachVout( vout_thread_t *p_vout );
253     void detachVout();
254     void fullscreenChanged( vout_thread_t *, bool b_fs, int i_timeout );
255     vout_thread_t *p_vout;
256
257     int i_mouse_last_move_x;
258     int i_mouse_last_move_y;
259
260 protected:
261     friend class MainInterface;
262     friend class VolumeClickHandler;
263
264     virtual void mouseMoveEvent( QMouseEvent *event );
265     virtual void mousePressEvent( QMouseEvent *event );
266     virtual void enterEvent( QEvent *event );
267     virtual void leaveEvent( QEvent *event );
268     virtual void keyPressEvent( QKeyEvent *event );
269
270 private slots:
271     void showFSC();
272     void planHideFSC();
273     void hideFSC();
274
275     void slowHideFSC();
276
277
278 private:
279     QTimer *p_hideTimer;
280 #if HAVE_TRANSPARENCY
281     QTimer *p_slowHideTimer;
282 #endif
283
284     int i_mouse_last_x;
285     int i_mouse_last_y;
286
287     bool b_mouse_over;
288
289     bool b_slow_hide_begin;
290     int  i_slow_hide_timeout;
291
292 #ifdef WIN32TRICK
293     bool b_fscHidden;
294 #endif
295
296     virtual void customEvent( QEvent *event );
297
298
299     /* Shared variable between FSC and VLC (protected by a lock) */
300     vlc_mutex_t lock;
301     bool        b_fullscreen;
302     int         i_hide_timeout;  /* FSC hiding timeout, same as mouse hiding timeout */
303 };
304
305
306 #define VOLUME_MAX 200
307 class VolumeClickHandler : public QObject
308 {
309 public:
310     VolumeClickHandler( intf_thread_t *_p_intf, ControlsWidget *_m ) :QObject(_m)
311     {m = _m; p_intf = _p_intf; }
312     virtual ~VolumeClickHandler() {};
313     bool eventFilter( QObject *obj, QEvent *e )
314     {
315         if (e->type() == QEvent::MouseButtonPress  )
316         {
317             aout_VolumeMute( p_intf, NULL );
318             audio_volume_t i_volume;
319             aout_VolumeGet( p_intf, &i_volume );
320             m->updateVolume( i_volume *  VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
321             return true;
322         }
323         return false;
324     }
325 private:
326     ControlsWidget *m;
327     intf_thread_t *p_intf;
328 };
329
330 #include <QLabel>
331 #include <QMouseEvent>
332 class TimeLabel : public QLabel
333 {
334     Q_OBJECT
335 public:
336     TimeLabel( intf_thread_t *_p_intf );
337 protected:
338     virtual void mousePressEvent( QMouseEvent *event )
339     {
340         toggleTimeDisplay();
341     }
342     virtual void mouseDoubleClickEvent( QMouseEvent *event )
343     {
344         toggleTimeDisplay();
345         emit timeLabelDoubleClicked();
346     }
347 private slots:
348     void setDisplayPosition( float pos, int time, int length );
349 private:
350     intf_thread_t *p_intf;
351     bool b_remainingTime;
352     void toggleTimeDisplay();
353 signals:
354     void timeLabelDoubleClicked();
355 };
356
357 class SpeedLabel : public QLabel
358 {
359     Q_OBJECT
360 public:
361     SpeedLabel( intf_thread_t *_p_intf, const QString text ): QLabel( text)
362     { p_intf = _p_intf; }
363
364 protected:
365     virtual void mouseDoubleClickEvent ( QMouseEvent * event )
366     {
367         THEMIM->getIM()->setRate( INPUT_RATE_DEFAULT );
368     }
369 private:
370     intf_thread_t *p_intf;
371 };
372
373 /******************** Speed Control Widgets ****************/
374 class SpeedControlWidget : public QFrame
375 {
376     Q_OBJECT
377 public:
378     SpeedControlWidget( intf_thread_t *);
379     virtual ~SpeedControlWidget();
380     void updateControls( int );
381 private:
382     intf_thread_t *p_intf;
383     QSlider *speedSlider;
384 public slots:
385     void setEnable( bool );
386 private slots:
387     void updateRate( int );
388     void resetRate();
389 };
390
391 class CoverArtLabel : public QLabel
392 {
393     Q_OBJECT
394 public:
395     CoverArtLabel( QWidget *parent,
396                    vlc_object_t *p_this,
397                    input_item_t *p_input = NULL );
398     virtual ~CoverArtLabel()
399             { if( p_input ) vlc_gc_decref( p_input ); };
400 private:
401     input_item_t *p_input;
402     vlc_object_t *p_this;
403     QString prevArt;
404
405 public slots:
406     void requestUpdate() { emit updateRequested(); };
407     void update( input_item_t* p_item )
408             { if( p_input ) vlc_gc_decref( p_input );
409               if( ( p_input = p_item ) ) vlc_gc_incref( p_input );
410               requestUpdate(); }
411
412 private slots:
413     void doUpdate();
414     void downloadCover();
415
416 signals:
417     void updateRequested();
418 };
419
420 #endif