Skip to content

Commit

Permalink
CircularProgressBar removed, using QskProgressRing instead
Browse files Browse the repository at this point in the history
  • Loading branch information
uwerat committed Sep 4, 2024
1 parent 86942d4 commit c61e3c7
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 147 deletions.
1 change: 1 addition & 0 deletions examples/gallery/progressbar/ProgressBarPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ void ProgressBarPage::populate()
{
auto* ring = new QskProgressRing( determinateRingsHBox );
ring->setSize( size );
ring->setLayoutAlignmentHint( Qt::AlignCenter );

QQuickItem* parentItem;

Expand Down
2 changes: 0 additions & 2 deletions examples/iotdashboard/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
set(SOURCES
Box.h Box.cpp
BoxWithButtons.h BoxWithButtons.cpp
CircularProgressBar.h CircularProgressBar.cpp
CircularProgressBarSkinlet.h CircularProgressBarSkinlet.cpp
Diagram.h Diagram.cpp
DiagramSkinlet.h DiagramSkinlet.cpp
EnergyMeter.h EnergyMeter.cpp
Expand Down
19 changes: 0 additions & 19 deletions examples/iotdashboard/CircularProgressBar.cpp

This file was deleted.

21 changes: 0 additions & 21 deletions examples/iotdashboard/CircularProgressBar.h

This file was deleted.

24 changes: 0 additions & 24 deletions examples/iotdashboard/CircularProgressBarSkinlet.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions examples/iotdashboard/CircularProgressBarSkinlet.h

This file was deleted.

8 changes: 5 additions & 3 deletions examples/iotdashboard/EnergyMeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*****************************************************************************/

#include "EnergyMeter.h"
#include "CircularProgressBar.h"

#include <QskProgressRing.h>
#include <QskTextLabel.h>
#include <QskFontRole.h>

Expand Down Expand Up @@ -35,8 +35,10 @@ EnergyMeter::EnergyMeter( const QColor& textColor,
{
setAutoLayoutChildren( true );

auto valueBar = new CircularProgressBar( this );
valueBar->setGradientHint( CircularProgressBar::Fill, gradient );
auto valueBar = new QskProgressRing( this );
valueBar->setSizePolicy(
QskSizePolicy::MinimumExpanding, QskSizePolicy::Constrained );
valueBar->setFillGradient( gradient );
valueBar->setValue( value );

auto valueLabel = new ValueLabel( this );
Expand Down
11 changes: 4 additions & 7 deletions examples/iotdashboard/Skin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

#include "Box.h"
#include "BoxWithButtons.h"
#include "CircularProgressBar.h"
#include "CircularProgressBarSkinlet.h"
#include "DashboardPage.h"
#include "Diagram.h"
#include "DiagramSkinlet.h"
Expand Down Expand Up @@ -56,7 +54,6 @@ Skin::Skin( QObject* parent )
{
setObjectName( "iot" );

declareSkinlet< CircularProgressBar, CircularProgressBarSkinlet >();
declareSkinlet< Diagram, DiagramSkinlet >();
declareSkinlet< LightDisplay, LightDisplaySkinlet >();
declareSkinlet< StorageBar, StorageBarSkinlet >();
Expand Down Expand Up @@ -127,10 +124,10 @@ void Skin::initHints()
ed.setGradient( TopBarItem::Item4, 0xff6776ff, 0xff6100ff );

// the bar gradient is defined through the top bar items above
ed.setArcMetrics( CircularProgressBar::Groove, 90, -360, 8.53 );
ed.setArcMetrics( QskProgressRing::Groove, 90, -360, 8.53 );
// the span angle will be set in the progress bar, we just give a dummy
// value here:
ed.setArcMetrics( CircularProgressBar::Fill, 90, -360, 8.53 );
ed.setArcMetrics( QskProgressRing::Fill, 90, -360, 8.53 );

ed.setFontRole( TimeTitleLabel::Text, { QskFontRole::Caption, QskFontRole::High } );

Expand Down Expand Up @@ -282,8 +279,8 @@ void Skin::initHints()
ed.setColor( QskTextLabel::Text, palette.text );
ed.setColor( UsageDiagramBox::DayText, palette.text );

ed.setMetric( CircularProgressBar::Groove | QskAspect::Border, 2 );
ed.setColor( CircularProgressBar::Groove | QskAspect::Border,
ed.setMetric( QskProgressRing::Groove | QskAspect::Border, 2 );
ed.setColor( QskProgressRing::Groove | QskAspect::Border,
palette.circularProgressBarGroove );

// storage bar
Expand Down
51 changes: 27 additions & 24 deletions examples/iotdashboard/StorageMeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,47 @@
*****************************************************************************/

#include "StorageMeter.h"
#include "CircularProgressBar.h"

#include <QskFontRole.h>
#include <QskTextLabel.h>

QSK_SUBCONTROL( StorageMeter, Status )

namespace
{
inline QString make_text( const QLocale& locale, const qreal value )
{
return locale.toString( static_cast< int >( value ) ) + " " + locale.percent();
}
}

StorageMeter::StorageMeter( QQuickItem* parent ) noexcept
: CircularProgressBar( parent )
, label( new QskTextLabel( this ) )
: QskProgressRing( parent )
{
setAutoLayoutChildren( true );
setSizePolicy( QskSizePolicy::Preferred, QskSizePolicy::Constrained );
initSizePolicy( QskSizePolicy::MinimumExpanding, QskSizePolicy::Constrained );

label->setText( make_text( locale(), value() ) );
label->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
label->setLayoutAlignmentHint( Qt::AlignCenter );
label->setFontRole( QskFontRole::Caption );
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::setValue( const qreal value )
void StorageMeter::updateMeter( const qreal value )
{
const auto gradient = gradientHint( StorageMeter::Status );
const auto color = gradient.extracted( value / 100.0, value / 100.0 ).startColor();
setGradientHint( StorageMeter::Fill, { color, color.lighter() } );
CircularProgressBar::setValue( value );
label->setTextColor( color );
label->setText( make_text( locale(), 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
QSizeF StorageMeter::contentsSizeHint(
Qt::SizeHint which, const QSizeF& constraint ) const
{
if ( which != Qt::PreferredSize )
return QSizeF();
Expand Down
18 changes: 10 additions & 8 deletions examples/iotdashboard/StorageMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@

#pragma once

#include "CircularProgressBar.h"
#include <QskControl.h>
#include <QskProgressRing.h>

class StorageMeter final : public CircularProgressBar
class QskTextLabel;

class StorageMeter final : public QskProgressRing
{
public:
QSK_SUBCONTROLS( Status )
explicit StorageMeter( QQuickItem* parent = nullptr ) noexcept;
public Q_SLOTS:
void setValue( qreal value );

StorageMeter( QQuickItem* parent = nullptr ) noexcept;

private:
QSizeF contentsSizeHint( Qt::SizeHint which, const QSizeF& constraint ) const override;
class QskTextLabel* label = nullptr;
void updateMeter( qreal value );
QSizeF contentsSizeHint( Qt::SizeHint, const QSizeF& ) const override;

QskTextLabel* m_label = nullptr;
};
2 changes: 2 additions & 0 deletions src/controls/QskProgressRing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ QskProgressRing::QskProgressRing( qreal min, qreal max, QQuickItem* parent )
: Inherited( min, max, parent )
, m_data( new PrivateData )
{
initSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );

m_data->size = NormalSize;

setSubcontrolProxy( Inherited::Groove, Groove );
Expand Down
17 changes: 1 addition & 16 deletions src/controls/QskProgressRingSkinlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,7 @@ QRectF QskProgressRingSkinlet::subControlRect(
QskAspect::Subcontrol subControl ) const
{
if( subControl == Q::Groove || subControl == Q::Fill )
{
const auto ring = static_cast< const Q* >( skinnable );

const auto size = ring->strutSizeHint( Q::Fill );

auto rect = contentsRect;
if( ring->layoutMirroring() )
rect.setLeft( rect.right() - size.width() );
else
rect.setWidth( size.width() );

rect.setTop( rect.top() + 0.5 * ( rect.height() - size.height() ) );
rect.setHeight( size.height() );

return rect;
}
return contentsRect;

return Inherited::subControlRect( skinnable, contentsRect, subControl );
}
Expand Down

0 comments on commit c61e3c7

Please sign in to comment.