File: messagereplydialog.cpp

package info (click to toggle)
js8call 2.2.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 22,416 kB
  • sloc: cpp: 563,285; f90: 9,265; ansic: 937; python: 132; sh: 93; makefile: 6
file content (66 lines) | stat: -rw-r--r-- 1,717 bytes parent folder | download | duplicates (3)
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
#include "messagereplydialog.h"
#include "ui_messagereplydialog.h"

#include "varicode.h"

#include <QSet>

MessageReplyDialog::MessageReplyDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::MessageReplyDialog)
{
    ui->setupUi(this);

    auto enterFilter = new EnterKeyPressEater();
    connect(enterFilter, &EnterKeyPressEater::enterKeyPressed, this, [this](QObject *, QKeyEvent *, bool *pProcessed){
        if(QApplication::keyboardModifiers() & Qt::ShiftModifier){
            if(pProcessed) *pProcessed = false;
            return;
        }
        if(pProcessed) *pProcessed = true;

        this->accept();
    });
    ui->textEdit->installEventFilter(enterFilter);
}

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);
    }
}