diff --git a/assets/qml/Windows/Setup.qml b/assets/qml/Windows/Setup.qml index 215ee03d..2dc44e49 100644 --- a/assets/qml/Windows/Setup.qml +++ b/assets/qml/Windows/Setup.qml @@ -48,6 +48,8 @@ Control { property alias dmDataBits: dataBits.currentIndex property alias dmBaudValue: baudRate.currentIndex property alias dmFlowControl: flowControl.currentIndex + property alias dmStartSequence: startSeqText.text + property alias dmEndSequence: endSeqText.text property alias appLanguage: languageCombo.currentIndex } @@ -330,6 +332,38 @@ Control { model: Cpp_Misc_Translator.availableLanguages onCurrentIndexChanged: Cpp_Misc_Translator.setLanguage(currentIndex) } + + // + // Start sequence + // + Label { + text: qsTr("Start sequence") + ": " + } TextField { + id: startSeqText + Layout.fillWidth: true + placeholderText: "/*" + text: "/*" + onTextChanged: { + if (text !== Cpp_IO_Manager.startSequence) + Cpp_IO_Manager.startSequence = text + } + } + + // + // End sequence + // + Label { + text: qsTr("End sequence") + ": " + } TextField { + id: endSeqText + Layout.fillWidth: true + placeholderText: "*/" + text: "*/" + onTextChanged: { + if (text !== Cpp_IO_Manager.finishSequence) + Cpp_IO_Manager.finishSequence = text + } + } } // diff --git a/src/IO/Manager.cpp b/src/IO/Manager.cpp index ba672ebf..166c7090 100644 --- a/src/IO/Manager.cpp +++ b/src/IO/Manager.cpp @@ -33,6 +33,28 @@ using namespace IO; */ static Manager *INSTANCE = nullptr; +/** + * Adds support for C escape sequences to the given @a str. + * When user inputs "\n" in a textbox, Qt automatically converts that string to "\\n". + * For our purposes, we need to convert "\\n" back to "\n", and so on with the rest of + * the escape sequences supported by C. + * + * TODO: add support for numbers + */ +static QString ADD_ESCAPE_SEQUENCES(const QString &str) +{ + auto escapedStr = str; + escapedStr = escapedStr.replace("\\a", "\a"); + escapedStr = escapedStr.replace("\\b", "\b"); + escapedStr = escapedStr.replace("\\e", "\e"); + escapedStr = escapedStr.replace("\\f", "\f"); + escapedStr = escapedStr.replace("\\n", "\n"); + escapedStr = escapedStr.replace("\\r", "\r"); + escapedStr = escapedStr.replace("\\t", "\t"); + escapedStr = escapedStr.replace("\\v", "\v"); + return escapedStr; +} + /** * Constructor function */ @@ -363,7 +385,10 @@ void Manager::setMaxBufferSize(const int maxBufferSize) */ void Manager::setStartSequence(const QString &sequence) { - m_startSequence = sequence; + m_startSequence = ADD_ESCAPE_SEQUENCES(sequence); + if (m_startSequence.isEmpty()) + m_startSequence = "/*"; + emit startSequenceChanged(); } @@ -373,7 +398,10 @@ void Manager::setStartSequence(const QString &sequence) */ void Manager::setFinishSequence(const QString &sequence) { - m_finishSequence = sequence; + m_finishSequence = ADD_ESCAPE_SEQUENCES(sequence); + if (m_finishSequence.isEmpty()) + m_finishSequence = "/*"; + emit finishSequenceChanged(); } diff --git a/src/IO/Manager.h b/src/IO/Manager.h index 379605bd..956327c4 100644 --- a/src/IO/Manager.h +++ b/src/IO/Manager.h @@ -52,6 +52,14 @@ class Manager : public QObject Q_PROPERTY(QString receivedDataLength READ receivedDataLength NOTIFY receivedBytesChanged) + Q_PROPERTY(QString startSequence + READ startSequence + WRITE setStartSequence + NOTIFY startSequenceChanged) + Q_PROPERTY(QString finishSequence + READ finishSequence + WRITE setFinishSequence + NOTIFY finishSequenceChanged) // clang-format on signals: