BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
GroupInfoBox.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/InfoWidgets/GroupInfoBox.cpp
6 //! @brief Implements class GroupInfoBox
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 
17 #include <QApplication>
18 #include <QMouseEvent>
19 #include <QPainter>
20 #include <QPixmap>
21 #include <QPushButton>
22 #include <QStyleOptionGroupBox>
23 #include <QStylePainter>
24 #include <QToolTip>
25 #include <iostream>
26 
27 namespace {
28 int imageWidth = 16;
29 int imageheigth = 16;
30 int offset_of_tooltip_position = 20;
31 int offset_of_icon_position = 24;
32 } // namespace
33 
34 GroupInfoBox::GroupInfoBox(QWidget* parent) : QGroupBox(parent), m_xImage(0), m_yImage(0)
35 {
36  init_box();
37 }
38 
39 GroupInfoBox::GroupInfoBox(const QString& title, QWidget* parent)
40  : QGroupBox(title, parent), m_title(title)
41 {
42  init_box();
43 }
44 
45 void GroupInfoBox::setButtonToolTip(const QString& text)
46 {
47  m_toolTipText = text;
48 }
49 
50 void GroupInfoBox::mousePressEvent(QMouseEvent* e)
51 {
52  if (e->button() == Qt::LeftButton) {
53  QStyleOptionGroupBox option;
54  initStyleOption(&option);
55  QRect buttonArea(m_xImage, m_yImage, imageWidth, imageheigth);
56  if (buttonArea.contains(e->pos()))
57  emit clicked(true);
58  }
59 }
60 
61 void GroupInfoBox::mouseMoveEvent(QMouseEvent* event)
62 {
63  QRect buttonArea(m_xImage, m_yImage, imageWidth, imageheigth);
64 
65  if (buttonArea.contains(event->pos())) {
66  QToolTip::showText(
67  this->mapToGlobal(QPoint(m_xImage + offset_of_tooltip_position, m_yImage)),
69  }
70 }
71 
73 {
74  setMouseTracking(true);
75  m_toolTipText = "Gives access to the extended distribution viewer.";
76 }
77 
78 void GroupInfoBox::paintEvent(QPaintEvent*)
79 {
80  QStylePainter paint(this);
81  QStyleOptionGroupBox option;
82  initStyleOption(&option);
83  paint.drawComplexControl(QStyle::CC_GroupBox, option);
84 
85  m_xImage = this->geometry().topRight().x() - offset_of_icon_position;
86  m_yImage = 0;
87 
88  // draw groupbox
89  int shift(1);
91  shift = 3;
92 
93  paint.drawItemPixmap(option.rect.adjusted(0, shift, 0, 0), Qt::AlignTop | Qt::AlignRight,
94  QPixmap(":/images/magnifier.png"));
95 }
Defines class GroupInfoBox.
static bool isLinuxHost()
Definition: hostosinfo.h:68
void paintEvent(QPaintEvent *)
void setButtonToolTip(const QString &text)
QString m_toolTipText
Definition: GroupInfoBox.h:39
void mousePressEvent(QMouseEvent *e)
void mouseMoveEvent(QMouseEvent *event)
GroupInfoBox(QWidget *parent=0)
Defines Utils namespace.