summaryrefslogtreecommitdiffstats
path: root/src/server/connectionframe
diff options
context:
space:
mode:
authorSimon Rettberg2022-10-30 20:34:23 +0100
committerSimon Rettberg2022-10-30 20:34:23 +0100
commit9f479b8f76238a03bce5d13aee14efd34e659c6e (patch)
treee320d32838202ac4604032da7a4bc3702cc304da /src/server/connectionframe
parentUpdate translation files (diff)
downloadpvs2-9f479b8f76238a03bce5d13aee14efd34e659c6e.tar.gz
pvs2-9f479b8f76238a03bce5d13aee14efd34e659c6e.tar.xz
pvs2-9f479b8f76238a03bce5d13aee14efd34e659c6e.zip
Clean up and modernize code
- static "new-style" signal->slot connections - Fix a lot of things Clang-Tidy complained about - Move includes to .cpp files and use forward decls in .h - Don't use <QtWidgets> and <QtCore>, but specific includes instead
Diffstat (limited to 'src/server/connectionframe')
-rw-r--r--src/server/connectionframe/connectionframe.cpp95
-rw-r--r--src/server/connectionframe/connectionframe.h55
2 files changed, 85 insertions, 65 deletions
diff --git a/src/server/connectionframe/connectionframe.cpp b/src/server/connectionframe/connectionframe.cpp
index c2bba70..c6c20b8 100644
--- a/src/server/connectionframe/connectionframe.cpp
+++ b/src/server/connectionframe/connectionframe.cpp
@@ -16,46 +16,51 @@
#include "connectionframe.h"
#include "../mainwindow/mainwindow.h"
+#include "../../shared/util.h"
#include "../net/client.h"
-#include <QImage>
-#include <cassert>
-#include <cmath>
-static QString style_student(
- "QLabel{ background-color: #FFF; border-radius: 2px; color: black;} \
- QGroupBox { background-color: #AAA; margin: 2px; border-radius: 4px}"
+#include <QImage>
+#include <QResizeEvent>
+#include <QBoxLayout>
+#include <QLabel>
+#include <QApplication>
+#include <QPainter>
+
+static const QString style_student(
+ "QLabel{ background-color: #FFF; border-radius: 2px; color: black;}"
+ " QGroupBox { background-color: #AAA; margin: 2px; border-radius: 4px}"
);
-static QString style_tutor(
- "QLabel{ background-color: #FFF; border-radius: 2px; color: black;} \
- QGroupBox { background-color: #70C670; margin: 2px; border-radius: 4px}"
+static const QString style_tutor(
+ "QLabel{ background-color: #FFF; border-radius: 2px; color: black;}"
+ " QGroupBox { background-color: #70C670; margin: 2px; border-radius: 4px}"
);
-static QString style_attention(
- "QLabel{ background-color: #FFF; border-radius: 2px; color: black;} \
- QGroupBox { background-color: #C88; margin: 2px; border-radius: 4px}"
+static const QString style_attention(
+ "QLabel{ background-color: #FFF; border-radius: 2px; color: black;}"
+ " QGroupBox { background-color: #C88; margin: 2px; border-radius: 4px}"
);
-static QString style_selectedStudent(
- "QLabel{ background-color: #FFF; border-radius: 2px; color: black; } \
- QGroupBox { background-color: #ccebff; margin: 0px; border-radius: 4px; border: 4px solid #6C8CF0;}"
+static const QString style_selectedStudent(
+ "QLabel{ background-color: #FFF; border-radius: 2px; color: black; }"
+ " QGroupBox { background-color: #ccebff; margin: 0px; border-radius: 4px; border: 4px solid #6C8CF0;}"
);
-static QString style_selectedTutor(
- "QLabel{ background-color: #FFF; border-radius: 2px; color: black;} \
- QGroupBox { background-color: #9f9; margin: 0px; border-radius: 4px; border: 4px solid #6C8CF0;}"
+static const QString style_selectedTutor(
+ "QLabel{ background-color: #FFF; border-radius: 2px; color: black;}"
+ " QGroupBox { background-color: #9f9; margin: 0px; border-radius: 4px; border: 4px solid #6C8CF0;}"
);
-static QString style_selectedAttention(
- "QLabel{ background-color: #FFF; border-radius: 2px; color: black;} \
- QGroupBox { background-color: #E99; margin: 0px; border-radius: 4px; border: 4px solid #6C8CF0;}"
+static const QString style_selectedAttention(
+ "QLabel{ background-color: #FFF; border-radius: 2px; color: black;}"
+ " QGroupBox { background-color: #E99; margin: 0px; border-radius: 4px; border: 4px solid #6C8CF0;}"
);
-static QString style_exam (
- "QLabel{ background-color: #919191; color: black; } \
- QGroupBox { background-color: #d35400; margin: 1px; border-radius: 4px}"
+static const QString style_exam (
+ "QLabel{ background-color: #919191; color: black; }"
+ " QGroupBox { background-color: #d35400; margin: 1px; border-radius: 4px}"
);
-static QString style_exam_selected (
- "QLabel{ background-color: #919191; color: black; } \
- QGroupBox { background-color: #cc743a; margin: 1px; border-radius: 4px}"
+static const QString style_exam_selected (
+ "QLabel{ background-color: #919191; color: black; }"
+ " QGroupBox { background-color: #cc743a; margin: 1px; border-radius: 4px}"
);
-static QString style_disconnected(
- "QLabel{ background-color: #919191; border-radius: 2px; color: black; } \
- QGroupBox { background-color: #7F7F7F; margin: 1px; border-radius: 4px}"
+static const QString style_disconnected(
+ "QLabel{ background-color: #919191; border-radius: 2px; color: black; }"
+ " QGroupBox { background-color: #7F7F7F; margin: 1px; border-radius: 4px}"
);
static QIcon *term = nullptr, *cam = nullptr, *eye = nullptr, *lock = nullptr;
@@ -70,9 +75,10 @@ bool ConnectionFrame::paintDisabled = false;
* @param width
* @param height
*/
-ConnectionFrame::ConnectionFrame(MainWindow* main, QWidget *parent, bool fromRoomplan) :
- QGroupBox(parent), _client(nullptr), _timerId(0), _timerCounter(0), _isSelected(false), _isTutor(false),
- _isFromRoomplan(fromRoomplan), _mainWindow(main)
+ConnectionFrame::ConnectionFrame(MainWindow* main, QWidget *parent, bool fromRoomplan)
+ : QGroupBox(parent)
+ , _isFromRoomplan(fromRoomplan)
+ , _mainWindow(main)
{
//defines the ui-stuff
@@ -158,7 +164,7 @@ void ConnectionFrame::updateGeometry()
*/
QLabel* ConnectionFrame::addIcon(const QIcon* icon)
{
- QLabel *label = new QLabel(this);
+ auto *label = new QLabel(this);
label->setPixmap(icon->pixmap(24, 24, QIcon::Normal, QIcon::On));
label->setAttribute(Qt::WA_TranslucentBackground);
label->hide();
@@ -174,17 +180,17 @@ QLabel* ConnectionFrame::addIcon(const QIcon* icon)
void ConnectionFrame::assignClient(Client* client)
{
assert(_client == nullptr);
- connect( client, SIGNAL(disconnected()), this, SLOT(onClientDisconnected()) );
- connect( client, SIGNAL(thumbUpdated(Client*, const QImage&)), this, SLOT(onThumbUpdated(Client*, const QImage&)) );
- connect( client, SIGNAL(vncServerStateChange(Client*)), this, SLOT(updateAppearance()));
- connect( client, SIGNAL(vncClientStateChange(Client*)), this, SLOT(updateAppearance()));
- connect( client, SIGNAL(stateChanged()), this, SLOT(updateAppearance()));
_client = client;
+ connect(_client, &Client::disconnected, this, &ConnectionFrame::onClientDisconnected );
+ connect(_client, &Client::thumbUpdated, this, &ConnectionFrame::onThumbUpdated );
+ connect(_client, &Client::vncServerStateChange, this, &ConnectionFrame::updateAppearance);
+ connect(_client, &Client::vncClientStateChange, this, &ConnectionFrame::updateAppearance);
+ connect(_client, &Client::stateChanged, this, &ConnectionFrame::updateAppearance);
_computerId = client->ip();
updateLabels();
showDefaultThumb();
if (_timerId == 0)
- _timerId = startTimer(1000 + qrand() % 150);
+ _timerId = startTimer(slxrand() % 150 + 1000);
this->updateAppearance();
_client->setTutor(_isTutor);
}
@@ -382,8 +388,8 @@ void ConnectionFrame::updateAppearance()
} else {
this->setStyleSheet(style_disconnected);
}
- for (QList<QLabel*>::iterator it(_icons.begin()); it != _icons.end(); ++it) {
- (**it).hide();
+ for (auto *_icon : _icons) {
+ _icon->hide();
}
return;
}
@@ -448,3 +454,8 @@ void ConnectionFrame::onThumbUpdated(Client* client, const QImage& thumb)
this->update();
}
+void ConnectionFrame::resizeEvent(QResizeEvent *event) {
+ calcDesiredThumbSize(event->size());
+ QGroupBox::resizeEvent(event);
+}
+
diff --git a/src/server/connectionframe/connectionframe.h b/src/server/connectionframe/connectionframe.h
index 1d004e6..cfebe85 100644
--- a/src/server/connectionframe/connectionframe.h
+++ b/src/server/connectionframe/connectionframe.h
@@ -1,9 +1,14 @@
-#ifndef _CONNECTIONFRAME_H_
-#define _CONNECTIONFRAME_H_
-#include <QtWidgets>
-#include "../net/client.h"
+#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
@@ -34,11 +39,11 @@ private:
QPoint _gridPosition;
QSize _desiredThumbSize;
- Client *_client;
+ Client *_client{};
- int _timerId, _timerCounter;
- bool _isSelected;
- bool _isTutor;
+ int _timerId{}, _timerCounter{};
+ bool _isSelected{};
+ bool _isTutor{};
bool _isFromRoomplan;
void showDefaultThumb();
@@ -52,35 +57,39 @@ public:
static bool paintDisabled;
ConnectionFrame(MainWindow* main, QWidget* parent, bool fromRoomplan = false);
- virtual ~ConnectionFrame();
+ ~ConnectionFrame() override;
- const inline QPoint getGridPosition() const { return _gridPosition; }
+ 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);
- inline bool isSelected() { return _isSelected; }
+ bool isSelected() const { return _isSelected; }
const QString& computerId() const { return _computerId; }
- void setComputerId(QString computerId) { if (_client != nullptr) return; _computerId = computerId; updateLabels(); }
+ void setComputerId(QString computerId) {
+ if (_client != nullptr)
+ return;
+ _computerId = std::move(computerId); updateLabels();
+ }
Client* client() const { return _client; }
- inline bool isTutor() { return _isTutor; }
- inline bool isFromRoomplan() { return _isFromRoomplan; }
+ bool isTutor() const { return _isTutor; }
+ bool isFromRoomplan() const { 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);
+ 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);