]> git.sesse.net Git - vlc/blob - modules/gui/qt4/util/qvlcframe.hpp
Change the QSettings stuff here too (this looks kind of hackish but at least it makes...
[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     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 )
57     {
58         QSettings settings( "vlc", "vlc-qt-interface" );
59         settings.beginGroup( name );
60         resize( settings.value( "size", defSize ).toSize() );
61         move( settings.value( "pos", QPoint( 0,0 ) ).toPoint() );
62         settings.endGroup();
63     }
64     void writeSettings( QString name )
65     {
66         QSettings settings( "vlc", "vlc-qt-interface" );
67         settings.beginGroup( name );
68         settings.setValue ("size", size() );
69         settings.setValue( "pos", pos() );
70         settings.endGroup();
71     }
72     virtual void cancel()
73     {
74         hide();
75     }
76     virtual void close()
77     {
78         hide();
79     }
80     virtual void keyPressEvent( QKeyEvent *keyEvent )
81     {
82         if( keyEvent->key() == Qt::Key_Escape )
83         {
84             msg_Dbg( p_intf, "Escp Key pressed" );
85             cancel();
86         }
87         else if( keyEvent->key() == Qt::Key_Return )
88         {
89              msg_Dbg( p_intf, "Enter Key pressed" );
90              close();
91          }
92
93     }
94 };
95
96 class QVLCDialog : public QDialog
97 {
98 public:
99     QVLCDialog( QWidget* parent, intf_thread_t *_p_intf ) :
100                                     QDialog( parent ), p_intf( _p_intf )
101     {}
102     virtual ~QVLCDialog() {};
103     void toggleVisible()
104     {
105         if( isVisible() ) hide();
106         else show();
107     }
108
109 protected:
110     intf_thread_t *p_intf;
111
112     virtual void cancel()
113     {
114         hide();
115     }
116     virtual void close()
117     {
118         hide();
119     }
120     virtual void keyPressEvent( QKeyEvent *keyEvent )
121     {
122         if( keyEvent->key() == Qt::Key_Escape )
123         {
124             msg_Dbg( p_intf, "Escp Key pressed" );
125             cancel();
126         }
127         else if( keyEvent->key() == Qt::Key_Return )
128         {
129              msg_Dbg( p_intf, "Enter Key pressed" );
130              close();
131         }
132     }
133 };
134
135 class QVLCMW : public QMainWindow
136 {
137 public:
138     QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf )
139     {    }
140     virtual ~QVLCMW() {};
141     void toggleVisible()
142     {
143         if( isVisible() ) hide();
144         else show();
145     }
146 protected:
147     intf_thread_t *p_intf;
148     QSize mainSize;
149
150     void readSettings( QString name, QSize defSize )
151     {
152         QSettings settings( "vlc", "vlc-qt-interface" );
153         settings.beginGroup( name );
154         QSize s =  settings.value( "size", defSize ).toSize() ;
155         fprintf( stderr, "%i %i ", s.width(), s.height() );
156         move( settings.value( "pos", QPoint( 0,0 ) ).toPoint() );
157         settings.endGroup();
158     }
159     void readSettings( QString name )
160     {
161         QSettings settings( "vlc", "vlc-qt-interface" );
162         settings.beginGroup( name );
163         mainSize = settings.value( "size", QSize( 0,0 ) ).toSize();
164         settings.endGroup();
165     }
166     void writeSettings( QString name )
167     {
168         QSettings settings( "vlc", "vlc-qt-interface" );
169         settings.beginGroup( name );
170         settings.setValue ("size", size() );
171         settings.setValue( "pos", pos() );
172         settings.endGroup();
173     }
174 };
175
176 #endif