1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 17:42:10 +01:00
falkonOfficial/src/lib/other/statusbar.cpp

153 lines
4.0 KiB
C++
Raw Normal View History

2011-09-23 22:06:21 +02:00
/* ============================================================
2017-08-25 17:11:29 +02:00
* Falkon - Qt web browser
2018-01-24 19:18:58 +01:00
* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
2011-09-23 22:06:21 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
2018-01-24 19:18:58 +01:00
#include "statusbar.h"
#include "browserwindow.h"
#include "tabwidget.h"
#include "tabbedwebview.h"
2011-05-31 21:11:46 +02:00
#include "squeezelabelv1.h"
#include "mainapplication.h"
#include "webpage.h"
#include "proxystyle.h"
#include "qztools.h"
#include <QStyleOptionFrame>
#include <QStatusBar>
#include <QToolTip>
#include <QStylePainter>
#include <QTimer>
TipLabel::TipLabel(QWidget* parent)
: SqueezeLabelV1(parent)
{
setWindowFlags(Qt::ToolTip);
setForegroundRole(QPalette::ToolTipText);
setBackgroundRole(QPalette::ToolTipBase);
setPalette(QToolTip::palette());
ensurePolished();
setFrameStyle(QFrame::NoFrame);
setMargin(3);
m_timer = new QTimer(this);
m_timer->setSingleShot(true);
m_timer->setInterval(500);
connect(m_timer, SIGNAL(timeout()), this, SLOT(hide()));
}
void TipLabel::show(QWidget* widget)
{
m_timer->stop();
widget->installEventFilter(this);
SqueezeLabelV1::show();
}
void TipLabel::hideDelayed()
{
m_timer->start();
}
void TipLabel::resizeEvent(QResizeEvent* ev)
{
SqueezeLabelV1::resizeEvent(ev);
// Oxygen is setting rounded corners only for top-level tooltips
if (mApp->styleName() == QLatin1String("oxygen")) {
setMask(QzTools::roundedRect(rect(), 4));
}
}
void TipLabel::paintEvent(QPaintEvent* ev)
{
QStylePainter p(this);
QStyleOptionFrame opt;
opt.init(this);
p.drawPrimitive(QStyle::PE_PanelTipLabel, opt);
p.end();
SqueezeLabelV1::paintEvent(ev);
}
bool TipLabel::eventFilter(QObject* o, QEvent* e)
{
Q_UNUSED(o);
switch (e->type()) {
case QEvent::Leave:
case QEvent::WindowDeactivate:
case QEvent::Wheel:
hide();
break;
case QEvent::MouseMove:
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
if (o == this)
hide();
break;
default:
break;
}
return false;
}
2018-01-24 19:18:58 +01:00
StatusBar::StatusBar(BrowserWindow* window)
: m_window(window)
, m_statusBarText(new TipLabel(window))
{
}
2018-01-24 19:18:58 +01:00
void StatusBar::showMessage(const QString &message, int timeout)
{
2018-01-24 19:18:58 +01:00
if (isVisible()) {
const static QChar LRE(0x202a);
2018-01-24 19:18:58 +01:00
QStatusBar::showMessage(message.isRightToLeft() ? message : (LRE + message), timeout);
return;
}
2018-01-24 19:18:58 +01:00
if (mApp->activeWindow() != m_window) {
return;
}
WebView* view = m_window->weView();
2018-01-24 19:18:58 +01:00
const int verticalScrollSize = view->scrollBarGeometry(Qt::Vertical).width();;
const int horizontalScrollSize = view->scrollBarGeometry(Qt::Horizontal).height();
2018-01-24 19:18:58 +01:00
m_statusBarText->setText(message);
m_statusBarText->setMaximumWidth(view->width() - verticalScrollSize);
m_statusBarText->resize(m_statusBarText->sizeHint());
2018-01-24 19:18:58 +01:00
QPoint position(0, view->height() - horizontalScrollSize - m_statusBarText->height());
const QRect statusRect = QRect(view->mapToGlobal(QPoint(0, position.y())), m_statusBarText->size());
2018-01-24 19:18:58 +01:00
if (statusRect.contains(QCursor::pos())) {
position.setY(position.y() - m_statusBarText->height());
}
2018-01-24 19:18:58 +01:00
m_statusBarText->move(view->mapToGlobal(position));
m_statusBarText->show(view);
}
2018-01-24 19:18:58 +01:00
void StatusBar::clearMessage()
{
2018-01-24 19:18:58 +01:00
QStatusBar::clearMessage();
m_statusBarText->hideDelayed();
}