1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
4 ** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
5 ** Contact: http://www.qt-project.org/legal
6 **
7 ** This file is part of the QtSerialPort module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Digia.  For licensing terms and
15 ** conditions see http://qt.digia.com/licensing.  For further information
16 ** use the contact form at http://qt.digia.com/contact-us.
17 **
18 ** GNU Lesser General Public License Usage
19 ** Alternatively, this file may be used under the terms of the GNU Lesser
20 ** General Public License version 2.1 as published by the Free Software
21 ** Foundation and appearing in the file LICENSE.LGPL included in the
22 ** packaging of this file.  Please review the following information to
23 ** ensure the GNU Lesser General Public License version 2.1 requirements
24 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** In addition, as a special exception, Digia gives you certain additional
27 ** rights.  These rights are described in the Digia Qt LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42 
43 #include "console.h"
44 
45 #include <QScrollBar>
46 
47 #include <QtCore/QDebug>
48 
Console(QWidget * parent)49 Console::Console(QWidget *parent)
50     : QPlainTextEdit(parent)
51     , localEchoEnabled(false)
52 {
53     document()->setMaximumBlockCount(1000);
54     QFont font = document()->defaultFont();
55     font.setFamily("Droid Sans Mono");
56     document()->setDefaultFont(font);
57     //setCenterOnScroll(true);
58 }
59 
putData(const QByteArray & data)60 void Console::putData(const QByteArray &data)
61 {
62     insertPlainText(QString(data));
63 
64     QScrollBar *bar = verticalScrollBar();
65     bar->setValue(bar->maximum());
66 }
67 
setLocalEchoEnabled(bool set)68 void Console::setLocalEchoEnabled(bool set)
69 {
70     localEchoEnabled = set;
71 }
72 
keyPressEvent(QKeyEvent * e)73 void Console::keyPressEvent(QKeyEvent *e)
74 {
75     switch (e->key()) {
76     case Qt::Key_Backspace:
77     case Qt::Key_Left:
78     case Qt::Key_Right:
79     case Qt::Key_Up:
80     case Qt::Key_Down:
81         break;
82     default:
83         if (localEchoEnabled)
84             QPlainTextEdit::keyPressEvent(e);
85         emit getData(e->text().toLocal8Bit());
86     }
87 }
88 
mousePressEvent(QMouseEvent * e)89 void Console::mousePressEvent(QMouseEvent *e)
90 {
91     Q_UNUSED(e)
92     setFocus();
93 }
94 
mouseDoubleClickEvent(QMouseEvent * e)95 void Console::mouseDoubleClickEvent(QMouseEvent *e)
96 {
97     Q_UNUSED(e)
98 }
99 
contextMenuEvent(QContextMenuEvent * e)100 void Console::contextMenuEvent(QContextMenuEvent *e)
101 {
102     Q_UNUSED(e)
103 }
104