author | unc0rr |
Mon, 27 Jan 2014 01:07:12 +0400 | |
changeset 10079 | c88e38a0f478 |
parent 8417 | 790492abc004 |
child 11495 | fb7817a5c2b1 |
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); |
|
8157 | 61 |
} |
62 |
||
63 |
bool BanDialog::byIP() |
|
64 |
{ |
|
65 |
return rbIP->isChecked(); |
|
66 |
} |
|
67 |
||
68 |
int BanDialog::duration() |
|
69 |
{ |
|
70 |
return cbTime->itemData(cbTime->currentIndex()).toInt(); |
|
71 |
} |
|
72 |
||
73 |
QString BanDialog::banId() |
|
74 |
{ |
|
75 |
return leId->text(); |
|
76 |
} |
|
77 |
||
78 |
QString BanDialog::reason() |
|
79 |
{ |
|
80 |
return leReason->text().isEmpty() ? tr("you know why") : leReason->text(); |
|
81 |
} |
|
82 |
||
83 |
void BanDialog::okClicked() |
|
84 |
{ |
|
85 |
if(leId->text().isEmpty()) |
|
86 |
{ |
|
87 |
QMessageBox::warning(this, tr("Warning"), tr("Please, specify %1").arg(byIP() ? tr("IP") : tr("nickname"))); |
|
88 |
return; |
|
89 |
} |
|
90 |
||
91 |
accept(); |
|
92 |
} |