BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
gui2::ProjectPaneWidget Class Reference

Panel with labels to hold project name and project dir. More...

Inheritance diagram for gui2::ProjectPaneWidget:
[legend]
Collaboration diagram for gui2::ProjectPaneWidget:
[legend]

Signals

void projectSelected (const QString &project_dir)
 

Public Member Functions

 ProjectPaneWidget (QWidget *parent=nullptr)
 
void clear ()
 Clear content of widget and make it inactive. More...
 
void setActive (bool value)
 Set 'active' flag to the given value. More...
 
void setCurrentProject (const QString &project_dir, bool is_modified=false)
 Sets current project dir to 'project_dir', adjust title according to 'is_modified'. More...
 

Protected Member Functions

void enterEvent (QEvent *) override
 
void leaveEvent (QEvent *) override
 
void mousePressEvent (QMouseEvent *event) override
 
void paintEvent (QPaintEvent *) override
 

Private Attributes

bool m_active {false}
 
QLabel * m_currentProjectDir {nullptr}
 
QLabel * m_currentProjectTitle {nullptr}
 
QString m_projectDir
 
QColor m_widgetColor
 

Detailed Description

Panel with labels to hold project name and project dir.

When user clicks on it, sends the request to open corresponding project. Part of RecentProjectsWidget.

Definition at line 28 of file projectpanewidget.h.

Constructor & Destructor Documentation

◆ ProjectPaneWidget()

gui2::ProjectPaneWidget::ProjectPaneWidget ( QWidget *  parent = nullptr)
explicit

Definition at line 31 of file projectpanewidget.cpp.

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 }

References m_currentProjectDir, and m_currentProjectTitle.

Member Function Documentation

◆ clear()

void gui2::ProjectPaneWidget::clear ( )

Clear content of widget and make it inactive.

Inactive widget doesnt' send signals when user click on it.

Definition at line 62 of file projectpanewidget.cpp.

63 {
64  setActive(false);
65  m_projectDir.clear();
66  m_currentProjectDir->setText({});
67  m_currentProjectDir->setToolTip({});
68  m_currentProjectTitle->setText({});
69 }
void setActive(bool value)
Set 'active' flag to the given value.

References m_currentProjectDir, m_currentProjectTitle, m_projectDir, and setActive().

Here is the call graph for this function:

◆ enterEvent()

void gui2::ProjectPaneWidget::enterEvent ( QEvent *  )
overrideprotected

Definition at line 86 of file projectpanewidget.cpp.

87 {
88  if (m_active)
89  m_widgetColor = QColor(Qt::lightGray);
90  update();
91 }

References m_active, and m_widgetColor.

◆ leaveEvent()

void gui2::ProjectPaneWidget::leaveEvent ( QEvent *  )
overrideprotected

Definition at line 93 of file projectpanewidget.cpp.

94 {
95  m_widgetColor = QColor(Qt::white);
96  update();
97 }

References m_widgetColor.

◆ mousePressEvent()

void gui2::ProjectPaneWidget::mousePressEvent ( QMouseEvent *  event)
overrideprotected

Definition at line 99 of file projectpanewidget.cpp.

100 {
101  if (m_active && event->button() == Qt::LeftButton)
103 }
void projectSelected(const QString &project_dir)

References m_active, m_projectDir, and projectSelected().

◆ paintEvent()

void gui2::ProjectPaneWidget::paintEvent ( QPaintEvent *  )
overrideprotected

Definition at line 80 of file projectpanewidget.cpp.

81 {
82  QPainter painter(this);
83  painter.fillRect(0, 0, size().width(), size().height(), m_widgetColor);
84 }

References m_widgetColor.

◆ projectSelected

void gui2::ProjectPaneWidget::projectSelected ( const QString &  project_dir)
signal

◆ setActive()

void gui2::ProjectPaneWidget::setActive ( bool  value)

Set 'active' flag to the given value.

'False' means that the widget only shows the project title, but doesn't react on mouse clicks and doesn't change the background on mouse hover events.

Definition at line 74 of file projectpanewidget.cpp.

75 {
76  m_active = value;
77  update();
78 }

References m_active.

Referenced by clear(), and gui2::RecentProjectWidget::setCurrentProject().

◆ setCurrentProject()

void gui2::ProjectPaneWidget::setCurrentProject ( const QString &  project_dir,
bool  is_modified = false 
)

Sets current project dir to 'project_dir', adjust title according to 'is_modified'.

Definition at line 46 of file projectpanewidget.cpp.

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 }
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 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

References m_active, m_currentProjectDir, m_currentProjectTitle, m_projectDir, ModelView::Utils::ProjectWindowTitle(), and ModelView::Utils::WithTildeHomePath().

Referenced by gui2::RecentProjectWidget::setCurrentProject().

Here is the call graph for this function:

Member Data Documentation

◆ m_active

bool gui2::ProjectPaneWidget::m_active {false}
private

Definition at line 53 of file projectpanewidget.h.

Referenced by enterEvent(), mousePressEvent(), setActive(), and setCurrentProject().

◆ m_currentProjectDir

QLabel* gui2::ProjectPaneWidget::m_currentProjectDir {nullptr}
private

Definition at line 51 of file projectpanewidget.h.

Referenced by ProjectPaneWidget(), clear(), and setCurrentProject().

◆ m_currentProjectTitle

QLabel* gui2::ProjectPaneWidget::m_currentProjectTitle {nullptr}
private

Definition at line 50 of file projectpanewidget.h.

Referenced by ProjectPaneWidget(), clear(), and setCurrentProject().

◆ m_projectDir

QString gui2::ProjectPaneWidget::m_projectDir
private

Definition at line 54 of file projectpanewidget.h.

Referenced by clear(), mousePressEvent(), and setCurrentProject().

◆ m_widgetColor

QColor gui2::ProjectPaneWidget::m_widgetColor
private

Definition at line 52 of file projectpanewidget.h.

Referenced by enterEvent(), leaveEvent(), and paintEvent().


The documentation for this class was generated from the following files: