Browse Source

Replace Qt::ToolTip popup window flag with Qt::Tool

Closes #417
Julien Finet 11 years ago
parent
commit
b1af3f79be

+ 4 - 3
Libs/Widgets/ctkBasePopupWidget.cpp

@@ -107,6 +107,7 @@ void ctkBasePopupWidgetPrivate::init()
   // case, we sometimes aren't the active window but we still would like to
   // show the children tooltips.
   q->setAttribute(Qt::WA_AlwaysShowToolTips, true);
+  //q->setAttribute(Qt::WA_MacAlwaysShowToolWindow, true);
 
   this->AlphaAnimation = new QPropertyAnimation(q, "effectAlpha", q);
   this->AlphaAnimation->setDuration(this->EffectDuration);
@@ -429,7 +430,7 @@ void ctkBasePopupWidgetPrivate::hideAll()
   // It is possible to have the popup widget not being a popup but inside
   // a layout: maybe the popup has been pin-down in a way that it gets parented
   // In that case, there is no reason to hide the popup.
-  if (!(q->windowFlags() & Qt::ToolTip))
+  if (!(q->windowFlags() & PopupWindowType))
     {
     return;
     }
@@ -461,7 +462,7 @@ void ctkBasePopupWidgetPrivate::hideAll()
 ctkBasePopupWidget::ctkBasePopupWidget(QWidget* parentWidget)
   //: Superclass(QApplication::desktop()->screen(QApplication::desktop()->screenNumber(parentWidget)),
   : Superclass(parentWidget,
-               Qt::ToolTip | Qt::FramelessWindowHint)
+               PopupWindowType | Qt::FramelessWindowHint)
   , d_ptr(new ctkBasePopupWidgetPrivate(*this))
 {
   Q_D(ctkBasePopupWidget);
@@ -472,7 +473,7 @@ ctkBasePopupWidget::ctkBasePopupWidget(QWidget* parentWidget)
 ctkBasePopupWidget::ctkBasePopupWidget(ctkBasePopupWidgetPrivate* pimpl, QWidget* parentWidget)
   //: //Superclass(QApplication::desktop()->screen(QApplication::desktop()->screenNumber(parentWidget)),
   : Superclass(parentWidget,
-               Qt::ToolTip | Qt::FramelessWindowHint)
+               PopupWindowType | Qt::FramelessWindowHint)
   , d_ptr(pimpl)
 {
 }

+ 1 - 0
Libs/Widgets/ctkBasePopupWidget_p.h

@@ -27,6 +27,7 @@ class QLabel;
 
 // CTK includes
 #include "ctkBasePopupWidget.h"
+#define PopupWindowType Qt::Tool
 
 // -------------------------------------------------------------------------
 /// \ingroup Widgets

+ 26 - 16
Libs/Widgets/ctkPopupWidget.cpp

@@ -22,6 +22,7 @@
 #include <QApplication>
 #include <QDebug>
 #include <QDesktopWidget>
+#include <QDialog>
 #include <QDir>
 #include <QEvent>
 #include <QLabel>
@@ -108,27 +109,20 @@ bool ctkPopupWidgetPrivate::eventFilter(QObject* obj, QEvent* event)
 	    QRect desiredGeometry = this->desiredOpenGeometry(newBaseGeometry);
 	    q->move(desiredGeometry.topLeft());
       }
-    else if (widget->isWindow() &&
-             widget->windowType() != Qt::ToolTip &&
-             widget->windowType() != Qt::Popup)
+    else if (this->isHidingCandidate(widget))
       {
       QTimer::singleShot(0, this, SLOT(updateVisibility()));
       }
     }
   else if (event->type() == QEvent::Resize)
     {
-    if (widget->isWindow() &&
-        widget != this->BaseWidget->window() &&
-        widget->windowType() != Qt::ToolTip &&
-        widget->windowType() != Qt::Popup)
+    if (this->isHidingCandidate(widget))
       {
       QTimer::singleShot(0, this, SLOT(updateVisibility()));
       }
     }
   else if (event->type() == QEvent::WindowStateChange &&
-           widget != this->BaseWidget->window() &&
-           widget->windowType() != Qt::ToolTip &&
-           widget->windowType() != Qt::Popup)
+           this->isHidingCandidate(widget))
     {
     QTimer::singleShot(0, this, SLOT(updateVisibility()));
     }
@@ -158,6 +152,25 @@ void ctkPopupWidgetPrivate::onApplicationDeactivate()
 }
 
 // -------------------------------------------------------------------------
+bool ctkPopupWidgetPrivate::isHidingCandidate(QWidget* widget)const
+{
+  bool canWindowsHidePopup = false;
+#if defined Q_OS_MAC
+  canWindowsHidePopup = true;
+#endif
+  bool isWindow = widget->isWindow();
+  QDialog* dialog = qobject_cast<QDialog*>(widget);
+  bool isModal = dialog ? dialog->isModal() : false;
+  bool isBasePopupWidget = qobject_cast<ctkBasePopupWidget*>(widget);
+  bool isToolTip = widget->windowType() == Qt::ToolTip;
+  bool isPopup = widget->windowType() == Qt::Popup;
+  bool isSelf = (widget == (this->BaseWidget ? this->BaseWidget->window() : 0));
+
+  return canWindowsHidePopup && isWindow && !isModal && !isBasePopupWidget &&
+    !isToolTip && !isPopup && !isSelf;
+}
+
+// -------------------------------------------------------------------------
 void ctkPopupWidgetPrivate::updateVisibility()
 {
   Q_Q(ctkPopupWidget);
@@ -168,8 +181,8 @@ void ctkPopupWidgetPrivate::updateVisibility()
       (!this->BaseWidget->window()->isActiveWindow() &&
       // and no other active window
        (!qApp->activeWindow() ||
-      // or the active window is a popup/tooltip
-        (qApp->activeWindow()->windowType() != Qt::ToolTip &&
+      // or the active window is a popup
+        (!qobject_cast<ctkBasePopupWidget*>(qApp->activeWindow()) && //->windowType() != PopupWindowType &&
          qApp->activeWindow()->windowType() != Qt::Popup))))
     {
     foreach(QWidget* topLevelWidget, qApp->topLevelWidgets())
@@ -181,9 +194,7 @@ void ctkPopupWidgetPrivate::updateVisibility()
       // Of course, tooltips and popups don't count as covering windows.
       if (topLevelWidget->isVisible() &&
           !(topLevelWidget->windowState() & Qt::WindowMinimized) &&
-          topLevelWidget->windowType() != Qt::ToolTip &&
-          topLevelWidget->windowType() != Qt::Popup &&
-          topLevelWidget != (this->BaseWidget ? this->BaseWidget->window() : 0) &&
+          this->isHidingCandidate(topLevelWidget) &&
           topLevelWidget->frameGeometry().intersects(q->geometry()))
         {
         //qDebug() << "hide" << q << "because of: " << topLevelWidget
@@ -226,7 +237,6 @@ void ctkPopupWidgetPrivate::temporarilyHiddenOn()
 void ctkPopupWidgetPrivate::temporarilyHiddenOff()
 {
   Q_Q(ctkPopupWidget);
-
   int forcedClosed = this->property("forcedClosed").toInt();
   if (forcedClosed > 0)
     {

+ 2 - 0
Libs/Widgets/ctkPopupWidget_p.h

@@ -50,6 +50,8 @@ public:
   void temporarilyHiddenOn();
   void temporarilyHiddenOff();
 
+  bool isHidingCandidate(QWidget* widget)const;
+
 public Q_SLOTS:
   void updateVisibility();
   void onApplicationDeactivate();