Refactor MemoEdit

This commit is contained in:
Aditya Kulkarni
2019-03-22 12:44:40 -07:00
parent 38998078ba
commit 9dd6821178
10 changed files with 282 additions and 28 deletions

44
src/memoedit.cpp Normal file
View File

@@ -0,0 +1,44 @@
#include "memoedit.h"
MemoEdit::MemoEdit(QWidget* parent) : QPlainTextEdit(parent) {
QObject::connect(this, &QPlainTextEdit::textChanged, [=]() {
QString txt = this->toPlainText();
if (lenDisplayLabel)
lenDisplayLabel->setText(QString::number(txt.toUtf8().size()) + "/" + QString::number(maxlen));
if (txt.toUtf8().size() <= maxlen) {
// Everything is fine
acceptButton->setEnabled(true);
lenDisplayLabel->setStyleSheet("");
}
else {
// Overweight
acceptButton->setEnabled(false);
lenDisplayLabel->setStyleSheet("color: red;");
}
});
}
void MemoEdit::setMaxLen(int len) {
this->maxlen = len;
}
void MemoEdit::setLenDisplayLabel(QLabel* label) {
this->lenDisplayLabel = label;
}
void MemoEdit::setAcceptButton(QPushButton* button) {
this->acceptButton = button;
}
void MemoEdit::includeReplyTo(QString addr) {
if (addr.isEmpty())
return;
auto curText = this->toPlainText();
if (curText.endsWith(addr))
return;
this->setPlainText(curText + "\n" + tr("Reply to") + ":\n" + addr);
}