+ Save main window's state and geometry on exit and restore it back on

startup.
This commit is contained in:
Konstantin Isakov 2009-04-03 21:24:07 +00:00
parent 6f20c0ffa7
commit 129e922138
3 changed files with 33 additions and 0 deletions

View file

@ -217,6 +217,16 @@ Class load() throw( exError )
lastPopupHeight.toElement().text().toULong() ); lastPopupHeight.toElement().text().toULong() );
} }
QDomNode mainWindowState = root.namedItem( "mainWindowState" );
if ( !mainWindowState.isNull() )
c.mainWindowState = QByteArray::fromBase64( mainWindowState.toElement().text().toLatin1() );
QDomNode mainWindowGeometry = root.namedItem( "mainWindowGeometry" );
if ( !mainWindowGeometry.isNull() )
c.mainWindowGeometry = QByteArray::fromBase64( mainWindowGeometry.toElement().text().toLatin1() );
return c; return c;
} }
@ -402,6 +412,14 @@ void save( Class const & c ) throw( exError )
opt.appendChild( dd.createTextNode( QString::number( c.lastPopupSize.height() ) ) ); opt.appendChild( dd.createTextNode( QString::number( c.lastPopupSize.height() ) ) );
root.appendChild( opt ); root.appendChild( opt );
} }
opt = dd.createElement( "mainWindowState" );
opt.appendChild( dd.createTextNode( QString::fromLatin1( c.mainWindowState.toBase64() ) ) );
root.appendChild( opt );
opt = dd.createElement( "mainWindowGeometry" );
opt.appendChild( dd.createTextNode( QString::fromLatin1( c.mainWindowGeometry.toBase64() ) ) );
root.appendChild( opt );
} }
configFile.write( dd.toByteArray() ); configFile.write( dd.toByteArray() );

View file

@ -112,6 +112,9 @@ struct Class
QString lastMainGroup; // Last used group in main window QString lastMainGroup; // Last used group in main window
QString lastPopupGroup; // Last used group in popup window QString lastPopupGroup; // Last used group in popup window
QSize lastPopupSize; QSize lastPopupSize;
QByteArray mainWindowState; // Binary state saved by QMainWindow
QByteArray mainWindowGeometry; // Geometry saved by QMainWindow
}; };
DEF_EX( exError, "Error with the program's configuration", std::exception ) DEF_EX( exError, "Error with the program's configuration", std::exception )

View file

@ -40,6 +40,8 @@ MainWindow::MainWindow():
// Make the toolbar // Make the toolbar
navToolbar = addToolBar( tr( "Navigation" ) ); navToolbar = addToolBar( tr( "Navigation" ) );
navToolbar->setObjectName( "navToolbar" );
navBack = navToolbar->addAction( QIcon( ":/icons/previous.png" ), tr( "Back" ) ); navBack = navToolbar->addAction( QIcon( ":/icons/previous.png" ), tr( "Back" ) );
navForward = navToolbar->addAction( QIcon( ":/icons/next.png" ), tr( "Forward" ) ); navForward = navToolbar->addAction( QIcon( ":/icons/next.png" ), tr( "Forward" ) );
@ -130,6 +132,12 @@ MainWindow::MainWindow():
ui.translateLine->installEventFilter( this ); ui.translateLine->installEventFilter( this );
ui.wordList->installEventFilter( this ); ui.wordList->installEventFilter( this );
if ( cfg.mainWindowGeometry.size() )
restoreGeometry( cfg.mainWindowGeometry );
if ( cfg.mainWindowState.size() )
restoreState( cfg.mainWindowState );
applyProxySettings(); applyProxySettings();
makeDictionaries(); makeDictionaries();
@ -156,6 +164,10 @@ MainWindow::MainWindow():
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
// Save MainWindow state and geometry
cfg.mainWindowState = saveState();
cfg.mainWindowGeometry = saveGeometry();
// Save any changes in last chosen groups etc // Save any changes in last chosen groups etc
Config::save( cfg ); Config::save( cfg );
} }