Refactor MemoEdit
This commit is contained in:
44
src/memoedit.cpp
Normal file
44
src/memoedit.cpp
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user