]> git.sesse.net Git - vlc/commitdiff
Saveing Window Positions useing the QT defined methods as far as possible.
authorAndré Weber <atmo@videolan.org>
Sun, 9 Mar 2008 20:02:46 +0000 (21:02 +0100)
committerAndré Weber <atmo@videolan.org>
Sun, 9 Mar 2008 20:07:11 +0000 (21:07 +0100)
On first start if there is no position info stored - try center the dialogs
on the primary desktop/screen. (or same screen as the controller)

the component playlist shall not save there settings to a fixed location,
so it may become problematic if we use the component twice - like it
is done. The location shall be given controlled by its owner component
or window.

modules/gui/qt4/components/playlist/playlist.cpp
modules/gui/qt4/dialogs/playlist.cpp
modules/gui/qt4/dialogs/playlist.hpp
modules/gui/qt4/main_interface.cpp
modules/gui/qt4/util/qvlcframe.hpp

index ed94919cbfbe480738533457189ec13b3cac2b46..5ecba18b6d7fb2f686d1e3515c1bd4adc4083853 100644 (file)
@@ -115,11 +115,10 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i,
     setCollapsible( 1, false );
 
     /* In case we want to keep the splitter informations */
-    settings->beginGroup( "playlist" );
+    // components shall never write there setting to a fixed location, may infer
+    // with other uses of the same component...
+    // settings->beginGroup( "playlist" );
     restoreState( settings->value("splitterSizes").toByteArray());
-    resize( settings->value("size", QSize(600, 300)).toSize());
-    move( settings->value("pos", QPoint( 0, 400)).toPoint());
-    settings->endGroup();
 }
 
 void PlaylistWidget::setArt( QString url )
@@ -145,10 +144,6 @@ PlaylistWidget::~PlaylistWidget()
 
 void PlaylistWidget::savingSettings( QSettings *settings )
 {
-    settings->beginGroup( "playlist" );
-    settings->setValue( "pos", parent->pos() );
-    settings->setValue( "size", parent->size() );
     settings->setValue( "splitterSizes", saveState() );
-    settings->endGroup();
 }
 
index fcb20ea2deeb43780bc1a75cbce4bd2404142120..71308534961c685d0c2c81fe7f6741ebd1bff7de 100644 (file)
@@ -49,15 +49,28 @@ PlaylistDialog::PlaylistDialog( intf_thread_t *_p_intf )
     setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
 
     QHBoxLayout *l = new QHBoxLayout( centralWidget() );
-    QSettings *settings = new QSettings( "vlc", "vlc-qt-interface" );
-    PlaylistWidget *plw = new PlaylistWidget( p_intf, settings, this );
-    l->addWidget( plw );
 
-    readSettings( "playlist", QSize( 600,700 ) );
+    settings = new QSettings( "vlc", "vlc-qt-interface" );
+    settings->beginGroup("playlistdialog");
+
+    playlistWidget = new PlaylistWidget( p_intf, settings, this );
+    l->addWidget( playlistWidget );
+
+    readSettings( settings, QSize( 600,700 ) );
+
+    settings->endGroup();
 }
 
 PlaylistDialog::~PlaylistDialog()
-{}
+{
+    settings->beginGroup("playlistdialog");
+
+    writeSettings(settings);
+    playlistWidget->savingSettings(settings);
+
+    settings->endGroup();
+    delete settings;
+}
 
 void PlaylistDialog::dropEvent( QDropEvent *event )
 {
index a64f6045dd99cf24fc3ca7fd0de776d1ed1e8f68..962a5b89093d54038adb298066f0e7ab74e00a54 100644 (file)
@@ -25,6 +25,7 @@
 #define _PLAYLIST_DIALOG_H_
 
 #include "util/qvlcframe.hpp"
+#include "../components/playlist/playlist.hpp"
 
 #include <QModelIndex>
 
@@ -36,6 +37,10 @@ class QSettings;
 class PlaylistDialog : public QVLCMW
 {
     Q_OBJECT;
+private:
+    PlaylistWidget *playlistWidget;
+    QSettings *settings;
+
 public:
     static PlaylistDialog * getInstance( intf_thread_t *p_intf )
     {
index 697438d60309806ab6ea3ae7d75ad076fb33046f..b51980c8ff40270947aa9c075913ef72f63686e9 100644 (file)
@@ -138,14 +138,14 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 
 #if 0
     /* Create a Dock to get the playlist */
-/*    dockPL = new QDockWidget( qtr( "Playlist" ), this );
+    dockPL = new QDockWidget( qtr( "Playlist" ), this );
     dockPL->setSizePolicy( QSizePolicy::Preferred,
                            QSizePolicy::Expanding );
     dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
     dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
                            | Qt::RightDockWidgetArea
                            | Qt::BottomDockWidgetArea );
-    dockPL->hide();*/
+    dockPL->hide();
 #endif
 
     /************
@@ -244,13 +244,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
              this, doComponentsUpdate() );
 
     /* Size and placement of interface */
-    move( settings->value( "pos", QPoint( 0, 0 ) ).toPoint() );
+    QVLCTools::restoreWidgetPosition(settings,this,QSize(350,60));
 
-    QSize newSize = settings->value( "size", QSize( 350, 60 ) ).toSize();
-    if( newSize.isValid() )
-        resize( newSize );
-    else
-        msg_Warn( p_intf, "Invalid size in constructor" );
 
     /* Playlist */
     if( settings->value( "playlist-visible", 0 ).toInt() ) togglePlaylist();
@@ -274,16 +269,19 @@ MainInterface::~MainInterface()
 {
     msg_Dbg( p_intf, "Destroying the main interface" );
 
-    if( playlistWidget ) playlistWidget->savingSettings( settings );
+    if( playlistWidget )
+        playlistWidget->savingSettings( settings );
 
     settings->beginGroup( "MainWindow" );
-//    settings->setValue( "playlist-floats", (int)(dockPL->isFloating()) );
+
+    // settings->setValue( "playlist-floats", (int)(dockPL->isFloating()) );
     settings->setValue( "playlist-visible", (int)playlistVisible );
     settings->setValue( "adv-controls",
                         getControlsVisibilityStatus() & CONTROLS_ADVANCED );
-    settings->setValue( "pos", pos() );
+
     if( !videoIsActive )
-        settings->setValue( "size", size() );
+        QVLCTools::saveWidgetPosition(settings, this);
+
     if( bgWidget )
         settings->setValue( "backgroundSize", bgWidget->size() );
 
index 623d6523619708068021f263f1f6c6da49d90593..0fa30fa3f177ad4bcf8bb8ec74bcbb5833996396 100644 (file)
 #include <QMainWindow>
 #include <QPushButton>
 #include <QKeyEvent>
+#include <QDesktopWidget>
 
 #include "qt4.hpp"
 #include <vlc/vlc.h>
 #include <vlc_charset.h>
 
+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(QString configName, QWidget *widget)
+       {
+         QSettings *settings = new QSettings("vlc", "vlc-qt-interface");
+         settings->beginGroup( configName );
+         QVLCTools::saveWidgetPosition(settings, widget);
+         settings->endGroup();
+         delete settings;
+       }
+
+
+       /*
+         use this method only for restoring window state of non docked
+         windows!
+       */
+       static vlc_bool_t 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 VLC_TRUE;
+          }
+          return VLC_FALSE;
+       }
+
+       static vlc_bool_t restoreWidgetPosition(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 );
+         vlc_bool_t defaultUsed = QVLCTools::restoreWidgetPosition(settings,
+                                                                   widget,
+                                                                   defSize,
+                                                                   defPos);
+         settings->endGroup();
+         delete settings;
+
+         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:
@@ -57,26 +134,14 @@ protected:
                        QSize defSize = QSize( 0, 0 ),
                        QPoint defPos = QPoint( 0, 0 ) )
     {
-        QSettings settings( "vlc", "vlc-qt-interface" );
-        settings.beginGroup( name );
-        /* never trust any saved size ;-) */
-        QSize newSize = settings.value( "size", defSize ).toSize();
-        if( newSize.isValid() )
-           resize( newSize );
-        move( settings.value( "pos", defPos ).toPoint() );
-        settings.endGroup();
+        QVLCTools::restoreWidgetPosition(name, this, defSize, defPos);
     }
+
     void writeSettings( QString name )
     {
-        QSettings settings( "vlc", "vlc-qt-interface" );
-        settings.beginGroup( name );
-        /* only save valid sizes ... */
-        QSize currentsize = size();
-        if( currentsize.isValid() )
-           settings.setValue ("size", currentsize );
-        settings.setValue( "pos", pos() );
-        settings.endGroup();
+        QVLCTools::saveWidgetPosition(name, this);
     }
+
     virtual void cancel()
     {
         hide();
@@ -156,36 +221,34 @@ protected:
 
     void readSettings( QString name, QSize defSize )
     {
-        QSettings settings( "vlc", "vlc-qt-interface" );
-        settings.beginGroup( name );
-        QSize s =  settings.value( "size", defSize ).toSize() ;
-        move( settings.value( "pos", QPoint( 0,0 ) ).toPoint() );
-        settings.endGroup();
+        QVLCTools::restoreWidgetPosition(name, this, defSize);
     }
 
     void readSettings( QString name )
     {
-        QSettings settings( "vlc", "vlc-qt-interface" );
-        settings.beginGroup( name );
-        mainSize = settings.value( "size", QSize( 0,0 ) ).toSize();
-        if( !mainSize.isValid() )
-        {
-           mainSize = QSize(0,0);
-        }
-        settings.endGroup();
+        QVLCTools::restoreWidgetPosition(name, this);
     }
 
-    void writeSettings( QString name )
+    void readSettings( QSettings *settings )
+    {
+        QVLCTools::restoreWidgetPosition(settings, this);
+    }
+
+    void readSettings( QSettings *settings, QSize defSize)
+    {
+        QVLCTools::restoreWidgetPosition(settings, this, defSize);
+    }
+
+    void writeSettings(QString name )
+    {
+        QVLCTools::saveWidgetPosition(name, this);
+    }
+
+    void writeSettings(QSettings *settings )
     {
-        QSettings settings( "vlc", "vlc-qt-interface" );
-        settings.beginGroup( name );
-        /* only save valid sizes ... */
-        QSize currentsize = size();
-        if( currentsize.isValid() )
-            settings.setValue ("size", currentsize );
-        settings.setValue( "pos", pos() );
-        settings.endGroup();
+        QVLCTools::saveWidgetPosition(settings, this);
     }
+
 };
 
 #endif