From 717a0a9d043bb5052930fa990865850e96a99eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Mon, 10 Dec 2012 08:16:31 +0100 Subject: QGraphicsView - emit signal when rubber band changes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The rubberBandRect function is nice to have, but this patch makes it easier to track the rubber band by emiting a signal on change. That makes it easier (and less clumsy/hacky) to show information related to the rubber band. Change-Id: If65eb85d743a1804be3fdb823a821423411e9745 Reviewed-by: Andreas Aardal Hanssen Reviewed-by: Samuel Rødal --- .../qgraphicsview/rubberband/rubberbandtest.cpp | 27 ++++++++-------------- 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'tests/manual/widgets/qgraphicsview/rubberband/rubberbandtest.cpp') diff --git a/tests/manual/widgets/qgraphicsview/rubberband/rubberbandtest.cpp b/tests/manual/widgets/qgraphicsview/rubberband/rubberbandtest.cpp index 85881ca67a..f6077e3044 100644 --- a/tests/manual/widgets/qgraphicsview/rubberband/rubberbandtest.cpp +++ b/tests/manual/widgets/qgraphicsview/rubberband/rubberbandtest.cpp @@ -60,11 +60,12 @@ public: class MyGraphicsView : public QGraphicsView { - + Q_OBJECT public: MyGraphicsView(QWidget *w, QLabel *l) : QGraphicsView(w), rubberbandLabel(l) { setDragMode(QGraphicsView::RubberBandDrag); + connect(this, SIGNAL(rubberBandChanged(QRect, QPointF, QPointF)), this, SLOT(updateRubberbandInfo(QRect, QPointF, QPointF))); } protected: void mouseMoveEvent(QMouseEvent *event) @@ -80,29 +81,17 @@ protected: int yglobal = event->globalY(); if (yglobal > bottomPos) verticalScrollBar()->setValue(verticalScrollBar()->value() + 10); - updateRubberbandInfo(); } - void mouseReleaseEvent(QMouseEvent *event) - { - QGraphicsView::mouseReleaseEvent(event); - updateRubberbandInfo(); - } - - void wheelEvent (QWheelEvent *event) - { - QGraphicsView::wheelEvent(event); - updateRubberbandInfo(); - } - - void updateRubberbandInfo() +protected slots: + void updateRubberbandInfo(QRect r, QPointF from, QPointF to) { QString textToShow; QDebug s(&textToShow); - s << rubberBandRect(); - if (rubberbandLabel->text() != textToShow) - rubberbandLabel->setText(textToShow); + s << r << from << to; + rubberbandLabel->setText(textToShow); } +protected: QLabel *rubberbandLabel; }; @@ -135,3 +124,5 @@ int main(int argc, char *argv[]) app.exec(); return 0; } + +#include "rubberbandtest.moc" -- cgit v1.2.3