1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-08-14 15:33:34 -04:00

CW keyer keyboard input: GUI mods (1)

This commit is contained in:
f4exb
2019-07-29 18:54:50 +02:00
parent aaa2647cb1
commit 57efa91a5b
8 changed files with 482 additions and 11 deletions
+168 -3
View File
@@ -24,20 +24,27 @@
#include "dsp/cwkeyer.h"
#include "util/simpleserializer.h"
#include "util/messagequeue.h"
#include "commandkeyreceiver.h"
#include "mainwindow.h"
CWKeyerGUI::CWKeyerGUI(QWidget* parent) :
QWidget(parent),
ui(new Ui::CWKeyerGUI),
m_messageQueue(0),
m_cwKeyer(0),
m_doApplySettings(true)
m_messageQueue(nullptr),
m_cwKeyer(nullptr),
m_doApplySettings(true),
m_keyScope(NoKeyScope)
{
ui->setupUi(this);
m_commandKeyReceiver = new CommandKeyReceiver();
m_commandKeyReceiver->setRelease(true);
this->installEventFilter(m_commandKeyReceiver);
}
CWKeyerGUI::~CWKeyerGUI()
{
this->releaseKeyboard(); // just in case
m_commandKeyReceiver->deleteLater();
delete ui;
}
@@ -47,6 +54,7 @@ void CWKeyerGUI::setBuddies(MessageQueue* messageQueue, CWKeyer* cwKeyer)
m_cwKeyer = cwKeyer;
applySettings();
sendSettings();
displaySettings(m_cwKeyer->getSettings());
}
void CWKeyerGUI::resetToDefaults()
@@ -130,6 +138,7 @@ void CWKeyerGUI::on_playDots_toggled(bool checked)
//ui->playDots->setEnabled(!checked); // release other source inputs
ui->playDashes->setEnabled(!checked);
ui->playText->setEnabled(!checked);
ui->keyboardKeyer->setEnabled(!checked);
if (m_doApplySettings)
{
@@ -143,6 +152,7 @@ void CWKeyerGUI::on_playDashes_toggled(bool checked)
ui->playDots->setEnabled(!checked); // release other source inputs
//ui->playDashes->setEnabled(!checked);
ui->playText->setEnabled(!checked);
ui->keyboardKeyer->setEnabled(!checked);
if (m_doApplySettings)
{
@@ -156,6 +166,7 @@ void CWKeyerGUI::on_playText_toggled(bool checked)
ui->playDots->setEnabled(!checked); // release other source inputs
ui->playDashes->setEnabled(!checked);
//ui->playText->setEnabled(!checked);
ui->keyboardKeyer->setEnabled(!checked);
if (m_doApplySettings)
{
@@ -188,6 +199,134 @@ void CWKeyerGUI::on_playStop_toggled(bool checked)
}
}
void CWKeyerGUI::on_keyDotCapture_toggled(bool checked)
{
if (checked && ui->keyDashCapture->isChecked())
{
ui->keyDotCapture->setChecked(false);
ui->keyDashCapture->setChecked(false);
return;
}
if (checked)
{
m_keyScope = DotKeyScope;
setFocus();
setFocusPolicy(Qt::StrongFocus);
connect(m_commandKeyReceiver, SIGNAL(capturedKey(Qt::Key, Qt::KeyboardModifiers, bool)),
this, SLOT(commandKeyPressed(Qt::Key, Qt::KeyboardModifiers, bool)));
}
else
{
m_keyScope = NoKeyScope;
disconnect(m_commandKeyReceiver, SIGNAL(capturedKey(Qt::Key, Qt::KeyboardModifiers, bool)),
this, SLOT(commandKeyPressed(Qt::Key, Qt::KeyboardModifiers, bool)));
setFocusPolicy(Qt::NoFocus);
clearFocus();
}
}
void CWKeyerGUI::on_keyDashCapture_toggled(bool checked)
{
if (checked && ui->keyDotCapture->isChecked())
{
ui->keyDotCapture->setChecked(false);
ui->keyDashCapture->setChecked(false);
return;
}
if (checked)
{
m_keyScope = DashKeyScope;
m_commandKeyReceiver->setRelease(false);
setFocus();
setFocusPolicy(Qt::StrongFocus);
connect(m_commandKeyReceiver, SIGNAL(capturedKey(Qt::Key, Qt::KeyboardModifiers, bool)),
this, SLOT(commandKeyPressed(Qt::Key, Qt::KeyboardModifiers, bool)));
}
else
{
m_keyScope = NoKeyScope;
m_commandKeyReceiver->setRelease(false);
disconnect(m_commandKeyReceiver, SIGNAL(capturedKey(Qt::Key, Qt::KeyboardModifiers, bool)),
this, SLOT(commandKeyPressed(Qt::Key, Qt::KeyboardModifiers, bool)));
setFocusPolicy(Qt::NoFocus);
clearFocus();
}
}
void CWKeyerGUI::commandKeyPressed(Qt::Key key, Qt::KeyboardModifiers keyModifiers, bool release)
{
(void) release;
// qDebug("CWKeyerGUI::commandKeyPressed: key: %x", m_key);
// qDebug("CWKeyerGUI::commandKeyPressed: has modifiers: %x", QFlags<Qt::KeyboardModifier>::Int(keyModifiers));
if (m_keyScope == DotKeyScope)
{
m_dotKey = key;
m_dotKeyModifiers = keyModifiers;
setKeyLabel(ui->keyDotLabel, key, keyModifiers);
ui->keyDotCapture->setChecked(false);
if (m_doApplySettings)
{
m_cwKeyer->setDotKey(key);
m_cwKeyer->setDotKeyModifiers(keyModifiers);
sendSettings();
}
}
else if (m_keyScope == DashKeyScope)
{
m_dashKey = key;
m_dashKeyModifiers = keyModifiers;
setKeyLabel(ui->keyDashLabel, key, keyModifiers);
ui->keyDashCapture->setChecked(false);
if (m_doApplySettings)
{
m_cwKeyer->setDashKey(key);
m_cwKeyer->setDashKeyModifiers(keyModifiers);
sendSettings();
}
}
m_commandKeyReceiver->setRelease(true);
}
void CWKeyerGUI::on_keyboardKeyer_toggled(bool checked)
{
qDebug("CWKeyerGUI::on_keyboardKeyer_toggled: %s", checked ? "true" : "false");
ui->playDots->setEnabled(!checked); // block or release other source inputs
ui->playDashes->setEnabled(!checked);
ui->playText->setEnabled(!checked);
if (m_doApplySettings)
{
m_cwKeyer->setMode(checked ? CWKeyerSettings::CWKeyboard : CWKeyerSettings::CWNone);
sendSettings();
}
if (checked) {
MainWindow::getInstance()->commandKeysConnect(this, SLOT(keyboardKeyPressed(Qt::Key, Qt::KeyboardModifiers, bool)));
} else {
MainWindow::getInstance()->commandKeysDisconnect(this, SLOT(keyboardKeyPressed(Qt::Key, Qt::KeyboardModifiers, bool)));
}
}
void CWKeyerGUI::keyboardKeyPressed(Qt::Key key, Qt::KeyboardModifiers keyModifiers, bool release)
{
const CWKeyerSettings& settings = m_cwKeyer->getSettings();
if ((key == settings.m_dotKey) && (keyModifiers == settings.m_dotKeyModifiers))
{
qDebug("CWKeyerGUI::keyboardKeyPressed: dot %s", release ? "released" : "pressed");
}
else if ((key == settings.m_dashKey) && (keyModifiers == settings.m_dashKeyModifiers))
{
qDebug("CWKeyerGUI::keyboardKeyPressed: dash %s", release ? "released" : "pressed");
}
}
// === End SLOTS ==============================================================
void CWKeyerGUI::applySettings()
@@ -199,6 +338,11 @@ void CWKeyerGUI::applySettings()
value = ui->cwSpeed->value();
ui->cwSpeedText->setText(QString("%1").arg(value));
m_cwKeyer->setWPM(value);
m_cwKeyer->setDotKey(m_dotKey);
m_cwKeyer->setDotKeyModifiers(m_dotKeyModifiers);
m_cwKeyer->setDashKey(m_dashKey);
m_cwKeyer->setDashKeyModifiers(m_dashKeyModifiers);
}
void CWKeyerGUI::displaySettings(const CWKeyerSettings& settings)
@@ -220,9 +364,30 @@ void CWKeyerGUI::displaySettings(const CWKeyerSettings& settings)
ui->cwSpeed->setValue(settings.m_wpm);
ui->cwSpeedText->setText(QString("%1").arg(settings.m_wpm));
setKeyLabel(ui->keyDotLabel, settings.m_dotKey, settings.m_dotKeyModifiers);
setKeyLabel(ui->keyDashLabel, settings.m_dashKey, settings.m_dashKeyModifiers);
blockApplySettings(false);
}
void CWKeyerGUI::setKeyLabel(QLabel *label, Qt::Key key, Qt::KeyboardModifiers keyModifiers)
{
if (key == 0)
{
label->setText("");
}
else if (keyModifiers != Qt::NoModifier)
{
QString altGrStr = keyModifiers & Qt::GroupSwitchModifier ? "Gr " : "";
int maskedModifiers = (keyModifiers & 0x3FFFFFFF) + ((keyModifiers & 0x40000000)>>3);
label->setText(altGrStr + QKeySequence(maskedModifiers, key).toString());
}
else
{
label->setText(QKeySequence(key).toString());
}
}
void CWKeyerGUI::blockApplySettings(bool block)
{
m_doApplySettings = !block;