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>
33 #include <QMainWindow>
34 #include <QPushButton>
36 #include <QDesktopWidget>
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(QString configName, QWidget *widget)
57 QSettings *settings = new QSettings("vlc", "vlc-qt-interface");
58 settings->beginGroup( configName );
59 QVLCTools::saveWidgetPosition(settings, widget);
66 use this method only for restoring window state of non docked
69 static vlc_bool_t 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 vlc_bool_t restoreWidgetPosition(QString configName,
89 QSize defSize = QSize( 0, 0 ),
90 QPoint defPos = QPoint( 0, 0 ) )
92 QSettings *settings = new QSettings( "vlc", "vlc-qt-interface" );
93 settings->beginGroup( configName );
94 vlc_bool_t defaultUsed = QVLCTools::restoreWidgetPosition(settings,
105 call this method for a window or dialog to show it centred on
108 static void centerWidgetOnScreen(QWidget *widget)
110 QDesktopWidget * const desktop = QApplication::desktop();
111 QRect screenRect = desktop->screenGeometry(widget);
112 QPoint p1 = widget->frameGeometry().center();
114 widget->move ( screenRect.center() - p1 );
118 class QVLCFrame : public QWidget
122 QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL, Qt::Window ), p_intf( _p_intf )
124 QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL ), p_intf( _p_intf )
127 virtual ~QVLCFrame() {};
131 if( isVisible() ) hide();
135 intf_thread_t *p_intf;
137 void readSettings( QString name,
138 QSize defSize = QSize( 0, 0 ),
139 QPoint defPos = QPoint( 0, 0 ) )
141 QVLCTools::restoreWidgetPosition(name, this, defSize, defPos);
144 void writeSettings( QString name )
146 QVLCTools::saveWidgetPosition(name, this);
149 virtual void cancel()
157 virtual void keyPressEvent( QKeyEvent *keyEvent )
159 if( keyEvent->key() == Qt::Key_Escape )
161 msg_Dbg( p_intf, "Escp Key pressed" );
164 else if( keyEvent->key() == Qt::Key_Return )
166 msg_Dbg( p_intf, "Enter Key pressed" );
172 class QVLCDialog : public QDialog
175 QVLCDialog( QWidget* parent, intf_thread_t *_p_intf ) :
176 QDialog( parent ), p_intf( _p_intf )
178 virtual ~QVLCDialog() {};
181 if( isVisible() ) hide();
186 intf_thread_t *p_intf;
188 virtual void cancel()
196 virtual void keyPressEvent( QKeyEvent *keyEvent )
198 if( keyEvent->key() == Qt::Key_Escape )
200 msg_Dbg( p_intf, "Escp Key pressed" );
203 else if( keyEvent->key() == Qt::Key_Return )
205 msg_Dbg( p_intf, "Enter Key pressed" );
211 class QVLCMW : public QMainWindow
214 QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf )
216 virtual ~QVLCMW() {};
219 if( isVisible() ) hide();
223 intf_thread_t *p_intf;
226 void readSettings( QString name, QSize defSize )
228 QVLCTools::restoreWidgetPosition(name, this, defSize);
231 void readSettings( QString name )
233 QVLCTools::restoreWidgetPosition(name, this);
236 void readSettings( QSettings *settings )
238 QVLCTools::restoreWidgetPosition(settings, this);
241 void readSettings( QSettings *settings, QSize defSize)
243 QVLCTools::restoreWidgetPosition(settings, this, defSize);
246 void writeSettings(QString name )
248 QVLCTools::saveWidgetPosition(name, this);
251 void writeSettings(QSettings *settings )
253 QVLCTools::saveWidgetPosition(settings, this);