BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
recentprojectwidget.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/welcomeview/recentprojectwidget.cpp
6 //! @brief Implements class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
20 #include <QLabel>
21 #include <QScrollArea>
22 #include <QVBoxLayout>
23 
24 namespace {
25 const int max_recent_project_count = 10;
26 const double section_label_scale = 1.25;
27 } // namespace
28 
29 namespace gui2 {
30 
32  : QWidget(parent), m_currentProjectPane(new ProjectPaneWidget)
33 {
34  auto layout = new QVBoxLayout(this);
35  layout->setContentsMargins(20, 0, 10, 0);
36 
37  layout->addWidget(createRecentProjectScrollArea());
38  layout->addStretch(1);
39 }
40 
42 {
43  return StyleUtils::DockSizeHint();
44 }
45 
47 {
49 }
50 
51 //! Set current project title and label on appropriate widget.
52 void RecentProjectWidget::setCurrentProject(const QString& project_dir, bool is_modified)
53 {
54  m_currentProjectPane->setCurrentProject(project_dir, is_modified);
56 }
57 
58 //! Set name of all recent projects to appropriate widgets.
59 void RecentProjectWidget::setRecentProjectsList(const QStringList& projects)
60 {
61  int widget_index{0};
62  for (auto widget : m_recentProjectPanes) {
63  if (widget_index < projects.size())
64  widget->setCurrentProject(projects.at(widget_index), false);
65  else
66  widget->clear();
67 
68  ++widget_index;
69  }
70 }
71 
73 {
74  auto result = new QVBoxLayout;
75  auto label = new QLabel("Current Project");
76  ModelView::Utils::ScaleLabelFont(label, section_label_scale);
77  result->addWidget(label);
78  result->addWidget(m_currentProjectPane);
79  return result;
80 }
81 
83 {
84  auto result = new QVBoxLayout;
85  auto label = new QLabel("Recent Projects");
86  ModelView::Utils::ScaleLabelFont(label, section_label_scale);
87  result->addWidget(label);
88 
89  for (int i = 0; i < max_recent_project_count; ++i) {
90  auto widget = new ProjectPaneWidget;
91  connect(widget, &ProjectPaneWidget::projectSelected, this,
93  m_recentProjectPanes.push_back(widget);
94  result->addWidget(widget);
95  }
96  return result;
97 }
98 
100 {
101  auto result = new ModelView::AdjustingScrollArea;
102 
103  auto content = new QWidget;
104  auto layout = new QVBoxLayout;
105  layout->addLayout(createCurrentProjectLayout());
106  layout->addSpacing(ModelView::Utils::SizeOfLetterM().height());
107  layout->addLayout(createRecentProjectLayout());
108  content->setLayout(layout);
109 
110  result->setWidget(content);
111  return result;
112 }
113 
114 } // namespace gui2
Defines class CLASS?
Modification of standard scroll area, which makes widget with dynamic layout occupy the whole availab...
Panel with labels to hold project name and project dir.
void setCurrentProject(const QString &project_dir, bool is_modified=false)
Sets current project dir to 'project_dir', adjust title according to 'is_modified'.
void projectSelected(const QString &project_dir)
void setActive(bool value)
Set 'active' flag to the given value.
void setRecentProjectsList(const QStringList &projects)
Set name of all recent projects to appropriate widgets.
ProjectPaneWidget * m_currentProjectPane
RecentProjectWidget(QWidget *parent=nullptr)
void setCurrentProject(const QString &project_dir, bool is_modified)
Set current project title and label on appropriate widget.
std::vector< ProjectPaneWidget * > m_recentProjectPanes
QBoxLayout * createCurrentProjectLayout() const
QSize sizeHint() const override
QSize minimumSizeHint() const override
QBoxLayout * createRecentProjectLayout()
void projectSelected(const QString &project_dir)
Defines class CLASS?
MVVM_VIEW_EXPORT QSize SizeOfLetterM()
Returns size corresponding to actual size of letter M basing on current font metrics.
MVVM_VIEW_EXPORT void ScaleLabelFont(QLabel *label, double scale)
Set label's font size to system font size scaled by given factor.
DAREFLCORE_EXPORT QSize DockMinimumSizeHint()
Hint on minimum size of docks on main reflectometry window.
Definition: styleutils.cpp:34
DAREFLCORE_EXPORT QSize DockSizeHint()
Hint on size of docks on main reflectometry window.
Definition: styleutils.cpp:29
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
Definition: app_constants.h:20
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?