From e9e8511a09a12a66f68146c1e97d1bbc5895cc67 Mon Sep 17 00:00:00 2001
From: Gennady Pospelov <g.pospelov@fz-juelich.de>
Date: Wed, 4 Mar 2015 17:13:47 +0100
Subject: [PATCH] New AdjustingScrollingArea for instrument view

---
 .../InstrumentComponentsWidget.cpp            |  5 +-
 .../InstrumentEditorWidget.cpp                | 60 +++++++++----------
 .../InstrumentEditorWidget.h                  |  8 ---
 3 files changed, 31 insertions(+), 42 deletions(-)

diff --git a/GUI/coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.cpp b/GUI/coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.cpp
index 4ba3f1da9f4..7d44275f94b 100644
--- a/GUI/coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.cpp
+++ b/GUI/coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.cpp
@@ -27,11 +27,12 @@ InstrumentComponentsWidget::InstrumentComponentsWidget(QWidget *parent)
     , m_beamItem(0)
     , m_detectorItem(0)
 {
-    setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
+//    setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
     QVBoxLayout *mainLayout = new QVBoxLayout(this);
-    mainLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
+//    mainLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
     mainLayout->addWidget(m_beamEditor);
     mainLayout->addWidget(m_detectorEditor);
+//    setStyleSheet("InstrumentComponentsWidget {background-color:black;}");
 //    mainLayout->addStretch();
 //    setLayout(mainLayout);
 }
diff --git a/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.cpp b/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.cpp
index 1fca0b11951..b48996ea0a1 100644
--- a/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.cpp
+++ b/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.cpp
@@ -26,6 +26,7 @@
 #include <QComboBox>
 #include <QLineEdit>
 #include <QScrollArea>
+#include <QScrollBar>
 #include <QEvent>
 #include <QDebug>
 
@@ -33,17 +34,23 @@
 class AdjustingScrollArea : public QScrollArea {
     bool eventFilter(QObject * obj, QEvent * ev) {
         if (obj == widget() && ev->type() != QEvent::Resize) {
-            // Essential vvv
-            setMaximumWidth(width() - viewport()->width() + widget()->width());
+//            setMaximumWidth(width() - viewport()->width() + widget()->width());
+            widget()->setMaximumWidth(viewport()->width());
             setMaximumHeight(height() - viewport()->height() + widget()->height());
-            qDebug() << "EEEEEEEEEEEEEEEEEEEEEE ";
         }
         return QScrollArea::eventFilter(obj, ev);
     }
 
-    QSize sizeHint() const { return widget()->sizeHint(); }
+    QSize sizeHint() const {
+        QScrollBar *horizontal = horizontalScrollBar();
+        QSize result(viewport()->width(), widget()->height()+horizontal->height()*2);
+        return result;
+    }
 public:
-    AdjustingScrollArea(QWidget * parent = 0) : QScrollArea(parent) {}
+    AdjustingScrollArea(QWidget * parent = 0) : QScrollArea(parent)
+    {
+        setObjectName("MyScrollArea");
+    }
     void setWidget(QWidget *w) {
         QScrollArea::setWidget(w);
         // It so happens that QScrollArea already filters widget events,
@@ -57,18 +64,20 @@ InstrumentEditorWidget::InstrumentEditorWidget(QWidget *parent)
     : QWidget(parent)
     , m_nameLineEdit(new QLineEdit())
     , m_typeComboBox(new QComboBox())
-    , m_scrollArea(0)
-//    , m_beamWidget(new BeamEditorWidget(this))
-//    , m_detectorWidget(new DetectorEditorWidget(this))
-//    , m_testWidget(new TestInstrumentWidget(this))
     , m_currentItem(0)
     , m_block_signals(false)
-    , m_instrumentComponents(0)
+    , m_instrumentComponents(new InstrumentComponentsWidget)
 {
-
     setMinimumSize(400, 400);
     setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 
+    // main group box with all instrument parameters
+    QGroupBox *instrumentGroup = new QGroupBox(tr("Instrument Parameters"));
+    QVBoxLayout *instrumentGroupLayout = new QVBoxLayout;
+    //instrumentGroupLayout->setContentsMargins(0,0,0,0);
+    instrumentGroup->setLayout(instrumentGroupLayout);
+
+    // top block with instrument name and type
     m_typeComboBox->setMinimumWidth(300);
     m_typeComboBox->addItem("Default GISAS Instrument");
 
@@ -81,36 +90,23 @@ InstrumentEditorWidget::InstrumentEditorWidget(QWidget *parent)
     topLayout->addLayout(nameAndTypeLayout );
     topLayout->addStretch(1);
 
-    QGroupBox *instrumentGroup = new QGroupBox(tr("Instrument Parameters"));
-    QVBoxLayout *instrumentGroupLayout = new QVBoxLayout;
     instrumentGroupLayout->addLayout(topLayout);
 
-
-    m_instrumentComponents = new InstrumentComponentsWidget;
-    //m_instrumentComponents->setFixedWidth(500);
+    // Scroling area with insturment components
+    m_instrumentComponents->setStyleSheet("InstrumentComponentsWidget {background-color:black;}");
 
     AdjustingScrollArea *area = new AdjustingScrollArea;
     area->setWidgetResizable(true);
-    //area->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
+    area->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
     area->setWidget(m_instrumentComponents);
+    area->setContentsMargins( 0, 0, 0, 0 );
+    area->setStyleSheet("QScrollArea#MyScrollArea {border: 0px; background-color:#D3D0CE;}");
+    instrumentGroupLayout->addWidget(area, 1);
+    instrumentGroupLayout->addStretch();
 
-
-    instrumentGroupLayout->addWidget(area);
-
-
-//    instrumentGroupLayout->addWidget(m_instrumentComponents);
-    //m_scrollArea->setWidgetResizable(true);
-//    m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-//    m_scrollArea->setWidget(m_instrumentComponents);
-//    m_scrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
-//    instrumentGroupLayout->addWidget(m_scrollArea);
-
-
-    instrumentGroup->setLayout(instrumentGroupLayout);
-
+    // setting main layout
     QVBoxLayout *mainLayout = new QVBoxLayout;
     mainLayout->addWidget(instrumentGroup);
-    mainLayout->addStretch();
     setLayout(mainLayout);
 
     connect(m_nameLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(onChangedEditor(const QString &)));
diff --git a/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.h b/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.h
index 98f5c81bbf2..f4bbecaf9ec 100644
--- a/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.h
+++ b/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.h
@@ -28,7 +28,6 @@ class BeamEditorWidget;
 class QLineEdit;
 class QComboBox;
 class InstrumentComponentsWidget;
-class QScrollArea;
 
 class BA_CORE_API_ InstrumentEditorWidget : public QWidget
 {
@@ -49,16 +48,9 @@ private:
 
     QLineEdit *m_nameLineEdit;
     QComboBox *m_typeComboBox;
-    QScrollArea *m_scrollArea;
-//    BeamEditorWidget *m_beamWidget;
-//    DetectorEditorWidget *m_detectorWidget;
-
     ParameterizedItem *m_currentItem;
     bool m_block_signals;
-
-
     InstrumentComponentsWidget *m_instrumentComponents;
-
 };
 
 #endif
-- 
GitLab