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 <QHBoxLayout>
30 #include <QApplication>
31 #include <QMainWindow>
33 #include <QDesktopWidget>
43 use this function to save a widgets screen position
44 only for windows / dialogs which are floating, if a
45 window is docked into an other - don't all this function
46 or it may write garbage to position info!
48 static void saveWidgetPosition( QSettings *settings, QWidget *widget)
50 settings->setValue("geometry", widget->saveGeometry());
52 static void saveWidgetPosition( intf_thread_t *p_intf,
53 const QString& configName,
56 getSettings()->beginGroup( configName );
57 QVLCTools::saveWidgetPosition(getSettings(), widget);
58 getSettings()->endGroup();
63 use this method only for restoring window state of non docked
66 static bool restoreWidgetPosition(QSettings *settings,
68 QSize defSize = QSize( 0, 0 ),
69 QPoint defPos = QPoint( 0, 0 ))
71 if(!widget->restoreGeometry(settings->value("geometry")
75 widget->resize(defSize);
77 if(defPos.x() == 0 && defPos.y()==0)
78 widget->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, widget->size(), qApp->desktop()->availableGeometry()));
84 static bool restoreWidgetPosition( intf_thread_t *p_intf,
85 const QString& configName,
87 QSize defSize = QSize( 0, 0 ),
88 QPoint defPos = QPoint( 0, 0 ) )
90 getSettings()->beginGroup( configName );
91 bool defaultUsed = QVLCTools::restoreWidgetPosition( getSettings(),
95 getSettings()->endGroup();
101 class QVLCFrame : public QWidget
104 QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL ), p_intf( _p_intf )
106 virtual ~QVLCFrame() {};
110 if( isVisible() ) hide();
114 intf_thread_t *p_intf;
116 void readSettings( const QString& name,
117 QSize defSize = QSize( 1, 1 ),
118 QPoint defPos = QPoint( 0, 0 ) )
120 QVLCTools::restoreWidgetPosition(p_intf, name, this, defSize, defPos);
123 void writeSettings( const QString& name )
125 QVLCTools::saveWidgetPosition( p_intf, name, this);
128 virtual void cancel()
136 virtual void keyPressEvent( QKeyEvent *keyEvent )
138 if( keyEvent->key() == Qt::Key_Escape )
142 else if( keyEvent->key() == Qt::Key_Return
143 || keyEvent->key() == Qt::Key_Enter )
150 class QVLCDialog : public QDialog
153 QVLCDialog( QWidget* parent, intf_thread_t *_p_intf ) :
154 QDialog( parent ), p_intf( _p_intf )
156 virtual ~QVLCDialog() {};
159 if( isVisible() ) hide();
164 intf_thread_t *p_intf;
166 virtual void cancel()
174 virtual void keyPressEvent( QKeyEvent *keyEvent )
176 if( keyEvent->key() == Qt::Key_Escape )
180 else if( keyEvent->key() == Qt::Key_Return
181 || keyEvent->key() == Qt::Key_Enter )
188 class QVLCMW : public QMainWindow
191 QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf )
193 virtual ~QVLCMW() {};
196 if( isVisible() ) hide();
200 intf_thread_t *p_intf;
203 void readSettings( const QString& name, QSize defSize )
205 QVLCTools::restoreWidgetPosition( p_intf, name, this, defSize);
208 void readSettings( const QString& name )
210 QVLCTools::restoreWidgetPosition( p_intf, name, this);
212 void readSettings( QSettings *settings )
214 QVLCTools::restoreWidgetPosition(settings, this);
217 void readSettings( QSettings *settings, QSize defSize)
219 QVLCTools::restoreWidgetPosition(settings, this, defSize);
222 void writeSettings( const QString& name )
224 QVLCTools::saveWidgetPosition( p_intf, name, this);
226 void writeSettings(QSettings *settings )
228 QVLCTools::saveWidgetPosition(settings, this);