QTfrontend/ui/widget/roomnameprompt.cpp
author sheepluva
Mon, 10 Aug 2015 03:53:11 +0200
changeset 11046 47a8c19ecb60
parent 10108 c68cf030eded
child 11490 fb7817a5c2b1
permissions -rw-r--r--
more copyright fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8456
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     1
/*
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10108
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
8456
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     4
 *
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     8
 *
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    12
 * GNU General Public License for more details.
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    13
 *
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 9998
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
8456
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    17
 */
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    18
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    19
#include <QDialog>
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    20
#include <QVBoxLayout>
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    21
#include <QHBoxLayout>
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    22
#include <QPushButton>
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    23
#include <QLineEdit>
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    24
#include <QLabel>
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    25
#include <QDebug>
9541
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    26
#include <QCheckBox>
8456
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    27
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    28
#include "roomnameprompt.h"
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    29
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    30
RoomNamePrompt::RoomNamePrompt(QWidget* parent, const QString & roomName) : QDialog(parent)
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    31
{
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    32
    setModal(true);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    33
    setWindowFlags(Qt::Sheet);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    34
    setWindowModality(Qt::WindowModal);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    35
    setMinimumSize(360, 130);
9541
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    36
    resize(360, 180);
8456
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    37
    setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    38
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    39
    // Layout
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    40
    QVBoxLayout * dialogLayout = new QVBoxLayout(this);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    41
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    42
    // Label
9541
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    43
    label = new QLabel(tr("Enter a name for your room."), this);
8456
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    44
    label->setWordWrap(true);
9541
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    45
    dialogLayout->addWidget(label);
8456
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    46
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    47
    // Input box
9541
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    48
    leRoomName = new QLineEdit(this);
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    49
    leRoomName->setText(roomName);
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    50
    leRoomName->setMaxLength(59); // It didn't like 60 :(
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    51
    leRoomName->setStyleSheet("QLineEdit { padding: 3px; }");
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    52
    leRoomName->selectAll();
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    53
    dialogLayout->addWidget(leRoomName);
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    54
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    55
    cbSetPassword = new QCheckBox(this);
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    56
    cbSetPassword->setText(tr("set password"));
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    57
    dialogLayout->addWidget(cbSetPassword);
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    58
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    59
    lePassword = new QLineEdit(this);
9547
f9e82f34c904 Fix issue 662
unc0rr
parents: 9541
diff changeset
    60
    lePassword->setMaxLength(30);
f9e82f34c904 Fix issue 662
unc0rr
parents: 9541
diff changeset
    61
    lePassword->setStyleSheet("QLineEdit { padding: 3px; }");
9541
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    62
    lePassword->setEnabled(false);
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    63
    dialogLayout->addWidget(lePassword);
8456
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    64
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    65
    dialogLayout->addStretch(1);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    66
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    67
    // Buttons
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    68
    QHBoxLayout * buttonLayout = new QHBoxLayout();
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    69
    buttonLayout->addStretch(1);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    70
    dialogLayout->addLayout(buttonLayout);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    71
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    72
    QPushButton * btnCancel = new QPushButton(tr("Cancel"));
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    73
    QPushButton * btnOkay = new QPushButton(tr("Create room"));
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    74
    connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    75
    connect(btnOkay, SIGNAL(clicked()), this, SLOT(accept()));
9163
67334acaaac7 port all Q_WS_* to Q_OS_* so that we are forward compatible with Qt5
koda
parents: 9080
diff changeset
    76
#ifdef Q_OS_MAC
8622
2045bdf1b11b Resolves issue 528. Fixed platform-specific order of buttons on seed prompt and new room prompt. Fixed height of back button on all pages -- now aligns to bottom. On pagemain, feedback and dlc buttons no longer fixed size.
dag10
parents: 8456
diff changeset
    77
        buttonLayout->addWidget(btnCancel);
2045bdf1b11b Resolves issue 528. Fixed platform-specific order of buttons on seed prompt and new room prompt. Fixed height of back button on all pages -- now aligns to bottom. On pagemain, feedback and dlc buttons no longer fixed size.
dag10
parents: 8456
diff changeset
    78
        buttonLayout->addWidget(btnOkay);
2045bdf1b11b Resolves issue 528. Fixed platform-specific order of buttons on seed prompt and new room prompt. Fixed height of back button on all pages -- now aligns to bottom. On pagemain, feedback and dlc buttons no longer fixed size.
dag10
parents: 8456
diff changeset
    79
#else
2045bdf1b11b Resolves issue 528. Fixed platform-specific order of buttons on seed prompt and new room prompt. Fixed height of back button on all pages -- now aligns to bottom. On pagemain, feedback and dlc buttons no longer fixed size.
dag10
parents: 8456
diff changeset
    80
        buttonLayout->addWidget(btnOkay);
2045bdf1b11b Resolves issue 528. Fixed platform-specific order of buttons on seed prompt and new room prompt. Fixed height of back button on all pages -- now aligns to bottom. On pagemain, feedback and dlc buttons no longer fixed size.
dag10
parents: 8456
diff changeset
    81
        buttonLayout->addWidget(btnCancel);
2045bdf1b11b Resolves issue 528. Fixed platform-specific order of buttons on seed prompt and new room prompt. Fixed height of back button on all pages -- now aligns to bottom. On pagemain, feedback and dlc buttons no longer fixed size.
dag10
parents: 8456
diff changeset
    82
#endif
8456
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    83
    btnOkay->setDefault(true);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    84
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    85
    setStyleSheet("QPushButton { padding: 5px; }");
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    86
9541
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    87
    connect(cbSetPassword, SIGNAL(toggled(bool)), this, SLOT(checkBoxToggled()));
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    88
}
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    89
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    90
QString RoomNamePrompt::getRoomName()
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    91
{
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    92
    return leRoomName->text();
8456
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    93
}
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    94
9541
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    95
QString RoomNamePrompt::getPassword()
8456
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    96
{
9541
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    97
    return lePassword->text();
8456
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    98
}
9541
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
    99
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
   100
void RoomNamePrompt::checkBoxToggled()
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
   101
{
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
   102
    lePassword->setEnabled(cbSetPassword->isChecked());
312bb4384f33 - Frontend finally learns how to create passworded room
unc0rr
parents: 9163
diff changeset
   103
}