From a8881c1d73ad0fa447ca74ecb18cc7409b9eb90b Mon Sep 17 00:00:00 2001 From: nowrep Date: Tue, 19 Jul 2011 23:26:34 +0200 Subject: [PATCH] Address of hovered link won't stuck at screen when changing to other window anymore. --- src/other/statusbarmessage.cpp | 68 ++++++++++++++++++++++------------ src/other/statusbarmessage.h | 19 ++++++++++ 2 files changed, 64 insertions(+), 23 deletions(-) diff --git a/src/other/statusbarmessage.cpp b/src/other/statusbarmessage.cpp index 76ec29c03..932ad4e84 100644 --- a/src/other/statusbarmessage.cpp +++ b/src/other/statusbarmessage.cpp @@ -2,38 +2,60 @@ #include "qupzilla.h" #include "squeezelabelv1.h" +TipLabel::TipLabel(QupZilla* parent) : SqueezeLabelV1(parent) , p_QupZilla(parent) +{ + m_timer = new QTimer(); + m_timer->setInterval(300); + connect(m_timer, SIGNAL(timeout()), this, SLOT(checkMainWindowFocus())); -class TipLabel : public SqueezeLabelV1 { -public: - TipLabel() - { - setWindowFlags(Qt::ToolTip); - setForegroundRole(QPalette::ToolTipText); - setBackgroundRole(QPalette::ToolTipBase); - setPalette(QToolTip::palette()); - ensurePolished(); - setFrameStyle(QFrame::NoFrame); - setMargin(2); - } + setWindowFlags(Qt::ToolTip); + setForegroundRole(QPalette::ToolTipText); + setBackgroundRole(QPalette::ToolTipBase); + setPalette(QToolTip::palette()); + ensurePolished(); + setFrameStyle(QFrame::NoFrame); + setMargin(2); +} - void paintEvent(QPaintEvent *ev) - { - QStylePainter p(this); - QStyleOptionFrame opt; - opt.init(this); - p.drawPrimitive(QStyle::PE_PanelTipLabel, opt); - p.end(); +void TipLabel::paintEvent(QPaintEvent *ev) +{ + QStylePainter p(this); + QStyleOptionFrame opt; + opt.init(this); + p.drawPrimitive(QStyle::PE_PanelTipLabel, opt); + p.end(); + + SqueezeLabelV1::paintEvent(ev); +} + +void TipLabel::show() +{ + if (!p_QupZilla->weView()->hasFocus()) + return; + + m_timer->start(); + SqueezeLabelV1::show(); +} + +void TipLabel::hide() +{ + m_timer->stop(); + SqueezeLabelV1::hide(); +} + +void TipLabel::checkMainWindowFocus() +{ + if (!p_QupZilla->weView()->hasFocus()) + hide(); +} - SqueezeLabelV1::paintEvent(ev); - } -}; StatusBarMessage::StatusBarMessage(QupZilla* mainClass) : QObject() , p_QupZilla(mainClass) { - m_statusBarText = new TipLabel(); + m_statusBarText = new TipLabel(mainClass); } #define STATUS_Y_OFFSET -35 diff --git a/src/other/statusbarmessage.h b/src/other/statusbarmessage.h index 9b273464f..f9dfd0795 100644 --- a/src/other/statusbarmessage.h +++ b/src/other/statusbarmessage.h @@ -3,9 +3,28 @@ #include #include +#include "squeezelabelv1.h" class QupZilla; class TipLabel; + +class TipLabel : public SqueezeLabelV1 { + Q_OBJECT + +public: + TipLabel(QupZilla* parent); + void paintEvent(QPaintEvent *ev); + void show(); + void hide(); + +private slots: + void checkMainWindowFocus(); + +private: + QTimer* m_timer; + QupZilla* p_QupZilla; +}; + class StatusBarMessage : public QObject { Q_OBJECT