summaryrefslogtreecommitdiffstats
path: root/src/server/connectionframe/connectionframe.h
blob: cfebe85acacbd1a7c96b8a822aaf59d556674a6b (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
107
#ifndef PVS_CONNECTIONFRAME_H_
#define PVS_CONNECTIONFRAME_H_

#include <QGroupBox>
#include <utility>

class QBoxLayout;
class QLabel;

class MainWindow;
class Client;

/**
 * Class for representing the clients of current session, with a specific frame
 * displaying username and hostname for each one.
 */
class ConnectionFrame : public QGroupBox
{

	Q_OBJECT

private:

	QString _computerId;

	QBoxLayout *_mainLayout;
	QBoxLayout *_iconLayout;
	QLabel *_lblUserName;
	QLabel *_lblHostName;
	QLabel *_lblExamMode;

	QLabel *_icoCam, *_icoEye, *_icoLock;
	QList<QLabel*> _icons;

	QImage _remoteScreen;

	QPoint _clickPoint;
	QPoint _previousPosition;
	QPoint _gridPosition;
	QSize _desiredThumbSize;

	Client *_client{};

	int _timerId{}, _timerCounter{};
	bool _isSelected{};
	bool _isTutor{};
	bool _isFromRoomplan;

	void showDefaultThumb();
	void calcDesiredThumbSize(const QSize &frameSize);
	QLabel* addIcon(const QIcon* icon);

	MainWindow *_mainWindow;

public:

	static bool paintDisabled;

	ConnectionFrame(MainWindow* main, QWidget* parent, bool fromRoomplan = false);
	~ConnectionFrame() override;

	const QPoint& getGridPosition() const { return _gridPosition; }
	void setGridPosition(int x, int y);
	void setGridPosition(const QPoint& pos);
	void updateGeometry();

	void assignClient(Client *client);
	void setSelection(bool selected);
	bool isSelected() const { return _isSelected; }

	const QString& computerId() const { return _computerId; }
	void setComputerId(QString computerId) {
		if (_client != nullptr)
			return;
		_computerId = std::move(computerId); updateLabels();
	}
	Client* client() const { return _client; }

	bool isTutor() const { return _isTutor; }
	bool isFromRoomplan() const { return _isFromRoomplan; }
	void setTutor(bool b);

protected:
	void resizeEvent(QResizeEvent* event) override;
	void mouseDoubleClickEvent(QMouseEvent* event) override;
	void mouseReleaseEvent(QMouseEvent* e) override;
	void enterEvent(QEvent* event) override;
	void leaveEvent(QEvent* event) override;
	void mousePressEvent(QMouseEvent* event) override;
	void mouseMoveEvent(QMouseEvent* event) override;
	void paintEvent(QPaintEvent *event) override;
	void timerEvent(QTimerEvent* event) override;

signals:
	void frameMoving(ConnectionFrame* frame);
	void frameMoved(ConnectionFrame* frame);
	void doubleClicked(ConnectionFrame* frame);
	void clicked(ConnectionFrame* frame);

private slots:
	void onClientDisconnected();
	void onThumbUpdated(Client* client, const QImage& thumb);
	void updateAppearance();
	void updateLabels();
};

#endif