Add Headermemo, work in Progress

This commit is contained in:
DenioD
2020-04-28 20:32:31 +02:00
parent e681d3000d
commit 555ac40ec2
5 changed files with 91 additions and 71 deletions

View File

@@ -6,6 +6,8 @@
#include "ui_mainwindow.h"
#include "addressbook.h"
#include "ui_memodialog.h"
#include "addressbook.h"
#include <QUuid>
@@ -93,51 +95,23 @@ void ChatModel::renderChatBox(QListWidget *view)
}
}
void MainWindow::setupchatTab() {
// Send button
QObject::connect(ui->sendChatButton, &QPushButton::clicked, this, &MainWindow::sendChatButton);
QString MainWindow::createHeaderMemo(QString cid, QString zaddr, int version=0, int headerNumber=1)
{
QString header="";
QJsonDocument j;
QJsonObject h;
// We use short keynames to use less space for metadata and so allow
// the user to send more actual data in memos
h["h"] = headerNumber; // header number
h["v"] = version; // HushChat version
h["z"] = zaddr; // zaddr to respond to
h["cid"] = cid; // conversation id
}
j.setObject(h);
header = j.toJson();
qDebug() << "made header=" << header;
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 ChatMemoEdit::setLenDisplayLabel(QLabel* label) {
this->lenDisplayLabel = label;
}
void ChatMemoEdit::setSendChatButton(QPushButton* button) {
this->sendChatButton = button;
return header;
}
// Create a Tx from the current state of the Chat page.
@@ -158,13 +132,17 @@ Tx MainWindow::createTxFromChatPage() {
amt = CAmount::fromDecimalString("0.00001");
totalAmt = totalAmt + amt;
QString cid = QString::number( time(NULL) % std::rand() ); // low entropy for testing!
// QString cid = QUuid::createUuid().toString(QUuid::WithoutBraces); // Needs to get a fix
QString hmemo= createHeaderMemo(cid,"ZADDR");
QString memo = ui->memoTxtChat->toPlainText().trimmed();
//ui->chatmemoSize->setLenDisplayLabel()
// ui->memoSizeChat->setLenDisplayLabel();
tx.toAddrs.push_back(ToFields{addr, amt, memo,}) ;
tx.toAddrs.push_back(ToFields{addr, amt, hmemo.toUtf8().toHex()}) ;
qDebug()<<hmemo;
tx.toAddrs.push_back( ToFields{addr, amt, memo.toUtf8().toHex()});
qDebug() << "pushback chattx";
}

View File

@@ -4,6 +4,7 @@
#include <map>
#include <vector>
#include <QListWidget>
#include "precompiled.h"
class ChatItem
{
@@ -117,21 +118,4 @@ class ChatModel
void addMessage(long timestamp, ChatItem item);
};
class ChatMemoEdit : public QPlainTextEdit
{
public:
ChatMemoEdit(QWidget* parent);
void setMaxLen(int len);
void setLenDisplayLabel(QLabel* label);
void setSendChatButton(QPushButton* button);
void includeReplyTo(QString replyToAddress);
void updateDisplay();
private:
int maxlen = 512;
QLabel* lenDisplayLabel = nullptr;
QPushButton* sendChatButton = nullptr;
};
#endif

View File

@@ -983,6 +983,54 @@ void MainWindow::setupTransactionsTab() {
});
}
void MainWindow::setupchatTab() {
// Send button
QObject::connect(ui->sendChatButton, &QPushButton::clicked, this, &MainWindow::sendChatButton);
}
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 ChatMemoEdit::setLenDisplayLabel(QLabel* label_40) {
this->lenDisplayLabel = label_40;
}
void ChatMemoEdit::setSendChatButton(QPushButton* button) {
this->sendChatButton = button;
}
void MainWindow::updateChat()
{
qDebug() << "Called MainWindow::updateChat()";

View File

@@ -76,6 +76,7 @@ public:
Logger* logger;
void doClose();
QString createHeaderMemo(QString cid, QString zaddr, int version, int headerNumnber);
public slots:
void slot_change_theme(const QString& themeName);
@@ -153,4 +154,21 @@ private:
QMovie* loadingMovie;
};
class ChatMemoEdit : public QPlainTextEdit
{
public:
ChatMemoEdit(QWidget* parent);
void setMaxLen(int len);
void setLenDisplayLabel(QLabel* label_40);
void setSendChatButton(QPushButton* button);
void includeReplyTo(QString replyToAddress);
void updateDisplay();
private:
int maxlen = 512;
QLabel* lenDisplayLabel = nullptr;
QPushButton* sendChatButton = nullptr;
};
#endif // MAINWINDOW_H

View File

@@ -1388,14 +1388,6 @@
</property>
</widget>
<widget class="QLabel" name="memoSizeChat">
<property name="geometry">
<rect>
<x>1150</x>
<y>460</y>
<width>91</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string notr="true">0 / 512</string>
</property>