1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
/** Copyright (C) 2006, Ian Paul Larsen.
**
** This program 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 2 of the License, or
** (at your option) any later version.
**
** This program 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 this program; if not, write to the Free Software Foundation, Inc.,
** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
**/
#include <iostream>
#include <QPainter>
#include <QTextCursor>
#include <QMutex>
#include <QClipboard>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QMessageBox>
#include <QtPrintSupport/QPrintDialog>
#include <QtPrintSupport/QPrinter>
#include "Settings.h"
#include "BasicOutput.h"
extern QMutex *mymutex;
extern int currentKey;
BasicOutput::BasicOutput( ) : QTextEdit () {
setInputMethodHints(Qt::ImhNoPredictiveText);
setFocusPolicy(Qt::StrongFocus);
setAcceptRichText(false);
gettingInput = false;
}
BasicOutput::~BasicOutput( ) {
// destructor for basic output
}
void
BasicOutput::getInput() {
gettingInput = true;
startPos = textCursor().position();
setReadOnly(false);
setFocus();
}
void
BasicOutput::keyPressEvent(QKeyEvent *e) {
e->accept();
if (!gettingInput) {
mymutex->lock();
currentKey = e->key();
mymutex->unlock();
//QTextEdit::keyPressEvent(e);
} else {
if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
QTextCursor t(textCursor());
t.setPosition(startPos, QTextCursor::KeepAnchor);
emit(inputEntered(t.selectedText())); // send the string back to the interperter and run controller
insertPlainText("\n");
gettingInput = false;
setReadOnly(true);
} else if (e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Left) {
QTextCursor t(textCursor());
t.movePosition(QTextCursor::PreviousCharacter);
if (t.position() >= startPos)
QTextEdit::keyPressEvent(e);
} else if (e->key() == Qt::Key_Home || e->key() == Qt::Key_PageUp || e->key() == Qt::Key_Up) {
QTextCursor t(textCursor());
t.setPosition(startPos);
setTextCursor(t);
} else {
QTextEdit::keyPressEvent(e);
}
}
}
bool BasicOutput::initActions(QMenu * vMenu, ToolBar * vToolBar) {
if ((NULL == vMenu) || (NULL == vToolBar)) {
return false;
}
QAction *copyAct = vMenu->addAction(QObject::tr("Copy"));
QAction *pasteAct = vMenu->addAction(QObject::tr("Paste"));
QAction *printAct = vMenu->addAction(QObject::tr("Print"));
vToolBar->addAction(copyAct);
vToolBar->addAction(pasteAct);
vToolBar->addAction(printAct);
QObject::connect(copyAct, SIGNAL(triggered()), this, SLOT(copy()));
QObject::connect(pasteAct, SIGNAL(triggered()), this, SLOT(paste()));
QObject::connect(printAct, SIGNAL(triggered()), this, SLOT(slotPrint()));
m_usesToolBar = true;
m_usesMenu = true;
return true;
}
void BasicOutput::slotPrint() {
#ifdef ANDROID
QMessageBox::warning(this, QObject::tr("Print Error"), QObject::tr("Printing is not supported in this platform at this time."));
#else
QTextDocument *document = this->document();
QPrinter printer;
QPrintDialog *dialog = new QPrintDialog(&printer, this);
dialog->setWindowTitle(QObject::tr("Print Text Output"));
if (dialog->exec() == QDialog::Accepted) {
if ((printer.printerState() != QPrinter::Error) && (printer.printerState() != QPrinter::Aborted)) {
document->print(&printer);
} else {
QMessageBox::warning(this, QObject::tr("Print Error"), QObject::tr("Unable to carry out printing.\nPlease check your printer settings."));
}
}
#endif
}
|