17#include <QRandomGenerator>
18#include <swspectrumwidget.h>
21SWSpectrumWidget::SWSpectrumWidget( QWidget* parent )
25 setNumBarsBlocks( 16, 16 );
26 _valueList.resize( _numBars );
35void SWSpectrumWidget::onTimer()
49void SWSpectrumWidget::paintEvent( QPaintEvent* event )
53 Q_ASSERT( _colors.size() >= _maxNumBarsBlocks );
55 QPainter painter(
this );
56 painter.setBackgroundMode( Qt::TransparentMode );
62 int frameWidth = rect().width();
63 int frameHeight = rect().height();
64 int blockHeight = frameHeight / _numBlocks;
66 int blockWidth = frameWidth / _numBars;
70 for(
int x=0; x<_numBars; ++x )
74 int barHeight = qRound( _valueList[x] * frameHeight );
75 int blocks = barHeight / blockHeight;
76 int blockPosY = frameHeight - blocks * blockHeight;
80 for(
int y = 0; y < blocks; ++y )
82 QRect block = QRect( blockPosX, blockPosY, blockWidth - _padding, blockHeight - _padding );
83 painter.fillRect( block, getBlockColor( x, y ) );
85 blockPosY += blockHeight;
88 blockPosX += blockWidth;