using ValueMeter for StorageMeter/EnergyMeter
This commit is contained in:
parent
c61e3c7f36
commit
d0a564ff50
@ -8,7 +8,6 @@ set(SOURCES
|
||||
BoxWithButtons.h BoxWithButtons.cpp
|
||||
Diagram.h Diagram.cpp
|
||||
DiagramSkinlet.h DiagramSkinlet.cpp
|
||||
EnergyMeter.h EnergyMeter.cpp
|
||||
GraphicProvider.h GraphicProvider.cpp
|
||||
GridBox.h GridBox.cpp
|
||||
LightDisplaySkinlet.h LightDisplaySkinlet.cpp
|
||||
@ -29,7 +28,7 @@ set(SOURCES
|
||||
UsageBox.h UsageBox.cpp
|
||||
UsageDiagram.h UsageDiagram.cpp
|
||||
StoragePage.h StoragePage.cpp
|
||||
StorageMeter.h StorageMeter.cpp
|
||||
ValueMeter.h ValueMeter.cpp
|
||||
StorageBar.h StorageBar.cpp
|
||||
StorageBarSkinlet.h StorageBarSkinlet.cpp
|
||||
nodes/DiagramDataNode.h nodes/DiagramDataNode.cpp
|
||||
|
@ -1,71 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2021 Edelhirsch Software GmbH
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*****************************************************************************/
|
||||
|
||||
#include "EnergyMeter.h"
|
||||
|
||||
#include <QskProgressRing.h>
|
||||
#include <QskTextLabel.h>
|
||||
#include <QskFontRole.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
class ValueLabel : public QskTextLabel
|
||||
{
|
||||
public:
|
||||
ValueLabel( QQuickItem* parent )
|
||||
: QskTextLabel( parent )
|
||||
{
|
||||
initSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
|
||||
setLayoutAlignmentHint( Qt::AlignCenter );
|
||||
setFontRole( QskFontRole::Caption );
|
||||
}
|
||||
|
||||
void setValue( int value )
|
||||
{
|
||||
setText( locale().toString( value ) + " " + locale().percent() );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
EnergyMeter::EnergyMeter( const QColor& textColor,
|
||||
const QskGradient& gradient, int value, QQuickItem* parent )
|
||||
: QskControl( parent )
|
||||
{
|
||||
setAutoLayoutChildren( true );
|
||||
|
||||
auto valueBar = new QskProgressRing( this );
|
||||
valueBar->setSizePolicy(
|
||||
QskSizePolicy::MinimumExpanding, QskSizePolicy::Constrained );
|
||||
valueBar->setFillGradient( gradient );
|
||||
valueBar->setValue( value );
|
||||
|
||||
auto valueLabel = new ValueLabel( this );
|
||||
valueLabel->setTextColor( textColor );
|
||||
valueLabel->setValue( value );
|
||||
}
|
||||
|
||||
QSizeF EnergyMeter::contentsSizeHint(
|
||||
Qt::SizeHint which, const QSizeF& constraint ) const
|
||||
{
|
||||
if ( which != Qt::PreferredSize )
|
||||
return QSizeF();
|
||||
|
||||
qreal size;
|
||||
|
||||
if ( constraint.width() > 0 )
|
||||
{
|
||||
size = constraint.width();
|
||||
}
|
||||
else if ( constraint.height() > 0 )
|
||||
{
|
||||
size = constraint.height();
|
||||
}
|
||||
else
|
||||
{
|
||||
size = 57;
|
||||
}
|
||||
|
||||
return QSizeF( size, size );
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2021 Edelhirsch Software GmbH
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QskControl.h>
|
||||
|
||||
class EnergyMeter : public QskControl
|
||||
{
|
||||
public:
|
||||
EnergyMeter( const QColor&, const QskGradient&,
|
||||
int progress, QQuickItem* parent = nullptr );
|
||||
|
||||
protected:
|
||||
QSizeF contentsSizeHint( Qt::SizeHint, const QSizeF& ) const override;
|
||||
};
|
@ -19,7 +19,6 @@
|
||||
#include "RoundedIcon.h"
|
||||
#include "StorageBar.h"
|
||||
#include "StorageBarSkinlet.h"
|
||||
#include "StorageMeter.h"
|
||||
#include "StoragePage.h"
|
||||
#include "TopBar.h"
|
||||
#include "UsageBox.h"
|
||||
@ -35,6 +34,7 @@
|
||||
#include <QskSkinHintTableEditor.h>
|
||||
#include <QskStateCombination.h>
|
||||
#include <QskTextLabel.h>
|
||||
#include <QskProgressRing.h>
|
||||
#include <QskGraphicLabel.h>
|
||||
#include <QskFontRole.h>
|
||||
|
||||
@ -298,9 +298,13 @@ void Skin::initHints()
|
||||
|
||||
// storage meter
|
||||
{
|
||||
ed.setGradient( StorageMeter::Status,
|
||||
{ { { 0.00, "#00ff00" }, { 0.33, "#00ff00" }, { 0.33, "#ffaf00" }, { 0.66, "#ffaf00" },
|
||||
{ 0.66, "#ff0000" }, { 1.00, "#ff0000" } } } );
|
||||
ed.setGradient( StoragePage::Status,
|
||||
{ {
|
||||
{ 0.00, "#00ff00" }, { 0.33, "#00ff00" },
|
||||
{ 0.33, "#ffaf00" }, { 0.66, "#ffaf00" },
|
||||
{ 0.66, "#ff0000" }, { 1.00, "#ff0000" }
|
||||
} }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,68 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2022 Edelhirsch Software GmbH
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*****************************************************************************/
|
||||
|
||||
#include "StorageMeter.h"
|
||||
|
||||
#include <QskFontRole.h>
|
||||
#include <QskTextLabel.h>
|
||||
|
||||
QSK_SUBCONTROL( StorageMeter, Status )
|
||||
|
||||
StorageMeter::StorageMeter( QQuickItem* parent ) noexcept
|
||||
: QskProgressRing( parent )
|
||||
{
|
||||
setAutoLayoutChildren( true );
|
||||
initSizePolicy( QskSizePolicy::MinimumExpanding, QskSizePolicy::Constrained );
|
||||
|
||||
m_label = new QskTextLabel( this );
|
||||
m_label->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
|
||||
m_label->setLayoutAlignmentHint( Qt::AlignCenter );
|
||||
m_label->setFontRole( QskFontRole::Caption );
|
||||
|
||||
connect( this, &QskProgressRing::valueChanged,
|
||||
this, &StorageMeter::updateMeter );
|
||||
|
||||
updateMeter( value() );
|
||||
}
|
||||
|
||||
void StorageMeter::updateMeter( const qreal value )
|
||||
{
|
||||
const auto color = qskInterpolatedColorAt(
|
||||
gradientHint( Status ).stops(), value / 100.0 );
|
||||
|
||||
setFillGradient( { color, color.lighter() } );
|
||||
|
||||
m_label->setTextColor( color );
|
||||
|
||||
const auto locale = this->locale();
|
||||
const auto text = locale.toString( static_cast< int >( value ) )
|
||||
+ " " + locale.percent();
|
||||
|
||||
m_label->setText( text );
|
||||
}
|
||||
|
||||
QSizeF StorageMeter::contentsSizeHint(
|
||||
Qt::SizeHint which, const QSizeF& constraint ) const
|
||||
{
|
||||
if ( which != Qt::PreferredSize )
|
||||
return QSizeF();
|
||||
|
||||
qreal size;
|
||||
|
||||
if ( constraint.width() > 0 )
|
||||
{
|
||||
size = constraint.width();
|
||||
}
|
||||
else if ( constraint.height() > 0 )
|
||||
{
|
||||
size = constraint.height();
|
||||
}
|
||||
else
|
||||
{
|
||||
size = 57;
|
||||
}
|
||||
|
||||
return QSizeF( size, size );
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
#include "StoragePage.h"
|
||||
#include "Box.h"
|
||||
#include "StorageBar.h"
|
||||
#include "StorageMeter.h"
|
||||
#include "ValueMeter.h"
|
||||
#include <QTimer>
|
||||
#include <QskAnimator.h>
|
||||
#include <QskBox.h>
|
||||
@ -20,6 +20,60 @@
|
||||
#include <QskTextLabel.h>
|
||||
|
||||
QSK_SUBCONTROL( StoragePage, Panel )
|
||||
QSK_SUBCONTROL( StoragePage, Status )
|
||||
|
||||
namespace
|
||||
{
|
||||
struct Storage
|
||||
{
|
||||
struct Media
|
||||
{
|
||||
qreal pictures = 0;
|
||||
qreal music = 0;
|
||||
qreal videos = 0;
|
||||
qreal documents = 0;
|
||||
qreal others = 0;
|
||||
|
||||
inline constexpr bool operator==( const Media& rhs ) const noexcept
|
||||
{
|
||||
return pictures == rhs.pictures && music == rhs.music && videos == rhs.videos &&
|
||||
documents == rhs.documents && others == rhs.others;
|
||||
}
|
||||
|
||||
inline constexpr qreal free() const noexcept
|
||||
{
|
||||
return 1.0 - pictures - music - videos - documents - others;
|
||||
}
|
||||
};
|
||||
|
||||
QString title;
|
||||
QString description;
|
||||
Media distribution;
|
||||
};
|
||||
|
||||
class StorageMeter final : public ValueMeter
|
||||
{
|
||||
public:
|
||||
StorageMeter( QQuickItem* parent = nullptr )
|
||||
: ValueMeter( parent )
|
||||
{
|
||||
setFixedSize( 64, 64 );
|
||||
|
||||
connect( this, &ValueMeter::valueChanged,
|
||||
this, &StorageMeter::setStatusColor );
|
||||
}
|
||||
|
||||
private:
|
||||
void setStatusColor( qreal value )
|
||||
{
|
||||
const auto color = qskInterpolatedColorAt(
|
||||
gradientHint( StoragePage::Status ).stops(), value / 100.0 );
|
||||
|
||||
setFillGradient( { color, color.lighter() } );
|
||||
setTextColor( color );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
struct StorageRowAnimator final : public QObject, public QskAnimator
|
||||
{
|
||||
@ -85,8 +139,6 @@ void StoragePage::addRow( const QString& title, const QString& description,
|
||||
const auto percent = 100.0 * ( 1.0 - storage.distribution.free() );
|
||||
auto* const meter = new StorageMeter( left );
|
||||
meter->setValue( percent );
|
||||
meter->setMinimumSize( 64, 64 );
|
||||
meter->setMaximumSize( 64, 64 );
|
||||
|
||||
auto* const maintitle = new QskTextLabel( storage.title, center );
|
||||
maintitle->setFontRole( QskFontRole::Headline );
|
||||
@ -136,5 +188,6 @@ void StoragePage::addRow( const QString& title, const QString& description,
|
||||
bar->setDocuments( media.documents * v );
|
||||
bar->setOthers( media.others * v );
|
||||
};
|
||||
connect( sync, &QskPushButton::clicked, animator, [ animator ]() { animator->start(); } );
|
||||
connect( sync, &QskPushButton::clicked,
|
||||
animator, [ animator ]() { animator->start(); } );
|
||||
}
|
||||
|
@ -7,44 +7,15 @@
|
||||
|
||||
#include <QVector>
|
||||
#include <QskLinearBox.h>
|
||||
#include <memory>
|
||||
|
||||
class QQuickItem;
|
||||
|
||||
class StoragePage final : public QskLinearBox
|
||||
{
|
||||
public:
|
||||
QSK_SUBCONTROLS( Panel )
|
||||
explicit StoragePage( QQuickItem* parent = nullptr );
|
||||
QSK_SUBCONTROLS( Panel, Status )
|
||||
|
||||
StoragePage( QQuickItem* parent = nullptr );
|
||||
|
||||
private:
|
||||
struct Storage
|
||||
{
|
||||
struct Media
|
||||
{
|
||||
qreal pictures = 0;
|
||||
qreal music = 0;
|
||||
qreal videos = 0;
|
||||
qreal documents = 0;
|
||||
qreal others = 0;
|
||||
|
||||
inline constexpr bool operator==( const Media& rhs ) const noexcept
|
||||
{
|
||||
return pictures == rhs.pictures && music == rhs.music && videos == rhs.videos &&
|
||||
documents == rhs.documents && others == rhs.others;
|
||||
}
|
||||
|
||||
inline constexpr qreal free() const noexcept
|
||||
{
|
||||
return 1.0 - pictures - music - videos - documents - others;
|
||||
}
|
||||
};
|
||||
|
||||
QString title;
|
||||
QString description;
|
||||
Media distribution;
|
||||
};
|
||||
|
||||
void addRow( const QString& title, const QString& description,
|
||||
qreal pictures, qreal music, qreal videos, qreal documents, qreal others );
|
||||
};
|
||||
|
@ -4,7 +4,7 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include "TopBar.h"
|
||||
#include "EnergyMeter.h"
|
||||
#include "ValueMeter.h"
|
||||
|
||||
#include <QskFontRole.h>
|
||||
#include <QskTextLabel.h>
|
||||
@ -41,6 +41,22 @@ namespace
|
||||
return TopBarItem::Item4;
|
||||
}
|
||||
}
|
||||
|
||||
class EnergyMeter : public ValueMeter
|
||||
{
|
||||
public:
|
||||
EnergyMeter( const QColor& textColor,
|
||||
const QskGradient& gradient, int value, QQuickItem* parent )
|
||||
: ValueMeter( parent )
|
||||
{
|
||||
setFillGradient( gradient );
|
||||
setValue( value );
|
||||
setTextColor( textColor );
|
||||
|
||||
setFixedSize( 57, 57 );
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
TopBarItem::TopBarItem(
|
||||
@ -62,9 +78,7 @@ TopBarItem::TopBarItem(
|
||||
const auto subcontrol = subcontrolForIndex( index );
|
||||
const auto textColor = color( subcontrol | QskAspect::TextColor );
|
||||
|
||||
auto meter = new EnergyMeter(
|
||||
textColor, gradient, progress, pieChartAndDisplay );
|
||||
meter->setSizePolicy( Qt::Horizontal, QskSizePolicy::Constrained );
|
||||
(void) new EnergyMeter( textColor, gradient, progress, pieChartAndDisplay );
|
||||
|
||||
auto display = new QskLinearBox( Qt::Vertical, pieChartAndDisplay );
|
||||
display->setSpacing( 0 );
|
||||
|
42
examples/iotdashboard/ValueMeter.cpp
Normal file
42
examples/iotdashboard/ValueMeter.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2022 Edelhirsch Software GmbH
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*****************************************************************************/
|
||||
|
||||
#include "ValueMeter.h"
|
||||
|
||||
#include <QskFontRole.h>
|
||||
#include <QskTextLabel.h>
|
||||
|
||||
ValueMeter::ValueMeter( QQuickItem* parent )
|
||||
: QskProgressRing( parent )
|
||||
{
|
||||
setAutoLayoutChildren( true );
|
||||
initSizePolicy( QskSizePolicy::MinimumExpanding, QskSizePolicy::Constrained );
|
||||
|
||||
m_label = new QskTextLabel( this );
|
||||
m_label->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
|
||||
m_label->setLayoutAlignmentHint( Qt::AlignCenter );
|
||||
m_label->setFontRole( QskFontRole::Caption );
|
||||
|
||||
connect( this, &QskProgressRing::valueChanged,
|
||||
this, &ValueMeter::updateMeter );
|
||||
|
||||
updateMeter( value() );
|
||||
}
|
||||
|
||||
void ValueMeter::updateMeter( const qreal value )
|
||||
{
|
||||
m_label->setText( text( value ) );
|
||||
}
|
||||
|
||||
QString ValueMeter::text( qreal value ) const
|
||||
{
|
||||
value = static_cast< int >( value );
|
||||
return locale().toString( value ) + ' ' + locale().percent();
|
||||
}
|
||||
|
||||
void ValueMeter::setTextColor( const QColor& color )
|
||||
{
|
||||
m_label->setTextColor( color );
|
||||
}
|
@ -9,16 +9,17 @@
|
||||
|
||||
class QskTextLabel;
|
||||
|
||||
class StorageMeter final : public QskProgressRing
|
||||
class ValueMeter : public QskProgressRing
|
||||
{
|
||||
public:
|
||||
QSK_SUBCONTROLS( Status )
|
||||
ValueMeter( QQuickItem* parent = nullptr );
|
||||
|
||||
StorageMeter( QQuickItem* parent = nullptr ) noexcept;
|
||||
void setTextColor( const QColor& );
|
||||
|
||||
protected:
|
||||
virtual QString text( qreal ) const;
|
||||
|
||||
private:
|
||||
void updateMeter( qreal value );
|
||||
QSizeF contentsSizeHint( Qt::SizeHint, const QSizeF& ) const override;
|
||||
|
||||
QskTextLabel* m_label = nullptr;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user