From b48e0dfc854d9ecca4f2c3fdc33b617f6889829b Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Wed, 21 Oct 2009 18:59:01 +0530 Subject: allow enabling disabling of the selection ui --- webview.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'webview.cpp') diff --git a/webview.cpp b/webview.cpp index 4e3783d..2c3eed9 100644 --- a/webview.cpp +++ b/webview.cpp @@ -8,15 +8,24 @@ WebView::WebView(QGraphicsItem * parent) : QGraphicsWebView(parent) + , m_scrapSelectionEnabled(false) , m_scrapRect(QRect()) , m_scrapSelected(false) { setAcceptHoverEvents(true); } +void WebView::setScrapSelectionEnabled(bool enabled) { + m_scrapSelectionEnabled = enabled; +} + +bool WebView::scrapSelectionEnabled() const { + return m_scrapSelectionEnabled; +} + void WebView::hoverMoveEvent(QGraphicsSceneHoverEvent* event) { - if (m_scrapSelected) { + if (!m_scrapSelectionEnabled || m_scrapSelected) { QGraphicsWebView::hoverMoveEvent(event); return; } @@ -50,6 +59,10 @@ void WebView::hoverMoveEvent(QGraphicsSceneHoverEvent* event) void WebView::mousePressEvent(QGraphicsSceneMouseEvent *event) { + if (!m_scrapSelectionEnabled) { + QGraphicsWebView::mousePressEvent(event); + return; + } if (page()->mainFrame()->scrollBarGeometry(Qt::Horizontal).contains(event->pos().toPoint()) || page()->mainFrame()->scrollBarGeometry(Qt::Vertical).contains(event->pos().toPoint())) { QGraphicsWebView::mousePressEvent(event); @@ -68,16 +81,19 @@ void WebView::mousePressEvent(QGraphicsSceneMouseEvent *event) } void WebView::keyPressEvent(QKeyEvent *event) { - if (event->key() == Qt::Key_Escape) { + if (!m_scrapSelectionEnabled && event->key() == Qt::Key_Escape) { m_scrapSelected = false; update(); + return; } + QGraphicsWebView::keyPressEvent(event); } void WebView::paint(QPainter* painter, const QStyleOptionGraphicsItem* options, QWidget* widget) { QGraphicsWebView::paint(painter, options, widget); - + if (!m_scrapSelectionEnabled) + return; QPainterPath pageAreaPath, greyedoutPath; QPainterPath scrollbars; if (page() && page()->mainFrame()) { -- cgit v1.2.3