Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions QLog.pro
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ SOURCES += \
ui/component/MultiselectCompleter.cpp \
ui/component/RepeatButton.cpp \
ui/component/SmartSearchBox.cpp \
ui/component/SwitchButton.cpp
ui/component/SwitchButton.cpp \
ui/component/tunablelabel.cpp

HEADERS += \
core/AlertEvaluator.h \
Expand Down Expand Up @@ -336,7 +337,8 @@ HEADERS += \
ui/component/ShutdownAwareWidget.h \
ui/component/SmartSearchBox.h \
ui/component/StyleItemDelegate.h \
ui/component/SwitchButton.h
ui/component/SwitchButton.h \
ui/component/tunablelabel.h

FORMS += \
ui/ActivityEditor.ui \
Expand Down
30 changes: 30 additions & 0 deletions ui/RigWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "data/Data.h"
#include "service/hrdlog/HRDLog.h"
#include "data/BandPlan.h"
#include "ui/component/tunablelabel.h"

// On AIR pinging to HRDLog [in sec]
#define ONAIR_INTERVAL (1 * 60)
Expand Down Expand Up @@ -43,6 +44,18 @@ RigWidget::RigWidget(QWidget *parent) :
QStringListModel* modesModel = new QStringListModel(this);
ui->modeComboBox->setModel(modesModel);

auto *tuneLbl = qobject_cast<TunableLabel*>(ui->freqLabel);
if (tuneLbl) {
tuneLbl->setBaseStepHz(100);

connect(tuneLbl, &TunableLabel::tuneDeltaRequested, this, &RigWidget::onTuneDeltaRequested);

connect(tuneLbl, &TunableLabel::clicked, this, [this]{
this->setFocus(Qt::MouseFocusReason);
});
}


refreshRigProfileCombo();

QTimer *onAirTimer = new QTimer(this);
Expand All @@ -62,6 +75,23 @@ RigWidget::~RigWidget()
delete ui;
}

void RigWidget::onTuneDeltaRequested(qint64 deltaHz)
{
FCT_IDENTIFICATION;

if (lastSeenFreq == 0.0)
return;
const double deltaMHz = static_cast<double>(deltaHz) / 1000000.0;
const double newMHz = lastSeenFreq + deltaMHz;

if (rigOnline) {
Rig::instance()->setFrequency(MHz(newMHz));
qCDebug(runtime) << "Mouse Wheel freq: " << newMHz;
}
}



void RigWidget::updateFrequency(VFOID vfoid, double vfoFreq, double ritFreq, double xitFreq)
{
FCT_IDENTIFICATION;
Expand Down
3 changes: 3 additions & 0 deletions ui/RigWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QWidget>
#include "rig/Rig.h"
#include "service/hrdlog/HRDLog.h"
#include "ui/component/tunablelabel.h"

namespace Ui {
class RigWidget;
Expand Down Expand Up @@ -44,6 +45,7 @@ public slots:

private slots:
void sendOnAirState();
void onTuneDeltaRequested(qint64 deltaHz);

private:

Expand All @@ -52,6 +54,7 @@ private slots:
double lastSeenFreq;
QString lastSeenMode;
bool rigOnline;
// RigWidget.h

Ui::RigWidget *ui;
HRDLogUploader *hrdlog;
Expand Down
9 changes: 8 additions & 1 deletion ui/RigWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="freqLabel">
<widget class="TunableLabel" name="freqLabel">
<property name="font">
<font>
<pointsize>20</pointsize>
Expand Down Expand Up @@ -214,6 +214,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>TunableLabel</class>
<extends>QLabel</extends>
<header>ui/component/tunablelabel.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
Expand Down
72 changes: 72 additions & 0 deletions ui/component/tunablelabel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "ui/component/tunablelabel.h"

#include <QWheelEvent>
#include <QMouseEvent>

TunableLabel::TunableLabel(QWidget *parent)
: QLabel(parent)
{
setFocusPolicy(Qt::StrongFocus);
setMouseTracking(true);
m_wheelRemainder = 0.0;
}

qint64 TunableLabel::effectiveStepHz(Qt::KeyboardModifiers mods) const
{
qint64 step = m_baseStepHz;

if (mods.testFlag(Qt::ControlModifier)) step *= 5;
if (mods.testFlag(Qt::ShiftModifier)) step *= 5; // Ctrl+Shift => ×100
if (mods.testFlag(Qt::AltModifier)) step *= 5; // Alt adds another ×10

return step;
}

void TunableLabel::wheelEvent(QWheelEvent *event)
{
const QPoint pixel = event->pixelDelta();
const QPoint angle = event->angleDelta();

int steps = 0;

if (!pixel.isNull()) {
static constexpr double kPixelsPerStep = 20.0; // tune feel
m_wheelRemainder += pixel.y();
steps = static_cast<int>(m_wheelRemainder / kPixelsPerStep);
if (steps != 0)
m_wheelRemainder -= steps * kPixelsPerStep;
} else if (!angle.isNull()) {
steps = angle.y() / 120;
}

if (steps != 0) {
const qint64 stepHz = effectiveStepHz(event->modifiers());
const qint64 deltaHz = static_cast<qint64>(steps) * stepHz; // +up/-down
emit tuneDeltaRequested(deltaHz);
event->accept();
return;
}

QLabel::wheelEvent(event);
}


void TunableLabel::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
emit clicked();
event->accept();
return;
}
QLabel::mousePressEvent(event);
}

void TunableLabel::mouseDoubleClickEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
emit doubleClicked();
event->accept();
return;
}
QLabel::mouseDoubleClickEvent(event);
}
35 changes: 35 additions & 0 deletions ui/component/tunablelabel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include <QLabel>

class QWheelEvent;
class QMouseEvent;

class TunableLabel : public QLabel
{
Q_OBJECT
public:
explicit TunableLabel(QWidget *parent = nullptr);

void setBaseStepHz(qint64 hz) { m_baseStepHz = hz; }
qint64 baseStepHz() const { return m_baseStepHz; }

signals:
// deltaHz can be positive (scroll up) or negative (scroll down)
void tuneDeltaRequested(qint64 deltaHz);

// Optional: click/double-click hooks (nice for “set focus”, “open keypad”, etc.)
void clicked();
void doubleClicked();

protected:
void wheelEvent(QWheelEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseDoubleClickEvent(QMouseEvent *event) override;

private:
qint64 effectiveStepHz(Qt::KeyboardModifiers mods) const;
qint64 m_baseStepHz = 10; // default 10 Hz per notch
double m_wheelRemainder = 0.0; // accumulate trackpad pixels

};
Loading