forked from shadowsocks/shadowsocks-qt5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuriinputdialog.cpp
39 lines (34 loc) · 1.02 KB
/
uriinputdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "uriinputdialog.h"
#include "ui_uriinputdialog.h"
#include "ssvalidator.h"
#include <QPushButton>
URIInputDialog::URIInputDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::URIInputDialog)
{
ui->setupUi(this);
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
connect(ui->uriEdit, &QLineEdit::textChanged, this, &URIInputDialog::onURIChanged);
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &URIInputDialog::onAccepted);
this->adjustSize();
}
URIInputDialog::~URIInputDialog()
{
delete ui;
}
void URIInputDialog::onURIChanged(const QString &str)
{
if (!SSValidator::validate(str)) {
ui->uriEdit->setStyleSheet("background: pink");
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
}
else {
ui->uriEdit->setStyleSheet("background: #81F279");
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
}
}
void URIInputDialog::onAccepted()
{
emit acceptedURI(ui->uriEdit->text());
this->accept();
}