diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2012-08-03 15:52:32 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2012-12-10 02:48:04 +0100 |
commit | f6b940c5c4d76db3155bd99a2e23c6009e17309d (patch) | |
tree | 11bfd7b90851f79d15ba45458fbff053a17fa6f0 /src | |
parent | Implementing the webwindow as special widget (diff) | |
download | rekonq-f6b940c5c4d76db3155bd99a2e23c6009e17309d.tar.xz |
link hovered messages restored :)
Diffstat (limited to 'src')
-rw-r--r-- | src/webwindow/webwindow.cpp | 76 | ||||
-rw-r--r-- | src/webwindow/webwindow.h | 10 |
2 files changed, 86 insertions, 0 deletions
diff --git a/src/webwindow/webwindow.cpp b/src/webwindow/webwindow.cpp index 8a87ca90..60e7970b 100644 --- a/src/webwindow/webwindow.cpp +++ b/src/webwindow/webwindow.cpp @@ -42,6 +42,11 @@ #include <KUrl> #include <KToolBar> +#include <QLabel> +#include <QStyle> +#include <QTextDocument> +#include <QTimer> +#include <QWebFrame> #include <QWebView> #include <QWebHistory> #include <QVBoxLayout> @@ -56,6 +61,8 @@ WebWindow::WebWindow(QWidget *parent) , _bookmarksBar(0) , m_loadStopReloadAction(0) , m_rekonqMenu(0) + , m_popup(new QLabel(this)) + , m_hidePopupTimer(new QTimer(this)) , _ac(new KActionCollection(this)) { init(); @@ -70,6 +77,8 @@ WebWindow::WebWindow(WebPage *page, QWidget *parent) , _bookmarksBar(0) , m_loadStopReloadAction(0) , m_rekonqMenu(0) + , m_popup(new QLabel(this)) + , m_hidePopupTimer(new QTimer(this)) , _ac(new KActionCollection(this)) { _tab->view()->setPage(page); @@ -124,6 +133,14 @@ void WebWindow::init() // page signals connect(page(), SIGNAL(pageCreated(WebPage *)), this, SIGNAL(pageCreated(WebPage *))); + + // message popup + m_popup->setAutoFillBackground(true); + m_popup->setMargin(4); + m_popup->raise(); + m_popup->hide(); + connect(m_hidePopupTimer, SIGNAL(timeout()), m_popup, SLOT(hide())); + connect(_tab->page(), SIGNAL(linkHovered(QString,QString,QString)), this, SLOT(notifyMessage(QString))); } void WebWindow::setupActions() @@ -162,6 +179,8 @@ void WebWindow::setupActions() m_loadStopReloadAction->setIcon(KIcon("go-jump-locationbar")); m_loadStopReloadAction->setToolTip(i18n("Go")); m_loadStopReloadAction->setText(i18n("Go")); + + updateHistoryActions(); } @@ -398,6 +417,63 @@ void WebWindow::updateHistoryActions() } +void WebWindow::notifyMessage(const QString &msg) +{ + // deleting popus if empty msgs + if (msg.isEmpty()) + { + m_hidePopupTimer->start(250); + return; + } + + m_hidePopupTimer->stop(); + m_hidePopupTimer->start(3000); + + QString msgToShow = Qt::escape(msg); + + // fix crash on window close + if (!_tab || !_tab->page()) + return; + + const int margin = 4; + const int halfWidth = width() / 2; + + // Set Popup size + QFontMetrics fm = m_popup->fontMetrics(); + QSize labelSize(fm.width(msgToShow) + 2 * margin, fm.height() + 2 * margin); + + if (labelSize.width() > halfWidth) + labelSize.setWidth(halfWidth); + + m_popup->setFixedSize(labelSize); + m_popup->setText(fm.elidedText(msgToShow, Qt::ElideMiddle, labelSize.width() - 2 * margin)); + + // NOTE: while currentFrame should NEVER be null + // we are checking here its existence cause of bug:264187 + if (!_tab->page()->currentFrame()) + return; + + const bool horizontalScrollbarIsVisible = _tab->page()->currentFrame()->scrollBarMaximum(Qt::Horizontal); + const bool verticalScrollbarIsVisible = _tab->page()->currentFrame()->scrollBarMaximum(Qt::Vertical); + const bool actionBarsVisible = false; //m_findBar->isVisible() || m_zoomBar->isVisible(); + + const int scrollbarExtent = style()->pixelMetric(QStyle::PM_ScrollBarExtent); + const int hScrollbarSize = horizontalScrollbarIsVisible ? scrollbarExtent : 0; + const int vScrollbarSize = verticalScrollbarIsVisible ? scrollbarExtent : 0; + + const QPoint mousePos = mapFromGlobal(QCursor::pos()); + const QPoint bottomPoint = mapTo(this, geometry().bottomLeft()); + + int y = bottomPoint.y() + 1 - m_popup->height() - hScrollbarSize; // +1 because bottom() returns top() + height() - 1, see QRect doku + int x = QRect(QPoint(0, y), labelSize).contains(mousePos) || actionBarsVisible + ? width() - labelSize.width() - vScrollbarSize + : 0; + + m_popup->move(x, y); + m_popup->show(); +} + + KUrl WebWindow::url() const { return _tab->url(); diff --git a/src/webwindow/webwindow.h b/src/webwindow/webwindow.h index c727ecf0..695c7393 100644 --- a/src/webwindow/webwindow.h +++ b/src/webwindow/webwindow.h @@ -50,7 +50,9 @@ class RekonqMenu; class KMenu; class KToolBar; +class QLabel; class QPixmap; +class QTimer; class QUrl; @@ -100,6 +102,11 @@ private Q_SLOTS: void openNext(Qt::MouseButtons = Qt::LeftButton, Qt::KeyboardModifiers = Qt::NoModifier); void updateHistoryActions(); + /** + * Notifies a message in a popup + */ + void notifyMessage(const QString &msg); + Q_SIGNALS: void titleChanged(QString); @@ -125,6 +132,9 @@ private: RekonqMenu *m_rekonqMenu; + QLabel *m_popup; + QTimer *m_hidePopupTimer; + KActionCollection *_ac; }; |