Properly save/restore main window configuration when it maximized

This commit is contained in:
Abs62 2013-01-29 23:20:53 +04:00
parent 4d2baab8b9
commit d8decdae83
3 changed files with 69 additions and 5 deletions

View file

@ -731,6 +731,22 @@ Class load() throw( exError )
if ( !mainWindowGeometry.isNull() ) if ( !mainWindowGeometry.isNull() )
c.mainWindowGeometry = QByteArray::fromBase64( mainWindowGeometry.toElement().text().toLatin1() ); c.mainWindowGeometry = QByteArray::fromBase64( mainWindowGeometry.toElement().text().toLatin1() );
QDomNode maximizedMainWindowGeometry = root.namedItem( "maximizedMainWindowGeometry" );
if ( !maximizedMainWindowGeometry.isNull() )
{
int x = 0, y = 0, width = 0, height = 0;
if( !maximizedMainWindowGeometry.namedItem( "x" ).isNull() )
x = maximizedMainWindowGeometry.namedItem( "x" ).toElement().text().toInt();
if( !maximizedMainWindowGeometry.namedItem( "y" ).isNull() )
y = maximizedMainWindowGeometry.namedItem( "y" ).toElement().text().toInt();
if( !maximizedMainWindowGeometry.namedItem( "width" ).isNull() )
width = maximizedMainWindowGeometry.namedItem( "width" ).toElement().text().toInt();
if( !maximizedMainWindowGeometry.namedItem( "height" ).isNull() )
height = maximizedMainWindowGeometry.namedItem( "height" ).toElement().text().toInt();
c.maximizedMainWindowGeometry = QRect( x, y, width, height );
}
QDomNode dictInfoGeometry = root.namedItem( "dictInfoGeometry" ); QDomNode dictInfoGeometry = root.namedItem( "dictInfoGeometry" );
if ( !dictInfoGeometry.isNull() ) if ( !dictInfoGeometry.isNull() )
@ -1385,6 +1401,27 @@ void save( Class const & c ) throw( exError )
opt.appendChild( dd.createTextNode( QString::fromLatin1( c.mainWindowGeometry.toBase64() ) ) ); opt.appendChild( dd.createTextNode( QString::fromLatin1( c.mainWindowGeometry.toBase64() ) ) );
root.appendChild( opt ); root.appendChild( opt );
{
QDomElement maximizedMainWindowGeometry = dd.createElement( "maximizedMainWindowGeometry" );
root.appendChild( maximizedMainWindowGeometry );
opt = dd.createElement( "x" );
opt.appendChild( dd.createTextNode( QString::number( c.maximizedMainWindowGeometry.x() ) ) );
maximizedMainWindowGeometry.appendChild( opt );
opt = dd.createElement( "y" );
opt.appendChild( dd.createTextNode( QString::number( c.maximizedMainWindowGeometry.y() ) ) );
maximizedMainWindowGeometry.appendChild( opt );
opt = dd.createElement( "width" );
opt.appendChild( dd.createTextNode( QString::number( c.maximizedMainWindowGeometry.width() ) ) );
maximizedMainWindowGeometry.appendChild( opt );
opt = dd.createElement( "height" );
opt.appendChild( dd.createTextNode( QString::number( c.maximizedMainWindowGeometry.height() ) ) );
maximizedMainWindowGeometry.appendChild( opt );
}
opt = dd.createElement( "dictInfoGeometry" ); opt = dd.createElement( "dictInfoGeometry" );
opt.appendChild( dd.createTextNode( QString::fromLatin1( c.dictInfoGeometry.toBase64() ) ) ); opt.appendChild( dd.createTextNode( QString::fromLatin1( c.dictInfoGeometry.toBase64() ) ) );
root.appendChild( opt ); root.appendChild( opt );

View file

@ -10,6 +10,7 @@
#include <QDateTime> #include <QDateTime>
#include <QKeySequence> #include <QKeySequence>
#include <QSet> #include <QSet>
#include <QRect>
#include "ex.hh" #include "ex.hh"
/// GoldenDict's configuration /// GoldenDict's configuration
@ -422,6 +423,8 @@ struct Class
/// Bigger headwords won't be indexed. For now, only in DSL. /// Bigger headwords won't be indexed. For now, only in DSL.
unsigned int maxHeadwordSize; unsigned int maxHeadwordSize;
QRect maximizedMainWindowGeometry;
QString editDictionaryCommandLine; // Command line to call external editor for dictionary QString editDictionaryCommandLine; // Command line to call external editor for dictionary
Class(): lastMainGroupId( 0 ), lastPopupGroupId( 0 ), Class(): lastMainGroupId( 0 ), lastPopupGroupId( 0 ),

View file

@ -604,11 +604,24 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
ui.historyList->installEventFilter( this ); ui.historyList->installEventFilter( this );
if ( cfg.mainWindowGeometry.size() ) QRect baseGeometry;
restoreGeometry( cfg.mainWindowGeometry ); if( cfg.maximizedMainWindowGeometry.width() > 0 )
{
if ( cfg.mainWindowState.size() ) if ( cfg.mainWindowGeometry.size() )
restoreState( cfg.mainWindowState, 1 ); restoreGeometry( cfg.mainWindowGeometry );
baseGeometry = geometry();
setGeometry( cfg.maximizedMainWindowGeometry );
if ( cfg.mainWindowState.size() )
restoreState( cfg.mainWindowState, 1 );
setWindowState( windowState() | Qt::WindowMaximized );
}
else
{
if ( cfg.mainWindowGeometry.size() )
restoreGeometry( cfg.mainWindowGeometry );
if ( cfg.mainWindowState.size() )
restoreState( cfg.mainWindowState, 1 );
}
updateSearchPaneAndBar( cfg.preferences.searchInDock ); updateSearchPaneAndBar( cfg.preferences.searchInDock );
ui.searchPane->setVisible( cfg.preferences.searchInDock ); ui.searchPane->setVisible( cfg.preferences.searchInDock );
@ -673,6 +686,12 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
{ {
show(); show();
focusTranslateLine(); focusTranslateLine();
if( baseGeometry.width() > 0 )
{
hide();
setGeometry( baseGeometry );
showMaximized();
}
} }
connect( &newReleaseCheckTimer, SIGNAL( timeout() ), connect( &newReleaseCheckTimer, SIGNAL( timeout() ),
@ -794,6 +813,11 @@ void MainWindow::mousePressEvent( QMouseEvent *event)
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
if( isMaximized() )
cfg.maximizedMainWindowGeometry = geometry();
else
cfg.maximizedMainWindowGeometry = QRect();
commitData(); commitData();
// Close all tabs -- they should be destroyed before network managers // Close all tabs -- they should be destroyed before network managers