Browse Source

add contextmenu for chatitems #78

pull/130/head
DenioD 4 years ago
parent
commit
cae2c12b56
  1. 19
      src/chatmodel.cpp
  2. 113
      src/mainwindow.cpp
  3. 9
      src/mainwindow.ui

19
src/chatmodel.cpp

@ -115,9 +115,11 @@ void MainWindow::renderContactRequest(){
QStandardItemModel* contactRequest = new QStandardItemModel();
for (auto &c : DataStore::getChatDataStore()->getAllNewContactRequests())
for (auto &c : DataStore::getChatDataStore()->getAllNewContactRequests())
{
@ -134,6 +136,7 @@ void MainWindow::renderContactRequest(){
}
QStandardItemModel* contactRequestOld = new QStandardItemModel();
for (auto &p : AddressBook::getInstance()->getAllAddressLabels())
@ -157,13 +160,16 @@ void MainWindow::renderContactRequest(){
QModelIndex index = requestContact.requestContact->currentIndex();
QString label_contact = index.data(Qt::DisplayRole).toString();
QStandardItemModel* contactMemo = new QStandardItemModel();
if ((c.second.isOutgoing() == false) && (requestContact.zaddrnew->text() == c.second.getAddress()) && (c.second.getType() != "Cont"))
{
QStandardItem* Items = new QStandardItem(c.second.getMemo());
contactMemo->appendRow(Items);
contactMemo->appendRow(Items);
requestContact.requestMemo->setModel(contactMemo);
requestContact.requestMemo->show();
@ -172,17 +178,18 @@ void MainWindow::renderContactRequest(){
requestContact.requestZaddr->setText(c.second.getRequestZaddr());
requestContact.requestMyAddr->setText(c.second.getAddress());
}else{}
}
}
});
QObject::connect(requestContact.requestContactOld, &QTableView::clicked, [&] () {
for (auto &c : DataStore::getChatDataStore()->getAllRawChatItems()){
/* QModelIndex index = requestContact.requestContactOld->currentIndex();
QString label_contactold = index.data(Qt::DisplayRole).toString();*/
QModelIndex index = requestContact.requestContactOld->currentIndex();
QString label_contactold = index.data(Qt::DisplayRole).toString();
QStandardItemModel* contactMemo = new QStandardItemModel();
if ((c.second.isOutgoing() == false) && (requestContact.zaddrold->text() == c.second.getAddress()) && (c.second.getType() != "Cont"))

113
src/mainwindow.cpp

@ -30,6 +30,7 @@
#include "FileSystem/FileSystem.h"
#include "Crypto/passwd.h"
#include "Crypto/FileEncryption.h"
#include "DataStore/DataStore.h"
using json = nlohmann::json;
@ -1362,6 +1363,118 @@ void MainWindow::setupchatTab() {
ui->contactNameMemo->setText("");
/////Copy Chatmessages
QMenu* contextMenuChat;
QAction* copymessage;
QAction* viewexplorer;
QAction* copytxid;
contextMenuChat = new QMenu(ui->listChat);
copymessage = new QAction("Copy message to clipboard",contextMenuChat);
viewexplorer = new QAction("View on block explorerr",contextMenuChat);
copytxid = new QAction("Copy txid to clipboard ",contextMenuChat);
QObject::connect(ui->listContactWidget, &QTableView::clicked, [=] () {
ui->listChat->setContextMenuPolicy(Qt::ActionsContextMenu);
ui->listChat->addAction(copymessage);
ui->listChat->addAction(viewexplorer);
ui->listChat->addAction(copytxid);
QObject::connect(copymessage, &QAction::triggered, [=] {
QModelIndex index = ui->listChat->currentIndex();
QString memo_chat = index.data(Qt::DisplayRole).toString();
QClipboard *clipboard = QGuiApplication::clipboard();
int startPos = memo_chat.indexOf("<p>") + 3;
int endPos = memo_chat.indexOf("</p>");
int length = endPos - startPos;
QString copymemo = memo_chat.mid(startPos, length);
clipboard->setText(copymemo);
ui->statusBar->showMessage(tr("Copied message to clipboard"), 3 * 1000);
});
QObject::connect(copytxid, &QAction::triggered, [=] {
QModelIndex index = ui->listChat->currentIndex();
QString memo_chat = index.data(Qt::DisplayRole).toString();
QClipboard *clipboard = QGuiApplication::clipboard();
int startPos = memo_chat.indexOf("<p>") + 3;
int endPos = memo_chat.indexOf("</p>");
int length = endPos - startPos;
QString copymemo = memo_chat.mid(startPos, length);
int startPosT = memo_chat.indexOf("<small>") + 7;
int endPosT = memo_chat.indexOf("<b>");
int lengthT = endPosT - startPosT;
QString time = memo_chat.mid(startPosT, lengthT);
for (auto &c : DataStore::getChatDataStore()->getAllRawChatItems()){
if (c.second.getMemo() == copymemo)
{
int timestamp = c.second.getTimestamp();
QDateTime myDateTime;
QString lock;
myDateTime.setTime_t(timestamp);
QString timestamphtml = myDateTime.toString("yyyy-MM-dd hh:mm");
if(timestamphtml == time)
{
clipboard->setText(c.second.getTxid());
ui->statusBar->showMessage(tr("Copied Txid to clipboard"), 3 * 1000);
}else{}
}
}
});
QObject::connect(viewexplorer, &QAction::triggered, [=] {
QModelIndex index = ui->listChat->currentIndex();
QString memo_chat = index.data(Qt::DisplayRole).toString();
int startPos = memo_chat.indexOf("<p>") + 3;
int endPos = memo_chat.indexOf("</p>");
int length = endPos - startPos;
QString copymemo = memo_chat.mid(startPos, length);
int startPosT = memo_chat.indexOf("<small>") + 7;
int endPosT = memo_chat.indexOf("<b>");
int lengthT = endPosT - startPosT;
QString time = memo_chat.mid(startPosT, lengthT);
for (auto &c : DataStore::getChatDataStore()->getAllRawChatItems()){
if (c.second.getMemo() == copymemo)
{
int timestamp = c.second.getTimestamp();
QDateTime myDateTime;
QString lock;
myDateTime.setTime_t(timestamp);
QString timestamphtml = myDateTime.toString("yyyy-MM-dd hh:mm");
if(timestamphtml == time)
{
Settings::openTxInExplorer(c.second.getTxid());
}else{}
}
}
});
});
///////// Add contextmenu
QMenu* contextMenu;
QAction* requestAction;

9
src/mainwindow.ui

@ -1602,6 +1602,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>The locks shows you the status of the message. Red lock = unconfirmed, green lock = min. 1 confirmations, orange lock = message is notarized</string>
</property>
@ -1638,9 +1641,15 @@
<property name="movement">
<enum>QListView::Snap</enum>
</property>
<property name="flow">
<enum>QListView::TopToBottom</enum>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="layoutMode">
<enum>QListView::SinglePass</enum>
</property>
<property name="modelColumn">
<number>0</number>
</property>

Loading…
Cancel
Save