123 lines
2.6 KiB
C++
123 lines
2.6 KiB
C++
/***************************************************************************
|
|
|
|
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 <QRandomGenerator>
|
|
#include <swspectrumwidget.h>
|
|
|
|
|
|
/**
|
|
* @brief SWSpectrumWidget::SWSpectrumWidget
|
|
* @param parent
|
|
*/
|
|
|
|
SWSpectrumWidget::SWSpectrumWidget( QWidget* parent )
|
|
: SWBarWidget( parent )
|
|
{
|
|
|
|
setNumBars( 16 );
|
|
setNumBlocks( 16 );
|
|
_valueList.resize( _numBars );
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* @brief SWSpectrumWidget::~SWSpectrumWidget
|
|
*/
|
|
|
|
SWSpectrumWidget::~SWSpectrumWidget()
|
|
{
|
|
// stop threads
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Löscht die Werteliste und ruft 'update' auf.
|
|
*/
|
|
|
|
void SWSpectrumWidget::clearValueList()
|
|
{
|
|
_valueList.clear();
|
|
_valueList.resize( _numBars );
|
|
update();
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Slot; Wird aufgerufen, wenn sich die Werteliste geändert hat.
|
|
* Ruft update auf.
|
|
* @param freshdata
|
|
*/
|
|
|
|
void SWSpectrumWidget::onValueListChanged( const SWValVec& freshdata )
|
|
{
|
|
_valueList = freshdata;
|
|
_valueList.resize( _numBars );
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Zeichnet das Widget neu.
|
|
* @param event
|
|
*/
|
|
|
|
void SWSpectrumWidget::paintEvent( QPaintEvent* )
|
|
{
|
|
|
|
QPainter painter( this );
|
|
painter.setBackgroundMode( Qt::TransparentMode );
|
|
//painter.fillRect(rect(), Qt::darkGray);
|
|
|
|
// Draw the bars
|
|
|
|
// der Rand wird im Parentwidget 'beschlossen'
|
|
int frameWidth = rect().width();
|
|
int frameHeight = rect().height();
|
|
int blockHeight = frameHeight / _numBlocks;
|
|
int blockWidth = qRound( double( frameWidth ) / double( _numBars ) );
|
|
//int blockWidth = frameWidth / _numBars;
|
|
|
|
int blockPosX = 0;
|
|
for( int x=0; x<_numBars; ++x )
|
|
{
|
|
|
|
int barHeight = qRound( _valueList[x] * frameHeight );
|
|
int blocks = barHeight / blockHeight;
|
|
int blockPosY = frameHeight - blocks * blockHeight;
|
|
|
|
for( int y = 0; y < blocks; ++y )
|
|
{
|
|
QRect block = QRect( blockPosX, blockPosY, blockWidth - _padding, blockHeight - _padding );
|
|
painter.fillRect( block, getBlockColor( x, y ) );
|
|
//painter.fillRect( block, _colors[y] );
|
|
//painter.drawText( block, QString::number(y) );
|
|
blockPosY += blockHeight;
|
|
}
|
|
|
|
blockPosX += blockWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|