BornAgain  1.19.0
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/coregui/Views/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 
26 #include <QCommandLinkButton>
27 #include <QDesktopServices>
28 #include <QDir>
29 #include <QUrl>
30 #include <QVBoxLayout>
31 
32 namespace {
33 const int buttonHeight = 45;
34 const int buttonWidth = 140;
35 
36 const QString centralWidgetStyle =
37  "QWidget#containerWidget "
38  "{border-left: 1px solid gray; border-right: 1px solid gray;background-color:white;}";
39 } // namespace
40 
42  : m_mainWindow(parent)
43  , m_newProjectButton(nullptr)
44  , m_openProjectButton(nullptr)
45  , m_newUsertButton(nullptr)
46  , m_currentProjectLabel(nullptr)
47  , m_recentProjectLayout(nullptr)
48  , m_notifierWidget(new UpdateNotifierWidget(parent->updateNotifier()))
49 {
50  QPalette palette;
51  palette.setColor(QPalette::Window, QColor(240, 240, 240, 255));
52  setAutoFillBackground(true);
53  setPalette(palette);
54 
55  auto centralWidgetLayout = new QVBoxLayout;
56  centralWidgetLayout->setMargin(0);
57  centralWidgetLayout->addWidget(createProjectWidget());
58  centralWidgetLayout->addWidget(m_notifierWidget);
59  centralWidgetLayout->addStretch(1);
60 
61  auto centralWidget = new QWidget;
62  centralWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
63  centralWidget->setObjectName("containerWidget");
64  centralWidget->setMaximumWidth(1200);
65  centralWidget->setContentsMargins(0, 30, 0, 0);
66  centralWidget->setStyleSheet(centralWidgetStyle);
67  centralWidget->setLayout(centralWidgetLayout);
68 
69  auto mainLayout = new QHBoxLayout;
70  mainLayout->setContentsMargins(0, 0, 0, 0);
71  mainLayout->addWidget(new QWidget);
72  mainLayout->addWidget(centralWidget);
73  mainLayout->addWidget(new QWidget);
74  setLayout(mainLayout);
75 
76  connect(m_newProjectButton, &QPushButton::clicked, projectManager(),
78  connect(m_openProjectButton, &QPushButton::clicked, [=]() { projectManager()->openProject(); });
79  connect(m_newUsertButton, &QPushButton::clicked, this, &WelcomeView::onNewUser);
80  connect(projectManager(), &ProjectManager::modified, this,
82 
84 }
85 
87 {
88  auto recentProLabel = new QLabel("Recent Projects:");
89  recentProLabel->setFont(StyleUtils::sectionFont());
90 
92  m_recentProjectLayout->addWidget(recentProLabel);
93 
94  for (const auto& file : projectManager()->recentProjects()) {
95  QPalette palette;
96  palette.setColor(QPalette::ButtonText, QColor(41, 73, 150));
97 
98  auto button = new QCommandLinkButton;
99  button->setText(GUI_StringUtils::withTildeHomePath(QDir::toNativeSeparators(file)));
100  button->setFont(StyleUtils::labelFont());
101  button->setPalette(palette);
102  button->setFixedHeight(30);
103  connect(button, &QCommandLinkButton::clicked, [=] { projectManager()->openProject(file); });
104  m_recentProjectLayout->addWidget(button);
105  }
106  m_recentProjectLayout->addStretch();
107 }
108 
109 //! returns current project name suited for displaying on current project layout
111 {
112  QString result("Untitled");
113  if (auto projectDocument = projectManager()->document()) {
114  if (projectDocument->hasValidNameAndPath())
116  QDir::toNativeSeparators(projectDocument->projectFileName()));
117  else
118  result = projectDocument->projectName();
119  }
120  return result;
121 }
122 
123 //! updates label with current project name in picturesque manner
125 {
127 }
128 
130 {
131  return m_mainWindow->projectManager();
132 }
133 
134 void WelcomeView::onWebLinkClicked(const QUrl& url)
135 {
136  QDesktopServices::openUrl(url);
137 }
138 
140 {
141  QDesktopServices::openUrl(QUrl("http://www.bornagainproject.org"));
142 }
143 
145 {
148  update();
149 }
150 
151 void WelcomeView::showEvent(QShowEvent*)
152 {
154 }
155 
157 {
158  auto layout = new QHBoxLayout;
159  layout->addLayout(createButtonLayout());
160  layout->addWidget(createSeparationFrame());
161  layout->addLayout(createProjectLayout());
162  layout->addStretch(1);
163 
164  auto result = new QWidget;
165  result->setLayout(layout);
166  result->setFixedHeight(430);
167 
168  return result;
169 }
170 
172 {
173  m_newProjectButton = new QPushButton("New Project");
174  m_newProjectButton->setMinimumWidth(buttonWidth);
175  m_newProjectButton->setMinimumHeight(buttonHeight);
176  m_newProjectButton->setToolTip("Create new project");
177  m_newProjectButton->setAttribute(Qt::WA_MacShowFocusRect, false);
178 
179  m_openProjectButton = new QPushButton("Open Project");
180  m_openProjectButton->setMinimumWidth(buttonWidth);
181  m_openProjectButton->setMinimumHeight(buttonHeight);
182  m_openProjectButton->setToolTip("Open existing project");
183 
184  m_newUsertButton = new QPushButton("Website");
185  m_newUsertButton->setMinimumWidth(buttonWidth);
186  m_newUsertButton->setMinimumHeight(buttonHeight);
187  m_newUsertButton->setToolTip("Open BornAgain web site");
188 
189  auto buttonLayout = new QVBoxLayout;
190  buttonLayout->addWidget(m_newProjectButton);
191  buttonLayout->addWidget(m_openProjectButton);
192  buttonLayout->addStretch(1);
193  buttonLayout->addWidget(m_newUsertButton);
194 
195  auto result = new QHBoxLayout;
196  result->setContentsMargins(30, 0, 30, 0);
197  result->addLayout(buttonLayout);
198 
199  return result;
200 }
201 
203 {
204  auto result = new QVBoxLayout;
205  result->setContentsMargins(30, 0, 0, 0);
206 
207  auto label = new QLabel("Current Project:");
208  label->setFont(StyleUtils::sectionFont());
209 
210  m_currentProjectLabel = new FancyLabel("Untitled");
211  result->addWidget(label);
212  result->addWidget(m_currentProjectLabel);
213 
214  return result;
215 }
216 
218 {
219  m_recentProjectLayout = new QVBoxLayout;
220  m_recentProjectLayout->setContentsMargins(30, 0, 0, 0);
221  return m_recentProjectLayout;
222 }
223 
225 {
226  auto result = new QVBoxLayout;
227  result->addLayout(createCurrentProjectLayout());
228  result->addSpacing(15);
229  result->addLayout(createRecentProjectLayout());
230  return result;
231 }
232 
234 {
235  auto result = new QFrame;
236  result->setFrameShape(QFrame::VLine);
237  result->setFrameShadow(QFrame::Sunken);
238  return result;
239 }
Defines class DesignerHelper.
Defines class FancyLabel.
Defines class MainWindow.
Defines class ProjectManager.
Defines LayoutUtils namespace.
DefinesStyleUtils namespace.
Defines class UpdateNotifierWidget.
Defines class WelcomeView.
The FancyLabel class is a QLabel-like class with trivial animation when text slowly appears on the sc...
Definition: FancyLabel.h:23
void setTextAnimated(const QString &animated_text)
Definition: FancyLabel.cpp:28
ProjectManager * projectManager()
Definition: mainwindow.cpp:179
Handles activity related to opening/save projects.
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).
Small on WelcomeView for notofications about updates.
QWidget * createProjectWidget()
void generateRecentProjectList()
Definition: WelcomeView.cpp:86
QBoxLayout * createProjectLayout()
WelcomeView(MainWindow *parent)
Definition: WelcomeView.cpp:41
QPushButton * m_openProjectButton
Definition: WelcomeView.h:59
QBoxLayout * createRecentProjectLayout()
void updateRecentProjectPanel()
ProjectManager * projectManager()
QPushButton * m_newProjectButton
Definition: WelcomeView.h:58
QString currentProjectFancyName()
returns current project name suited for displaying on current project layout
UpdateNotifierWidget * m_notifierWidget
Definition: WelcomeView.h:63
FancyLabel * m_currentProjectLabel
Definition: WelcomeView.h:61
MainWindow * m_mainWindow
Definition: WelcomeView.h:57
void onWebLinkClicked(const QUrl &url)
QBoxLayout * createCurrentProjectLayout()
void onNewUser()
QBoxLayout * createButtonLayout()
QVBoxLayout * m_recentProjectLayout
Definition: WelcomeView.h:62
void showEvent(QShowEvent *)
QPushButton * m_newUsertButton
Definition: WelcomeView.h:60
void setCurrentProjectName(const QString &name)
updates label with current project name in picturesque manner
QFrame * createSeparationFrame()
Defines namespace Constants.
QString withTildeHomePath(const QString &path)
void clearLayout(QLayout *layout, bool deleteWidgets=true)
Removes content from box layout.
Definition: LayoutUtils.cpp:21
QString const & name(EShape k)
Definition: particles.cpp:21
QFont labelFont(bool bold=false)
Returns font for labels.
Definition: StyleUtils.cpp:78
QFont sectionFont(bool bold=false)
Returns font for sections.
Definition: StyleUtils.cpp:69
Defines class ProjectDocument.
Defines functions from Utils namespace.