BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
WelcomeView.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Toplevel/WelcomeView.cpp
6 //! @brief Implements class WelcomeView
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include "GUI/Util/Path.h"
20 #include "ui_WelcomeView.h"
21 
22 #include <QCommandLinkButton>
23 #include <QDesktopServices>
24 #include <QDir>
25 #include <QUrl>
26 
27 WelcomeView::WelcomeView(QWidget* parent)
28  : QWidget(parent)
29  , m_ui(new Ui::WelcomeView)
30 {
31  m_ui->setupUi(this);
32 
33  setAttribute(Qt::WA_StyledBackground, true);
34  setProperty("stylable", true); // for stylesheet addressing
35 
37 
38  QPalette palette = this->palette();
39  palette.setColor(QPalette::Window, Qt::white);
40  setPalette(palette);
41 
42  connect(m_ui->newButton, &QPushButton::clicked, projectManager(), &ProjectManager::newProject);
43  connect(m_ui->openButton, &QPushButton::clicked, [=]() { projectManager()->openProject(); });
44  connect(m_ui->websiteButton, &QPushButton::clicked,
45  []() { QDesktopServices::openUrl(QUrl("https://www.bornagainproject.org")); });
48 
50 }
51 
53 {
54  return ProjectManager::instance();
55 }
56 
58 {
59  GUI::Util::Layout::clearLayout(m_ui->recentProjectsLayout);
60 
61  for (const auto& file : projectManager()->recentProjects()) {
62  auto* button = new QCommandLinkButton;
63  button->setText(QFileInfo(file).baseName());
64  button->setDescription(GUI::Util::Path::withTildeHomePath(QDir::toNativeSeparators(file)));
65  button->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
66  connect(button, &QCommandLinkButton::clicked, [=] { projectManager()->openProject(file); });
67 
68  m_ui->recentProjectsLayout->addWidget(button);
69  }
70  m_ui->recentProjectsLayout->addStretch(1);
71 }
Defines class GroupBoxCollapser.
Defines namespace GUI::Util::Layout.
Defines class Helpers functions.
Defines class ProjectManager.
Defines class WelcomeView.
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
Handles activity related to opening/save projects.
void recentListModified()
static ProjectManager * instance()
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 updateRecentProjectPanel()
Definition: WelcomeView.cpp:57
ProjectManager * projectManager()
Definition: WelcomeView.cpp:52
Ui::WelcomeView * m_ui
Definition: WelcomeView.h:36
WelcomeView(QWidget *parent)
Definition: WelcomeView.cpp:27
void clearLayout(QLayout *layout, bool deleteWidgets=true)
Removes content from box layout.
Definition: LayoutUtils.cpp:68
QString baseName(const QString &fileName)
Returns base name of file.
Definition: Path.cpp:133
QString withTildeHomePath(const QString &path)
Definition: Path.cpp:45