diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2013-03-23 22:41:12 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-26 08:29:39 +0100 |
commit | eacecbe76e967e59a4cd0f873471693df7bb9e63 (patch) | |
tree | da8ae550e261531999e49bdbab39536a4117fb03 /examples | |
parent | 48670b8437902548f1aec7f4f973fc84dcd12349 (diff) | |
download | qtserialport-eacecbe76e967e59a4cd0f873471693df7bb9e63.tar.gz |
Add local echo support for the terminal example
Earlier, by default when put a characters for the transfer, this
characters is always displayed on the console, i.e. can be said
that has always worked the local echo mode.
This led to the problem with duplication of input characters on the
console, in case if the remote device (e.g. a modem) was enabled the
echo mode by default. For example, when typing the command "AT", the
console displays "AATT".
To fix this problem, to the settings dialog was added the checkbox
"Local echo" in which can turn off the display of input characters
to the console.
Change-Id: Iebc9384bab97e313a954a8f8c00ea22129913280
Reviewed-by: Laszlo Papp <lpapp@kde.org>
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/terminal/console.cpp | 13 | ||||
-rw-r--r-- | examples/terminal/console.h | 5 | ||||
-rw-r--r-- | examples/terminal/mainwindow.cpp | 1 | ||||
-rw-r--r-- | examples/terminal/settingsdialog.cpp | 3 | ||||
-rw-r--r-- | examples/terminal/settingsdialog.h | 1 | ||||
-rw-r--r-- | examples/terminal/settingsdialog.ui | 119 |
6 files changed, 89 insertions, 53 deletions
diff --git a/examples/terminal/console.cpp b/examples/terminal/console.cpp index c9d5836..7f3f891 100644 --- a/examples/terminal/console.cpp +++ b/examples/terminal/console.cpp @@ -46,8 +46,9 @@ #include <QtCore/QDebug> -Console::Console(QWidget *parent) : - QPlainTextEdit(parent) +Console::Console(QWidget *parent) + : QPlainTextEdit(parent) + , localEchoEnabled(false) { document()->setMaximumBlockCount(100); QPalette p = palette(); @@ -65,6 +66,11 @@ void Console::putData(const QByteArray &data) bar->setValue(bar->maximum()); } +void Console::setLocalEchoEnabled(bool set) +{ + localEchoEnabled = set; +} + void Console::keyPressEvent(QKeyEvent *e) { switch (e->key()) { @@ -76,7 +82,8 @@ void Console::keyPressEvent(QKeyEvent *e) // skip processing break; default: - QPlainTextEdit::keyPressEvent(e); + if (localEchoEnabled) + QPlainTextEdit::keyPressEvent(e); emit getData(e->text().toLocal8Bit()); } } diff --git a/examples/terminal/console.h b/examples/terminal/console.h index 2862bf6..9b5ba1f 100644 --- a/examples/terminal/console.h +++ b/examples/terminal/console.h @@ -57,12 +57,17 @@ public: void putData(const QByteArray &data); + void setLocalEchoEnabled(bool set); + protected: virtual void keyPressEvent(QKeyEvent *e); virtual void mousePressEvent(QMouseEvent *e); virtual void mouseDoubleClickEvent(QMouseEvent *e); virtual void contextMenuEvent(QContextMenuEvent *e); +private: + bool localEchoEnabled; + }; #endif // CONSOLE_H diff --git a/examples/terminal/mainwindow.cpp b/examples/terminal/mainwindow.cpp index f560f9a..47864a2 100644 --- a/examples/terminal/mainwindow.cpp +++ b/examples/terminal/mainwindow.cpp @@ -100,6 +100,7 @@ void MainWindow::openSerialPort() && serial->setFlowControl(p.flowControl)) { console->setEnabled(true); + console->setLocalEchoEnabled(p.localEchoEnabled); ui->actionConnect->setEnabled(false); ui->actionDisconnect->setEnabled(true); ui->actionConfigure->setEnabled(false); diff --git a/examples/terminal/settingsdialog.cpp b/examples/terminal/settingsdialog.cpp index 57370d2..4533da9 100644 --- a/examples/terminal/settingsdialog.cpp +++ b/examples/terminal/settingsdialog.cpp @@ -198,4 +198,7 @@ void SettingsDialog::updateSettings() currentSettings.flowControl = static_cast<QSerialPort::FlowControl>( ui->flowControlBox->itemData(ui->flowControlBox->currentIndex()).toInt()); currentSettings.stringFlowControl = ui->flowControlBox->currentText(); + + // Additional options + currentSettings.localEchoEnabled = ui->localEchoCheckBox->isChecked(); } diff --git a/examples/terminal/settingsdialog.h b/examples/terminal/settingsdialog.h index d9f99f7..ff8f8b6 100644 --- a/examples/terminal/settingsdialog.h +++ b/examples/terminal/settingsdialog.h @@ -75,6 +75,7 @@ public: QString stringStopBits; QSerialPort::FlowControl flowControl; QString stringFlowControl; + bool localEchoEnabled; }; explicit SettingsDialog(QWidget *parent = 0); diff --git a/examples/terminal/settingsdialog.ui b/examples/terminal/settingsdialog.ui index 7c0f33a..28c1211 100644 --- a/examples/terminal/settingsdialog.ui +++ b/examples/terminal/settingsdialog.ui @@ -6,61 +6,14 @@ <rect> <x>0</x> <y>0</y> - <width>280</width> - <height>206</height> + <width>281</width> + <height>262</height> </rect> </property> <property name="windowTitle"> <string>Settings</string> </property> <layout class="QGridLayout" name="gridLayout_3"> - <item row="0" column="0"> - <widget class="QGroupBox" name="selectBox"> - <property name="title"> - <string>Select Serial Port</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0"> - <widget class="QComboBox" name="serialPortInfoListBox"/> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="descriptionLabel"> - <property name="text"> - <string>Description:</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="manufacturerLabel"> - <property name="text"> - <string>Manufacturer:</string> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="locationLabel"> - <property name="text"> - <string>Location:</string> - </property> - </widget> - </item> - <item row="4" column="0"> - <widget class="QLabel" name="vidLabel"> - <property name="text"> - <string>Vendor ID:</string> - </property> - </widget> - </item> - <item row="5" column="0"> - <widget class="QLabel" name="pidLabel"> - <property name="text"> - <string>Product ID:</string> - </property> - </widget> - </item> - </layout> - </widget> - </item> <item row="0" column="1"> <widget class="QGroupBox" name="parametersBox"> <property name="title"> @@ -120,7 +73,54 @@ </layout> </widget> </item> - <item row="1" column="0" colspan="2"> + <item row="0" column="0"> + <widget class="QGroupBox" name="selectBox"> + <property name="title"> + <string>Select Serial Port</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QComboBox" name="serialPortInfoListBox"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="descriptionLabel"> + <property name="text"> + <string>Description:</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="manufacturerLabel"> + <property name="text"> + <string>Manufacturer:</string> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="locationLabel"> + <property name="text"> + <string>Location:</string> + </property> + </widget> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="vidLabel"> + <property name="text"> + <string>Vendor ID:</string> + </property> + </widget> + </item> + <item row="5" column="0"> + <widget class="QLabel" name="pidLabel"> + <property name="text"> + <string>Product ID:</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="2" column="0" colspan="2"> <layout class="QHBoxLayout" name="horizontalLayout"> <item> <spacer name="horizontalSpacer"> @@ -144,6 +144,25 @@ </item> </layout> </item> + <item row="1" column="0" colspan="2"> + <widget class="QGroupBox" name="additionalOptionsGroupBox"> + <property name="title"> + <string>Additional options</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QCheckBox" name="localEchoCheckBox"> + <property name="text"> + <string>Local echo</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + </item> </layout> </widget> <resources/> |