From 38b5dc5fbdae25491435395202f6980f44ca8ef5 Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Wed, 12 Mar 2014 18:36:24 +0100 Subject: Tooltip support. Basic tooltip support for widgets relying on the existing QToolTip mechanism. Left unimplemented on the Qt Quick side for now since ToolTip support is still very much a work in progress there. Change-Id: Ia4bfd715a224e0cbc147c8860e131d1545cebe1e Reviewed-by: Jocelyn Turcotte --- src/webenginewidgets/api/qwebengineview.cpp | 7 +++++-- src/webenginewidgets/render_widget_host_view_qt_delegate_popup.cpp | 6 ++++++ src/webenginewidgets/render_widget_host_view_qt_delegate_popup.h | 1 + .../render_widget_host_view_qt_delegate_webpage.cpp | 6 ++++++ src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.h | 1 + 5 files changed, 19 insertions(+), 2 deletions(-) (limited to 'src/webenginewidgets') diff --git a/src/webenginewidgets/api/qwebengineview.cpp b/src/webenginewidgets/api/qwebengineview.cpp index a29349052..3f3fdd7cd 100644 --- a/src/webenginewidgets/api/qwebengineview.cpp +++ b/src/webenginewidgets/api/qwebengineview.cpp @@ -228,8 +228,11 @@ bool QWebEngineView::event(QEvent *ev) if (ev->type() == QEvent::ContextMenu) { ev->accept(); return true; - } else if (ev->type() == QEvent::MetaCall) - // Meta calls are not safe to forward to the page, as they could be widget specific (e.g. QWidgetPrivate::_q_showIfNotHidden) + + // Meta calls are not safe to forward to the page, as they could be widget specific (e.g. QWidgetPrivate::_q_showIfNotHidden) + // ToolTip events need to be processed at the widget level for the tooltip to show. + } else if (ev->type() == QEvent::MetaCall + || ev->type() == QEvent::ToolTip) return QWidget::event(ev); if (d->page && d->page->event(ev)) return true; diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_popup.cpp b/src/webenginewidgets/render_widget_host_view_qt_delegate_popup.cpp index 7900ed9b5..eae3b8a6d 100644 --- a/src/webenginewidgets/render_widget_host_view_qt_delegate_popup.cpp +++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_popup.cpp @@ -62,6 +62,7 @@ RenderWidgetHostViewQtDelegatePopup::RenderWidgetHostViewQtDelegatePopup(RenderW // loses focus, WebKit will cause its associated popups (including this one) // to be destroyed. setAttribute(Qt::WA_ShowWithoutActivating); + setAttribute(Qt::WA_AlwaysShowToolTips); setFocusPolicy(Qt::NoFocus); setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus); } @@ -137,6 +138,11 @@ void RenderWidgetHostViewQtDelegatePopup::move(const QPoint &pos) QWidget::move(mapped); } +void RenderWidgetHostViewQtDelegatePopup::setTooltip(const QString &tooltip) +{ + setToolTip(tooltip); +} + void RenderWidgetHostViewQtDelegatePopup::paintEvent(QPaintEvent *event) { QPainter painter(this); diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_popup.h b/src/webenginewidgets/render_widget_host_view_qt_delegate_popup.h index 330afc25e..5f3e6595c 100644 --- a/src/webenginewidgets/render_widget_host_view_qt_delegate_popup.h +++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_popup.h @@ -74,6 +74,7 @@ public: virtual void move(const QPoint &) Q_DECL_OVERRIDE; virtual void inputMethodStateChanged(bool) Q_DECL_OVERRIDE {} virtual bool supportsHardwareAcceleration() const Q_DECL_OVERRIDE { return false; } + virtual void setTooltip(const QString &tooltip) Q_DECL_OVERRIDE; protected: void paintEvent(QPaintEvent * event); diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.cpp b/src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.cpp index d6e99f4ea..e8a3e7d44 100644 --- a/src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.cpp +++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.cpp @@ -139,6 +139,12 @@ bool RenderWidgetHostViewQtDelegateWebPage::supportsHardwareAcceleration() const return false; } +void RenderWidgetHostViewQtDelegateWebPage::setTooltip(const QString &tooltip) +{ + if (m_page && m_page->view()) + m_page->view()->setToolTip(tooltip); +} + void RenderWidgetHostViewQtDelegateWebPage::paint(QPainter *painter, const QRectF &boundingRect) { m_client->fetchBackingStore(); diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.h b/src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.h index 52988aefa..80da9d727 100644 --- a/src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.h +++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.h @@ -75,6 +75,7 @@ public: virtual void move(const QPoint&) Q_DECL_OVERRIDE {} virtual void inputMethodStateChanged(bool editorVisible) Q_DECL_OVERRIDE; virtual bool supportsHardwareAcceleration() const Q_DECL_OVERRIDE; + virtual void setTooltip(const QString &tooltip) Q_DECL_OVERRIDE; void paint(QPainter *painter, const QRectF &boundingRect); void notifyResize(); -- cgit v1.2.3