BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
projectpanewidget.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/welcomeview/projectpanewidget.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 
17 #include <QLabel>
18 #include <QMouseEvent>
19 #include <QPainter>
20 #include <QVBoxLayout>
21 
22 namespace {
23 int widget_height()
24 {
25  return ModelView::Utils::SizeOfLetterM().height() * 3;
26 }
27 } // namespace
28 
29 namespace gui2 {
30 
32  : QWidget(parent)
33  , m_currentProjectTitle(new QLabel(" "))
34  , m_currentProjectDir(new QLabel(" "))
35  , m_widgetColor(QColor(Qt::white))
36 {
37  setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
38  setFixedHeight(widget_height());
39  auto layout = new QVBoxLayout(this);
40  layout->addWidget(m_currentProjectTitle);
41  layout->addWidget(m_currentProjectDir);
42 }
43 
44 //! Sets current project dir to 'project_dir', adjust title according to 'is_modified'.
45 
46 void ProjectPaneWidget::setCurrentProject(const QString& project_dir, bool is_modified)
47 {
48  m_active = true;
49  m_projectDir = project_dir;
50 
51  auto trimmed_project_dir = ModelView::Utils::WithTildeHomePath(project_dir);
52  auto project_title = ModelView::Utils::ProjectWindowTitle(project_dir, is_modified);
53 
54  m_currentProjectDir->setText(trimmed_project_dir);
55  m_currentProjectDir->setToolTip(m_projectDir);
56  m_currentProjectTitle->setText(project_title);
57 }
58 
59 //! Clear content of widget and make it inactive. Inactive widget doesnt' send signals when
60 //! user click on it.
61 
63 {
64  setActive(false);
65  m_projectDir.clear();
66  m_currentProjectDir->setText({});
67  m_currentProjectDir->setToolTip({});
68  m_currentProjectTitle->setText({});
69 }
70 
71 //! Set 'active' flag to the given value. 'False' means that the widget only shows the project
72 //! title, but doesn't react on mouse clicks and doesn't change the background on mouse
73 //! hover events.
75 {
76  m_active = value;
77  update();
78 }
79 
81 {
82  QPainter painter(this);
83  painter.fillRect(0, 0, size().width(), size().height(), m_widgetColor);
84 }
85 
87 {
88  if (m_active)
89  m_widgetColor = QColor(Qt::lightGray);
90  update();
91 }
92 
94 {
95  m_widgetColor = QColor(Qt::white);
96  update();
97 }
98 
99 void ProjectPaneWidget::mousePressEvent(QMouseEvent* event)
100 {
101  if (m_active && event->button() == Qt::LeftButton)
103 }
104 
105 } // namespace gui2
void enterEvent(QEvent *) override
void mousePressEvent(QMouseEvent *event) override
ProjectPaneWidget(QWidget *parent=nullptr)
void clear()
Clear content of widget and make it inactive.
void leaveEvent(QEvent *) override
void setCurrentProject(const QString &project_dir, bool is_modified=false)
Sets current project dir to 'project_dir', adjust title according to 'is_modified'.
void paintEvent(QPaintEvent *) override
void projectSelected(const QString &project_dir)
void setActive(bool value)
Set 'active' flag to the given value.
MVVM_VIEW_EXPORT QString WithTildeHomePath(const QString &path)
Returns a string where Linux path to the file is striped using '~/'.
Definition: widgetutils.cpp:79
MVVM_VIEW_EXPORT QSize SizeOfLetterM()
Returns size corresponding to actual size of letter M basing on current font metrics.
MVVM_VIEW_EXPORT QString ProjectWindowTitle(const QString &project_dir, bool is_modified)
Returns a title composed from last part of project path, and is_modified flag.
Definition: widgetutils.cpp:98
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
Definition: app_constants.h:20
Defines class CLASS?
Defines class CLASS?