File: messagereplydialog.cpp

package info (click to toggle)
js8call 2.5.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 24,724 kB
  • sloc: cpp: 562,639; sh: 898; python: 132; ansic: 102; makefile: 4
file content (54 lines) | stat: -rw-r--r-- 1,605 bytes parent folder | download | duplicates (2)
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
#include "messagereplydialog.h"
#include "JS8_Include/EventFilter.h"
#include "JS8_Main/varicode.h"
#include "ui_messagereplydialog.h"
#include <QSet>

MessageReplyDialog::MessageReplyDialog(QWidget *parent)
    : QDialog(parent), ui(new Ui::MessageReplyDialog) {
    ui->setupUi(this);
    ui->textEdit->installEventFilter(new EventFilter::EnterKeyPress(
        [this](QKeyEvent *const event) {
            if (event->modifiers() & Qt::ShiftModifier)
                return false;
            this->accept();
            return true;
        },
        this));
}

MessageReplyDialog::~MessageReplyDialog() { delete ui; }

void MessageReplyDialog::setLabel(QString value) { ui->label->setText(value); }

void MessageReplyDialog::setTextValue(QString text) {
    ui->textEdit->setPlainText(text);
}

QString MessageReplyDialog::textValue() const {
    return ui->textEdit->toPlainText();
}

void MessageReplyDialog::on_textEdit_textChanged() {
    auto text = ui->textEdit->toPlainText();

    QString x;
    QString::const_iterator i;
    for (i = text.constBegin(); i != text.constEnd(); i++) {
        auto ch = (*i).toUpper().toLatin1();
        if (ch == 10 || (32 <= ch && ch <= 126)) {
            // newline or printable 7-bit ascii
            x += ch;
        }
    }

    if (x != text) {
        int pos = ui->textEdit->textCursor().position();
        int maxpos = x.size();
        ui->textEdit->setPlainText(x);
        QTextCursor c = ui->textEdit->textCursor();
        c.setPosition(pos < maxpos ? pos : maxpos, QTextCursor::MoveAnchor);

        ui->textEdit->setTextCursor(c);
    }
}