AnalyzerBase: Refactor code
This commit is contained in:
@@ -32,10 +32,11 @@
|
|||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
|
#include <QBasicTimer>
|
||||||
|
#include <QShowEvent>
|
||||||
|
#include <QHideEvent>
|
||||||
#include <QTimerEvent>
|
#include <QTimerEvent>
|
||||||
#include <QtEvents>
|
|
||||||
|
|
||||||
#include "core/logging.h"
|
|
||||||
#include "engine/enginebase.h"
|
#include "engine/enginebase.h"
|
||||||
|
|
||||||
// INSTRUCTIONS Base2D
|
// INSTRUCTIONS Base2D
|
||||||
@@ -51,16 +52,34 @@
|
|||||||
|
|
||||||
Analyzer::Base::Base(QWidget *parent, const uint scopeSize)
|
Analyzer::Base::Base(QWidget *parent, const uint scopeSize)
|
||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
timeout_(40),
|
|
||||||
fht_(new FHT(scopeSize)),
|
fht_(new FHT(scopeSize)),
|
||||||
engine_(nullptr),
|
engine_(nullptr),
|
||||||
lastscope_(512),
|
lastscope_(512),
|
||||||
new_frame_(false),
|
new_frame_(false),
|
||||||
is_playing_(false) {}
|
is_playing_(false),
|
||||||
|
timeout_(40) {}
|
||||||
|
|
||||||
void Analyzer::Base::hideEvent(QHideEvent*) { timer_.stop(); }
|
Analyzer::Base::~Base() {
|
||||||
|
delete fht_;
|
||||||
|
}
|
||||||
|
|
||||||
void Analyzer::Base::showEvent(QShowEvent*) { timer_.start(timeout(), this); }
|
void Analyzer::Base::showEvent(QShowEvent*) {
|
||||||
|
timer_.start(timeout(), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Analyzer::Base::hideEvent(QHideEvent*) {
|
||||||
|
timer_.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Analyzer::Base::ChangeTimeout(const int timeout) {
|
||||||
|
|
||||||
|
timeout_ = timeout;
|
||||||
|
if (timer_.isActive()) {
|
||||||
|
timer_.stop();
|
||||||
|
timer_.start(timeout_, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void Analyzer::Base::transform(Scope &scope) {
|
void Analyzer::Base::transform(Scope &scope) {
|
||||||
|
|
||||||
@@ -186,10 +205,6 @@ void Analyzer::Base::demo(QPainter &p) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Analyzer::Base::polishEvent() {
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Analyzer::interpolate(const Scope &inVec, Scope &outVec) {
|
void Analyzer::interpolate(const Scope &inVec, Scope &outVec) {
|
||||||
|
|
||||||
double pos = 0.0;
|
double pos = 0.0;
|
||||||
|
|||||||
@@ -44,8 +44,8 @@
|
|||||||
|
|
||||||
class QHideEvent;
|
class QHideEvent;
|
||||||
class QShowEvent;
|
class QShowEvent;
|
||||||
class QTimerEvent;
|
|
||||||
class QPaintEvent;
|
class QPaintEvent;
|
||||||
|
class QTimerEvent;
|
||||||
|
|
||||||
namespace Analyzer {
|
namespace Analyzer {
|
||||||
|
|
||||||
@@ -55,19 +55,13 @@ class Base : public QWidget {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~Base() override { delete fht_; }
|
~Base() override;
|
||||||
|
|
||||||
int timeout() const { return timeout_; }
|
int timeout() const { return timeout_; }
|
||||||
|
|
||||||
void set_engine(EngineBase *engine) { engine_ = engine; }
|
void set_engine(EngineBase *engine) { engine_ = engine; }
|
||||||
|
|
||||||
void changeTimeout(int newTimeout) {
|
void ChangeTimeout(const int timeout);
|
||||||
timeout_ = newTimeout;
|
|
||||||
if (timer_.isActive()) {
|
|
||||||
timer_.stop();
|
|
||||||
timer_.start(timeout_, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void framerateChanged() {}
|
virtual void framerateChanged() {}
|
||||||
|
|
||||||
@@ -76,10 +70,8 @@ class Base : public QWidget {
|
|||||||
|
|
||||||
void hideEvent(QHideEvent*) override;
|
void hideEvent(QHideEvent*) override;
|
||||||
void showEvent(QShowEvent*) override;
|
void showEvent(QShowEvent*) override;
|
||||||
void paintEvent(QPaintEvent*) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
void timerEvent(QTimerEvent*) override;
|
void timerEvent(QTimerEvent *e) override;
|
||||||
|
|
||||||
void polishEvent();
|
|
||||||
|
|
||||||
int resizeExponent(int);
|
int resizeExponent(int);
|
||||||
int resizeForBands(const int);
|
int resizeForBands(const int);
|
||||||
@@ -90,13 +82,13 @@ class Base : public QWidget {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
QBasicTimer timer_;
|
QBasicTimer timer_;
|
||||||
int timeout_;
|
|
||||||
FHT *fht_;
|
FHT *fht_;
|
||||||
EngineBase *engine_;
|
EngineBase *engine_;
|
||||||
Scope lastscope_;
|
Scope lastscope_;
|
||||||
|
|
||||||
bool new_frame_;
|
bool new_frame_;
|
||||||
bool is_playing_;
|
bool is_playing_;
|
||||||
|
int timeout_;
|
||||||
};
|
};
|
||||||
|
|
||||||
void interpolate(const Scope&, Scope&);
|
void interpolate(const Scope&, Scope&);
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ void AnalyzerContainer::ChangeAnalyzer(const int id) {
|
|||||||
current_analyzer_->set_engine(engine_);
|
current_analyzer_->set_engine(engine_);
|
||||||
// Even if it is not supposed to happen, I don't want to get a dbz error
|
// Even if it is not supposed to happen, I don't want to get a dbz error
|
||||||
current_framerate_ = current_framerate_ == 0 ? kMediumFramerate : current_framerate_;
|
current_framerate_ = current_framerate_ == 0 ? kMediumFramerate : current_framerate_;
|
||||||
current_analyzer_->changeTimeout(1000 / current_framerate_);
|
current_analyzer_->ChangeTimeout(1000 / current_framerate_);
|
||||||
|
|
||||||
layout()->addWidget(current_analyzer_);
|
layout()->addWidget(current_analyzer_);
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ void AnalyzerContainer::ChangeFramerate(int new_framerate) {
|
|||||||
if (current_analyzer_) {
|
if (current_analyzer_) {
|
||||||
// Even if it is not supposed to happen, I don't want to get a dbz error
|
// Even if it is not supposed to happen, I don't want to get a dbz error
|
||||||
new_framerate = new_framerate == 0 ? kMediumFramerate : new_framerate;
|
new_framerate = new_framerate == 0 ? kMediumFramerate : new_framerate;
|
||||||
current_analyzer_->changeTimeout(1000 / new_framerate);
|
current_analyzer_->ChangeTimeout(1000 / new_framerate);
|
||||||
|
|
||||||
// notify the current analyzer that the framerate has changed
|
// notify the current analyzer that the framerate has changed
|
||||||
current_analyzer_->framerateChanged();
|
current_analyzer_->framerateChanged();
|
||||||
|
|||||||
Reference in New Issue
Block a user