Browse Source

set maxLen for Chatmessages

pull/130/head
DenioD 4 years ago
parent
commit
7e0748dd24
  1. 43
      src/Chat/Chat.cpp
  2. 2
      src/Chat/Chat.h
  3. 4
      src/chatmodel.cpp
  4. 6
      src/controller.cpp
  5. 2
      src/controller.h
  6. 39
      src/mainwindow.cpp
  7. 17
      src/mainwindow.h
  8. 23
      src/mainwindow.ui

43
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);

2
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();

4
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//////////

6
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);
}

2
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);

39
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);
}

17
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

23
src/mainwindow.ui

@ -1400,7 +1400,7 @@
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-weight:600; text-decoration: underline;&quot;&gt;Contactlist&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QTextEdit" name="memoTxtChat">
<widget class="ChatMemoEdit" name="memoTxtChat">
<property name="geometry">
<rect>
<x>340</x>
@ -1633,6 +1633,22 @@
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="memoSize">
<property name="geometry">
<rect>
<x>1160</x>
<y>540</y>
<width>91</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string notr="true">0 / 512</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</widget>
</widget>
</item>
@ -1819,6 +1835,11 @@
<extends>QLabel</extends>
<header>fillediconlabel.h</header>
</customwidget>
<customwidget>
<class>ChatMemoEdit</class>
<extends>QTextEdit</extends>
<header location="global">mainwindow.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>Address1</tabstop>

Loading…
Cancel
Save