This commit is contained in:
pokamest 2021-01-03 19:14:54 +03:00
parent 65698b9502
commit f36c16191b
5 changed files with 70 additions and 27 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

View file

@ -36,5 +36,6 @@
<file>server_scripts/remove_openvpn_server.sh</file> <file>server_scripts/remove_openvpn_server.sh</file>
<file>server_scripts/setup_openvpn_server.sh</file> <file>server_scripts/setup_openvpn_server.sh</file>
<file>server_scripts/template.ovpn</file> <file>server_scripts/template.ovpn</file>
<file>images/background_connected.png</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -21,9 +21,15 @@ MainWindow::MainWindow(QWidget *parent) :
m_vpnConnection(nullptr) m_vpnConnection(nullptr)
{ {
ui->setupUi(this); 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 // Post initialization
ui->widget_tittlebar->hide();
if (m_settings->haveAuthData()) { if (m_settings->haveAuthData()) {
goToPage(Page::Vpn); goToPage(Page::Vpn);
@ -78,7 +84,37 @@ MainWindow::~MainWindow()
void MainWindow::goToPage(Page page) void MainWindow::goToPage(Page page)
{ {
ui->stackedWidget_main->setCurrentIndex(static_cast<int>(page)); ui->stackedWidget_main->slideInIdx(static_cast<int>(page));
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if (obj == ui->widget_tittlebar) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(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) 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->setPassword(ui->lineEdit_new_server_password->text());
m_settings->save(); m_settings->save();
//goToPage(Page::Vpn);
if (requestOvpnConfig(m_settings->serverName(), m_settings->login(), m_settings->password())) { if (requestOvpnConfig(m_settings->serverName(), m_settings->login(), m_settings->password())) {
goToPage(Page::Vpn); 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; return false;
} }
void MainWindow::on_pushButton_close_clicked()
{
qApp->exit();
}

View file

@ -37,8 +37,9 @@ private slots:
void onPushButtonNewServerSetup(bool clicked); void onPushButtonNewServerSetup(bool clicked);
void onPushButtonSettingsClicked(bool clicked); void onPushButtonSettingsClicked(bool clicked);
void on_pushButton_close_clicked();
protected: protected:
void keyPressEvent(QKeyEvent* event);
bool requestOvpnConfig(const QString& hostName, const QString& userName, const QString& password, int port = 22, int timeout = 30); bool requestOvpnConfig(const QString& hostName, const QString& userName, const QString& password, int port = 22, int timeout = 30);
private: private:
@ -47,6 +48,11 @@ private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
VpnConnection* m_vpnConnection; VpnConnection* m_vpnConnection;
Settings* m_settings; Settings* m_settings;
bool canMove = false;
QPoint offset;
bool eventFilter(QObject *obj, QEvent *event) override;
void keyPressEvent(QKeyEvent* event) override;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View file

@ -231,9 +231,7 @@ image-position: right;
<cursorShape>PointingHandCursor</cursorShape> <cursorShape>PointingHandCursor</cursorShape>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true"> <string notr="true">QPushButton {
QPushButton {
image-position: right; image-position: right;
image: url(:/images/close.png); image: url(:/images/close.png);
@ -381,7 +379,6 @@ border-radius: 4px;</string>
/* grey */ /* grey */
border: 1px solid #A7A7A7; border: 1px solid #A7A7A7;
box-sizing: border-box;
color: #333333;</string> color: #333333;</string>
</property> </property>
<property name="text"> <property name="text">
@ -593,7 +590,6 @@ color: #333333;</string>
/* grey */ /* grey */
border: 1px solid #A7A7A7; border: 1px solid #A7A7A7;
box-sizing: border-box;
color: #333333;</string> color: #333333;</string>
</property> </property>
<property name="text"> <property name="text">
@ -614,11 +610,10 @@ color: #333333;</string>
/* grey */ /* grey */
border: 1px solid #A7A7A7; border: 1px solid #A7A7A7;
box-sizing: border-box;
color: #333333;</string> color: #333333;</string>
</property> </property>
<property name="text"> <property name="text">
<string/> <string>root</string>
</property> </property>
</widget> </widget>
<widget class="QLineEdit" name="lineEdit_new_server_password"> <widget class="QLineEdit" name="lineEdit_new_server_password">
@ -635,7 +630,6 @@ color: #333333;</string>
/* grey */ /* grey */
border: 1px solid #A7A7A7; border: 1px solid #A7A7A7;
box-sizing: border-box;
color: #333333;</string> color: #333333;</string>
</property> </property>
<property name="text"> <property name="text">
@ -684,9 +678,9 @@ border-radius: 4px;
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>50</x> <x>50</x>
<y>120</y> <y>115</y>
<width>281</width> <width>281</width>
<height>16</height> <height>21</height>
</rect> </rect>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
@ -695,10 +689,6 @@ font-style: normal;
font-weight: normal; font-weight: normal;
font-size: 16px; font-size: 16px;
line-height: 20px; line-height: 20px;
/* or 125% */
display: flex;
align-items: center;
text-align: center; text-align: center;
/* акцент */ /* акцент */
@ -805,14 +795,14 @@ QPushButton:hover {
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>380</width> <width>380</width>
<height>200</height> <height>325</height>
</rect> </rect>
</property> </property>
<property name="cursor"> <property name="cursor">
<cursorShape>PointingHandCursor</cursorShape> <cursorShape>PointingHandCursor</cursorShape>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">image: url(:/images/tray/active.png);</string> <string notr="true">border-image: url(:/images/background_connected.png);</string>
</property> </property>
<property name="text"> <property name="text">
<string/> <string/>
@ -955,7 +945,7 @@ line-height: 21px;
</string> </string>
</property> </property>
<property name="text"> <property name="text">
<string>Add site</string> <string>+ Add site</string>
</property> </property>
</widget> </widget>
<widget class="QPushButton" name="pushButton_settings"> <widget class="QPushButton" name="pushButton_settings">
@ -1282,7 +1272,7 @@ color: #181922;</string>
/* grey */ /* grey */
border: 1px solid #A7A7A7; border: 1px solid #A7A7A7;
box-sizing: border-box;</string> </string>
</property> </property>
<property name="text"> <property name="text">
<string/> <string/>
@ -1431,9 +1421,6 @@ font-style: normal;
font-weight: bold; font-weight: bold;
font-size: 20px; font-size: 20px;
line-height: 25px; line-height: 25px;
/* identical to box height, or 125% */
display: flex;
align-items: center;
Text-align:left; Text-align:left;
padding-left: 30px; padding-left: 30px;
@ -1480,9 +1467,6 @@ font-style: normal;
font-weight: bold; font-weight: bold;
font-size: 20px; font-size: 20px;
line-height: 25px; line-height: 25px;
/* identical to box height, or 125% */
display: flex;
align-items: center;
Text-align:left; Text-align:left;
padding-left: 30px; padding-left: 30px;