Debian Codegraph @

tests/manual/modbus/adueditor/plaintextedit.h

raw
1 // Copyright (C) 2017 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #ifndef PLAINTEXTEDIT_H
5 #define PLAINTEXTEDIT_H
6
7 #include <QMenu>
8 #include <QPlainTextEdit>
9
10 class PlainTextEdit : public QPlainTextEdit
11 {
12 Q_OBJECT
13 Q_DISABLE_COPY(PlainTextEdit)
14
15 public Q_SLOT:
16 void setFocus() {
17 QWidget::setFocus();
18 }
19
20 public:
21 explicit PlainTextEdit(QWidget *parent = nullptr)
22 : QPlainTextEdit(parent)
23 {}
24
25 void keyPressEvent(QKeyEvent *e)
26 {
27 switch (e->key()) {
28 case Qt::Key_Delete:
29 case Qt::Key_Backspace:
30 setTextInteractionFlags(textInteractionFlags() | Qt::TextEditable);
31 QPlainTextEdit::keyPressEvent(e);
32 setTextInteractionFlags(textInteractionFlags() &~ Qt::TextEditable);
33 break;
34 default:
35 QPlainTextEdit::keyPressEvent(e);
36 }
37 }
38
39 void contextMenuEvent(QContextMenuEvent *event)
40 {
41 QMenu menu(this);
42 menu.addAction(tr("Clear"), this, &QPlainTextEdit::clear);
43 #ifndef QT_NO_CLIPBOARD
44 menu.addAction(tr("Copy"), QKeySequence::Copy, this, &QPlainTextEdit::copy);
45 #endif
46 menu.addSeparator();
47 menu.addAction(tr("Select All"), QKeySequence::SelectAll,
48 this, &QPlainTextEdit::selectAll);
49 menu.exec(event->globalPos());
50 }
51 };
52
53 #endif // PLAINTEXTEDIT_H