summaryrefslogtreecommitdiffstats
path: root/pica-client/chatwindow.h
blob: fa306a9d9568563a8cc379380454906024150d8b (plain) (blame)
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
/*
	(c) Copyright  2012 - 2018 Anton Sviridenko
	https://picapica.im

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef CHATWINDOW_H
#define CHATWINDOW_H

#include <QWidget>
#include <QTextEdit>
#include <QList>
#include <QMenuBar>
#include <QAction>
#include <QMenu>
#include <QPushButton>
#include <QLabel>
#include "history.h"

class TextSend : public QTextEdit
{
	Q_OBJECT
public:
	explicit TextSend(QWidget *parent);
signals:
	void send_pressed();
private:
	void keyPressEvent(QKeyEvent *e);

};

class ChatWindow : public QWidget
{
	Q_OBJECT
public:
	explicit ChatWindow(QByteArray peer_id, QString status);

	QByteArray getPeerId()
	{
		return peer_id_;
	};

signals:
	void msg_input(QString msg, ChatWindow *sender_window);
	void chatwindow_close(ChatWindow *sender_window);
	void contacts_update();

public slots:
	void msg_from_peer(QString msg);
	void msg_delivered();
	void msg_informational(QString text);//юзер в оффлайне, набирает сообщение, и т.д. серым шрифтом, курсив
	void set_peer_name();
	void update_status(QString status);


private:
	QTextEdit *chatw;
	TextSend *sendtextw;
	QByteArray peer_id_;
	QList<int> undelivered_msgs;
	History hist;
	QMenuBar *menu;
	QAction *hist24h;
	QAction *hist1week;
	QAction *histAll;
	QString peer_name_;
	QString my_name_;
	bool addcontactquestion;
	QPushButton *btAddCtYes;
	QPushButton *btAddCtNo;
	QPushButton *btAddCtBlacklist;
	QLabel *lbAddCtQuestion;
	QLabel *lbConnStatus;

	bool isEmptyMessage(const QString &msg) const;
	void put_message(QString msg, QByteArray id, bool is_me);
	int draw_message(QString msg, QString nickname, QString datetime, QString color, bool is_delivered);
	void print_history(QList<History::HistoryRecord> H);

	void closeEvent(QCloseEvent *e);

private slots:
	void send_message();

	void show_history24h();
	void show_history1w();
	void show_historyAll();

	void addct_yes();
	void addct_no();
	void addct_blacklist();
	void addct_removequestion();
};

#endif // CHATWINDOW_H