diff --git a/client/images/background_connected.png b/client/images/background_connected.png new file mode 100644 index 00000000..7e83c851 Binary files /dev/null and b/client/images/background_connected.png differ diff --git a/client/resources.qrc b/client/resources.qrc index fd24e397..52bf71f4 100644 --- a/client/resources.qrc +++ b/client/resources.qrc @@ -36,5 +36,6 @@ server_scripts/remove_openvpn_server.sh server_scripts/setup_openvpn_server.sh server_scripts/template.ovpn + images/background_connected.png diff --git a/client/ui/mainwindow.cpp b/client/ui/mainwindow.cpp index 5c657722..f95090c2 100644 --- a/client/ui/mainwindow.cpp +++ b/client/ui/mainwindow.cpp @@ -21,9 +21,15 @@ MainWindow::MainWindow(QWidget *parent) : m_vpnConnection(nullptr) { ui->setupUi(this); + ui->widget_tittlebar->installEventFilter(this); + + setWindowFlags(Qt:: ToolTip | Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); + setAttribute(Qt::WA_TranslucentBackground); + + ui->stackedWidget_main->setSpeed(200); + ui->stackedWidget_main->setAnimation(QEasingCurve::Linear); // Post initialization - ui->widget_tittlebar->hide(); if (m_settings->haveAuthData()) { goToPage(Page::Vpn); @@ -78,7 +84,37 @@ MainWindow::~MainWindow() void MainWindow::goToPage(Page page) { - ui->stackedWidget_main->setCurrentIndex(static_cast(page)); + ui->stackedWidget_main->slideInIdx(static_cast(page)); +} + +bool MainWindow::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == ui->widget_tittlebar) { + QMouseEvent *mouseEvent = static_cast(event); + + if (!mouseEvent) + return false; + + if(event->type() == QEvent::MouseButtonPress) { + offset = mouseEvent->pos(); + canMove = true; + } + + if(event->type() == QEvent::MouseButtonRelease) { + canMove = false; + } + + if (event->type() == QEvent::MouseMove) { + if(canMove && (mouseEvent->buttons() & Qt::LeftButton)) { + move(mapToParent(mouseEvent->pos() - offset)); + } + + event->ignore(); + return false; + } + } + + return QMainWindow::eventFilter(obj, event); } void MainWindow::keyPressEvent(QKeyEvent *event) @@ -108,8 +144,19 @@ void MainWindow::onPushButtonNewServerConnectWithNewData(bool clicked) m_settings->setPassword(ui->lineEdit_new_server_password->text()); m_settings->save(); + //goToPage(Page::Vpn); + if (requestOvpnConfig(m_settings->serverName(), m_settings->login(), m_settings->password())) { goToPage(Page::Vpn); + + ui->pushButton_connect->setDown(true); + + if (!m_vpnConnection->connectToVpn()) { + ui->pushButton_connect->setChecked(false); + QMessageBox::critical(this, APPLICATION_NAME, m_vpnConnection->lastError()); + return; + } + } } } @@ -231,3 +278,8 @@ bool MainWindow::requestOvpnConfig(const QString& hostName, const QString& userN return false; } + +void MainWindow::on_pushButton_close_clicked() +{ + qApp->exit(); +} diff --git a/client/ui/mainwindow.h b/client/ui/mainwindow.h index 27560dd0..47d16c32 100644 --- a/client/ui/mainwindow.h +++ b/client/ui/mainwindow.h @@ -37,8 +37,9 @@ private slots: void onPushButtonNewServerSetup(bool clicked); void onPushButtonSettingsClicked(bool clicked); + void on_pushButton_close_clicked(); + protected: - void keyPressEvent(QKeyEvent* event); bool requestOvpnConfig(const QString& hostName, const QString& userName, const QString& password, int port = 22, int timeout = 30); private: @@ -47,6 +48,11 @@ private: Ui::MainWindow *ui; VpnConnection* m_vpnConnection; Settings* m_settings; + + bool canMove = false; + QPoint offset; + bool eventFilter(QObject *obj, QEvent *event) override; + void keyPressEvent(QKeyEvent* event) override; }; #endif // MAINWINDOW_H diff --git a/client/ui/mainwindow.ui b/client/ui/mainwindow.ui index 78aebdb2..7c8fd627 100644 --- a/client/ui/mainwindow.ui +++ b/client/ui/mainwindow.ui @@ -231,9 +231,7 @@ image-position: right; PointingHandCursor - - -QPushButton { + QPushButton { image-position: right; image: url(:/images/close.png); @@ -381,7 +379,6 @@ border-radius: 4px; /* grey */ border: 1px solid #A7A7A7; -box-sizing: border-box; color: #333333; @@ -593,7 +590,6 @@ color: #333333; /* grey */ border: 1px solid #A7A7A7; -box-sizing: border-box; color: #333333; @@ -614,11 +610,10 @@ color: #333333; /* grey */ border: 1px solid #A7A7A7; -box-sizing: border-box; color: #333333; - + root @@ -635,7 +630,6 @@ color: #333333; /* grey */ border: 1px solid #A7A7A7; -box-sizing: border-box; color: #333333; @@ -684,9 +678,9 @@ border-radius: 4px; 50 - 120 + 115 281 - 16 + 21 @@ -695,10 +689,6 @@ font-style: normal; font-weight: normal; font-size: 16px; line-height: 20px; - -/* or 125% */ -display: flex; -align-items: center; text-align: center; /* акцент */ @@ -805,14 +795,14 @@ QPushButton:hover { 0 0 380 - 200 + 325 PointingHandCursor - image: url(:/images/tray/active.png); + border-image: url(:/images/background_connected.png); @@ -955,7 +945,7 @@ line-height: 21px; - Add site + + Add site @@ -1282,7 +1272,7 @@ color: #181922; /* grey */ border: 1px solid #A7A7A7; -box-sizing: border-box; + @@ -1431,9 +1421,6 @@ font-style: normal; font-weight: bold; font-size: 20px; line-height: 25px; -/* identical to box height, or 125% */ -display: flex; -align-items: center; Text-align:left; padding-left: 30px; @@ -1480,9 +1467,6 @@ font-style: normal; font-weight: bold; font-size: 20px; line-height: 25px; -/* identical to box height, or 125% */ -display: flex; -align-items: center; Text-align:left; padding-left: 30px;