mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 04:24:09 +00:00
Win-specific: Refactor of main window geometry saving
This commit is contained in:
parent
023f30a997
commit
696fdbb994
35
config.cc
35
config.cc
|
@ -798,6 +798,22 @@ Class load() throw( exError )
|
|||
height = maximizedMainWindowGeometry.namedItem( "height" ).toElement().text().toInt();
|
||||
c.maximizedMainWindowGeometry = QRect( x, y, width, height );
|
||||
}
|
||||
|
||||
QDomNode normalMainWindowGeometry = root.namedItem( "normalMainWindowGeometry" );
|
||||
|
||||
if ( !normalMainWindowGeometry.isNull() )
|
||||
{
|
||||
int x = 0, y = 0, width = 0, height = 0;
|
||||
if( !normalMainWindowGeometry.namedItem( "x" ).isNull() )
|
||||
x = normalMainWindowGeometry.namedItem( "x" ).toElement().text().toInt();
|
||||
if( !normalMainWindowGeometry.namedItem( "y" ).isNull() )
|
||||
y = normalMainWindowGeometry.namedItem( "y" ).toElement().text().toInt();
|
||||
if( !normalMainWindowGeometry.namedItem( "width" ).isNull() )
|
||||
width = normalMainWindowGeometry.namedItem( "width" ).toElement().text().toInt();
|
||||
if( !normalMainWindowGeometry.namedItem( "height" ).isNull() )
|
||||
height = normalMainWindowGeometry.namedItem( "height" ).toElement().text().toInt();
|
||||
c.normalMainWindowGeometry = QRect( x, y, width, height );
|
||||
}
|
||||
#endif
|
||||
|
||||
QDomNode dictInfoGeometry = root.namedItem( "dictInfoGeometry" );
|
||||
|
@ -1535,6 +1551,25 @@ void save( Class const & c ) throw( exError )
|
|||
opt = dd.createElement( "height" );
|
||||
opt.appendChild( dd.createTextNode( QString::number( c.maximizedMainWindowGeometry.height() ) ) );
|
||||
maximizedMainWindowGeometry.appendChild( opt );
|
||||
|
||||
QDomElement normalMainWindowGeometry = dd.createElement( "normalMainWindowGeometry" );
|
||||
root.appendChild( normalMainWindowGeometry );
|
||||
|
||||
opt = dd.createElement( "x" );
|
||||
opt.appendChild( dd.createTextNode( QString::number( c.normalMainWindowGeometry.x() ) ) );
|
||||
normalMainWindowGeometry.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "y" );
|
||||
opt.appendChild( dd.createTextNode( QString::number( c.normalMainWindowGeometry.y() ) ) );
|
||||
normalMainWindowGeometry.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "width" );
|
||||
opt.appendChild( dd.createTextNode( QString::number( c.normalMainWindowGeometry.width() ) ) );
|
||||
normalMainWindowGeometry.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "height" );
|
||||
opt.appendChild( dd.createTextNode( QString::number( c.normalMainWindowGeometry.height() ) ) );
|
||||
normalMainWindowGeometry.appendChild( opt );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -475,6 +475,7 @@ struct Class
|
|||
|
||||
#ifdef Q_OS_WIN
|
||||
QRect maximizedMainWindowGeometry;
|
||||
QRect normalMainWindowGeometry;
|
||||
#endif
|
||||
|
||||
QString editDictionaryCommandLine; // Command line to call external editor for dictionary
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <QRunnable>
|
||||
#include <QThreadPool>
|
||||
#include <QSslConfiguration>
|
||||
#include <QDesktopWidget>
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
#include "lionsupport.h"
|
||||
|
@ -38,6 +39,10 @@
|
|||
#include "mouseover_win32/GDDataTranfer.h"
|
||||
#include "wstring.hh"
|
||||
#include "wstring_qt.hh"
|
||||
|
||||
#define gdStoreNormalGeometryEvent ( ( QEvent::Type )( QEvent::User + 1 ) )
|
||||
#define gdApplyNormalGeometryEvent ( ( QEvent::Type )( QEvent::User + 2 ) )
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
|
@ -644,13 +649,16 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
ui.historyList->installEventFilter( this );
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
QRect baseGeometry;
|
||||
if( cfg.normalMainWindowGeometry.width() <= 0 )
|
||||
{
|
||||
QRect r = QApplication::desktop()->availableGeometry();
|
||||
cfg.normalMainWindowGeometry.setRect( r.width() / 4, r.height() / 4, r.width() / 2, r.height() / 2 );
|
||||
}
|
||||
if( cfg.maximizedMainWindowGeometry.width() > 0 )
|
||||
{
|
||||
setGeometry( cfg.maximizedMainWindowGeometry );
|
||||
if ( cfg.mainWindowGeometry.size() )
|
||||
restoreGeometry( cfg.mainWindowGeometry );
|
||||
baseGeometry = geometry();
|
||||
setGeometry( cfg.maximizedMainWindowGeometry );
|
||||
if ( cfg.mainWindowState.size() )
|
||||
restoreState( cfg.mainWindowState, 1 );
|
||||
setWindowState( windowState() | Qt::WindowMaximized );
|
||||
|
@ -732,15 +740,6 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
{
|
||||
show();
|
||||
focusTranslateLine();
|
||||
#ifdef Q_OS_WIN
|
||||
if( baseGeometry.width() > 0 )
|
||||
{
|
||||
hide();
|
||||
setGeometry( baseGeometry );
|
||||
showMaximized();
|
||||
activateWindow();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
connect( &newReleaseCheckTimer, SIGNAL( timeout() ),
|
||||
|
@ -867,9 +866,15 @@ MainWindow::~MainWindow()
|
|||
{
|
||||
#ifdef Q_OS_WIN
|
||||
if( isMaximized() )
|
||||
{
|
||||
cfg.maximizedMainWindowGeometry = geometry();
|
||||
}
|
||||
else
|
||||
{
|
||||
cfg.maximizedMainWindowGeometry = QRect();
|
||||
if( !isMinimized() )
|
||||
cfg.normalMainWindowGeometry = geometry();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Close all tabs -- they should be destroyed before network managers
|
||||
|
@ -2022,6 +2027,23 @@ bool MainWindow::handleBackForwardMouseButtons ( QMouseEvent * event) {
|
|||
|
||||
bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
if( obj == this && ev->type() == gdStoreNormalGeometryEvent )
|
||||
{
|
||||
if( !isMaximized() && !isMinimized() && !isFullScreen() )
|
||||
cfg.normalMainWindowGeometry = normalGeometry();
|
||||
ev->accept();
|
||||
return true;
|
||||
}
|
||||
|
||||
if( obj == this && ev->type() == gdApplyNormalGeometryEvent )
|
||||
{
|
||||
if( !isMaximized() && !isMinimized() && !isFullScreen() )
|
||||
setGeometry( cfg.normalMainWindowGeometry );
|
||||
ev->accept();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
if ( ev->type() == QEvent::ShortcutOverride ) {
|
||||
// Handle Ctrl+H to show the History Pane.
|
||||
QKeyEvent * ke = static_cast<QKeyEvent*>( ev );
|
||||
|
@ -2044,6 +2066,13 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
|
|||
// when the main window is moved or resized, hide the word list suggestions
|
||||
if ( obj == this && ( ev->type() == QEvent::Move || ev->type() == QEvent::Resize ) )
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
if( !isMaximized() && !isMinimized() && !isFullScreen() && gdAskMessage != 0xFFFFFFFF )
|
||||
{
|
||||
QEvent *ev = new QEvent( gdStoreNormalGeometryEvent );
|
||||
qApp->postEvent( this, ev );
|
||||
}
|
||||
#endif
|
||||
if ( !cfg.preferences.searchInDock )
|
||||
{
|
||||
translateBox->setPopupEnabled( false );
|
||||
|
@ -2055,6 +2084,14 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
|
|||
{
|
||||
QWindowStateChangeEvent *stev = static_cast< QWindowStateChangeEvent *>( ev );
|
||||
wasMaximized = ( stev->oldState() == Qt::WindowMaximized && isMinimized() );
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
if( stev->oldState() == Qt::WindowMaximized && !isMinimized() && cfg.normalMainWindowGeometry.width() > 0 )
|
||||
{
|
||||
QEvent *ev = new QEvent( gdApplyNormalGeometryEvent );
|
||||
qApp->postEvent( this, ev );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if ( ev->type() == QEvent::MouseButtonPress ) {
|
||||
|
|
Loading…
Reference in a new issue