Added rotation of waterfall plot.

master
Hannes Matuschek 12 years ago
parent 25460354f2
commit 6ecbe5ca87

@ -73,10 +73,11 @@ LinearColorMap::map(const double &value) {
/* ****************************************************************************************** *
* Implementation of WaterFallView
* ****************************************************************************************** */
WaterFallView::WaterFallView(SpectrumProvider *spectrum, size_t height, QWidget *parent)
: QWidget(parent), _spectrum(spectrum), _N(_spectrum->fftSize()), _M(height), _waterfall(_N,_M)
WaterFallView::WaterFallView(SpectrumProvider *spectrum, size_t hist, Direction dir, QWidget *parent)
: QWidget(parent), _spectrum(spectrum), _N(_spectrum->fftSize()), _M(hist), _dir(dir),
_waterfall(_N,_M)
{
setMinimumHeight(height);
setMinimumHeight(hist);
// Fill waterfall pixmap
_waterfall.fill(Qt::black);
// Create color map
@ -93,6 +94,7 @@ WaterFallView::WaterFallView(SpectrumProvider *spectrum, size_t height, QWidget
void
WaterFallView::_onSpectrumUpdated() {
if (_waterfall.isNull() || (_M==0) || (_N==0)) { return; }
QPainter painter(&_waterfall);
// scroll pixmap one pixel up
QRect target(0,0, _N, _M-1), source(0,1,_N,_M-1);
@ -131,8 +133,29 @@ void
WaterFallView::paintEvent(QPaintEvent *evt) {
QPainter painter(this);
painter.save();
// Draw scaled pixmap
painter.drawPixmap(evt->rect(), _waterfall.scaled(this->width(), this->height()), evt->rect());
// Draw transformed pixmap
QTransform trafo;
switch (_dir) {
case BOTTOM_UP:
trafo.scale(this->width()/qreal(_N), this->height()/qreal(_M));
break;
case LEFT_RIGHT:
trafo.rotate(90);
trafo.scale(this->width()/qreal(_M), this->height()/qreal(_N));
break;
case TOP_DOWN:
trafo.rotate(180);
trafo.scale(this->width()/qreal(_N), this->height()/qreal(_M));
break;
case RIGHT_LEFT:
trafo.rotate(270);
trafo.scale(this->width()/qreal(_M), this->height()/qreal(_N));
break;
}
painter.setTransform(trafo);
painter.drawPixmap(evt->rect(), _waterfall, evt->rect());
painter.restore();
}

@ -70,12 +70,17 @@ class WaterFallView : public QWidget
{
Q_OBJECT
public:
typedef enum {
BOTTOM_UP, TOP_DOWN, LEFT_RIGHT, RIGHT_LEFT
} Direction;
public:
/** Constructor.
* @param spectrum Specifies the spectrum sink.
* @param height Specifies the number of PSDs to display.
* @param hist Specifies the number of PSDs to display.
* @param parent The parent widget. */
explicit WaterFallView(SpectrumProvider *spectrum, size_t height=100, QWidget *parent = 0);
explicit WaterFallView(SpectrumProvider *spectrum, size_t hist=100, Direction dir=BOTTOM_UP, QWidget *parent = 0);
signals:
void click(double f);
@ -98,6 +103,8 @@ protected:
size_t _N;
/** "Height of the spectrum. */
size_t _M;
/** Specifies the direction of the waterfall. */
Direction _dir;
/** The waterfall spectrogram. */
QPixmap _waterfall;
/** The color map to be used. */

Loading…
Cancel
Save