From c1954633de37fe8972859020a94cb7e0dafb04f4 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Thu, 21 May 2020 16:00:25 +0200 Subject: [PATCH 1/6] merge PR, send request from Contacttab --- src/Model/ContactRequest.cpp | 28 +++++++- src/Model/ContactRequest.h | 8 ++- src/chatmodel.cpp | 122 +++++++++++++++++++++++++++-------- src/contactrequest.ui | 63 ++++++++++++++---- src/mainwindow.h | 2 + 5 files changed, 182 insertions(+), 41 deletions(-) diff --git a/src/Model/ContactRequest.cpp b/src/Model/ContactRequest.cpp index 68b4ed3..9741ba0 100644 --- a/src/Model/ContactRequest.cpp +++ b/src/Model/ContactRequest.cpp @@ -5,12 +5,14 @@ ContactRequest::ContactRequest() {} -ContactRequest::ContactRequest(QString sender, QString receiver, QString memo, QString cid) +ContactRequest::ContactRequest(QString sender, QString receiver, QString memo, QString cid, QString label, QString avatar) { _senderAddress = sender; _receiverAddress = receiver; _memo = memo; _cid = cid; + _label = label; + _avatar = avatar; } QString ContactRequest::getSenderAddress() @@ -33,6 +35,16 @@ QString ContactRequest::getCid() return _cid; } +QString ContactRequest::getLabel() +{ + return _label; +} + +QString ContactRequest::getAvatar() +{ + return _avatar; +} + void ContactRequest::setSenderAddress(QString address) { _senderAddress = address; @@ -53,9 +65,19 @@ void ContactRequest::setCid(QString cid) _cid = cid; } +void ContactRequest::setLabel(QString label) +{ + _label = label; +} + +void ContactRequest::setAvatar(QString avatar) +{ + _avatar = avatar; +} + QString ContactRequest::toString() { - return "sender: " + _senderAddress + " receiver: " + _receiverAddress + " memo: " + _memo + " cid: " + _cid; + return "sender: " + _senderAddress + " receiver: " + _receiverAddress + " memo: " + _memo + " cid: " + _cid + " label: " + _label + " avatar: " + _avatar; } ContactRequest::~ContactRequest() @@ -64,4 +86,6 @@ ContactRequest::~ContactRequest() _receiverAddress = ""; _memo = ""; _cid = ""; + _label = ""; + _avatar = ""; } \ No newline at end of file diff --git a/src/Model/ContactRequest.h b/src/Model/ContactRequest.h index 5339d5c..5335434 100644 --- a/src/Model/ContactRequest.h +++ b/src/Model/ContactRequest.h @@ -14,18 +14,24 @@ class ContactRequest QString _receiverAddress; QString _memo; QString _cid; + QString _label; + QString _avatar; public: ContactRequest(); - ContactRequest(QString sender, QString receiver, QString memo, QString cid); + ContactRequest(QString sender, QString receiver, QString memo, QString cid, QString label, QString avatar); QString getSenderAddress(); QString getReceiverAddress(); QString getMemo(); QString getCid(); + QString getLabel(); + QString getAvatar(); void setSenderAddress(QString address); void setReceiverAddress(QString contact); void setMemo(QString memo); void setCid(QString cid); + void setLabel(QString label); + void setAvatar(QString avatar); QString toString(); ~ContactRequest(); }; diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index e8f8015..42a2419 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -463,6 +463,8 @@ void::MainWindow::addContact() QDialog dialog(this); request.setupUi(&dialog); Settings::saveRestore(&dialog); + + bool sapling = true; rpc->createNewZaddr(sapling, [=] (json reply) { QString myAddr = QString::fromStdString(reply.get()[0]); @@ -471,21 +473,48 @@ void::MainWindow::addContact() ui->listReceiveAddresses->setCurrentIndex(0); qDebug() << "new generated myAddr" << myAddr; }); + + QString cid = QUuid::createUuid().toString(QUuid::WithoutBraces); + request.cid->setText(cid); + + - QString cid = QUuid::createUuid().toString(QUuid::WithoutBraces); - request.cid->setText(cid); - QObject::connect(request.sendRequestButton, &QPushButton::clicked, [&] () { - QString cid = request.cid->text(); - QString addr = request.zaddr->text().trimmed(); - QString getrequest = addr; - QString newLabel = request.labelRequest->text().trimmed(); + + QString addr = request.zaddr->text(); QString myAddr = request.myzaddr->text().trimmed(); + QString memo = request.memorequest->toPlainText().trimmed(); + QString avatar = QString(":/icons/res/") + request.comboBoxAvatar->currentText() + QString(".png"); + QString label = request.labelRequest->text().trimmed(); + + contactRequest.setSenderAddress(myAddr); contactRequest.setReceiverAddress(addr); - contactRequest.setMemo(newLabel); + contactRequest.setMemo(memo); contactRequest.setCid(cid); - QString avatar = QString(":/icons/res/") + request.comboBoxAvatar->currentText() + QString(".png"); + contactRequest.setAvatar(avatar); + contactRequest.setLabel(label); + + }); + + QObject::connect(request.sendRequestButton, &QPushButton::clicked, this, &MainWindow::saveandsendContact); + QObject::connect(request.onlyAdd, &QPushButton::clicked, this, &MainWindow::saveContact); + + dialog.exec(); + + rpc->refreshContacts(ui->listContactWidget); + +} + +void MainWindow::saveandsendContact() +{ + this->ContactRequest(); + QString addr = contactRequest.getReceiverAddress(); + QString newLabel = contactRequest.getLabel(); + QString myAddr = contactRequest.getSenderAddress(); + QString cid = contactRequest.getCid(); + QString avatar = contactRequest.getAvatar(); + if (addr.isEmpty() || newLabel.isEmpty()) { QMessageBox::critical( @@ -520,42 +549,83 @@ void::MainWindow::addContact() QMessageBox::Ok ); return; - }); - - dialog.exec(); - rpc->refreshContacts(ui->listContactWidget); + + + } +void MainWindow::saveContact() +{ + QString addr = contactRequest.getReceiverAddress(); + QString newLabel = contactRequest.getLabel(); + QString myAddr = contactRequest.getSenderAddress(); + QString cid = contactRequest.getCid(); + QString avatar = contactRequest.getAvatar(); + + if (addr.isEmpty() || newLabel.isEmpty()) + { + QMessageBox::critical( + this, + QObject::tr("Address or Label Error"), + QObject::tr("Address or Label cannot be empty"), + QMessageBox::Ok + ); + return; + } + + // Test if address is valid. + if (!Settings::isValidAddress(addr)) + { + QMessageBox::critical( + this, + QObject::tr("Address Format Error"), + QObject::tr("%1 doesn't seem to be a valid hush address.").arg(addr), + QMessageBox::Ok + ); + return; + } + + ///////Todo: Test if label allready exist! + + ////// Success, so show it + AddressBook::getInstance()->addAddressLabel(newLabel, addr, myAddr, cid, avatar); + QMessageBox::information( + this, + QObject::tr("Added Contact"), + QObject::tr("successfully added your new contact").arg(newLabel), + QMessageBox::Ok + ); + return; + +} // Create a Tx for a contact Request Tx MainWindow::createTxForSafeContactRequest() { Tx tx; +{ CAmount totalAmt; QString amtStr = "0"; CAmount amt; amt = CAmount::fromDecimalString("0"); totalAmt = totalAmt + amt; - for(auto &c : AddressBook::getInstance()->getAllAddressLabels()) - { - if (ui->contactNameMemo->text().trimmed() == c.getName()) - { - QString cid = c.getCid(); - QString myAddr = c.getMyAddress(); + + QString cid = contactRequest.getCid(); + QString myAddr = contactRequest.getSenderAddress(); QString type = "Cont"; - QString addr = c.getPartnerAddress(); - qDebug() << contactRequest.toString(); + QString addr = contactRequest.getReceiverAddress(); + QString hmemo= createHeaderMemo(type,cid,myAddr); - QString memo = ui->memoTxtChat->toPlainText().trimmed(); + QString memo = contactRequest.getMemo(); // ui->memoSizeChat->setLenDisplayLabel();// Todo -> activate lendisplay for chat tx.toAddrs.push_back(ToFields{addr, amt, hmemo}); tx.toAddrs.push_back(ToFields{addr, amt, memo}); qDebug() << "pushback chattx"; tx.fee = Settings::getMinerFee(); - } - } + +} return tx; qDebug() << "RequestTx created"; @@ -563,7 +633,7 @@ Tx MainWindow::createTxForSafeContactRequest() void MainWindow::ContactRequest() { - /* if (request.labelRequest->text().trimmed().isEmpty() || request.memorequest->toPlainText().trimmed().isEmpty()) { + if (contactRequest.getReceiverAddress().isEmpty() || contactRequest.getMemo().isEmpty()) { // auto addr = ""; // if (! Settings::isZAddress(AddressBook::addressFromAddressLabel(addr->text()))) { @@ -573,7 +643,7 @@ void MainWindow::ContactRequest() { msg.exec(); return; - }*/ + } Tx tx = createTxForSafeContactRequest(); diff --git a/src/contactrequest.ui b/src/contactrequest.ui index e099111..5f4d6ec 100644 --- a/src/contactrequest.ui +++ b/src/contactrequest.ui @@ -14,21 +14,21 @@ Send a contact request - + <html><head/><body><p align="right">Choose a avatar for your contact :</p></body></html> - + <html><head/><body><p>Please insert a Nickname for your contact :</p></body></html> - + @@ -162,44 +162,54 @@ - + - + <html><head/><body><p>Please insert the Address of your contact :</p></body></html> - + - + + + + Insert a memo for the request + + + + Your HushChat Address - + + + + - + The Conversation ID - + - + @@ -215,7 +225,36 @@ + + + + Qt::Horizontal + + + + 278 + 20 + + + + + + + + 100 + 0 + + + + Only add this contact + + + false + + + + @@ -224,7 +263,7 @@ - Add Contact + Add Contact & send request false diff --git a/src/mainwindow.h b/src/mainwindow.h index 4419fcb..445e3f6 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -56,6 +56,8 @@ public: bool isWebsocketListening(); void createWebsocket(QString wormholecode); void stopWebsocket(); + void saveContact(); + void saveandsendContact(); void balancesReady(); From ee672cfcca1e6a091b62219e3a4603aa80d3c100 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Thu, 21 May 2020 17:41:12 +0200 Subject: [PATCH 2/6] contact gui fix --- src/chatmodel.cpp | 11 +- src/contactrequest.ui | 148 +++++++++++++++++++---- src/mainwindow.ui | 227 +----------------------------------- src/requestContactDialog.ui | 144 ++++++++++++----------- 4 files changed, 205 insertions(+), 325 deletions(-) diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 42a2419..29ba9c9 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -127,7 +127,6 @@ void MainWindow::renderContactRequest(){ requestContact.requestZaddr->setText(c.second.getRequestZaddr()); - requestContact.requestCID->setText(c.second.getCid()); requestContact.requestMyAddr->setText(c.second.getAddress()); }else{} } @@ -152,9 +151,8 @@ void MainWindow::renderContactRequest(){ requestContact.requestMemo->setModel(contactMemo); requestContact.requestMemo->show(); - - requestContact.requestZaddr->setText(c.second.getRequestZaddr()); requestContact.requestCID->setText(c.second.getCid()); + requestContact.requestZaddr->setText(c.second.getRequestZaddr()); requestContact.requestMyAddr->setText(c.second.getAddress()); }else{} } @@ -468,14 +466,15 @@ void::MainWindow::addContact() bool sapling = true; rpc->createNewZaddr(sapling, [=] (json reply) { QString myAddr = QString::fromStdString(reply.get()[0]); + rpc->refreshAddresses(); request.myzaddr->setText(myAddr); ui->listReceiveAddresses->insertItem(0, myAddr); ui->listReceiveAddresses->setCurrentIndex(0); - qDebug() << "new generated myAddr" << myAddr; + qDebug() << "new generated myAddr add Contact" << myAddr; }); QString cid = QUuid::createUuid().toString(QUuid::WithoutBraces); - request.cid->setText(cid); + @@ -483,7 +482,7 @@ void::MainWindow::addContact() QString addr = request.zaddr->text(); QString myAddr = request.myzaddr->text().trimmed(); - QString memo = request.memorequest->toPlainText().trimmed(); + QString memo = request.memorequest->text().trimmed(); QString avatar = QString(":/icons/res/") + request.comboBoxAvatar->currentText() + QString(".png"); QString label = request.labelRequest->text().trimmed(); diff --git a/src/contactrequest.ui b/src/contactrequest.ui index 5f4d6ec..8667057 100644 --- a/src/contactrequest.ui +++ b/src/contactrequest.ui @@ -10,25 +10,31 @@ 427 + + + 780 + 427 + + Send a contact request - + - <html><head/><body><p align="right">Choose a avatar for your contact :</p></body></html> + <html><head/><body><p align="right"><span style=" font-weight:600; text-decoration: underline;">Choose a avatar for your contact :</span></p></body></html> - <html><head/><body><p>Please insert a Nickname for your contact :</p></body></html> + <html><head/><body><p><span style=" font-weight:600; text-decoration: underline;">Please insert a Nickname for your contact :</span></p></body></html> - + @@ -168,49 +174,120 @@ - <html><head/><body><p>Please insert the Address of your contact :</p></body></html> + <html><head/><body><p><span style=" font-weight:600; text-decoration: underline;">Please insert the Address of your contact :</span></p></body></html> - - - - - - - Insert a memo for the request + + + + + 650 + 25 + + + + + 650 + 25 + - Your HushChat Address + <html><head/><body><p><span style=" font-weight:600; text-decoration: underline;">Your HushChat Address :</span></p></body></html> - - + + + + + 650 + 25 + + + + + 650 + 25 + + + + <html><head/><body><p><span style=" color:#d3d7cf;">Generate your HushChat Address - please wait a second - </span></p></body></html> + + - - + + + + Qt::Vertical + + + + 20 + 148 + + + - - + + - The Conversation ID + <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Insert a memo for your request</span></p></body></html> - - - - + + + + + 500 + 71 + + + + + 500 + 71 + + + + Qt::NoContextMenu + + + false + + + Qt::ImhSensitiveData + + + 512 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + false + + + Add some memo to your request + + + true + + + 80 + 25 + + 100 @@ -220,6 +297,9 @@ Cancel + + false + false @@ -240,6 +320,12 @@ + + + 152 + 25 + + 100 @@ -249,13 +335,22 @@ Only add this contact + + false + false - + + + + 188 + 25 + + 100 @@ -265,6 +360,9 @@ Add Contact & send request + + false + false diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 82b4260..1ce2a50 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1569,7 +1569,7 @@ - 50 + 0 20 61 51 @@ -1607,7 +1607,7 @@ - 210 + 70 20 61 51 @@ -1633,229 +1633,6 @@ true - - - - 90 - 10 - 21 - 16 - - - - - - - - - 204 - 0 - 0 - - - - - - - 204 - 0 - 0 - - - - - - - 239 - 41 - 41 - - - - - - - 204 - 0 - 0 - - - - - - - 204 - 0 - 0 - - - - - - - 204 - 0 - 0 - - - - - - - 204 - 0 - 0 - - - - - - - - - 204 - 0 - 0 - - - - - - - 204 - 0 - 0 - - - - - - - 239 - 41 - 41 - - - - - - - 204 - 0 - 0 - - - - - - - 204 - 0 - 0 - - - - - - - 204 - 0 - 0 - - - - - - - 204 - 0 - 0 - - - - - - - - - 190 - 190 - 190 - - - - - - - 190 - 190 - 190 - - - - - - - 239 - 41 - 41 - - - - - - - 190 - 190 - 190 - - - - - - - 204 - 0 - 0 - - - - - - - 204 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - - - 12 - - - - Qt::LeftToRight - - - 1 - - - Qt::AutoText - - diff --git a/src/requestContactDialog.ui b/src/requestContactDialog.ui index d2a3b68..7e676e7 100644 --- a/src/requestContactDialog.ui +++ b/src/requestContactDialog.ui @@ -14,10 +14,26 @@ Incoming contact request - - + + - <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Open requests</span></p></body></html> + My Zaddr : + + + + + + + true + + + QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked + + + false + + + QAbstractItemView::SingleSelection @@ -44,6 +60,16 @@ + + + + + + + Give a Nickname: + + + @@ -72,13 +98,6 @@ - - - - <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Recently closed requests</span></p></body></html> - - - @@ -86,66 +105,10 @@ - - - - true - - - QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked - - - false - - - QAbstractItemView::SingleSelection - - - - - - - Request from : - - - - - - - - - - Cid : - - - - - - - - - - My Zaddr : - - - - - - - - - - Nickname - - - - - - - - + + - <html><head/><body><p align="right">Choose a avatar for your contact :</p></body></html> + <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Open requests</span></p></body></html> @@ -283,6 +246,19 @@ + + + + <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Recently closed requests</span></p></body></html> + + + + + + + + + @@ -294,6 +270,9 @@ Cancel + + false + false @@ -304,6 +283,33 @@ Add this new Contact + + false + + + + + + + Request from : + + + + + + + <html><head/><body><p align="right">Choose a avatar for your contact :</p></body></html> + + + + + + + + + + Cid : + From 7e0748dd24dd0ae9253b1891e243c79abb9dab10 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Thu, 21 May 2020 20:31:54 +0200 Subject: [PATCH 3/6] set maxLen for Chatmessages --- src/Chat/Chat.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- src/Chat/Chat.h | 2 +- src/chatmodel.cpp | 4 ++-- src/controller.cpp | 6 +++--- src/controller.h | 2 +- src/mainwindow.cpp | 39 ++++++--------------------------------- src/mainwindow.h | 17 +++++++++++------ src/mainwindow.ui | 23 ++++++++++++++++++++++- 8 files changed, 88 insertions(+), 48 deletions(-) diff --git a/src/Chat/Chat.cpp b/src/Chat/Chat.cpp index c7d6637..d6c8445 100644 --- a/src/Chat/Chat.cpp +++ b/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); diff --git a/src/Chat/Chat.h b/src/Chat/Chat.h index 526aa36..efe5b56 100644 --- a/src/Chat/Chat.h +++ b/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(); diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 29ba9c9..349f8be 100644 --- a/src/chatmodel.cpp +++ b/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////////// diff --git a/src/controller.cpp b/src/controller.cpp index db895a1..8c3b603 100644 --- a/src/controller.cpp +++ b/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); } diff --git a/src/controller.h b/src/controller.h index cfd3bbb..b34aeb4 100644 --- a/src/controller.h +++ b/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); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e895947..4f0f08f 100644 --- a/src/mainwindow.cpp +++ b/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); + } diff --git a/src/mainwindow.h b/src/mainwindow.h index 445e3f6..85f4feb 100644 --- a/src/mainwindow.h +++ b/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 diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 1ce2a50..399e3e9 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1400,7 +1400,7 @@ <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Contactlist</span></p></body></html> - + 340 @@ -1633,6 +1633,22 @@ true + + + + 1160 + 540 + 91 + 17 + + + + 0 / 512 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + @@ -1819,6 +1835,11 @@ QLabel
fillediconlabel.h
+ + ChatMemoEdit + QTextEdit +
mainwindow.h
+
Address1 From 747580151ac4999280391232d466b4d73a384692 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Thu, 21 May 2020 21:32:45 +0200 Subject: [PATCH 4/6] change some gui elements --- src/Chat/Chat.cpp | 10 ++--- src/Chat/Helper/ChatDelegator.h | 2 +- src/DataStore/ChatDataStore.cpp | 1 + src/chatmodel.cpp | 4 +- src/controller.cpp | 2 +- src/mainwindow.cpp | 4 +- src/mainwindow.ui | 76 +++++++++++++++++++++++++++------ 7 files changed, 74 insertions(+), 25 deletions(-) diff --git a/src/Chat/Chat.cpp b/src/Chat/Chat.cpp index d6c8445..30a827d 100644 --- a/src/Chat/Chat.cpp +++ b/src/Chat/Chat.cpp @@ -50,9 +50,6 @@ 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); - // ui->lcdNumber->display("1"); DataStore::getChatDataStore()->dump(); // test to see if the chat items in datastore are correctly dumped to json for (auto &p : AddressBook::getInstance()->getAllAddressLabels()) { @@ -63,7 +60,7 @@ void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view, QLabel *label) if ( (p.getName() == ui->contactNameMemo->text().trimmed()) && (p.getPartnerAddress() == c.second.getAddress()) && - (c.second.isOutgoing() == true)) + (c.second.isOutgoing() == true)) { QStandardItem *Items = new QStandardItem(c.second.toChatLine()); @@ -81,8 +78,9 @@ void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view, QLabel *label) if ( (p.getName() == ui->contactNameMemo->text().trimmed()) && (p.getMyAddress() == c.second.getAddress()) && - (c.second.isOutgoing() == false)) - + (c.second.isOutgoing() == false) && + (c.second.getCid() == p.getCid()) + ) { QStandardItem *Items1 = new QStandardItem(c.second.toChatLine()); Items1->setData(INCOMING, Qt::UserRole + 1); diff --git a/src/Chat/Helper/ChatDelegator.h b/src/Chat/Helper/ChatDelegator.h index 6e3e676..10b45e5 100644 --- a/src/Chat/Helper/ChatDelegator.h +++ b/src/Chat/Helper/ChatDelegator.h @@ -37,7 +37,7 @@ class ListViewDelegate : public QAbstractItemDelegate inline QSize sizeHint(QStyleOptionViewItem const &option, QModelIndex const &index) const; }; -inline ListViewDelegate::ListViewDelegate(QObject *parent): QAbstractItemDelegate(parent), d_radius(5), d_toppadding(5), d_bottompadding(3), d_leftpadding(5), d_rightpadding(5), d_verticalmargin(5), d_horizontalmargin(10), d_pointerwidth(10), d_pointerheight(17), d_widthfraction(.6) +inline ListViewDelegate::ListViewDelegate(QObject *parent): QAbstractItemDelegate(parent), d_radius(5), d_toppadding(5), d_bottompadding(3), d_leftpadding(5), d_rightpadding(7), d_verticalmargin(5), d_horizontalmargin(10), d_pointerwidth(10), d_pointerheight(17), d_widthfraction(.7) { } diff --git a/src/DataStore/ChatDataStore.cpp b/src/DataStore/ChatDataStore.cpp index 1313103..21ddef9 100644 --- a/src/DataStore/ChatDataStore.cpp +++ b/src/DataStore/ChatDataStore.cpp @@ -96,6 +96,7 @@ std::map ChatDataStore::getAllMemos() (c.second.getMemo().startsWith("{") == false) && (c.second.getMemo().isEmpty() == false) + ) { diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 349f8be..28f7dfe 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -125,7 +125,7 @@ void MainWindow::renderContactRequest(){ requestContact.requestMemo->setModel(contactMemo); requestContact.requestMemo->show(); - + requestContact.requestCID->setText(c.second.getCid()); requestContact.requestZaddr->setText(c.second.getRequestZaddr()); requestContact.requestMyAddr->setText(c.second.getAddress()); }else{} @@ -617,7 +617,7 @@ Tx MainWindow::createTxForSafeContactRequest() QString hmemo= createHeaderMemo(type,cid,myAddr); QString memo = contactRequest.getMemo(); - // ui->memoSizeChat->setLenDisplayLabel();// Todo -> activate lendisplay for chat + tx.toAddrs.push_back(ToFields{addr, amt, hmemo}); tx.toAddrs.push_back(ToFields{addr, amt, memo}); diff --git a/src/controller.cpp b/src/controller.cpp index 8c3b603..d3c05fe 100644 --- a/src/controller.cpp +++ b/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,ui->memoSize); + chat->renderChatBox(ui, ui->listChat,ui->memoSizeChat); // refreshContacts( // ui->listContactWidget diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4f0f08f..0e231f4 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1080,14 +1080,14 @@ void MainWindow::setupchatTab() { }); -ui->memoTxtChat->setLenDisplayLabel(ui->memoSize);// Todo -> activate lendisplay for chat +ui->memoTxtChat->setLenDisplayLabel(ui->memoSizeChat); } void MainWindow::updateChat() { - rpc->refreshChat(ui->listChat,ui->memoSize); + rpc->refreshChat(ui->listChat,ui->memoSizeChat); rpc->refresh(true); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 399e3e9..2d85bd5 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1506,16 +1506,16 @@ - Qt::ScrollBarAlwaysOff + Qt::ScrollBarAsNeeded - Qt::ScrollBarAlwaysOff + Qt::ScrollBarAsNeeded QAbstractScrollArea::AdjustToContents - QAbstractItemView::NoEditTriggers + QAbstractItemView::AllEditTriggers QListView::Adjust @@ -1533,12 +1533,24 @@ - 270 - 580 + 10 + 20 51 51 + + + 51 + 51 + + + + + 51 + 51 + + 100 @@ -1569,12 +1581,24 @@ - 0 + 80 20 - 61 + 51 51 + + + 51 + 51 + + + + + 51 + 51 + + 100 @@ -1607,12 +1631,24 @@ - 70 + 150 20 - 61 + 51 51 + + + 51 + 51 + + + + + 51 + 51 + + Get a new Address @@ -1633,15 +1669,18 @@ true - + - 1160 - 540 + 1140 + 640 91 17 + + QFrame::Sunken + 0 / 512 @@ -1649,6 +1688,17 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + listContactWidget + label_39 + contactNameMemo + contactNameMemo_3 + safeContactRequest + pushContact + givemeZaddr + memoSizeChat + listChat + memoTxtChat + sendChatButton
@@ -1838,7 +1888,7 @@ ChatMemoEdit QTextEdit -
mainwindow.h
+
mainwindow.h
From 1a36a7f3c404373dd63c44ff5d6377e9c5bb7918 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Thu, 21 May 2020 21:44:21 +0200 Subject: [PATCH 5/6] try catch myZaddr --- src/addressbook.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/addressbook.cpp b/src/addressbook.cpp index b557dd9..f51e279 100644 --- a/src/addressbook.cpp +++ b/src/addressbook.cpp @@ -144,22 +144,35 @@ void AddressBook::open(MainWindow* parent, QLineEdit* target) // Connect the dialog's closing to updating the label address completor QObject::connect(&d, &QDialog::finished, [=] (auto) { parent->updateLabels(); }); + Controller* rpc = parent->getRPC(); bool sapling = true; + try + { rpc->createNewZaddr(sapling, [=] (json reply) { QString myAddr = QString::fromStdString(reply.get()[0]); QString message = QString("New Chat Address for your partner: ") + myAddr; QString cid = QUuid::createUuid().toString(QUuid::WithoutBraces); + + rpc->refreshAddresses(); parent->ui->listReceiveAddresses->insertItem(0, myAddr); parent->ui->listReceiveAddresses->setCurrentIndex(0); - qDebug() << "new generated myAddr" << myAddr; + qDebug() << " new Addr in Addressbook" << myAddr; ab.cid->setText(cid); ab.addr_chat->setText(myAddr); }); - model.updateUi(); //todo fix updating gui after adding - //rpc->refresh(true); + } + + catch(...) + { + + + qDebug() << QString("Caught something nasty with myZaddr Addressbook"); + } + + // model.updateUi(); //todo fix updating gui after adding // If there is a target then make it the addr for the "Add to" button if (target != nullptr && Settings::isValidAddress(target->text())) From eae77fb8aa8087f0fec0f4d0b8420373302b5d0c Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Thu, 21 May 2020 22:19:31 +0200 Subject: [PATCH 6/6] fix windows icons --- application.qrc | 5 +- src/Model/ChatItem.cpp | 4 +- src/chatmodel.cpp | 2 + src/requestContactDialog.ui | 213 ++++++++++++++++++++++++------------ 4 files changed, 148 insertions(+), 76 deletions(-) diff --git a/application.qrc b/application.qrc index 7ab9af5..bf9a3b9 100644 --- a/application.qrc +++ b/application.qrc @@ -38,9 +38,8 @@ res/message-icon.svg res/lock.svg res/lock.png - res/lock_green.svg - res/lock_blue.svg - res/unlocked.svg + res/lock_green.png + res/unlocked.png res/getAddrWhite.png res/send-white.png res/requestWhite.png diff --git a/src/Model/ChatItem.cpp b/src/Model/ChatItem.cpp index 540c7ba..fff8f9a 100644 --- a/src/Model/ChatItem.cpp +++ b/src/Model/ChatItem.cpp @@ -137,10 +137,10 @@ QString ChatItem::toChatLine() myDateTime.setTime_t(_timestamp); if (_confirmations == 0){ - lock = " "; + lock = " "; }else{ - lock = " "; + lock = " "; } diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 28f7dfe..d3abd34 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -126,6 +126,7 @@ void MainWindow::renderContactRequest(){ requestContact.requestMemo->show(); requestContact.requestCID->setText(c.second.getCid()); + requestContact.requestCID->setVisible(false); requestContact.requestZaddr->setText(c.second.getRequestZaddr()); requestContact.requestMyAddr->setText(c.second.getAddress()); }else{} @@ -152,6 +153,7 @@ void MainWindow::renderContactRequest(){ requestContact.requestMemo->show(); requestContact.requestCID->setText(c.second.getCid()); + requestContact.requestCID->setVisible(false); requestContact.requestZaddr->setText(c.second.getRequestZaddr()); requestContact.requestMyAddr->setText(c.second.getAddress()); }else{} diff --git a/src/requestContactDialog.ui b/src/requestContactDialog.ui index 7e676e7..2eb4bc0 100644 --- a/src/requestContactDialog.ui +++ b/src/requestContactDialog.ui @@ -6,38 +6,28 @@ 0 0 - 1025 - 562 + 812 + 495 + + + 812 + 495 + + Incoming contact request - - + + - My Zaddr : - - - - - - - true - - - QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked - - - false - - - QAbstractItemView::SingleSelection + <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Open requests</span></p></body></html> - + <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Memo of the request</span></p></body></html> @@ -46,6 +36,12 @@ + + + 256 + 231 + + true @@ -60,18 +56,14 @@ - - - - - - - Give a Nickname: - - - - + + + + 521 + 231 + + Qt::ScrollBarAlwaysOff @@ -98,22 +90,112 @@ - - + + - <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Details of the request</span></p></body></html> + <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Recently closed requests</span></p></body></html> - - + + + + + 256 + 192 + + + + true + + + QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked + + + false + + + QAbstractItemView::SingleSelection + + + + + - <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Open requests</span></p></body></html> + Request from : - + + + + + 351 + 25 + + + + + 351 + 25 + + + + + + + + My Zaddr : + + + + + + + + 351 + 25 + + + + + 351 + 25 + + + + + + + + Give a Nickname: + + + + + + + + + + <html><head/><body><p align="right">Choose a avatar for your contact :</p></body></html> + + + + + + + 106 + 25 + + + + + 106 + 25 + + Stag @@ -246,21 +328,14 @@ - - - - <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Recently closed requests</span></p></body></html> - - - - - - - - - - + + + + 80 + 25 + + 100 @@ -278,8 +353,14 @@ - + + + + 153 + 25 + + Add this new Contact @@ -288,27 +369,17 @@ - - - - Request from : - - - - - + + - <html><head/><body><p align="right">Choose a avatar for your contact :</p></body></html> + - - - - - + + - Cid : + <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Details of the request</span></p></body></html>