leftover code removed

This commit is contained in:
Uwe Rathmann 2021-08-25 15:46:08 +02:00
parent 3983da2025
commit bd0c40b241
5 changed files with 53 additions and 121 deletions

View File

@ -4,6 +4,7 @@
*****************************************************************************/
#include "PieChartPainted.h"
#include "CircularProgressBar.h"
#include <QskAnimator.h>
#include <QskBox.h>
@ -13,112 +14,61 @@
#include <QskTextLabel.h>
#include <QskFunctions.h>
#include <QFontMetricsF>
#include <QGuiApplication>
#include <QQuickPaintedItem>
#include <QQuickWindow>
QSK_SUBCONTROL( PieChartPainted, Panel )
namespace
{
QColor invertedColor( const QColor& c )
class ProgressLabel : public QskTextLabel
{
QColor ret = { 255 - c.red(), 255 - c.green(), 255 - c.blue()};
return ret;
}
}
// ### There must be an easier way to do this
class ProgressBarAnimator : public QskAnimator
{
public:
ProgressBarAnimator( PieChartPainted* pieChart, CircularProgressBar* progressBar )
: m_pieChart( pieChart )
, m_progressBar( progressBar )
{
QQuickWindow* w = static_cast< QQuickWindow* >( qGuiApp->allWindows().at( 0 ) );
setWindow( w );
setDuration( 500 );
setEasingCurve( QEasingCurve::Linear );
setAutoRepeat( false );
}
void setup() override
{
m_backgroundColor = m_pieChart->color( PieChartPainted::Panel );
}
void advance( qreal value ) override
{
const QColor c = m_backgroundColor;
const QColor c2 = invertedColor( c );
const QColor newColor = QskRgb::interpolated( c2, c, value );
m_progressBar->setBackgroundColor( newColor );
QRadialGradient gradient = m_ringGradient;
QRadialGradient newGradient = gradient;
for( const QGradientStop& stop : gradient.stops() )
public:
ProgressLabel( QQuickItem* parent )
: QskTextLabel( parent )
{
QColor c = stop.second;
QColor c2 = invertedColor( c );
const QColor newColor = QskRgb::interpolated( c, c2, value );
newGradient.setColorAt( stop.first, newColor );
initSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
setLayoutAlignmentHint( Qt::AlignCenter );
setFontRole( QskSkin::SmallFont );
}
m_progressBar->update();
}
void setValue( int value )
{
setText( locale().toString( value ) + " " + locale().percent() );
}
};
}
private:
QColor m_backgroundColor;
QRadialGradient m_ringGradient;
PieChartPainted* m_pieChart;
CircularProgressBar* m_progressBar;
};
PieChartPainted::PieChartPainted( const QColor& color, const QskGradient& gradient, int progress, int /*value*/, QQuickItem* parent )
PieChartPainted::PieChartPainted( const QColor& textColor, const QskGradient& gradient,
int progress, QQuickItem* parent )
: QskControl( parent )
, m_color( color )
, m_gradient( gradient )
, m_progressBar( new CircularProgressBar( this ) )
, m_progressLabel( new QskTextLabel( this ) )
, m_animator( new ProgressBarAnimator( this, m_progressBar ) )
{
setAutoLayoutChildren( true );
setSubcontrolProxy( QskBox::Panel, PieChartPainted::Panel );
m_progressBar->setGradientHint( CircularProgressBar::Bar, gradient );
m_progressBar->setValue( progress );
auto progressBar = new CircularProgressBar( this );
progressBar->setGradientHint( CircularProgressBar::Bar, gradient );
progressBar->setValue( progress );
auto progressText = QString::number( progress ) + " %";
m_progressLabel->setText( progressText );
m_progressLabel->setFontRole( QskSkin::SmallFont );
m_progressLabel->setTextColor( color );
const QColor c = this->color( Panel );
m_progressBar->setBackgroundColor( c );
connect( qskSetup, &QskSetup::skinChanged,
[this]() { m_animator->start(); } );
auto progressLabel = new ProgressLabel( this );
progressLabel->setTextColor( textColor );
progressLabel->setValue( progress );
}
QSizeF PieChartPainted::contentsSizeHint( Qt::SizeHint, const QSizeF& ) const
QSizeF PieChartPainted::contentsSizeHint(
Qt::SizeHint which, const QSizeF& constraint ) const
{
return {57, 57};
}
void PieChartPainted::updateLayout()
{
m_progressBar->update();
const auto rect = layoutRect();
QFontMetricsF fm( m_progressLabel->effectiveFont( QskTextLabel::Text ) );
auto textWidth = qskHorizontalAdvance( fm, m_progressLabel->text() );
auto posX = rect.width() / 2 - textWidth / 2;
auto posY = rect.height() / 2 - fm.height() / 2;
m_progressLabel->setPosition( posX, posY );
m_progressLabel->setFixedWidth( textWidth );
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 );
}

View File

@ -6,27 +6,13 @@
#pragma once
#include <QskControl.h>
#include "CircularProgressBar.h"
class ProgressBarAnimator;
class QskTextLabel;
class PieChartPainted : public QskControl
{
public:
QSK_SUBCONTROLS( Panel )
PieChartPainted( const QColor&, const QskGradient&,
int progress, int value, QQuickItem* parent = nullptr );
int progress, QQuickItem* parent = nullptr );
protected:
QSizeF contentsSizeHint( Qt::SizeHint, const QSizeF& ) const override;
void updateLayout() override;
private:
QColor m_color;
QskGradient m_gradient;
CircularProgressBar* m_progressBar;
QskTextLabel* m_progressLabel;
ProgressBarAnimator* m_animator;
};

View File

@ -182,7 +182,6 @@ void Skin::initHints( const Palette& palette )
ed.setGradient( BoxWithButtons::Panel, palette.box );
ed.setGradient( UsageDiagramBox::Panel, palette.box );
ed.setColor( LightDisplay::Panel, palette.lightDisplay );
ed.setColor( PieChartPainted::Panel, palette.pieChart );
ed.setGradient( RoundButton::Panel, palette.roundButton );
ed.setBoxBorderColors( UsageDiagramBox::DaysBox, palette.weekdayBox );
ed.setColor( QskTextLabel::Text, palette.text );

View File

@ -15,7 +15,7 @@ class Skin : public QskSkin
{
public:
Palette( const QskGradient& menuBar, const QskGradient& mainContent,
const QskGradient& box, const QColor& lightDisplay, const QColor& pieChart,
const QskGradient& box, const QColor& lightDisplay,
const QskGradient& roundButton, const QColor& weekdayBox,
const QColor& text, const QColor& shadow,
const QskGradient& circularProgressBarGroove )
@ -23,7 +23,6 @@ class Skin : public QskSkin
, mainContent( mainContent )
, box( box )
, lightDisplay( lightDisplay )
, pieChart( pieChart )
, roundButton( roundButton )
, weekdayBox( weekdayBox )
, text( text )
@ -35,7 +34,6 @@ class Skin : public QskSkin
QskGradient mainContent;
QskGradient box;
QColor lightDisplay;
QColor pieChart;
QskGradient roundButton;
QColor weekdayBox;
QColor text;
@ -61,8 +59,7 @@ class DaytimeSkin : public Skin
DaytimeSkin( QObject* parent = nullptr )
: Skin(
Skin::Palette( {"#6D7BFB"}, {"#fbfbfb"}, {"#ffffff"},
"#ffffff", "#ffffff", {"#f7f7f7"},
{"#f4f4f4"}, Qt::black, Qt::black,
"#ffffff", {"#f7f7f7"}, {"#f4f4f4"}, Qt::black, Qt::black,
{ Qt::Horizontal, { { 0.0, 0xc4c4c4 }, { 0.5, 0xf8f8f8 }, { 1.0, 0xc4c4c4 } } } )
, parent )
{
@ -75,8 +72,7 @@ class NighttimeSkin : public Skin
NighttimeSkin( QObject* parent = nullptr )
: Skin(
Skin::Palette( {"#2937A7"}, {"#040404"}, {"#000000"},
"#000000", "#000000", {"#0a0a0a"},
{"#0c0c0c"}, Qt::white, Qt::white,
"#000000", {"#0a0a0a"}, {"#0c0c0c"}, Qt::white, Qt::white,
{ Qt::Horizontal, { { 0.0, 0x666666 }, { 0.5, 0x222222 }, { 1.0, 0x333333 } } } )
, parent )
{

View File

@ -51,8 +51,6 @@ TopBarItem::TopBarItem(
{
setSubcontrolProxy( QskLinearBox::Panel, Panel );
setAutoLayoutChildren( true );
setAutoAddChildren( true );
setSpacing( 15 );
auto* textLabel = new QskTextLabel( name, this );
@ -61,9 +59,12 @@ TopBarItem::TopBarItem(
auto* pieChartAndDisplay = new QskLinearBox( Qt::Horizontal, this );
pieChartAndDisplay->setSpacing( 10 );
QskAspect::Subcontrol subcontrol = subcontrolForIndex( index );
QColor textColor = color( subcontrol | QskAspect::TextColor );
new PieChartPainted( textColor, gradient, progress, value, pieChartAndDisplay );
const auto subcontrol = subcontrolForIndex( index );
const auto textColor = color( subcontrol | QskAspect::TextColor );
auto pieChart = new PieChartPainted(
textColor, gradient, progress, pieChartAndDisplay );
pieChart->setSizePolicy( Qt::Horizontal, QskSizePolicy::Constrained );
auto display = new QskLinearBox( Qt::Vertical, pieChartAndDisplay );
display->setSpacing( 0 );