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

View File

@@ -330,22 +330,8 @@ void MainWindow::memoButtonClicked(int number, bool includeReplyTo) {
memoDialog.setupUi(&dialog);
Settings::saveRestore(&dialog);
QObject::connect(memoDialog.memoTxt, &QPlainTextEdit::textChanged, [=] () {
QString txt = memoDialog.memoTxt->toPlainText();
memoDialog.memoSize->setText(QString::number(txt.toUtf8().size()) + "/512");
if (txt.toUtf8().size() <= 512) {
// Everything is fine
memoDialog.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
memoDialog.memoSize->setStyleSheet("");
}
else {
// Overweight
memoDialog.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
memoDialog.memoSize->setStyleSheet("color: red;");
}
});
memoDialog.memoTxt->setLenDisplayLabel(memoDialog.memoSize);
memoDialog.memoTxt->setAcceptButton(memoDialog.buttonBox->button(QDialogButtonBox::Ok));
auto fnAddReplyTo = [=, &dialog]() {
QString replyTo = ui->inputsCombo->currentText();
@@ -354,11 +340,8 @@ void MainWindow::memoButtonClicked(int number, bool includeReplyTo) {
if (replyTo.isEmpty())
return;
}
auto curText = memoDialog.memoTxt->toPlainText();
if (curText.endsWith(replyTo))
return;
memoDialog.memoTxt->setPlainText(curText + "\n" + tr("Reply to") + ":\n" + replyTo);
memoDialog.memoTxt->includeReplyTo(replyTo);
// MacOS has a really annoying bug where the Plaintext doesn't refresh when the content is
// updated. So we do this ugly hack - resize the window slightly to force it to refresh