CDPBaseToggleButton Class
The Toggle Button is an on/off button that can send and receive values from remote or local cdp communication objects like signals and parameters. It can also be used to send messages and toggle based on remote state values. More...
Header: | #include <CDPBaseWidgets/CDPBaseToggleButton.h> |
Inherits: | CDPBaseWidget, StateChanger, and CDPBaseCom |
Public Types
typedef | ToggleButtonSvgMap |
enum | ToggleButtonType { Custom, Default } |
Properties
|
|
- 6 properties inherited from CDPBaseWidget
Public Functions
CDPBaseToggleButton(QWidget *parent = 0) | |
virtual | ~CDPBaseToggleButton() |
bool | allowBorderPix() |
double | buttonPos() |
ToggleButtonType | buttonType() |
QString | cdpEnabledRouting() |
virtual QString | cdpPropValueOff() |
virtual QString | cdpPropValueOn() |
QString | cdpStyle() |
virtual QString | cdpTextMsgOff() |
virtual QString | cdpTextMsgOn() |
QString | cdpTextMsgRouting() |
virtual bool | checked() |
virtual double | disabledStateOpacity() const |
bool | isCustom() |
const QString & | leftText() |
const QColor & | leftTextColor() |
const QString & | rightText() |
const QColor & | rightTextColor() |
virtual QString | routing() |
virtual void | setAllowBorderPix(bool allow) |
void | setButtonPos(double pos) |
virtual void | setButtonType(ToggleButtonType type) |
void | setCdpEnabledRouting(QString routing) |
virtual void | setCdpPropValueOff(QString routing) |
virtual void | setCdpPropValueOn(QString routing) |
void | setCdpStyle(QString routing) |
virtual void | setCdpTextMsgOff(QString routing) |
virtual void | setCdpTextMsgOn(QString routing) |
void | setCdpTextMsgRouting(QString routing) |
virtual void | setDisabledStateOpacity(double opacity) |
void | setLeftText(const QString &text) |
void | setLeftTextColor(const QColor &text) |
void | setRightText(const QString &text) |
void | setRightTextColor(const QColor &text) |
virtual void | setRouting(QString routing) |
void | setSvgFile(const QString &svg) |
const QString & | svgFile() |
- 8 public functions inherited from CDPBaseWidget
- 3 public functions inherited from StateChanger
- 17 public functions inherited from CDPBaseCom
- 4 public functions inherited from CDPBaseControlVisible
Public Slots
virtual void | PropertyChanged(std::string strFullPropertyName, std::string strNewPropertyValue) |
virtual void | setChecked(bool checked = true, bool updateCdp = true) |
virtual void | setInCommand(bool cmd) |
virtual void | setValue(double value) |
virtual void | setWidgetFont(const QString &font) |
virtual void | setWidgetStyle(int style) |
virtual void | setWidgetTheme(const QString &theme) |
- 10 public slots inherited from CDPBaseWidget
Signals
- 1 signal inherited from CDPBaseWidget
Protected Functions
double | buttonMaxPos() |
double | buttonWidth() |
void | changeEvent(QEvent *e) override |
void | drawBorderPixmap(QPixmap &pix, const QPixmap &borderPix, QSize pixSize) |
void | loadPixmap(QPixmap &pix, const ParserSVG::StyleMap &map, QSize pixSize = QSize(), QSizeF paintSize = QSize()) |
void | loadPixmapDisabled(QPixmap &pixmapDisabled) |
void | loadPixmaps() |
virtual QSize | minimumSizeHint() const |
virtual void | mouseMoveEvent(QMouseEvent *ev) |
virtual void | mousePressEvent(QMouseEvent *ev) |
virtual void | mouseReleaseEvent(QMouseEvent *ev) |
virtual void | paintEvent(QPaintEvent *ev) |
virtual void | resizeEvent(QResizeEvent *ev) |
virtual QSize | sizeHint() const |
void | updateTextColorsFromSvg() |
- 4 protected functions inherited from CDPBaseCom
- 1 protected function inherited from CDPBaseControlVisible
Protected Slots
virtual void | checkEnable(double value) |
virtual void | emitToggled() |
void | initDeprecated() |
virtual void | updateFromCdp() |
Additional Inherited Members
- 2 static public members inherited from CDPBaseCom
Detailed Description
The Toggle Button is an on/off button that can send and receive values from remote or local cdp communication objects like signals and parameters. It can also be used to send messages and toggle based on remote state values.
The following two examples shows the main usage of the button. Note that toggling is not only done by the values 0
and 1
. The user can add any values/text by using the properties, cdpValueOn and cdpValueOff.
How to toggle a remote CDP object value
- All you need is the routing to the property value of the object.
- Use cdpValueOff and cdpValueOn to choose different values than
0
and1
. - Make sure that cdpTextMsgOn and cdpTextMsgOff is not set.
How to toggle component states
- This requires that the component has at least two states and messages handlers to control it.
- Configure routing to the component
CurrentState
, cdpRouting =Application.FilterComponent.CurrentState
- Configure the states that are to toggle the button, cdpValueOn =
On
(all other states will toggle the button off). - Configure the messages that will trigger the component to switch state, cdpTextMsgOn =
TurnOn
and cdpTextMsgOff =TurnOff
In CDP version 4.7, a third option was introduced. Now, the user can configure, cdpTextMsgRouting, to specify a different destination for cdpTextMsgOn and cdpTextMsgOff than the parent of the object routed in cdpRouting.
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 shows the svg structure that can be used on the CDPBaseToggleButton.
svg └─── Layer1 ├─── cdpTextOn (text) ├─── cdpTextOff (text) ├─── cdpBorderMarginTopLeft (transparent rect/path) ├─── cdpBorderMarginBottomRight (transparent rect/path) ├─── cdpButton (element group) │ ├─── < Path > (transparent rect/path) │ └─── < Group > (actual graphics) ├─── cdpButtonOff (element group) │ ├─── < Path > (transparent rect/path) │ └─── < Group > (actual graphics) ├─── cdpButtonDisabled (element group) │ ├─── < Path > (transparent rect/path) │ └─── < Group > (actual graphics) ├─── cdpButtonOffDisabled (element group) │ ├─── < Path > (transparent rect/path) │ └─── < Group > (actual graphics) ├─── cdpBackground (element group) │ ├─── < Path > (transparent rect/path) │ └─── < Group > (actual graphics) ├─── cdpBackgroundOff (element group) │ ├─── < Path > (transparent rect/path) │ └─── < Group > (actual graphics) ├─── cdpBackgroundDisabled (element group) │ ├─── < Path > (transparent rect/path) │ └─── < Group > (actual graphics) └─── cdpBackgroundOffDisabled (element group) ├─── < Path > (transparent rect/path) └─── < Group > (actual graphics)
The following table explains the named elements in more detail.
Property | Type | Description |
---|---|---|
cdpTextOn | text | The color and size of the font to be used in the button on state. Use opacity to control text transparency. |
cdpTextOff | text | The color and size of the font to be used in the button off state. Use opacity to control text transparency. |
cdpBorderMarginBottomRight | rect | Transparent rectangle that specifies the right border margin by its width and the bottom border margin by its height. |
cdpBorderMarginTopLeft | rect | Transparent rectangle that specifies the left border margin by its width and the top border margin by its height. |
cdpButton | rect or an element group containing a rect | The cdpButton should contain the actual button 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. |
cdpButtonOff | rect or an element group containing a rect | The cdpButtonOff is similar to the cdpButton element, but will show when the button is in unchecked/off state. |
cdpButtonDisabled | rect or an element group containing a rect | The cdpButtonDisabled element is used to style the button when it is both checked and disabled. |
cdpButtonOffDisabled | rect or an element group containing a rect | The cdpButtonOffDisabled element is used to style the button when it is unchecked and disabled. Skipping this element will instead use cdpButtonDisabled. |
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. |
cdpBackgroundOff | rect or an element group containing a rect | The cdpBackgroundOff is similar to the cdpBackground element, but will show when the button is in unchecked/off state. |
cdpBackgroundDisabled | rect or an element group containing a rect | The cdpBackgroundDisabled is similar to the cdpBackground element, but will show when the button is both checked and disabled. |
cdpBackgroundOffDisabled | rect or an element group containing a rect | The cdpBackgroundOffDisabled is similar to the cdpBackgroundOff element, but will show when the button is both unchecked and disabled. Skipping this element will instead use cdpBackgroundDisabled. |
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.
Note: Skipping both cdpButtonDisabled and cdpBackgroundDisabled will trigger opacity in the disabled state. It is also possible to force the opacity to any level using the property named disabledStateOpacity.
Style element structure
The toggle button also supports styles that can be changed by the widgetStyle property or by cdp signal/object. Styles makes it possible to change colors and shape of button, background and texts.
svg ├─── Layer1 │ └─── ... (see previous section) └─── Styles ├─── cdpTextOnStyleX (text) ├─── cdpTextOffStyleX (text) ├─── cdpButtonStyleX (element group) │ ├─── < Path > (transparent rect/path) │ └─── < Group > (button graphics) └─── cdpBackgroundStyleX (element group) ├─── < Path > (transparent rect/path) └─── < Group > (actual graphics)
How to handle round designs
The toggle button allows border margins by default as this will make the widget scalable to any size while maintaining its corner radius. On rounded designs, however, this is not always what we want. To enable buttons to be circular with a round knob, we might need to turn off border margins by setting the property named, allowBorderMargins to false
. This is often used in combination with the minimumSize and maximumSize properties to tweak the button into looking good.
Member Type Documentation
typedef CDPBaseToggleButton::ToggleButtonSvgMap
enum CDPBaseToggleButton::ToggleButtonType
Property Documentation
allowBorderPix : bool
This property holds whether to enable or disable border pixmap provided by the svg file.
The border pixmap makes the button maintain its corners and border sizes while being resized.
Access functions:
bool | allowBorderPix() |
virtual void | setAllowBorderPix(bool allow) |
cdpEnabledRouting : QString
This property holds the routing to the cdp object that is used to enable or disable the widget.
Access functions:
QString | cdpEnabledRouting() |
void | setCdpEnabledRouting(QString routing) |
cdpOfflineValue : const double
This property holds the value to show when communication is offline and cdpOfflineValueEnabled is set to true.
The property has no effect when cdpOfflineValueEnabled is set to false
.
See also cdpOfflineValueEnabled.
cdpOfflineValueEnabled : const bool
This property holds whether or not to show cdpOfflineValue when communication is offline.
Setting the property to false
will make the widget keep/show the last value when communication is down.
See also cdpOfflineValue.
cdpRouting : QString
This property holds the routing to the cdp object we want connect to. The object will control the state of the button. Messages configured in cdpTextMsgOn and cdpTextMsgOff are sent to the parent of the routed object unless cdpTextMsgRouting is configured.
Access functions:
virtual QString | routing() |
virtual void | setRouting(QString routing) |
See also cdpTextMsgRouting, cdpValueOn, and cdpValueOff.
cdpStyleRouting : QString
This property holds the routing to the cdp object that is used to change the widget svg style.
Access functions:
QString | cdpStyle() |
void | setCdpStyle(QString routing) |
cdpTextMsgOff : QString
This property holds the CDPMessage to send to the application when the button state changes to unchecked.
Access functions:
virtual QString | cdpTextMsgOff() |
virtual void | setCdpTextMsgOff(QString routing) |
See also cdpTextMsgOn.
cdpTextMsgOn : QString
This property holds the CDPMessage to send to the application when the button state changes to checked.
Access functions:
virtual QString | cdpTextMsgOn() |
virtual void | setCdpTextMsgOn(QString routing) |
See also cdpTextMsgOff.
cdpTextMsgRouting : QString
This property holds the routing to the cdp object that we want to message. When not set, messages are sent to the parent of object routed in cdpRouting.
Access functions:
QString | cdpTextMsgRouting() |
void | setCdpTextMsgRouting(QString routing) |
See also cdpTextMsgOn and cdpTextMsgOff.
cdpValueOff : QString
This property holds the value which should set the CDPBaseToggleButton state to unchecked.
Can be a state or a numeric value.
Note: If this value is set and cdpValueOn is not, then every other value will set the button state to checked.
Access functions:
virtual QString | cdpPropValueOff() |
virtual void | setCdpPropValueOff(QString routing) |
See also cdpValueOn and cdpRouting.
cdpValueOn : QString
This property holds the value which should set the CDPBaseToggleButton state to checked.
Can be a state or a numeric value.
Note: If this value is set, every other value will set the button state to unchecked.
Access functions:
virtual QString | cdpPropValueOn() |
virtual void | setCdpPropValueOn(QString routing) |
See also cdpValueOff and cdpRouting.
checked : bool
This property holds whether the slider is checked (right position) or not (left position).
Access functions:
virtual bool | checked() |
virtual void | setChecked(bool checked = true, bool updateCdp = true) |
disabledStateOpacity : double
This property holds the level of opacity for the widget in the disabled state.
The valid range of opacity is from 1.0 (completely opaque) to 0.0 (completely transparent).
Setting this property configures a fixed opacity that can be different than the global opacity used in other widgets.
Access functions:
virtual double | disabledStateOpacity() const |
virtual void | setDisabledStateOpacity(double opacity) |
svgFile : QString
This property holds the path to the svg file that styles the widget.
The path can be either to a resource or a file on disk.
Note: Resources can be overridden by files on disk with identical names.
Access functions:
const QString & | svgFile() |
void | setSvgFile(const QString &svg) |
See also type.
textLeft : QString
This property holds the text on the left side of the button (checked text).
Access functions:
const QString & | leftText() |
void | setLeftText(const QString &text) |
See also checked and textRight.
textLeftColor : QColor
This property holds the color of the left side text (checked text).
Access functions:
const QColor & | leftTextColor() |
void | setLeftTextColor(const QColor &text) |
See also textLeft.
textRight : QString
This property holds the text on the right side of the button (unchecked text).
Access functions:
const QString & | rightText() |
void | setRightText(const QString &text) |
See also checked and textLeft.
textRightColor : QColor
This property holds the color of the right side text (unchecked text).
Access functions:
const QColor & | rightTextColor() |
void | setRightTextColor(const QColor &text) |
See also textRight.
type : ToggleButtonType
This property holds whether to use the default button type or a custom one.
Options are: "Custom" "Default" This property directly affects the svgFile property. Setting it to "Default" sets the svgFile to a default value. Setting it to "Custom" allows the user to set a custom svg file to the svgFile property. The svgFile property can only be edited when this property is set to Custom.
Access functions:
ToggleButtonType | buttonType() |
virtual void | setButtonType(ToggleButtonType type) |
See also svgFile.
Member Function Documentation
CDPBaseToggleButton::CDPBaseToggleButton(QWidget *parent = 0)
Default constructs an instance of CDPBaseToggleButton.
[virtual]
CDPBaseToggleButton::~CDPBaseToggleButton()
Destroys the instance of CDPBaseToggleButton. The destructor is virtual.
[virtual slot]
void CDPBaseToggleButton::PropertyChanged(std::string strFullPropertyName, std::string strNewPropertyValue)
[protected]
double CDPBaseToggleButton::buttonMaxPos()
double CDPBaseToggleButton::buttonPos()
See also setButtonPos().
[protected]
double CDPBaseToggleButton::buttonWidth()
[protected]
void CDPBaseToggleButton::changeEvent(QEvent *e)
[virtual protected slot]
void CDPBaseToggleButton::checkEnable(double value)
[protected]
void CDPBaseToggleButton::drawBorderPixmap(QPixmap &pix, const QPixmap &borderPix, QSize pixSize)
[virtual protected slot]
void CDPBaseToggleButton::emitToggled()
[protected slot]
void CDPBaseToggleButton::initDeprecated()
bool CDPBaseToggleButton::isCustom()
[protected]
void CDPBaseToggleButton::loadPixmap(QPixmap &pix, const ParserSVG::StyleMap &map, QSize pixSize = QSize(), QSizeF paintSize = QSize())
[protected]
void CDPBaseToggleButton::loadPixmapDisabled(QPixmap &pixmapDisabled)
[protected]
void CDPBaseToggleButton::loadPixmaps()
[virtual protected]
QSize CDPBaseToggleButton::minimumSizeHint() const
[virtual protected]
void CDPBaseToggleButton::mouseMoveEvent(QMouseEvent *ev)
[virtual protected]
void CDPBaseToggleButton::mousePressEvent(QMouseEvent *ev)
[virtual protected]
void CDPBaseToggleButton::mouseReleaseEvent(QMouseEvent *ev)
[virtual protected]
void CDPBaseToggleButton::paintEvent(QPaintEvent *ev)
[virtual protected]
void CDPBaseToggleButton::resizeEvent(QResizeEvent *ev)
void CDPBaseToggleButton::setButtonPos(double pos)
See also buttonPos().
[virtual slot]
void CDPBaseToggleButton::setInCommand(bool cmd)
[virtual slot]
void CDPBaseToggleButton::setValue(double value)
[virtual slot]
void CDPBaseToggleButton::setWidgetFont(const QString &font)
[virtual slot]
void CDPBaseToggleButton::setWidgetStyle(int style)
[virtual slot]
void CDPBaseToggleButton::setWidgetTheme(const QString &theme)
[virtual protected]
QSize CDPBaseToggleButton::sizeHint() const
[signal]
void CDPBaseToggleButton::toggled(bool)
Note: Signal toggled is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:
connect(cDPBaseToggleButton, static_cast<void(CDPBaseToggleButton::*)(bool)>(&CDPBaseToggleButton::toggled), [=](bool ){ /* ... */ });
[signal]
void CDPBaseToggleButton::toggled(int)
Note: Signal toggled is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:
connect(cDPBaseToggleButton, static_cast<void(CDPBaseToggleButton::*)(int)>(&CDPBaseToggleButton::toggled), [=](int ){ /* ... */ });
[virtual protected slot]
void CDPBaseToggleButton::updateFromCdp()
[protected]
void CDPBaseToggleButton::updateTextColorsFromSvg()
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.