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"
|
2014-02-19 22:07:21 +01:00
|
|
|
#include "browserwindow.h"
|
2012-01-21 23:19:38 +01:00
|
|
|
#include "tabwidget.h"
|
|
|
|
#include "tabbedwebview.h"
|
2011-05-31 21:11:46 +02:00
|
|
|
#include "squeezelabelv1.h"
|
2012-01-28 12:02:37 +01:00
|
|
|
#include "mainapplication.h"
|
2013-04-21 01:24:24 +02:00
|
|
|
#include "webpage.h"
|
|
|
|
#include "proxystyle.h"
|
|
|
|
#include "qztools.h"
|
2011-05-09 17:58:19 +02:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QStyleOptionFrame>
|
|
|
|
#include <QStatusBar>
|
|
|
|
#include <QToolTip>
|
|
|
|
#include <QStylePainter>
|
2012-03-21 13:00:30 +01:00
|
|
|
#include <QTimer>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2012-03-04 14:25:52 +01:00
|
|
|
TipLabel::TipLabel(QWidget* parent)
|
2011-10-24 17:46:45 +02:00
|
|
|
: SqueezeLabelV1(parent)
|
2011-07-19 23:26:34 +02:00
|
|
|
{
|
|
|
|
setWindowFlags(Qt::ToolTip);
|
|
|
|
setForegroundRole(QPalette::ToolTipText);
|
|
|
|
setBackgroundRole(QPalette::ToolTipBase);
|
|
|
|
setPalette(QToolTip::palette());
|
|
|
|
ensurePolished();
|
|
|
|
setFrameStyle(QFrame::NoFrame);
|
2011-10-28 17:52:42 +02:00
|
|
|
setMargin(3);
|
2011-11-04 22:34:45 +01:00
|
|
|
|
2012-03-21 13:00:30 +01:00
|
|
|
m_timer = new QTimer(this);
|
|
|
|
m_timer->setSingleShot(true);
|
|
|
|
m_timer->setInterval(500);
|
|
|
|
connect(m_timer, SIGNAL(timeout()), this, SLOT(hide()));
|
2011-07-19 23:26:34 +02:00
|
|
|
}
|
2011-05-09 17:58:19 +02:00
|
|
|
|
2012-03-26 17:47:05 +02:00
|
|
|
void TipLabel::show(QWidget* widget)
|
2012-03-21 13:00:30 +01:00
|
|
|
{
|
|
|
|
m_timer->stop();
|
|
|
|
|
2012-03-26 17:47:05 +02:00
|
|
|
widget->installEventFilter(this);
|
2012-03-21 13:00:30 +01:00
|
|
|
SqueezeLabelV1::show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TipLabel::hideDelayed()
|
|
|
|
{
|
|
|
|
m_timer->start();
|
|
|
|
}
|
|
|
|
|
2013-04-21 01:24:24 +02:00
|
|
|
void TipLabel::resizeEvent(QResizeEvent* ev)
|
|
|
|
{
|
|
|
|
SqueezeLabelV1::resizeEvent(ev);
|
|
|
|
|
|
|
|
// Oxygen is setting rounded corners only for top-level tooltips
|
2014-03-10 00:47:07 +01:00
|
|
|
if (mApp->styleName() == QLatin1String("oxygen")) {
|
2013-04-21 01:24:24 +02:00
|
|
|
setMask(QzTools::roundedRect(rect(), 4));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-24 17:46:45 +02:00
|
|
|
void TipLabel::paintEvent(QPaintEvent* ev)
|
2011-07-19 23:26:34 +02:00
|
|
|
{
|
|
|
|
QStylePainter p(this);
|
|
|
|
QStyleOptionFrame opt;
|
|
|
|
opt.init(this);
|
|
|
|
p.drawPrimitive(QStyle::PE_PanelTipLabel, opt);
|
|
|
|
p.end();
|
|
|
|
|
|
|
|
SqueezeLabelV1::paintEvent(ev);
|
|
|
|
}
|
|
|
|
|
2011-11-04 22:34:45 +01:00
|
|
|
bool TipLabel::eventFilter(QObject* o, QEvent* e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(o);
|
|
|
|
|
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::Leave:
|
|
|
|
case QEvent::WindowDeactivate:
|
|
|
|
case QEvent::Wheel:
|
|
|
|
hide();
|
|
|
|
break;
|
|
|
|
|
2014-07-08 18:20:02 +02:00
|
|
|
case QEvent::MouseMove:
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
if (o == this)
|
|
|
|
hide();
|
|
|
|
break;
|
|
|
|
|
2011-11-04 22:34:45 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-03-26 17:47:05 +02:00
|
|
|
|
2011-11-04 22:34:45 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-24 19:18:58 +01:00
|
|
|
StatusBar::StatusBar(BrowserWindow* window)
|
2014-02-19 22:07:21 +01:00
|
|
|
: m_window(window)
|
|
|
|
, m_statusBarText(new TipLabel(window))
|
2011-05-09 17:58:19 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-24 19:18:58 +01:00
|
|
|
void StatusBar::showMessage(const QString &message, int timeout)
|
2011-05-09 17:58:19 +02:00
|
|
|
{
|
2018-01-24 19:18:58 +01:00
|
|
|
if (isVisible()) {
|
2015-10-15 09:23:48 +02:00
|
|
|
const static QChar LRE(0x202a);
|
2018-01-24 19:18:58 +01:00
|
|
|
QStatusBar::showMessage(message.isRightToLeft() ? message : (LRE + message), timeout);
|
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2015-05-22 23:30:51 +02:00
|
|
|
|
2018-01-24 19:18:58 +01:00
|
|
|
if (mApp->activeWindow() != m_window) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebView* view = m_window->weView();
|
2016-12-26 20:17:53 +01:00
|
|
|
|
2018-01-24 19:18:58 +01:00
|
|
|
const int verticalScrollSize = view->scrollBarGeometry(Qt::Vertical).width();;
|
|
|
|
const int horizontalScrollSize = view->scrollBarGeometry(Qt::Horizontal).height();
|
2011-10-15 16:37:32 +02:00
|
|
|
|
2018-01-24 19:18:58 +01:00
|
|
|
m_statusBarText->setText(message);
|
|
|
|
m_statusBarText->setMaximumWidth(view->width() - verticalScrollSize);
|
|
|
|
m_statusBarText->resize(m_statusBarText->sizeHint());
|
2011-10-15 16:37:32 +02:00
|
|
|
|
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());
|
2011-10-15 16:37:32 +02:00
|
|
|
|
2018-01-24 19:18:58 +01:00
|
|
|
if (statusRect.contains(QCursor::pos())) {
|
|
|
|
position.setY(position.y() - m_statusBarText->height());
|
2011-05-09 17:58:19 +02:00
|
|
|
}
|
2018-01-24 19:18:58 +01:00
|
|
|
|
|
|
|
m_statusBarText->move(view->mapToGlobal(position));
|
|
|
|
m_statusBarText->show(view);
|
2011-05-09 17:58:19 +02:00
|
|
|
}
|
|
|
|
|
2018-01-24 19:18:58 +01:00
|
|
|
void StatusBar::clearMessage()
|
2011-05-09 17:58:19 +02:00
|
|
|
{
|
2018-01-24 19:18:58 +01:00
|
|
|
QStatusBar::clearMessage();
|
|
|
|
m_statusBarText->hideDelayed();
|
2011-05-09 17:58:19 +02:00
|
|
|
}
|