Skip to content
Snippets Groups Projects
SampleView.cpp 5.14 KiB
Newer Older
  • Learn to ignore specific revisions
  • //  ************************************************************************************************
    
    Pospelov, Gennady's avatar
    Pospelov, Gennady committed
    //
    
    //  BornAgain: simulate and fit reflection and scattering
    
    Pospelov, Gennady's avatar
    Pospelov, Gennady committed
    //
    
    Wuttke, Joachim's avatar
    mv  
    Wuttke, Joachim committed
    //! @file      GUI/View/SampleDesigner/SampleView.cpp
    
    Pospelov, Gennady's avatar
    Pospelov, Gennady committed
    //! @brief     Implements class SampleView
    //!
    
    //! @homepage  http://www.bornagainproject.org
    
    Pospelov, Gennady's avatar
    Pospelov, Gennady committed
    //! @license   GNU General Public License v3 or higher (see COPYING)
    
    //! @copyright Forschungszentrum Jülich GmbH 2018
    //! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
    
    Pospelov, Gennady's avatar
    Pospelov, Gennady committed
    //
    
    //  ************************************************************************************************
    
    Pospelov, Gennady's avatar
    Pospelov, Gennady committed
    
    
    Wuttke, Joachim's avatar
    mv  
    Wuttke, Joachim committed
    #include "GUI/View/SampleDesigner/SampleView.h"
    
    #include "GUI/Model/Project/ProjectDocument.h"
    #include "GUI/Model/Sample/MultiLayerItem.h"
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
    #include "GUI/View/Common/DocksController.h"
    
    #include "GUI/View/Common/StyledToolBar.h"
    
    #include "GUI/View/SampleDesigner/LayerOrientedSampleEditor.h"
    #include "GUI/View/SampleDesigner/RealSpacePanel.h"
    #include "GUI/View/SampleDesigner/SampleListView.h"
    #include "GUI/View/SampleDesigner/ScriptPanel.h"
    
    #include <QDockWidget>
    
    #include <QMenu>
    
    SampleView::SampleView(QWidget* parent, ProjectDocument* document)
    
        : QMainWindow(parent), m_document(document)
    
        setObjectName("SampleView");
    
        connect(m_document, &ProjectDocument::singleSampleModeChanged, this,
                &SampleView::updateSingleSampleMode);
    
    
        m_docks = new DocksController(this);
    
    
        auto* editor = new LayerOrientedSampleEditor(this, document);
    
        auto* sampleSelectionPane = new QWidget(this);
        auto* sampleSelectionLayout = new QVBoxLayout(sampleSelectionPane);
    
        sampleSelectionLayout->setContentsMargins(0, 0, 0, 0);
        sampleSelectionLayout->setSpacing(0);
    
    
        auto* sampleSelectionToolbar = new StyledToolBar(sampleSelectionPane);
    
        auto* sampleSelectionView = new SampleListView(this, m_document->sampleModel());
        sampleSelectionToolbar->addAction(sampleSelectionView->newSampleAction());
        sampleSelectionToolbar->addAction(sampleSelectionView->chooseFromLibraryAction());
        if (auto* btn = dynamic_cast<QToolButton*>(sampleSelectionToolbar->widgetForAction(
                sampleSelectionView->chooseFromLibraryAction())))
            btn->setPopupMode(QToolButton::InstantPopup);
    
        sampleSelectionToolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
        sampleSelectionLayout->addWidget(sampleSelectionToolbar);
        sampleSelectionLayout->addWidget(sampleSelectionView);
        sampleSelectionView->setSizePolicy(QSizePolicy::MinimumExpanding,
                                           QSizePolicy::MinimumExpanding);
    
        auto* scriptPanel = new ScriptPanel(m_document->sampleModel(), this);
    
        m_realSpacePanel =
            new RealSpacePanel(m_document->materialModel(), m_document->sampleModel(), this);
    
        m_realSpacePanel->setLockViewActionVisible(false); // lock not used in layer oriented editor
    
    
        sampleSelectionPane->setWindowTitle("Samples");
    
        m_docks->addWidget(SAMPLE_LIST, sampleSelectionPane, Qt::LeftDockWidgetArea);
    
        m_docks->addWidget(REALSPACEPANEL, m_realSpacePanel, Qt::BottomDockWidgetArea);
    
        m_docks->addWidget(PYTHONPANEL, scriptPanel, Qt::BottomDockWidgetArea);
    
    
        connect(scriptPanel, &ScriptPanel::widgetHeightRequest, m_docks,
                &DocksController::setDockHeightForWidget);
    
        connect(sampleSelectionView, &SampleListView::currentSampleChanged, editor,
                &LayerOrientedSampleEditor::setCurrentSample);
    
    
        connect(sampleSelectionView, &SampleListView::currentSampleChanged, m_realSpacePanel->canvas(),
                &RealSpaceCanvas::setCurrentItem);
    
    
        connect(editor, &LayerOrientedSampleEditor::requestViewInRealSpace, this,
                &SampleView::onRequestViewInRealSpace);
    
    
        connect(editor, &LayerOrientedSampleEditor::requestCreateNewSample,
                sampleSelectionView->newSampleAction(), &QAction::trigger, Qt::QueuedConnection);
    
    
        setCentralWidget(editor);
        resetLayout();
    }
    
    
        m_docks->setDockVisible(SAMPLE_LIST, !m_document->singleSampleMode());
    
    void SampleView::onRequestViewInRealSpace(SessionItem* itemToView)
    {
        if (!itemToView)
            return;
    
        m_docks->setDockVisible(REALSPACEPANEL);
        m_realSpacePanel->canvas()->setCurrentItem(itemToView);
    }
    
    
    void SampleView::toggleRealSpaceView()
    {
    
        m_docks->toggleDock(REALSPACEPANEL);
    }
    
    
    void SampleView::fillViewMenu(QMenu* menu)
    {
    
        m_docks->addDockActionsToMenu(menu);
    
        menu->addSeparator();
    
    
        auto* action = new QAction(menu);
    
        action->setText("Reset to default layout");
        connect(action, &QAction::triggered, this, &SampleView::resetLayout);
        menu->addAction(action);
    
    Pospelov, Gennady's avatar
    Pospelov, Gennady committed
    }
    
        tabifyDockWidget(m_docks->findDock(REALSPACEPANEL), m_docks->findDock(PYTHONPANEL));
    
        m_docks->findDock(REALSPACEPANEL)->raise(); // makes first tab active
    
        m_docks->findDock(REALSPACEPANEL)->hide();
    
        m_docks->findDock(PYTHONPANEL)->hide();
    
    
        if (auto* d = m_docks->findDock(SAMPLE_LIST)) {
            if (m_document->singleSampleMode())
                d->hide();
            else
                d->show();
        }