1 /*****************************************************************************
2 * qvlcframe.hpp : A few helpers
3 *****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
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.
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.
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 *****************************************************************************/
29 #include <QSpacerItem>
30 #include <QHBoxLayout>
31 #include <QApplication>
32 #include <QMainWindow>
33 #include <QPushButton>
35 #include <QDesktopWidget>
39 #include <vlc_common.h>
40 #include <vlc_charset.h>
46 use this function to save a widgets screen position
47 only for windows / dialogs which are floating, if a
48 window is docked into an other - don't all this function
49 or it may write garbage to position info!
51 static void saveWidgetPosition( QSettings *settings, QWidget *widget)
53 settings->setValue("geometry", widget->saveGeometry());
55 static void saveWidgetPosition( intf_thread_t *p_intf,
59 getSettings()->beginGroup( configName );
60 QVLCTools::saveWidgetPosition(getSettings(), widget);
61 getSettings()->endGroup();
66 use this method only for restoring window state of non docked
69 static bool restoreWidgetPosition(QSettings *settings,
71 QSize defSize = QSize( 0, 0 ),
72 QPoint defPos = QPoint( 0, 0 ))
74 if(!widget->restoreGeometry(settings->value("geometry")
78 widget->resize(defSize);
80 if(defPos.x() == 0 && defPos.y()==0)
81 centerWidgetOnScreen(widget);
87 static bool restoreWidgetPosition( intf_thread_t *p_intf,
90 QSize defSize = QSize( 0, 0 ),
91 QPoint defPos = QPoint( 0, 0 ) )
93 getSettings()->beginGroup( configName );
94 bool defaultUsed = QVLCTools::restoreWidgetPosition( getSettings(),
98 getSettings()->endGroup();
104 call this method for a window or dialog to show it centred on
107 static void centerWidgetOnScreen(QWidget *widget)
109 QDesktopWidget * const desktop = QApplication::desktop();
110 QRect screenRect = desktop->screenGeometry(widget);
111 QPoint p1 = widget->frameGeometry().center();
113 widget->move ( screenRect.center() - p1 );
117 class QVLCFrame : public QWidget
121 QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL, Qt::Window ), p_intf( _p_intf )
123 QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL ), p_intf( _p_intf )
126 virtual ~QVLCFrame() {};
130 if( isVisible() ) hide();
134 intf_thread_t *p_intf;
136 void readSettings( QString name,
137 QSize defSize = QSize( 0, 0 ),
138 QPoint defPos = QPoint( 0, 0 ) )
140 QVLCTools::restoreWidgetPosition(p_intf, name, this, defSize, defPos);
143 void writeSettings( QString name )
145 QVLCTools::saveWidgetPosition( p_intf, name, this);
148 virtual void cancel()
156 virtual void keyPressEvent( QKeyEvent *keyEvent )
158 if( keyEvent->key() == Qt::Key_Escape )
160 msg_Dbg( p_intf, "Escp Key pressed" );
163 else if( keyEvent->key() == Qt::Key_Return )
165 msg_Dbg( p_intf, "Enter Key pressed" );
171 class QVLCDialog : public QDialog
174 QVLCDialog( QWidget* parent, intf_thread_t *_p_intf ) :
175 QDialog( parent ), p_intf( _p_intf )
177 virtual ~QVLCDialog() {};
180 if( isVisible() ) hide();
185 intf_thread_t *p_intf;
187 virtual void cancel()
195 virtual void keyPressEvent( QKeyEvent *keyEvent )
197 if( keyEvent->key() == Qt::Key_Escape )
199 msg_Dbg( p_intf, "Escp Key pressed" );
202 else if( keyEvent->key() == Qt::Key_Return )
204 msg_Dbg( p_intf, "Enter Key pressed" );
210 class QVLCMW : public QMainWindow
213 QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf )
215 virtual ~QVLCMW() {};
218 if( isVisible() ) hide();
222 intf_thread_t *p_intf;
225 void readSettings( QString name, QSize defSize )
227 QVLCTools::restoreWidgetPosition( p_intf, name, this, defSize);
230 void readSettings( QString name )
232 QVLCTools::restoreWidgetPosition( p_intf, name, this);
234 void readSettings( QSettings *settings )
236 QVLCTools::restoreWidgetPosition(settings, this);
239 void readSettings( QSettings *settings, QSize defSize)
241 QVLCTools::restoreWidgetPosition(settings, this, defSize);
244 void writeSettings(QString name )
246 QVLCTools::saveWidgetPosition( p_intf, name, this);
248 void writeSettings(QSettings *settings )
250 QVLCTools::saveWidgetPosition(settings, this);