BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ContentPane.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/ContentPane.h
6 //! @brief Defines ContentPane 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 #ifndef BORNAGAIN_GUI_COREGUI_VIEWS_ACCORDIONWIDGET_CONTENTPANE_H
32 #define BORNAGAIN_GUI_COREGUI_VIEWS_ACCORDIONWIDGET_CONTENTPANE_H
33 
35 #include <QFrame>
36 #include <QHBoxLayout>
37 #include <QPainter>
38 #include <QPoint>
39 #include <QPropertyAnimation>
40 #include <QString>
41 #include <QStyleOption>
42 #include <QWidget>
43 #include <memory>
44 
45 // TODO: Do i really need to export the ClickableFrame class?
46 /**
47  * @brief Content Pane class
48  *
49  * @details
50  * Content Panes are part of a QAccordion object. They represent a clickable
51  * Header and can be expanded or retracted.
52  *
53  * When a ContentPane is created you have to provide a Header (ContentPane(QString, QWidget*))
54  * and, if you want, a QFrame* (ContentPane(QString, QFrame*, QWidget*)) with the
55  * content that should be displayed when the ContentPane is expanded.
56  *
57  * Managing the content is pretty straight forward use getContentFrame() and setContentFrame()
58  * to manage the content. You are absolutely free to do anything what you like with
59  * this QFrame. Just keep in mind there is a maximumHeight for the container in which
60  * the content frame is placed (currently 150). If your content exceeds this height
61  * you have to either increase it with setMaximumHeight() or add a
62  * [QScrollArea](http://doc.qt.io/qt-5/qscrollarea.html) to the content frame. You may use
63  * setContainerFrameStyle() to change the frame style of the container.
64  *
65  * The Header can be changed after the creation of the ContentPane with setHeader().
66  * Additionally you can set a tooltip, a standard stylesheet and a mouseover
67  * stylesheet, and the frame style.
68  * @sa
69  * setHeaderTooltip(), setHeaderStylesheet(), setHeaderHoverStylesheet(),
70  * setHeaderFrameStyle()
71  *
72  * @details
73  * The animation speed is influenceable setAnimationDuration().
74  */
75 class ContentPane : public QWidget {
76  Q_OBJECT
77 public:
78  /**
79  * @brief ContentPane constructor
80  * @param header The Header of the content pane
81  * @param parent Parent widget or 0
82  */
83  explicit ContentPane(QString header, QWidget* parent = 0);
84  /**
85  * @brief ContentPane constructor
86  * @param header The Header of the content pane
87  * @param content Content to display when expanded
88  * @param parent Parent widget or 0
89  */
90  explicit ContentPane(QString header, QFrame* content, QWidget* parent = 0);
91 
92  /**
93  * @brief Check if this Content pane is active
94  * @return boolean True if active
95  */
96  bool getActive();
97 
98  /**
99  * @brief Get the content frame of the content pane
100  * @return QFrame*
101  *
102  * @details
103  * Use this method to get a pointer to a QFrame where you can place
104  * your content. The widget lifetime is managed by qAccordion.
105  */
106  QFrame* getContentFrame();
107  /**
108  * @brief Set the content frame
109  * @param content QFrame* with your content
110  *
111  * Set / change the content frame of this content pane with content. The
112  * lifecycle
113  */
114  void setContentFrame(QFrame* content);
115 
116  /**
117  * @brief Get the maximum height of the content pane container frame
118  * @return int
119  */
120  int getMaximumHeight();
121  /**
122  * @brief Set the maximum height of the content pane container.
123  * @param maxHeight
124  *
125  * @details
126  * Every content pane has a container frame that defines the visible maximum
127  * height. With this function you can change this setting.
128  *
129  @note
130  * This setting does not set the maximum height of the content frame. It is
131  * the users responsibilty to make sure everything in the content frame is
132  * visible. This can be influenced by either changing the maximum height of the
133  * container or for example by adding a [QScrollArea](http://doc.qt.io/qt-5.5/qscrollarea.html).
134  */
135  void setMaximumHeight(int maxHeight);
136  /**
137  * @brief Set the header of the content pane
138  * @param header
139  */
140  void setHeader(QString header);
141  /**
142  * @brief Return the header of the content pane
143  * @return QString
144  */
145  QString getHeader();
146  /**
147  * @brief Set header tooltip
148  * @param tooltip String to show as tooltip
149  *
150  * @details
151  * Set a string as header tooltip that will be shown when the mouse hovers
152  * over the header area.
153  */
154  void setHeaderTooltip(QString tooltip);
155  /**
156  * @brief Get the header tooltip
157  * @return Tooltip as QString
158  *
159  * @details
160  * Get the header tooltip as QString.
161  */
162  QString getHeaderTooltip();
163  /**
164  * @brief Set a stylesheet for the header frame
165  * @param stylesheet CSS Style Sheet as string
166  *
167  * @details
168  * You can use [Cascading Style Sheets](http://doc.qt.io/qt-5/stylesheet.html) as supported by
169  * Qt to style the header. This is the standard style sheet. You may also set a style for mouse
170  * over with setHeaderHoverStylesheet().
171  */
172  void setHeaderStylesheet(QString stylesheet);
173  /**
174  * @brief Get the current header style sheet
175  * @return CSS string
176  *
177  * @details
178  * Get the css of the content pane header as QString.
179  */
180  QString getHeaderStylesheet();
181  /**
182  * @brief Set a stylesheet for the header frame when the mouse hovers over it
183  * @param stylesheet CSS Style Sheet as string
184  *
185  * @details
186  * Set a stylesheet for the header for a special effect when the mouse hovers over it.
187  * @sa
188  * setHeaderStylesheet() for additional details.
189  */
190  void setHeaderHoverStylesheet(QString stylesheet);
191  /**
192  * @brief Get the mouse over header style sheet
193  * @return CSS Style Sheet as string
194  *
195  * @details
196  * Returns the mouse over header style sheet.
197  */
198  QString getHeaderHoverStylesheet();
199  /**
200  * @brief Set the header frame style
201  * @param style
202  *
203  * @details
204  * The style is the bitwise OR between a frame shape and a frame shadow style.
205  * See the [Qt Documentation](http://doc.qt.io/qt-5/qframe.html#setFrameStyle) for additional
206  * details.
207  */
208  void setHeaderFrameStyle(int style);
209  /**
210  * @brief Get the header frame style
211  * @return int
212  *
213  * @sa
214  * setHeaderFrameStyle() for additional information.
215  */
216  int getHeaderFrameStyle();
217  /**
218  * @brief Set the container frame style
219  * @param style
220  *
221  * @sa
222  * setHeaderFrameStyle() for additional information
223  */
224  void setContainerFrameStyle(int style);
225  /**
226  * @brief Get the container frame style
227  * @return int
228  *
229  * @sa
230  * setHeaderFrameStyle() for additional information
231  */
233  /**
234  * @brief Set the duration for the open and close animation
235  * @param duration Duration in milliseconds
236  *
237  * @details
238  * Set the duration of the QPropertyAnimation in milliseconds.
239  */
240  void setAnimationDuration(uint duration);
241  /**
242  * @brief Get the duration of the open, close animation.
243  * @return Duration in milliseconds
244  */
246 
247 signals:
248 
249  /**
250  * @brief Clicked signal is emitted when the header is clicked
251  */
252  void clicked();
253  /**
254  * @brief Signal will be emitted after the open animation finished
255  */
256  void isActive();
257  /**
258  * @brief Signal will be emitted after the close animation finished
259  */
260  void isInactive();
261 
262 public slots:
263 
264  /**
265  * @brief Slot that is called when the header has been triggered
266  * @param pos Currently unused
267  *
268  * @details
269  * This slot is used to notify the ContentPane widget that the header
270  * has been triggered. You can use this slot yourself to open or close the
271  * ContentPane. Check the state of the pane before with getActive() as this
272  * slot might not do what you intended to do (for example you want to close
273  * the ContentPane. If it is already inactive and you call this slot without
274  * checking the state it will be opened).
275  */
276  void headerClicked();
277 
278 private:
279  // yeah we are friends. this is important to keep openContentPane and
280  // closeContentPane private
281  friend class AccordionWidget;
282 
283  QFrame* content;
285  QFrame* container;
286 
290 
291  bool active;
292 
293  std::unique_ptr<QPropertyAnimation> openAnimation;
294  std::unique_ptr<QPropertyAnimation> closeAnimation;
295 
296  void initDefaults(QString header);
297  void initHeaderFrame(QString header);
299  void initAnimations();
300 
301 private slots:
302 
303  /**
304  * @brief Open the content pane
305  *
306  * @details
307  * This will open the content pane if it is currently closed.
308  * @warning
309  * Currently there is no inbuild mechanism to close an already open
310  * Content Pane when you open another one programmatically. Meaning you have
311  * to take care of this yourself.
312  */
313  void openContentPane();
314  /**
315  * @brief Close the content pane
316  *
317  * @details
318  * This will close the content pane if it is currently open.
319  */
320  void closeContentPane();
321 
322 protected:
323  /**
324  * @brief paintEvent Reimplement paintEvent to use stylesheets in derived Widgets
325  * @param event
326  */
327  void paintEvent(ATTR_UNUSED QPaintEvent* event);
328 };
329 
330 #endif // BORNAGAIN_GUI_COREGUI_VIEWS_ACCORDIONWIDGET_CONTENTPANE_H
Defines AccordionWidget class.
#define ATTR_UNUSED
QAccordion base class.
The ClickableFrame class.
Content Pane class.
Definition: ContentPane.h:75
void setHeaderTooltip(QString tooltip)
Set header tooltip.
Definition: ContentPane.cpp:92
void clicked()
Clicked signal is emitted when the header is clicked.
QString getHeaderStylesheet()
Get the current header style sheet.
ClickableFrame * header
Definition: ContentPane.h:284
void setHeaderStylesheet(QString stylesheet)
Set a stylesheet for the header frame.
QString getHeaderTooltip()
Get the header tooltip.
Definition: ContentPane.cpp:97
int getMaximumHeight()
Get the maximum height of the content pane container frame.
Definition: ContentPane.cpp:67
int containerAnimationMaxHeight
Definition: ContentPane.h:289
void closeContentPane()
Close the content pane.
uint getAnimationDuration()
Get the duration of the open, close animation.
ContentPane(QString header, QWidget *parent=0)
ContentPane constructor.
Definition: ContentPane.cpp:35
QString getHeader()
Return the header of the content pane.
Definition: ContentPane.cpp:87
int contentPaneFrameStyle
Definition: ContentPane.h:288
QFrame * getContentFrame()
Get the content frame of the content pane.
Definition: ContentPane.cpp:53
void isActive()
Signal will be emitted after the open animation finished.
void initAnimations()
void setAnimationDuration(uint duration)
Set the duration for the open and close animation.
void openContentPane()
Open the content pane.
std::unique_ptr< QPropertyAnimation > openAnimation
Definition: ContentPane.h:293
bool getActive()
Check if this Content pane is active.
Definition: ContentPane.cpp:48
QFrame * content
Definition: ContentPane.h:283
QString getHeaderHoverStylesheet()
Get the mouse over header style sheet.
void isInactive()
Signal will be emitted after the close animation finished.
void initHeaderFrame(QString header)
void setContentFrame(QFrame *content)
Set the content frame.
Definition: ContentPane.cpp:58
void setHeaderFrameStyle(int style)
Set the header frame style.
int getContainerFrameStyle()
Get the container frame style.
void setHeader(QString header)
Set the header of the content pane.
Definition: ContentPane.cpp:82
void setMaximumHeight(int maxHeight)
Set the maximum height of the content pane container.
Definition: ContentPane.cpp:72
QFrame * container
Definition: ContentPane.h:285
void headerClicked()
Slot that is called when the header has been triggered.
void initDefaults(QString header)
void setHeaderHoverStylesheet(QString stylesheet)
Set a stylesheet for the header frame when the mouse hovers over it.
void setContainerFrameStyle(int style)
Set the container frame style.
int getHeaderFrameStyle()
Get the header frame style.
std::unique_ptr< QPropertyAnimation > closeAnimation
Definition: ContentPane.h:294
int headerFrameStyle
Definition: ContentPane.h:287
void initContainerContentFrame()
void paintEvent(ATTR_UNUSED QPaintEvent *event)
paintEvent Reimplement paintEvent to use stylesheets in derived Widgets