first re-commit.
This commit is contained in:
151
swbarwidget.cpp
Normal file
151
swbarwidget.cpp
Normal file
@@ -0,0 +1,151 @@
|
||||
/***************************************************************************
|
||||
|
||||
source::worx raDIYo
|
||||
Copyright © 2020-2022 c.holzheuer
|
||||
chris@sourceworx.org
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <QtGlobal>
|
||||
|
||||
#include <swbarwidget.h>
|
||||
|
||||
|
||||
/**
|
||||
* @brief SWBarWidget::SWBarWidget : Konstruktor.
|
||||
* Hier werden die für alle Subklassen gemeinsam gültigen
|
||||
* Paramter initialisiert, etwa @see setColorRange, @see calcSizeRatio
|
||||
*/
|
||||
|
||||
SWBarWidget::SWBarWidget( QWidget* parent )
|
||||
: QWidget( parent )
|
||||
{
|
||||
|
||||
|
||||
// Papas Lieblingsfarben
|
||||
QStringList list { "#010130", "#20014e", "#0C0786", "#40039C",
|
||||
"#6A00A7", "#8F0DA3", "#B02A8F", "#CA4678",
|
||||
"#E06461", "#F1824C", "#FCA635", "#FCCC25",
|
||||
"#FFEE00", "#EFF821" };
|
||||
setColorRange( list );
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief gibt die Anzahl der Balken des Diagramms zurück.
|
||||
*/
|
||||
|
||||
int SWBarWidget::numBars()
|
||||
{
|
||||
return _numBars;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setzt die die Anzahl der Balken des Diagramms.
|
||||
*/
|
||||
|
||||
void SWBarWidget::setNumBars( int bars )
|
||||
{
|
||||
Q_ASSERT( bars > 0 );
|
||||
_numBars = bars;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gibt die Anzahl der Blöcke pro Balken des Diagramms zurück.
|
||||
*/
|
||||
|
||||
int SWBarWidget::numBlocks()
|
||||
{
|
||||
return _numBlocks;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setzt die Anzahl der Blöcke pro Balken des Diagramms.
|
||||
*
|
||||
*/
|
||||
|
||||
void SWBarWidget::setNumBlocks( int blocks )
|
||||
{
|
||||
Q_ASSERT( blocks > 0 );
|
||||
_numBlocks = blocks;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gib denb Abstand in Pixeln zwischen Blöcken und Balken zurück.
|
||||
* Default ist 3.
|
||||
*/
|
||||
|
||||
int SWBarWidget::padding()
|
||||
{
|
||||
return _padding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Setzt das 'padding', also den Abstand zwischen Blöcken und Balken des Diagramms
|
||||
* @param padding der Abstand in Pixeln.
|
||||
*/
|
||||
|
||||
void SWBarWidget::setPadding( int padding )
|
||||
{
|
||||
_padding = padding;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Intere Funktion zur Ermittlung der Farbe eines Blocks.
|
||||
*/
|
||||
|
||||
QColor SWBarWidget::getBlockColor( int x, int y )
|
||||
{
|
||||
Q_UNUSED( x )
|
||||
int virtIdx = _numBlocks - 1 - y;
|
||||
double _sizeRatio = (double) _numBlocks / (double) _colors.size();
|
||||
int realIdx = (int) ( (double) virtIdx / _sizeRatio );
|
||||
return _colors[ realIdx ];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setzt die Farbliste zur Darstellung der Blöcke eines Balkens.
|
||||
* @param colorlist Eine Stringliste mit den Hexcodes der Farben.
|
||||
*/
|
||||
|
||||
void SWBarWidget::setColorRange( const QStringList& colorlist )
|
||||
{
|
||||
Q_ASSERT( !colorlist.empty() );
|
||||
|
||||
_colors.clear();
|
||||
for( const QString& color : colorlist )
|
||||
_colors.append( QColor( color ) );
|
||||
_numBlocks =_colors.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt die Farbliste zur Darstellung der Blöcke eines Balkens.
|
||||
* @param Ein Vector mit QColors.
|
||||
*/
|
||||
|
||||
void SWBarWidget::setColorRange( const SWColorVec& colorlist )
|
||||
{
|
||||
Q_ASSERT( !colorlist.empty() );
|
||||
|
||||
_colors.clear();
|
||||
for( const QColor& color : colorlist )
|
||||
_colors.append( color );
|
||||
_numBlocks =_colors.size();
|
||||
}
|
Reference in New Issue
Block a user