summaryrefslogblamecommitdiffstats
path: root/src/server/connectionframe/connectionframe.h
blob: 898d97a7f87b51246e168a5aeb6ab523e75c0c86 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11

                           
                    
                          
 

                 



                                                                               


                                        
                








                                
                             
 
                                             

                              
                             


                                 
                             
                                
 


                                    
                         
                      
                             
 

                                                 
                                
                                                          

                                           

                                
       


                                  
                                                                                      

                                   




                                                                             

                                          
                                                        

                                                                 
                                                                                                                         

                                                  
                                                  
                                                                
                              

          
                                                                                      









                                                       
                                                



                                                   
                                    
                                                                 
                                
                            


      
#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