Преглед на файлове

Fix unpinning ctkPopupWidget

When a pinned popup was getting closed, if the mouse was over the base
widget or the closing popup, it was getting open again.
Julien Finet преди 14 години
родител
ревизия
8433552278
променени са 2 файла, в които са добавени 30 реда и са изтрити 1 реда
  1. 20 1
      Libs/Widgets/Testing/Cpp/ctkPopupWidgetTest1.cpp
  2. 10 0
      Libs/Widgets/ctkPopupWidget.cpp

+ 20 - 1
Libs/Widgets/Testing/Cpp/ctkPopupWidgetTest1.cpp

@@ -57,6 +57,8 @@ QWidget* createPanel(const QString& title, QList<ctkPopupWidget*>& popups)
   QPushButton* toggleButton = new QPushButton("Toggle popup");
   toggleButton->setObjectName("toggleButton");
   toggleButton->setCheckable(true);
+  QToolButton* pinButton = new QToolButton(0);
+  pinButton->setCheckable(true);
 
   QVBoxLayout* collapsibleLayout = new QVBoxLayout;
   collapsibleLayout->addWidget(focusComboBox);
@@ -66,6 +68,7 @@ QWidget* createPanel(const QString& title, QList<ctkPopupWidget*>& popups)
   vlayout->addWidget(button);
   vlayout->addWidget(openButton);
   vlayout->addWidget(toggleButton);
+  vlayout->addWidget(pinButton);
   topLevel->setLayout(vlayout);
 
   ctkPopupWidget* focusPopup = new ctkPopupWidget;
@@ -133,7 +136,23 @@ QWidget* createPanel(const QString& title, QList<ctkPopupWidget*>& popups)
                    togglePopup, SLOT(showPopup(bool)));
   togglePopup->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
   
-  popups << focusPopup << openPopup << togglePopup;
+  ctkPopupWidget* pinPopup = new ctkPopupWidget;
+  pinPopup->setObjectName("pinPopup");
+  pinPopup->setBaseWidget(pinButton);
+  QPushButton* pinPopupContent = new QPushButton("pin button");
+  pinPopupContent->setCheckable(true);
+  QObject::connect(pinPopupContent, SIGNAL(toggled(bool)),
+                   pinButton, SLOT(setChecked(bool)));
+  QObject::connect(pinButton, SIGNAL(toggled(bool)),
+                   pinPopupContent, SLOT(setChecked(bool)));
+  pinPopupContent->setObjectName("pinPopupContent");
+  QVBoxLayout* pinLayout = new QVBoxLayout;
+  pinLayout->addWidget(pinPopupContent);
+  pinPopup->setLayout(pinLayout);
+  QObject::connect(pinButton, SIGNAL(toggled(bool)),
+                   pinPopup, SLOT(pinPopup(bool)));
+  
+  popups << focusPopup << openPopup << togglePopup << pinPopup;
   return topLevel;
 }
 

+ 10 - 0
Libs/Widgets/ctkPopupWidget.cpp

@@ -744,6 +744,12 @@ void ctkPopupWidget::onEffectFinished()
     {
     d->hideAll();
     emit this->popupOpened(false);
+    /// restore the AutoShow if needed.
+    if (!this->property("AutoShowOnClose").isNull())
+      {
+      d->AutoShow = this->property("AutoShowOnClose").toBool();
+      this->setProperty("AutoShowOnClose", QVariant());
+      }
     }
   else
     {
@@ -1025,6 +1031,7 @@ void ctkPopupWidget::hidePopup()
 // --------------------------------------------------------------------------
 void ctkPopupWidget::pinPopup(bool pin)
 {
+  Q_D(ctkPopupWidget);
   this->setAutoHide(!pin);
   if (pin)
     {
@@ -1032,6 +1039,9 @@ void ctkPopupWidget::pinPopup(bool pin)
     }
   else
     {
+    // When closing, we don't want to inadvertently re-open the menu.
+    this->setProperty("AutoShowOnClose", this->autoShow());
+    d->AutoShow = false;
     this->hidePopup();
     }
 }