CDPBaseLabel Class
The Label widget provides a text or animation display More...
Header: | #include <CDPBaseWidgets/CDPBaseLabel.h> |
Inherits: | StateChanger, CDPBaseCom, CDPBaseControlVisible, |
Inherited By: |
Public Types
enum | NumForm { Normal, Scientific, MixedMode } |
typedef | StylingSvgMap |
enum | StylingType { NoFile, CSS, SVG, General, ..., Unit } |
enum | TextCase { None, UpperCase, LowerCase } |
Properties
|
|
Public Functions
CDPBaseLabel(QWidget *parent = 0) | |
virtual | ~CDPBaseLabel() |
QString | cdpStyle() |
QString | cssFile() |
bool | cssFileDisabled() |
QColor | fontColor() |
StylingType | getStylingType() |
bool | isCssStyling() |
bool | isSvgStyling() |
QString | movieFile() const |
bool | noSystemBackground() |
NumForm | numFormat() |
bool | opaquePaintEvent() |
bool | playMovie() const |
QString | postfix() |
int | precision() |
QString | routing() |
bool | scaleMovie() const |
void | setCdpStyle(QString routing) |
void | setCssFile(QString cssFile, bool updateTheme = true) |
virtual void | setIQtCDPPointer(IQtCDP *pIQtCDP) |
void | setNoSystemBackground(bool enable) |
void | setNumFormat(NumForm format) |
void | setOpaquePaintEvent(bool enable) |
void | setPostfix(QString pfix) |
void | setPrecision(int value) |
void | setStylingType(StylingType type) |
void | setSvgFile(const QString &svg) |
virtual void | setTextFromProperty(QString propertyValue) |
QString | svgFile() |
TextCase | textCase() const |
- 3 public functions inherited from StateChanger
- 17 public functions inherited from CDPBaseCom
- 4 public functions inherited from CDPBaseControlVisible
Public Slots
virtual void | handleVisible(double visible) |
virtual void | hideWidget() |
virtual void | setFontColor(QColor fontColor) |
virtual void | setInCommand(bool cmd) |
virtual void | setMovieFile(const QString &filePath) |
virtual void | setPlayMovie(bool play) |
void | setRouting(QString routing) |
virtual void | setScaleMovie(bool scale) |
virtual void | setSmoothPixmap(bool smooth) |
virtual void | setTextCase(TextCase tc) |
virtual void | setValue(double value) |
virtual void | setValue(int value) |
virtual void | setValue(bool value) |
virtual void | setValue(const QString &value) |
virtual bool | setValue(QString value, bool bScale) |
virtual void | setWidgetFont(const QString &font) |
virtual void | setWidgetStyle(double style) |
virtual void | setWidgetStyle(int style) |
virtual void | setWidgetTheme(const QString &theme) |
virtual void | showWidget() |
virtual int | widgetStyle() |
Signals
Protected Functions
QString | addUrl(QString path) |
QString | generatedStyleSheet() |
void | loadSvg() |
virtual void | mousePressEvent(QMouseEvent *e) |
virtual void | mouseReleaseEvent(QMouseEvent *e) |
void | processSvgFile(QString svg) |
void | resizeEvent(QResizeEvent *e) override |
void | updateTextColorFromSvg() |
- 4 protected functions inherited from CDPBaseCom
- 1 protected function inherited from CDPBaseControlVisible
Additional Inherited Members
- 2 static public members inherited from CDPBaseCom
Detailed Description
The Label widget provides a text or animation display
To enter a text to be displayed, double-click on the widget and type the text or use the text property.
To show text or numeric values from a control system, enter routing to the remote object in the cdpRouting property. The received values can be scaled to preferred display units using a factor configured in cdpScaling. For instance, if the received value is in meters and we want to display it in km, we can configure cdpScaling to 0.001. In this case, we could also configure the cdpPostfix to km to always append that after the value. There are also other important properties, like precision, for selecting the number of decimals in values.
The stylingType property is important to ensure consistent styling across the design. Each theme uses different font families and sizes on different text types like titles, units, and values. Using the pre-defined types instead of manually changing the font properties will make your design show correctly also in other themes. Also, consistent use of the stylingType property makes it possible to do global changes to texts by overriding the general theme styling file, described in Styling by SVG.
Some applications require more styles than what is provided by the stylingType property. In the Open Bridge theme, this is solved by setting the stylingType property of the Label to NoFile
and the styleSheet property empty. The font size and color can now be set to anything, but the theme provides CSS styling that is selected on the different Labels using dynamic widget properties. This is done similarly to adding dynamic routings as described in the Design Mode Manual, but in the Open Bridge case, the properties have different names and types. The different styling types are defined in the theme file, themes/openbridge_light/general/main.css. Have a look at the example in, Creating an Open Bridge Styled Conning GUI Using Drag and Drop, to see how the different values and titles are styled using dynamic int properties named valueStyle and titleStyle.
The Label supports showing gif and webp animation files by configuring the movieFile property. There are also properties for scaling the movie, scaleMovie, and playMovie for running the movie. The playMovie property can be connected to the control system using dynamic property routing as described in the Design Mode Manual or by buttons using widget signal and slot connections.
Styling by SVG
The Label is usually styled by selecting one of the predefined types in the stylingType property, like Title, Value, Unit etc. Selecting one of these types will read the styling from a general theme SVG file, located in "themes/${theme_name}/general/theme.svg". The structure of the theme.svg file is not similar to the one used when setting stylingType to SVG and providing a SVG file in the svgFile property. That one uses the same styling as the Line Edit as described in the bottom of this section. The theme.svg file has the following SVG structure.
svg └─── Layer1 ├─── cdpValuePostfix (text) ├─── cdpValue (text) ├─── cdpSubHeading (text) ├─── cdpTitle (text) ├─── cdpFontColorUnit (text) ├─── cdpFontColorMain (text) └─── cdpFontColorMainInv (text)
The following table explains the named elements in more detail. Note that some of them are not relevant for the Label.
Property | Type | Description |
---|---|---|
cdpValuePostfix | text | The color, size and family of the font to be used when setting stylingType to Unit. |
cdpValue | Transparent rect/path | The color, size and family of the font to be used when setting stylingType to Value. |
cdpSubHeading | text | The color, size and family of the font to be used when setting stylingType to SubHeading. This property also provides text alignment by checking if the text in the SVG element contains AlignLeft, AlignRight, AlignCenter, AlignVCenter and/or AlignHCenter. The default is horizontal and vertical centered text. |
cdpTitle | text | The color, size and family of the font to be used when setting stylingType to Title. Similar to cdpSubHeading, it also sets the text alignment. A common use case for the Title is when placing labels as a top titles in containers. |
cdpFontColorUnit | text | This color element is currently not in use by any CDP widget, but this might change in the future. |
cdpFontColorMain | text | The color of the font to be used when setting stylingType to General. |
cdpFontColorMainInv | text | This color element is currently not in use by any CDP widget, but this might change in the future. |
When not styling using the general theme file, the svgFile property can be used to style the widget. Styling by SVG enables switching between different themes in runtime (as long as the files are placed at identical locations within theme directories).
The CDPBaseLabel supports reading both background image and text color from SVG similar to that of CDPBaseLineEdit described here. To enable the background to show on the label we have to make sure that the property named noSystemBackground is set to false.
Note: The SVG doesn't have to include background image though it is supported, but when present, the widget will generate raster images as described here.
Member Type Documentation
enum CDPBaseLabel::NumForm
This enum type specifies how to format numbers:
Constant | Value | Description |
---|---|---|
CDPBaseLabel::Normal | 1 | Format as [-]9.9 |
CDPBaseLabel::Scientific | 2 | Format as [-]9.9e[+|-]999 |
CDPBaseLabel::MixedMode | 3 | Use "Normal" or "Scientific" format, whichever is the most concise. |
typedef CDPBaseLabel::StylingSvgMap
enum CDPBaseLabel::StylingType
This enum type specifies a styling type:
Constant | Value | Description |
---|---|---|
CDPBaseLabel::NoFile | 0 | No custom styling (enables styleSheet property). |
CDPBaseLabel::CSS | 1 | Style by CSS file (enables cssFile property). |
CDPBaseLabel::SVG | 2 | Style by SVG file (enables svgFile property). |
CDPBaseLabel::General | 3 | Generates stylesheet with color. |
CDPBaseLabel::Value | 6 | Value text styling as provided by general theme SVG. |
CDPBaseLabel::SubHeading | 5 | Sub heading text styling as provided by general theme SVG. |
CDPBaseLabel::Main | 8 | Main contents text styling as provided by general theme SVG. |
CDPBaseLabel::Title | 4 | Title text styling as provided by general theme SVG. |
CDPBaseLabel::Unit | 7 | Value unit text styling as provided by general theme SVG. |
enum CDPBaseLabel::TextCase
Property Documentation
cdpOfflineValue : const QString
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.
Access functions:
QString | routing() |
void | setRouting(QString routing) |
cdpScaling : const double
This property holds a value with which the decimal (if present) value is multiplied.
This works with both signals and properties.
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) |
cdpVisibleRouting : const QString
This property holds the full path of the signal/parameter that controls the “visible” property.
Note: Values not equal to 1 are considered false.
See also visible.
cssFile : QString
This property holds the css file to use for customization.
http://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qspinbox
Access functions:
QString | cssFile() |
void | setCssFile(QString cssFile, bool updateTheme = true) |
See also svgFile.
fontColor : QColor
This property holds the font color.
Note: If set, this overrides the text color from SVG file and the entire code received from CSS file.
Access functions:
QColor | fontColor() |
virtual void | setFontColor(QColor fontColor) |
movieFile : QString
This property holds the path to a simple movie file (.gif) to show/play on the label. Starting and stopping the movie is done using the playMovie property. Note that there are tools online for converting formats like mp4 to gif.
Access functions:
QString | movieFile() const |
virtual void | setMovieFile(const QString &filePath) |
See also playMovie.
noSystemBackground : bool
This property holds whether the widget has a background.
Newly exposed areas are never filled with the background.
Access functions:
bool | noSystemBackground() |
void | setNoSystemBackground(bool enable) |
See also opaquePaintEvent.
numFormat : NumForm
This property holds the format in which numbers are displayed.
Access functions:
NumForm | numFormat() |
void | setNumFormat(NumForm format) |
See also precision.
opaquePaintEvent : bool
This property holds whether the widget is transparent.
Set true
to optimize painting when having no transparency in widget graphics This property should be set true
on all widgets that does not require transparency. It will prevent Qt from painting widgets behind current widget and thus increase performance.
Access functions:
bool | opaquePaintEvent() |
void | setOpaquePaintEvent(bool enable) |
See also visible, cdpVisibleRouting, and noSystemBackground.
playMovie : bool
This property holds whether to start or stop the movie file provided in movieFile. The playMovie property can be controlled by signal and slot connection or by adding a dynamic property as described in the Design mode manual.
Access functions:
bool | playMovie() const |
virtual void | setPlayMovie(bool play) |
See also movieFile.
postfix : QString
This property holds the string that is appended to the displayed value.
Access functions:
QString | postfix() |
void | setPostfix(QString pfix) |
precision : int
This property holds the value of decimal places for numbers.
Sets the number of decimals to show when displaying fractured numbers or number of decimal notations before switching to scientific display in “MixedMode”
Access functions:
int | precision() |
void | setPrecision(int value) |
See also numFormat.
scaleMovie : bool
This property holds whether or not to scale the movie file provided in movieFile to the size of the widget. Setting this property to false will set the original size on the movie.
Access functions:
bool | scaleMovie() const |
virtual void | setScaleMovie(bool scale) |
See also movieFile.
stylingType : StylingType
This property holds a selection of how to customize the widget.
Note: All styles can be overridden by fontColor.
Access functions:
StylingType | getStylingType() |
void | setStylingType(StylingType type) |
svgFile : QString
This property holds the svg file to use for customization.
Access functions:
QString | svgFile() |
void | setSvgFile(const QString &svg) |
See also cssFile and noSystemBackground.
textCase : TextCase
This property holds whether to convert text to upper/lower case or keep it as it is.
Note: The postfix is not converted along with the value text. If you want it converted it must be moved to a separate label.
Access functions:
TextCase | textCase() const |
virtual void | setTextCase(TextCase tc) |
visible : const bool
This property holds whether to show the QWidget or not.
See also cdpVisibleRouting.
widgetStyle : int
This property holds the widget style to use in the SVG or CSS file.
Example showing a .css file that will change text color based on widgetStyle:
QLabel[widgetStyle="0"]{ color: #64dcff; } QLabel[widgetStyle="1"]{ color: #f6a623; } QLabel[widgetStyle="2"]{ color: #e8392e; }
Note: This will only have effect if the SVG or CSS file provides styles.
Access functions:
virtual int | widgetStyle() |
virtual void | setWidgetStyle(double style) |
virtual void | setWidgetStyle(int style) |
See also stylingType.
Member Function Documentation
CDPBaseLabel::CDPBaseLabel(QWidget *parent = 0)
Default constructs an instance of CDPBaseLabel.
[virtual]
CDPBaseLabel::~CDPBaseLabel()
Destroys the instance of CDPBaseLabel. The destructor is virtual.
[protected]
QString CDPBaseLabel::addUrl(QString path)
[signal]
void CDPBaseLabel::clicked()
bool CDPBaseLabel::cssFileDisabled()
[protected]
QString CDPBaseLabel::generatedStyleSheet()
[virtual slot]
void CDPBaseLabel::handleVisible(double visible)
[virtual slot]
void CDPBaseLabel::hideWidget()
bool CDPBaseLabel::isCssStyling()
bool CDPBaseLabel::isSvgStyling()
[protected]
void CDPBaseLabel::loadSvg()
[virtual protected]
void CDPBaseLabel::mousePressEvent(QMouseEvent *e)
[virtual protected]
void CDPBaseLabel::mouseReleaseEvent(QMouseEvent *e)
[signal]
void CDPBaseLabel::pressed()
[protected]
void CDPBaseLabel::processSvgFile(QString svg)
[signal]
void CDPBaseLabel::released()
[protected]
void CDPBaseLabel::resizeEvent(QResizeEvent *e)
[virtual]
void CDPBaseLabel::setIQtCDPPointer(IQtCDP *pIQtCDP)
[virtual slot]
void CDPBaseLabel::setInCommand(bool cmd)
[virtual slot]
void CDPBaseLabel::setSmoothPixmap(bool smooth)
[virtual]
void CDPBaseLabel::setTextFromProperty(QString propertyValue)
[virtual slot]
void CDPBaseLabel::setValue(double value)
[virtual slot]
void CDPBaseLabel::setValue(int value)
[virtual slot]
void CDPBaseLabel::setValue(bool value)
[virtual slot]
void CDPBaseLabel::setValue(const QString &value)
[virtual slot]
bool CDPBaseLabel::setValue(QString value, bool bScale)
[virtual slot]
void CDPBaseLabel::setWidgetFont(const QString &font)
[virtual slot]
void CDPBaseLabel::setWidgetTheme(const QString &theme)
[virtual slot]
void CDPBaseLabel::showWidget()
[protected]
void CDPBaseLabel::updateTextColorFromSvg()
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.