forked from foldynl/QLog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKSTChatWidget.h
186 lines (156 loc) · 5.01 KB
/
KSTChatWidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#ifndef QLOG_UI_KSTCHATWIDGET_H
#define QLOG_UI_KSTCHATWIDGET_H
#include <QWidget>
#include <QPointer>
#include <QPainterPath>
#include <QAbstractTextDocumentLayout>
#include <QListView>
#include <QMainWindow>
#include <QPushButton>
#include <QStyledItemDelegate>
#include <QTextDocument>
#include <QTextOption>
#include <QVBoxLayout>
#include <QWidget>
#include <QMargins>
#include <QPainter>
#include "core/KSTChat.h"
#include "ui/NewContactWidget.h"
namespace Ui {
class KSTChatWidget;
}
class ChatMessageModel : public QAbstractListModel
{
public:
enum MessageDirection
{
OUTGOING = 0,
INCOMING = 1,
INCOMING_TOYOU = 2,
INCOMING_HIGHLIGHT = 3
};
public:
explicit ChatMessageModel(QObject* parent = nullptr) :
QAbstractListModel(parent) {}
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const override;
void addMessage(MessageDirection direction,
const KSTChatMsg &msg);
void clear();
KSTChatMsg getMessage(const QModelIndex &index) const;
private:
QList<QPair<int, KSTChatMsg>> messages;
};
class HTMLDelegate : public QStyledItemDelegate
{
public:
explicit HTMLDelegate(QObject* parent = nullptr) :
QStyledItemDelegate(parent){};
protected:
void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
};
class MessageDelegate : public QStyledItemDelegate
{
public:
explicit MessageDelegate(QObject* parent = nullptr) :
QStyledItemDelegate(parent),
d_radius(10),
d_toppadding(0),
d_bottompadding(0),
d_leftpadding(2),
d_rightpadding(2),
d_verticalmargin(2),
d_horizontalmargin(2),
d_pointerwidth(5),
d_pointerheight(5),
d_widthfraction(0.95) {}
void paint(QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const override;
QSize sizeHint(const QStyleOptionViewItem& option,
const QModelIndex& index) const override;
private:
int d_radius;
int d_toppadding;
int d_bottompadding;
int d_leftpadding;
int d_rightpadding;
int d_verticalmargin;
int d_horizontalmargin;
int d_pointerwidth;
int d_pointerheight;
float d_widthfraction;
};
class UserListModel : public QAbstractTableModel {
Q_OBJECT
public:
UserListModel(QObject* parent = 0) : QAbstractTableModel(parent) {}
int rowCount(const QModelIndex& parent = QModelIndex()) const;
int columnCount(const QModelIndex& parent = QModelIndex()) const;
QVariant data(const QModelIndex& index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
void updateList(const QList<KSTUsersInfo> &userList);
void clear();
KSTUsersInfo getUserInfo(const QModelIndex &index) const;
private:
QList<KSTUsersInfo> userData;
};
class KSTChatWidget : public QWidget
{
Q_OBJECT
public:
explicit KSTChatWidget(int chatRoomIndex,
const QString& username,
const QString& password,
const NewContactWidget *,
QWidget *parent = nullptr);
~KSTChatWidget();
QList<KSTUsersInfo> getUserList();
signals:
void chatClosed();
void chatUpdated(QWidget *);
void valuableMessageUpdated(QWidget *);
void prepareQSOInfo(QString, QString);
void userListUpdated(QWidget *);
void beamingRequested(double);
public slots:
void addChatMessage(KSTChatMsg);
void sendMessage();
void updateUserList();
void setPrivateChatCallsign(QString);
void reloadStationProfile();
void setBeamActionVisible(bool);
void resetDupe();
void recalculateDupe();
void recalculateDxccStatus();
void updateSpotsStatusWhenQSOAdded(const QSqlRecord &record);
void updateSpotsStatusWhenQSODeleted(const QSqlRecord &record);
void updateSpotsDxccStatusWhenQSODeleted(const QSet<uint> &entities);
private slots:
void showChatError(const QString &);
void closeChat();
void displayedColumns();
void userDoubleClicked(QModelIndex);
void messageDoubleClicked(QModelIndex);
void prefillQSOAction();
void highlightPressed();
bool isHighlightCandidate(KSTChatMsg &);
void editHighlightRules();
void resetPressed();
void beamingRequest();
void clearValuableMessages();
private:
Ui::KSTChatWidget *ui;
QPointer<ChatMessageModel> messageModel;
QPointer<ChatMessageModel> valuableMessageModel;
QPointer<KSTChat> chat;
UserListModel* userListModel;
QSortFilterProxyModel * proxyModel;
QPointer<chatHighlightEvaluator> highlightEvaluator;
QString userName;
void setSelectedCallsignInUserList(const QString &);
};
#endif // QLOG_UI_KSTCHATWIDGET_H