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>
This commit is contained in:
xiaoyifang 2024-07-06 13:23:22 +08:00 committed by GitHub
parent 297795a654
commit 5780bdbbb1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 25 deletions

View file

@ -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;

View file

@ -10,7 +10,8 @@
#include <QApplication>
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:

View file

@ -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