BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ClickableFrame.h
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.h
6 //! @brief Defines 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 QFlags(0) was deprecated
32 
33 #ifndef BORNAGAIN_GUI_COREGUI_VIEWS_ACCORDIONWIDGET_CLICKABLEFRAME_H
34 #define BORNAGAIN_GUI_COREGUI_VIEWS_ACCORDIONWIDGET_CLICKABLEFRAME_H
35 
36 #include <QFrame>
37 #include <QGraphicsView>
38 #include <QHBoxLayout>
39 #include <QLabel>
40 #include <QMouseEvent>
41 #include <QString>
42 
43 #ifdef __GNUC__
44 #define ATTR_UNUSED __attribute__((unused))
45 #else
46 #define ATTR_UNUSED
47 #endif
48 
49 // TODO: No need to use a namespace for our constants as we are using them only
50 // in this class
52 const char* const CARRET_ICON_CLOSED =
53  ":/qAccordionIcons/caret-right.png"; /**< Qt qrc "path" for the closed icon */
54 const char* const CARRET_ICON_OPENED =
55  ":/qAccordionIcons/caret-bottom.png"; /**< Qt qrc "path" for the opened icon */
56 } // namespace ClickableFrame_constants
57 
58 /**
59  * @brief The ClickableFrame class
60  *
61  * This class represents a clickable QFrame. It is used by a ContentPane. The class
62  * is used internally.
63  */
64 class ClickableFrame : public QFrame {
65 
66  Q_OBJECT
67 public:
68  /**
69  * @brief ClickableFrame constructor
70  * @param header Header of the frame
71  * @param parent Parent widget or 0
72  * @param f Qt::WindowFlags
73  */
74  explicit ClickableFrame(QString header, QWidget* parent = 0, Qt::WindowFlags f = {});
75 
76  // TODO: Expose this function to the ContentPane api
77  /**
78  * @brief Change clickable status
79  * @param status
80  *
81  * @warning
82  * This function is currently not exposed by the qAccordion api.
83  */
84  void setClickable(bool status);
85  /**
86  * @brief Check if the frame is clickable
87  * @return bool
88  */
89  bool getClickable();
90  /**
91  * @brief Set the header string
92  * @param header
93  */
94  void setHeader(QString header);
95  /**
96  * @brief Get the header string
97  * @return QString
98  */
99  QString getHeader();
100  /**
101  * @brief Set the default stylesheet
102  * @param stylesheet
103  */
104  void setNormalStylesheet(QString stylesheet);
105  /**
106  * @brief Get the default stylesheet
107  * @return QString
108  */
109  QString getNormalStylesheet();
110  /**
111  * @brief Set mouseover stylesheet
112  * @param stylesheet
113  */
114  void setHoverStylesheet(QString stylesheet);
115  /**
116  * @brief Get mouseover stylesheet
117  * @return
118  */
119  QString getHoverStylesheet();
120 
121 signals:
122  /**
123  * @brief Signal that is emitted upon a singleclick
124  * @param pos
125  */
126  void singleClick(QPoint pos);
127 
128 public slots:
129 
130  /**
131  * @brief Set the caret pixmap
132  * @param pixmapPath
133  *
134  * @details
135  * Set the carret pixmap according to the state (expanded, retracted) of the
136  * ContentPane that this ClickableFrame belongs to.
137  */
138  void setCaretPixmap(QString pixmapPath);
139 
140 private:
141  QLabel* caretLabel;
142  QLabel* nameLabel;
143 
146 
147  QString header;
148  QString tooltip;
149 
150  bool clickable;
151 
152  void initFrame();
153 
154 protected:
155  /**
156  * @brief Reimplemented function to QMouseEvents
157  * @param event
158  */
159  void mousePressEvent(QMouseEvent* event);
160 
161  /**
162  * @brief Enter event for mouse over effects.
163  * @param event
164  */
165  void enterEvent(QEvent* event);
166  /**
167  * @brief Leave effect for mouse over effects.
168  * @param event
169  */
170  void leaveEvent(QEvent* event);
171 };
172 
173 #endif // BORNAGAIN_GUI_COREGUI_VIEWS_ACCORDIONWIDGET_CLICKABLEFRAME_H
The ClickableFrame class.
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.
const char *const CARRET_ICON_OPENED
Qt qrc "path" for the opened icon.
const char *const CARRET_ICON_CLOSED
Qt qrc "path" for the closed icon.