| 1 | // File: outputpane.cpp |
| 2 | /* |
| 3 | Pep8-1 is a virtual machine for writing machine language and assembly |
| 4 | language programs. |
| 5 | |
| 6 | Copyright (C) 2009 J. Stanley Warford, Pepperdine University |
| 7 | |
| 8 | This program is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | #include <QFontDialog> |
| 22 | #include <QScrollBar> |
| 23 | #include "outputpane.h" |
| 24 | #include "ui_outputpane.h" |
| 25 | #include "pep.h" |
| 26 | |
| 27 | OutputPane::OutputPane(QWidget *parent) : |
| 28 | QWidget(parent), |
| 29 | ui(new Ui::OutputPane) |
| 30 | { |
| 31 | ui->setupUi(this); |
| 32 | |
| 33 | ui->label->setFont(QFont(Pep::labelFont, Pep::labelFontSize)); |
| 34 | ui->plainTextEdit->setFont(QFont(Pep::codeFont, Pep::ioFontSize)); |
| 35 | } |
| 36 | |
| 37 | OutputPane::~OutputPane() |
| 38 | { |
| 39 | delete ui; |
| 40 | } |
| 41 | |
| 42 | void OutputPane::appendOutput(QString str) |
| 43 | { |
| 44 | ui->plainTextEdit->setPlainText(ui->plainTextEdit->toPlainText().append(str)); |
| 45 | ui->plainTextEdit->verticalScrollBar()->setValue(ui->plainTextEdit->verticalScrollBar()->maximum()); |
| 46 | } |
| 47 | |
| 48 | void OutputPane::clearOutput() |
| 49 | { |
| 50 | ui->plainTextEdit->clear(); |
| 51 | } |
| 52 | |
| 53 | void OutputPane::highlightOnFocus() |
| 54 | { |
| 55 | if (ui->plainTextEdit->hasFocus()) { |
| 56 | ui->label->setAutoFillBackground(true); |
| 57 | } |
| 58 | else { |
| 59 | ui->label->setAutoFillBackground(false); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | bool OutputPane::hasFocus() |
| 64 | { |
| 65 | return ui->plainTextEdit->hasFocus(); |
| 66 | } |
| 67 | |
| 68 | void OutputPane::copy() |
| 69 | { |
| 70 | ui->plainTextEdit->copy(); |
| 71 | } |
| 72 | |
| 73 | void OutputPane::onFontChanged(QFont font) |
| 74 | { |
| 75 | ui->plainTextEdit->setFont(font); |
| 76 | } |
| 77 | |
| 78 | void OutputPane::mouseReleaseEvent(QMouseEvent *) |
| 79 | { |
| 80 | ui->plainTextEdit->setFocus(); |
| 81 | } |