From 5d57fd5fd1f095f38f6ca3793aa6007f18d75c78 Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Sat, 15 Feb 2020 21:40:48 +0800 Subject: [PATCH] Open window at center --- GPClient/gpclient.cpp | 28 ++++++++++++++++++++++++++++ GPClient/gpclient.h | 1 + GPClient/gpclient.ui | 6 +++--- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/GPClient/gpclient.cpp b/GPClient/gpclient.cpp index 70afff8..7649916 100644 --- a/GPClient/gpclient.cpp +++ b/GPClient/gpclient.cpp @@ -2,12 +2,17 @@ #include "ui_gpclient.h" #include "samlloginwindow.h" +#include + GPClient::GPClient(QWidget *parent) : QMainWindow(parent) , ui(new Ui::GPClient) { ui->setupUi(this); + setFixedSize(width(), height()); + moveCenter(); + QObject::connect(this, &GPClient::connectFailed, [this]() { ui->connectButton->setDisabled(false); ui->connectButton->setText("Connect"); @@ -136,6 +141,7 @@ void GPClient::onLoginSuccess(QJsonObject loginResult) ui->statusLabel->setText("Connecting..."); ui->connectButton->setText("Cancel"); + ui->connectButton->setDisabled(false); vpn->connect(host, user, cookieValue); } @@ -158,6 +164,28 @@ void GPClient::onVPNLogAvailable(QString log) qDebug() << log; } +void GPClient::moveCenter() +{ + QDesktopWidget *desktop = QApplication::desktop(); + + int screenWidth, width; + int screenHeight, height; + int x, y; + QSize windowSize; + + screenWidth = desktop->width(); + screenHeight = desktop->height(); + + windowSize = size(); + width = windowSize.width(); + height = windowSize.height(); + + x = (screenWidth - width) / 2; + y = (screenHeight - height) / 2; + y -= 50; + move(x, y); +} + void GPClient::samlLogin(const QString portal) { const QString preloginUrl = "https://" + portal + "/ssl-vpn/prelogin.esp"; diff --git a/GPClient/gpclient.h b/GPClient/gpclient.h index 454960d..c03f364 100644 --- a/GPClient/gpclient.h +++ b/GPClient/gpclient.h @@ -39,6 +39,7 @@ private: QNetworkReply *reply; com::yuezk::qt::GPService *vpn; + void moveCenter(); void samlLogin(const QString portal); }; #endif // GPCLIENT_H diff --git a/GPClient/gpclient.ui b/GPClient/gpclient.ui index 9da6c49..2205c55 100644 --- a/GPClient/gpclient.ui +++ b/GPClient/gpclient.ui @@ -6,12 +6,12 @@ 0 0 - 258 - 301 + 260 + 300 - GPClient + GP VPN Client