From e57b1010554530dadc62976d9aeea789596085af Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Sat, 6 Nov 2021 10:39:25 +0100 Subject: [PATCH] add value text --- examples/iotdashboard/LightDisplay.cpp | 6 ++++-- examples/iotdashboard/LightDisplay.h | 4 ++-- examples/iotdashboard/LightDisplaySkinlet.cpp | 9 ++++++--- examples/iotdashboard/MainContent.cpp | 3 ++- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/examples/iotdashboard/LightDisplay.cpp b/examples/iotdashboard/LightDisplay.cpp index 7af22589..379c940e 100644 --- a/examples/iotdashboard/LightDisplay.cpp +++ b/examples/iotdashboard/LightDisplay.cpp @@ -27,12 +27,14 @@ QSK_SUBCONTROL( LightDisplay, LeftLabel ) QSK_SUBCONTROL( LightDisplay, RightLabel ) LightDisplay::LightDisplay( QQuickItem* parent ) - : QskBoundedControl( parent ) + : QskBoundedValueInput( parent ) { setAlignmentHint( LeftLabel, Qt::AlignRight ); + setAlignmentHint( ValueText, Qt::AlignCenter | Qt::AlignHCenter ); + + setBoundaries( 0, 100 ); // ### move to Skin: - setGradient( Qt::magenta ); setShadow( { 0, 20 } ); setShadowColor( 0xe5e5e5 ); } diff --git a/examples/iotdashboard/LightDisplay.h b/examples/iotdashboard/LightDisplay.h index de27155b..87ad394f 100644 --- a/examples/iotdashboard/LightDisplay.h +++ b/examples/iotdashboard/LightDisplay.h @@ -5,11 +5,11 @@ #pragma once -#include +#include #include #include -class LightDisplay : public QskBoundedControl +class LightDisplay : public QskBoundedValueInput { Q_OBJECT diff --git a/examples/iotdashboard/LightDisplaySkinlet.cpp b/examples/iotdashboard/LightDisplaySkinlet.cpp index 54c45784..2413f19a 100644 --- a/examples/iotdashboard/LightDisplaySkinlet.cpp +++ b/examples/iotdashboard/LightDisplaySkinlet.cpp @@ -30,7 +30,8 @@ QRectF LightDisplaySkinlet::subControlRect( const QskSkinnable* skinnable, QRectF rect = contentsRect; if( subControl == LightDisplay::Groove - || subControl == LightDisplay::Panel ) + || subControl == LightDisplay::Panel + || subControl == LightDisplay::ValueText ) { QSizeF size = textLabelsSize( display ); @@ -120,8 +121,10 @@ QSGNode* LightDisplaySkinlet::updateSubNode( } case ValueTextRole: { - - return nullptr; + const QString valueText = QString::number( display->value(), 'f', 0 ) + + QStringLiteral( " %" ); + return updateTextNode( skinnable, node, valueText, {}, + LightDisplay::ValueText ); } case LeftLabelRole: { diff --git a/examples/iotdashboard/MainContent.cpp b/examples/iotdashboard/MainContent.cpp index 4f41e3c0..85132b81 100644 --- a/examples/iotdashboard/MainContent.cpp +++ b/examples/iotdashboard/MainContent.cpp @@ -54,7 +54,8 @@ namespace LightIntensity( QQuickItem* parent = nullptr ) : Box( "Light intensity", parent ) { - new LightDisplay( this ); + auto* lightDisplay = new LightDisplay( this ); + lightDisplay->setValue( 50.0 ); } }; }