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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
/* Yo Emacs, this -*- C++ -*-
Copyright (C) 1999-2001 Jens Hoefkens
jens@hoefkens.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
$Id$
*/
#include "kbginvite.h"
#include "kbginvite.moc"
#include <qlabel.h>
#include <qlayout.h>
#include <qframe.h>
#include <qspinbox.h>
#include <qstring.h>
#include <klocale.h>
#include <klineedit.h>
#include <kpushbutton.h>
#include <kstdguiitem.h>
class KBgInvitePrivate {
public:
KLineEdit *mLe;
QSpinBox *mSb;
QPushButton *mInvite, *mResume, *mUnlimited, *mCancel, *mClose;
};
/*
* Constructor is quite simple - most positioning is left to
* the toolkit.
*/
KBgInvite::KBgInvite(const char *name)
: KDialog(0, name, false)
{
setCaption(i18n("Invite Players"));
d = new KBgInvitePrivate();
QLabel *info = new QLabel(this);
d->mLe = new KLineEdit(this, "invitation dialog");
d->mSb = new QSpinBox(1, 999, 1, this, "spin box");
d->mInvite = new QPushButton(i18n("&Invite"), this);
d->mResume = new QPushButton(i18n("&Resume"), this);
d->mUnlimited = new QPushButton(i18n("&Unlimited"), this);
d->mClose = new KPushButton(KStdGuiItem::close(), this);
d->mCancel = new KPushButton(KStdGuiItem::clear(), this);
info->setText(i18n("Type the name of the player you want to invite in the first entry\n"
"field and select the desired match length in the spin box."));
QFrame *hLine = new QFrame(this);
hLine->setFrameStyle(QFrame::Sunken|QFrame::HLine);
/*
* Set up layouts
*/
QBoxLayout *vbox = new QVBoxLayout(this);
QBoxLayout *hbox_1 = new QHBoxLayout(vbox);
QBoxLayout *hbox_2 = new QHBoxLayout(vbox);
QBoxLayout *hbox_3 = new QHBoxLayout(vbox);
QBoxLayout *hbox_4 = new QHBoxLayout(vbox);
QBoxLayout *hbox_5 = new QHBoxLayout(vbox);
hbox_1->addWidget(info);
hbox_2->addWidget(d->mLe);
hbox_2->addWidget(d->mSb);
hbox_3->addWidget(hLine);
hbox_4->addWidget(d->mInvite);
hbox_4->addWidget(d->mResume);
hbox_4->addWidget(d->mUnlimited);
hbox_5->addWidget(d->mClose);
hbox_5->addWidget(d->mCancel);
/*
* Adjust widget sizes and resize the dialog
*/
KDialog::resizeLayout(this, marginHint(), spacingHint());
setMinimumSize(childrenRect().size());
vbox->activate();
resize(minimumSize());
/*
* Set focus and default buttons
*/
d->mInvite->setDefault(true);
d->mInvite->setAutoDefault(true);
d->mLe->setFocus();
/*
* Connect the buttons
*/
connect(d->mUnlimited, SIGNAL(clicked()), SLOT(unlimitedClicked()));
connect(d->mResume, SIGNAL(clicked()), SLOT(resumeClicked()));
connect(d->mInvite, SIGNAL(clicked()), SLOT(inviteClicked()));
connect(d->mClose, SIGNAL(clicked()), SLOT(hide()));
connect(d->mCancel, SIGNAL(clicked()), SLOT(cancelClicked()));
}
/*
* Destructor
*/
KBgInvite::~KBgInvite()
{
delete d;
}
/*
* After hiding, we tell our creator that we are ready to die.
*/
void KBgInvite::hide()
{
emit dialogDone();
}
/*
* Set player name
*/
void KBgInvite::setPlayer(const QString &player)
{
d->mLe->setText(player);
}
/*
* Invitation with number
*/
void KBgInvite::inviteClicked()
{
QString tmp;
emit inviteCommand(QString("invite ") + d->mLe->text() + " " + tmp.setNum(d->mSb->value()));
}
/*
* Invitation for unlimited match
*/
void KBgInvite::unlimitedClicked()
{
emit inviteCommand(QString("invite ") + d->mLe->text() + " unlimited");
}
/*
* Resume a game
*/
void KBgInvite::resumeClicked()
{
emit inviteCommand(QString("invite ") + d->mLe->text());
}
/*
* Slot for Cancel. clear everything to default.
*/
void KBgInvite::cancelClicked()
{
d->mSb->setValue(1);
d->mLe->clear();
}
// EOF
|