Changeset - c51c9195eb8f
[Not reviewed]
snapshots
0 4 2
Hasan Yavuz ÖZDERYA - 10 years ago 2015-09-30 07:40:13
hy@ozderya.net
show flashing overlay when snapshot taken
6 files changed with 153 insertions and 0 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -74,6 +74,7 @@ add_executable(${PROGRAM_NAME} WIN32
 
  snapshot.cpp
 
  snapshotview.cpp
 
  snapshotmanager.cpp
 
  plotsnapshotoverlay.cpp
 
  ${UI_FILES}
 
  ${RES_FILES}
 
  misc/windows_icon.rc
mainwindow.cpp
Show inline comments
 
@@ -108,6 +108,9 @@ MainWindow::MainWindow(QWidget *parent) 
 
    QObject::connect(ui->actionClear, SIGNAL(triggered(bool)),
 
                     this, SLOT(clearPlot()));
 

	
 
    QObject::connect(snapshotMan.takeSnapshotAction(), &QAction::triggered,
 
                     ui->plot, &Plot::flashSnapshotOverlay);
 

	
 
    // setup number of channels spinbox
 
    QObject::connect(ui->spNumOfChannels,
 
                     SELECT<int>::OVERLOAD_OF(&QSpinBox::valueChanged),
plot.cpp
Show inline comments
 
@@ -72,6 +72,13 @@ Plot::Plot(QWidget* parent) :
 
    connect(&_unzoomAction, &QAction::triggered, this, &Plot::unzoom);
 
    connect(&_darkBackgroundAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
            this, &Plot::darkBackground);
 

	
 
    snapshotOverlay = NULL;
 
}
 

	
 
Plot::~Plot()
 
{
 
    if (snapshotOverlay != NULL) delete snapshotOverlay;
 
}
 

	
 
void Plot::setAxis(bool autoScaled, double yAxisMin, double yAxisMax)
 
@@ -187,3 +194,26 @@ QColor Plot::makeColor(unsigned int chan
 
        return QColor::fromHsv(360*i/n + 360/pow(2,p+1), 255, 230);
 
    }
 
}
 

	
 
void Plot::flashSnapshotOverlay()
 
{
 
    if (snapshotOverlay != NULL) delete snapshotOverlay;
 

	
 
    QColor color;
 
    if (_darkBackgroundAction.isChecked())
 
    {
 
        color = QColor(Qt::white);
 
    }
 
    else
 
    {
 
        color = QColor(Qt::black);
 
    }
 

	
 
    snapshotOverlay = new PlotSnapshotOverlay(this->canvas(), color);
 
    connect(snapshotOverlay, &PlotSnapshotOverlay::done,
 
            [this]()
 
            {
 
                delete snapshotOverlay;
 
                snapshotOverlay = NULL;
 
            });
 
}
plot.h
Show inline comments
 
@@ -26,8 +26,10 @@
 
#include <qwt_plot.h>
 
#include <qwt_plot_grid.h>
 
#include <qwt_plot_shapeitem.h>
 

	
 
#include "zoomer.h"
 
#include "scalezoomer.h"
 
#include "plotsnapshotoverlay.h"
 

	
 
class Plot : public QwtPlot
 
{
 
@@ -35,6 +37,7 @@ class Plot : public QwtPlot
 

	
 
public:
 
    Plot(QWidget* parent = 0);
 
    ~Plot();
 
    void setAxis(bool autoScaled, double yMin = 0, double yMax = 1);
 

	
 
    QList<QAction*> menuActions();
 
@@ -48,6 +51,7 @@ private:
 
    ScaleZoomer sZoomer;
 
    QwtPlotGrid grid;
 
    QwtPlotShapeItem rectItem;
 
    PlotSnapshotOverlay* snapshotOverlay;
 

	
 
    QAction _showGridAction;
 
    QAction _showMinorGridAction;
 
@@ -62,6 +66,8 @@ public slots:
 
    void unzoom();
 
    void darkBackground(bool enabled = true);
 

	
 
    void flashSnapshotOverlay();
 

	
 
private slots:
 
    void unzoomed();
 
};
plotsnapshotoverlay.cpp
Show inline comments
 
new file 100644
 
/*
 
  Copyright © 2015 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
  serialplot 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 3 of the License, or
 
  (at your option) any later version.
 

	
 
  serialplot is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU General Public License for more details.
 

	
 
  You should have received a copy of the GNU General Public License
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include <algorithm>
 
#include <QPen>
 

	
 
#include "plotsnapshotoverlay.h"
 

	
 
#define LINE_WIDTH (10)
 
#define ANIM_LENGTH (500) // milliseconds
 
#define UPDATE_PERIOD (20) // milliseconds
 

	
 
PlotSnapshotOverlay::PlotSnapshotOverlay(QWidget* widget, QColor color) :
 
    QwtWidgetOverlay(widget)
 
{
 
    _color = color;
 
    animTimer.setSingleShot(true);
 
    animTimer.setInterval(ANIM_LENGTH);
 
    updateTimer.setSingleShot(false);
 
    updateTimer.setInterval(UPDATE_PERIOD);
 

	
 
    connect(&updateTimer, &QTimer::timeout, [this](){this->updateOverlay();});
 
    connect(&animTimer, &QTimer::timeout, &updateTimer, &QTimer::stop);
 
    connect(&animTimer, &QTimer::timeout, this, &PlotSnapshotOverlay::done);
 

	
 
    animTimer.start();
 
    updateTimer.start();
 
}
 

	
 
void PlotSnapshotOverlay::drawOverlay(QPainter* painter) const
 
{
 
        if (!animTimer.isActive()) return;
 
    QColor lineColor = _color;
 

	
 
    double fadingRatio = ((double) animTimer.remainingTime()) / ANIM_LENGTH;
 
    lineColor.setAlpha(std::min(255, (int) (255*fadingRatio)));
 

	
 
    QPen pen(lineColor);
 
    pen.setWidth(LINE_WIDTH);
 
    pen.setJoinStyle(Qt::MiterJoin);
 

	
 
    int width = painter->device()->width();
 
    int height = painter->device()->height();
 

	
 
    painter->save();
 
    painter->setPen(pen);
 
    painter->drawRect(LINE_WIDTH/2, LINE_WIDTH/2, width-LINE_WIDTH, height-LINE_WIDTH);
 
    painter->restore();
 
}
plotsnapshotoverlay.h
Show inline comments
 
new file 100644
 
/*
 
  Copyright © 2015 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
  serialplot 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 3 of the License, or
 
  (at your option) any later version.
 

	
 
  serialplot is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU General Public License for more details.
 

	
 
  You should have received a copy of the GNU General Public License
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#ifndef PLOTSNAPSHOTOVERLAY_H
 
#define PLOTSNAPSHOTOVERLAY_H
 

	
 
#include <QColor>
 
#include <QPainter>
 
#include <QTimer>
 
#include <qwt_widget_overlay.h>
 

	
 
// Draws a sort of flashing effect on plot widget when snapshot taken
 
class PlotSnapshotOverlay : public QwtWidgetOverlay
 
{
 
    Q_OBJECT
 

	
 
public:
 
    PlotSnapshotOverlay(QWidget* widget, QColor color);
 

	
 
protected:
 
    void drawOverlay(QPainter*) const;
 

	
 
signals:
 
    void done(); // indicates that animation completed
 

	
 
private:
 
    QColor _color;
 
    QTimer animTimer; // controls fading
 
    QTimer updateTimer; // need to force repaint the canvas
 
};
 

	
 
#endif // PLOTSNAPSHOTOVERLAY_H
0 comments (0 inline, 0 general)