From 0c4483ae02565251d36f43c5a64a47dc68a1ade1 Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Wed, 10 Jul 2024 16:28:28 +0800 Subject: [PATCH] Revert "opt: remove wasMaximized logic of mainwindow" (#1664) * Revert "opt: remove wasMaximized logic of mainwindow" This reverts commit 99c221c8549c131afc7526bf8391ecab46a82276. * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- src/ui/mainwindow.cc | 17 +++++++++++++++++ src/ui/mainwindow.hh | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/ui/mainwindow.cc b/src/ui/mainwindow.cc index 5f22c249..65ca9bf3 100644 --- a/src/ui/mainwindow.cc +++ b/src/ui/mainwindow.cc @@ -165,6 +165,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ): audioPlayerFactory( cfg.preferences ), wordFinder( this ), wordListSelChanged( false ), + wasMaximized( false ), headwordsDlg( nullptr ), ftsIndexing( dictionaries ), ftsDlg( nullptr ), @@ -871,6 +872,8 @@ MainWindow::MainWindow( Config::Class & cfg_ ): mainStatusBar->showMessage( tr( "Accessibility API is not enabled" ), 10000, QPixmap( ":/icons/error.svg" ) ); #endif + wasMaximized = isMaximized(); + history.setSaveInterval( cfg.preferences.historyStoreInterval ); #ifndef Q_OS_MACOS ui.centralWidget->grabGesture( Gestures::GDPinchGestureType ); @@ -2494,6 +2497,11 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev ) } } + if ( obj == this && ev->type() == QEvent::WindowStateChange ) { + auto stev = dynamic_cast< QWindowStateChangeEvent * >( ev ); + wasMaximized = ( stev->oldState() == Qt::WindowMaximized && isMinimized() ); + } + if ( ev->type() == QEvent::MouseButtonPress ) { auto event = dynamic_cast< QMouseEvent * >( ev ); @@ -2751,6 +2759,15 @@ void MainWindow::toggleMainWindow( bool onlyShow ) raise(); shown = true; } + else if ( isMinimized() ) { + if ( wasMaximized ) + showMaximized(); + else + showNormal(); + activateWindow(); + raise(); + shown = true; + } else if ( !isActiveWindow() ) { activateWindow(); if ( cfg.preferences.raiseWindowOnSearch ) { diff --git a/src/ui/mainwindow.hh b/src/ui/mainwindow.hh index a9cab3d6..66d4a636 100644 --- a/src/ui/mainwindow.hh +++ b/src/ui/mainwindow.hh @@ -158,6 +158,8 @@ private: bool wordListSelChanged; + bool wasMaximized; // Window state before minimization + QPrinter & getPrinter(); // Creates a printer if it's not there and returns it DictHeadwords * headwordsDlg;