BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
fancytab.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/mainwindow/fancytab.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 <QHBoxLayout>
18 #include <QLabel>
19 #include <QMouseEvent>
20 #include <QPainter>
21 
22 namespace {
23 QColor defaultColor()
24 {
25  static QWidget tmpWidget;
26  return tmpWidget.palette().color(QPalette::Window);
27 }
28 } // namespace
29 
30 namespace gui2 {
31 
32 FancyTab::FancyTab(const QString& title, QWidget* parent)
33  : QWidget(parent), m_label(new QLabel(title))
34 {
36  setFixedHeight(ModelView::Utils::HeightOfLetterM() * 2.5);
37 
38  auto layout = new QHBoxLayout(this);
39  layout->setContentsMargins(0, 0, 0, 0);
40 
41  layout->addWidget(m_label, 0, Qt::AlignCenter);
42  setMouseTracking(true);
43 }
44 
45 void FancyTab::setSelected(bool value)
46 {
47  m_isSelected = value;
48  update();
49 }
50 
51 void FancyTab::paintEvent(QPaintEvent*)
52 {
53  QPainter painter(this);
54 
55  if (m_widgetColor.isValid())
56  painter.fillRect(0, 0, size().width(), size().height(), m_widgetColor);
57 
58  if (m_isSelected && isEnabled())
59  painter.fillRect(
60  QRectF(QPointF(0, size().height() - 2), QPointF(size().width(), size().height())),
61  QColor("#0d4283"));
62 }
63 
64 void FancyTab::mousePressEvent(QMouseEvent* event)
65 {
66  if (isEnabled() && event->button() == Qt::LeftButton)
67  clicked();
68 }
69 
70 void FancyTab::enterEvent(QEvent*)
71 {
72  if (isEnabled())
73  m_widgetColor = QColor(Qt::lightGray);
74  update();
75 }
76 
77 void FancyTab::leaveEvent(QEvent*)
78 {
79  if (isEnabled())
80  m_widgetColor = defaultColor();
81  update();
82 }
83 
84 } // namespace gui2
bool m_isSelected
Definition: fancytab.h:46
FancyTab(const QString &title, QWidget *parent=nullptr)
Definition: fancytab.cpp:32
void leaveEvent(QEvent *) override
Definition: fancytab.cpp:77
void setSelected(bool value)
Definition: fancytab.cpp:45
void paintEvent(QPaintEvent *) override
Definition: fancytab.cpp:51
void enterEvent(QEvent *) override
Definition: fancytab.cpp:70
QLabel * m_label
Definition: fancytab.h:45
void mousePressEvent(QMouseEvent *event) override
Definition: fancytab.cpp:64
QColor m_widgetColor
Definition: fancytab.h:47
Defines class CLASS?
MVVM_VIEW_EXPORT int HeightOfLetterM()
Returns height of the letter 'M' deduced from 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.
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
Definition: app_constants.h:20
Defines class CLASS?