author | Wuzzy <almikes@aol.com> |
Mon, 25 Sep 2017 21:18:59 +0200 | |
changeset 12527 | 228ebbc8656d |
parent 12480 | d7414e3b3bbb |
permissions | -rw-r--r-- |
8157 | 1 |
#include <QFormLayout> |
2 |
#include <QComboBox> |
|
3 |
#include <QRadioButton> |
|
4 |
#include <QLineEdit> |
|
5 |
#include <QLabel> |
|
6 |
#include <QPushButton> |
|
7 |
#include <QHBoxLayout> |
|
8 |
#include <QMessageBox> |
|
8411
cb371dac50c0
reuse the same words with tr() and .arg() in bandialog
koda
parents:
8177
diff
changeset
|
9 |
#include "HWApplication.h" |
8157 | 10 |
|
11 |
#include "bandialog.h" |
|
12 |
||
13 |
BanDialog::BanDialog(QWidget *parent) : |
|
14 |
QDialog(parent) |
|
15 |
{ |
|
16 |
QFormLayout * formLayout = new QFormLayout(this); |
|
17 |
||
18 |
rbIP = new QRadioButton(this); |
|
19 |
rbIP->setChecked(true); |
|
20 |
rbNick = new QRadioButton(this); |
|
21 |
leId = new QLineEdit(this); |
|
22 |
leReason = new QLineEdit(this); |
|
23 |
cbTime = new QComboBox(this); |
|
24 |
||
10079 | 25 |
const int min = 60; |
26 |
const int hour = 60 * min; |
|
27 |
const int day = 24 * hour; |
|
28 |
cbTime->addItem(HWApplication::tr("%1 minutes", 0, 10).arg(10), 10 * min); |
|
29 |
cbTime->addItem(HWApplication::tr("%1 minutes", 0, 30).arg(30), 30 * min); |
|
30 |
cbTime->addItem(HWApplication::tr("%1 hour", 0, 1).arg(1), 1 * hour); |
|
31 |
cbTime->addItem(HWApplication::tr("%1 hours", 0, 3).arg(3), 3 * hour); |
|
32 |
cbTime->addItem(HWApplication::tr("%1 hours", 0, 5).arg(5), 5 * hour); |
|
33 |
cbTime->addItem(HWApplication::tr("%1 hours", 0, 12).arg(12), 12 * hour); |
|
34 |
cbTime->addItem(HWApplication::tr("%1 day", 0, 1).arg(1), 1 * day); |
|
35 |
cbTime->addItem(HWApplication::tr("%1 days", 0, 3).arg(3), 3 * day); |
|
36 |
cbTime->addItem(HWApplication::tr("%1 days", 0, 7).arg(7), 7 * day); |
|
37 |
cbTime->addItem(HWApplication::tr("%1 days", 0, 14).arg(14), 14 * day); |
|
8177 | 38 |
cbTime->addItem(tr("permanent"), 3650 * 24 * 60 * 60); |
8157 | 39 |
cbTime->setCurrentIndex(0); |
40 |
||
41 |
formLayout->addRow(tr("IP"), rbIP); |
|
42 |
formLayout->addRow(tr("Nick"), rbNick); |
|
43 |
formLayout->addRow(tr("IP/Nick"), leId); |
|
44 |
formLayout->addRow(tr("Reason"), leReason); |
|
45 |
formLayout->addRow(tr("Duration"), cbTime); |
|
46 |
||
47 |
formLayout->setLabelAlignment(Qt::AlignRight); |
|
48 |
||
49 |
QHBoxLayout * hbox = new QHBoxLayout(); |
|
50 |
formLayout->addRow(hbox); |
|
51 |
QPushButton * btnOk = new QPushButton(tr("Ok"), this); |
|
52 |
QPushButton * btnCancel = new QPushButton(tr("Cancel"), this); |
|
53 |
hbox->addStretch(); |
|
54 |
hbox->addWidget(btnOk); |
|
55 |
hbox->addWidget(btnCancel); |
|
56 |
||
57 |
connect(btnOk, SIGNAL(clicked()), this, SLOT(okClicked())); |
|
58 |
connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject())); |
|
8159 | 59 |
|
60 |
this->setWindowModality(Qt::WindowModal); |
|
11495
fb7817a5c2b1
Add window titles for title-less windows
Wuzzy <almikes@aol.com>
parents:
10079
diff
changeset
|
61 |
this->setWindowTitle(tr("Ban player")); |
8157 | 62 |
} |
63 |
||
64 |
bool BanDialog::byIP() |
|
65 |
{ |
|
66 |
return rbIP->isChecked(); |
|
67 |
} |
|
68 |
||
69 |
int BanDialog::duration() |
|
70 |
{ |
|
71 |
return cbTime->itemData(cbTime->currentIndex()).toInt(); |
|
72 |
} |
|
73 |
||
74 |
QString BanDialog::banId() |
|
75 |
{ |
|
76 |
return leId->text(); |
|
77 |
} |
|
78 |
||
79 |
QString BanDialog::reason() |
|
80 |
{ |
|
81 |
return leReason->text().isEmpty() ? tr("you know why") : leReason->text(); |
|
82 |
} |
|
83 |
||
84 |
void BanDialog::okClicked() |
|
85 |
{ |
|
86 |
if(leId->text().isEmpty()) |
|
87 |
{ |
|
12480
d7414e3b3bbb
Rewrite missing IP/nick warning of the ban dialog
Wuzzy <almikes@aol.com>
parents:
11495
diff
changeset
|
88 |
QString warning_text; |
d7414e3b3bbb
Rewrite missing IP/nick warning of the ban dialog
Wuzzy <almikes@aol.com>
parents:
11495
diff
changeset
|
89 |
if (byIP()) |
d7414e3b3bbb
Rewrite missing IP/nick warning of the ban dialog
Wuzzy <almikes@aol.com>
parents:
11495
diff
changeset
|
90 |
warning_text = QString(tr("Please specify an IP address.")); |
d7414e3b3bbb
Rewrite missing IP/nick warning of the ban dialog
Wuzzy <almikes@aol.com>
parents:
11495
diff
changeset
|
91 |
else |
d7414e3b3bbb
Rewrite missing IP/nick warning of the ban dialog
Wuzzy <almikes@aol.com>
parents:
11495
diff
changeset
|
92 |
warning_text = QString(tr("Please specify a nickname.")); |
d7414e3b3bbb
Rewrite missing IP/nick warning of the ban dialog
Wuzzy <almikes@aol.com>
parents:
11495
diff
changeset
|
93 |
|
d7414e3b3bbb
Rewrite missing IP/nick warning of the ban dialog
Wuzzy <almikes@aol.com>
parents:
11495
diff
changeset
|
94 |
QMessageBox::warning(this, tr("Warning"), warning_text); |
8157 | 95 |
return; |
96 |
} |
|
97 |
||
98 |
accept(); |
|
99 |
} |