34 #include <QApplication>
36 #include <QButtonGroup>
37 #include <QCloseEvent>
38 #include <QMessageBox>
39 #include <QProgressBar>
40 #include <QPushButton>
42 #include <QStackedLayout>
44 #include <QToolButton>
49 : QMainWindow(nullptr)
50 , m_progressBar(new QProgressBar)
51 , m_viewSelectionButtons(new QButtonGroup(this))
52 , m_viewsStack(new QStackedLayout)
53 , m_viewSelectionButtonsLayout(new QVBoxLayout)
54 , m_statusBar(new QStatusBar)
67 , m_sessionModelView(0)
74 QWidget* centralWidget =
new QWidget(
this);
75 QHBoxLayout* mainLayout =
new QHBoxLayout(centralWidget);
76 mainLayout->setMargin(0);
77 mainLayout->setSpacing(0);
83 fillerButton->setMinimumSize(5, 5);
84 fillerButton->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
85 fillerButton->setEnabled(
false);
88 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
95 m_statusBar->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
97 QVBoxLayout* vlayout =
new QVBoxLayout;
98 vlayout->setMargin(0);
99 vlayout->setSpacing(0);
104 mainLayout->addLayout(vlayout);
106 setCentralWidget(centralWidget);
209 if (
const QAction* action = qobject_cast<const QAction*>(sender())) {
210 QString file = action->data().value<QString>();
219 if (
auto widget = QApplication::focusWidget())
220 widget->clearFocus();
235 btn->setEnabled(isActive);
236 btn->setVisible(isActive);
241 if (
jobModel()->hasUnfinishedJobs()) {
243 "Can't quit the application while jobs are running.\n"
244 "Cancel running jobs or wait until they are completed.");
263 QApplication::setWindowIcon(QIcon(
":/images/BornAgain.ico"));
265 setDockNestingEnabled(
true);
266 setAcceptDrops(
true);
268 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
269 setCorner(Qt::BottomRightCorner, Qt::BottomDockWidgetArea);
276 m_progressBar->setFixedHeight(QApplication::fontMetrics().boundingRect(
"M").height());
277 m_progressBar->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
291 addView(ViewId::WELCOME, QIcon(
":/images/main_welcomeview.svg"),
"Welcome",
294 addView(ViewId::INSTRUMENT, QIcon(
":/images/main_instrumentview.svg"),
"Instrument",
297 addView(ViewId::SAMPLE, QIcon(
":/images/main_sampleview.svg"),
"Sample",
"Build the sample",
300 addView(ViewId::IMPORT, QIcon(
":/images/main_importview.svg"),
"Data",
303 addView(ViewId::SIMULATION, QIcon(
":/images/main_simulationview.svg"),
"Simulation",
306 addView(ViewId::JOB, QIcon(
":/images/main_jobview.svg"),
"Jobs",
307 "Switch to see job results, tune parameters real time,\nfit the data",
m_jobView);
309 addView(ViewId::SESSIONMODEL, QIcon(
":/images/main_sessionmodel.svg"),
"Models",
"",
354 btn->setToolTip(tooltip);
371 int maxTextWidth = 0;
372 int maxTextHeight = 0;
374 const auto r = fontMetrics.boundingRect(b->text());
375 maxTextWidth = std::max(maxTextWidth, r.width());
376 maxTextHeight = std::max(maxTextHeight, r.height());
381 const int margin = fontMetrics.boundingRect(
"M").width();
382 const int buttonExtent = std::max(70, maxTextWidth + 2 * margin);
385 const int iconExtent = buttonExtent - margin - maxTextHeight;
389 b->setFixedSize(buttonExtent, buttonExtent);
390 b->setIconSize({iconExtent, iconExtent});
395 if (
auto fillerBtn =
dynamic_cast<QToolButton*
>(filler->widget()); fillerBtn)
396 fillerBtn->setFixedWidth(buttonExtent);
404 const QString viewSelectionButtonStyle =
405 "QToolButton { border: none; color: white; background-color: qlineargradient(x1: 0, "
406 "y1: 0, x2: 1, y2: 0, stop : 0 #153b4c, stop : 1 #347a9c);} "
407 "QToolButton:pressed { "
408 " color: black; background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 "
411 "QToolButton:hover { "
412 " color: white; background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 "
413 "#254b5c, stop: 1 #448aac); }"
414 "QToolButton:checked { "
415 " color: black; background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 "
420 QToolButton* btn =
new QToolButton;
421 btn->setCheckable(
true);
422 btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
423 btn->setStyleSheet(viewSelectionButtonStyle);
Defines class holding all application models.
#define ASSERT(condition)
Defines class GUIHelpers functions.
Defines class ActionManager.
Defines class MainWindow.
Defines class ProjectManager.
Defines class ImportDataView.
Defines class InstrumentView.
Defines class LinkInstrumentManager.
Defines class SampleView.
Defines class SessionModelView.
Defines class SimulationView.
Implements class UpdateNotifier.
Defines class WelcomeView.
Class to handle MainWindow's menu and corresponding actions.
SampleModel * sampleModel()
RealDataModel * realDataModel()
MaterialModel * materialModel()
InstrumentModel * instrumentModel()
The ImportDataView class is a main view for importing experimental data.
The JobView class is a main view to show list of jobs, job results and widgets for real time and fitt...
The LinkInstrumentManager class provides communication between InstrumentModel and RealDataModel.
void setModels(InstrumentModel *instrumentModel, RealDataModel *realDataModel)
Sets models and builds initial links.
SimulationView * m_simulationView
WelcomeView * m_welcomeView
SessionModelView * m_sessionModelView
void setCurrentView(int viewId)
QButtonGroup * m_viewSelectionButtons
InstrumentView * m_instrumentView
LinkInstrumentManager * m_linkManager
QWidget * currentView() const
UpdateNotifier * updateNotifier()
void closeEvent(QCloseEvent *event)
static MainWindow * instance()
Returns the one and only instance of this class.
void onSessionModelViewActive(bool isActive)
Inserts/removes developers SessionModelView on the left tabbar.
ProjectManager * m_projectManager
ImportDataView * m_importDataView
InstrumentModel * instrumentModel()
void onFocusRequest(int index)
LinkInstrumentManager * linkInstrumentManager()
void addView(ViewId id, const QIcon &icon, const QString &title, const QString &tooltip, QWidget *view)
UpdateNotifier * m_updateNotifier
void onRunSimulationShortcut()
QStackedLayout * m_viewsStack
ApplicationModels * m_applicationModels
QProgressBar * progressBar()
ApplicationModels * models()
QVBoxLayout * m_viewSelectionButtonsLayout
SampleModel * sampleModel()
QProgressBar * m_progressBar
MaterialModel * materialModel()
void currentViewChanged(ViewId newView)
ProjectManager * projectManager()
RealDataModel * realDataModel()
QToolButton * createViewSelectionButton() const
static MainWindow * s_instance
Holds the one and only instance of this class.
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.
bool closeCurrentProject()
Processes close current project request.
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 writeSettings()
Saves settings of ProjectManager in global settings.
The RealDataModel class is a model to store all imported RealDataItem's.
Main model to hold sample items.
The SessionModelView is a technical view which shows the content all current application models.
void onRunSimulationShortcut()
Defines namespace Constants.
const char S_SESSIONMODELVIEW[]
const char APPLICATION_NAME[]
const char S_VIEWISACTIVE[]
const char S_WINDOWPOSITION[]
const char S_WINDOWSIZE[]
const char S_MAINWINDOW[]
QString getBornAgainVersionString()
void warning(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)