CDPBaseContainer Class
The Container is a container widget that supports both SVG themes and ordinary pixmap backgrounds. More...
Header: | #include <CDPBaseWidgets/CDPBaseContainer.h> |
Inherits: | CDPBaseWidget and RoutingContainerBase |
Inherited By: |
Public Types
typedef | ContainerSvgMap |
enum | ContainerType { Custom, Container, Title, CSS } |
Properties
|
|
- 6 properties inherited from CDPBaseWidget
Public Functions
CDPBaseContainer(QWidget *parent = 0) | |
virtual | ~CDPBaseContainer() |
virtual int | animHeightMs() |
virtual int | animHeightPx() |
virtual bool | animStartIsMax() |
virtual int | animWidthMs() |
virtual int | animWidthPx() |
virtual bool | animate() |
virtual int | borderMarginBottom() |
const QMargins & | borderMarginInUse() |
virtual int | borderMarginLeft() |
virtual int | borderMarginRight() |
virtual int | borderMarginTop() |
virtual QMargins | borderMargins() |
virtual QString | borderPixmap() |
virtual ContainerType | containerType() |
virtual QString | cssFile() |
virtual bool | isCustom() |
QString | overlayUiFile() const |
bool | overlayVisible() const |
QString | overlayVisibleRouting() |
void | resizeEvent(QResizeEvent *event) override |
virtual void | setAnimHeightMs(int value) |
virtual void | setAnimHeightPx(int value) |
virtual void | setAnimStartIsMax(bool max) |
virtual void | setAnimWidthMs(int value) |
virtual void | setAnimWidthPx(int value) |
virtual void | setAnimate(bool anim) |
virtual void | setBorderMarginBottom(int bottom) |
virtual void | setBorderMarginLeft(int left) |
virtual void | setBorderMarginRight(int right) |
virtual void | setBorderMarginTop(int top) |
virtual void | setBorderMargins(QMargins margins) |
virtual void | setBorderPixmap(QString name) |
virtual void | setContainerType(ContainerType type) |
virtual void | setCssFile(QString cssFile) |
virtual void | setOverlayUiFile(const QString &filename) |
void | setOverlayVisibleRouting(const QString &routing) |
virtual void | setSvgBorderMargin(bool enable) |
virtual void | setVisibleAboveWindowWidth(int value) |
virtual void | setVisibleBelowWindowWidth(int value) |
QSize | sizeHint() const override |
virtual bool | svgBorderMargin() |
virtual bool | usingSvgBorderMargins() |
virtual int | visibleAboveWindowWidth() |
virtual int | visibleBelowWindowWidth() |
- 8 public functions inherited from CDPBaseWidget
- 3 public functions inherited from RoutingContainerBase
- 4 public functions inherited from CDPBaseControlVisible
Public Slots
virtual void | animateHeight() |
virtual void | animateHeight(bool increase) |
virtual void | animateHeightToMax() |
virtual void | animateHeightToMin() |
virtual void | animateWidth() |
virtual void | animateWidth(bool increase) |
virtual void | animateWidthToMax() |
virtual void | animateWidthToMin() |
virtual void | polishStyle() |
virtual void | resetToCdp() |
virtual void | sendToCdp() |
virtual void | setOverlayVisible(bool show) |
virtual void | setWidgetStyle(int style) |
virtual void | setWidgetTheme(const QString &theme) |
- 10 public slots inherited from CDPBaseWidget
Protected Functions
virtual void | clearSvg() |
virtual void | loadPixmaps() |
virtual void | paintEvent(QPaintEvent *ev) |
virtual void | processSvgFile(QString svg) |
Reimplemented Protected Functions
virtual void | setWidgetVisible(bool visible) override |
- 1 protected function inherited from CDPBaseControlVisible
Additional Inherited Members
- 1 signal inherited from CDPBaseWidget
Detailed Description
The Container is a container widget that supports both SVG themes and ordinary pixmap backgrounds.
In addition to being an ordinary widget container, it is commonly used to group menu buttons. The container includes properties for animating size which can be used to hide/show the menu. Connect any clickable widget to different slots to animate on height or width, but note that animations will only work when the container is placed in a layout.
The following describes how to hide and show a vertical container side menu using a button in a top menu: Connect the button signal named, clicked() to the container slot named animateWidth(). The button can now be clicked to hide or show the menu and thus make extra space for the page elements. Read more about widget connections in the Design Mode Manual.
The container also supports showing a UI/form file as an overlay on top of its contents. This is typically used to show alarm states or important control system messages. When the overlay is visible the container contents is not clickable.
The container can be used to set styling on child widgets. Internally, it has a theme property that always contains the name of the current theme. This enables theme specific styling for all children that can be styled by CSS. For instance, if wanting to style all label children with a certain text color. The following could be added to the styleSheet property:
CDPBaseContainer[theme="flat_gray"] CDPBaseLabel { color: red; } CDPBaseContainer[theme="flat_gray_light"] CDPBaseLabel { color: yellow; }
This requires that the labels are not configured with a styling type or stylesheet that will override the styling set by the container.
To provide the code in a reusable CSS file, we could move the theme specific styling to a separate file and update the type and cssFile properties accordingly. For total theme separation, we could split the theme specific styling into separate files for each theme and remove the theme selection part. In that case, the file for the flat_gray theme would only include the following:
CDPBaseLabel { color: red; }
The stylesheet can also be used to set widget properties. This is done by adding the keyword qproperty-, in front of the property name you would like to set. For instance, the following could be added to set the text of a label depending on the current theme:
CDPBaseContainer[theme="flat_gray"] CDPBaseLabel { qproperty-text: "Red"; } CDPBaseContainer[theme="flat_gray_light"] CDPBaseLabel { qproperty-text: "Yellow"; }
Note: Selecting CSS as the styling type without adding a CSS file will make the container background transparent.
Styling by SVG
Use the svgFile property to style the widget using a SVG file. Styling by SVG enables switching between different themes in runtime (as long as the files are placed at identical locations within theme directories).
Main element structure
The following tree view shows the SVG structure that can be used on the CDPBaseContainer.
svg └─── Layer1 ├─── cdpBorderMarginTopLeft (transparent rect/path) ├─── cdpBorderMarginBottomRight (transparent rect/path) └─── cdpBackground (element group) ├─── < Path > (transparent rect/path) └─── < Group > (background graphics)
The following table explains the named elements in more detail.
Property | Type | Description |
---|---|---|
cdpBorderMarginTopLeft | rect | Transparent rectangle that specifies the left border margin by its width and the top border margin by its height. |
cdpBorderMarginBottomRight | rect | Transparent rectangle that specifies the right border margin by its width and the bottom border margin by its height. |
cdpBackground | rect or an element group containing a rect | The cdpBackground should contain the actual background graphics. To ensure that the SVG parser gets the correct background size (and aspect ratio), we have to place a transparent rect along with the graphics within a group element. |
Note: Elements that are written with pointy brackets, like < Path >, can be given any name. Avoid cdp prefix as these are special to the parser.
Style element structure
The container supports the following style structure.
svg ├─── Layer1 │ └─── ... (see previous section) └─── Styles └─── cdpBackgroundStyleX (element group) ├─── < Path > (transparent rect/path) └─── < Group > (background graphics)
Member Type Documentation
typedef CDPBaseContainer::ContainerSvgMap
enum CDPBaseContainer::ContainerType
This enum type specifies styling types that can be used on the container:
Constant | Value | Description |
---|---|---|
CDPBaseContainer::Custom | 0 | Style the widget with a custom border pixmap. |
CDPBaseContainer::Container | 1 | Style the widget using default container border pixmap. |
CDPBaseContainer::Title | 2 | Style the widget with default title background. |
CDPBaseContainer::CSS | 3 | Style the widget using a css file. |
Property Documentation
animEnable : bool
This property holds whether to enable size animation triggered by qt signals and slots.
Setting animEnabled to true
, allows us to connect the slots named animateHeight() and animateWidth() and initiate/toggle the containers height and width. The distance is specified by animHeightPx and animWidthPx while animation duration is set in animHeightMs and animWidthMs.
Note: that the container must be in a layout for the animation to work.
Access functions:
virtual bool | animate() |
virtual void | setAnimate(bool anim) |
See also animHeightPx, animWidthPx, animHeightMs, and animWidthMs.
animHeightMs : int
This property holds the duration of the height animation.
Access functions:
virtual int | animHeightMs() |
virtual void | setAnimHeightMs(int value) |
See also animHeightPx, animEnable, animWidthMs, and animWidthPx.
animHeightPx : int
This property holds the distance to move during height animation.
Access functions:
virtual int | animHeightPx() |
virtual void | setAnimHeightPx(int value) |
See also animWidthPx, animEnable, animHeightMs, and animWidthMs.
animStartIsMax : bool
This property holds whether or not the initial size is max or min.
Access functions:
virtual bool | animStartIsMax() |
virtual void | setAnimStartIsMax(bool max) |
See also animHeightPx, animEnable, animWidthMs, animWidthPx, and animHeightMs.
animWidthMs : int
This property holds the duration of the width animation.
Access functions:
virtual int | animWidthMs() |
virtual void | setAnimWidthMs(int value) |
See also animHeightPx, animEnable, animHeightMs, and animWidthPx.
animWidthPx : int
This property holds the distance to move during width animation.
Access functions:
virtual int | animWidthPx() |
virtual void | setAnimWidthPx(int value) |
See also animHeightPx, animEnable, animHeightMs, and animWidthMs.
borderMarginBottom : int
This property holds the bottom border margin.
Note that it will show the svg border margin if the svgBorderMargins property is set.
Access functions:
virtual int | borderMarginBottom() |
virtual void | setBorderMarginBottom(int bottom) |
See also borderPixmap and svgBorderMargins.
borderMarginLeft : int
This property holds the left border margin.
Note that it will show the svg border margin if the svgBorderMargins property is set.
Access functions:
virtual int | borderMarginLeft() |
virtual void | setBorderMarginLeft(int left) |
See also borderPixmap and svgBorderMargins.
borderMarginRight : int
This property holds the right border margin.
Note that it will show the svg border margin if the svgBorderMargins property is set.
Access functions:
virtual int | borderMarginRight() |
virtual void | setBorderMarginRight(int right) |
See also borderPixmap and svgBorderMargins.
borderMarginTop : int
This property holds the top border margin.
Note that it will show the svg border margin if the svgBorderMargins property is set.
Access functions:
virtual int | borderMarginTop() |
virtual void | setBorderMarginTop(int top) |
See also borderPixmap and svgBorderMargins.
borderPixmap : QString
This property holds the border pixmap to show in the container.
The path can be either to a resource or a file on a disk. Note that resources can be overridden by files on disk with identical names. The property can only be edited when the type property is set to "Custom".
Access functions:
virtual QString | borderPixmap() |
virtual void | setBorderPixmap(QString name) |
See also svgBorderMargins.
cdpFullTargetRouting : const QString
This property holds the context routing when the cdpTargetRouting contains relative routing.
cdpTargetRouting : const QString
This property holds the target routing that will be used as base for relative routing in child widget properties.
cssFile : QString
This property holds the css file to style the widget.
Similar to the borderPixmap, the path is updated for the selected theme. Note that when both a css file and a borderPixmap is present, we have to select the CSS type to disable borderPixmap (for instance to style the container itself).
Access functions:
virtual QString | cssFile() |
virtual void | setCssFile(QString cssFile) |
See also borderPixmap.
overlayUiFile : QString
This property holds the ui file to show as overlay on top of the container.
An overlay usually includes transparency and is used to cover different parts of the container. It can be used to show notification icons, text for offline state, or other graphics that can be turned on or off as a top layer.
The overlay is toggled on and off using the property named overlayVisible or by configuring routing in overlayVisibleRouting.
An example ui file could be a form based on CDPBaseContainer, configured with type set to CSS and cssFile set to themes/<theme name>/backgrounds/overlay.css.
Access functions:
QString | overlayUiFile() const |
virtual void | setOverlayUiFile(const QString &filename) |
See also overlayVisible and overlayVisibleRouting.
overlayVisible : bool
This property holds whether to show or hide the overlay provided in overlayUiFile.
Access functions:
bool | overlayVisible() const |
virtual void | setOverlayVisible(bool show) |
See also overlayUiFile and overlayVisibleRouting.
overlayVisibleRouting : QString
This property holds routing for controlling overlayVisible property.
The user can also show and hide the overlay by toggling the overlayVisible property directly.
To have something to show and hide, the property named overlayUiFile must be configured.
Access functions:
QString | overlayVisibleRouting() |
void | setOverlayVisibleRouting(const QString &routing) |
See also overlayVisible and overlayUiFile.
svgBorderMargins : bool
This property holds whether to use the border margins provided in the svg file.
Note: the borderMargin properties will show the svg border margins when svgBorderMargins is set. Trying to change the borderMargins while svgBorderMargins is enabled will change the non svg border margins, but the changes wont show until the svgBorderMargins property is set to false.
Access functions:
virtual bool | svgBorderMargin() |
virtual void | setSvgBorderMargin(bool enable) |
See also borderPixmap, borderMarginBottom, borderMarginLeft, borderMarginTop, and borderMarginRight.
type : ContainerType
This property holds the styling type to use when styling the widget.
Setting it to "Custom", "Container" or "Title", changes the string in the borderPixmap property. The only difference is that the borderPixmap property can only be edited when type is set to "Custom". The type named "CSS" is different as it disables the borderPixmap and selects cssFile instead. When no cssFile is specified, the widget will function as an ordinary qt widget and show as transparent.
Access functions:
virtual ContainerType | containerType() |
virtual void | setContainerType(ContainerType type) |
See also borderPixmap and cssFile.
visibleAboveWindowWidth : int
Access functions:
virtual int | visibleAboveWindowWidth() |
virtual void | setVisibleAboveWindowWidth(int value) |
visibleBelowWindowWidth : int
Access functions:
virtual int | visibleBelowWindowWidth() |
virtual void | setVisibleBelowWindowWidth(int value) |
Member Function Documentation
CDPBaseContainer::CDPBaseContainer(QWidget *parent = 0)
Default constructs an instance of CDPBaseContainer.
[virtual]
CDPBaseContainer::~CDPBaseContainer()
Destroys the instance of CDPBaseContainer. The destructor is virtual.
[virtual slot]
void CDPBaseContainer::animateHeight()
[virtual slot]
void CDPBaseContainer::animateHeight(bool increase)
[virtual slot]
void CDPBaseContainer::animateHeightToMax()
[virtual slot]
void CDPBaseContainer::animateHeightToMin()
[virtual slot]
void CDPBaseContainer::animateWidth()
[virtual slot]
void CDPBaseContainer::animateWidth(bool increase)
[virtual slot]
void CDPBaseContainer::animateWidthToMax()
[virtual slot]
void CDPBaseContainer::animateWidthToMin()
const QMargins &CDPBaseContainer::borderMarginInUse()
[virtual]
QMargins CDPBaseContainer::borderMargins()
See also setBorderMargins().
[virtual protected]
void CDPBaseContainer::clearSvg()
[virtual]
bool CDPBaseContainer::isCustom()
[virtual protected]
void CDPBaseContainer::loadPixmaps()
[virtual protected]
void CDPBaseContainer::paintEvent(QPaintEvent *ev)
[virtual slot]
void CDPBaseContainer::polishStyle()
[virtual protected]
void CDPBaseContainer::processSvgFile(QString svg)
[virtual slot]
void CDPBaseContainer::resetToCdp()
Executing this slot will reset widgets in the container to the value of their routed CDP object.
The functionality is often used in settings dialogs to make widgets like spin boxes, line edits, and combo boxes revert to remote values when the user clicks Cancel. Usually, these widgets are configured to not send user changes to the control system until the user clicks OK or Save. This is achieved by configuring the widgets to update on slot only (e.g. CDPBaseSpinBox::updateOnSlotOnly). Dialog buttons like OK and Save can connect to the slot named sendToCdp to make widgets send their values to routed CDP objects.
Note that the reset will only get executed on child widgets that inherit the ICDPSendAndReset interface.
See also sendToCdp.
void CDPBaseContainer::resizeEvent(QResizeEvent *event)
[virtual slot]
void CDPBaseContainer::sendToCdp()
Executing this slot will request widgets in the container to send their values to routed CDP objects.
The functionality is often used in settings dialogs as described in resetToCdp.
Note that the send request will only get executed on child widgets that inherit the ICDPSendAndReset interface.
See also resetToCdp.
[virtual]
void CDPBaseContainer::setBorderMargins(QMargins margins)
See also borderMargins().
[virtual slot]
void CDPBaseContainer::setWidgetStyle(int style)
[virtual slot]
void CDPBaseContainer::setWidgetTheme(const QString &theme)
[override virtual protected]
void CDPBaseContainer::setWidgetVisible(bool visible)
QSize CDPBaseContainer::sizeHint() const
[virtual]
bool CDPBaseContainer::usingSvgBorderMargins()
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.