+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 an other - 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,
+ 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)
+ centerWidgetOnScreen(widget);
+ return true;
+ }
+ return false;
+ }
+
+ static bool restoreWidgetPosition( intf_thread_t *p_intf,
+ 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;
+ }
+
+ /*
+ 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 );
+ }
+};
+