Skip to content

Commit

Permalink
polarplot: Add background color compatible with theme
Browse files Browse the repository at this point in the history
This allows a better visualization of the plot and the head indicator

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
  • Loading branch information
patrickelectric committed Aug 31, 2019
1 parent b1ed1d5 commit b1b1c7f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/waterfall/polarplot.cpp
Expand Up @@ -15,6 +15,7 @@ uint16_t PolarPlot::_angularResolution = 400;

PolarPlot::PolarPlot(QQuickItem *parent)
:Waterfall(parent)
,_backgroundImage(1, 1, QImage::Format_RGBA8888)
,_distances(_angularResolution, 0)
,_image(2500, 2500, QImage::Format_RGBA8888)
,_maxDistance(0)
Expand All @@ -30,13 +31,28 @@ PolarPlot::PolarPlot(QQuickItem *parent)
_updateTimer->start(50);

connect(this, &Waterfall::mousePosChanged, this, &PolarPlot::updateMouseColumnData);
connect(this, &Waterfall::themeChanged, this, &PolarPlot::clear);
connect(this, &QQuickItem::widthChanged, this, &PolarPlot::updateMask);
connect(this, &QQuickItem::heightChanged, this, &PolarPlot::updateMask);
}

void PolarPlot::updateMask()
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
_polarBackgroundMask.clear();
#else
QPainterPath newPath;
_polarBackgroundMask = newPath;
#endif
_polarBackgroundMask.addEllipse(0, 0, width(), height());
}

void PolarPlot::clear()
{
qCDebug(polarplot) << "Cleaning waterfall and restarting internal variables";
_image.fill(Qt::transparent);
_distances.fill(0, _angularResolution);
_backgroundImage.fill(valueToRGB(0));
_maxDistance = 0;
}

Expand All @@ -49,6 +65,8 @@ void PolarPlot::paint(QPainter *painter)

// http://blog.qt.io/blog/2006/05/13/fast-transformed-pixmapimage-drawing/
pix = QPixmap::fromImage(_image, Qt::NoFormatConversion);
_painter->setClipPath(_polarBackgroundMask);
_painter->drawImage(QRect(0, 0, width(), height()), _backgroundImage);
_painter->drawPixmap(QRect(0, 0, width(), height()), pix, QRect(0, 0, _image.width(), _image.height()));
}

Expand Down
12 changes: 8 additions & 4 deletions src/waterfall/polarplot.h
Expand Up @@ -105,23 +105,27 @@ class PolarPlot : public Waterfall
Q_DISABLE_COPY(PolarPlot)

/**
* @brief Load user gradients
* @brief Update mouse column information
*
*/
void loadUserGradients();
void updateMouseColumnData();

/**
* @brief Update mouse column information
* @brief Update mask variable to remove unnecessary pixels
* outside the main area.
* For this plot, the mask is a full circle.
*
*/
void updateMouseColumnData();
void updateMask();

QImage _backgroundImage;
QVector<float> _distances;
QImage _image;
float _maxDistance;
float _mouseSampleAngle;
float _mouseSampleDistance;
QPainter *_painter;
QPainterPath _polarBackgroundMask;
static uint16_t _angularResolution;
QTimer* _updateTimer;
};

0 comments on commit b1b1c7f

Please sign in to comment.