32 #include <QApplication>
34 #include <QButtonGroup>
35 #include <QCloseEvent>
36 #include <QMessageBox>
37 #include <QProgressBar>
38 #include <QPushButton>
40 #include <QStackedLayout>
42 #include <QToolButton>
45 : QMainWindow(nullptr)
46 , m_progressBar(new QProgressBar)
47 , m_viewSelectionButtons(new QButtonGroup(this))
48 , m_viewsStack(new QStackedLayout)
49 , m_viewSelectionButtonsLayout(new QVBoxLayout)
52 , m_welcomeView(nullptr)
53 , m_instrumentView(nullptr)
54 , m_sampleView(nullptr)
55 , m_importDataView(nullptr)
56 , m_simulationView(nullptr)
57 , m_projectSettingsView(nullptr)
59 , m_sessionModelView(nullptr)
61 auto* centralWidget =
new QWidget(
this);
62 auto* mainLayout =
new QHBoxLayout(centralWidget);
63 mainLayout->setMargin(0);
64 mainLayout->setSpacing(0);
70 fillerButton->setMinimumSize(5, 5);
71 fillerButton->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
72 fillerButton->setEnabled(
false);
75 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
82 auto* vlayout =
new QVBoxLayout;
83 vlayout->setMargin(0);
84 vlayout->setSpacing(0);
88 mainLayout->addLayout(vlayout);
90 setCentralWidget(centralWidget);
149 if (!doc.has_value())
150 setWindowTitle(
"BornAgain");
151 else if (doc.value()->isModified())
152 setWindowTitle(
"BornAgain - *" + doc.value()->projectName());
154 setWindowTitle(
"BornAgain - " + doc.value()->projectName());
164 if (
const auto* action = qobject_cast<const QAction*>(sender())) {
165 auto file = action->data().value<QString>();
174 if (
auto* widget = QApplication::focusWidget())
175 widget->clearFocus();
183 ASSERT(btn !=
nullptr);
190 btn->setEnabled(isActive);
191 btn->setVisible(isActive);
199 "Can't quit the application while jobs are running.\n"
200 "Cancel running jobs or wait until they are completed.");
214 setDockNestingEnabled(
true);
215 setAcceptDrops(
true);
217 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
218 setCorner(Qt::BottomRightCorner, Qt::BottomDockWidgetArea);
225 m_progressBar->setFixedHeight(QApplication::fontMetrics().boundingRect(
"M").height());
226 m_progressBar->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
264 "Switch to see job results, tune parameters real time,\nfit the data",
m_jobView);
309 btn->setToolTip(tooltip);
326 int maxTextWidth = 0;
327 int maxTextHeight = 0;
329 const auto r = fontMetrics.boundingRect(b->text());
330 maxTextWidth = std::max(maxTextWidth, r.width());
331 maxTextHeight = std::max(maxTextHeight, r.height());
336 const int margin = fontMetrics.boundingRect(
"M").width();
337 const int buttonExtent = std::max(70, maxTextWidth + 2 * margin);
340 const int iconExtent = buttonExtent - margin - maxTextHeight;
344 b->setFixedSize(buttonExtent, buttonExtent);
345 b->setIconSize({iconExtent, iconExtent});
350 if (
auto* fillerBtn =
dynamic_cast<QToolButton*
>(filler->widget()); fillerBtn)
351 fillerBtn->setFixedWidth(buttonExtent);
399 auto* btn =
new QToolButton;
400 btn->setObjectName(
"ViewSelectionButton");
401 btn->setCheckable(
true);
402 btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
Defines class ActionManager.
ApplicationSettings * appSettings
global pointer to the instance
Defines class ApplicationSettings.
Defines class ImportDataView.
Defines class InstrumentView.
Defines class MainWindow.
Defines class Helpers functions.
Defines class ProjectManager.
Defines class ProjectSettingsView.
Defines class SampleView.
SessionData * gSessionData
global pointer to the single instance
Defines struct SessionData.
Defines class SessionModelView.
Defines class SimulationView.
Defines class WelcomeView.
Class to handle MainWindow's menu and corresponding actions.
bool createNewProjectOnStartup() const
The ImportDataView class is a main view for importing experimental data.
void closeEvent(QCloseEvent *event) override
SimulationView * m_simulationView
void raiseView(int viewId)
WelcomeView * m_welcomeView
SessionModelView * m_sessionModelView
void setCurrentView(int viewId)
void onDocumentOpenedOrClosed(bool open)
QButtonGroup * m_viewSelectionButtons
InstrumentView * m_instrumentView
QWidget * currentView() const
void onSessionModelViewActive(bool isActive)
Inserts/removes developers SessionModelView on the left tabbar.
ProjectManager * m_projectManager
ImportDataView * m_importDataView
void onFocusRequest(int index)
void addView(ViewId id, const QIcon &icon, const QString &title, const QString &tooltip, QWidget *view)
void onRunSimulationShortcut()
QStackedLayout * m_viewsStack
QProgressBar * progressBar()
QVBoxLayout * m_viewSelectionButtonsLayout
QProgressBar * m_progressBar
void currentViewChanged(ViewId newView)
void onAboutToCloseDocument()
void onDocumentModified()
ProjectManager * projectManager()
ProjectSettingsView * m_projectSettingsView
QToolButton * createViewSelectionButton() const
void updateViewSelectionButtonsGeometry() const
Recalculate the size of the view selection buttons to show complete button text.
SampleView * m_sampleView
Handles activity related to opening/save projects.
void aboutToCloseDocument()
bool closeCurrentProject()
Processes close current project request. Call save/discard/cancel dialog, if necessary....
void readSettings()
Reads settings of ProjectManager from global settings.
void openProject(QString fileName="")
Opens existing project. If fileName is empty, will popup file selection dialog.
void newProject()
Processes new project request (close old project, rise dialog for project name, create project).
void documentOpenedOrClosed(bool opened)
void writeSettings()
Saves settings of ProjectManager in global settings.
Widget to define project settings.
The SessionModelView is a technical view which shows the content all current application models....
Widget to define a simulation. Contains:
Defines namespace GUI::Constants.
const char S_VIEWISACTIVE[]
const char S_MAINWINDOW[]
const char S_SESSIONMODELVIEW[]
const char S_WINDOWSIZE[]
const char S_WINDOWPOSITION[]
void warning(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)
std::optional< ProjectDocument * > projectDocument