Add Headermemo, work in Progress
This commit is contained in:
@@ -6,6 +6,8 @@
|
|||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include "addressbook.h"
|
#include "addressbook.h"
|
||||||
#include "ui_memodialog.h"
|
#include "ui_memodialog.h"
|
||||||
|
#include "addressbook.h"
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -93,51 +95,23 @@ void ChatModel::renderChatBox(QListWidget *view)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setupchatTab() {
|
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
|
||||||
|
|
||||||
// Send button
|
j.setObject(h);
|
||||||
QObject::connect(ui->sendChatButton, &QPushButton::clicked, this, &MainWindow::sendChatButton);
|
header = j.toJson();
|
||||||
|
qDebug() << "made header=" << header;
|
||||||
|
|
||||||
}
|
return 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a Tx from the current state of the Chat page.
|
// Create a Tx from the current state of the Chat page.
|
||||||
@@ -158,13 +132,17 @@ Tx MainWindow::createTxFromChatPage() {
|
|||||||
|
|
||||||
amt = CAmount::fromDecimalString("0.00001");
|
amt = CAmount::fromDecimalString("0.00001");
|
||||||
totalAmt = totalAmt + amt;
|
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();
|
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";
|
qDebug() << "pushback chattx";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
|
#include "precompiled.h"
|
||||||
|
|
||||||
class ChatItem
|
class ChatItem
|
||||||
{
|
{
|
||||||
@@ -117,21 +118,4 @@ class ChatModel
|
|||||||
void addMessage(long timestamp, ChatItem item);
|
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
|
#endif
|
||||||
@@ -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()
|
void MainWindow::updateChat()
|
||||||
{
|
{
|
||||||
qDebug() << "Called MainWindow::updateChat()";
|
qDebug() << "Called MainWindow::updateChat()";
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ public:
|
|||||||
Logger* logger;
|
Logger* logger;
|
||||||
|
|
||||||
void doClose();
|
void doClose();
|
||||||
|
QString createHeaderMemo(QString cid, QString zaddr, int version, int headerNumnber);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void slot_change_theme(const QString& themeName);
|
void slot_change_theme(const QString& themeName);
|
||||||
@@ -153,4 +154,21 @@ private:
|
|||||||
QMovie* loadingMovie;
|
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
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
@@ -1388,14 +1388,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QLabel" name="memoSizeChat">
|
<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">
|
<property name="text">
|
||||||
<string notr="true">0 / 512</string>
|
<string notr="true">0 / 512</string>
|
||||||
</property>
|
</property>
|
||||||
|
|||||||
Reference in New Issue
Block a user