All pastes #773400 Raw Edit

Stuff

public text v1 · immutable
·published 2007-11-14 14:45 UTC
rendered paste body
Index: widgets/pushbutton.cpp
===================================================================
--- widgets/pushbutton.cpp      (revision 736643)
+++ widgets/pushbutton.cpp      (working copy)
@@ -26,6 +26,7 @@
 #include <QStyle>
 #include <QWidget>
 #include <QPainter>
+#include <QGraphicsScene>
 #include <QGraphicsSceneMouseEvent>
 #include <QFontMetricsF>
 #include <QApplication>
@@ -250,22 +251,36 @@
     update();
 }

+void PushButton::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+{
+    event->accept();
+    if (sceneBoundingRect().contains(event->scenePos())) {
+        if (d->state == Private::Released && scene()->mouseGrabberItem() == this) {
+            d->state = Private::Pressed;
+            update();
+        }
+    } else {
+        if (d->state == Private::Pressed) {
+            d->state = Private::Released;
+            update();
+        }
+    }
+}
+
 void PushButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
 {
     event->accept();
     if (d->state == Private::Pressed) {
         d->state = Private::Released;

-        if (sceneBoundingRect().contains(event->scenePos())) {
-            emit clicked();
+        emit clicked();

-            if (d->checkable) {
-                d->checked = ! d->checked;
-                emit toggled(d->checked);
-            }
+        if (d->checkable) {
+            d->checked = ! d->checked;
+            emit toggled(d->checked);
         }
+        update();
     }
-    update();
 }

 QSizeF PushButton::minimumSize() const
Index: widgets/pushbutton.h
===================================================================
--- widgets/pushbutton.h        (revision 736643)
+++ widgets/pushbutton.h        (working copy)
@@ -178,6 +178,7 @@

 protected:
     void mousePressEvent(QGraphicsSceneMouseEvent *event);
+    void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
     void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);

     void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);