Browse Source

Add Headermemo, work in Progress

pull/130/head
DenioD 4 years ago
parent
commit
555ac40ec2
  1. 74
      src/chatmodel.cpp
  2. 18
      src/chatmodel.h
  3. 48
      src/mainwindow.cpp
  4. 18
      src/mainwindow.h
  5. 8
      src/mainwindow.ui

74
src/chatmodel.cpp

@ -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)
{
// Send button QString header="";
QObject::connect(ui->sendChatButton, &QPushButton::clicked, this, &MainWindow::sendChatButton); 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
ChatMemoEdit::ChatMemoEdit(QWidget* parent) : QPlainTextEdit(parent) { h["h"] = headerNumber; // header number
QObject::connect(this, &QPlainTextEdit::textChanged, this, &ChatMemoEdit::updateDisplay); h["v"] = version; // HushChat version
} h["z"] = zaddr; // zaddr to respond to
h["cid"] = cid; // conversation id
void ChatMemoEdit::updateDisplay() {
QString txt = this->toPlainText(); j.setObject(h);
if (lenDisplayLabel) header = j.toJson();
lenDisplayLabel->setText(QString::number(txt.toUtf8().size()) + "/" + QString::number(maxlen)); qDebug() << "made header=" << header;
if (txt.toUtf8().size() <= maxlen) { return header;
// 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";
} }

18
src/chatmodel.h

@ -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

48
src/mainwindow.cpp

@ -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()";

18
src/mainwindow.h

@ -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

8
src/mainwindow.ui

@ -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>

Loading…
Cancel
Save