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