mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 23:34:06 +00:00
Properly save/restore main window configuration when it maximized
This commit is contained in:
parent
4d2baab8b9
commit
d8decdae83
37
config.cc
37
config.cc
|
@ -731,6 +731,22 @@ Class load() throw( exError )
|
|||
if ( !mainWindowGeometry.isNull() )
|
||||
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" );
|
||||
|
||||
if ( !dictInfoGeometry.isNull() )
|
||||
|
@ -1385,6 +1401,27 @@ void save( Class const & c ) throw( exError )
|
|||
opt.appendChild( dd.createTextNode( QString::fromLatin1( c.mainWindowGeometry.toBase64() ) ) );
|
||||
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.appendChild( dd.createTextNode( QString::fromLatin1( c.dictInfoGeometry.toBase64() ) ) );
|
||||
root.appendChild( opt );
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <QDateTime>
|
||||
#include <QKeySequence>
|
||||
#include <QSet>
|
||||
#include <QRect>
|
||||
#include "ex.hh"
|
||||
|
||||
/// GoldenDict's configuration
|
||||
|
@ -422,6 +423,8 @@ struct Class
|
|||
/// Bigger headwords won't be indexed. For now, only in DSL.
|
||||
unsigned int maxHeadwordSize;
|
||||
|
||||
QRect maximizedMainWindowGeometry;
|
||||
|
||||
QString editDictionaryCommandLine; // Command line to call external editor for dictionary
|
||||
|
||||
Class(): lastMainGroupId( 0 ), lastPopupGroupId( 0 ),
|
||||
|
|
|
@ -604,11 +604,24 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
|
||||
ui.historyList->installEventFilter( this );
|
||||
|
||||
QRect baseGeometry;
|
||||
if( cfg.maximizedMainWindowGeometry.width() > 0 )
|
||||
{
|
||||
if ( cfg.mainWindowGeometry.size() )
|
||||
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 );
|
||||
ui.searchPane->setVisible( cfg.preferences.searchInDock );
|
||||
|
@ -673,6 +686,12 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
{
|
||||
show();
|
||||
focusTranslateLine();
|
||||
if( baseGeometry.width() > 0 )
|
||||
{
|
||||
hide();
|
||||
setGeometry( baseGeometry );
|
||||
showMaximized();
|
||||
}
|
||||
}
|
||||
|
||||
connect( &newReleaseCheckTimer, SIGNAL( timeout() ),
|
||||
|
@ -794,6 +813,11 @@ void MainWindow::mousePressEvent( QMouseEvent *event)
|
|||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
if( isMaximized() )
|
||||
cfg.maximizedMainWindowGeometry = geometry();
|
||||
else
|
||||
cfg.maximizedMainWindowGeometry = QRect();
|
||||
|
||||
commitData();
|
||||
|
||||
// Close all tabs -- they should be destroyed before network managers
|
||||
|
|
Loading…
Reference in a new issue