2011-06-27 18:54:15 +00:00
|
|
|
/* This file is (c) 2011 Tvangeste <i.4m.l33t@yandex.ru>
|
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#include "mainstatusbar.hh"
|
|
|
|
|
|
|
|
#include <Qt>
|
|
|
|
#include <QFrame>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QEvent>
|
|
|
|
|
|
|
|
MainStatusBar::MainStatusBar(QWidget *parent) : QFrame(parent)
|
|
|
|
{
|
|
|
|
// style
|
|
|
|
setWindowFlags( Qt::Tool | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint );
|
|
|
|
setFrameStyle( QFrame::Box | QFrame::Plain );
|
|
|
|
setLineWidth(0);
|
|
|
|
|
|
|
|
// components
|
|
|
|
label = new QLabel(QString(), this);
|
|
|
|
label->setTextFormat(Qt::PlainText);
|
|
|
|
timer = new QTimer(this);
|
|
|
|
|
|
|
|
// layout
|
|
|
|
QVBoxLayout * layout = new QVBoxLayout;
|
|
|
|
layout->addWidget(label);
|
|
|
|
layout->setSizeConstraint(QLayout::SetFixedSize);
|
|
|
|
layout->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
|
|
|
layout->setMargin(4);
|
|
|
|
setLayout(layout);
|
|
|
|
|
|
|
|
parentWidget()->installEventFilter( this );
|
|
|
|
|
|
|
|
connect( timer, SIGNAL( timeout() ), SLOT( clearMessage() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainStatusBar::clearMessage()
|
|
|
|
{
|
|
|
|
message = QString();
|
|
|
|
label->setText(message);
|
|
|
|
timer->stop();
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MainStatusBar::currentMessage() const
|
|
|
|
{
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainStatusBar::showMessage(const QString & str, int timeout)
|
|
|
|
{
|
|
|
|
message = str;
|
|
|
|
|
|
|
|
if ( timeout > 0 )
|
|
|
|
{
|
|
|
|
timer->start( timeout );
|
|
|
|
}
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2011-06-30 13:13:23 +00:00
|
|
|
void MainStatusBar::refresh(bool forceHide)
|
2011-06-27 18:54:15 +00:00
|
|
|
{
|
|
|
|
|
2011-06-30 13:13:23 +00:00
|
|
|
if ( forceHide )
|
|
|
|
{
|
|
|
|
hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-27 18:54:15 +00:00
|
|
|
if ( !message.isEmpty() )
|
|
|
|
{
|
|
|
|
|
2011-06-30 14:34:56 +00:00
|
|
|
int maxLabelLength = parentWidget()->width() - 2 * layout()->margin();
|
2011-06-27 18:54:15 +00:00
|
|
|
label->setText( label->fontMetrics().elidedText( message, Qt::ElideRight, maxLabelLength ) );
|
|
|
|
|
|
|
|
adjustSize();
|
|
|
|
|
2011-06-30 14:34:56 +00:00
|
|
|
// move(pGeom.left(), pGeom.bottom() - size().height() + 1 );
|
|
|
|
|
|
|
|
move(parentWidget()->mapToGlobal(QPoint(0, parentWidget()->height() - height() + 1)));
|
2011-06-30 13:13:23 +00:00
|
|
|
|
|
|
|
if ( parentWidget()->isHidden() )
|
|
|
|
{
|
|
|
|
hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( parentWidget()->isMinimized() )
|
|
|
|
{
|
|
|
|
hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-27 18:54:15 +00:00
|
|
|
show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainStatusBar::mousePressEvent ( QMouseEvent * )
|
|
|
|
{
|
|
|
|
clearMessage();
|
|
|
|
}
|
|
|
|
|
2011-06-30 13:13:23 +00:00
|
|
|
bool MainStatusBar::eventFilter(QObject *, QEvent * e)
|
2011-06-27 18:54:15 +00:00
|
|
|
{
|
2011-06-30 13:13:23 +00:00
|
|
|
switch ( e->type() ) {
|
|
|
|
case QEvent::Hide:
|
2011-06-27 18:54:15 +00:00
|
|
|
case QEvent::WindowDeactivate:
|
2011-06-30 13:13:23 +00:00
|
|
|
#ifdef Q_WS_X11
|
|
|
|
// workaround for X11 idiosyncrasies
|
|
|
|
// qDebug() << e->type();
|
|
|
|
refresh(true);
|
|
|
|
break;
|
|
|
|
#endif
|
2011-06-30 14:34:56 +00:00
|
|
|
case QEvent::Resize:
|
|
|
|
case QEvent::FocusOut:
|
2011-06-30 13:13:23 +00:00
|
|
|
case QEvent::Move:
|
|
|
|
case QEvent::WindowStateChange:
|
2011-06-27 18:54:15 +00:00
|
|
|
case QEvent::WindowActivate:
|
2011-06-30 13:13:23 +00:00
|
|
|
// qDebug() << e->type();
|
2011-06-27 18:54:15 +00:00
|
|
|
refresh();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|