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