+#include <QKeyEvent>
+#include <QDesktopWidget>
+#include <QSettings>
+#include <QStyle>
+
+#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;
+ }
+};