IOT dashboard: Make temperature and humidity changeable with buttons

This commit is contained in:
Peter Hartmann 2022-12-17 11:06:47 +01:00 committed by uwerat
parent 0f825209d0
commit 1338c876fd
6 changed files with 63 additions and 12 deletions

View File

@ -19,6 +19,8 @@ namespace
{ {
class UpAndDownBox : public QskLinearBox class UpAndDownBox : public QskLinearBox
{ {
Q_OBJECT
public: public:
UpAndDownBox( QQuickItem* parent ) UpAndDownBox( QQuickItem* parent )
: QskLinearBox( Qt::Vertical, parent ) : QskLinearBox( Qt::Vertical, parent )
@ -26,15 +28,25 @@ namespace
setSizePolicy( Qt::Horizontal, QskSizePolicy::Fixed ); setSizePolicy( Qt::Horizontal, QskSizePolicy::Fixed );
setSpacing( 0 ); setSpacing( 0 );
new RoundButton( QskAspect::Top, this ); auto* const topButton = new RoundButton( QskAspect::Top, this );
new RoundButton( QskAspect::Bottom, this ); connect( topButton, &QskPushButton::clicked, this, &UpAndDownBox::increase );
auto* const bottomButton = new RoundButton( QskAspect::Bottom, this );
connect( bottomButton, &QskPushButton::clicked, this, &UpAndDownBox::decrease );
} }
Q_SIGNALS:
void increase();
void decrease();
}; };
} }
BoxWithButtons::BoxWithButtons( const QString& title, const QString& value, BoxWithButtons::BoxWithButtons( const QString& title, const QString &prefix,
bool isBright, QQuickItem* parent ) const int initialValue, const QString &suffix,
bool isBright, QQuickItem* parent )
: Box( QString(), parent ) : Box( QString(), parent )
, m_prefix( prefix )
, m_suffix( suffix )
{ {
setSubcontrolProxy( QskBox::Panel, Panel ); setSubcontrolProxy( QskBox::Panel, Panel );
@ -54,10 +66,30 @@ BoxWithButtons::BoxWithButtons( const QString& title, const QString& value,
auto* titleLabel = new QskTextLabel( title, titleAndValue ); auto* titleLabel = new QskTextLabel( title, titleAndValue );
titleLabel->setFontRole( Skin::TitleFont ); titleLabel->setFontRole( Skin::TitleFont );
auto valueLabel = new QskTextLabel( value, titleAndValue ); m_valueLabel = new QskTextLabel( titleAndValue );
valueLabel->setSubcontrolProxy( QskTextLabel::Text, ValueText ); m_valueLabel->setSubcontrolProxy( QskTextLabel::Text, ValueText );
setValue( initialValue );
layout->addStretch( 1 ); layout->addStretch( 1 );
new UpAndDownBox( layout ); auto* const upAndDownBox = new UpAndDownBox( layout );
connect( upAndDownBox, &UpAndDownBox::increase, this, [this]()
{
setValue( m_value + 1 );
} );
connect( upAndDownBox, &UpAndDownBox::decrease, this, [this]()
{
setValue( m_value - 1 );
} );
} }
void BoxWithButtons::setValue( const int value )
{
m_value = qBound( 0, value, 100 );
const QString text = m_prefix + QString::number( m_value ) + m_suffix;
m_valueLabel->setText( text );
}
#include "BoxWithButtons.moc"

View File

@ -7,11 +7,22 @@
#include "Box.h" #include "Box.h"
class QskTextLabel;
class BoxWithButtons : public Box class BoxWithButtons : public Box
{ {
public: public:
QSK_SUBCONTROLS( Panel, ValuePanel, ValueText ) QSK_SUBCONTROLS( Panel, ValuePanel, ValueText )
BoxWithButtons( const QString& title, const QString& value, BoxWithButtons( const QString& title, const QString& prefix,
bool isBright, QQuickItem* parent = nullptr ); const int initialValue, const QString& suffix,
bool isBright, QQuickItem* parent = nullptr );
private:
void setValue( const int value );
const QString m_prefix;
int m_value;
const QString m_suffix;
QskTextLabel* m_valueLabel;
}; };

View File

@ -33,7 +33,7 @@ namespace
{ {
public: public:
IndoorTemperature( QQuickItem* parent = nullptr ) IndoorTemperature( QQuickItem* parent = nullptr )
: BoxWithButtons( "Indoor Temperature", "+24", true, parent ) : BoxWithButtons( "Indoor Temperature", "+", 24, {}, true, parent )
{ {
} }
}; };
@ -42,7 +42,7 @@ namespace
{ {
public: public:
Humidity( QQuickItem* parent = nullptr ) Humidity( QQuickItem* parent = nullptr )
: BoxWithButtons( "Humidity", "30%", false, parent ) : BoxWithButtons( "Humidity", {}, 30, "%", false, parent )
{ {
} }
}; };

View File

@ -7,7 +7,7 @@
#include <QskPushButton.h> #include <QskPushButton.h>
class RoundButton : QskPushButton class RoundButton : public QskPushButton
{ {
Q_OBJECT Q_OBJECT

View File

@ -29,6 +29,7 @@
#include <QskFunctions.h> #include <QskFunctions.h>
#include <QskShadowMetrics.h> #include <QskShadowMetrics.h>
#include <QskSkinHintTableEditor.h> #include <QskSkinHintTableEditor.h>
#include <QskStateCombination.h>
#include <QskTextLabel.h> #include <QskTextLabel.h>
#include <QFontDatabase> #include <QFontDatabase>
@ -237,6 +238,10 @@ void Skin::initHints( const Palette& palette )
ed.setGradient( LightDisplay::Panel, palette.box ); ed.setGradient( LightDisplay::Panel, palette.box );
ed.setGradient( LightDisplay::Knob, palette.box ); ed.setGradient( LightDisplay::Knob, palette.box );
ed.setGradient( RoundButton::Panel, palette.roundButton ); ed.setGradient( RoundButton::Panel, palette.roundButton );
ed.setGradient( RoundButton::Panel | QskAbstractButton::Pressed, palette.roundButtonPressed,
{ QskStateCombination::CombinationNoState, RoundButton::Top } );
ed.setAnimation( RoundButton::Panel | QskAspect::Color, 100 );
ed.setBoxBorderColors( UsageDiagramBox::DaysBox, palette.weekdayBox ); ed.setBoxBorderColors( UsageDiagramBox::DaysBox, palette.weekdayBox );
ed.setColor( QskTextLabel::Text, palette.text ); ed.setColor( QskTextLabel::Text, palette.text );
ed.setColor( UsageDiagramBox::DayText, palette.text ); ed.setColor( UsageDiagramBox::DayText, palette.text );
@ -250,6 +255,7 @@ Skin::Palette DaytimeSkin::palette() const
0xfffbfbfb, 0xfffbfbfb,
Qt::white, Qt::white,
0xfff7f7f7, 0xfff7f7f7,
0xffe5e5e5,
0xfff4f4f4, 0xfff4f4f4,
Qt::black, Qt::black,
0xffe5e5e5, 0xffe5e5e5,
@ -264,6 +270,7 @@ Skin::Palette NighttimeSkin::palette() const
0xff040404, 0xff040404,
Qt::black, Qt::black,
0xff0a0a0a, 0xff0a0a0a,
0xff1a1a1a,
0xff0c0c0c, 0xff0c0c0c,
Qt::white, Qt::white,
0xff1a1a1a, 0xff1a1a1a,

View File

@ -17,6 +17,7 @@ class Skin : public QskSkin
QColor mainContent; QColor mainContent;
QColor box; QColor box;
QColor roundButton; QColor roundButton;
QColor roundButtonPressed;
QColor weekdayBox; QColor weekdayBox;
QColor text; QColor text;
QColor shadow; QColor shadow;