Commit 894f52c8 authored by André Weber's avatar André Weber

Saveing Window Positions useing the QT defined methods as far as possible.

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.
parent d28d1294
......@@ -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();
}
......@@ -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 )
{
......
......@@ -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 )
{
......
......@@ -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() );
......
......@@ -33,11 +33,88 @@
#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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment