Merge pull request #356 from xiaoyifang/goldendict-master

upstream:save/restore scanpopup position
This commit is contained in:
xiaoyifang 2023-02-26 15:37:46 +08:00 committed by GitHub
commit 27766d4e22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View file

@ -170,6 +170,7 @@ ScanPopup::ScanPopup( QWidget * parent,
connect( &dictionaryBar, &DictionaryBar::showDictionaryInfo, this, &ScanPopup::showDictionaryInfo ); connect( &dictionaryBar, &DictionaryBar::showDictionaryInfo, this, &ScanPopup::showDictionaryInfo );
connect( &dictionaryBar, &DictionaryBar::openDictionaryFolder, this, &ScanPopup::openDictionaryFolder ); connect( &dictionaryBar, &DictionaryBar::openDictionaryFolder, this, &ScanPopup::openDictionaryFolder );
pinnedGeometry = cfg.popupWindowGeometry;
if( cfg.popupWindowGeometry.size() ) if( cfg.popupWindowGeometry.size() )
restoreGeometry( cfg.popupWindowGeometry ); restoreGeometry( cfg.popupWindowGeometry );
@ -546,6 +547,11 @@ void ScanPopup::engagePopup( bool forcePopup, bool giveFocus )
move( x, y ); move( x, y );
} }
else
{
if( pinnedGeometry.size() > 0 )
restoreGeometry( pinnedGeometry );
}
show(); show();
@ -933,6 +939,22 @@ void ScanPopup::showEvent( QShowEvent * ev )
} }
} }
void ScanPopup::closeEvent( QCloseEvent * ev )
{
if( isVisible() && ui.pinButton->isChecked() )
pinnedGeometry = saveGeometry();
QMainWindow::closeEvent( ev );
}
void ScanPopup::moveEvent( QMoveEvent * ev )
{
if( isVisible() && ui.pinButton->isChecked() )
pinnedGeometry = saveGeometry();
QMainWindow::moveEvent( ev );
}
void ScanPopup::prefixMatchFinished() void ScanPopup::prefixMatchFinished()
{ {
// Check that there's a window there at all // Check that there's a window there at all
@ -988,6 +1010,9 @@ void ScanPopup::pinButtonClicked( bool checked )
cfg.pinPopupWindow = checked; cfg.pinPopupWindow = checked;
show(); show();
if( checked )
pinnedGeometry = saveGeometry();
} }
void ScanPopup::focusTranslateLine() void ScanPopup::focusTranslateLine()

View file

@ -150,6 +150,7 @@ private:
bool mouseIntercepted; bool mouseIntercepted;
QPoint startPos; // For window moving QPoint startPos; // For window moving
QByteArray pinnedGeometry;
QTimer hideTimer; // When mouse leaves the window, a grace period is QTimer hideTimer; // When mouse leaves the window, a grace period is
// given for it to return back. If it doesn't before // given for it to return back. If it doesn't before
@ -180,6 +181,8 @@ private:
virtual void enterEvent( QEvent * event ); virtual void enterEvent( QEvent * event );
#endif #endif
virtual void showEvent( QShowEvent * ); virtual void showEvent( QShowEvent * );
virtual void closeEvent( QCloseEvent * );
virtual void moveEvent( QMoveEvent * );
/// Returns inputWord, chopped with appended ... if it's too long/ /// Returns inputWord, chopped with appended ... if it's too long/
QString elideInputWord(); QString elideInputWord();