]> git.sesse.net Git - vlc/blob - modules/gui/qt4/util/qvlcframe.hpp
Qt4 - Remove useless inclusion.
[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 <QPushButton>
35 #include <QKeyEvent>
36
37 #include "qt4.hpp"
38 #include <vlc/vlc.h>
39 #include <vlc_charset.h>
40
41 class QVLCFrame : public QWidget
42 {
43 public:
44     QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL ), p_intf( _p_intf )
45     {    };
46     virtual ~QVLCFrame()   {};
47
48     void toggleVisible()
49     {
50         if( isVisible() ) hide();
51         else show();
52     }
53 protected:
54     intf_thread_t *p_intf;
55
56     void readSettings( QString name, QSize defSize, QPoint defPos )
57     {
58         QSettings settings( "vlc", "vlc-qt-interface" );
59         settings.beginGroup( name );
60         /* never trust any saved size ;-) */
61         QSize newSize = settings.value( "size", defSize ).toSize();
62         if( newSize.isValid() )
63            resize( newSize );
64         move( settings.value( "pos", defPos ).toPoint() );
65         settings.endGroup();
66     }
67     void writeSettings( QString name )
68     {
69         QSettings settings( "vlc", "vlc-qt-interface" );
70         settings.beginGroup( name );
71         /* only save valid sizes ... */
72         QSize currentsize = size();
73         if( currentsize.isValid() )
74            settings.setValue ("size", currentsize );
75         settings.setValue( "pos", pos() );
76         settings.endGroup();
77     }
78     virtual void cancel()
79     {
80         hide();
81     }
82     virtual void close()
83     {
84         hide();
85     }
86     virtual void keyPressEvent( QKeyEvent *keyEvent )
87     {
88         if( keyEvent->key() == Qt::Key_Escape )
89         {
90             msg_Dbg( p_intf, "Escp Key pressed" );
91             cancel();
92         }
93         else if( keyEvent->key() == Qt::Key_Return )
94         {
95              msg_Dbg( p_intf, "Enter Key pressed" );
96              close();
97          }
98     }
99 };
100
101 class QVLCDialog : public QDialog
102 {
103 public:
104     QVLCDialog( QWidget* parent, intf_thread_t *_p_intf ) :
105                                     QDialog( parent ), p_intf( _p_intf )
106     {}
107     virtual ~QVLCDialog() {};
108     void toggleVisible()
109     {
110         if( isVisible() ) hide();
111         else show();
112     }
113
114 protected:
115     intf_thread_t *p_intf;
116
117     virtual void cancel()
118     {
119         hide();
120     }
121     virtual void close()
122     {
123         hide();
124     }
125     virtual void keyPressEvent( QKeyEvent *keyEvent )
126     {
127         if( keyEvent->key() == Qt::Key_Escape )
128         {
129             msg_Dbg( p_intf, "Escp Key pressed" );
130             cancel();
131         }
132         else if( keyEvent->key() == Qt::Key_Return )
133         {
134              msg_Dbg( p_intf, "Enter Key pressed" );
135              close();
136         }
137     }
138 };
139
140 class QVLCMW : public QMainWindow
141 {
142 public:
143     QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf )
144     {    }
145     virtual ~QVLCMW() {};
146     void toggleVisible()
147     {
148         if( isVisible() ) hide();
149         else show();
150     }
151 protected:
152     intf_thread_t *p_intf;
153     QSize mainSize;
154
155     void readSettings( QString name, QSize defSize )
156     {
157         QSettings settings( "vlc", "vlc-qt-interface" );
158         settings.beginGroup( name );
159         QSize s =  settings.value( "size", defSize ).toSize() ;
160         fprintf( stderr, "%i %i ", s.width(), s.height() );
161         move( settings.value( "pos", QPoint( 0,0 ) ).toPoint() );
162         settings.endGroup();
163     }
164
165     void readSettings( QString name )
166     {
167         QSettings settings( "vlc", "vlc-qt-interface" );
168         settings.beginGroup( name );
169         mainSize = settings.value( "size", QSize( 0,0 ) ).toSize();
170         if( !mainSize.isValid() )
171         {
172            mainSize = QSize(0,0);
173         }
174         settings.endGroup();
175     }
176
177     void writeSettings( QString name )
178     {
179         QSettings settings( "vlc", "vlc-qt-interface" );
180         settings.beginGroup( name );
181         /* only save valid sizes ... */
182         QSize currentsize = size();
183         if( currentsize.isValid() )
184             settings.setValue ("size", currentsize );
185         settings.setValue( "pos", pos() );
186         settings.endGroup();
187     }
188 };
189
190 #endif