summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@forwardbias.in>2009-10-21 18:59:01 +0530
committerRoopesh Chander <roop@forwardbias.in>2009-10-21 18:59:01 +0530
commitb48e0dfc854d9ecca4f2c3fdc33b617f6889829b (patch)
tree91aa241b0db095af601751859d60d7f60a5a0f42
parentf12646679f58dc9d59c5180f0c8d64b862506df9 (diff)
allow enabling disabling of the selection ui
-rw-r--r--webview.cpp22
-rw-r--r--webview.h3
2 files changed, 22 insertions, 3 deletions
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()) {
diff --git a/webview.h b/webview.h
index 29746f4..6928a9a 100644
--- a/webview.h
+++ b/webview.h
@@ -11,6 +11,8 @@ class WebView : public QGraphicsWebView
{
public:
WebView(QGraphicsItem * parent = 0);
+ void setScrapSelectionEnabled(bool enabled);
+ bool scrapSelectionEnabled() const;
protected:
void hoverMoveEvent(QGraphicsSceneHoverEvent* event);
@@ -19,6 +21,7 @@ protected:
void paint(QPainter* painter, const QStyleOptionGraphicsItem* options, QWidget* widget = 0);
private:
+ bool m_scrapSelectionEnabled;
QRect m_scrapRect;
bool m_scrapSelected;
};