| 1 | /* dialogue.cpp |
| 2 | * |
| 3 | * This file is part of PRAELECTOR |
| 4 | * |
| 5 | * PRAELECTOR is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * PRAELECTOR is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with PRAELECTOR; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <QFont> |
| 22 | #include <dialogue.h> |
| 23 | #include <QDebug> |
| 24 | |
| 25 | |
| 26 | Dialogue::Dialogue () |
| 27 | { |
| 28 | resize(400, 300); |
| 29 | QFont font; |
| 30 | font.setPointSize(14); |
| 31 | setFont(font); |
| 32 | verticalLayout = new QVBoxLayout(this); |
| 33 | verticalLayout->setSpacing(6); |
| 34 | verticalLayout->setContentsMargins(11, 11, 11, 11); |
| 35 | |
| 36 | label = new QLabel(this); |
| 37 | verticalLayout->addWidget(label); |
| 38 | |
| 39 | plainTextEdit = new QPlainTextEdit(this); |
| 40 | plainTextEdit->setTabChangesFocus(true); |
| 41 | plainTextEdit->installEventFilter (this); |
| 42 | verticalLayout->addWidget(plainTextEdit); |
| 43 | |
| 44 | buttonBox = new QDialogButtonBox(this); |
| 45 | buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); |
| 46 | verticalLayout->addWidget(buttonBox); |
| 47 | |
| 48 | setModal (true); |
| 49 | |
| 50 | connect (buttonBox,SIGNAL(accepted()),this,SLOT(accept())); |
| 51 | connect (buttonBox,SIGNAL(rejected()),this,SLOT(reject())); |
| 52 | } |
| 53 | |
| 54 | bool Dialogue::eventFilter(QObject *obj, QEvent *event) |
| 55 | { |
| 56 | if (obj == plainTextEdit) |
| 57 | { |
| 58 | if (event->type() == QEvent::KeyPress) { |
| 59 | QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); |
| 60 | if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) |
| 61 | { |
| 62 | accept(); |
| 63 | return true; |
| 64 | } |
| 65 | } else { |
| 66 | return false; |
| 67 | } |
| 68 | } |
| 69 | return QDialog::eventFilter(obj, event); |
| 70 | } |
| 71 | |
| 72 | QString Dialogue::getText () |
| 73 | { |
| 74 | return plainTextEdit->toPlainText (); |
| 75 | } |
| 76 | |
| 77 | void Dialogue::setLabel (QString l) |
| 78 | { |
| 79 | label->setText (l); |
| 80 | } |
| 81 | |
| 82 | void Dialogue::setText (QString t) |
| 83 | { |
| 84 | plainTextEdit->setPlainText (t); |
| 85 | plainTextEdit->selectAll (); |
| 86 | } |
| 87 |