set maxLen for Chatmessages
This commit is contained in:
@@ -6,8 +6,49 @@
|
|||||||
#include "../DataStore/DataStore.h"
|
#include "../DataStore/DataStore.h"
|
||||||
Chat::Chat() {}
|
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();
|
QStandardItemModel *chat = new QStandardItemModel();
|
||||||
// ui->lcdNumber->setStyleSheet("background-color: red");
|
// ui->lcdNumber->setStyleSheet("background-color: red");
|
||||||
// ui->lcdNumber->setPalette(Qt::red);
|
// ui->lcdNumber->setPalette(Qt::red);
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class Chat // Chat Controller
|
|||||||
public:
|
public:
|
||||||
Chat();
|
Chat();
|
||||||
//QString zaddr();
|
//QString zaddr();
|
||||||
void renderChatBox(Ui::MainWindow* ui, QListView *view); // action
|
void renderChatBox(Ui::MainWindow* ui, QListView *view, QLabel *label); // action
|
||||||
// void renderContactRequest();
|
// void renderContactRequest();
|
||||||
/*void triggerRequest();
|
/*void triggerRequest();
|
||||||
void showMessages();
|
void showMessages();
|
||||||
|
|||||||
@@ -308,7 +308,7 @@ Tx MainWindow::createTxFromChatPage() {
|
|||||||
QString memo = ui->memoTxtChat->toPlainText().trimmed();
|
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, hmemo});
|
||||||
tx.toAddrs.push_back(ToFields{addr, amt, memo});
|
tx.toAddrs.push_back(ToFields{addr, amt, memo});
|
||||||
@@ -326,7 +326,7 @@ Tx MainWindow::createTxFromChatPage() {
|
|||||||
qDebug() << "ChatTx created";
|
qDebug() << "ChatTx created";
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::sendChatButton() {
|
void MainWindow::sendChat() {
|
||||||
|
|
||||||
////////////////////////////Todo: Check if a Contact is selected//////////
|
////////////////////////////Todo: Check if a Contact is selected//////////
|
||||||
|
|
||||||
|
|||||||
@@ -1009,7 +1009,7 @@ void Controller::refreshTransactions() {
|
|||||||
|
|
||||||
// Update model data, which updates the table view
|
// Update model data, which updates the table view
|
||||||
transactionsTableModel->replaceData(txdata);
|
transactionsTableModel->replaceData(txdata);
|
||||||
chat->renderChatBox(ui, ui->listChat);
|
chat->renderChatBox(ui, ui->listChat,ui->memoSize);
|
||||||
// refreshContacts(
|
// refreshContacts(
|
||||||
// ui->listContactWidget
|
// 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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public:
|
|||||||
void refreshGBPCAP();
|
void refreshGBPCAP();
|
||||||
void refreshAUDCAP();
|
void refreshAUDCAP();
|
||||||
|
|
||||||
void refreshChat(QListView *listWidget);
|
void refreshChat(QListView *listWidget, QLabel *label);
|
||||||
void refreshContacts(QListView *listWidget);
|
void refreshContacts(QListView *listWidget);
|
||||||
|
|
||||||
void executeStandardUITransaction(Tx tx);
|
void executeStandardUITransaction(Tx tx);
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
ui->memoTxtChat->setAutoFillBackground(false);
|
ui->memoTxtChat->setAutoFillBackground(false);
|
||||||
ui->memoTxtChat->setPlaceholderText("Send Message");
|
ui->memoTxtChat->setPlaceholderText("Send Message");
|
||||||
ui->memoTxtChat->setTextColor(Qt::white);
|
ui->memoTxtChat->setTextColor(Qt::white);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Status Bar
|
// Status Bar
|
||||||
setupStatusBar();
|
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->safeContactRequest, &QPushButton::clicked, this, &MainWindow::addContact);
|
||||||
QObject::connect(ui->pushContact, &QPushButton::clicked, this , &MainWindow::renderContactRequest);
|
QObject::connect(ui->pushContact, &QPushButton::clicked, this , &MainWindow::renderContactRequest);
|
||||||
|
|
||||||
@@ -1078,45 +1080,16 @@ void MainWindow::setupchatTab() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
ui->memoTxtChat->setLenDisplayLabel(ui->memoSize);// Todo -> activate lendisplay for chat
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatMemoEdit::ChatMemoEdit(QWidget* parent) : QPlainTextEdit(parent) {
|
|
||||||
QObject::connect(this, &QPlainTextEdit::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 MainWindow::updateChat()
|
void MainWindow::updateChat()
|
||||||
{
|
{
|
||||||
rpc->refreshChat(ui->listChat);
|
rpc->refreshChat(ui->listChat,ui->memoSize);
|
||||||
rpc->refresh(true);
|
rpc->refresh(true);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ public:
|
|||||||
void stopWebsocket();
|
void stopWebsocket();
|
||||||
void saveContact();
|
void saveContact();
|
||||||
void saveandsendContact();
|
void saveandsendContact();
|
||||||
|
void setMaxLen(int len);
|
||||||
|
void updateDisplay();
|
||||||
|
|
||||||
|
|
||||||
void balancesReady();
|
void balancesReady();
|
||||||
@@ -108,7 +110,7 @@ private:
|
|||||||
void setuphushdTab();
|
void setuphushdTab();
|
||||||
void setupchatTab();
|
void setupchatTab();
|
||||||
void renderContactRequest();
|
void renderContactRequest();
|
||||||
void setLenDisplayLabel(QLabel* label);
|
// void setLenDisplayLabel(QLabel* label);
|
||||||
|
|
||||||
void updateContacts();
|
void updateContacts();
|
||||||
void updateChat();
|
void updateChat();
|
||||||
@@ -130,9 +132,11 @@ private:
|
|||||||
|
|
||||||
void cancelButton();
|
void cancelButton();
|
||||||
void sendButton();
|
void sendButton();
|
||||||
void sendChatButton();
|
void sendChat();
|
||||||
void addContact();
|
void addContact();
|
||||||
void ContactRequest();
|
void ContactRequest();
|
||||||
|
|
||||||
|
|
||||||
void addAddressSection();
|
void addAddressSection();
|
||||||
void maxAmountChecked(int checked);
|
void maxAmountChecked(int checked);
|
||||||
|
|
||||||
@@ -171,6 +175,7 @@ private:
|
|||||||
WSServer* wsserver = nullptr;
|
WSServer* wsserver = nullptr;
|
||||||
WormholeClient* wormhole = nullptr;
|
WormholeClient* wormhole = nullptr;
|
||||||
|
|
||||||
|
|
||||||
Controller* rpc = nullptr;
|
Controller* rpc = nullptr;
|
||||||
|
|
||||||
QCompleter* labelCompleter = nullptr;
|
QCompleter* labelCompleter = nullptr;
|
||||||
@@ -182,15 +187,14 @@ private:
|
|||||||
QMovie* loadingMovie;
|
QMovie* loadingMovie;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ChatMemoEdit : public QPlainTextEdit
|
class ChatMemoEdit : public QTextEdit
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ChatMemoEdit(QWidget* parent);
|
ChatMemoEdit(QWidget* parent);
|
||||||
|
|
||||||
void setMaxLen(int len);
|
void setMaxLen(int len);
|
||||||
|
void setLenDisplayLabel(QLabel* label);
|
||||||
void setSendChatButton(QPushButton* button);
|
void SetSendChatButton(QPushButton* button);
|
||||||
void includeReplyTo(QString replyToAddress);
|
|
||||||
void updateDisplay();
|
void updateDisplay();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -199,4 +203,5 @@ private:
|
|||||||
QPushButton* sendChatButton = nullptr;
|
QPushButton* sendChatButton = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
@@ -1400,7 +1400,7 @@
|
|||||||
<string><html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Contactlist</span></p></body></html></string>
|
<string><html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Contactlist</span></p></body></html></string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QTextEdit" name="memoTxtChat">
|
<widget class="ChatMemoEdit" name="memoTxtChat">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>340</x>
|
<x>340</x>
|
||||||
@@ -1633,6 +1633,22 @@
|
|||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</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>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@@ -1819,6 +1835,11 @@
|
|||||||
<extends>QLabel</extends>
|
<extends>QLabel</extends>
|
||||||
<header>fillediconlabel.h</header>
|
<header>fillediconlabel.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>ChatMemoEdit</class>
|
||||||
|
<extends>QTextEdit</extends>
|
||||||
|
<header location="global">mainwindow.h</header>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>Address1</tabstop>
|
<tabstop>Address1</tabstop>
|
||||||
|
|||||||
Reference in New Issue
Block a user