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>
44 use this function to save a widgets screen position
45 only for windows / dialogs which are floating, if a
46 window is docked into an other - don't all this function
47 or it may write garbage to position info!
49 static void saveWidgetPosition( QSettings *settings, QWidget *widget)
51 settings->setValue("geometry", widget->saveGeometry());
53 static void saveWidgetPosition( intf_thread_t *p_intf,
57 getSettings()->beginGroup( configName );
58 QVLCTools::saveWidgetPosition(getSettings(), widget);
59 getSettings()->endGroup();
64 use this method only for restoring window state of non docked
67 static bool restoreWidgetPosition(QSettings *settings,
69 QSize defSize = QSize( 0, 0 ),
70 QPoint defPos = QPoint( 0, 0 ))
72 if(!widget->restoreGeometry(settings->value("geometry")
76 widget->resize(defSize);
78 if(defPos.x() == 0 && defPos.y()==0)
79 centerWidgetOnScreen(widget);
85 static bool restoreWidgetPosition( intf_thread_t *p_intf,
88 QSize defSize = QSize( 0, 0 ),
89 QPoint defPos = QPoint( 0, 0 ) )
91 getSettings()->beginGroup( configName );
92 bool defaultUsed = QVLCTools::restoreWidgetPosition( getSettings(),
96 getSettings()->endGroup();
102 call this method for a window or dialog to show it centred on
105 static void centerWidgetOnScreen(QWidget *widget)
107 QDesktopWidget * const desktop = QApplication::desktop();
108 QRect screenRect = desktop->availableGeometry(widget);
109 QPoint p1 = widget->frameGeometry().center();
111 widget->move ( screenRect.center() - p1 );
115 class QVLCFrame : public QWidget
119 QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL, Qt::Window ), p_intf( _p_intf )
121 QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL ), p_intf( _p_intf )
124 virtual ~QVLCFrame() {};
128 if( isVisible() ) hide();
132 intf_thread_t *p_intf;
134 void readSettings( QString name,
135 QSize defSize = QSize( 1, 1 ),
136 QPoint defPos = QPoint( 0, 0 ) )
138 QVLCTools::restoreWidgetPosition(p_intf, name, this, defSize, defPos);
141 void writeSettings( QString name )
143 QVLCTools::saveWidgetPosition( p_intf, name, this);
146 virtual void cancel()
154 virtual void keyPressEvent( QKeyEvent *keyEvent )
156 if( keyEvent->key() == Qt::Key_Escape )
160 else if( keyEvent->key() == Qt::Key_Return
161 || keyEvent->key() == Qt::Key_Enter )
168 class QVLCDialog : public QDialog
171 QVLCDialog( QWidget* parent, intf_thread_t *_p_intf ) :
172 QDialog( parent ), p_intf( _p_intf )
174 virtual ~QVLCDialog() {};
177 if( isVisible() ) hide();
182 intf_thread_t *p_intf;
184 virtual void cancel()
192 virtual void keyPressEvent( QKeyEvent *keyEvent )
194 if( keyEvent->key() == Qt::Key_Escape )
196 msg_Dbg( p_intf, "Escp Key pressed" );
199 else if( keyEvent->key() == Qt::Key_Return
200 || keyEvent->key() == Qt::Key_Enter )
202 msg_Dbg( p_intf, "Enter Key pressed" );
208 class QVLCMW : public QMainWindow
211 QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf )
213 virtual ~QVLCMW() {};
216 if( isVisible() ) hide();
220 intf_thread_t *p_intf;
223 void readSettings( QString name, QSize defSize )
225 QVLCTools::restoreWidgetPosition( p_intf, name, this, defSize);
228 void readSettings( QString name )
230 QVLCTools::restoreWidgetPosition( p_intf, name, this);
232 void readSettings( QSettings *settings )
234 QVLCTools::restoreWidgetPosition(settings, this);
237 void readSettings( QSettings *settings, QSize defSize)
239 QVLCTools::restoreWidgetPosition(settings, this, defSize);
242 void writeSettings(QString name )
244 QVLCTools::saveWidgetPosition( p_intf, name, this);
246 void writeSettings(QSettings *settings )
248 QVLCTools::saveWidgetPosition(settings, this);