From 35c3facc81cf10a2070cc5091e4e447ecc7416e3 Mon Sep 17 00:00:00 2001 From: Manuel Schneider Date: Tue, 6 May 2014 14:37:44 +0200 Subject: Changes the approach of Qt Gui initialization to the member pointer approach. This means multiple inheritance is avoided and the form is now a member pointer of the class. Immlicitely renamed some ui elements for clearification. Again changed unnecessary use of QDialog to QWidget. --- gui/client/connect.ui | 8 ++-- gui/client/toolbar.ui | 30 ++++++++----- src/client/connectwindow/connectwindow.cpp | 56 ++++++++++++------------ src/client/connectwindow/connectwindow.h | 11 +++-- src/client/toolbar/toolbar.cpp | 23 ++++++---- src/client/toolbar/toolbar.h | 13 ++++-- src/server/mainwindow/mainwindow.h | 3 +- src/server/sessionnamewindow/sessionnamewindow.h | 5 +-- src/shared/settings.h | 2 + 9 files changed, 88 insertions(+), 63 deletions(-) diff --git a/gui/client/connect.ui b/gui/client/connect.ui index c702123..1cb873c 100644 --- a/gui/client/connect.ui +++ b/gui/client/connect.ui @@ -1,13 +1,13 @@ - Dialog - + ConnectWindow + 0 0 - 511 - 121 + 512 + 128 diff --git a/gui/client/toolbar.ui b/gui/client/toolbar.ui index 8f32658..199eef2 100644 --- a/gui/client/toolbar.ui +++ b/gui/client/toolbar.ui @@ -1,7 +1,7 @@ - ToolbarClass - + Toolbar + 0 @@ -66,8 +66,17 @@ QCheckBox::indicator:checked:pressed { } - - + + + 0 + + + 0 + + + 0 + + 0 @@ -78,12 +87,12 @@ QCheckBox::indicator:checked:pressed { QFrame::Raised - + - 68 + 84 0 @@ -96,7 +105,7 @@ QCheckBox::indicator:checked:pressed { - + Qt::Horizontal @@ -119,7 +128,7 @@ QCheckBox::indicator:checked:pressed { - + Qt::Horizontal @@ -132,7 +141,7 @@ QCheckBox::indicator:checked:pressed { - + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> @@ -143,7 +152,7 @@ p, li { white-space: pre-wrap; } - + 16 @@ -168,7 +177,6 @@ p, li { white-space: pre-wrap; } - diff --git a/src/client/connectwindow/connectwindow.cpp b/src/client/connectwindow/connectwindow.cpp index ca01404..5215a32 100644 --- a/src/client/connectwindow/connectwindow.cpp +++ b/src/client/connectwindow/connectwindow.cpp @@ -5,26 +5,28 @@ * Author: sr */ -#include "connectwindow.h" +#include #include "../../shared/settings.h" #include "../../shared/network.h" #include "../../shared/util.h" - #include "../net/serverconnection.h" - -#include +#include "connectwindow.h" +#include "ui_connect.h" #define UDPBUFSIZ 9000 #define SALT_LEN 18 ConnectWindow::ConnectWindow(QWidget *parent) : - QDialog(parent), _connected(false), _timerDiscover(0), _timerHide(0), _connection(NULL), _state(Idle), - _hashErrorCount(0), _hashSslErrorCount(0), _certErrorCount(0), _ipErrorCount(0), _discoveryInterval(800) + QWidget(parent), _ui(new Ui::ConnectWindow), _connected(false), + _timerDiscover(0), _timerHide(0), _connection(NULL), _state(Idle), + _hashErrorCount(0), _hashSslErrorCount(0), _certErrorCount(0), + _ipErrorCount(0), _discoveryInterval(800) { - setupUi(this); - // - connect(cmdOK, SIGNAL(clicked()), this, SLOT(onOkClick())); - connect(cmdCancel, SIGNAL(clicked()), this, SLOT(onCancelClick())); + // Initialize the GUI + _ui->setupUi(this); + + connect(_ui->cmdOK, SIGNAL(clicked()), this, SLOT(onOkClick())); + connect(_ui->cmdCancel, SIGNAL(clicked()), this, SLOT(onCancelClick())); int tries = 10; while (tries-- != 0) { @@ -66,51 +68,51 @@ void ConnectWindow::setState(const ConnectionState state) void ConnectWindow::updateState() { - txtName->setEnabled(_state == Idle && !_connected); + _ui->txtName->setEnabled(_state == Idle && !_connected); if (_connected) { - cmdOK->setEnabled(true); - cmdOK->setText(tr("&Disconnect")); - lblStatus->setText(tr("Connected.")); - txtName->setEnabled(false); + _ui->cmdOK->setEnabled(true); + _ui->cmdOK->setText(tr("&Disconnect")); + _ui->lblStatus->setText(tr("Connected.")); + _ui->txtName->setEnabled(false); return; } if (_state != Idle) - cmdOK->setText(tr("&Stop")); + _ui->cmdOK->setText(tr("&Stop")); else - cmdOK->setText(tr("&Connect")); + _ui->cmdOK->setText(tr("&Connect")); switch (_state) { case Idle: - lblStatus->setText(tr("Ready to connect; please enter session name.")); + _ui->lblStatus->setText(tr("Ready to connect; please enter session name.")); break; case Scanning: - lblStatus->setText(tr("Scanning for session %1.").arg(txtName->text())); + _ui->lblStatus->setText(tr("Scanning for session %1.").arg(_ui->txtName->text())); _timerDiscover = startTimer(_discoveryInterval); break; case Connecting: - lblStatus->setText(tr("Found session, connecting...")); + _ui->lblStatus->setText(tr("Found session, connecting...")); break; case AwaitingChallenge: - lblStatus->setText(tr("Waiting for server challenge...")); + _ui->lblStatus->setText(tr("Waiting for server challenge...")); break; case AwaitingChallengeResponse: - lblStatus->setText(tr("Replied to challenge, sent own...")); + _ui->lblStatus->setText(tr("Replied to challenge, sent own...")); break; case LoggingIn: - lblStatus->setText(tr("Logging in...")); + _ui->lblStatus->setText(tr("Logging in...")); break; case Connected: - lblStatus->setText(tr("Connection established!")); + _ui->lblStatus->setText(tr("Connection established!")); break; case InvalidIpList: case InvalidHash: case InvalidCert: case InvalidSslHash: - lblError->setText(tr("Invalid hash: %1; invalid cert: %2; invalid iplist: %3; invalid sslhash: %4") + _ui->lblError->setText(tr("Invalid hash: %1; invalid cert: %2; invalid iplist: %3; invalid sslhash: %4") .arg(_hashErrorCount).arg(_certErrorCount).arg(_ipErrorCount).arg(_hashSslErrorCount)); break; } @@ -189,7 +191,7 @@ void ConnectWindow::closeEvent(QCloseEvent *e) void ConnectWindow::showEvent(QShowEvent* event) { - txtName->setFocus(); + _ui->txtName->setFocus(); } /* @@ -214,7 +216,7 @@ void ConnectWindow::onOkClick() { // Connect (scan for session) _discoveryInterval = 800; - _nameBytes = txtName->text().toUtf8(); + _nameBytes = _ui->txtName->text().toUtf8(); _timerDiscover = startTimer(_discoveryInterval); _hashErrorCount = _hashSslErrorCount = _certErrorCount = _ipErrorCount = 0; this->setState(Scanning); diff --git a/src/client/connectwindow/connectwindow.h b/src/client/connectwindow/connectwindow.h index 2bc2f86..191121c 100644 --- a/src/client/connectwindow/connectwindow.h +++ b/src/client/connectwindow/connectwindow.h @@ -19,13 +19,14 @@ #include #include #include -#include "ui_connect.h" - #include "../../shared/networkmessage.h" +namespace Ui{ +class ConnectWindow; +} class ServerConnection; -class ConnectWindow : public QDialog, private Ui_Dialog +class ConnectWindow : public QWidget { Q_OBJECT @@ -46,6 +47,8 @@ public: }; private: + Ui::ConnectWindow *_ui; + bool _connected; int _timerDiscover, _timerHide; ServerConnection *_connection; @@ -62,7 +65,7 @@ private: void updateState(); public: - ConnectWindow(QWidget *parent = NULL); + explicit ConnectWindow(QWidget *parent = NULL); virtual ~ConnectWindow(); void setConnected(const bool connected); diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp index 34dafd5..bce6b6e 100644 --- a/src/client/toolbar/toolbar.cpp +++ b/src/client/toolbar/toolbar.cpp @@ -5,20 +5,26 @@ * Author: sr */ -#include "toolbar.h" #include "../../shared/settings.h" #include "../net/serverconnection.h" #include "../vnc/vncwindow.h" #include "../vnc/vncserver.h" +#include "toolbar.h" +#include "ui_toolbar.h" + Toolbar::Toolbar(QWidget *parent) : - QWidget(parent), _location(POSITION_TOP_CENTER), _hideTimer(0), _connection(NULL) + QWidget(parent), _ui(new Ui::Toolbar), _location(POSITION_TOP_CENTER), + _hideTimer(0), _connection(NULL) { - setupUi(this); + // Initialize the GUI + _ui->setupUi(this); + setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint); setAttribute(Qt::WA_AlwaysShowToolTips); setAttribute(Qt::WA_QuitOnClose); setVisible(true); + // VNC Window _vnc = new VncWindow(NULL); // Connect window @@ -44,7 +50,7 @@ void Toolbar::setupMenu() _menu->addSeparator(); _menu->addAction(_acnQuit); - cmdMenu->setMenu(_menu); + _ui->cmdMenu->setMenu(_menu); connect(_acnQuit, SIGNAL(triggered()), this, SLOT(onQuit())); connect(_acnDisconnect, SIGNAL(triggered()), _connectWindow, SLOT(show())); @@ -55,6 +61,7 @@ Toolbar::~Toolbar() VncServer::instance()->stop(); _vnc->deleteLater(); _connectWindow->deleteLater(); + delete _ui; } //###########\\/\/ @@ -164,14 +171,14 @@ void Toolbar::onDisconnected() if (_connection != NULL) _connection->blockSignals(true); _connection = NULL; - lblStatus->setStyleSheet("color:red"); - lblStatus->setText(tr("Offline")); + _ui->lblStatus->setStyleSheet("color:red"); + _ui->lblStatus->setText(tr("Offline")); } void Toolbar::onConnected(ServerConnection* connection) { - lblStatus->setStyleSheet("color:green"); - lblStatus->setText(tr("Online")); + _ui->lblStatus->setStyleSheet("color:green"); + _ui->lblStatus->setText(tr("Online")); // if (_connection != NULL) { diff --git a/src/client/toolbar/toolbar.h b/src/client/toolbar/toolbar.h index 8887ca7..be42aa2 100644 --- a/src/client/toolbar/toolbar.h +++ b/src/client/toolbar/toolbar.h @@ -15,18 +15,23 @@ #define PVSCLIENTGUI_H_ #include -#include "ui_toolbar.h" class ServerConnection; class VncWindow; class ConnectWindow; class BlankScreen; -class Toolbar : public QWidget, private Ui_ToolbarClass +namespace Ui{ +class Toolbar; +} + +class Toolbar : public QWidget { -Q_OBJECT + Q_OBJECT private: + Ui::Toolbar *_ui; + int _location; int _hideTimer; int _hideDelay; @@ -48,7 +53,7 @@ private: void timerEvent(QTimerEvent* event); public: - Toolbar(QWidget *parent = NULL); + explicit Toolbar(QWidget *parent = 0); virtual ~Toolbar(); int const static POSITION_TOP_LEFT = 0; diff --git a/src/server/mainwindow/mainwindow.h b/src/server/mainwindow/mainwindow.h index 3ea82ca..c06f8e9 100644 --- a/src/server/mainwindow/mainwindow.h +++ b/src/server/mainwindow/mainwindow.h @@ -11,8 +11,7 @@ class ConnectionFrame; class ListenServer; class DiscoveryListener; -namespace Ui -{ +namespace Ui{ class MainWindow; } diff --git a/src/server/sessionnamewindow/sessionnamewindow.h b/src/server/sessionnamewindow/sessionnamewindow.h index ed944c1..ee93ea2 100644 --- a/src/server/sessionnamewindow/sessionnamewindow.h +++ b/src/server/sessionnamewindow/sessionnamewindow.h @@ -4,8 +4,7 @@ #include -namespace Ui -{ +namespace Ui{ class SessionName; } @@ -14,7 +13,7 @@ class SessionNameWindow : public QDialog Q_OBJECT private: - Ui::SessionName *ui; + Ui::SessionName *ui; public: SessionNameWindow(QWidget *parent = 0); diff --git a/src/shared/settings.h b/src/shared/settings.h index c1c45c1..2713693 100644 --- a/src/shared/settings.h +++ b/src/shared/settings.h @@ -1,6 +1,8 @@ #ifndef _SETTINGS_H_ #define _SETTINGS_H_ +#include + #define CLIENT_PORT 5194 static const QString CLIENT_PORT_STR(QString::number(CLIENT_PORT)); static const QByteArray CLIENT_PORT_ARRAY(QString::number(CLIENT_PORT).toUtf8()); -- cgit v1.2.3-55-g7522