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::openDictionaryFolder, this, &ScanPopup::openDictionaryFolder );
pinnedGeometry = cfg.popupWindowGeometry;
if( cfg.popupWindowGeometry.size() )
restoreGeometry( cfg.popupWindowGeometry );
@ -546,6 +547,11 @@ void ScanPopup::engagePopup( bool forcePopup, bool giveFocus )
move( x, y );
}
else
{
if( pinnedGeometry.size() > 0 )
restoreGeometry( pinnedGeometry );
}
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()
{
// Check that there's a window there at all
@ -988,6 +1010,9 @@ void ScanPopup::pinButtonClicked( bool checked )
cfg.pinPopupWindow = checked;
show();
if( checked )
pinnedGeometry = saveGeometry();
}
void ScanPopup::focusTranslateLine()

View file

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