2012-02-20 21:47:14 +00:00
|
|
|
/* This file is (c) 2012 Tvangeste <i.4m.l33t@yandex.ru>
|
2011-06-27 18:54:15 +00:00
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#include "mainstatusbar.hh"
|
|
|
|
|
|
|
|
#include <Qt>
|
|
|
|
#include <QFrame>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QEvent>
|
2011-07-09 11:55:44 +00:00
|
|
|
#include <QApplication>
|
2011-06-27 18:54:15 +00:00
|
|
|
|
2011-07-14 20:11:57 +00:00
|
|
|
MainStatusBar::MainStatusBar( QWidget *parent ) : QWidget( parent )
|
2011-06-27 18:54:15 +00:00
|
|
|
{
|
2011-07-14 20:11:57 +00:00
|
|
|
textWidget = new QLabel( QString(), this );
|
|
|
|
textWidget->setObjectName( "text" );
|
|
|
|
textWidget->setFont( QApplication::font( "QStatusBar" ) );
|
|
|
|
textWidget->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
|
2011-07-09 11:55:44 +00:00
|
|
|
|
2011-07-14 20:11:57 +00:00
|
|
|
picWidget = new QLabel( QString(), this );
|
|
|
|
picWidget->setObjectName( "icon" );
|
|
|
|
picWidget->setPixmap( QPixmap() );
|
|
|
|
picWidget->setScaledContents( true );
|
|
|
|
picWidget->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Ignored );
|
2011-07-09 11:55:44 +00:00
|
|
|
|
2011-07-14 20:11:57 +00:00
|
|
|
timer = new QTimer( this );
|
|
|
|
timer->setSingleShot( true );
|
2011-06-27 18:54:15 +00:00
|
|
|
|
|
|
|
// layout
|
2011-07-09 11:55:44 +00:00
|
|
|
QHBoxLayout * layout = new QHBoxLayout;
|
2011-07-14 20:11:57 +00:00
|
|
|
layout->setSpacing( 0 );
|
|
|
|
layout->setSizeConstraint( QLayout::SetFixedSize );
|
|
|
|
layout->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
|
|
|
|
layout->setContentsMargins( 0, 0, 0, 0 );
|
|
|
|
layout->addWidget( picWidget );
|
|
|
|
layout->addWidget( textWidget );
|
|
|
|
setLayout( layout );
|
2011-06-27 18:54:15 +00:00
|
|
|
|
2011-07-09 17:05:14 +00:00
|
|
|
parentWidget()->installEventFilter( this );
|
|
|
|
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( timer, &QTimer::timeout, this, &MainStatusBar::clearMessage );
|
2011-06-27 18:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainStatusBar::clearMessage()
|
|
|
|
{
|
2015-11-01 12:22:18 +00:00
|
|
|
message.clear();
|
|
|
|
textWidget->setText( backgroungMessage );
|
2011-07-14 20:11:57 +00:00
|
|
|
picWidget->setPixmap( QPixmap() );
|
2011-06-27 18:54:15 +00:00
|
|
|
timer->stop();
|
2023-03-10 14:02:17 +00:00
|
|
|
hide();
|
2011-06-27 18:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString MainStatusBar::currentMessage() const
|
|
|
|
{
|
2015-11-01 12:22:18 +00:00
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainStatusBar::setBackgroundMessage(const QString & bkg_message )
|
|
|
|
{
|
|
|
|
backgroungMessage = bkg_message;
|
|
|
|
if( message.isEmpty() )
|
|
|
|
{
|
|
|
|
textWidget->setText( backgroungMessage );
|
2023-03-10 14:02:17 +00:00
|
|
|
raise();
|
|
|
|
show();
|
2015-11-01 12:22:18 +00:00
|
|
|
}
|
2011-06-27 18:54:15 +00:00
|
|
|
}
|
|
|
|
|
2011-07-09 11:55:44 +00:00
|
|
|
void MainStatusBar::showMessage(const QString & str, int timeout, const QPixmap & pixmap)
|
2011-06-27 18:54:15 +00:00
|
|
|
{
|
2015-11-01 12:22:18 +00:00
|
|
|
textWidget->setText( message = str );
|
2011-07-09 11:55:44 +00:00
|
|
|
picWidget->setPixmap( pixmap );
|
2011-06-27 18:54:15 +00:00
|
|
|
|
2023-03-10 14:02:17 +00:00
|
|
|
if ( !picWidget->pixmap().isNull() )
|
2011-07-09 11:55:44 +00:00
|
|
|
{
|
2023-03-10 14:02:17 +00:00
|
|
|
picWidget->setFixedSize( textWidget->height(), textWidget->height() );
|
2011-07-09 11:55:44 +00:00
|
|
|
}
|
2023-03-10 14:02:17 +00:00
|
|
|
else
|
2011-06-30 13:13:23 +00:00
|
|
|
{
|
2023-03-10 14:02:17 +00:00
|
|
|
picWidget->setFixedSize( 0, 0 );
|
2011-06-27 18:54:15 +00:00
|
|
|
}
|
2023-03-10 14:02:17 +00:00
|
|
|
|
|
|
|
if ( timeout > 0 )
|
2011-06-27 18:54:15 +00:00
|
|
|
{
|
2023-03-10 14:02:17 +00:00
|
|
|
timer->start( timeout );
|
2011-06-27 18:54:15 +00:00
|
|
|
}
|
2023-03-10 14:02:17 +00:00
|
|
|
raise();
|
|
|
|
show();
|
2023-03-15 14:58:11 +00:00
|
|
|
move( QPoint( 0, parentWidget()->height() - height() ) );
|
2011-06-27 18:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainStatusBar::mousePressEvent ( QMouseEvent * )
|
|
|
|
{
|
|
|
|
clearMessage();
|
|
|
|
}
|
2011-07-09 17:05:14 +00:00
|
|
|
|
2011-07-14 20:11:57 +00:00
|
|
|
bool MainStatusBar::eventFilter( QObject *, QEvent * e )
|
2011-07-09 17:05:14 +00:00
|
|
|
{
|
|
|
|
switch ( e->type() ) {
|
|
|
|
case QEvent::Resize:
|
2023-03-10 14:02:17 +00:00
|
|
|
move( QPoint( 0, parentWidget()->height() - height() ) );
|
2011-07-09 17:05:14 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2023-03-15 14:58:11 +00:00
|
|
|
}
|
2011-07-09 17:05:14 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|