improve some gui elements
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
// Copyright 2019-2020 The Hush developers
|
||||
// GPLv3
|
||||
|
||||
#include "Chat.h"
|
||||
#include "../addressbook.h"
|
||||
#include "../DataStore/DataStore.h"
|
||||
@@ -23,9 +26,11 @@ void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view)
|
||||
{
|
||||
|
||||
QStandardItem *Items = new QStandardItem(c.second.toChatLine());
|
||||
Items->setData("Outgoing", Qt::UserRole + 1);
|
||||
|
||||
Items->setData(OUTGOING, Qt::UserRole + 1);
|
||||
chat->appendRow(Items);
|
||||
ui->listChat->setModel(chat);
|
||||
ui->listChat->setModel(chat);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -39,7 +44,7 @@ void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view)
|
||||
|
||||
{
|
||||
QStandardItem *Items1 = new QStandardItem(c.second.toChatLine());
|
||||
Items1->setData("Incoming", Qt::UserRole + 1);
|
||||
Items1->setData(INCOMING, Qt::UserRole + 1);
|
||||
chat->appendRow(Items1);
|
||||
ui->listChat->setModel(chat);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// Copyright 2019-2020 The Hush developers
|
||||
// GPLv3
|
||||
|
||||
#ifndef CHATDELEGATOR_H
|
||||
#define CHATDELEGATOR_H
|
||||
|
||||
@@ -6,6 +9,14 @@
|
||||
#include <QAbstractItemDelegate>
|
||||
#include <QPainter>
|
||||
|
||||
enum RenderType
|
||||
{
|
||||
OUTGOING=0,
|
||||
INCOMING=1,
|
||||
INDATE=2,
|
||||
OUTDATE=3
|
||||
};
|
||||
|
||||
class ListViewDelegate : public QAbstractItemDelegate
|
||||
{
|
||||
int d_radius;
|
||||
@@ -26,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(15), d_horizontalmargin(10), d_pointerwidth(10), d_pointerheight(17), d_widthfraction(.7)
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -43,7 +54,9 @@ inline void ListViewDelegate::paint(QPainter *painter, QStyleOptionViewItem cons
|
||||
qreal contentswidth = option.rect.width() * d_widthfraction - d_horizontalmargin - d_pointerwidth - d_leftpadding - d_rightpadding;
|
||||
bodydoc.setTextWidth(contentswidth);
|
||||
qreal bodyheight = bodydoc.size().height();
|
||||
bool outgoing = index.data(Qt::UserRole + 1).toString() == "Outgoing";
|
||||
int outgoing = index.data(Qt::UserRole + 1).toInt();
|
||||
int outdate = index.data(Qt::UserRole + 1).toInt();
|
||||
int indate = index.data(Qt::UserRole + 1).toInt();
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
@@ -53,10 +66,26 @@ inline void ListViewDelegate::paint(QPainter *painter, QStyleOptionViewItem cons
|
||||
|
||||
painter->translate(option.rect.left() + d_horizontalmargin, option.rect.top() + ((index.row() == 0) ? d_verticalmargin : 0));
|
||||
|
||||
// background color for chat bubble
|
||||
QColor bgcolor("#535353");
|
||||
if (outgoing)
|
||||
bgcolor = "#eeeeee";
|
||||
QColor bgcolor("#ffffff");
|
||||
switch(outgoing)
|
||||
{
|
||||
case INDATE:
|
||||
bgcolor = "transparent";
|
||||
break;
|
||||
|
||||
case OUTDATE:
|
||||
bgcolor = "transparent";
|
||||
break;
|
||||
|
||||
case OUTGOING:
|
||||
bgcolor = "#f8f9fa";
|
||||
break;
|
||||
|
||||
default:
|
||||
case INCOMING:
|
||||
bgcolor = "#535353";
|
||||
break;
|
||||
}
|
||||
|
||||
// create chat bubble
|
||||
QPainterPath pointie;
|
||||
@@ -85,7 +114,7 @@ inline void ListViewDelegate::paint(QPainter *painter, QStyleOptionViewItem cons
|
||||
pointie.closeSubpath();
|
||||
|
||||
// rotate bubble for outgoing messages
|
||||
if (outgoing)
|
||||
if ((outgoing == OUTGOING) || (outdate == OUTDATE))
|
||||
{
|
||||
painter->translate(option.rect.width() - pointie.boundingRect().width() - d_horizontalmargin - d_pointerwidth, 0);
|
||||
painter->translate(pointie.boundingRect().center());
|
||||
@@ -99,7 +128,7 @@ inline void ListViewDelegate::paint(QPainter *painter, QStyleOptionViewItem cons
|
||||
painter->fillPath(pointie, QBrush(bgcolor));
|
||||
|
||||
// rotate back or painter is going to paint the text rotated...
|
||||
if (outgoing)
|
||||
if ((outgoing == OUTGOING) || (outdate == OUTDATE))
|
||||
{
|
||||
painter->translate(pointie.boundingRect().center());
|
||||
painter->rotate(-180);
|
||||
@@ -108,13 +137,30 @@ inline void ListViewDelegate::paint(QPainter *painter, QStyleOptionViewItem cons
|
||||
|
||||
// set text color used to draw message body
|
||||
QAbstractTextDocumentLayout::PaintContext ctx;
|
||||
if (outgoing)
|
||||
ctx.palette.setColor(QPalette::Text, QColor("black"));
|
||||
else
|
||||
ctx.palette.setColor(QPalette::Text, QColor("white"));
|
||||
switch(outgoing)
|
||||
{
|
||||
case INDATE:
|
||||
ctx.palette.setColor(QPalette::Text, QColor("Black"));
|
||||
break;
|
||||
|
||||
case OUTDATE:
|
||||
ctx.palette.setColor(QPalette::Text, QColor("Black"));
|
||||
break;
|
||||
|
||||
case OUTGOING:
|
||||
ctx.palette.setColor(QPalette::Text, QColor("Black"));
|
||||
break;
|
||||
|
||||
default:
|
||||
case INCOMING:
|
||||
ctx.palette.setColor(QPalette::Text, QColor("whitesmoke"));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// draw body text
|
||||
painter->translate((outgoing ? 0 : d_pointerwidth) + d_leftpadding, 0);
|
||||
painter->translate((outgoing == OUTGOING ? 0 : d_pointerwidth) + d_leftpadding, 0);
|
||||
painter->translate((outdate == OUTDATE ? 0 : d_pointerwidth) + d_leftpadding, 0);
|
||||
bodydoc.documentLayout()->draw(painter, ctx);
|
||||
|
||||
painter->restore();
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// Copyright 2019-2020 The Hush developers
|
||||
// GPLv3
|
||||
|
||||
#include "ChatDataStore.h"
|
||||
|
||||
ChatDataStore* ChatDataStore::getInstance()
|
||||
@@ -43,8 +46,8 @@ std::map<QString, ChatItem> ChatDataStore::getAllContactRequests()
|
||||
for(auto &c: this->data)
|
||||
{
|
||||
if (
|
||||
(c.second.getType() == "cont") &&
|
||||
(c.second.isOutgoing() == false) &&
|
||||
(c.second.isOutgoing() == false) &&
|
||||
(c.second.getType() == "cont") &&
|
||||
(c.second.getMemo().startsWith("{"))
|
||||
)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
// Copyright 2019-2020 The Hush developers
|
||||
// GPLv3
|
||||
|
||||
#include "ChatItem.h"
|
||||
|
||||
ChatItem::ChatItem() {}
|
||||
|
||||
ChatItem::ChatItem(long timestamp, QString address, QString contact, QString memo, QString requestZaddr, QString type, QString cid, QString txid)
|
||||
ChatItem::ChatItem(long timestamp, QString address, QString contact, QString memo, QString requestZaddr, QString type, QString cid, QString txid, int confirmations)
|
||||
{
|
||||
_timestamp = timestamp;
|
||||
_address = address;
|
||||
@@ -12,10 +15,11 @@ ChatItem::ChatItem(long timestamp, QString address, QString contact, QString mem
|
||||
_type = type;
|
||||
_cid = cid;
|
||||
_txid = txid;
|
||||
_confirmations = confirmations;
|
||||
_outgoing = false;
|
||||
}
|
||||
|
||||
ChatItem::ChatItem(long timestamp, QString address, QString contact, QString memo, QString requestZaddr, QString type, QString cid, QString txid, bool outgoing)
|
||||
ChatItem::ChatItem(long timestamp, QString address, QString contact, QString memo, QString requestZaddr, QString type, QString cid, QString txid, int confirmations, bool outgoing)
|
||||
{
|
||||
_timestamp = timestamp;
|
||||
_address = address;
|
||||
@@ -25,6 +29,7 @@ ChatItem::ChatItem(long timestamp, QString address, QString contact, QString mem
|
||||
_type = type;
|
||||
_cid = cid;
|
||||
_txid = txid;
|
||||
_confirmations = confirmations;
|
||||
_outgoing = outgoing;
|
||||
}
|
||||
|
||||
@@ -66,6 +71,10 @@ QString ChatItem::getTxid()
|
||||
{
|
||||
return _txid;
|
||||
}
|
||||
int ChatItem::getConfirmations()
|
||||
{
|
||||
return _confirmations;
|
||||
}
|
||||
|
||||
bool ChatItem::isOutgoing()
|
||||
{
|
||||
@@ -110,26 +119,38 @@ void ChatItem::setTxid(QString txid)
|
||||
{
|
||||
_txid = txid;
|
||||
}
|
||||
void ChatItem::setConfirmations(int confirmations)
|
||||
{
|
||||
_confirmations = confirmations;
|
||||
}
|
||||
|
||||
void ChatItem::toggleOutgo()
|
||||
{
|
||||
_outgoing = true;
|
||||
}
|
||||
|
||||
|
||||
QString ChatItem::toChatLine()
|
||||
{
|
||||
QDateTime myDateTime;
|
||||
QString lock;
|
||||
myDateTime.setTime_t(_timestamp);
|
||||
QString line = QString("[") + myDateTime.toString("d.M.yy hh:mm") + QString("] ");
|
||||
line += QString("") + QString(_memo) + QString("\n\n");
|
||||
|
||||
if (_confirmations == 0){
|
||||
lock = "<b> <img src=':/icons/res/unlocked.svg'><b>";
|
||||
}else{
|
||||
|
||||
lock = "<b> <img src=':/icons/res/lock_green.svg'><b>";
|
||||
|
||||
}
|
||||
|
||||
QString line = QString("<small style='background: rgba(255,255,255,0.1);'>") + myDateTime.toString("dd.MM.yyyy hh:mm");
|
||||
line += QString(lock) + QString("</small>");
|
||||
line += QString("<p>") + _memo.toHtmlEscaped() + QString("</p>");
|
||||
return line;
|
||||
}
|
||||
|
||||
ChatItem::~ChatItem()
|
||||
{
|
||||
/*delete timestamp;
|
||||
delete address;
|
||||
delete contact;
|
||||
delete memo;
|
||||
delete outgoing;*/
|
||||
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
// Copyright 2019-2020 The Hush developers
|
||||
// GPLv3
|
||||
|
||||
#ifndef CHATITEM_H
|
||||
#define CHATITEM_H
|
||||
|
||||
@@ -14,12 +17,13 @@ class ChatItem
|
||||
QString _type;
|
||||
QString _cid;
|
||||
QString _txid;
|
||||
int _confirmations;
|
||||
bool _outgoing = false;
|
||||
|
||||
public:
|
||||
ChatItem();
|
||||
ChatItem(long timestamp, QString address, QString contact, QString memo,QString requestZaddr, QString type, QString cid, QString txid);
|
||||
ChatItem(long timestamp, QString address, QString contact, QString memo, QString requestZaddr, QString type, QString cid, QString txid, bool outgoing);
|
||||
ChatItem(long timestamp, QString address, QString contact, QString memo,QString requestZaddr, QString type, QString cid, QString txid, int confirmations);
|
||||
ChatItem(long timestamp, QString address, QString contact, QString memo, QString requestZaddr, QString type, QString cid, QString txid, int confirmations, bool outgoing);
|
||||
long getTimestamp();
|
||||
QString getAddress();
|
||||
QString getContact();
|
||||
@@ -28,6 +32,7 @@ class ChatItem
|
||||
QString getType();
|
||||
QString getCid();
|
||||
QString getTxid();
|
||||
int getConfirmations();
|
||||
bool isOutgoing();
|
||||
void setTimestamp(long timestamp);
|
||||
void setAddress(QString address);
|
||||
@@ -37,6 +42,7 @@ class ChatItem
|
||||
void setType(QString type);
|
||||
void setCid(QString cid);
|
||||
void setTxid(QString txid);
|
||||
void setConfirmations(int confirmations);
|
||||
void toggleOutgo();
|
||||
QString toChatLine();
|
||||
~ChatItem();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Copyright 2019-2020 The Hush developers
|
||||
// GPLv3
|
||||
|
||||
#include "addressbook.h"
|
||||
#include "ui_addressbook.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// Copyright 2019-2020 The Hush developers
|
||||
// GPLv3
|
||||
|
||||
#ifndef CHATMODEL_H
|
||||
#define CHATMODEL_H
|
||||
#include <QString>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Copyright 2019-2020 The Hush developers
|
||||
// GPLv3
|
||||
|
||||
#include "contactmodel.h"
|
||||
#include "addressbook.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
@@ -878,9 +878,11 @@ void Controller::refreshTransactions() {
|
||||
QString(""),
|
||||
cid,
|
||||
txid,
|
||||
confirmations,
|
||||
true
|
||||
);
|
||||
qDebug()<<"Memo : " <<memo;
|
||||
qDebug()<<"Confirmation :" << confirmations;
|
||||
|
||||
DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item);
|
||||
|
||||
@@ -973,9 +975,11 @@ void Controller::refreshTransactions() {
|
||||
type,
|
||||
cid,
|
||||
txid,
|
||||
confirmations,
|
||||
false
|
||||
);
|
||||
qDebug()<< "Position : " << position;
|
||||
qDebug()<<"Confirmation :" << confirmations;
|
||||
|
||||
DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Copyright 2019-2020 The Hush developers
|
||||
// GPLv3
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "addressbook.h"
|
||||
#include "viewalladdresses.h"
|
||||
|
||||
Reference in New Issue
Block a user