2016-12-11 05:35:25 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2016 F4EXB //
|
|
|
|
// written by Edouard Griffiths //
|
|
|
|
// //
|
|
|
|
// This program 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 as version 3 of the License, or //
|
2019-04-11 08:43:33 -04:00
|
|
|
// (at your option) any later version. //
|
2016-12-11 05:35:25 -05:00
|
|
|
// //
|
|
|
|
// This program 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 V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
#include "gui/cwkeyergui.h"
|
|
|
|
#include "ui_cwkeyergui.h"
|
|
|
|
#include "dsp/cwkeyer.h"
|
|
|
|
#include "util/simpleserializer.h"
|
2018-12-19 18:09:53 -05:00
|
|
|
#include "util/messagequeue.h"
|
2019-07-29 12:54:50 -04:00
|
|
|
#include "commandkeyreceiver.h"
|
|
|
|
#include "mainwindow.h"
|
2016-12-11 05:35:25 -05:00
|
|
|
|
|
|
|
CWKeyerGUI::CWKeyerGUI(QWidget* parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
ui(new Ui::CWKeyerGUI),
|
2019-07-29 12:54:50 -04:00
|
|
|
m_cwKeyer(nullptr),
|
|
|
|
m_doApplySettings(true),
|
|
|
|
m_keyScope(NoKeyScope)
|
2016-12-11 05:35:25 -05:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2019-07-29 12:54:50 -04:00
|
|
|
m_commandKeyReceiver = new CommandKeyReceiver();
|
|
|
|
m_commandKeyReceiver->setRelease(true);
|
|
|
|
this->installEventFilter(m_commandKeyReceiver);
|
2016-12-11 05:35:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
CWKeyerGUI::~CWKeyerGUI()
|
|
|
|
{
|
|
|
|
this->releaseKeyboard(); // just in case
|
2019-07-29 12:54:50 -04:00
|
|
|
m_commandKeyReceiver->deleteLater();
|
2016-12-11 05:35:25 -05:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2019-07-29 19:31:46 -04:00
|
|
|
void CWKeyerGUI::setCWKeyer(CWKeyer* cwKeyer)
|
2016-12-11 05:35:25 -05:00
|
|
|
{
|
|
|
|
m_cwKeyer = cwKeyer;
|
2019-07-29 19:31:46 -04:00
|
|
|
setSettings(cwKeyer->getSettings());
|
|
|
|
displaySettings();
|
2016-12-11 05:35:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void CWKeyerGUI::resetToDefaults()
|
|
|
|
{
|
2019-07-29 19:31:46 -04:00
|
|
|
m_settings.resetToDefaults();
|
|
|
|
displaySettings();
|
|
|
|
applySettings(true);
|
2016-12-11 05:35:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray CWKeyerGUI::serialize() const
|
|
|
|
{
|
2019-07-29 19:31:46 -04:00
|
|
|
return m_settings.serialize();
|
2016-12-11 05:35:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CWKeyerGUI::deserialize(const QByteArray& data)
|
|
|
|
{
|
2019-07-29 19:31:46 -04:00
|
|
|
if (m_settings.deserialize(data))
|
2016-12-11 05:35:25 -05:00
|
|
|
{
|
2019-07-29 19:31:46 -04:00
|
|
|
displaySettings();
|
|
|
|
applySettings(true);
|
2016-12-11 05:35:25 -05:00
|
|
|
return true;
|
|
|
|
}
|
2017-05-05 04:40:45 -04:00
|
|
|
else
|
|
|
|
{
|
2019-07-29 19:31:46 -04:00
|
|
|
resetToDefaults();
|
2017-05-05 04:40:45 -04:00
|
|
|
return false;
|
|
|
|
}
|
2016-12-11 05:35:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// === SLOTS ==================================================================
|
|
|
|
|
2018-11-12 12:36:27 -05:00
|
|
|
void CWKeyerGUI::on_cwTextClear_clicked(bool checked)
|
2016-12-11 05:35:25 -05:00
|
|
|
{
|
2018-11-12 12:36:27 -05:00
|
|
|
(void) checked;
|
2016-12-11 05:35:25 -05:00
|
|
|
ui->cwTextEdit->clear();
|
2019-07-29 19:31:46 -04:00
|
|
|
m_settings.m_text = "";
|
|
|
|
applySettings();
|
2016-12-11 05:35:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void CWKeyerGUI::on_cwTextEdit_editingFinished()
|
|
|
|
{
|
2019-07-29 19:31:46 -04:00
|
|
|
m_settings.m_text = ui->cwTextEdit->text();
|
|
|
|
applySettings();
|
2016-12-11 05:35:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void CWKeyerGUI::on_cwSpeed_valueChanged(int value)
|
|
|
|
{
|
|
|
|
ui->cwSpeedText->setText(QString("%1").arg(value));
|
2019-07-29 19:31:46 -04:00
|
|
|
m_settings.m_wpm = value;
|
|
|
|
applySettings();
|
2016-12-11 05:35:25 -05:00
|
|
|
}
|
|
|
|
|
2016-12-11 15:52:53 -05:00
|
|
|
void CWKeyerGUI::on_playDots_toggled(bool checked)
|
2016-12-11 05:35:25 -05:00
|
|
|
{
|
2016-12-11 15:52:53 -05:00
|
|
|
//ui->playDots->setEnabled(!checked); // release other source inputs
|
|
|
|
ui->playDashes->setEnabled(!checked);
|
|
|
|
ui->playText->setEnabled(!checked);
|
2019-07-29 12:54:50 -04:00
|
|
|
ui->keyboardKeyer->setEnabled(!checked);
|
2019-07-29 19:31:46 -04:00
|
|
|
m_settings.m_mode = checked ? CWKeyerSettings::CWDots : CWKeyerSettings::CWNone;
|
|
|
|
applySettings();
|
2016-12-11 05:35:25 -05:00
|
|
|
}
|
|
|
|
|
2016-12-11 15:52:53 -05:00
|
|
|
void CWKeyerGUI::on_playDashes_toggled(bool checked)
|
2016-12-11 05:35:25 -05:00
|
|
|
{
|
2016-12-11 15:52:53 -05:00
|
|
|
ui->playDots->setEnabled(!checked); // release other source inputs
|
|
|
|
//ui->playDashes->setEnabled(!checked);
|
|
|
|
ui->playText->setEnabled(!checked);
|
2019-07-29 12:54:50 -04:00
|
|
|
ui->keyboardKeyer->setEnabled(!checked);
|
2019-07-29 19:31:46 -04:00
|
|
|
m_settings.m_mode = checked ? CWKeyerSettings::CWDashes : CWKeyerSettings::CWNone;
|
|
|
|
applySettings();
|
2016-12-11 05:35:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void CWKeyerGUI::on_playText_toggled(bool checked)
|
|
|
|
{
|
2016-12-11 15:52:53 -05:00
|
|
|
ui->playDots->setEnabled(!checked); // release other source inputs
|
|
|
|
ui->playDashes->setEnabled(!checked);
|
|
|
|
//ui->playText->setEnabled(!checked);
|
2019-07-29 12:54:50 -04:00
|
|
|
ui->keyboardKeyer->setEnabled(!checked);
|
2016-12-11 15:52:53 -05:00
|
|
|
|
|
|
|
if (checked) {
|
|
|
|
ui->playStop->setChecked(true);
|
|
|
|
} else {
|
|
|
|
ui->playStop->setChecked(false);
|
|
|
|
}
|
2019-07-29 19:31:46 -04:00
|
|
|
|
|
|
|
m_settings.m_mode = checked ? CWKeyerSettings::CWText : CWKeyerSettings::CWNone;
|
|
|
|
applySettings();
|
2016-12-11 05:35:25 -05:00
|
|
|
}
|
|
|
|
|
2016-12-13 20:54:05 -05:00
|
|
|
void CWKeyerGUI::on_playLoopCW_toggled(bool checked)
|
2016-12-11 05:35:25 -05:00
|
|
|
{
|
2019-07-29 19:31:46 -04:00
|
|
|
m_settings.m_loop = checked;
|
|
|
|
applySettings();
|
2016-12-11 05:35:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void CWKeyerGUI::on_playStop_toggled(bool checked)
|
|
|
|
{
|
2018-12-19 18:09:53 -05:00
|
|
|
if (checked) {
|
2016-12-11 05:35:25 -05:00
|
|
|
m_cwKeyer->resetText();
|
2018-12-19 18:09:53 -05:00
|
|
|
} else {
|
2016-12-11 05:35:25 -05:00
|
|
|
m_cwKeyer->stopText();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-30 03:27:55 -04:00
|
|
|
void CWKeyerGUI::on_keyingStyle_toggled(bool checked)
|
|
|
|
{
|
|
|
|
m_settings.m_keyboardIambic = !checked;
|
|
|
|
applySettings();
|
|
|
|
}
|
|
|
|
|
2019-07-29 12:54:50 -04:00
|
|
|
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;
|
2019-07-29 19:31:46 -04:00
|
|
|
// qDebug("CWKeyerGUI::commandKeyPressed: key scope: %d", (int) m_keyScope);
|
|
|
|
// qDebug("CWKeyerGUI::commandKeyPressed: key: %x", key);
|
|
|
|
// qDebug("CWKeyerGUI::commandKeyPressed: has modifiers: %x", QFlags<Qt::KeyboardModifier>::Int(keyModifiers));
|
2019-07-29 12:54:50 -04:00
|
|
|
|
|
|
|
if (m_keyScope == DotKeyScope)
|
|
|
|
{
|
|
|
|
setKeyLabel(ui->keyDotLabel, key, keyModifiers);
|
|
|
|
ui->keyDotCapture->setChecked(false);
|
2019-07-29 19:31:46 -04:00
|
|
|
m_settings.m_dotKey = key;
|
|
|
|
m_settings.m_dotKeyModifiers = keyModifiers;
|
|
|
|
applySettings();
|
2019-07-29 12:54:50 -04:00
|
|
|
}
|
|
|
|
else if (m_keyScope == DashKeyScope)
|
|
|
|
{
|
|
|
|
setKeyLabel(ui->keyDashLabel, key, keyModifiers);
|
|
|
|
ui->keyDashCapture->setChecked(false);
|
2019-07-29 19:31:46 -04:00
|
|
|
m_settings.m_dashKey = key;
|
|
|
|
m_settings.m_dashKeyModifiers = keyModifiers;
|
|
|
|
applySettings();
|
2019-07-29 12:54:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2019-07-29 19:31:46 -04:00
|
|
|
m_settings.m_mode = checked ? CWKeyerSettings::CWKeyboard : CWKeyerSettings::CWNone;
|
|
|
|
applySettings();
|
2019-07-29 12:54:50 -04:00
|
|
|
|
|
|
|
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");
|
2019-07-30 03:27:55 -04:00
|
|
|
if (release) {
|
|
|
|
m_cwKeyer->setKeyboardSilence();
|
|
|
|
} else {
|
|
|
|
m_cwKeyer->setKeyboardDots();
|
|
|
|
}
|
2019-07-29 12:54:50 -04:00
|
|
|
}
|
|
|
|
else if ((key == settings.m_dashKey) && (keyModifiers == settings.m_dashKeyModifiers))
|
|
|
|
{
|
|
|
|
qDebug("CWKeyerGUI::keyboardKeyPressed: dash %s", release ? "released" : "pressed");
|
2019-07-30 03:27:55 -04:00
|
|
|
if (release) {
|
|
|
|
m_cwKeyer->setKeyboardSilence();
|
|
|
|
} else {
|
|
|
|
m_cwKeyer->setKeyboardDashes();
|
|
|
|
}
|
2019-07-29 12:54:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-11 05:35:25 -05:00
|
|
|
// === End SLOTS ==============================================================
|
|
|
|
|
2019-07-29 19:31:46 -04:00
|
|
|
void CWKeyerGUI::applySettings(bool force)
|
2016-12-11 05:35:25 -05:00
|
|
|
{
|
2019-07-29 19:31:46 -04:00
|
|
|
if (m_doApplySettings && m_cwKeyer)
|
|
|
|
{
|
|
|
|
CWKeyer::MsgConfigureCWKeyer* message = CWKeyer::MsgConfigureCWKeyer::create(m_settings, force);
|
|
|
|
m_cwKeyer->getInputMessageQueue()->push(message);
|
|
|
|
}
|
2016-12-11 05:35:25 -05:00
|
|
|
}
|
2017-12-11 12:18:47 -05:00
|
|
|
|
2019-07-29 19:31:46 -04:00
|
|
|
void CWKeyerGUI::displaySettings()
|
2017-12-11 12:18:47 -05:00
|
|
|
{
|
|
|
|
blockApplySettings(true);
|
|
|
|
|
2019-07-29 19:31:46 -04:00
|
|
|
ui->playLoopCW->setChecked(m_settings.m_loop);
|
|
|
|
|
|
|
|
ui->playDots->setEnabled((m_settings.m_mode == CWKeyerSettings::CWDots) || (m_settings.m_mode == CWKeyerSettings::CWNone));
|
|
|
|
ui->playDots->setChecked(m_settings.m_mode == CWKeyerSettings::CWDots);
|
2017-12-11 12:18:47 -05:00
|
|
|
|
2019-07-29 19:31:46 -04:00
|
|
|
ui->playDashes->setEnabled((m_settings.m_mode == CWKeyerSettings::CWDashes) || (m_settings.m_mode == CWKeyerSettings::CWNone));
|
|
|
|
ui->playDashes->setChecked(m_settings.m_mode == CWKeyerSettings::CWDashes);
|
2017-12-12 12:56:24 -05:00
|
|
|
|
2019-07-29 19:31:46 -04:00
|
|
|
ui->playText->setEnabled((m_settings.m_mode == CWKeyerSettings::CWText) || (m_settings.m_mode == CWKeyerSettings::CWNone));
|
|
|
|
ui->playText->setChecked(m_settings.m_mode == CWKeyerSettings::CWText);
|
2017-12-12 12:56:24 -05:00
|
|
|
|
2019-07-29 19:31:46 -04:00
|
|
|
ui->keyboardKeyer->setEnabled((m_settings.m_mode == CWKeyerSettings::CWKeyboard) || (m_settings.m_mode == CWKeyerSettings::CWNone));
|
|
|
|
ui->keyboardKeyer->setChecked(m_settings.m_mode == CWKeyerSettings::CWKeyboard);
|
2017-12-11 12:18:47 -05:00
|
|
|
|
2019-07-29 19:31:46 -04:00
|
|
|
ui->cwTextEdit->setText(m_settings.m_text);
|
|
|
|
ui->cwSpeed->setValue(m_settings.m_wpm);
|
|
|
|
ui->cwSpeedText->setText(QString("%1").arg(m_settings.m_wpm));
|
2019-07-30 03:27:55 -04:00
|
|
|
ui->keyingStyle->setChecked(!m_settings.m_keyboardIambic);
|
2017-12-11 12:18:47 -05:00
|
|
|
|
2019-07-29 19:31:46 -04:00
|
|
|
setKeyLabel(ui->keyDotLabel, m_settings.m_dotKey, m_settings.m_dotKeyModifiers);
|
|
|
|
setKeyLabel(ui->keyDashLabel, m_settings.m_dashKey, m_settings.m_dashKeyModifiers);
|
2019-07-29 12:54:50 -04:00
|
|
|
|
2017-12-11 12:18:47 -05:00
|
|
|
blockApplySettings(false);
|
|
|
|
}
|
|
|
|
|
2019-07-29 12:54:50 -04:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-11 12:18:47 -05:00
|
|
|
void CWKeyerGUI::blockApplySettings(bool block)
|
|
|
|
{
|
|
|
|
m_doApplySettings = !block;
|
|
|
|
}
|