Skip to content

Commit

Permalink
Adds click action for BFO frequency set
Browse files Browse the repository at this point in the history
  • Loading branch information
sardylan committed Jul 23, 2020
1 parent b7ee14a commit 35ebec7
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 64 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

set (APPLICATION_NAME "Audio Receiver")
set (APPLICATION_VERSION "0.8.5")
set (APPLICATION_VERSION "0.9.0")

set (ORGANIZATION_NAME "The HellNet.org")
set (ORGANIZATION_DOMAIN "thehellnet.org")
Expand Down
79 changes: 31 additions & 48 deletions src/widgets/waterfall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Waterfall::Waterfall(QWidget *parent) {
frequency = 0;
bfoEnabled = false;
bfoFrequency = 0;

mousePosX = 0;
showMousePos = false;
}

Waterfall::~Waterfall() = default;
Expand Down Expand Up @@ -101,46 +104,6 @@ void Waterfall::paintGL() {
glEnd();
}

// unsigned int interval = 0;
// unsigned int intervalBig = 0;
//
// if (maxFrequency == 8000) {
// interval = 500;
// intervalBig = 1000;
// } else if (maxFrequency == 11025) {
// interval = 500;
// intervalBig = 1000;
// } else if (maxFrequency == 22050) {
// interval = 1000;
// intervalBig = 2000;
// } else if (maxFrequency == 44100) {
// interval = 2000;
// intervalBig = 4000;
// } else if (maxFrequency == 48000) {
// interval = 2000;
// intervalBig = 4000;
// } else if (maxFrequency == 96000) {
// interval = 4000;
// intervalBig = 8000;
// }
//
// if (interval > 0) {
// for (int iterX = 0; iterX < maxFrequency; iterX += interval) {
// glBegin(GL_LINES);
//
// if (iterX % intervalBig == 0)
// glColor4ub(64, 64, 64, 128);
// else
// glColor4ub(32, 32, 32, 128);
//
// float x = (float) iterX / maxFrequency;
// glVertex2f(x, 0);
// glVertex2f(x, height);
//
// glEnd();
// }
// }

if (bfoEnabled && bfoFrequency >= 0 && bfoFrequency <= frequency) {
qreal x = (qreal) bfoFrequency / frequency;
glBegin(GL_LINES);
Expand All @@ -150,14 +113,34 @@ void Waterfall::paintGL() {
glEnd();
}

// if (showMousePos) {
// float x = (float) mousePosX / width;
// glBegin(GL_LINES);
// glColor4ub(255, 255, 255, 64);
// glVertex2f(x, 0);
// glVertex2f(x, height);
// glEnd();
// }
if (bfoEnabled && showMousePos) {
qreal x = (qreal) mousePosX / width;

glBegin(GL_LINES);
glColor4ub(128, 128, 128, 64);
glVertex2f(x, 0);
glVertex2f(x, height);
glEnd();
}
}

void Waterfall::mouseMoveEvent(QMouseEvent *event) {
mousePosX = event->pos().x();

if (event->button() == Qt::LeftButton) {
auto mouseFrequency = (unsigned int) (((double) mousePosX / width) * frequency);
QMetaObject::invokeMethod(this, "newClickFrequency", Qt::QueuedConnection, Q_ARG(unsigned int, mouseFrequency));
}
}

void Waterfall::enterEvent(QEvent *event) {
if (event->type() == QEvent::Enter)
showMousePos = true;
}

void Waterfall::leaveEvent(QEvent *event) {
if (event->type() == QEvent::Leave)
showMousePos = false;
}

void Waterfall::addData(const QList<qreal> &values) {
Expand Down
16 changes: 16 additions & 0 deletions src/widgets/waterfall.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <QtCore/QtDebug>
#include <QtCore/QList>
#include <QtCore/QDateTime>
#include <QtCore/QEvent>

#include <QtGui/QMouseEvent>

#include <QtWidgets/QOpenGLWidget>

Expand Down Expand Up @@ -61,6 +64,12 @@ namespace audioreceiver::widgets {

void paintGL() override;

void mouseMoveEvent(QMouseEvent *event) override;

void enterEvent(QEvent *event) override;

void leaveEvent(QEvent *event) override;

private:

int width;
Expand All @@ -72,8 +81,15 @@ namespace audioreceiver::widgets {
bool bfoEnabled;
unsigned int bfoFrequency;

int mousePosX;
bool showMousePos;

void cleanDataList();

signals:

void newClickFrequency(unsigned int frequency);

};

}
Expand Down
25 changes: 13 additions & 12 deletions src/windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,6 @@ void Main::updateWaterfall(const QList<qreal> &values) {
QMetaObject::invokeMethod(waterfall, "addData", Qt::QueuedConnection, Q_ARG(const QList<qreal>, values));
}

void Main::updateBFOEnabled() {
bool status = ui->bfoEnableCheckBox->isChecked();

waterfall->setBfoEnabled(status);

ui->bfoFrequencySlider->setEnabled(status);
ui->bfoFrequencyValue->setEnabled(status);
}

void Main::updateGainValue() {
int value = ui->gainSlider->value();
qreal gain = (qreal) value / AUDIORECEIVER_AUDIO_GAIN_RESOLUTION;
Expand All @@ -132,8 +123,16 @@ void Main::updateGainValue() {
QMetaObject::invokeMethod(this, "newGainValue", Qt::QueuedConnection, Q_ARG(qreal, gain));
}

void Main::updateBFOValue() {
int value = ui->bfoFrequencySlider->value();
void Main::updateBFOEnabled() {
bool status = ui->bfoEnableCheckBox->isChecked();

waterfall->setBfoEnabled(status);

ui->bfoFrequencySlider->setEnabled(status);
ui->bfoFrequencyValue->setEnabled(status);
}

void Main::updateBFOValue(int value) {
ui->bfoFrequencyValue->setText(QString("%1 Hz").arg(value));
waterfall->setBfoFrequency(value);
QMetaObject::invokeMethod(this, "newBFOFrequency", Qt::QueuedConnection, Q_ARG(unsigned int, value));
Expand All @@ -151,13 +150,15 @@ void Main::signalConnect() {

connect(ui->gainSlider, &QSlider::valueChanged, this, &Main::updateGainValue);
connect(ui->bfoFrequencySlider, &QSlider::valueChanged, this, &Main::updateBFOValue);

connect(waterfall, &widgets::Waterfall::newClickFrequency, this, &Main::updateBFOValue);
}

void Main::initUi() {
ui->bfoFrequencySlider->setMinimum(0);
ui->bfoFrequencySlider->setMaximum(1);
ui->bfoFrequencySlider->setValue(0);
updateBFOValue();
updateBFOValue(ui->bfoFrequencySlider->value());

ui->bfoEnableCheckBox->setChecked(false);
updateBFOEnabled();
Expand Down
6 changes: 3 additions & 3 deletions src/windows/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ namespace audioreceiver::windows {

void updateClock();

void updateBFOEnabled();

void updateGainValue();

void updateBFOValue();
void updateBFOEnabled();

void updateBFOValue(int value);

signals:

Expand Down

0 comments on commit 35ebec7

Please sign in to comment.