summaryrefslogtreecommitdiffstats
path: root/kbackgammon/engines/fibs/kbginvite.cpp
blob: ef186f03ab3bd8d2fdaae4dcc2bba2a306c37e57 (plain)
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
/*
  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 <tqlabel.h>
#include <tqlayout.h>
#include <tqframe.h>
#include <tqspinbox.h>
#include <tqstring.h>

#include <tdelocale.h>
#include <klineedit.h>
#include <kpushbutton.h>
#include <kstdguiitem.h>

class KBgInvitePrivate {

public:

    KLineEdit    *mLe;
    TQSpinBox     *mSb;
    TQPushButton  *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();

    TQLabel *info = new TQLabel(this);

    d->mLe = new KLineEdit(this, "invitation dialog");
    d->mSb = new TQSpinBox(1, 999, 1, this, "spin box");

    d->mInvite    = new TQPushButton(i18n("&Invite"),    this);
    d->mResume    = new TQPushButton(i18n("&Resume"),    this);
    d->mUnlimited = new TQPushButton(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."));

    TQFrame *hLine = new TQFrame(this);
    hLine->setFrameStyle(TQFrame::Sunken|TQFrame::HLine);

    /*
     * Set up layouts
     */
    TQBoxLayout *vbox   = new TQVBoxLayout(this);

    TQBoxLayout *hbox_1 = new TQHBoxLayout(vbox);
    TQBoxLayout *hbox_2 = new TQHBoxLayout(vbox);
    TQBoxLayout *hbox_3 = new TQHBoxLayout(vbox);
    TQBoxLayout *hbox_4 = new TQHBoxLayout(vbox);
    TQBoxLayout *hbox_5 = new TQHBoxLayout(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, TQT_SIGNAL(clicked()), TQT_SLOT(unlimitedClicked()));
    connect(d->mResume,    TQT_SIGNAL(clicked()), TQT_SLOT(resumeClicked()));
    connect(d->mInvite,    TQT_SIGNAL(clicked()), TQT_SLOT(inviteClicked()));
    connect(d->mClose,     TQT_SIGNAL(clicked()), TQT_SLOT(hide()));
    connect(d->mCancel,    TQT_SIGNAL(clicked()), TQT_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 TQString &player)
{
    d->mLe->setText(player);
}

/*
 * Invitation with number
 */
void KBgInvite::inviteClicked()
{
    TQString tmp;
    emit inviteCommand(TQString("invite ") + d->mLe->text() + " " + tmp.setNum(d->mSb->value()));
}

/*
 * Invitation for unlimited match
 */
void KBgInvite::unlimitedClicked()
{
    emit inviteCommand(TQString("invite ") + d->mLe->text() + " unlimited");
}

/*
 * Resume a game
 */
void KBgInvite::resumeClicked()
{
    emit inviteCommand(TQString("invite ") + d->mLe->text());
}

/*
 * Slot for Cancel. clear everything to default.
 */
void KBgInvite::cancelClicked()
{
    d->mSb->setValue(1);
    d->mLe->clear();
}

// EOF