#include <QWidget>
#include <QDialog>
-#include <QSpacerItem>
#include <QHBoxLayout>
#include <QApplication>
-#include <QSettings>
#include <QMainWindow>
-#include <QPushButton>
#include <QKeyEvent>
#include <QDesktopWidget>
+#include <QSettings>
+#include <QStyle>
#include "qt4.hpp"
-#include <vlc_common.h>
-#include <vlc_charset.h>
class QVLCTools
{
/*
use this function to save a widgets screen position
only for windows / dialogs which are floating, if a
- window is docked into an other - don't all this function
+ 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)
+ static void saveWidgetPosition( QSettings *settings, QWidget *widget)
{
settings->setValue("geometry", widget->saveGeometry());
}
- static void saveWidgetPosition(QString configName, QWidget *widget)
+ static void saveWidgetPosition( intf_thread_t *p_intf,
+ const QString& configName,
+ QWidget *widget)
{
- QSettings *settings = new QSettings("vlc", "vlc-qt-interface");
- settings->beginGroup( configName );
- QVLCTools::saveWidgetPosition(settings, widget);
- settings->endGroup();
- delete settings;
+ getSettings()->beginGroup( configName );
+ QVLCTools::saveWidgetPosition(getSettings(), widget);
+ getSettings()->endGroup();
}
widget->resize(defSize);
if(defPos.x() == 0 && defPos.y()==0)
- centerWidgetOnScreen(widget);
+ widget->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, widget->size(), qApp->desktop()->availableGeometry()));
return true;
}
return false;
}
- static bool restoreWidgetPosition(QString configName,
+ static bool restoreWidgetPosition( intf_thread_t *p_intf,
+ const QString& configName,
QWidget *widget,
QSize defSize = QSize( 0, 0 ),
QPoint defPos = QPoint( 0, 0 ) )
{
- QSettings *settings = new QSettings( "vlc", "vlc-qt-interface" );
- settings->beginGroup( configName );
- bool defaultUsed = QVLCTools::restoreWidgetPosition(settings,
+ getSettings()->beginGroup( configName );
+ bool defaultUsed = QVLCTools::restoreWidgetPosition( getSettings(),
widget,
defSize,
defPos);
- settings->endGroup();
- delete settings;
+ getSettings()->endGroup();
return defaultUsed;
}
-
- /*
- call this method for a window or dialog to show it centred on
- current screen
- */
- static void centerWidgetOnScreen(QWidget *widget)
- {
- QDesktopWidget * const desktop = QApplication::desktop();
- QRect screenRect = desktop->screenGeometry(widget);
- QPoint p1 = widget->frameGeometry().center();
-
- widget->move ( screenRect.center() - p1 );
- }
};
class QVLCFrame : public QWidget
{
public:
-#ifdef __APPLE__
- QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL, Qt::Window ), p_intf( _p_intf )
-#else
QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL ), p_intf( _p_intf )
-#endif
{};
virtual ~QVLCFrame() {};
protected:
intf_thread_t *p_intf;
- void readSettings( QString name,
- QSize defSize = QSize( 0, 0 ),
+ void restoreWidgetPosition( const QString& name,
+ QSize defSize = QSize( 1, 1 ),
QPoint defPos = QPoint( 0, 0 ) )
{
- QVLCTools::restoreWidgetPosition(name, this, defSize, defPos);
+ QVLCTools::restoreWidgetPosition(p_intf, name, this, defSize, defPos);
}
- void writeSettings( QString name )
+ void saveWidgetPosition( const QString& name )
{
- QVLCTools::saveWidgetPosition(name, this);
+ QVLCTools::saveWidgetPosition( p_intf, name, this);
}
virtual void cancel()
{
hide();
}
- virtual void keyPressEvent( QKeyEvent *keyEvent )
+ void keyPressEvent( QKeyEvent *keyEvent ) Q_DECL_OVERRIDE
{
if( keyEvent->key() == Qt::Key_Escape )
{
- msg_Dbg( p_intf, "Escp Key pressed" );
- cancel();
+ this->cancel();
}
- else if( keyEvent->key() == Qt::Key_Return )
+ else if( keyEvent->key() == Qt::Key_Return
+ || keyEvent->key() == Qt::Key_Enter )
{
- msg_Dbg( p_intf, "Enter Key pressed" );
- close();
- }
+ this->close();
+ }
}
};
{
hide();
}
- virtual void keyPressEvent( QKeyEvent *keyEvent )
+ void keyPressEvent( QKeyEvent *keyEvent ) Q_DECL_OVERRIDE
{
if( keyEvent->key() == Qt::Key_Escape )
{
- msg_Dbg( p_intf, "Escp Key pressed" );
- cancel();
+ this->cancel();
}
- else if( keyEvent->key() == Qt::Key_Return )
+ else if( keyEvent->key() == Qt::Key_Return
+ || keyEvent->key() == Qt::Key_Enter )
{
- msg_Dbg( p_intf, "Enter Key pressed" );
- close();
+ this->close();
}
}
};
class QVLCMW : public QMainWindow
{
public:
- QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf )
- { }
- virtual ~QVLCMW() {};
+ QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf ){}
void toggleVisible()
{
if( isVisible() ) hide();
intf_thread_t *p_intf;
QSize mainSize;
- void readSettings( QString name, QSize defSize )
+ void readSettings( const QString& name, QSize defSize )
{
- QVLCTools::restoreWidgetPosition(name, this, defSize);
+ QVLCTools::restoreWidgetPosition( p_intf, name, this, defSize);
}
- void readSettings( QString name )
+ void readSettings( const QString& name )
{
- QVLCTools::restoreWidgetPosition(name, this);
+ QVLCTools::restoreWidgetPosition( p_intf, name, this);
}
-
void readSettings( QSettings *settings )
{
QVLCTools::restoreWidgetPosition(settings, this);
QVLCTools::restoreWidgetPosition(settings, this, defSize);
}
- void writeSettings(QString name )
+ void writeSettings( const QString& name )
{
- QVLCTools::saveWidgetPosition(name, this);
+ QVLCTools::saveWidgetPosition( p_intf, name, this);
}
-
void writeSettings(QSettings *settings )
{
QVLCTools::saveWidgetPosition(settings, this);
}
-
};
#endif