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/Group/FilterPropertyProxy.h"
#include "GUI/Model/Project/ProjectDocument.h"
#include "GUI/Model/Sample/MultiLayerItem.h"
#include "GUI/View/SampleDesigner/DesignerScene.h"
#include "GUI/View/SampleDesigner/DesignerView.h"
#include "GUI/View/SampleDesigner/LayerOrientedSampleEditor.h"
#include "GUI/View/SampleDesigner/RealSpacePanel.h"
#include "GUI/View/SampleDesigner/SampleListView.h"
#include "GUI/View/SampleDesigner/SamplePropertyWidget.h"
#include "GUI/View/SampleDesigner/SampleToolBar.h"
#include "GUI/View/SampleDesigner/SampleToolBox.h"
#include "GUI/View/SampleDesigner/SampleTreeWidget.h"
#include "GUI/View/SampleDesigner/ScriptPanel.h"
#include <QBoxLayout>
#include <QToolButton>
SampleView::SampleView(QWidget* parent, ProjectDocument* document, bool initAsLayerOrientedEditor)
: QMainWindow(parent), m_document(document)
Matthias Puchner
committed
connect(m_document, &ProjectDocument::modified, this, &SampleView::updateFunctionalities);
if (initAsLayerOrientedEditor)
initLayerOrientedEditor();
else
initNetOrientedEditor();
}
void SampleView::initNetOrientedEditor()
{
const bool wasVisible = isVisible();
hide(); // important; otherwise the dockwidget layout is messed up
deleteEditor();
m_docks = new DocksController(this);
Matthias Puchner
committed
DesignerScene* designerScene = new DesignerScene(this, m_document);
DesignerView* designerView = new DesignerView(designerScene, this);
auto* toolBox = new SampleToolBox(this);
auto* treeWidget = new SampleTreeWidget(this, m_document->sampleModel());
auto* propertyWidget = new SamplePropertyWidget(treeWidget->treeView()->selectionModel(), this);
auto* scriptPanel = new ScriptPanel(m_document->sampleModel(), this);
auto* realSpacePanel = new RealSpacePanel(m_document->sampleModel(),
treeWidget->treeView()->selectionModel(), this);
m_docks->addWidget(TOOLBOX, toolBox, Qt::LeftDockWidgetArea);
m_docks->addWidget(SAMPLE_TREE, treeWidget, Qt::RightDockWidgetArea);
m_docks->addWidget(PROPERTY_EDITOR, propertyWidget, Qt::RightDockWidgetArea);
m_docks->addWidget(INFO, scriptPanel, Qt::BottomDockWidgetArea);
m_docks->addWidget(REALSPACEPANEL, realSpacePanel, Qt::BottomDockWidgetArea);
connect(scriptPanel, &ScriptPanel::widgetHeightRequest, m_docks,
&DocksController::setDockHeightForWidget);
designerScene->setSelectionModel(
treeWidget->treeView()->selectionModel(),
dynamic_cast<FilterPropertyProxy*>(
const_cast<QAbstractItemModel*>(treeWidget->treeView()->model())));
setCentralWidget(designerView);
resetLayout();
// m_toolBar should be initialized after MaterialBrowser
m_toolBar = new SampleToolBar(this);
connect(m_toolBar, &SampleToolBar::deleteItems, designerView,
&DesignerView::deleteSelectedItems);
connect(m_toolBar, &SampleToolBar::selectionMode, designerView, &DesignerView::onSelectionMode);
connect(designerView, &DesignerView::selectionModeChanged, m_toolBar,
Matthias Puchner
committed
&SampleToolBar::onViewSelectionMode);
connect(m_toolBar, &SampleToolBar::centerView, designerView, &DesignerView::onCenterView);
connect(m_toolBar, &SampleToolBar::changeScale, designerView, &DesignerView::onChangeScale);
Matthias Puchner
committed
connect(designerScene, &DesignerScene::selectionModeChangeRequest, designerView,
&DesignerView::onSelectionMode);
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
addToolBar(m_toolBar);
m_useLayerOrientedEditor = false;
if (wasVisible)
show();
}
void SampleView::initLayerOrientedEditor()
{
const bool wasVisible = isVisible();
hide(); // important; otherwise the dockwidget layout is messed up
deleteEditor();
m_docks = new DocksController(this);
auto editor = new LayerOrientedSampleEditor(this);
QWidget* sampleSelectionPane = new QWidget(this);
QVBoxLayout* 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);
auto* realSpacePanel = new RealSpacePanel(m_document->sampleModel(), nullptr, this);
sampleSelectionPane->setWindowTitle("Samples");
m_docks->addWidget(SAMPLE_LIST, sampleSelectionPane, Qt::LeftDockWidgetArea);
m_docks->addWidget(REALSPACEPANEL, realSpacePanel, Qt::BottomDockWidgetArea);
m_docks->addWidget(INFO, scriptPanel, Qt::BottomDockWidgetArea);
connect(scriptPanel, &ScriptPanel::widgetHeightRequest, m_docks,
&DocksController::setDockHeightForWidget);
connect(sampleSelectionView, &SampleListView::currentSampleChanged, editor,
&LayerOrientedSampleEditor::setCurrentSample);
setCentralWidget(editor);
resetLayout();
m_useLayerOrientedEditor = true;
if (wasVisible)
show();
}
void SampleView::deleteEditor()
{
delete m_toolBar;
m_toolBar = nullptr;
if (m_docks != nullptr) {
auto dockWidgets = m_docks->dockWidgets();
delete m_docks;
m_docks = nullptr;
qDeleteAll(dockWidgets);
}
Matthias Puchner
committed
if (auto* w = dynamic_cast<DesignerView*>(centralWidget()))
delete w->scene();
delete centralWidget();
}
void SampleView::updateFunctionalities()
{
if (auto* d = m_docks->findDock(SAMPLE_LIST)) {
if (m_document->singleSampleMode())
d->hide();
else
d->show();
}
void SampleView::toggleRealSpaceView()
{
m_docks->toggleDock(REALSPACEPANEL);
}
void SampleView::fillViewMenu(QMenu* menu)
{
QActionGroup* editorSelectionActions = new QActionGroup(this);
auto action = menu->addAction("Layer oriented sample editor");
action->setCheckable(true);
action->setChecked(m_useLayerOrientedEditor);
connect(action, &QAction::triggered, this, &SampleView::initLayerOrientedEditor,
Qt::QueuedConnection);
editorSelectionActions->addAction(action);
action = menu->addAction("Net oriented sample editor");
action->setCheckable(true);
action->setChecked(!m_useLayerOrientedEditor);
connect(action, &QAction::triggered, this, &SampleView::initNetOrientedEditor,
Qt::QueuedConnection);
editorSelectionActions->addAction(action);
menu->addSeparator();
m_docks->addDockActionsToMenu(menu);
menu->addSeparator();
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(INFO));
m_docks->findDock(REALSPACEPANEL)->raise(); // makes first tab active
m_docks->findDock(REALSPACEPANEL)->hide();
m_docks->findDock(INFO)->hide();
if (auto* d = m_docks->findDock(SAMPLE_LIST)) {
if (m_document->singleSampleMode())
d->hide();
else
d->show();
}