/*===================================================================== APM_PLANNER Open Source Ground Control Station (c) 2013, Bill Bonney This file is part of the APM_PLANNER project APM_PLANNER is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. APM_PLANNER is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with APM_PLANNER. If not, see . ======================================================================*/ /** * @file * @brief Text Console. * * @author Bill Bonney * * Influenced from Qt examples by :- * Copyright (C) 2012 Denis Shienkov * Copyright (C) 2012 Laszlo Papp * */ #include "console.h" #include "ApmHighlighter.h" #include #include 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); m_highlighter = new APMHighlighter(document()); } 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) }