]> git.sesse.net Git - vlc/blob - modules/gui/qt4/util/qvlcframe.hpp
* qt: escape key on QVLCFrame and QVLCDialog closes them
[vlc] / modules / gui / qt4 / util / qvlcframe.hpp
1 /*****************************************************************************
2  * qvlcframe.hpp : A few helpers
3  *****************************************************************************
4  * Copyright (C) 2006-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifndef _QVLCFRAME_H_
25 #define _QVLCFRAME_H_
26
27 #include <QWidget>
28 #include <QDialog>
29 #include <QSpacerItem>
30 #include <QHBoxLayout>
31 #include <QApplication>
32 #include <QSettings>
33 #include <QMainWindow>
34 #include <QPlastiqueStyle>
35 #include <QPushButton>
36 #include <QKeyEvent>
37 #include "qt4.hpp"
38 #include <vlc/vlc.h>
39 #include <vlc_charset.h>
40
41 class QVLCFrame : public QWidget
42 {
43 public:
44     static QHBoxLayout* doButtons( QWidget *w, QBoxLayout *l,
45                                QPushButton **defaul, char *psz_default,
46                                QPushButton **alt, char *psz_alt,
47                                QPushButton **other, char *psz_other )
48     {
49 #ifdef QT42
50 #else
51         QHBoxLayout *buttons_layout = new QHBoxLayout;
52         QSpacerItem *spacerItem = new QSpacerItem( 40, 20,
53                                QSizePolicy::Expanding, QSizePolicy::Minimum);
54         buttons_layout->addItem( spacerItem );
55
56         if( psz_default )
57         {
58             *defaul = new QPushButton(0);
59             (*defaul)->setFocus();
60             buttons_layout->addWidget( *defaul );
61             (*defaul)->setText( qfu( psz_default ) );
62         }
63         if( psz_alt )
64         {
65             *alt = new QPushButton(0);
66             buttons_layout->addWidget( *alt );
67             (*alt)->setText( qfu( psz_alt ) );
68         }
69         if( psz_other )
70         {
71             *other = new QPushButton( 0 );
72             buttons_layout->addWidget( *other );
73             (*other)->setText( qfu( psz_other ) );
74         }
75         if( l )
76             l->addLayout( buttons_layout );
77 #endif
78         return buttons_layout;
79     };
80
81     QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL ), p_intf( _p_intf )
82     {    };
83     virtual ~QVLCFrame()   {};
84
85     void toggleVisible()
86     {
87         if( isVisible() ) hide();
88         else show();
89     }
90 protected:
91     intf_thread_t *p_intf;
92
93     void readSettings( QString name, QSize defSize )
94     {
95         QSettings settings( "VideoLAN", "VLC" );
96         settings.beginGroup( name );
97         resize( settings.value( "size", defSize ).toSize() );
98         move( settings.value( "pos", QPoint( 0,0 ) ).toPoint() );
99         settings.endGroup();
100     }
101     void writeSettings( QString name )
102     {
103         QSettings settings( "VideoLAN", "VLC" );
104         settings.beginGroup( name );
105         settings.setValue ("size", size() );
106         settings.setValue( "pos", pos() );
107         settings.endGroup();
108     }
109     void cancel()
110     {
111         hide();
112     }
113     void keyPressEvent( QKeyEvent *keyEvent )
114     {
115         if( keyEvent->key() == Qt::Key_Escape )
116         {
117             cancel();
118         }
119     }
120 };
121
122 class QVLCDialog : public QDialog
123 {
124 public:
125     QVLCDialog( QWidget* parent, intf_thread_t *_p_intf ) :
126                                     QDialog( parent ), p_intf( _p_intf )
127     {}
128     virtual ~QVLCDialog() {};
129     void toggleVisible()
130     {
131         if( isVisible() ) hide();
132         else show();
133     }
134
135 protected:
136     intf_thread_t *p_intf;
137
138     void cancel()
139     {
140         hide();
141     }
142     void keyPressEvent( QKeyEvent *keyEvent )
143     {
144         if( keyEvent->key() == Qt::Key_Escape )
145         {
146             cancel();
147         }
148     }
149 };
150
151 class QVLCMW : public QMainWindow
152 {
153 public:
154     QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf )
155     {    }
156     virtual ~QVLCMW() {};
157     void toggleVisible()
158     {
159         if( isVisible() ) hide();
160         else show();
161     }
162 protected:
163     intf_thread_t *p_intf;
164     QSize mainSize;
165
166     void readSettings( QString name, QSize defSize )
167     {
168         QSettings settings( "VideoLAN", "VLC" );
169         settings.beginGroup( name );
170       QSize s =  settings.value( "size", defSize ).toSize() ;
171       fprintf( stderr, "%i %i ", s.width(), s.height() );
172         move( settings.value( "pos", QPoint( 0,0 ) ).toPoint() );
173         settings.endGroup();
174     }
175     void readSettings( QString name )
176     {
177         QSettings settings( "VideoLAN", "VLC" );
178         settings.beginGroup( name );
179         mainSize = settings.value( "size", QSize( 0,0 ) ).toSize();
180         settings.endGroup();
181     }
182     void writeSettings( QString name )
183     {
184         QSettings settings( "VideoLAN", "VLC" );
185         settings.beginGroup( name );
186         settings.setValue ("size", size() );
187         settings.setValue( "pos", pos() );
188         settings.endGroup();
189     }
190 };
191
192 #endif