Newer
Older
// ************************************************************************************************
// BornAgain: simulate and fit reflection and scattering
//! @homepage http://www.bornagainproject.org
//! @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)
// ************************************************************************************************
#include "GUI/Model/Project/ProjectDocument.h"
#include "GUI/Model/Sample/MultiLayerItem.h"
Matthias Puchner
committed
#include "GUI/Model/Sample/SampleModel.h"
#include "GUI/View/Common/StyledToolBar.h"
Matthias Puchner
committed
#include "GUI/View/Realspace/RealSpaceCanvas.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 <QBoxLayout>
#include <QToolButton>
SampleView::SampleView(QWidget* parent, ProjectDocument* document)
: QMainWindow(parent), m_document(document)
Matthias Puchner
committed
Matthias Puchner
committed
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);
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);
Matthias Puchner
committed
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);
Matthias Puchner
committed
connect(editor, &LayerOrientedSampleEditor::requestViewInRealSpace, this,
&SampleView::onRequestViewInRealSpace);
Matthias Puchner
committed
connect(editor, &LayerOrientedSampleEditor::requestCreateNewSample,
sampleSelectionView->newSampleAction(), &QAction::trigger, Qt::QueuedConnection);
setCentralWidget(editor);
resetLayout();
}
Matthias Puchner
committed
void SampleView::updateSingleSampleMode()
Matthias Puchner
committed
m_docks->setDockVisible(SAMPLE_LIST, !m_document->singleSampleMode());
Matthias Puchner
committed
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);
void SampleView::resetLayout()
{
Matthias
committed
m_docks->resetLayout();
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();
}