X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fqt4%2Futil%2Fqvlcframe.hpp;h=edaa08be96d10a89257974ef4b2a36fdc4b568e7;hb=fdc455adc812cf9b02ae40c8bd47a1a261a32ce6;hp=85ad2a2e97f956ba4bc77c92f706fa744f6358da;hpb=df3a146185447ed55adf2a5d59254555bb0f4b48;p=vlc diff --git a/modules/gui/qt4/util/qvlcframe.hpp b/modules/gui/qt4/util/qvlcframe.hpp index 85ad2a2e97..edaa08be96 100644 --- a/modules/gui/qt4/util/qvlcframe.hpp +++ b/modules/gui/qt4/util/qvlcframe.hpp @@ -1,7 +1,7 @@ /***************************************************************************** * qvlcframe.hpp : A few helpers - **************************************************************************** - * Copyright (C) 2006 the VideoLAN team + ***************************************************************************** + * Copyright (C) 2006-2007 the VideoLAN team * $Id$ * * Authors: Clément Stenac @@ -18,69 +18,170 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ #ifndef _QVLCFRAME_H_ #define _QVLCFRAME_H_ #include +#include +#include #include -#include #include -#include -#include +#include +#include +#include +#include + +#include "qt4.hpp" + +class QVLCTools +{ + public: + /* + use this function to save a widgets screen position + only for windows / dialogs which are floating, if a + window is docked into another - don't all this function + or it may write garbage to position info! + */ + static void saveWidgetPosition( QSettings *settings, QWidget *widget) + { + settings->setValue("geometry", widget->saveGeometry()); + } + static void saveWidgetPosition( intf_thread_t *p_intf, + const QString& configName, + QWidget *widget) + { + getSettings()->beginGroup( configName ); + QVLCTools::saveWidgetPosition(getSettings(), widget); + getSettings()->endGroup(); + } + + + /* + use this method only for restoring window state of non docked + windows! + */ + static bool restoreWidgetPosition(QSettings *settings, + QWidget *widget, + QSize defSize = QSize( 0, 0 ), + QPoint defPos = QPoint( 0, 0 )) + { + if(!widget->restoreGeometry(settings->value("geometry") + .toByteArray())) + { + widget->move(defPos); + widget->resize(defSize); + + if(defPos.x() == 0 && defPos.y()==0) + widget->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, widget->size(), qApp->desktop()->availableGeometry())); + return true; + } + return false; + } + + static bool restoreWidgetPosition( intf_thread_t *p_intf, + const QString& configName, + QWidget *widget, + QSize defSize = QSize( 0, 0 ), + QPoint defPos = QPoint( 0, 0 ) ) + { + getSettings()->beginGroup( configName ); + bool defaultUsed = QVLCTools::restoreWidgetPosition( getSettings(), + widget, + defSize, + defPos); + getSettings()->endGroup(); + + return defaultUsed; + } +}; class QVLCFrame : public QWidget { public: - static void fixStyle( QWidget *w) + QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL ), p_intf( _p_intf ) + {}; + virtual ~QVLCFrame() {}; + + void toggleVisible() { - QStyle *style = qApp->style(); - // Plastique is too dark. - /// theming ? getting KDE data ? ? - if( qobject_cast(style) ) - { - QPalette plt( w->palette() ); - plt.setColor( QPalette::Active, QPalette::Highlight, Qt::gray ); - QColor vlg = (Qt::lightGray); - vlg = vlg.toHsv(); - vlg.setHsv( vlg.hue(), vlg.saturation(), 235 ); - plt.setColor( QPalette::Active, QPalette::Window, vlg ); - plt.setColor( QPalette::Inactive, QPalette::Window, vlg ); - w->setPalette( plt ); - } + if( isVisible() ) hide(); + else show(); } +protected: + intf_thread_t *p_intf; - QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL ), p_intf( _p_intf ) + void readSettings( const QString& name, + QSize defSize = QSize( 1, 1 ), + QPoint defPos = QPoint( 0, 0 ) ) { - fixStyle( this ); - }; - virtual ~QVLCFrame() {}; + QVLCTools::restoreWidgetPosition(p_intf, name, this, defSize, defPos); + } + + void writeSettings( const QString& name ) + { + QVLCTools::saveWidgetPosition( p_intf, name, this); + } + + virtual void cancel() + { + hide(); + } + virtual void close() + { + hide(); + } + virtual void keyPressEvent( QKeyEvent *keyEvent ) + { + if( keyEvent->key() == Qt::Key_Escape ) + { + this->cancel(); + } + else if( keyEvent->key() == Qt::Key_Return + || keyEvent->key() == Qt::Key_Enter ) + { + this->close(); + } + } +}; +class QVLCDialog : public QDialog +{ +public: + QVLCDialog( QWidget* parent, intf_thread_t *_p_intf ) : + QDialog( parent ), p_intf( _p_intf ) + {} + virtual ~QVLCDialog() {}; void toggleVisible() { if( isVisible() ) hide(); else show(); } + protected: intf_thread_t *p_intf; - void readSettings( QString name, QSize defSize ) + virtual void cancel() { - QSettings settings( "VideoLAN", "VLC" ); - settings.beginGroup( name ); - resize( settings.value( "size", defSize ).toSize() ); - move( settings.value( "pos", QPoint( 0,0 ) ).toPoint() ); - settings.endGroup(); + hide(); } - void writeSettings( QString name ) + virtual void close() { - fprintf( stderr, "save\n" ); - QSettings settings( "VideoLAN", "VLC" ); - settings.beginGroup( name ); - settings.setValue ("size", size() ); - settings.setValue( "pos", pos() ); - settings.endGroup(); + hide(); + } + virtual void keyPressEvent( QKeyEvent *keyEvent ) + { + if( keyEvent->key() == Qt::Key_Escape ) + { + this->cancel(); + } + else if( keyEvent->key() == Qt::Key_Return + || keyEvent->key() == Qt::Key_Enter ) + { + this->close(); + } } }; @@ -88,38 +189,43 @@ class QVLCMW : public QMainWindow { public: QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf ) + { } + virtual ~QVLCMW() {}; + void toggleVisible() { - QVLCFrame::fixStyle( this ); + if( isVisible() ) hide(); + else show(); } - virtual ~QVLCMW() {}; protected: intf_thread_t *p_intf; QSize mainSize; - void readSettings( QString name, QSize defSize ) + void readSettings( const QString& name, QSize defSize ) { - QSettings settings( "VideoLAN", "VLC" ); - settings.beginGroup( name ); - mainSize = settings.value( "size", defSize ).toSize(); - QPoint npos = settings.value( "pos", QPoint( 0,0 ) ).toPoint(); - if( npos.x() > 0 ) - move( npos ); - settings.endGroup(); + QVLCTools::restoreWidgetPosition( p_intf, name, this, defSize); } - void readSettings( QString name ) + + void readSettings( const QString& name ) + { + QVLCTools::restoreWidgetPosition( p_intf, name, this); + } + void readSettings( QSettings *settings ) + { + QVLCTools::restoreWidgetPosition(settings, this); + } + + void readSettings( QSettings *settings, QSize defSize) + { + QVLCTools::restoreWidgetPosition(settings, this, defSize); + } + + void writeSettings( const QString& name ) { - QSettings settings( "VideoLAN", "VLC" ); - settings.beginGroup( name ); - mainSize = settings.value( "size", QSize( 0,0 ) ).toSize(); - settings.endGroup(); + QVLCTools::saveWidgetPosition( p_intf, name, this); } - void writeSettings( QString name ) + void writeSettings(QSettings *settings ) { - QSettings settings( "VideoLAN", "VLC" ); - settings.beginGroup( name ); - settings.setValue ("size", size() ); - settings.setValue( "pos", pos() ); - settings.endGroup(); + QVLCTools::saveWidgetPosition(settings, this); } };