2011-09-23 22:06:21 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2011-10-17 09:59:09 +02:00
|
|
|
* Copyright (C) 2010-2011 David Rosca
|
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/>.
|
|
|
|
* ============================================================ */
|
2011-05-09 17:58:19 +02:00
|
|
|
#include "statusbarmessage.h"
|
|
|
|
#include "qupzilla.h"
|
2011-05-31 21:11:46 +02:00
|
|
|
#include "squeezelabelv1.h"
|
2011-05-09 17:58:19 +02:00
|
|
|
|
2011-10-24 17:46:45 +02:00
|
|
|
TipLabel::TipLabel(QupZilla* parent)
|
|
|
|
: SqueezeLabelV1(parent)
|
|
|
|
, p_QupZilla(parent)
|
|
|
|
, m_connected(false)
|
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
|
|
|
|
|
|
|
qApp->installEventFilter(this);
|
2011-07-19 23:26:34 +02:00
|
|
|
}
|
2011-05-09 17:58:19 +02:00
|
|
|
|
2011-10-24 17:46:45 +02:00
|
|
|
void TipLabel::show()
|
|
|
|
{
|
|
|
|
if (!m_connected) {
|
|
|
|
connect(p_QupZilla->tabWidget(), SIGNAL(currentChanged(int)), this, SLOT(hide()));
|
|
|
|
m_connected = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
SqueezeLabelV1::show();
|
|
|
|
}
|
|
|
|
|
|
|
|
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::WindowActivate:
|
|
|
|
case QEvent::WindowDeactivate:
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
case QEvent::MouseButtonDblClick:
|
|
|
|
case QEvent::FocusIn:
|
|
|
|
case QEvent::FocusOut:
|
|
|
|
case QEvent::Wheel:
|
|
|
|
hide();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-09 17:58:19 +02:00
|
|
|
StatusBarMessage::StatusBarMessage(QupZilla* mainClass)
|
2011-10-15 16:37:32 +02:00
|
|
|
: QObject(mainClass)
|
2011-05-09 17:58:19 +02:00
|
|
|
, p_QupZilla(mainClass)
|
2011-10-15 16:37:32 +02:00
|
|
|
, m_statusBarText(new TipLabel(mainClass))
|
2011-05-09 17:58:19 +02:00
|
|
|
{
|
2011-11-05 10:22:24 +01:00
|
|
|
m_statusBarText->setParent(p_QupZilla);
|
2011-05-09 17:58:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void StatusBarMessage::showMessage(const QString &message)
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (p_QupZilla->statusBar()->isVisible()) {
|
2011-05-09 17:58:19 +02:00
|
|
|
p_QupZilla->statusBar()->showMessage(message);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-15 16:37:32 +02:00
|
|
|
else {
|
|
|
|
WebView* view = p_QupZilla->weView();
|
|
|
|
QWebFrame* mainFrame = view->page()->mainFrame();
|
|
|
|
|
|
|
|
int horizontalScrollSize = 0;
|
|
|
|
int verticalScrollSize = 0;
|
|
|
|
const int scrollbarSize = p_QupZilla->style()->pixelMetric(QStyle::PM_ScrollBarExtent);
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (mainFrame->scrollBarMaximum(Qt::Horizontal)) {
|
2011-10-15 16:37:32 +02:00
|
|
|
horizontalScrollSize = scrollbarSize;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
if (mainFrame->scrollBarMaximum(Qt::Vertical)) {
|
2011-10-15 16:37:32 +02:00
|
|
|
verticalScrollSize = scrollbarSize;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-15 16:37:32 +02:00
|
|
|
|
2011-05-09 17:58:19 +02:00
|
|
|
m_statusBarText->setText(message);
|
|
|
|
m_statusBarText->resize(m_statusBarText->sizeHint());
|
2011-10-15 16:37:32 +02:00
|
|
|
m_statusBarText->setMaximumWidth(view->width() - verticalScrollSize);
|
|
|
|
|
|
|
|
QPoint position;
|
|
|
|
position.setY(view->height() - horizontalScrollSize - m_statusBarText->height());
|
|
|
|
|
|
|
|
QRect statusRect = QRect(view->mapToGlobal(QPoint(0, position.y())), m_statusBarText->size());
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (statusRect.contains(QCursor::pos())) {
|
2011-10-15 16:37:32 +02:00
|
|
|
position.setY(position.y() - m_statusBarText->height());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-15 16:37:32 +02:00
|
|
|
|
2011-10-27 14:26:40 +02:00
|
|
|
m_statusBarText->move(view->mapToGlobal(position));
|
2011-05-09 17:58:19 +02:00
|
|
|
m_statusBarText->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StatusBarMessage::clearMessage()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (p_QupZilla->statusBar()->isVisible()) {
|
2011-05-09 17:58:19 +02:00
|
|
|
p_QupZilla->statusBar()->showMessage("");
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-05-09 17:58:19 +02:00
|
|
|
m_statusBarText->hide();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-05-09 17:58:19 +02:00
|
|
|
}
|