QTfrontend/ui/dialog/bandialog.cpp
author Wuzzy <Wuzzy2@mail.ru>
Fri, 11 Oct 2019 18:41:56 +0200
changeset 15470 a18f7e4681b8
parent 12480 d7414e3b3bbb
permissions -rw-r--r--
Add flame-less dynamite sprite for drowning dynamite
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8157
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
     1
#include <QFormLayout>
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
     2
#include <QComboBox>
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
     3
#include <QRadioButton>
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
     4
#include <QLineEdit>
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
     5
#include <QLabel>
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
     6
#include <QPushButton>
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
     7
#include <QHBoxLayout>
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
     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
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    10
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    11
#include "bandialog.h"
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    12
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    13
BanDialog::BanDialog(QWidget *parent) :
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    14
    QDialog(parent)
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    15
{
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    16
    QFormLayout * formLayout = new QFormLayout(this);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    17
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    18
    rbIP = new QRadioButton(this);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    19
    rbIP->setChecked(true);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    20
    rbNick = new QRadioButton(this);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    21
    leId = new QLineEdit(this);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    22
    leReason = new QLineEdit(this);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    23
    cbTime = new QComboBox(this);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    24
10079
c88e38a0f478 Fix times
unc0rr
parents: 8417
diff changeset
    25
    const int min = 60;
c88e38a0f478 Fix times
unc0rr
parents: 8417
diff changeset
    26
    const int hour = 60 * min;
c88e38a0f478 Fix times
unc0rr
parents: 8417
diff changeset
    27
    const int day = 24 * hour;
c88e38a0f478 Fix times
unc0rr
parents: 8417
diff changeset
    28
    cbTime->addItem(HWApplication::tr("%1 minutes", 0, 10).arg(10), 10 * min);
c88e38a0f478 Fix times
unc0rr
parents: 8417
diff changeset
    29
    cbTime->addItem(HWApplication::tr("%1 minutes", 0, 30).arg(30), 30 * min);
c88e38a0f478 Fix times
unc0rr
parents: 8417
diff changeset
    30
    cbTime->addItem(HWApplication::tr("%1 hour", 0, 1).arg(1), 1 * hour);
c88e38a0f478 Fix times
unc0rr
parents: 8417
diff changeset
    31
    cbTime->addItem(HWApplication::tr("%1 hours", 0, 3).arg(3), 3 * hour);
c88e38a0f478 Fix times
unc0rr
parents: 8417
diff changeset
    32
    cbTime->addItem(HWApplication::tr("%1 hours", 0, 5).arg(5), 5 * hour);
c88e38a0f478 Fix times
unc0rr
parents: 8417
diff changeset
    33
    cbTime->addItem(HWApplication::tr("%1 hours", 0, 12).arg(12), 12 * hour);
c88e38a0f478 Fix times
unc0rr
parents: 8417
diff changeset
    34
    cbTime->addItem(HWApplication::tr("%1 day", 0, 1).arg(1), 1 * day);
c88e38a0f478 Fix times
unc0rr
parents: 8417
diff changeset
    35
    cbTime->addItem(HWApplication::tr("%1 days", 0, 3).arg(3), 3 * day);
c88e38a0f478 Fix times
unc0rr
parents: 8417
diff changeset
    36
    cbTime->addItem(HWApplication::tr("%1 days", 0, 7).arg(7), 7 * day);
c88e38a0f478 Fix times
unc0rr
parents: 8417
diff changeset
    37
    cbTime->addItem(HWApplication::tr("%1 days", 0, 14).arg(14), 14 * day);
8177
1fc36c2168c4 Some fixes
unc0rr
parents: 8159
diff changeset
    38
    cbTime->addItem(tr("permanent"), 3650 * 24 * 60 * 60);
8157
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    39
    cbTime->setCurrentIndex(0);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    40
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    41
    formLayout->addRow(tr("IP"), rbIP);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    42
    formLayout->addRow(tr("Nick"), rbNick);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    43
    formLayout->addRow(tr("IP/Nick"), leId);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    44
    formLayout->addRow(tr("Reason"), leReason);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    45
    formLayout->addRow(tr("Duration"), cbTime);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    46
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    47
    formLayout->setLabelAlignment(Qt::AlignRight);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    48
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    49
    QHBoxLayout * hbox = new QHBoxLayout();
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    50
    formLayout->addRow(hbox);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    51
    QPushButton * btnOk = new QPushButton(tr("Ok"), this);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    52
    QPushButton * btnCancel = new QPushButton(tr("Cancel"), this);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    53
    hbox->addStretch();
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    54
    hbox->addWidget(btnOk);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    55
    hbox->addWidget(btnCancel);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    56
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    57
    connect(btnOk, SIGNAL(clicked()), this, SLOT(okClicked()));
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    58
    connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
8159
e226be871b6e set window modality for new ban dialogs
koda
parents: 8157
diff changeset
    59
e226be871b6e set window modality for new ban dialogs
koda
parents: 8157
diff changeset
    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
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    62
}
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    63
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    64
bool BanDialog::byIP()
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    65
{
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    66
    return rbIP->isChecked();
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    67
}
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    68
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    69
int BanDialog::duration()
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    70
{
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    71
    return cbTime->itemData(cbTime->currentIndex()).toInt();
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    72
}
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    73
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    74
QString BanDialog::banId()
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    75
{
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    76
    return leId->text();
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    77
}
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    78
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    79
QString BanDialog::reason()
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    80
{
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    81
    return leReason->text().isEmpty() ? tr("you know why") : leReason->text();
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    82
}
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    83
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    84
void BanDialog::okClicked()
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    85
{
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    86
    if(leId->text().isEmpty())
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    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
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    95
        return;
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    96
    }
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    97
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    98
    accept();
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    99
}