BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ContentPane Class Reference

Content Pane class. More...

Inheritance diagram for ContentPane:
[legend]
Collaboration diagram for ContentPane:
[legend]

Public Slots

void headerClicked ()
 Slot that is called when the header has been triggered. More...
 

Signals

void clicked ()
 Clicked signal is emitted when the header is clicked. More...
 
void isActive ()
 Signal will be emitted after the open animation finished. More...
 
void isInactive ()
 Signal will be emitted after the close animation finished. More...
 

Public Member Functions

 ContentPane (QString header, QFrame *content, QWidget *parent=0)
 ContentPane constructor. More...
 
 ContentPane (QString header, QWidget *parent=0)
 ContentPane constructor. More...
 
bool getActive ()
 Check if this Content pane is active. More...
 
uint getAnimationDuration ()
 Get the duration of the open, close animation. More...
 
int getContainerFrameStyle ()
 Get the container frame style. More...
 
QFrame * getContentFrame ()
 Get the content frame of the content pane. More...
 
QString getHeader ()
 Return the header of the content pane. More...
 
int getHeaderFrameStyle ()
 Get the header frame style. More...
 
QString getHeaderHoverStylesheet ()
 Get the mouse over header style sheet. More...
 
QString getHeaderStylesheet ()
 Get the current header style sheet. More...
 
QString getHeaderTooltip ()
 Get the header tooltip. More...
 
int getMaximumHeight ()
 Get the maximum height of the content pane container frame. More...
 
void setAnimationDuration (uint duration)
 Set the duration for the open and close animation. More...
 
void setContainerFrameStyle (int style)
 Set the container frame style. More...
 
void setContentFrame (QFrame *content)
 Set the content frame. More...
 
void setHeader (QString header)
 Set the header of the content pane. More...
 
void setHeaderFrameStyle (int style)
 Set the header frame style. More...
 
void setHeaderHoverStylesheet (QString stylesheet)
 Set a stylesheet for the header frame when the mouse hovers over it. More...
 
void setHeaderStylesheet (QString stylesheet)
 Set a stylesheet for the header frame. More...
 
void setHeaderTooltip (QString tooltip)
 Set header tooltip. More...
 
void setMaximumHeight (int maxHeight)
 Set the maximum height of the content pane container. More...
 

Protected Member Functions

void paintEvent (ATTR_UNUSED QPaintEvent *event)
 paintEvent Reimplement paintEvent to use stylesheets in derived Widgets More...
 

Private Slots

void closeContentPane ()
 Close the content pane. More...
 
void openContentPane ()
 Open the content pane. More...
 

Private Member Functions

void initAnimations ()
 
void initContainerContentFrame ()
 
void initDefaults (QString header)
 
void initHeaderFrame (QString header)
 

Private Attributes

bool active
 
std::unique_ptr< QPropertyAnimation > closeAnimation
 
QFrame * container
 
int containerAnimationMaxHeight
 
QFrame * content
 
int contentPaneFrameStyle
 
ClickableFrameheader
 
int headerFrameStyle
 
std::unique_ptr< QPropertyAnimation > openAnimation
 

Friends

class AccordionWidget
 

Detailed Description

Content Pane class.

Content Panes are part of a QAccordion object. They represent a clickable Header and can be expanded or retracted.

When a ContentPane is created you have to provide a Header (ContentPane(QString, QWidget*)) and, if you want, a QFrame* (ContentPane(QString, QFrame*, QWidget*)) with the content that should be displayed when the ContentPane is expanded.

Managing the content is pretty straight forward use getContentFrame() and setContentFrame() to manage the content. You are absolutely free to do anything what you like with this QFrame. Just keep in mind there is a maximumHeight for the container in which the content frame is placed (currently 150). If your content exceeds this height you have to either increase it with setMaximumHeight() or add a QScrollArea to the content frame. You may use setContainerFrameStyle() to change the frame style of the container.

The Header can be changed after the creation of the ContentPane with setHeader(). Additionally you can set a tooltip, a standard stylesheet and a mouseover stylesheet, and the frame style.

See also
setHeaderTooltip(), setHeaderStylesheet(), setHeaderHoverStylesheet(), setHeaderFrameStyle()

The animation speed is influenceable setAnimationDuration().

Definition at line 75 of file ContentPane.h.

Constructor & Destructor Documentation

◆ ContentPane() [1/2]

ContentPane::ContentPane ( QString  header,
QWidget *  parent = 0 
)
explicit

ContentPane constructor.

Parameters
headerThe Header of the content pane
parentParent widget or 0

Definition at line 35 of file ContentPane.cpp.

35  : QWidget(parent)
36 {
37  this->content = nullptr;
38 
39  this->initDefaults(std::move(header));
40 }
ClickableFrame * header
Definition: ContentPane.h:284
QFrame * content
Definition: ContentPane.h:283
void initDefaults(QString header)

References content, header, and initDefaults().

Here is the call graph for this function:

◆ ContentPane() [2/2]

ContentPane::ContentPane ( QString  header,
QFrame *  content,
QWidget *  parent = 0 
)
explicit

ContentPane constructor.

Parameters
headerThe Header of the content pane
contentContent to display when expanded
parentParent widget or 0

Definition at line 42 of file ContentPane.cpp.

43  : QWidget(parent), content(content)
44 {
45  this->initDefaults(std::move(header));
46 }

References header, and initDefaults().

Here is the call graph for this function:

Member Function Documentation

◆ clicked

void ContentPane::clicked ( )
signal

Clicked signal is emitted when the header is clicked.

Referenced by headerClicked(), AccordionWidget::internalAddContentPane(), and AccordionWidget::internalInsertContentPane().

◆ closeContentPane

void ContentPane::closeContentPane ( )
privateslot

Close the content pane.

This will close the content pane if it is currently open.

Definition at line 151 of file ContentPane.cpp.

152 {
153  if (!this->getActive())
154  return;
155  this->closeAnimation->start();
157  this->active = false;
158 }
void setCaretPixmap(QString pixmapPath)
Set the caret pixmap.
bool getActive()
Check if this Content pane is active.
Definition: ContentPane.cpp:48
std::unique_ptr< QPropertyAnimation > closeAnimation
Definition: ContentPane.h:294
const char *const CARRET_ICON_CLOSED
Qt qrc "path" for the closed icon.

References active, ClickableFrame_constants::CARRET_ICON_CLOSED, closeAnimation, getActive(), header, and ClickableFrame::setCaretPixmap().

Referenced by AccordionWidget::handleClickedSignal().

Here is the call graph for this function:

◆ getActive()

bool ContentPane::getActive ( )

Check if this Content pane is active.

Returns
boolean True if active

Definition at line 48 of file ContentPane.cpp.

49 {
50  return this->active;
51 }

References active.

Referenced by closeContentPane(), AccordionWidget::handleClickedSignal(), openContentPane(), and setMaximumHeight().

◆ getAnimationDuration()

uint ContentPane::getAnimationDuration ( )

Get the duration of the open, close animation.

Returns
Duration in milliseconds

◆ getContainerFrameStyle()

int ContentPane::getContainerFrameStyle ( )

Get the container frame style.

Returns
int
See also
setHeaderFrameStyle() for additional information

Definition at line 137 of file ContentPane.cpp.

138 {
139  return this->container->frameStyle();
140 }
QFrame * container
Definition: ContentPane.h:285

References container.

◆ getContentFrame()

QFrame * ContentPane::getContentFrame ( )

Get the content frame of the content pane.

Returns
QFrame*

Use this method to get a pointer to a QFrame where you can place your content. The widget lifetime is managed by qAccordion.

Definition at line 53 of file ContentPane.cpp.

54 {
55  return this->content;
56 }

References content.

Referenced by MaskEditorPropertyPanel::setup_MaskProperties(), MaskEditorPropertyPanel::setup_MaskStack(), MaskEditorPropertyPanel::setup_PlotProperties(), and TestView::test_AccordionWidget().

◆ getHeader()

QString ContentPane::getHeader ( )

Return the header of the content pane.

Returns
QString

Definition at line 87 of file ContentPane.cpp.

88 {
89  return this->header->getHeader();
90 }
QString getHeader()
Get the header string.

References ClickableFrame::getHeader(), and header.

Here is the call graph for this function:

◆ getHeaderFrameStyle()

int ContentPane::getHeaderFrameStyle ( )

Get the header frame style.

Returns
int
See also
setHeaderFrameStyle() for additional information.

Definition at line 127 of file ContentPane.cpp.

128 {
129  return this->header->frameStyle();
130 }

References header.

◆ getHeaderHoverStylesheet()

QString ContentPane::getHeaderHoverStylesheet ( )

Get the mouse over header style sheet.

Returns
CSS Style Sheet as string

Returns the mouse over header style sheet.

Definition at line 117 of file ContentPane.cpp.

118 {
119  return this->header->getHoverStylesheet();
120 }
QString getHoverStylesheet()
Get mouseover stylesheet.

References ClickableFrame::getHoverStylesheet(), and header.

Here is the call graph for this function:

◆ getHeaderStylesheet()

QString ContentPane::getHeaderStylesheet ( )

Get the current header style sheet.

Returns
CSS string

Get the css of the content pane header as QString.

Definition at line 107 of file ContentPane.cpp.

108 {
109  return this->header->getNormalStylesheet();
110 }
QString getNormalStylesheet()
Get the default stylesheet.

References ClickableFrame::getNormalStylesheet(), and header.

Here is the call graph for this function:

◆ getHeaderTooltip()

QString ContentPane::getHeaderTooltip ( )

Get the header tooltip.

Returns
Tooltip as QString

Get the header tooltip as QString.

Definition at line 97 of file ContentPane.cpp.

98 {
99  return this->header->toolTip();
100 }

References header.

◆ getMaximumHeight()

int ContentPane::getMaximumHeight ( )

Get the maximum height of the content pane container frame.

Returns
int

Definition at line 67 of file ContentPane.cpp.

68 {
69  return this->container->maximumHeight();
70 }

References container.

◆ headerClicked

void ContentPane::headerClicked ( )
slot

Slot that is called when the header has been triggered.

Parameters
posCurrently unused

This slot is used to notify the ContentPane widget that the header has been triggered. You can use this slot yourself to open or close the ContentPane. Check the state of the pane before with getActive() as this slot might not do what you intended to do (for example you want to close the ContentPane. If it is already inactive and you call this slot without checking the state it will be opened).

Definition at line 230 of file ContentPane.cpp.

231 {
232  emit this->clicked();
233 }
void clicked()
Clicked signal is emitted when the header is clicked.

References clicked().

Referenced by MaskEditorPropertyPanel::MaskEditorPropertyPanel(), and initHeaderFrame().

◆ initAnimations()

void ContentPane::initAnimations ( )
private

Definition at line 207 of file ContentPane.cpp.

208 {
209  this->openAnimation = std::unique_ptr<QPropertyAnimation>(new QPropertyAnimation());
210  this->closeAnimation = std::unique_ptr<QPropertyAnimation>(new QPropertyAnimation());
211  // TODO: Currently these animations only animate maximumHeight. This leads to
212  // different behaviour depending on whether the Accordion Widget is placed
213  // inside a QScollWidget or not. Maybe we also need to animate minimumHeight
214  // as well to get the same effect.
215  this->openAnimation->setTargetObject(this->container);
216  this->openAnimation->setPropertyName("maximumHeight");
217  this->closeAnimation->setTargetObject(this->container);
218  this->closeAnimation->setPropertyName("maximumHeight");
219 
220  this->openAnimation->setDuration(100);
221  this->closeAnimation->setDuration(100);
222  this->openAnimation->setStartValue(0);
223  this->closeAnimation->setStartValue(this->containerAnimationMaxHeight);
224  this->openAnimation->setEndValue(this->containerAnimationMaxHeight);
225  this->closeAnimation->setEndValue(0);
226  this->openAnimation->setEasingCurve(QEasingCurve(QEasingCurve::Type::Linear));
227  this->closeAnimation->setEasingCurve(QEasingCurve(QEasingCurve::Type::Linear));
228 }
int containerAnimationMaxHeight
Definition: ContentPane.h:289
std::unique_ptr< QPropertyAnimation > openAnimation
Definition: ContentPane.h:293

References closeAnimation, container, containerAnimationMaxHeight, and openAnimation.

Referenced by initDefaults().

◆ initContainerContentFrame()

void ContentPane::initContainerContentFrame ( )
private

Definition at line 189 of file ContentPane.cpp.

190 {
191  this->container = new QFrame();
192  this->container->setLayout(new QVBoxLayout());
193  this->container->setFrameStyle(this->contentPaneFrameStyle);
194  this->container->setMaximumHeight(0);
195  this->container->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Preferred);
196  this->layout()->addWidget(this->container);
197 
198  if (this->content == nullptr) {
199  this->content = new QFrame();
200  }
201 
202  this->container->layout()->addWidget(this->content);
203  this->container->layout()->setSpacing(0);
204  this->container->layout()->setContentsMargins(QMargins());
205 }
int contentPaneFrameStyle
Definition: ContentPane.h:288

References container, content, and contentPaneFrameStyle.

Referenced by initDefaults().

◆ initDefaults()

void ContentPane::initDefaults ( QString  header)
private

Definition at line 160 of file ContentPane.cpp.

161 {
162  this->active = false;
163 
164  this->headerFrameStyle = QFrame::Shape::StyledPanel | QFrame::Shadow::Raised;
165  this->contentPaneFrameStyle = QFrame::Shape::StyledPanel | QFrame::Shadow::Plain;
166  this->containerAnimationMaxHeight = 150;
167  // TODO: Why do I need to set the vertial policy to Maximum? from the api
168  // documentation Minimum would make more sens :/
169  this->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Maximum);
170 
171  this->setLayout(new QVBoxLayout());
172  this->layout()->setSpacing(0);
173  this->layout()->setContentsMargins(QMargins());
174 
175  this->initHeaderFrame(std::move(header));
177  this->initAnimations();
178 }
void initAnimations()
void initHeaderFrame(QString header)
int headerFrameStyle
Definition: ContentPane.h:287
void initContainerContentFrame()

References active, containerAnimationMaxHeight, contentPaneFrameStyle, header, headerFrameStyle, initAnimations(), initContainerContentFrame(), and initHeaderFrame().

Referenced by ContentPane().

Here is the call graph for this function:

◆ initHeaderFrame()

void ContentPane::initHeaderFrame ( QString  header)
private

Definition at line 180 of file ContentPane.cpp.

181 {
182  this->header = new ClickableFrame(std::move(header));
183  this->header->setFrameStyle(this->headerFrameStyle);
184  this->layout()->addWidget(this->header);
185 
186  QObject::connect(this->header, &ClickableFrame::singleClick, this, &ContentPane::headerClicked);
187 }
The ClickableFrame class.
void singleClick(QPoint pos)
Signal that is emitted upon a singleclick.
void headerClicked()
Slot that is called when the header has been triggered.

References header, headerClicked(), headerFrameStyle, and ClickableFrame::singleClick().

Referenced by initDefaults().

Here is the call graph for this function:

◆ isActive

void ContentPane::isActive ( )
signal

Signal will be emitted after the open animation finished.

◆ isInactive

void ContentPane::isInactive ( )
signal

Signal will be emitted after the close animation finished.

◆ openContentPane

void ContentPane::openContentPane ( )
privateslot

Open the content pane.

This will open the content pane if it is currently closed.

Warning
Currently there is no inbuild mechanism to close an already open Content Pane when you open another one programmatically. Meaning you have to take care of this yourself.

Definition at line 142 of file ContentPane.cpp.

143 {
144  if (this->getActive())
145  return;
146  this->openAnimation->start();
148  this->active = true;
149 }
const char *const CARRET_ICON_OPENED
Qt qrc "path" for the opened icon.

References active, ClickableFrame_constants::CARRET_ICON_OPENED, getActive(), header, openAnimation, and ClickableFrame::setCaretPixmap().

Referenced by AccordionWidget::handleClickedSignal().

Here is the call graph for this function:

◆ paintEvent()

void ContentPane::paintEvent ( ATTR_UNUSED QPaintEvent *  event)
protected

paintEvent Reimplement paintEvent to use stylesheets in derived Widgets

Parameters
event

Definition at line 235 of file ContentPane.cpp.

236 {
237  QStyleOption o;
238  o.initFrom(this);
239  QPainter p(this);
240  style()->drawPrimitive(QStyle::PE_Widget, &o, &p, this);
241 }

◆ setAnimationDuration()

void ContentPane::setAnimationDuration ( uint  duration)

Set the duration for the open and close animation.

Parameters
durationDuration in milliseconds

Set the duration of the QPropertyAnimation in milliseconds.

◆ setContainerFrameStyle()

void ContentPane::setContainerFrameStyle ( int  style)

Set the container frame style.

Parameters
style
See also
setHeaderFrameStyle() for additional information

Definition at line 132 of file ContentPane.cpp.

133 {
134  this->container->setFrameStyle(style);
135 }

References container.

Referenced by MaskEditorPropertyPanel::setup_MaskProperties(), MaskEditorPropertyPanel::setup_MaskStack(), and MaskEditorPropertyPanel::setup_PlotProperties().

◆ setContentFrame()

void ContentPane::setContentFrame ( QFrame *  content)

Set the content frame.

Parameters
contentQFrame* with your content

Set / change the content frame of this content pane with content. The lifecycle

Definition at line 58 of file ContentPane.cpp.

59 {
60  this->container->layout()->removeWidget(this->content);
61  if (this->content != nullptr)
62  delete (this->content);
63  this->content = content;
64  dynamic_cast<QVBoxLayout*>(this->container->layout())->insertWidget(0, this->content);
65 }

References container, and content.

◆ setHeader()

void ContentPane::setHeader ( QString  header)

Set the header of the content pane.

Parameters
header

Definition at line 82 of file ContentPane.cpp.

83 {
84  this->header->setHeader(std::move(header));
85 }
void setHeader(QString header)
Set the header string.

References header.

◆ setHeaderFrameStyle()

void ContentPane::setHeaderFrameStyle ( int  style)

Set the header frame style.

Parameters
style

The style is the bitwise OR between a frame shape and a frame shadow style. See the Qt Documentation for additional details.

Definition at line 122 of file ContentPane.cpp.

123 {
124  this->header->setFrameStyle(style);
125 }

References header.

◆ setHeaderHoverStylesheet()

void ContentPane::setHeaderHoverStylesheet ( QString  stylesheet)

Set a stylesheet for the header frame when the mouse hovers over it.

Parameters
stylesheetCSS Style Sheet as string

Set a stylesheet for the header for a special effect when the mouse hovers over it.

See also
setHeaderStylesheet() for additional details.

Definition at line 112 of file ContentPane.cpp.

113 {
114  this->header->setHoverStylesheet(std::move(stylesheet));
115 }
void setHoverStylesheet(QString stylesheet)
Set mouseover stylesheet.

References header, and ClickableFrame::setHoverStylesheet().

Here is the call graph for this function:

◆ setHeaderStylesheet()

void ContentPane::setHeaderStylesheet ( QString  stylesheet)

Set a stylesheet for the header frame.

Parameters
stylesheetCSS Style Sheet as string

You can use Cascading Style Sheets as supported by Qt to style the header. This is the standard style sheet. You may also set a style for mouse over with setHeaderHoverStylesheet().

Definition at line 102 of file ContentPane.cpp.

103 {
104  this->header->setNormalStylesheet(std::move(stylesheet));
105 }
void setNormalStylesheet(QString stylesheet)
Set the default stylesheet.

References header, and ClickableFrame::setNormalStylesheet().

Here is the call graph for this function:

◆ setHeaderTooltip()

void ContentPane::setHeaderTooltip ( QString  tooltip)

Set header tooltip.

Parameters
tooltipString to show as tooltip

Set a string as header tooltip that will be shown when the mouse hovers over the header area.

Definition at line 92 of file ContentPane.cpp.

93 {
94  this->header->setToolTip(tooltip);
95 }

References header.

Referenced by MaskEditorPropertyPanel::setup_MaskProperties(), MaskEditorPropertyPanel::setup_MaskStack(), and MaskEditorPropertyPanel::setup_PlotProperties().

◆ setMaximumHeight()

void ContentPane::setMaximumHeight ( int  maxHeight)

Set the maximum height of the content pane container.

Parameters
maxHeight

Every content pane has a container frame that defines the visible maximum height. With this function you can change this setting.

Note
This setting does not set the maximum height of the content frame. It is the users responsibilty to make sure everything in the content frame is visible. This can be influenced by either changing the maximum height of the container or for example by adding a QScrollArea.

Definition at line 72 of file ContentPane.cpp.

73 {
74  this->containerAnimationMaxHeight = maxHeight;
75 
76  if (this->getActive())
77  this->container->setMaximumHeight(this->containerAnimationMaxHeight);
78  this->openAnimation->setEndValue(this->containerAnimationMaxHeight);
79  this->closeAnimation->setStartValue(this->containerAnimationMaxHeight);
80 }

References closeAnimation, container, containerAnimationMaxHeight, getActive(), and openAnimation.

Referenced by MaskEditorPropertyPanel::setup_MaskProperties(), MaskEditorPropertyPanel::setup_MaskStack(), MaskEditorPropertyPanel::setup_PlotProperties(), and TestView::test_AccordionWidget().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ AccordionWidget

friend class AccordionWidget
friend

Definition at line 281 of file ContentPane.h.

Member Data Documentation

◆ active

bool ContentPane::active
private

Definition at line 291 of file ContentPane.h.

Referenced by closeContentPane(), getActive(), initDefaults(), and openContentPane().

◆ closeAnimation

std::unique_ptr<QPropertyAnimation> ContentPane::closeAnimation
private

Definition at line 294 of file ContentPane.h.

Referenced by closeContentPane(), initAnimations(), and setMaximumHeight().

◆ container

◆ containerAnimationMaxHeight

int ContentPane::containerAnimationMaxHeight
private

Definition at line 289 of file ContentPane.h.

Referenced by initAnimations(), initDefaults(), and setMaximumHeight().

◆ content

QFrame* ContentPane::content
private

◆ contentPaneFrameStyle

int ContentPane::contentPaneFrameStyle
private

Definition at line 288 of file ContentPane.h.

Referenced by initContainerContentFrame(), and initDefaults().

◆ header

◆ headerFrameStyle

int ContentPane::headerFrameStyle
private

Definition at line 287 of file ContentPane.h.

Referenced by initDefaults(), and initHeaderFrame().

◆ openAnimation

std::unique_ptr<QPropertyAnimation> ContentPane::openAnimation
private

Definition at line 293 of file ContentPane.h.

Referenced by initAnimations(), openContentPane(), and setMaximumHeight().


The documentation for this class was generated from the following files: