| 368 | } |
| 369 | |
| 370 | class NoReturnTextEdit: public QTextEdit |
| 371 | { |
| 372 | Q_OBJECT |
| 373 | public: |
| 374 | explicit NoReturnTextEdit(QWidget *parent) : QTextEdit(parent) |
| 375 | { |
| 376 | setTextInteractionFlags(Qt::TextEditorInteraction); |
| 377 | setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff); |
| 378 | setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff); |
| 379 | } |
| 380 | bool event(QEvent * event) override |
| 381 | { |
| 382 | auto eventType = event->type(); |
| 383 | if(eventType == QEvent::KeyPress || eventType == QEvent::KeyRelease) |
| 384 | { |
| 385 | QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); |
| 386 | auto key = keyEvent->key(); |
| 387 | if ((key == Qt::Key_Return || key == Qt::Key_Enter) && eventType == QEvent::KeyPress) |
| 388 | { |
| 389 | emit editingDone(); |
| 390 | return true; |
| 391 | } |
| 392 | if(key == Qt::Key_Tab) |
| 393 | { |
| 394 | return true; |
| 395 | } |
| 396 | } |
| 397 | return QTextEdit::event(event); |
| 398 | } |
| 399 | signals: |
| 400 | void editingDone(); |
| 401 | }; |