From d7d9fc8c32635b59f55ac51fc7632a3015cdc970 Mon Sep 17 00:00:00 2001 From: vsonnier Date: Sat, 11 Jun 2016 10:08:12 +0200 Subject: [PATCH] LABEL: Add a label edit dialog, much like FrequencyDialog, works not bad --- CMakeLists.txt | 2 + src/AppFrame.cpp | 1 - src/CubicSDR.cpp | 13 +++++ src/CubicSDR.h | 2 + src/DemodLabelDialog.cpp | 94 +++++++++++++++++++++++++++++++++ src/DemodLabelDialog.h | 29 ++++++++++ src/visual/PrimaryGLContext.cpp | 4 +- src/visual/TuningCanvas.cpp | 2 +- src/visual/WaterfallCanvas.cpp | 7 ++- 9 files changed, 148 insertions(+), 6 deletions(-) create mode 100644 src/DemodLabelDialog.cpp create mode 100644 src/DemodLabelDialog.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c135e2..14908ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -271,6 +271,7 @@ SET (cubicsdr_sources src/AppFrame.cpp src/AppConfig.cpp src/FrequencyDialog.cpp + src/DemodLabelDialog.cpp src/IOThread.cpp src/ModemProperties.cpp src/sdr/SDRDeviceInfo.cpp @@ -368,6 +369,7 @@ SET (cubicsdr_headers src/AppFrame.h src/AppConfig.h src/FrequencyDialog.h + src/DemodLabelDialog.h src/IOThread.h src/ModemProperties.h src/sdr/SDRDeviceInfo.h diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 4afd065..254ec6c 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -1691,7 +1691,6 @@ bool AppFrame::loadSession(std::string fileName) { } //read the user label associated with the demodulator - //manage other languages than English if you please... std::string user_label = ""; DataNode *demodUserLabel = demod->hasAnother("user_label") ? demod->getNext("user_label") : nullptr; diff --git a/src/CubicSDR.cpp b/src/CubicSDR.cpp index ba55084..aa496cf 100644 --- a/src/CubicSDR.cpp +++ b/src/CubicSDR.cpp @@ -731,6 +731,19 @@ void CubicSDR::showFrequencyInput(FrequencyDialog::FrequencyDialogTarget targetM fdialog.ShowModal(); } +void CubicSDR::showLabelInput() { + + DemodulatorInstance *activeDemod = wxGetApp().getDemodMgr().getActiveDemodulator(); + + if (activeDemod != nullptr) { + + const wxString demodTitle("Set Demodulator label"); + + DemodLabelDialog labelDialog(appframe, -1, demodTitle, activeDemod, wxPoint(-100, -100), wxSize(500, 75), wxDEFAULT_DIALOG_STYLE); + labelDialog.ShowModal(); + } +} + AppFrame *CubicSDR::getAppFrame() { return appframe; } diff --git a/src/CubicSDR.h b/src/CubicSDR.h index a6e261f..1402816 100644 --- a/src/CubicSDR.h +++ b/src/CubicSDR.h @@ -22,6 +22,7 @@ #include "AppConfig.h" #include "AppFrame.h" #include "FrequencyDialog.h" +#include "DemodLabelDialog.h" #include "ScopeVisualProcessor.h" #include "SpectrumVisualProcessor.h" @@ -128,6 +129,7 @@ public: int getPPM(); void showFrequencyInput(FrequencyDialog::FrequencyDialogTarget targetMode = FrequencyDialog::FDIALOG_TARGET_DEFAULT, wxString initString = ""); + void showLabelInput(); AppFrame *getAppFrame(); bool areDevicesReady(); diff --git a/src/DemodLabelDialog.cpp b/src/DemodLabelDialog.cpp new file mode 100644 index 0000000..3bb71a0 --- /dev/null +++ b/src/DemodLabelDialog.cpp @@ -0,0 +1,94 @@ +#include "DemodLabelDialog.h" + +#include "wx/clipbrd.h" +#include +#include "CubicSDR.h" + +wxBEGIN_EVENT_TABLE(DemodLabelDialog, wxDialog) +EVT_CHAR_HOOK(DemodLabelDialog::OnChar) +EVT_SHOW(DemodLabelDialog::OnShow) +wxEND_EVENT_TABLE() + +DemodLabelDialog::DemodLabelDialog(wxWindow * parent, wxWindowID id, const wxString & title, + DemodulatorInstance *demod, const wxPoint & position, + const wxSize & size, long style) : + wxDialog(parent, id, title, position, size, style) { + + wxString labelStr; + + //by construction, is allways != nullptr + activeDemod = demod; + + labelStr = activeDemod->getDemodulatorUserLabel(); + + if (labelStr.empty()) { + //propose a default value... + labelStr = activeDemod->getDemodulatorType(); + } + + + dialogText = new wxTextCtrl(this, wxID_LABEL_INPUT, labelStr, wxPoint(6, 1), wxSize(size.GetWidth() - 20, size.GetHeight() - 70), + wxTE_PROCESS_ENTER); + dialogText->SetFont(wxFont(15, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD)); + + Centre(); + + dialogText->SetValue(labelStr); + dialogText->SetSelection(-1, -1); +} + + +void DemodLabelDialog::OnChar(wxKeyEvent& event) { + int c = event.GetKeyCode(); + + std::string strValue = dialogText->GetValue().ToStdString(); + + switch (c) { + case WXK_RETURN: + case WXK_NUMPAD_ENTER: + + //No need to display the demodulator type twice if the user do not change the default value... + if (strValue != activeDemod->getDemodulatorType()) { + activeDemod->setDemodulatorUserLabel(strValue); + } + else { + activeDemod->setDemodulatorUserLabel(""); + } + + Close(); + break; + case WXK_ESCAPE: + Close(); + break; + } + + if (event.ControlDown() && c == 'V') { + // Alter clipboard contents to remove unwanted chars + wxTheClipboard->Open(); + wxTextDataObject data; + wxTheClipboard->GetData(data); + std::string clipText = data.GetText().ToStdString(); + wxTheClipboard->SetData(new wxTextDataObject(clipText)); + wxTheClipboard->Close(); + event.Skip(); + } + else if (c == WXK_RIGHT || c == WXK_LEFT || event.ControlDown()) { + event.Skip(); + + } + else { +#ifdef __linux__ + dialogText->OnChar(event); + event.Skip(); +#else + event.DoAllowNextEvent(); +#endif + } +} + +void DemodLabelDialog::OnShow(wxShowEvent &event) { + + dialogText->SetFocus(); + dialogText->SetSelection(-1, -1); + event.Skip(); +} diff --git a/src/DemodLabelDialog.h b/src/DemodLabelDialog.h new file mode 100644 index 0000000..a10d34b --- /dev/null +++ b/src/DemodLabelDialog.h @@ -0,0 +1,29 @@ +#pragma once + +#include "wx/dialog.h" +#include "wx/textctrl.h" +#include "wx/string.h" +#include "wx/button.h" +#include "DemodulatorInstance.h" + +#define wxID_LABEL_INPUT 3002 + +class DemodLabelDialog : public wxDialog +{ +public: + + DemodLabelDialog( wxWindow * parent, wxWindowID id, const wxString & title, + DemodulatorInstance *demod = NULL, + const wxPoint & pos = wxDefaultPosition, + const wxSize & size = wxDefaultSize, + long style = wxDEFAULT_DIALOG_STYLE); + + wxTextCtrl * dialogText; + +private: + DemodulatorInstance *activeDemod = nullptr; + void OnEnter ( wxCommandEvent &event ); + void OnChar ( wxKeyEvent &event ); + void OnShow(wxShowEvent &event); + DECLARE_EVENT_TABLE() +}; diff --git a/src/visual/PrimaryGLContext.cpp b/src/visual/PrimaryGLContext.cpp index 4e44017..0701fd1 100644 --- a/src/visual/PrimaryGLContext.cpp +++ b/src/visual/PrimaryGLContext.cpp @@ -381,14 +381,14 @@ void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, RGBA4f color, long //demodulator user label if present: type is displayed above the label, which is at the bottom of the screen. if (!demod->getDemodulatorUserLabel().empty()) { - hPos += 2 * labelHeight; + hPos += 1.3 * labelHeight; } drawSingleDemodLabel(demodStr, uxPos, hPos, xOfs, yOfs, GLFont::GLFONT_ALIGN_CENTER); //revert... if (!demod->getDemodulatorUserLabel().empty()) { - hPos -= 2 * labelHeight; + hPos -= 1.3 * labelHeight; drawSingleDemodLabel(demod->getDemodulatorUserLabel(), uxPos, hPos, xOfs, yOfs, GLFont::GLFONT_ALIGN_CENTER); } diff --git a/src/visual/TuningCanvas.cpp b/src/visual/TuningCanvas.cpp index 1f20f11..6d58520 100644 --- a/src/visual/TuningCanvas.cpp +++ b/src/visual/TuningCanvas.cpp @@ -430,7 +430,7 @@ void TuningCanvas::OnKeyDown(wxKeyEvent& event) { } else if (hoverState == TUNING_HOVER_BW) { wxGetApp().showFrequencyInput(FrequencyDialog::FDIALOG_TARGET_BANDWIDTH); } - } + } } void TuningCanvas::OnKeyUp(wxKeyEvent& event) { diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index d65c98b..8b4bbfe 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -451,6 +451,9 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) { case WXK_SPACE: wxGetApp().showFrequencyInput(); break; + case 'E': //E is for 'Edit the label' of the active demodulator. + wxGetApp().showLabelInput(); + break; case 'C': if (wxGetApp().getDemodMgr().getActiveDemodulator()) { wxGetApp().setFrequency(wxGetApp().getDemodMgr().getActiveDemodulator()->getFrequency()); @@ -568,14 +571,14 @@ void WaterfallCanvas::updateHoverState() { mouseTracker.setVertDragLock(true); mouseTracker.setHorizDragLock(false); - setStatusText("Click and drag to change demodulator bandwidth. SPACE or numeric key for direct frequency input. [, ] to nudge, M for mute, D to delete, C to center."); + setStatusText("Click and drag to change demodulator bandwidth. SPACE or numeric key for direct frequency input. [, ] to nudge, M for mute, D to delete, C to center, E to edit label."); } else { SetCursor(wxCURSOR_SIZING); nextDragState = WF_DRAG_FREQUENCY; mouseTracker.setVertDragLock(true); mouseTracker.setHorizDragLock(false); - setStatusText("Click and drag to change demodulator frequency; SPACE or numeric key for direct input. [, ] to nudge, M for mute, D to delete, C to center."); + setStatusText("Click and drag to change demodulator frequency; SPACE or numeric key for direct input. [, ] to nudge, M for mute, D to delete, C to center, E to edit label."); } } else { SetCursor(wxCURSOR_CROSS);