From 7e0748dd24dd0ae9253b1891e243c79abb9dab10 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Thu, 21 May 2020 20:31:54 +0200 Subject: [PATCH] set maxLen for Chatmessages --- src/Chat/Chat.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- src/Chat/Chat.h | 2 +- src/chatmodel.cpp | 4 ++-- src/controller.cpp | 6 +++--- src/controller.h | 2 +- src/mainwindow.cpp | 39 ++++++--------------------------------- src/mainwindow.h | 17 +++++++++++------ src/mainwindow.ui | 23 ++++++++++++++++++++++- 8 files changed, 88 insertions(+), 48 deletions(-) diff --git a/src/Chat/Chat.cpp b/src/Chat/Chat.cpp index c7d6637..d6c8445 100644 --- a/src/Chat/Chat.cpp +++ b/src/Chat/Chat.cpp @@ -6,8 +6,49 @@ #include "../DataStore/DataStore.h" Chat::Chat() {} -void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view) +ChatMemoEdit::ChatMemoEdit(QWidget* parent) : QTextEdit(parent) { + QObject::connect(this, &QTextEdit::textChanged, this, &ChatMemoEdit::updateDisplay); +} + +void ChatMemoEdit::updateDisplay() { + QString txt = this->toPlainText(); + if (lenDisplayLabel) + lenDisplayLabel->setText(QString::number(txt.toUtf8().size()) + "/" + QString::number(maxlen)); + + if (txt.toUtf8().size() <= maxlen) { + // Everything is fine + if (sendChatButton) + sendChatButton->setEnabled(true); + + if (lenDisplayLabel) + lenDisplayLabel->setStyleSheet(""); + } + else { + // Overweight + if (sendChatButton) + sendChatButton->setEnabled(false); + + if (lenDisplayLabel) + lenDisplayLabel->setStyleSheet("color: red;"); + } +} + +void ChatMemoEdit::setMaxLen(int len) { + this->maxlen = len; + updateDisplay(); +} + +void ChatMemoEdit::SetSendChatButton(QPushButton* button) { + this->sendChatButton = button; +} + +void ChatMemoEdit::setLenDisplayLabel(QLabel* label) { + this->lenDisplayLabel = label; +} + +void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view, QLabel *label) { + QStandardItemModel *chat = new QStandardItemModel(); // ui->lcdNumber->setStyleSheet("background-color: red"); // ui->lcdNumber->setPalette(Qt::red); diff --git a/src/Chat/Chat.h b/src/Chat/Chat.h index 526aa36..efe5b56 100644 --- a/src/Chat/Chat.h +++ b/src/Chat/Chat.h @@ -28,7 +28,7 @@ class Chat // Chat Controller public: Chat(); //QString zaddr(); - void renderChatBox(Ui::MainWindow* ui, QListView *view); // action + void renderChatBox(Ui::MainWindow* ui, QListView *view, QLabel *label); // action // void renderContactRequest(); /*void triggerRequest(); void showMessages(); diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 29ba9c9..349f8be 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -308,7 +308,7 @@ Tx MainWindow::createTxFromChatPage() { QString memo = ui->memoTxtChat->toPlainText().trimmed(); - // ui->memoSizeChat->setLenDisplayLabel();// Todo -> activate lendisplay for chat + tx.toAddrs.push_back(ToFields{addr, amt, hmemo}); tx.toAddrs.push_back(ToFields{addr, amt, memo}); @@ -326,7 +326,7 @@ Tx MainWindow::createTxFromChatPage() { qDebug() << "ChatTx created"; } -void MainWindow::sendChatButton() { +void MainWindow::sendChat() { ////////////////////////////Todo: Check if a Contact is selected////////// diff --git a/src/controller.cpp b/src/controller.cpp index db895a1..8c3b603 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -1009,7 +1009,7 @@ void Controller::refreshTransactions() { // Update model data, which updates the table view transactionsTableModel->replaceData(txdata); - chat->renderChatBox(ui, ui->listChat); + chat->renderChatBox(ui, ui->listChat,ui->memoSize); // refreshContacts( // ui->listContactWidget @@ -1017,9 +1017,9 @@ void Controller::refreshTransactions() { }); } -void Controller::refreshChat(QListView *listWidget) +void Controller::refreshChat(QListView *listWidget, QLabel *label) { - chat->renderChatBox(ui, listWidget); + chat->renderChatBox(ui, listWidget, label); } diff --git a/src/controller.h b/src/controller.h index cfd3bbb..b34aeb4 100644 --- a/src/controller.h +++ b/src/controller.h @@ -74,7 +74,7 @@ public: void refreshGBPCAP(); void refreshAUDCAP(); - void refreshChat(QListView *listWidget); + void refreshChat(QListView *listWidget, QLabel *label); void refreshContacts(QListView *listWidget); void executeStandardUITransaction(Tx tx); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e895947..4f0f08f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -50,6 +50,8 @@ MainWindow::MainWindow(QWidget *parent) : ui->memoTxtChat->setAutoFillBackground(false); ui->memoTxtChat->setPlaceholderText("Send Message"); ui->memoTxtChat->setTextColor(Qt::white); + + // Status Bar setupStatusBar(); @@ -1053,7 +1055,7 @@ void MainWindow::setupchatTab() { - QObject::connect(ui->sendChatButton, &QPushButton::clicked, this, &MainWindow::sendChatButton); + QObject::connect(ui->sendChatButton, &QPushButton::clicked, this, &MainWindow::sendChat); QObject::connect(ui->safeContactRequest, &QPushButton::clicked, this, &MainWindow::addContact); QObject::connect(ui->pushContact, &QPushButton::clicked, this , &MainWindow::renderContactRequest); @@ -1078,45 +1080,16 @@ void MainWindow::setupchatTab() { }); - -} - -ChatMemoEdit::ChatMemoEdit(QWidget* parent) : QPlainTextEdit(parent) { - QObject::connect(this, &QPlainTextEdit::textChanged, this, &ChatMemoEdit::updateDisplay); +ui->memoTxtChat->setLenDisplayLabel(ui->memoSize);// Todo -> activate lendisplay for chat } -void ChatMemoEdit::updateDisplay() { - QString txt = this->toPlainText(); - if (lenDisplayLabel) - lenDisplayLabel->setText(QString::number(txt.toUtf8().size()) + "/" + QString::number(maxlen)); - - if (txt.toUtf8().size() <= maxlen) { - // Everything is fine - if (sendChatButton) - sendChatButton->setEnabled(true); - - if (lenDisplayLabel) - lenDisplayLabel->setStyleSheet(""); - } - else { - // Overweight - if (sendChatButton) - sendChatButton->setEnabled(false); - - if (lenDisplayLabel) - lenDisplayLabel->setStyleSheet("color: red;"); - } -} -void ChatMemoEdit::setMaxLen(int len) { - this->maxlen = len; - updateDisplay(); -} void MainWindow::updateChat() { - rpc->refreshChat(ui->listChat); + rpc->refreshChat(ui->listChat,ui->memoSize); rpc->refresh(true); + } diff --git a/src/mainwindow.h b/src/mainwindow.h index 445e3f6..85f4feb 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -58,6 +58,8 @@ public: void stopWebsocket(); void saveContact(); void saveandsendContact(); + void setMaxLen(int len); + void updateDisplay(); void balancesReady(); @@ -108,7 +110,7 @@ private: void setuphushdTab(); void setupchatTab(); void renderContactRequest(); - void setLenDisplayLabel(QLabel* label); + // void setLenDisplayLabel(QLabel* label); void updateContacts(); void updateChat(); @@ -130,9 +132,11 @@ private: void cancelButton(); void sendButton(); - void sendChatButton(); + void sendChat(); void addContact(); void ContactRequest(); + + void addAddressSection(); void maxAmountChecked(int checked); @@ -171,6 +175,7 @@ private: WSServer* wsserver = nullptr; WormholeClient* wormhole = nullptr; + Controller* rpc = nullptr; QCompleter* labelCompleter = nullptr; @@ -182,15 +187,14 @@ private: QMovie* loadingMovie; }; -class ChatMemoEdit : public QPlainTextEdit +class ChatMemoEdit : public QTextEdit { public: ChatMemoEdit(QWidget* parent); void setMaxLen(int len); - - void setSendChatButton(QPushButton* button); - void includeReplyTo(QString replyToAddress); + void setLenDisplayLabel(QLabel* label); + void SetSendChatButton(QPushButton* button); void updateDisplay(); private: @@ -199,4 +203,5 @@ private: QPushButton* sendChatButton = nullptr; }; + #endif // MAINWINDOW_H diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 1ce2a50..399e3e9 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1400,7 +1400,7 @@ <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Contactlist</span></p></body></html> - + 340 @@ -1633,6 +1633,22 @@ true + + + + 1160 + 540 + 91 + 17 + + + + 0 / 512 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + @@ -1819,6 +1835,11 @@ QLabel
fillediconlabel.h
+ + ChatMemoEdit + QTextEdit +
mainwindow.h
+
Address1