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