From 5780bdbbb1993d8ed8213c877e27acb68060fa8d Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Sat, 6 Jul 2024 13:23:22 +0800 Subject: [PATCH] fix: status bar position (#1643) * fix: statusbar rarely will be blocked by the webview. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- src/stylesheets/qt-classic.css | 16 ---------------- src/ui/mainstatusbar.cc | 20 ++++++++++++++------ src/ui/mainstatusbar.hh | 6 +++--- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/stylesheets/qt-classic.css b/src/stylesheets/qt-classic.css index 6aeeb106..952ff83c 100644 --- a/src/stylesheets/qt-classic.css +++ b/src/stylesheets/qt-classic.css @@ -20,22 +20,6 @@ QTabBar::close-button:hover { image: url(:/icons/closetab-hover.png); } -MainStatusBar #text { - border-top-right-radius: 3px; - border-top: 1px solid palette(dark); - border-right: 1px solid palette(dark); - background: palette(window); - padding: 2px; -} - -MainStatusBar #icon { - border-top: 1px solid palette(dark); - background: palette(window); - padding: 2px; - padding-left: 4px; - padding-right: 0px; -} - ScanPopup #translateLine { margin: 0px; padding: 1px 3px 1px 3px; diff --git a/src/ui/mainstatusbar.cc b/src/ui/mainstatusbar.cc index 9b557a5a..b63d9497 100644 --- a/src/ui/mainstatusbar.cc +++ b/src/ui/mainstatusbar.cc @@ -10,7 +10,8 @@ #include MainStatusBar::MainStatusBar( QWidget * parent ): - QWidget( parent ) + QWidget( parent ), + timer( new QTimer( this ) ) { textWidget = new QLabel( QString(), this ); textWidget->setObjectName( "text" ); @@ -23,7 +24,7 @@ MainStatusBar::MainStatusBar( QWidget * parent ): picWidget->setScaledContents( true ); picWidget->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Ignored ); - timer = new QTimer( this ); + timer->setSingleShot( true ); // layout @@ -31,7 +32,7 @@ MainStatusBar::MainStatusBar( QWidget * parent ): layout->setSpacing( 0 ); layout->setSizeConstraint( QLayout::SetFixedSize ); layout->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); - layout->setContentsMargins( 0, 0, 0, 0 ); + layout->setContentsMargins( 5, 5, 5, 5 ); layout->addWidget( picWidget ); layout->addWidget( textWidget ); setLayout( layout ); @@ -46,9 +47,10 @@ MainStatusBar::MainStatusBar( QWidget * parent ): void MainStatusBar::clearMessage() { message.clear(); - textWidget->setText( backgroungMessage ); + textWidget->setText( backgroundMessage ); picWidget->setPixmap( QPixmap() ); timer->stop(); + hide(); } QString MainStatusBar::currentMessage() const @@ -58,14 +60,16 @@ QString MainStatusBar::currentMessage() const void MainStatusBar::setBackgroundMessage( const QString & bkg_message ) { - backgroungMessage = bkg_message; + show(); + backgroundMessage = bkg_message; if ( message.isEmpty() ) { - textWidget->setText( backgroungMessage ); + textWidget->setText( backgroundMessage ); } } void MainStatusBar::showMessage( const QString & str, int timeout, const QPixmap & pixmap ) { + show(); textWidget->setText( message = str ); picWidget->setPixmap( pixmap ); @@ -81,6 +85,8 @@ void MainStatusBar::showMessage( const QString & str, int timeout, const QPixmap } if ( parentWidget() ) { + raise(); + move( 0, parentWidget()->height() - height() ); } } @@ -94,6 +100,8 @@ bool MainStatusBar::eventFilter( QObject *, QEvent * e ) { switch ( e->type() ) { case QEvent::Resize: + raise(); + move( QPoint( 0, parentWidget()->height() - height() ) ); break; default: diff --git a/src/ui/mainstatusbar.hh b/src/ui/mainstatusbar.hh index 921d0554..3052d674 100644 --- a/src/ui/mainstatusbar.hh +++ b/src/ui/mainstatusbar.hh @@ -25,7 +25,7 @@ public slots: void setBackgroundMessage( QString const & message ); protected: - virtual void mousePressEvent( QMouseEvent * event ); + void mousePressEvent( QMouseEvent * event ) override; private: // component to display a small picture @@ -35,10 +35,10 @@ private: QLabel * textWidget; QTimer * timer; - QString backgroungMessage; + QString backgroundMessage; QString message; - bool eventFilter( QObject * obj, QEvent * event ); + bool eventFilter( QObject * obj, QEvent * event ) override; }; #endif // MAINSTATUSBAR_HH