summaryrefslogtreecommitdiffstats
path: root/examples/serialport/terminal
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@digia.com>2013-04-30 14:46:08 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-05-03 17:01:47 +0200
commit494c616951d41f2f394a7157f8970e14096f41b4 (patch)
tree9e42e9970b4b28809d97c0de94acc9fa7a81c54e /examples/serialport/terminal
parentbcdeb589dd9d3b0ff7270d380d043b1882eefdc0 (diff)
Fix examples directory layout
Move examples into a dedicated 'serialport' directory. This is in line with what the other modules do, and makes sure that the examples show up in a sensible place even for the 'combined' source packages. Task-number: QTBUG-30912 Change-Id: Iefa2b634df3d2eb34f655b34f6fb24a224b78869 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Laszlo Papp <lpapp@kde.org> Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
Diffstat (limited to 'examples/serialport/terminal')
-rw-r--r--examples/serialport/terminal/console.cpp105
-rw-r--r--examples/serialport/terminal/console.h73
-rw-r--r--examples/serialport/terminal/images/application-exit.pngbin0 -> 11200 bytes
-rw-r--r--examples/serialport/terminal/images/clear.pngbin0 -> 12543 bytes
-rw-r--r--examples/serialport/terminal/images/connect.pngbin0 -> 15374 bytes
-rw-r--r--examples/serialport/terminal/images/disconnect.pngbin0 -> 15092 bytes
-rw-r--r--examples/serialport/terminal/images/settings.pngbin0 -> 16039 bytes
-rw-r--r--examples/serialport/terminal/main.cpp53
-rw-r--r--examples/serialport/terminal/mainwindow.cpp179
-rw-r--r--examples/serialport/terminal/mainwindow.h90
-rw-r--r--examples/serialport/terminal/mainwindow.ui162
-rw-r--r--examples/serialport/terminal/settingsdialog.cpp204
-rw-r--r--examples/serialport/terminal/settingsdialog.h102
-rw-r--r--examples/serialport/terminal/settingsdialog.ui170
-rw-r--r--examples/serialport/terminal/terminal.pro26
-rw-r--r--examples/serialport/terminal/terminal.qrc9
16 files changed, 1173 insertions, 0 deletions
diff --git a/examples/serialport/terminal/console.cpp b/examples/serialport/terminal/console.cpp
new file mode 100644
index 00000000..7f3f891e
--- /dev/null
+++ b/examples/serialport/terminal/console.cpp
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
+** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtSerialPort module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "console.h"
+
+#include <QScrollBar>
+
+#include <QtCore/QDebug>
+
+Console::Console(QWidget *parent)
+ : QPlainTextEdit(parent)
+ , localEchoEnabled(false)
+{
+ document()->setMaximumBlockCount(100);
+ QPalette p = palette();
+ p.setColor(QPalette::Base, Qt::black);
+ p.setColor(QPalette::Text, Qt::green);
+ setPalette(p);
+
+}
+
+void Console::putData(const QByteArray &data)
+{
+ insertPlainText(QString(data));
+
+ QScrollBar *bar = verticalScrollBar();
+ bar->setValue(bar->maximum());
+}
+
+void Console::setLocalEchoEnabled(bool set)
+{
+ localEchoEnabled = set;
+}
+
+void Console::keyPressEvent(QKeyEvent *e)
+{
+ switch (e->key()) {
+ case Qt::Key_Backspace:
+ case Qt::Key_Left:
+ case Qt::Key_Right:
+ case Qt::Key_Up:
+ case Qt::Key_Down:
+ // skip processing
+ break;
+ default:
+ if (localEchoEnabled)
+ QPlainTextEdit::keyPressEvent(e);
+ emit getData(e->text().toLocal8Bit());
+ }
+}
+
+void Console::mousePressEvent(QMouseEvent *e)
+{
+ Q_UNUSED(e)
+ setFocus();
+}
+
+void Console::mouseDoubleClickEvent(QMouseEvent *e)
+{
+ Q_UNUSED(e)
+}
+
+void Console::contextMenuEvent(QContextMenuEvent *e)
+{
+ Q_UNUSED(e)
+}
diff --git a/examples/serialport/terminal/console.h b/examples/serialport/terminal/console.h
new file mode 100644
index 00000000..9b5ba1f8
--- /dev/null
+++ b/examples/serialport/terminal/console.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
+** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtSerialPort module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CONSOLE_H
+#define CONSOLE_H
+
+#include <QPlainTextEdit>
+
+class Console : public QPlainTextEdit
+{
+ Q_OBJECT
+
+signals:
+ void getData(const QByteArray &data);
+
+public:
+ explicit Console(QWidget *parent = 0);
+
+ 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/serialport/terminal/images/application-exit.png b/examples/serialport/terminal/images/application-exit.png
new file mode 100644
index 00000000..32be6b3f
--- /dev/null
+++ b/examples/serialport/terminal/images/application-exit.png
Binary files differ
diff --git a/examples/serialport/terminal/images/clear.png b/examples/serialport/terminal/images/clear.png
new file mode 100644
index 00000000..aa612f1f
--- /dev/null
+++ b/examples/serialport/terminal/images/clear.png
Binary files differ
diff --git a/examples/serialport/terminal/images/connect.png b/examples/serialport/terminal/images/connect.png
new file mode 100644
index 00000000..dd5a51e9
--- /dev/null
+++ b/examples/serialport/terminal/images/connect.png
Binary files differ
diff --git a/examples/serialport/terminal/images/disconnect.png b/examples/serialport/terminal/images/disconnect.png
new file mode 100644
index 00000000..fd58f7a4
--- /dev/null
+++ b/examples/serialport/terminal/images/disconnect.png
Binary files differ
diff --git a/examples/serialport/terminal/images/settings.png b/examples/serialport/terminal/images/settings.png
new file mode 100644
index 00000000..3d1042e2
--- /dev/null
+++ b/examples/serialport/terminal/images/settings.png
Binary files differ
diff --git a/examples/serialport/terminal/main.cpp b/examples/serialport/terminal/main.cpp
new file mode 100644
index 00000000..e3565190
--- /dev/null
+++ b/examples/serialport/terminal/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
+** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtSerialPort module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+ w.show();
+ return a.exec();
+}
diff --git a/examples/serialport/terminal/mainwindow.cpp b/examples/serialport/terminal/mainwindow.cpp
new file mode 100644
index 00000000..47864a25
--- /dev/null
+++ b/examples/serialport/terminal/mainwindow.cpp
@@ -0,0 +1,179 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
+** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtSerialPort module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+#include "console.h"
+#include "settingsdialog.h"
+
+#include <QMessageBox>
+#include <QtSerialPort/QSerialPort>
+
+//! [0]
+MainWindow::MainWindow(QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::MainWindow)
+{
+//! [0]
+ ui->setupUi(this);
+ console = new Console;
+ console->setEnabled(false);
+ setCentralWidget(console);
+//! [1]
+ serial = new QSerialPort(this);
+//! [1]
+ settings = new SettingsDialog;
+
+ ui->actionConnect->setEnabled(true);
+ ui->actionDisconnect->setEnabled(false);
+ ui->actionQuit->setEnabled(true);
+ ui->actionConfigure->setEnabled(true);
+
+ initActionsConnections();
+
+ connect(serial, SIGNAL(error(QSerialPort::SerialPortError)), this,
+ SLOT(handleError(QSerialPort::SerialPortError)));
+
+//! [2]
+ connect(serial, SIGNAL(readyRead()), this, SLOT(readData()));
+//! [2]
+ connect(console, SIGNAL(getData(QByteArray)), this, SLOT(writeData(QByteArray)));
+//! [3]
+}
+//! [3]
+
+MainWindow::~MainWindow()
+{
+ delete settings;
+ delete ui;
+}
+
+//! [4]
+void MainWindow::openSerialPort()
+{
+ SettingsDialog::Settings p = settings->settings();
+ serial->setPortName(p.name);
+ if (serial->open(QIODevice::ReadWrite)) {
+ if (serial->setBaudRate(p.baudRate)
+ && serial->setDataBits(p.dataBits)
+ && serial->setParity(p.parity)
+ && serial->setStopBits(p.stopBits)
+ && serial->setFlowControl(p.flowControl)) {
+
+ console->setEnabled(true);
+ console->setLocalEchoEnabled(p.localEchoEnabled);
+ ui->actionConnect->setEnabled(false);
+ ui->actionDisconnect->setEnabled(true);
+ ui->actionConfigure->setEnabled(false);
+ ui->statusBar->showMessage(tr("Connected to %1 : %2, %3, %4, %5, %6")
+ .arg(p.name).arg(p.stringBaudRate).arg(p.stringDataBits)
+ .arg(p.stringParity).arg(p.stringStopBits).arg(p.stringFlowControl));
+
+ } else {
+ serial->close();
+ QMessageBox::critical(this, tr("Error"), serial->errorString());
+
+ ui->statusBar->showMessage(tr("Open error"));
+ }
+ } else {
+ QMessageBox::critical(this, tr("Error"), serial->errorString());
+
+ ui->statusBar->showMessage(tr("Configure error"));
+ }
+}
+//! [4]
+
+//! [5]
+void MainWindow::closeSerialPort()
+{
+ serial->close();
+ console->setEnabled(false);
+ ui->actionConnect->setEnabled(true);
+ ui->actionDisconnect->setEnabled(false);
+ ui->actionConfigure->setEnabled(true);
+ ui->statusBar->showMessage(tr("Disconnected"));
+}
+//! [5]
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Simple Terminal"),
+ tr("The <b>Simple Terminal</b> example demonstrates how to "
+ "use the Qt Serial Port module in modern GUI applications "
+ "using Qt, with a menu bar, toolbars, and a status bar."));
+}
+
+//! [6]
+void MainWindow::writeData(const QByteArray &data)
+{
+ serial->write(data);
+}
+//! [6]
+
+//! [7]
+void MainWindow::readData()
+{
+ QByteArray data = serial->readAll();
+ console->putData(data);
+}
+//! [7]
+
+//! [8]
+void MainWindow::handleError(QSerialPort::SerialPortError error)
+{
+ if (error == QSerialPort::ResourceError) {
+ QMessageBox::critical(this, tr("Critical Error"), serial->errorString());
+ closeSerialPort();
+ }
+}
+//! [8]
+
+void MainWindow::initActionsConnections()
+{
+ connect(ui->actionConnect, SIGNAL(triggered()), this, SLOT(openSerialPort()));
+ connect(ui->actionDisconnect, SIGNAL(triggered()), this, SLOT(closeSerialPort()));
+ connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(close()));
+ connect(ui->actionConfigure, SIGNAL(triggered()), settings, SLOT(show()));
+ connect(ui->actionClear, SIGNAL(triggered()), console, SLOT(clear()));
+ connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
+ connect(ui->actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
diff --git a/examples/serialport/terminal/mainwindow.h b/examples/serialport/terminal/mainwindow.h
new file mode 100644
index 00000000..1be7f893
--- /dev/null
+++ b/examples/serialport/terminal/mainwindow.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
+** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtSerialPort module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QtCore/QtGlobal>
+
+#include <QMainWindow>
+
+#include <QtSerialPort/QSerialPort>
+
+QT_BEGIN_NAMESPACE
+
+namespace Ui {
+class MainWindow;
+}
+
+QT_END_NAMESPACE
+
+class Console;
+class SettingsDialog;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+private slots:
+ void openSerialPort();
+ void closeSerialPort();
+ void about();
+ void writeData(const QByteArray &data);
+ void readData();
+
+ void handleError(QSerialPort::SerialPortError error);
+
+private:
+ void initActionsConnections();
+
+private:
+ Ui::MainWindow *ui;
+ Console *console;
+ SettingsDialog *settings;
+ QSerialPort *serial;
+};
+
+#endif // MAINWINDOW_H
diff --git a/examples/serialport/terminal/mainwindow.ui b/examples/serialport/terminal/mainwindow.ui
new file mode 100644
index 00000000..452fdd53
--- /dev/null
+++ b/examples/serialport/terminal/mainwindow.ui
@@ -0,0 +1,162 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Simple Terminal</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <layout class="QVBoxLayout" name="verticalLayout"/>
+ </widget>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>19</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menuCalls">
+ <property name="title">
+ <string>Calls</string>
+ </property>
+ <addaction name="actionConnect"/>
+ <addaction name="actionDisconnect"/>
+ <addaction name="separator"/>
+ <addaction name="actionQuit"/>
+ </widget>
+ <widget class="QMenu" name="menuTools">
+ <property name="title">
+ <string>Tools</string>
+ </property>
+ <addaction name="actionConfigure"/>
+ <addaction name="actionClear"/>
+ </widget>
+ <widget class="QMenu" name="menuHelp">
+ <property name="title">
+ <string>Help</string>
+ </property>
+ <addaction name="actionAbout"/>
+ <addaction name="actionAboutQt"/>
+ </widget>
+ <addaction name="menuCalls"/>
+ <addaction name="menuTools"/>
+ <addaction name="menuHelp"/>
+ </widget>
+ <widget class="QToolBar" name="mainToolBar">
+ <attribute name="toolBarArea">
+ <enum>TopToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ <addaction name="actionConnect"/>
+ <addaction name="actionDisconnect"/>
+ <addaction name="actionConfigure"/>
+ <addaction name="actionClear"/>
+ </widget>
+ <widget class="QStatusBar" name="statusBar"/>
+ <action name="actionAbout">
+ <property name="text">
+ <string>&amp;About</string>
+ </property>
+ <property name="toolTip">
+ <string>About program</string>
+ </property>
+ <property name="shortcut">
+ <string>Alt+A</string>
+ </property>
+ </action>
+ <action name="actionAboutQt">
+ <property name="text">
+ <string>About Qt</string>
+ </property>
+ </action>
+ <action name="actionConnect">
+ <property name="icon">
+ <iconset resource="terminal.qrc">
+ <normaloff>:/images/connect.png</normaloff>:/images/connect.png</iconset>
+ </property>
+ <property name="text">
+ <string>C&amp;onnect</string>
+ </property>
+ <property name="toolTip">
+ <string>Connect to serial port</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+O</string>
+ </property>
+ </action>
+ <action name="actionDisconnect">
+ <property name="icon">
+ <iconset resource="terminal.qrc">
+ <normaloff>:/images/disconnect.png</normaloff>:/images/disconnect.png</iconset>
+ </property>
+ <property name="text">
+ <string>&amp;Disconnect</string>
+ </property>
+ <property name="toolTip">
+ <string>Disconnect from serial port</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+D</string>
+ </property>
+ </action>
+ <action name="actionConfigure">
+ <property name="icon">
+ <iconset resource="terminal.qrc">
+ <normaloff>:/images/settings.png</normaloff>:/images/settings.png</iconset>
+ </property>
+ <property name="text">
+ <string>&amp;Configure</string>
+ </property>
+ <property name="toolTip">
+ <string>Configure serial port</string>
+ </property>
+ <property name="shortcut">
+ <string>Alt+C</string>
+ </property>
+ </action>
+ <action name="actionClear">
+ <property name="icon">
+ <iconset resource="terminal.qrc">
+ <normaloff>:/images/clear.png</normaloff>:/images/clear.png</iconset>
+ </property>
+ <property name="text">
+ <string>C&amp;lear</string>
+ </property>
+ <property name="toolTip">
+ <string>Clear data</string>
+ </property>
+ <property name="shortcut">
+ <string>Alt+L</string>
+ </property>
+ </action>
+ <action name="actionQuit">
+ <property name="icon">
+ <iconset resource="terminal.qrc">
+ <normaloff>:/images/application-exit.png</normaloff>:/images/application-exit.png</iconset>
+ </property>
+ <property name="text">
+ <string>&amp;Quit</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+Q</string>
+ </property>
+ </action>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources>
+ <include location="terminal.qrc"/>
+ </resources>
+ <connections/>
+</ui>
diff --git a/examples/serialport/terminal/settingsdialog.cpp b/examples/serialport/terminal/settingsdialog.cpp
new file mode 100644
index 00000000..65f6b87c
--- /dev/null
+++ b/examples/serialport/terminal/settingsdialog.cpp
@@ -0,0 +1,204 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
+** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtSerialPort module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "settingsdialog.h"
+#include "ui_settingsdialog.h"
+
+#include <QtSerialPort/QSerialPortInfo>
+#include <QIntValidator>
+#include <QLineEdit>
+
+QT_USE_NAMESPACE
+
+SettingsDialog::SettingsDialog(QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::SettingsDialog)
+{
+ ui->setupUi(this);
+
+ intValidator = new QIntValidator(0, 4000000, this);
+
+ ui->baudRateBox->setInsertPolicy(QComboBox::NoInsert);
+
+ connect(ui->applyButton, SIGNAL(clicked()),
+ this, SLOT(apply()));
+ connect(ui->serialPortInfoListBox, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(showPortInfo(int)));
+ connect(ui->baudRateBox, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(checkCustomBaudRatePolicy(int)));
+
+ fillPortsParameters();
+ fillPortsInfo();
+
+ updateSettings();
+}
+
+SettingsDialog::~SettingsDialog()
+{
+ delete ui;
+}
+
+SettingsDialog::Settings SettingsDialog::settings() const
+{
+ return currentSettings;
+}
+
+void SettingsDialog::showPortInfo(int idx)
+{
+ if (idx != -1) {
+ QStringList list = ui->serialPortInfoListBox->itemData(idx).toStringList();
+ ui->descriptionLabel->setText(tr("Description: %1").arg(list.at(1)));
+ ui->manufacturerLabel->setText(tr("Manufacturer: %1").arg(list.at(2)));
+ ui->locationLabel->setText(tr("Location: %1").arg(list.at(3)));
+ ui->vidLabel->setText(tr("Vendor Identifier: %1").arg(list.at(4)));
+ ui->pidLabel->setText(tr("Product Identifier: %1").arg(list.at(5)));
+ }
+}
+
+void SettingsDialog::apply()
+{
+ updateSettings();
+ hide();
+}
+
+void SettingsDialog::checkCustomBaudRatePolicy(int idx)
+{
+ bool isCustomBaudRate = !ui->baudRateBox->itemData(idx).isValid();
+ ui->baudRateBox->setEditable(isCustomBaudRate);
+ if (isCustomBaudRate) {
+ ui->baudRateBox->clearEditText();
+ QLineEdit *edit = ui->baudRateBox->lineEdit();
+ edit->setValidator(intValidator);
+ }
+}
+
+void SettingsDialog::fillPortsParameters()
+{
+ // fill baud rate (is not the entire list of available values,
+ // desired values??, add your independently)
+ ui->baudRateBox->addItem(QLatin1String("9600"), QSerialPort::Baud9600);
+ ui->baudRateBox->addItem(QLatin1String("19200"), QSerialPort::Baud19200);
+ ui->baudRateBox->addItem(QLatin1String("38400"), QSerialPort::Baud38400);
+ ui->baudRateBox->addItem(QLatin1String("115200"), QSerialPort::Baud115200);
+ ui->baudRateBox->addItem(QLatin1String("Custom"));
+
+ // fill data bits
+ ui->dataBitsBox->addItem(QLatin1String("5"), QSerialPort::Data5);
+ ui->dataBitsBox->addItem(QLatin1String("6"), QSerialPort::Data6);
+ ui->dataBitsBox->addItem(QLatin1String("7"), QSerialPort::Data7);
+ ui->dataBitsBox->addItem(QLatin1String("8"), QSerialPort::Data8);
+ ui->dataBitsBox->setCurrentIndex(3);
+
+ // fill parity
+ ui->parityBox->addItem(QLatin1String("None"), QSerialPort::NoParity);
+ ui->parityBox->addItem(QLatin1String("Even"), QSerialPort::EvenParity);
+ ui->parityBox->addItem(QLatin1String("Odd"), QSerialPort::OddParity);
+ ui->parityBox->addItem(QLatin1String("Mark"), QSerialPort::MarkParity);
+ ui->parityBox->addItem(QLatin1String("Space"), QSerialPort::SpaceParity);
+
+ // fill stop bits
+ ui->stopBitsBox->addItem(QLatin1String("1"), QSerialPort::OneStop);
+#ifdef Q_OS_WIN
+ ui->stopBitsBox->addItem(QLatin1String("1.5"), QSerialPort::OneAndHalfStop);
+#endif
+ ui->stopBitsBox->addItem(QLatin1String("2"), QSerialPort::TwoStop);
+
+ // fill flow control
+ ui->flowControlBox->addItem(QLatin1String("None"), QSerialPort::NoFlowControl);
+ ui->flowControlBox->addItem(QLatin1String("RTS/CTS"), QSerialPort::HardwareControl);
+ ui->flowControlBox->addItem(QLatin1String("XON/XOFF"), QSerialPort::SoftwareControl);
+}
+
+void SettingsDialog::fillPortsInfo()
+{
+ ui->serialPortInfoListBox->clear();
+ foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
+ QStringList list;
+ list << info.portName()
+ << info.description()
+ << info.manufacturer()
+ << info.systemLocation()
+ << (info.vendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : QString())
+ << (info.productIdentifier() ? QString::number(info.productIdentifier(), 16) : QString());
+
+ ui->serialPortInfoListBox->addItem(list.first(), list);
+ }
+}
+
+void SettingsDialog::updateSettings()
+{
+ currentSettings.name = ui->serialPortInfoListBox->currentText();
+
+ // Baud Rate
+ if (ui->baudRateBox->currentIndex() == 4) {
+ // custom baud rate
+ currentSettings.baudRate = ui->baudRateBox->currentText().toInt();
+ } else {
+ // standard baud rate
+ currentSettings.baudRate = static_cast<QSerialPort::BaudRate>(
+ ui->baudRateBox->itemData(ui->baudRateBox->currentIndex()).toInt());
+ }
+ currentSettings.stringBaudRate = QString::number(currentSettings.baudRate);
+
+ // Data bits
+ currentSettings.dataBits = static_cast<QSerialPort::DataBits>(
+ ui->dataBitsBox->itemData(ui->dataBitsBox->currentIndex()).toInt());
+ currentSettings.stringDataBits = ui->dataBitsBox->currentText();
+
+ // Parity
+ currentSettings.parity = static_cast<QSerialPort::Parity>(
+ ui->parityBox->itemData(ui->parityBox->currentIndex()).toInt());
+ currentSettings.stringParity = ui->parityBox->currentText();
+
+ // Stop bits
+ currentSettings.stopBits = static_cast<QSerialPort::StopBits>(
+ ui->stopBitsBox->itemData(ui->stopBitsBox->currentIndex()).toInt());
+ currentSettings.stringStopBits = ui->stopBitsBox->currentText();
+
+ // Flow control
+ 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/serialport/terminal/settingsdialog.h b/examples/serialport/terminal/settingsdialog.h
new file mode 100644
index 00000000..ff8f8b67
--- /dev/null
+++ b/examples/serialport/terminal/settingsdialog.h
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
+** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtSerialPort module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SETTINGSDIALOG_H
+#define SETTINGSDIALOG_H
+
+#include <QDialog>
+#include <QtSerialPort/QSerialPort>
+
+QT_USE_NAMESPACE
+
+QT_BEGIN_NAMESPACE
+
+namespace Ui {
+class SettingsDialog;
+}
+
+class QIntValidator;
+
+QT_END_NAMESPACE
+
+class SettingsDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ struct Settings {
+ QString name;
+ qint32 baudRate;
+ QString stringBaudRate;
+ QSerialPort::DataBits dataBits;
+ QString stringDataBits;
+ QSerialPort::Parity parity;
+ QString stringParity;
+ QSerialPort::StopBits stopBits;
+ QString stringStopBits;
+ QSerialPort::FlowControl flowControl;
+ QString stringFlowControl;
+ bool localEchoEnabled;
+ };
+
+ explicit SettingsDialog(QWidget *parent = 0);
+ ~SettingsDialog();
+
+ Settings settings() const;
+
+private slots:
+ void showPortInfo(int idx);
+ void apply();
+ void checkCustomBaudRatePolicy(int idx);
+
+private:
+ void fillPortsParameters();
+ void fillPortsInfo();
+ void updateSettings();
+
+private:
+ Ui::SettingsDialog *ui;
+ Settings currentSettings;
+ QIntValidator *intValidator;
+};
+
+#endif // SETTINGSDIALOG_H
diff --git a/examples/serialport/terminal/settingsdialog.ui b/examples/serialport/terminal/settingsdialog.ui
new file mode 100644
index 00000000..28c1211a
--- /dev/null
+++ b/examples/serialport/terminal/settingsdialog.ui
@@ -0,0 +1,170 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>SettingsDialog</class>
+ <widget class="QDialog" name="SettingsDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <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="1">
+ <widget class="QGroupBox" name="parametersBox">
+ <property name="title">
+ <string>Select Parameters</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="0">
+ <widget class="QLabel" name="baudRateLabel">
+ <property name="text">
+ <string>BaudRate:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QComboBox" name="baudRateBox"/>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="dataBitsLabel">
+ <property name="text">
+ <string>Data bits:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="dataBitsBox"/>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="parityLabel">
+ <property name="text">
+ <string>Parity:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QComboBox" name="parityBox"/>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="stopBitsLabel">
+ <property name="text">
+ <string>Stop bits:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QComboBox" name="stopBitsBox"/>
+ </item>
+ <item row="4" column="0">
+ <widget class="QLabel" name="flowControlLabel">
+ <property name="text">
+ <string>Flow control:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1">
+ <widget class="QComboBox" name="flowControlBox"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <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">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>96</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="applyButton">
+ <property name="text">
+ <string>Apply</string>
+ </property>
+ </widget>
+ </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/>
+ <connections/>
+</ui>
diff --git a/examples/serialport/terminal/terminal.pro b/examples/serialport/terminal/terminal.pro
new file mode 100644
index 00000000..0a5b545a
--- /dev/null
+++ b/examples/serialport/terminal/terminal.pro
@@ -0,0 +1,26 @@
+greaterThan(QT_MAJOR_VERSION, 4) {
+ QT += widgets serialport
+} else {
+ include($$QTSERIALPORT_PROJECT_ROOT/src/serialport/qt4support/serialport.prf)
+}
+
+TARGET = terminal
+TEMPLATE = app
+
+SOURCES += \
+ main.cpp \
+ mainwindow.cpp \
+ settingsdialog.cpp \
+ console.cpp
+
+HEADERS += \
+ mainwindow.h \
+ settingsdialog.h \
+ console.h
+
+FORMS += \
+ mainwindow.ui \
+ settingsdialog.ui
+
+RESOURCES += \
+ terminal.qrc
diff --git a/examples/serialport/terminal/terminal.qrc b/examples/serialport/terminal/terminal.qrc
new file mode 100644
index 00000000..0b498794
--- /dev/null
+++ b/examples/serialport/terminal/terminal.qrc
@@ -0,0 +1,9 @@
+<RCC>
+ <qresource prefix="/">
+ <file>images/connect.png</file>
+ <file>images/disconnect.png</file>
+ <file>images/application-exit.png</file>
+ <file>images/settings.png</file>
+ <file>images/clear.png</file>
+ </qresource>
+</RCC>