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