mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
+ Save main window's state and geometry on exit and restore it back on
startup.
This commit is contained in:
parent
6f20c0ffa7
commit
129e922138
|
@ -217,6 +217,16 @@ Class load() throw( exError )
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -402,6 +412,14 @@ void save( Class const & c ) throw( exError )
|
|||
opt.appendChild( dd.createTextNode( QString::number( c.lastPopupSize.height() ) ) );
|
||||
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() );
|
||||
|
|
|
@ -112,6 +112,9 @@ struct Class
|
|||
QString lastMainGroup; // Last used group in main window
|
||||
QString lastPopupGroup; // Last used group in popup window
|
||||
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 )
|
||||
|
|
|
@ -40,6 +40,8 @@ MainWindow::MainWindow():
|
|||
|
||||
// Make the toolbar
|
||||
navToolbar = addToolBar( tr( "Navigation" ) );
|
||||
navToolbar->setObjectName( "navToolbar" );
|
||||
|
||||
navBack = navToolbar->addAction( QIcon( ":/icons/previous.png" ), tr( "Back" ) );
|
||||
navForward = navToolbar->addAction( QIcon( ":/icons/next.png" ), tr( "Forward" ) );
|
||||
|
||||
|
@ -130,6 +132,12 @@ MainWindow::MainWindow():
|
|||
ui.translateLine->installEventFilter( this );
|
||||
ui.wordList->installEventFilter( this );
|
||||
|
||||
if ( cfg.mainWindowGeometry.size() )
|
||||
restoreGeometry( cfg.mainWindowGeometry );
|
||||
|
||||
if ( cfg.mainWindowState.size() )
|
||||
restoreState( cfg.mainWindowState );
|
||||
|
||||
applyProxySettings();
|
||||
|
||||
makeDictionaries();
|
||||
|
@ -156,6 +164,10 @@ MainWindow::MainWindow():
|
|||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
// Save MainWindow state and geometry
|
||||
cfg.mainWindowState = saveState();
|
||||
cfg.mainWindowGeometry = saveGeometry();
|
||||
|
||||
// Save any changes in last chosen groups etc
|
||||
Config::save( cfg );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue