瀏覽代碼

Listen for the Enter/Leave events of the pixmap label

In order to reopen the closing popup if the mouse gets into the area of
the closing pixmap.
Julien Finet 13 年之前
父節點
當前提交
1a5107e264
共有 1 個文件被更改,包括 13 次插入5 次删除
  1. 13 5
      Libs/Widgets/ctkPopupWidget.cpp

+ 13 - 5
Libs/Widgets/ctkPopupWidget.cpp

@@ -122,6 +122,7 @@ void ctkPopupWidgetPrivate::init()
                    q, SLOT(onEffectFinished()));
 
   this->PopupPixmapWidget = new QLabel(0, Qt::ToolTip | Qt::FramelessWindowHint);
+  this->PopupPixmapWidget->installEventFilter(q);
   this->ScrollAnimation = new QPropertyAnimation(q, "effectGeometry", q);
   this->ScrollAnimation->setDuration(DEFAULT_FADING_DURATION);
   QObject::connect(this->ScrollAnimation, SIGNAL(finished()),
@@ -869,6 +870,8 @@ void ctkPopupWidget::enterEvent(QEvent* event)
 bool ctkPopupWidget::eventFilter(QObject* obj, QEvent* event)
 {
   Q_D(ctkPopupWidget);
+  // Here we listen to PopupPixmapWidget, BaseWidget and ctkPopupWidget
+  // children popups that were under the mouse
   switch(event->type())
     {
     case QEvent::Move:
@@ -890,11 +893,14 @@ bool ctkPopupWidget::eventFilter(QObject* obj, QEvent* event)
     case QEvent::Close:
       // if the mouse was in a base widget child popup, then when we leave
       // the popup we want to check if it needs to be closed.
-      if (obj != d->BaseWidget  &&
-          qobject_cast<QWidget*>(obj)->windowType() == Qt::Popup)
+      if (obj != d->BaseWidget)
         {
-        QTimer::singleShot(LEAVE_CLOSING_DELAY, this, SLOT(updatePopup()));
-        obj->removeEventFilter(this);
+        if (obj != d->PopupPixmapWidget &&
+            qobject_cast<QWidget*>(obj)->windowType() == Qt::Popup)
+          {
+          obj->removeEventFilter(this);
+          QTimer::singleShot(LEAVE_CLOSING_DELAY, this, SLOT(updatePopup()));
+          }
         break;
         }
       d->temporarilyHiddenOn();
@@ -936,13 +942,15 @@ bool ctkPopupWidget::eventFilter(QObject* obj, QEvent* event)
       // Don't listen to base widget children that are popups as what
       // matters here is their close event instead
       if (obj != d->BaseWidget &&
+          obj != d->PopupPixmapWidget &&
           qobject_cast<QWidget*>(obj)->windowType() == Qt::Popup)
         {
         break;
         }
       // The mouse might have left the area that keeps the popup open
       QTimer::singleShot(LEAVE_CLOSING_DELAY, this, SLOT(updatePopup()));
-      if (obj != d->BaseWidget)
+      if (obj != d->BaseWidget &&
+          obj != d->PopupPixmapWidget)
         {
         obj->removeEventFilter(this);
         }