From bf8b0c960a048c4df402c80496f1845949b10bf0 Mon Sep 17 00:00:00 2001
From: DenioD <41270280+DenioD@users.noreply.github.com>
Date: Tue, 16 Jun 2020 21:55:33 +0200
Subject: [PATCH] fix symbol counter for requests #141
---
src/Chat/Chat.cpp | 39 +++++++++++++++++++++++++++++++++++++++
src/chatmodel.cpp | 6 ++++--
src/contactrequest.ui | 11 +++++++++--
src/mainwindow.cpp | 1 +
src/mainwindow.h | 16 ++++++++++++++++
src/mainwindow.ui | 2 +-
6 files changed, 70 insertions(+), 5 deletions(-)
diff --git a/src/Chat/Chat.cpp b/src/Chat/Chat.cpp
index 1916c9d..3c68837 100644
--- a/src/Chat/Chat.cpp
+++ b/src/Chat/Chat.cpp
@@ -46,6 +46,45 @@ void ChatMemoEdit::setLenDisplayLabelChat(QLabel* label) {
this->lenDisplayLabelchat = label;
}
+ChatMemoEditRequest::ChatMemoEditRequest(QWidget* parent) : QTextEdit(parent) {
+ QObject::connect(this, &QTextEdit::textChanged, this, &ChatMemoEditRequest::updateDisplayChatRequest);
+}
+
+void ChatMemoEditRequest::updateDisplayChatRequest() {
+ QString txt = this->toPlainText();
+ if (lenDisplayLabelchatRequest)
+ lenDisplayLabelchatRequest->setText(QString::number(txt.toUtf8().size()) + "/" + QString::number(maxlenchatrequest));
+
+ if (txt.toUtf8().size() <= maxlenchatrequest) {
+ // Everything is fine
+ if (sendRequestButton)
+ sendRequestButton->setEnabled(true);
+
+ if (lenDisplayLabelchatRequest)
+ lenDisplayLabelchatRequest->setStyleSheet("");
+ }
+ else {
+ // Overweight
+ if (sendRequestButton)
+ sendRequestButton->setEnabled(false);
+
+ if (lenDisplayLabelchatRequest)
+ lenDisplayLabelchatRequest->setStyleSheet("color: red;");
+ }
+}
+
+void ChatMemoEditRequest::setMaxLenChatRequest(int len) {
+ this->maxlenchatrequest = len;
+ updateDisplayChatRequest();
+}
+
+void ChatMemoEditRequest::SetSendRequestButton(QPushButton* button) {
+ this->sendRequestButton = button;
+}
+
+void ChatMemoEditRequest::setLenDisplayLabelChatRequest(QLabel* label) {
+ this->lenDisplayLabelchatRequest = label;
+}
void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view, QLabel *label)
{
diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp
index c30b06d..7d32180 100644
--- a/src/chatmodel.cpp
+++ b/src/chatmodel.cpp
@@ -703,6 +703,8 @@ void::MainWindow::addContact()
request.setupUi(&dialog);
Settings::saveRestore(&dialog);
+ request.memorequest->setLenDisplayLabelChatRequest(request.memoSizeChatRequest);
+
try
{
@@ -820,7 +822,7 @@ void MainWindow::ContactRequest() {
return;
}
- int max = 235;
+ int max = 512;
QString chattext = contactRequest.getMemo();;
int size = chattext.size();
@@ -829,7 +831,7 @@ void MainWindow::ContactRequest() {
// auto addr = "";
// if (! Settings::isZAddress(AddressBook::addressFromAddressLabel(addr->text()))) {
QMessageBox msg(QMessageBox::Critical, tr("Your Message is too long"),
- tr("You can only write messages with 235 character maximum \n") + tr("\n Please reduce your message to 235 character."),
+ tr("You can only write messages with 512 character maximum \n") + tr("\n Please reduce your message to 235 character."),
QMessageBox::Ok, this);
msg.exec();
diff --git a/src/contactrequest.ui b/src/contactrequest.ui
index 6f6a529..62699d3 100644
--- a/src/contactrequest.ui
+++ b/src/contactrequest.ui
@@ -378,7 +378,7 @@
-
-
+
0
@@ -391,7 +391,7 @@
-
-
+
Add a memo to your request
@@ -437,6 +437,13 @@
+
+
+ ChatMemoEditRequest
+ QTextEdit
+
+
+
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 0aca5e6..8c9923b 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1548,6 +1548,7 @@ void MainWindow::setupchatTab() {
});
ui->memoTxtChat->setLenDisplayLabelChat(ui->memoSizeChat);
+
}
void MainWindow::updateChat()
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 1edb3d8..3550b5a 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -214,5 +214,21 @@ private:
QPushButton* sendChatButton = nullptr;
};
+class ChatMemoEditRequest : public QTextEdit
+{
+public:
+ ChatMemoEditRequest(QWidget* parent);
+
+ void setMaxLenChatRequest(int len);
+ void setLenDisplayLabelChatRequest(QLabel* label);
+ void SetSendRequestButton(QPushButton* button);
+ void updateDisplayChatRequest();
+
+private:
+ int maxlenchatrequest = 512;
+ QLabel* lenDisplayLabelchatRequest = nullptr;
+ QPushButton* sendRequestButton = nullptr;
+};
+
#endif // MAINWINDOW_H
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index cf6fa57..f771bc4 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -429,7 +429,7 @@
0
0
1226
- 493
+ 509