Parcourir la source

Support multiple direction popup scrolling

Julien Finet il y a 14 ans
Parent
commit
faadf7dca5

+ 15 - 0
Libs/Widgets/Testing/Cpp/ctkPopupWidgetTest1.cpp

@@ -119,6 +119,9 @@ int ctkPopupWidgetTest1(int argc, char * argv [] )
   popup.setLayout(layout);
 
   popup.setBaseWidget(&base);
+  popup.setAlignment(Qt::AlignVCenter | Qt::AlignRight);
+  popup.setHorizontalDirection(Qt::RightToLeft);
+  popup.setOrientation(Qt::Horizontal);
   base.show();
   
   QList<ctkPopupWidget*> popups;
@@ -145,6 +148,18 @@ int ctkPopupWidgetTest1(int argc, char * argv [] )
   scrollPanel->show();
   fadePanel->show();
 
+  ctkPopupWidget screenPopup;
+  screenPopup.setAutoHide(false);
+  screenPopup.setOrientation(Qt::Horizontal | Qt::Vertical);
+
+  QFrame screenPopupContents;
+  screenPopupContents.setFixedSize(200, 200);
+  QVBoxLayout* screenLayout = new QVBoxLayout;
+  screenLayout->addWidget(&screenPopupContents);
+  screenPopup.setLayout(screenLayout);
+  screenPopup.move(0,0);
+  QTimer::singleShot(200, &screenPopup, SLOT(showPopup()));
+
   if (argc < 2 || QString(argv[1]) != "-I" )
     {
     QTimer::singleShot(200, &app, SLOT(quit()));

+ 14 - 18
Libs/Widgets/ctkPopupWidget.cpp

@@ -156,7 +156,7 @@ ctkPopupWidgetPrivate::ctkPopupWidgetPrivate(ctkPopupWidget& object)
   this->PopupPixmapWidget = 0;
   // Geometry attributes
   this->Alignment = Qt::AlignJustify | Qt::AlignBottom;
-  this->Orientation = Qt::Vertical;
+  this->Orientations = Qt::Vertical;
   this->VerticalDirection = ctkPopupWidget::TopToBottom;
   this->HorizontalDirection = Qt::LeftToRight;
 }
@@ -329,7 +329,7 @@ QRect ctkPopupWidgetPrivate::closedGeometry()const
 // -------------------------------------------------------------------------
 QRect ctkPopupWidgetPrivate::closedGeometry(QRect openGeom)const
 {
-  if (this->Orientation & Qt::Vertical)
+  if (this->Orientations & Qt::Vertical)
     {
     if (this->VerticalDirection == ctkPopupWidget::BottomToTop)
       {
@@ -337,9 +337,9 @@ QRect ctkPopupWidgetPrivate::closedGeometry(QRect openGeom)const
       }
     openGeom.setHeight(0);
     }
-  if (this->Orientation & Qt::Horizontal) 
+  if (this->Orientations & Qt::Horizontal)
     {
-    if (this->HorizontalDirection == Qt::LeftToRight)
+    if (this->HorizontalDirection == Qt::RightToLeft)
       {
       openGeom.moveLeft(openGeom.right());
       }
@@ -366,7 +366,7 @@ QRect ctkPopupWidgetPrivate::desiredOpenGeometry()const
   QRect geometry;
   if (this->Alignment & Qt::AlignJustify)
     {
-    if (this->Orientation & Qt::Vertical)
+    if (this->Orientations & Qt::Vertical)
       {
       size.setWidth(this->BaseWidget->width());
       }
@@ -409,14 +409,7 @@ QRect ctkPopupWidgetPrivate::desiredOpenGeometry()const
     }
   else if (this->Alignment & Qt::AlignHCenter)
     {
-    if (this->HorizontalDirection == Qt::LeftToRight)
-      {
-      geometry.moveLeft((topLeft.x() + bottomRight.x()) / 2 - size.width() / 2);
-      }
-    else
-      {
-      geometry.moveRight((topLeft.x() + bottomRight.x()) / 2 + size.width() / 2);
-      }
+    geometry.moveLeft((topLeft.x() + bottomRight.x()) / 2 - size.width() / 2);
     }
   else if (this->Alignment & Qt::AlignJustify)
     {
@@ -447,7 +440,10 @@ QRect ctkPopupWidgetPrivate::desiredOpenGeometry()const
     }
   else if (this->Alignment & Qt::AlignVCenter)
     {
-    if (this->VerticalDirection == ctkPopupWidget::TopToBottom)
+    geometry.moveTop((topLeft.y() + bottomRight.y()) / 2 - size.height() / 2);
+    }
+  return geometry;
+}
       {
       geometry.moveTop((topLeft.y() + bottomRight.y()) / 2 + size.height() / 2);
       }
@@ -575,17 +571,17 @@ void ctkPopupWidget::setAlignment(Qt::Alignment alignment)
 }
 
 // -------------------------------------------------------------------------
-Qt::Orientation ctkPopupWidget::orientation()const
+Qt::Orientations ctkPopupWidget::orientation()const
 {
   Q_D(const ctkPopupWidget);
-  return d->Orientation;
+  return d->Orientations;
 }
 
 // -------------------------------------------------------------------------
-void ctkPopupWidget::setOrientation(Qt::Orientation orientation)
+void ctkPopupWidget::setOrientation(Qt::Orientations orientations)
 {
   Q_D(ctkPopupWidget);
-  d->Orientation = orientation;
+  d->Orientations = orientations;
 }
 
 // -------------------------------------------------------------------------

+ 3 - 3
Libs/Widgets/ctkPopupWidget.h

@@ -62,7 +62,7 @@ class CTK_WIDGETS_EXPORT ctkPopupWidget : public QFrame
   /// Direction of the scrolling effect, can be Qt::Vertical, Qt::Horizontal or
   /// both Qt::Vertical|Qt::Horizontal.
   /// Vertical by default
-  Q_PROPERTY( Qt::Orientation orientation READ orientation WRITE setOrientation);
+  Q_PROPERTY( Qt::Orientations orientation READ orientation WRITE setOrientation);
   
   /// Control where the popup opens vertically.
   /// TopToBottom by default
@@ -110,8 +110,8 @@ public:
   Qt::Alignment alignment()const;
   void setAlignment(Qt::Alignment alignment);
   
-  Qt::Orientation orientation()const;
-  void setOrientation(Qt::Orientation orientation);
+  Qt::Orientations orientation()const;
+  void setOrientation(Qt::Orientations orientation);
   
   enum VerticalDirection{
     TopToBottom = 1,