LABEL: Add a label edit dialog, much like FrequencyDialog, works not bad

This commit is contained in:
vsonnier 2016-06-11 10:08:12 +02:00
parent 00e241a784
commit d7d9fc8c32
9 changed files with 148 additions and 6 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;
}

View File

@ -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();

94
src/DemodLabelDialog.cpp Normal file
View File

@ -0,0 +1,94 @@
#include "DemodLabelDialog.h"
#include "wx/clipbrd.h"
#include <sstream>
#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();
}

29
src/DemodLabelDialog.h Normal file
View File

@ -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()
};

View File

@ -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);
}

View File

@ -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) {

View File

@ -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);