]> git.sesse.net Git - vlc/blob - modules/gui/qt4/util/qvlcframe.hpp
Qt4 - Small modifications to messages dialog.
[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     virtual void cancel()
110     {
111         hide();
112     }
113     virtual void close()
114     {
115         hide();
116     }
117     virtual void keyPressEvent( QKeyEvent *keyEvent )
118     {
119         if( keyEvent->key() == Qt::Key_Escape )
120         {
121             msg_Dbg( p_intf, "Escp Key pressed" );
122             cancel();
123         }
124         else if( keyEvent->key() == Qt::Key_Return )
125         {
126              msg_Dbg( p_intf, "Enter Key pressed" );
127              close();
128          }
129
130     }
131 };
132
133 class QVLCDialog : public QDialog
134 {
135 public:
136     QVLCDialog( QWidget* parent, intf_thread_t *_p_intf ) :
137                                     QDialog( parent ), p_intf( _p_intf )
138     {}
139     virtual ~QVLCDialog() {};
140     void toggleVisible()
141     {
142         if( isVisible() ) hide();
143         else show();
144     }
145
146 protected:
147     intf_thread_t *p_intf;
148
149     virtual void cancel()
150     {
151         hide();
152     }
153     virtual void close()
154     {
155         hide();
156     }
157     virtual void keyPressEvent( QKeyEvent *keyEvent )
158     {
159         if( keyEvent->key() == Qt::Key_Escape )
160         {
161             msg_Dbg( p_intf, "Escp Key pressed" );
162             cancel();
163         }
164         else if( keyEvent->key() == Qt::Key_Return )
165         {
166              msg_Dbg( p_intf, "Enter Key pressed" );
167              close();
168         }
169     }
170 };
171
172 class QVLCMW : public QMainWindow
173 {
174 public:
175     QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf )
176     {    }
177     virtual ~QVLCMW() {};
178     void toggleVisible()
179     {
180         if( isVisible() ) hide();
181         else show();
182     }
183 protected:
184     intf_thread_t *p_intf;
185     QSize mainSize;
186
187     void readSettings( QString name, QSize defSize )
188     {
189         QSettings settings( "VideoLAN", "VLC" );
190         settings.beginGroup( name );
191       QSize s =  settings.value( "size", defSize ).toSize() ;
192       fprintf( stderr, "%i %i ", s.width(), s.height() );
193         move( settings.value( "pos", QPoint( 0,0 ) ).toPoint() );
194         settings.endGroup();
195     }
196     void readSettings( QString name )
197     {
198         QSettings settings( "VideoLAN", "VLC" );
199         settings.beginGroup( name );
200         mainSize = settings.value( "size", QSize( 0,0 ) ).toSize();
201         settings.endGroup();
202     }
203     void writeSettings( QString name )
204     {
205         QSettings settings( "VideoLAN", "VLC" );
206         settings.beginGroup( name );
207         settings.setValue ("size", size() );
208         settings.setValue( "pos", pos() );
209         settings.endGroup();
210     }
211 };
212
213 #endif