BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ClickableFrame.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/AccordionWidget/ClickableFrame.cpp
6 //! @brief Implements AccordionWidget 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 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 // This file is part of qAccordion. An Accordion widget for Qt
16 // Copyright (C) 2015 Christian Rapp <0x2a at posteo dot org>
17 //
18 // This program is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 // This program is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 // GNU General Public License for more details.
27 //
28 // You should have received a copy of the GNU General Public License
29 // along with this program. If not, see <http://www.gnu.org/licenses/>.
30 
31 // Patched JWu 12nov20 because QPalette:Background was deprecated
32 
34 #include <QStyleOption>
35 
36 ClickableFrame::ClickableFrame(QString header, QWidget* parent, Qt::WindowFlags f)
37  : QFrame(parent, f), header(header)
38 {
39  this->setAttribute(Qt::WA_Hover, true);
40  this->clickable = true;
41  this->setCursor(Qt::PointingHandCursor);
42  QColor background = this->palette().color(QPalette::Window);
43  QColor lighter = background.lighter(110);
44  this->normalStylesheet = "";
45  this->hoverStylesheet = "QFrame {background-color: " + lighter.name() + ";}";
46  this->initFrame();
47 }
48 
50 {
51  this->clickable = status;
52  if (status) {
53  this->setCursor(Qt::PointingHandCursor);
54  } else {
55  this->setCursor(Qt::ForbiddenCursor);
56  }
57 }
58 
60 {
61  return this->clickable;
62 }
63 
64 void ClickableFrame::setHeader(QString header)
65 {
66  this->header = header;
67  this->nameLabel->setText(this->header);
68 }
69 
71 {
72  return this->header;
73 }
74 
75 void ClickableFrame::setNormalStylesheet(QString stylesheet)
76 {
77  this->normalStylesheet = stylesheet;
78  this->setStyleSheet(this->normalStylesheet);
79 }
80 
82 {
83  return this->normalStylesheet;
84 }
85 
86 void ClickableFrame::setHoverStylesheet(QString stylesheet)
87 {
88  this->hoverStylesheet = stylesheet;
89 }
90 
92 {
93  return this->hoverStylesheet;
94 }
95 
96 void ClickableFrame::setCaretPixmap(QString pixmapPath)
97 {
98  this->caretLabel->setPixmap(QPixmap(pixmapPath));
99 }
100 
102 {
103  this->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Fixed);
104  this->setLayout(new QHBoxLayout());
105 
106  this->caretLabel = new QLabel();
107  this->caretLabel->setPixmap(QPixmap(":/qAccordionIcons/caret-right.png"));
108  this->layout()->addWidget(this->caretLabel);
109 
110  this->nameLabel = new QLabel();
111  nameLabel->setText(this->header);
112  this->layout()->addWidget(nameLabel);
113 
114  dynamic_cast<QHBoxLayout*>(this->layout())->addStretch();
115 
116  this->setStyleSheet(this->normalStylesheet);
117 }
118 
119 void ClickableFrame::mousePressEvent(QMouseEvent* event)
120 {
121  if (this->clickable) {
122  emit this->singleClick(event->pos());
123  event->accept();
124  } else {
125  event->ignore();
126  }
127 }
128 
130 {
131  if (this->clickable) {
132  this->setStyleSheet(this->hoverStylesheet);
133  }
134 }
135 
137 {
138  if (this->clickable) {
139  this->setStyleSheet(this->normalStylesheet);
140  }
141 }
Defines AccordionWidget class.
#define ATTR_UNUSED
void setClickable(bool status)
Change clickable status.
void setNormalStylesheet(QString stylesheet)
Set the default stylesheet.
void mousePressEvent(QMouseEvent *event)
Reimplemented function to QMouseEvents.
QString normalStylesheet
QString getHoverStylesheet()
Get mouseover stylesheet.
void setHeader(QString header)
Set the header string.
void setHoverStylesheet(QString stylesheet)
Set mouseover stylesheet.
QString getHeader()
Get the header string.
void singleClick(QPoint pos)
Signal that is emitted upon a singleclick.
ClickableFrame(QString header, QWidget *parent=0, Qt::WindowFlags f={})
ClickableFrame constructor.
void enterEvent(QEvent *event)
Enter event for mouse over effects.
QString getNormalStylesheet()
Get the default stylesheet.
void setCaretPixmap(QString pixmapPath)
Set the caret pixmap.
QLabel * caretLabel
bool getClickable()
Check if the frame is clickable.
QLabel * nameLabel
QString hoverStylesheet
void leaveEvent(QEvent *event)
Leave effect for mouse over effects.