Salome HOME
Set scroll area for B-Spline widgets
authorvsv <vsv@opencascade.com>
Tue, 21 Jan 2020 14:18:07 +0000 (17:18 +0300)
committervsv <vsv@opencascade.com>
Tue, 21 Jan 2020 14:18:07 +0000 (17:18 +0300)
src/PartSet/PartSet_BSplineWidget.cpp
src/PartSet/PartSet_BSplineWidget.h
src/PartSet/PartSet_WidgetBSplinePoints.cpp
src/PartSet/PartSet_WidgetBSplinePoints.h

index 7093c28fd5fe069d42a7558fb7c766c4ca05087f..893306dc12e4737a38e85d4a796eb9010bc3f2d7 100644 (file)
@@ -33,6 +33,7 @@
 #include <QGroupBox>
 #include <QLabel>
 #include <QVBoxLayout>
+#include <QScrollArea>
 
 
 PartSet_BSplineWidget::PartSet_BSplineWidget(
@@ -41,18 +42,36 @@ PartSet_BSplineWidget::PartSet_BSplineWidget(
   : ModuleBase_ModelWidget(theParent, theData)
 {
   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
-  ModuleBase_Tools::adjustMargins(aMainLayout);
+  aMainLayout->setContentsMargins(0, 0, 0, 0);
 
   // GroupBox to keep widgets for B-spline poles and weights
-  myPolesGroupBox = new QGroupBox(tr("Poles and weights"), theParent);
+  myPolesGroupBox = new QGroupBox(tr("Poles and weights"), this);
   aMainLayout->addWidget(myPolesGroupBox);
+
+  QVBoxLayout* aLayout = new QVBoxLayout(myPolesGroupBox);
+  ModuleBase_Tools::adjustMargins(aLayout);
+
+  myScrollArea = new QScrollArea(myPolesGroupBox);
+  myScrollArea->setWidgetResizable(true);
+  myScrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+  myScrollArea->setFrameStyle(QFrame::NoFrame);
+  aLayout->addWidget(myScrollArea);
+
+  QWidget* aContainer = new QWidget(myScrollArea);
+  QVBoxLayout* aBoxLay = new QVBoxLayout(aContainer);
+  aBoxLay->setContentsMargins(0, 0, 0, 0);
+
   // layout of GroupBox
-  QGridLayout* aGroupLayout = new QGridLayout(myPolesGroupBox);
+  myPolesWgt = new QWidget(aContainer);
+  QGridLayout* aGroupLayout = new QGridLayout(myPolesWgt);
   aGroupLayout->setSpacing(4);
   aGroupLayout->setColumnStretch(1, 1);
   ModuleBase_Tools::adjustMargins(aGroupLayout);
 
   restoreValueCustom();
+  aBoxLay->addWidget(myPolesWgt);
+  aBoxLay->addStretch(1);
+  myScrollArea->setWidget(aContainer);
 }
 
 void PartSet_BSplineWidget::setFeature(const FeaturePtr& theFeature,
@@ -73,26 +92,17 @@ void PartSet_BSplineWidget::deactivate()
 QList<QWidget*> PartSet_BSplineWidget::getControls() const
 {
   QList<QWidget*> aControls;
-  std::list<BSplinePoleWidgets>::const_iterator anIt = myPoles.begin();
-  for (; anIt != myPoles.end(); ++anIt) {
-    aControls.append(anIt->myWeight);
-  }
+  aControls.append(myScrollArea);
   return aControls;
 }
 
 void PartSet_BSplineWidget::storePolesAndWeights() const
 {
   std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
-  //AttributePoint2DArrayPtr aPointArray = std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(
-  //    aData->attribute(SketchPlugin_BSpline::POLES_ID()));
   AttributeDoubleArrayPtr aWeightsArray = aData->realArray(SketchPlugin_BSpline::WEIGHTS_ID());
 
-  //aPointArray->setSize((int)myPoles.size());
-  //aWeightsArray->setSize((int)myPoles.size());
-
   std::list<BSplinePoleWidgets>::const_iterator anIt = myPoles.begin();
   for (int anIndex = 0; anIt != myPoles.end(); ++anIndex, ++anIt) {
-    //aPointArray->setPnt(anIndex, anIt->myX->value(), anIt->myY->value());
     aWeightsArray->setValue(anIndex, anIt->myWeight->value());
   }
 }
@@ -103,17 +113,11 @@ bool PartSet_BSplineWidget::storeValueCustom()
   if (!aData || !aData->isValid()) // can be on abort of sketcher element
     return false;
 
-  //AttributePoint2DArrayPtr aPoles = std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(
-  //    aData->attribute(SketchPlugin_BSpline::POLES_ID()));
   AttributeDoubleArrayPtr aWeights = aData->realArray(SketchPlugin_BSpline::WEIGHTS_ID());
 
   bool isBlocked = blockSignals(true);
-  //bool isImmutable = aPoles->setImmutable(true);
-
   storePolesAndWeights();
   ModuleBase_Tools::flushUpdated(myFeature);
-
-  //aPoles->setImmutable(isImmutable);
   blockSignals(isBlocked);
 
   updateObject(myFeature);
@@ -149,7 +153,7 @@ bool PartSet_BSplineWidget::restoreValueCustom()
 
 void PartSet_BSplineWidget::addPoleWidget()
 {
-  QGridLayout* aGroupLay = dynamic_cast<QGridLayout*>(myPolesGroupBox->layout());
+  QGridLayout* aGroupLay = dynamic_cast<QGridLayout*>(myPolesWgt->layout());
   ModuleBase_Tools::adjustMargins(aGroupLay);
 
   int aNbPoles = (int)myPoles.size();
@@ -157,7 +161,7 @@ void PartSet_BSplineWidget::addPoleWidget()
   QString aPoleStr = tr("Pole %1");
   aPoleStr = aPoleStr.arg(aNbPoles + 1);
 
-  QGroupBox* aPoleGroupBox = new QGroupBox(aPoleStr, myPolesGroupBox);
+  QGroupBox* aPoleGroupBox = new QGroupBox(aPoleStr, myPolesWgt);
   QFormLayout* aPoleLay = new QFormLayout(aPoleGroupBox);
   ModuleBase_Tools::adjustMargins(aPoleLay);
   aPoleLay->setSpacing(2);
index 29a5fea889c9c47a0763db85ad5c0c259c17434f..ee20308948ffb42afc161be5d2522640610acb5f 100644 (file)
@@ -30,6 +30,7 @@
 #include <ModuleBase_ParamSpinBox.h>
 
 class QGroupBox;
+class QScrollArea;
 
 
 /** \brief Represent a content of the property panel to show/modify parameters of B-spline curve.
@@ -82,7 +83,9 @@ private:
     ModuleBase_ParamSpinBox* myWeight;
   };
 
-  QGroupBox* myPolesGroupBox; ///< widget to show poles and weights of B-spline curve
+  QWidget* myPolesWgt; ///< widget to show poles and weights of B-spline curve
+  QGroupBox* myPolesGroupBox;
+  QScrollArea* myScrollArea;
   std::list<BSplinePoleWidgets> myPoles; ///< list of B-spline poles and their weights
 };
 
index 6a18e7e5b0bdae90124224a8f247917386c71f4c..5ccc381e167f70de6e12d902a48a210d82d42bce 100644 (file)
 #include <QGroupBox>
 #include <QMouseEvent>
 #include <QGraphicsEffect>
+#include <QScrollArea>
 
 static const double MaxCoordinate = 1e12;
 
+static bool IsPointCreated = false;
+
+
 PartSet_WidgetBSplinePoints::PartSet_WidgetBSplinePoints(QWidget* theParent,
                                              ModuleBase_IWorkshop* theWorkshop,
                                              const Config_WidgetAPI* theData)
@@ -72,28 +76,45 @@ PartSet_WidgetBSplinePoints::PartSet_WidgetBSplinePoints(QWidget* theParent,
   myPointIndex(0), myFinished(false)
 {
   myRefAttribute = theData->getProperty("reference_attribute");
+  QVBoxLayout* aMainLayout = new QVBoxLayout(this);
+  ModuleBase_Tools::zeroMargins(aMainLayout);
 
   // the control should accept the focus, so the boolean flag is corrected to be true
   myIsObligatory = true;
   QString aPageName = translate(theData->getProperty(CONTAINER_PAGE_NAME));
-  myGroupBox = new QGroupBox(aPageName, theParent);
-  myGroupBox->setFlat(false);
+  myBox = new QGroupBox(aPageName, theParent);
+  myBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+  myBox->setFlat(false);
+  aMainLayout->addWidget(myBox);
 
   bool aAcceptVariables = theData->getBooleanAttribute(DOUBLE_WDG_ACCEPT_EXPRESSIONS, true);
 
   // B-spline weights attribute
   myWeightsAttr = theData->getProperty("weights");
 
+  QVBoxLayout* aLayout = new QVBoxLayout(myBox);
+  ModuleBase_Tools::adjustMargins(aLayout);
+
+  myScrollArea = new QScrollArea(myBox);
+  myScrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+  myScrollArea->setWidgetResizable(true);
+  myScrollArea->setFrameStyle(QFrame::NoFrame);
+  aLayout->addWidget(myScrollArea);
+
+  QWidget* aContainer = new QWidget(myScrollArea);
+  QVBoxLayout* aBoxLay = new QVBoxLayout(aContainer);
+  aBoxLay->setContentsMargins(0, 0, 0, 0);
+
+  myGroupBox = new QWidget(aContainer);
   QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
   ModuleBase_Tools::adjustMargins(aGroupLay);
   aGroupLay->setSpacing(4);
   aGroupLay->setColumnStretch(1, 1);
   createNextPoint();
+  aBoxLay->addWidget(myGroupBox);
+  aBoxLay->addStretch(1);
 
-  QVBoxLayout* aLayout = new QVBoxLayout(this);
-  ModuleBase_Tools::zeroMargins(aLayout);
-  aLayout->addWidget(myGroupBox);
-  setLayout(aLayout);
+  myScrollArea->setWidget(aContainer);
 
   myWidgetValidator = new ModuleBase_WidgetValidator(this, myWorkshop);
   myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
@@ -122,19 +143,24 @@ void PartSet_WidgetBSplinePoints::createNextPoint()
   aPoleLay->addWidget(myYSpin.back(), 1, 1);
 
   aGroupLay->addWidget(aPoleGroupBox, row, 1);
-
-  setHighlighted(true);
+  IsPointCreated = true;
 }
 
 void PartSet_WidgetBSplinePoints::removeLastPoint()
 {
   QGridLayout* aGroupLay = dynamic_cast<QGridLayout*>(myGroupBox->layout());
-  aGroupLay->removeWidget(myYSpin.back());
-  aGroupLay->removeWidget(myXSpin.back());
-  aGroupLay->removeWidget(myXSpin.back()->parentWidget());
+  QWidget* aXSpin = myXSpin.back();
+  QWidget* aYSpin = myYSpin.back();
+  QWidget* aBox = myXSpin.back()->parentWidget();
   myYSpin.pop_back();
   myXSpin.pop_back();
 
+  aGroupLay->removeWidget(aXSpin);
+  aGroupLay->removeWidget(aYSpin);
+  aGroupLay->removeWidget(aBox);
+
+  aBox->deleteLater();
+
   // update B-spline feature attributes
   storeValueCustom();
 }
@@ -417,22 +443,7 @@ bool PartSet_WidgetBSplinePoints::restoreCurentValue()
 QList<QWidget*> PartSet_WidgetBSplinePoints::getControls() const
 {
   QList<QWidget*> aControls;
-  std::vector<ModuleBase_LabelValue*>::const_iterator aXIt = myXSpin.begin();
-  std::vector<ModuleBase_LabelValue*>::const_iterator aYIt = myYSpin.begin();
-  for (; (*aXIt) != myXSpin.back() && (*aYIt) != myYSpin.back(); ++aXIt, ++aYIt) {
-    //aControls.append(*aXIt);
-    //aControls.append(*aYIt);
-    QGraphicsEffect* anEffect = (*aXIt)->graphicsEffect();
-    if (anEffect)
-      anEffect->deleteLater();
-    anEffect = (*aYIt)->graphicsEffect();
-    if (anEffect)
-      anEffect->deleteLater();
-    (*aXIt)->setGraphicsEffect(0);
-    (*aYIt)->setGraphicsEffect(0);
-  }
-  aControls.append(myXSpin.back());
-  aControls.append(myYSpin.back());
+  aControls.append(myScrollArea);
   return aControls;
 }
 
@@ -558,6 +569,12 @@ void PartSet_WidgetBSplinePoints::mouseMoved(ModuleBase_IViewWindow* theWindow,
   setPoint(aX, aY);
   blockValueState(isBlocked);
   setValueState(ModifiedInViewer);
+
+  if (IsPointCreated) {
+    QPoint aPnt = myGroupBox->geometry().bottomLeft();
+    myScrollArea->ensureVisible(aPnt.x(), aPnt.y());
+    IsPointCreated = false;
+  }
 }
 
 bool PartSet_WidgetBSplinePoints::processEscape()
index 360af3580f471755e109b259f3c0362deb019e6e..8285ab9a49e1eec9ce43432a74f15d63d635f990 100644 (file)
@@ -32,6 +32,7 @@ class ModelAPI_CompositeFeature;
 class ModuleBase_LabelValue;
 class PartSet_ExternalObjectsMgr;
 class QGroupBox;
+class QScrollArea;
 
 /**\class PartSet_WidgetBSplinePoints
  * \ingroup Modules
@@ -158,7 +159,9 @@ protected:
   ModuleBase_IWorkshop* myWorkshop; ///< workshop
 
 private:
-  QGroupBox* myGroupBox;  ///< the parent group box for all intenal widgets
+  QGroupBox* myBox;
+  QWidget* myGroupBox;  ///< the parent group box for all intenal widgets
+  QScrollArea* myScrollArea;
   std::vector<ModuleBase_LabelValue*> myXSpin; ///< the label for the X coordinate
   std::vector<ModuleBase_LabelValue*> myYSpin; ///< the label for the Y coordinate
   PartSet_ExternalObjectsMgr* myExternalObjectMgr; ///< reference to external objects manager