Open window at center

This commit is contained in:
Kevin Yue
2020-02-15 21:40:48 +08:00
parent c08ce6298c
commit 5d57fd5fd1
3 changed files with 32 additions and 3 deletions

View File

@@ -2,12 +2,17 @@
#include "ui_gpclient.h"
#include "samlloginwindow.h"
#include <QDesktopWidget>
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";