[Kst] extragear/graphics/kst/kst

George Staikos staikos at kde.org
Wed Nov 23 22:32:09 CET 2005


SVN commit 482717 by staikos:

- use a guarded ptr for the menu
- bail out on clicks when the menu is visible
- slight refactor of click handling


 M  +16 -13    kstviewwidget.cpp  
 M  +4 -2      kstviewwidget.h  


--- trunk/extragear/graphics/kst/kst/kstviewwidget.cpp #482716:482717
@@ -28,7 +28,7 @@
 #include "plotmimesource.h"
 
 KstViewWidget::KstViewWidget(KstTopLevelViewPtr view, QWidget *parent, const char *name, WFlags w)
-: QWidget(parent, name, WStyle_Customize | WRepaintNoErase | w), _view(view), _menu(0L) {
+: QWidget(parent, name, WStyle_Customize | WRepaintNoErase | w), _view(view) {
   _nextUpdate = P_PAINT;
   setDragEnabled(true);
   setDropEnabled(true);
@@ -105,7 +105,6 @@
 
 
 void KstViewWidget::leaveEvent(QEvent *e) {
-
   //kstdDebug() << "Leave event" << endl;
   QWidget::leaveEvent(e);
   if (_view->viewMode() != KstTopLevelView::DisplayMode) {
@@ -192,8 +191,13 @@
 
 
 void KstViewWidget::mousePressEvent(QMouseEvent *e) {
-  kstdDebug() << "Press event. button=" << e->button() << " state=" << e->state() << endl;
+  //kstdDebug() << "Press event. button=" << e->button() << " state=" << e->state() << endl;
 
+  if (_menu) {
+    QWidget::mousePressEvent(e);
+    return;
+  }
+
   if (_view->viewMode() == KstTopLevelView::DisplayMode) {
     KstViewObjectPtr vo;
     if (_view->mouseGrabbed()) {
@@ -202,7 +206,7 @@
       vo = findChildFor(e->pos());
     }
     if (vo) {
-      kstdDebug() << "Found mouse handler " << vo->tagName() << endl;
+      //kstdDebug() << "Found mouse handler " << vo->tagName() << endl;
       vo->mousePressEvent(this, e);
     }
     return;
@@ -210,19 +214,18 @@
 
   // Layout/graphics mode
   if (e->button() & Qt::LeftButton) {
-    kstdDebug() << "    -> left button" << endl;
+    //kstdDebug() << "    -> left button" << endl;
     if (_view->handlePress(e->pos(), e->state() & Qt::ShiftButton)) {
-      kstdDebug() << "   -> Accepting" << endl;
+      //kstdDebug() << "   -> Accepting" << endl;
       e->accept();
       return;
+    } else if (_view->tracking()) {
+      //kstdDebug() << "   -> Swallowing" << endl;
+      e->accept(); // swallow
+      return;
     }
   }
-  if (e->state() & Qt::LeftButton && _view->tracking()) {
-    kstdDebug() << "   -> Swallowing" << endl;
-    e->accept(); // swallow
-    return;
-  }
-  kstdDebug() << "   -> Passing up" << endl;
+  //kstdDebug() << "   -> Passing up" << endl;
   QWidget::mousePressEvent(e);
 }
 
@@ -316,6 +319,7 @@
   if (_view->mouseGrabber()) {
     _view->releaseMouse(_view->mouseGrabber());
   }
+  assert(!_menu);
   _menu = new KPopupMenu(this);
   //kstdDebug() << "Querying for the popup" << endl;
   bool rc = _view->popupMenu(_menu, e->pos());
@@ -332,7 +336,6 @@
   } else {
     delete _menu;
   }
-  _menu = 0L;
   e->accept();
 }
 
--- trunk/extragear/graphics/kst/kst/kstviewwidget.h #482716:482717
@@ -18,11 +18,13 @@
 #ifndef KSTVIEWWIDGET_H
 #define KSTVIEWWIDGET_H
 
+#include <qguardedptr.h>
 #include <qwidget.h>
+
+#include <kpopupmenu.h>
 #include "ksttoplevelview.h"
 
 class QDragObject;
-class KPopupMenu;
 
 class KstViewWidget : public QWidget {
   Q_OBJECT
@@ -70,7 +72,7 @@
     KstViewObject *_vo_datamode;
     bool _dropEnabled : 1;
     bool _dragEnabled : 1;
-    KPopupMenu *_menu;
+    QGuardedPtr<KPopupMenu> _menu;
     QDragObject *_drag;
     KstPaintType _nextUpdate;
 };


More information about the Kst mailing list