diff --git a/GUI/Model/Component/ComponentProxyModel.h b/GUI/Model/Component/ComponentProxyModel.h index 7158a6bd6a993911201f9fc4c54b1f7089e4fde2..24afc194b90196001141555b469e082b00c805a0 100644 --- a/GUI/Model/Component/ComponentProxyModel.h +++ b/GUI/Model/Component/ComponentProxyModel.h @@ -24,8 +24,8 @@ class SessionModel; class ProxyModelStrategy; -//! Proxy model to adjust SessionModel for component editor (right bottom corner of SampleView -//! and similar). +//! Proxy model to adjust SessionModel for component editor +//! //! The model hides all SessionItems which are not PropertyItems. //! The model hides GroupPropertyItem children and shows grand-children of currently selected item //! one level up. diff --git a/GUI/Model/Project/ProjectDocument.cpp b/GUI/Model/Project/ProjectDocument.cpp index a92dcc46c345b40ef5865adb03dd85b9e89b52d6..03eafdb077435c35edb53daa342ec2294c7657b0 100644 --- a/GUI/Model/Project/ProjectDocument.cpp +++ b/GUI/Model/Project/ProjectDocument.cpp @@ -251,6 +251,7 @@ void ProjectDocument::setSingleInstrumentMode(bool b) if (b != m_singleInstrumentMode) { m_singleInstrumentMode = b; emit modified(); + emit singleInstrumentModeChanged(); setModified(); } } @@ -265,6 +266,7 @@ void ProjectDocument::setSingleSampleMode(bool b) if (b != m_singleSampleMode) { m_singleSampleMode = b; emit modified(); + emit singleSampleModeChanged(); setModified(); } } @@ -279,6 +281,7 @@ void ProjectDocument::setFunctionalities(const Functionalities& f) if (m_functionalities != f) { m_functionalities = f; emit modified(); + emit functionalitiesChanged(); setModified(); } } diff --git a/GUI/Model/Project/ProjectDocument.h b/GUI/Model/Project/ProjectDocument.h index 406f9d2851a7b72dec935a98c2addf8162e3edc5..4ffac40b4b848ef32a5827d9e1efb0746b3e4594 100644 --- a/GUI/Model/Project/ProjectDocument.h +++ b/GUI/Model/Project/ProjectDocument.h @@ -104,8 +104,18 @@ public: void setFunctionalities(const Functionalities& f); signals: + //! Emitted for _any_ modifications in the document void modified(); + //! Emitted when functionality has changed + void functionalitiesChanged(); + + //! Emitted when single instrument mode has changed + void singleInstrumentModeChanged(); + + //! Emitted when single sample mode has changed + void singleSampleModeChanged(); + private: ReadResult readProject(QIODevice* device, MessageService& messageService); void writeTo(QIODevice* device); diff --git a/GUI/View/PropertyEditor/ComponentTreeView.cpp b/GUI/View/PropertyEditor/ComponentTreeView.cpp index 6c3fba99c14e0b28d2929a998009cec729a6f305..667f95f41a7e78e5166d6082c3f35042e224c9b3 100644 --- a/GUI/View/PropertyEditor/ComponentTreeView.cpp +++ b/GUI/View/PropertyEditor/ComponentTreeView.cpp @@ -31,7 +31,6 @@ ComponentTreeView::ComponentTreeView(QWidget* parent) , m_proxyModel(new ComponentProxyModel(this)) , m_placeHolderModel(new QStandardItemModel(this)) , m_eventFilter(new RightMouseButtonEater) - , m_show_root_item(false) { auto* layout = new QVBoxLayout; @@ -59,7 +58,6 @@ ComponentTreeView::ComponentTreeView(QWidget* parent) &ComponentTreeView::onCustomContextMenuRequested); setShowHeader(true); - setShowRootItem(false); } void ComponentTreeView::setItem(SessionItem* item) @@ -69,7 +67,7 @@ void ComponentTreeView::setItem(SessionItem* item) return; } setModel(item->model()); - setRootIndex(item->index(), m_show_root_item); + setRootIndex(item->index()); m_tree->expandAll(); } @@ -87,14 +85,13 @@ void ComponentTreeView::setModel(SessionModel* model) m_tree->setModel(m_placeHolderModel); } -void ComponentTreeView::setRootIndex(const QModelIndex& index, bool show_root_item) +void ComponentTreeView::setRootIndex(const QModelIndex& index) { if (QWidget* editor = m_tree->indexWidget(m_tree->currentIndex())) m_delegate->closeEditor(editor, QAbstractItemDelegate::NoHint); ASSERT(m_proxyModel); m_proxyModel->setRootIndex(index); - if (!show_root_item) - m_tree->setRootIndex(m_proxyModel->mapFromSource(index)); + m_tree->setRootIndex(m_proxyModel->mapFromSource(index)); } void ComponentTreeView::setShowHeader(bool show) @@ -102,11 +99,6 @@ void ComponentTreeView::setShowHeader(bool show) m_tree->setHeaderHidden(!show); } -void ComponentTreeView::setShowRootItem(bool show) -{ - m_show_root_item = show; -} - void ComponentTreeView::onCustomContextMenuRequested(const QPoint& pos) { auto point = m_tree->mapToGlobal(pos); diff --git a/GUI/View/PropertyEditor/ComponentTreeView.h b/GUI/View/PropertyEditor/ComponentTreeView.h index 7223a5707db450182d33ea89350f9ed89a6c9aec..ac1f96a39c7956df043b5d3e9e5838635ba008a5 100644 --- a/GUI/View/PropertyEditor/ComponentTreeView.h +++ b/GUI/View/PropertyEditor/ComponentTreeView.h @@ -39,21 +39,19 @@ public: void clearEditor(); void setShowHeader(bool show); - void setShowRootItem(bool show); private slots: void onCustomContextMenuRequested(const QPoint& pos); private: void setModel(SessionModel* model); - void setRootIndex(const QModelIndex& index, bool show_root_item = true); + void setRootIndex(const QModelIndex& index); QTreeView* m_tree; SessionModelDelegate* m_delegate; ComponentProxyModel* m_proxyModel; QStandardItemModel* m_placeHolderModel; std::unique_ptr<RightMouseButtonEater> m_eventFilter; - bool m_show_root_item; //!< Tree will starts from item itself, if true. }; #endif // BORNAGAIN_GUI_VIEW_PROPERTYEDITOR_COMPONENTTREEVIEW_H diff --git a/GUI/View/SampleDesigner/LayerOrientedSampleEditor.cpp b/GUI/View/SampleDesigner/LayerOrientedSampleEditor.cpp index 1b1e087074b2365b0b88320598d46bf4daaeed43..bf976cc9737fd0d3abc708395d26830c8fe7599f 100644 --- a/GUI/View/SampleDesigner/LayerOrientedSampleEditor.cpp +++ b/GUI/View/SampleDesigner/LayerOrientedSampleEditor.cpp @@ -13,6 +13,7 @@ // ************************************************************************************************ #include "GUI/View/SampleDesigner/LayerOrientedSampleEditor.h" +#include "GUI/Application/ApplicationSettings.h" #include "GUI/Model/Sample/LayerItem.h" #include "GUI/Model/Sample/MultiLayerItem.h" #include "GUI/View/Common/StyledToolBar.h" @@ -20,8 +21,8 @@ #include "GUI/View/SampleDesigner/MultiLayerForm.h" #include "GUI/View/SampleDesigner/SampleEditorController.h" -#include "GUI/Application/ApplicationSettings.h" #include <QBoxLayout> +#include <QPushButton> #include <QScrollArea> LayerOrientedSampleEditor::LayerOrientedSampleEditor(QWidget* parent) @@ -171,6 +172,17 @@ void LayerOrientedSampleEditor::createLayerColors() // #baLayerEditor move to be QWidget* LayerOrientedSampleEditor::createEmptyWidget() { auto* emptyWidget = new QWidget(this); - emptyWidget->setStyleSheet("background-color: white"); + emptyWidget->setProperty("stylable", true); // for stylesheet addressing + + auto* btn = new QPushButton("Create sample", emptyWidget); + connect(btn, &QPushButton::clicked, this, &LayerOrientedSampleEditor::requestCreateNewSample); + + auto* layout = new QHBoxLayout(emptyWidget); + layout->setContentsMargins(10, 20, 10, 20); + layout->addStretch(); + layout->addWidget(btn); + layout->addStretch(); + layout->setAlignment(Qt::AlignTop); + return emptyWidget; } diff --git a/GUI/View/SampleDesigner/LayerOrientedSampleEditor.h b/GUI/View/SampleDesigner/LayerOrientedSampleEditor.h index 8d5dd3c8bb14716271cf36c9d9a80d59caca8843..d242b562549973c175fe876de39272d51c026425 100644 --- a/GUI/View/SampleDesigner/LayerOrientedSampleEditor.h +++ b/GUI/View/SampleDesigner/LayerOrientedSampleEditor.h @@ -36,6 +36,7 @@ public: signals: void requestViewInRealSpace(SessionItem* itemToShow); + void requestCreateNewSample(); private: void updateActionEnabling(); @@ -43,6 +44,8 @@ private: void onUnitActionToggled(); void createLayerColors(); + + //! Create empty widget with a button for sample creation QWidget* createEmptyWidget(); private: diff --git a/GUI/View/SampleDesigner/SampleView.cpp b/GUI/View/SampleDesigner/SampleView.cpp index 9b345b09be7c93f5b6f24a4179af4a8f3c3d7ed3..bb3a76b69d3ce3dd335340cd3602ef1ac43e923a 100644 --- a/GUI/View/SampleDesigner/SampleView.cpp +++ b/GUI/View/SampleDesigner/SampleView.cpp @@ -34,7 +34,8 @@ SampleView::SampleView(QWidget* parent, ProjectDocument* document) { setObjectName("SampleView"); - connect(m_document, &ProjectDocument::modified, this, &SampleView::updateFunctionalities); + connect(m_document, &ProjectDocument::singleSampleModeChanged, this, + &SampleView::updateSingleSampleMode); m_docks = new DocksController(this); @@ -81,18 +82,16 @@ SampleView::SampleView(QWidget* parent, ProjectDocument* document) connect(editor, &LayerOrientedSampleEditor::requestViewInRealSpace, this, &SampleView::onRequestViewInRealSpace); + connect(editor, &LayerOrientedSampleEditor::requestCreateNewSample, + sampleSelectionView->newSampleAction(), &QAction::trigger, Qt::QueuedConnection); + setCentralWidget(editor); resetLayout(); } -void SampleView::updateFunctionalities() +void SampleView::updateSingleSampleMode() { - if (auto* d = m_docks->findDock(SAMPLE_LIST)) { - if (m_document->singleSampleMode()) - d->hide(); - else - d->show(); - } + m_docks->setDockVisible(SAMPLE_LIST, !m_document->singleSampleMode()); } void SampleView::onRequestViewInRealSpace(SessionItem* itemToView) diff --git a/GUI/View/SampleDesigner/SampleView.h b/GUI/View/SampleDesigner/SampleView.h index beaaa69ec702074966642af2426ad9cab84c15e3..c5f9d8f9151f6dfdfee32573a4b131cc94f516d7 100644 --- a/GUI/View/SampleDesigner/SampleView.h +++ b/GUI/View/SampleDesigner/SampleView.h @@ -35,7 +35,7 @@ public: private: void resetLayout(); - void updateFunctionalities(); + void updateSingleSampleMode(); //! Show the item in the real space view //!