Skip to content

Commit

Permalink
using ValueMeter for StorageMeter/EnergyMeter
Browse files Browse the repository at this point in the history
  • Loading branch information
uwerat committed Sep 5, 2024
1 parent c61e3c7 commit d0a564f
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 208 deletions.
3 changes: 1 addition & 2 deletions examples/iotdashboard/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
71 changes: 0 additions & 71 deletions examples/iotdashboard/EnergyMeter.cpp

This file was deleted.

18 changes: 0 additions & 18 deletions examples/iotdashboard/EnergyMeter.h

This file was deleted.

12 changes: 8 additions & 4 deletions examples/iotdashboard/Skin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -35,6 +34,7 @@
#include <QskSkinHintTableEditor.h>
#include <QskStateCombination.h>
#include <QskTextLabel.h>
#include <QskProgressRing.h>
#include <QskGraphicLabel.h>
#include <QskFontRole.h>

Expand Down Expand Up @@ -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" }
} }
);
}
}

Expand Down
68 changes: 0 additions & 68 deletions examples/iotdashboard/StorageMeter.cpp

This file was deleted.

61 changes: 57 additions & 4 deletions examples/iotdashboard/StoragePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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
{
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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(); } );
}
35 changes: 3 additions & 32 deletions examples/iotdashboard/StoragePage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

private:
struct Storage
{
struct Media
{
qreal pictures = 0;
qreal music = 0;
qreal videos = 0;
qreal documents = 0;
qreal others = 0;
QSK_SUBCONTROLS( Panel, Status )

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;
};
StoragePage( QQuickItem* parent = nullptr );

private:
void addRow( const QString& title, const QString& description,
qreal pictures, qreal music, qreal videos, qreal documents, qreal others );
};
22 changes: 18 additions & 4 deletions examples/iotdashboard/TopBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*****************************************************************************/

#include "TopBar.h"
#include "EnergyMeter.h"
#include "ValueMeter.h"

#include <QskFontRole.h>
#include <QskTextLabel.h>
Expand Down Expand Up @@ -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(
Expand All @@ -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 );
Expand Down
Loading

0 comments on commit d0a564f

Please sign in to comment.