Skip to content
Snippets Groups Projects
Commit 39c6bd55 authored by Ludwig Jaeck's avatar Ludwig Jaeck
Browse files

MainWindow: Sidebar Toolbuttons are now visible from the beginning

parent 743e96b3
No related branches found
No related tags found
1 merge request!1332Resolve "GUI: don't redraw everything upon leaving Welcome view."
......@@ -23,8 +23,8 @@
#include "GUI/View/Project/ProjectManager.h"
#include "GUI/View/SampleDesigner/SampleView.h"
#include "GUI/View/Tool/mainwindow_constants.h"
#include "GUI/View/Toplevel/SimulationView.h"
#include "GUI/View/Toplevel/ProjectsView.h"
#include "GUI/View/Toplevel/SimulationView.h"
#include <QAction>
#include <QApplication>
#include <QBoxLayout>
......@@ -82,6 +82,7 @@ MainWindow::MainWindow()
initApplication();
readSettings();
initProgressBar();
initButtons();
initViews();
connect(m_projectManager, &ProjectManager::documentOpenedOrClosed, this,
......@@ -207,13 +208,35 @@ void MainWindow::initProgressBar()
m_viewSelectionButtonsLayout->addWidget(m_progressBar);
}
void MainWindow::initViews()
void MainWindow::initButtons()
{
if (m_projectsView == nullptr) {
m_projectsView = new ProjectsView(this);
addView(ViewId::PROJECTS, QIcon(":/images/main_welcomeview.svg"), "Projects",
"Switch to Projects View", m_projectsView);
addButton(ViewId::PROJECTS, QIcon(":/images/main_welcomeview.svg"), "Projects",
"Switch to Projects View");
addButton(ViewId::INSTRUMENT, QIcon(":/images/main_instrumentview.svg"), "Instrument",
"Define the beam and the detector");
addButton(ViewId::SAMPLE, QIcon(":/images/main_sampleview.svg"), "Sample", "Build the sample");
addButton(ViewId::IMPORT, QIcon(":/images/main_importview.svg"), "Data",
"Import intensity data to fit");
addButton(ViewId::SIMULATION, QIcon(":/images/main_simulationview.svg"), "Simulation",
"Run simulation");
addButton(ViewId::JOB, QIcon(":/images/main_jobview.svg"), "Jobs",
"Switch to see job results, tune parameters real time,\nfit the data");
for (auto* button : m_viewSelectionButtons->buttons()) {
if (button == m_viewSelectionButtons->button(ViewId::PROJECTS))
continue;
button->setEnabled(false);
}
}
void MainWindow::initViews()
{
m_projectsView = new ProjectsView(this);
resetView(ViewId::PROJECTS, m_projectsView);
if (gProjectDocument.has_value()) {
auto* doc = gProjectDocument.value();
......@@ -223,20 +246,15 @@ void MainWindow::initViews()
m_simulationView = new SimulationView(this, doc);
m_jobView = new JobView(this, doc);
addView(ViewId::INSTRUMENT, QIcon(":/images/main_instrumentview.svg"), "Instrument",
"Define the beam and the detector", m_instrumentView);
resetView(ViewId::INSTRUMENT, m_instrumentView);
addView(ViewId::SAMPLE, QIcon(":/images/main_sampleview.svg"), "Sample", "Build the sample",
m_sampleView);
resetView(ViewId::SAMPLE, m_sampleView);
addView(ViewId::IMPORT, QIcon(":/images/main_importview.svg"), "Data",
"Import intensity data to fit", m_importDataView);
resetView(ViewId::IMPORT, m_importDataView);
addView(ViewId::SIMULATION, QIcon(":/images/main_simulationview.svg"), "Simulation",
"Run simulation", m_simulationView);
resetView(ViewId::SIMULATION, m_simulationView);
addView(ViewId::JOB, QIcon(":/images/main_jobview.svg"), "Jobs",
"Switch to see job results, tune parameters real time,\nfit the data", m_jobView);
resetView(ViewId::JOB, m_jobView);
connect(m_jobView, &JobView::focusRequest, this, &MainWindow::onFocusRequest);
......@@ -244,6 +262,8 @@ void MainWindow::initViews()
if (gProjectDocument.has_value())
setCurrentView(gProjectDocument.value()->viewId());
else
raiseView(ViewId::PROJECTS);
}
}
......@@ -270,8 +290,8 @@ void MainWindow::writeSettings()
settings.sync();
}
void MainWindow::addView(ViewId id, const QIcon& icon, const QString& title, const QString& tooltip,
QWidget* view)
void MainWindow::addButton(ViewId id, const QIcon& icon, const QString& title,
const QString& tooltip)
{
QToolButton* btn = createViewSelectionButton();
m_viewSelectionButtonsLayout->insertWidget(id, btn);
......@@ -282,7 +302,10 @@ void MainWindow::addView(ViewId id, const QIcon& icon, const QString& title, con
m_viewSelectionButtons->addButton(btn, id);
updateViewSelectionButtonsGeometry();
}
void MainWindow::resetView(ViewId id, QWidget* view)
{
m_viewsStack->insertWidget(id, view);
}
......@@ -329,9 +352,16 @@ void MainWindow::onDocumentOpenedOrClosed(bool open)
initViews();
updateTitle();
if (open) {
if (gProjectDocument.has_value())
if (gProjectDocument.has_value()) {
for (auto* button : m_viewSelectionButtons->buttons())
button->setEnabled(true);
auto* filler =
m_viewSelectionButtonsLayout->itemAt(m_viewSelectionButtons->buttons().size());
if (filler)
if (auto* fillerBtn = dynamic_cast<QToolButton*>(filler->widget()); fillerBtn)
fillerBtn->setEnabled(true);
setCurrentView(gProjectDocument.value()->viewId());
else
} else
setCurrentView(MainWindow::INSTRUMENT);
}
}
......@@ -345,9 +375,6 @@ void MainWindow::onAboutToCloseDocument()
{
setCurrentView(PROJECTS);
while (m_viewSelectionButtons->buttons().size() > 1)
delete m_viewSelectionButtons->buttons().last();
updateViewSelectionButtonsGeometry();
delete m_instrumentView;
......
......@@ -66,12 +66,13 @@ protected:
private:
void initApplication();
void initProgressBar();
void initButtons();
void initViews();
void readSettings();
void writeSettings();
void addView(ViewId id, const QIcon& icon, const QString& title, const QString& tooltip,
QWidget* view);
void addButton(ViewId id, const QIcon& icon, const QString& title, const QString& tooltip);
void resetView(ViewId id, QWidget* view);
QToolButton* createViewSelectionButton() const;
//! Recalculate the size of the view selection buttons to show complete button text
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment