summaryrefslogtreecommitdiffstats
path: root/src/server/connectionframe/connectionframe.h
blob: 898d97a7f87b51246e168a5aeb6ab523e75c0c86 (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
#ifndef _CONNECTIONFRAME_H_
#define _CONNECTIONFRAME_H_
#include <QtWidgets>
#include "../net/client.h"

class MainWindow;

/**
 * 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;

	static const int _startDragDistance = 40;

	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);
	virtual ~ConnectionFrame();

	const inline 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);
	inline bool isSelected() { return _isSelected; }

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

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

protected:
	void resizeEvent(QResizeEvent* event) { calcDesiredThumbSize(event->size()); }
	void mouseDoubleClickEvent(QMouseEvent* event);
	void mouseReleaseEvent(QMouseEvent* e);
	void enterEvent(QEvent* event);
	void leaveEvent(QEvent* event);
	void mousePressEvent(QMouseEvent* event);
	void mouseMoveEvent(QMouseEvent* event);
	void paintEvent(QPaintEvent *event);
	void timerEvent(QTimerEvent* event);

signals:
	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