raDIYo 0.4
swabstractbarwidget.cpp
1/***************************************************************************
2
3 source::worx raDIYo
4 Copyright © 2020-2022 c.holzheuer
5 c.holzheuer@sourceworx.org
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12***************************************************************************/
13
14#include <QDebug>
15#include <QPainter>
16#include <QtGlobal>
17
18#include <swabstractbarwidget.h>
19
20
29 : QWidget( parent )
30{
31
32 //QStringList list { "#0C0786", "#0C0786", "#40039C", "#6A00A7",
33 // "#8F0DA3", "#B02A8F", "#CA4678", "#E06461",
34 // "#F1824C", "#FCA635", "#FCCC25", "#ffeaa0",
35 // "#EFF821", "#fbff97" };
36
37 // Papas Lieblingsfarben
38 QStringList list { "#010130", "#20014e", "#0C0786", "#40039C",
39 "#6A00A7", "#8F0DA3", "#B02A8F", "#CA4678",
40 "#E06461", "#F1824C", "#FCA635", "#FCCC25",
41 "#FFEE00", "#EFF821" };
42
43 setColorRange( list );
44 _valueList.resize( list.length() );
45 _maxNumBarsBlocks = _numBars = _numBlocks = list.length();
46 calcSizeRatio();
47
48}
49
50
56{
57
58
59}
60
61//--
62
63
71{
72 return _gradientMode;
73}
74
75
82{
83 _gradientMode = mode;
84 update();
85}
86
87
95{
96 return _barMode;
97}
98
99
106{
107 _barMode = mode;
108 update();
109}
110
111
118{
119 return _numBars;
120}
121
122
129{
130 Q_ASSERT( bars > 0 );
131 _numBars = bars;
132 update();
133}
134
135
142{
143 return _numBlocks;
144}
145
146
153{
154 Q_ASSERT( blocks > 0 );
155 _numBlocks = blocks;
156 calcSizeRatio();
157 update();
158}
159
160
167void SWAbstractBarWidget::setNumBarsBlocks( int bars, int blocks )
168{
169 setNumBars( bars );
170 setNumBlocks( blocks );
171}
172
173
180{
181 return _value;
182}
183
184
190void SWAbstractBarWidget::setValue( double newvalue )
191{
192 Q_ASSERT( newvalue >= _minValue );
193 Q_ASSERT( newvalue <= _maxValue );
194}
195
202void SWAbstractBarWidget::setRange( int rangeFrom, int rangeTo )
203{
204 Q_ASSERT( rangeFrom >= 0 );
205 Q_ASSERT( rangeFrom < rangeTo );
206 _rangeFrom = rangeFrom;
207 _rangeTo = rangeTo;
208}
209
210
211void SWAbstractBarWidget::calcSizeRatio()
212{
213 _sizeRatio = (double) _numBlocks / (double) _maxNumBarsBlocks;
214}
215
216
217QColor SWAbstractBarWidget::getBlockColor( int x, int y )
218{
219 int virtIdx = _gradientMode ? _numBlocks - 1 - y : x ;
220 int realIdx = (int) ( (double) virtIdx / _sizeRatio );
221 return _colors[ realIdx ];
222}
223
224
234{
235
236 double testvalue = qBound( _rangeFrom, newvalue, _rangeTo ) / 1000.0 * _value;
237 qDebug() << "SWAbstractBarWidget::onDialValueChanged" << newvalue << ": " << testvalue;
238
239 if( testvalue == _value )
240 return;
241
242 _value = testvalue;
243 update();
244
245}
246
247void SWAbstractBarWidget::clearValueList()
248{
249 _valueList.clear();
250 _valueList.resize( _numBars );
251 update();
252}
253
254void SWAbstractBarWidget::onValueListChanged( const SWDoubleVec& freshdata )
255{
256 _valueList = freshdata;
257 _valueList.resize( _numBars );
258 update();
259
260}
261
262
263void SWAbstractBarWidget::setColorRange( const QStringList& colorlist )
264{
265 Q_ASSERT( !colorlist.empty() );
266
267 _colors.clear();
268 for( const QString& color : colorlist )
269 _colors.append( QColor( color ) );
270 _maxNumBarsBlocks = _numBars = _numBlocks =_colors.size();
271
272}
273
274void SWAbstractBarWidget::setColorRange( const SWColorVec& colorlist )
275{
276 Q_ASSERT( !colorlist.empty() );
277
278 _colors.clear();
279 for( const QColor& color : colorlist )
280 _colors.append( color );
281 _maxNumBarsBlocks = _numBars = _numBlocks =_colors.size();
282}
bool gradientMode()
SWAbstractBarWidget::gradientMode.
void setNumBarsBlocks(int bars, int blocks)
SWAbstractBarWidget::setNumBarsBlocks.
void setGradienMode(bool mode)
SWAbstractBarWidget::setGradienMode.
void setNumBlocks(int blocks)
SWAbstractBarWidget::setNumBlocks.
int numBlocks()
SWAbstractBarWidget::numBlocks.
void setRange(int rangeFrom, int rangeTo)
SWAbstractBarWidget::setRange.
SWAbstractBarWidget(QWidget *parent=0)
SWAbstractBarWidget::SWAbstractBarWidget : Konstruktor.
void setValue(double value)
SWAbstractBarWidget::setValue.
double value()
SWAbstractBarWidget::value.
int numBars()
SWAbstractBarWidget::numBars.
virtual void onDialValueChanged(int newvalue)
SWAbstractBarWidget::onDialValueChanged.
bool barMode()
SWAbstractBarWidget::barMode.
void setBarMode(bool mode)
SWAbstractBarWidget::setBarMode.
virtual ~SWAbstractBarWidget()
SWAbstractBarWidget::~SWAbstractBarWidget: Destruktor, macht nix.
void setNumBars(int bars)
SWAbstractBarWidget::setNumBars.