summaryrefslogtreecommitdiffstats
path: root/libtdegames/kchatdialog.cpp
blob: eaa6c6fcd599fa0e87905e2eba6f8a061306ac85 (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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
    This file is part of the TDE games library
    Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License version 2 as published by the Free Software Foundation.

    This library 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include "kchatdialog.h"

#include "kchatbase.h"

#include <tdelocale.h>
#include <tdefontdialog.h>

#include <tqlayout.h>
#include <tqlabel.h>
#include <tqpushbutton.h>

class KChatDialogPrivate
{
 public:
	KChatDialogPrivate()
	{
		mTextPage = 0;

		mNamePreview = 0;
		mTextPreview = 0;
		mSystemNamePreview = 0;
		mSystemTextPreview = 0;

		mChat = 0;
	}

	TQFrame* mTextPage;

	TQLabel* mNamePreview;
	TQLabel* mTextPreview;
	TQLabel* mSystemNamePreview;
	TQLabel* mSystemTextPreview;

	TQLineEdit* mMaxMessages;

	KChatBase* mChat;
};

KChatDialog::KChatDialog(KChatBase* chat, TQWidget* parent, bool modal) 
//	: KDialogBase(Tabbed, i18n("Configure Chat"), Ok|Default|Apply|Cancel, Ok, parent, 0, modal, true)
	: KDialogBase(Plain, i18n("Configure Chat"), Ok|Default|Apply|Cancel, Ok, parent, 0, modal, true)
{
 init();
 plugChatWidget(chat);
}

KChatDialog::KChatDialog(TQWidget* parent, bool modal) 
//	: KDialogBase(Tabbed, i18n("Configure Chat"), Ok|Default|Apply|Cancel, Ok, parent, 0, modal, true)
	: KDialogBase(Plain, i18n("Configure Chat"), Ok|Default|Apply|Cancel, Ok, parent, 0, modal, true)
{
 init();
}

KChatDialog::~KChatDialog()
{
 delete d;
}

void KChatDialog::init()
{
 d = new KChatDialogPrivate;
// d->mTextPage = addPage(i18n("&Messages"));// not a good name - game Messages?
 d->mTextPage = plainPage();
 TQGridLayout* layout = new TQGridLayout(d->mTextPage, 7, 2, KDialog::marginHint(), KDialog::spacingHint());

// General fonts
 TQPushButton* nameFont = new TQPushButton(i18n("Name Font..."), d->mTextPage);
 connect(nameFont, TQT_SIGNAL(pressed()), this, TQT_SLOT(slotGetNameFont()));
 layout->addWidget(nameFont, 0, 0);
 TQPushButton* textFont = new TQPushButton(i18n("Text Font..."), d->mTextPage);
 connect(textFont, TQT_SIGNAL(pressed()), this, TQT_SLOT(slotGetTextFont()));
 layout->addWidget(textFont, 0, 1);

 TQFrame* messagePreview = new TQFrame(d->mTextPage);
 messagePreview->setFrameStyle(TQFrame::StyledPanel | TQFrame::Sunken);
 TQHBoxLayout* messageLayout = new TQHBoxLayout(messagePreview);
 layout->addMultiCellWidget(messagePreview, 1, 1, 0, 1);

 d->mNamePreview = new TQLabel(i18n("Player: "), messagePreview);
 messageLayout->addWidget(d->mNamePreview, 0);
 d->mTextPreview = new TQLabel(i18n("This is a player message"), messagePreview);
 messageLayout->addWidget(d->mTextPreview, 1);

 layout->addRowSpacing(2, 10);
 
// System Message fonts
 TQLabel* systemMessages = new TQLabel(i18n("System Messages - Messages directly sent from the game"), d->mTextPage);
 layout->addMultiCellWidget(systemMessages, 3, 3, 0, 1);
 TQPushButton* systemNameFont = new TQPushButton(i18n("Name Font..."), d->mTextPage);
 connect(systemNameFont, TQT_SIGNAL(pressed()), this, TQT_SLOT(slotGetSystemNameFont()));
 layout->addWidget(systemNameFont, 4, 0);
 TQPushButton* systemTextFont = new TQPushButton(i18n("Text Font..."), d->mTextPage);
 connect(systemTextFont, TQT_SIGNAL(pressed()), this, TQT_SLOT(slotGetSystemTextFont()));
 layout->addWidget(systemTextFont, 4, 1);

 TQFrame* systemMessagePreview = new TQFrame(d->mTextPage);
 systemMessagePreview->setFrameStyle(TQFrame::StyledPanel | TQFrame::Sunken);
 TQHBoxLayout* systemMessageLayout = new TQHBoxLayout(systemMessagePreview);
 layout->addMultiCellWidget(systemMessagePreview, 5, 5, 0, 1);
 
 d->mSystemNamePreview = new TQLabel(i18n("--- Game: "), systemMessagePreview);
 systemMessageLayout->addWidget(d->mSystemNamePreview, 0);
 d->mSystemTextPreview = new TQLabel(i18n("This is a system message"), systemMessagePreview);
 systemMessageLayout->addWidget(d->mSystemTextPreview, 1);

// message count
 TQLabel* maxMessages = new TQLabel(i18n("Maximal number of messages (-1 = unlimited):"), d->mTextPage);
 layout->addWidget(maxMessages, 6, 0);
 d->mMaxMessages = new TQLineEdit(d->mTextPage);
 d->mMaxMessages->setText(TQString::number(-1));
 layout->addWidget(d->mMaxMessages, 6, 1);
}

void KChatDialog::slotGetNameFont()
{
 TQFont font = nameFont();
 TDEFontDialog::getFont(font);
 setNameFont(font);
}

void KChatDialog::slotGetTextFont()
{
 TQFont font = textFont();
 TDEFontDialog::getFont(font);
 setTextFont(font);
}

void KChatDialog::slotGetSystemNameFont()
{
 TQFont font = systemNameFont();
 TDEFontDialog::getFont(font);
 setSystemNameFont(font);
}

void KChatDialog::slotGetSystemTextFont()
{
 TQFont font = systemTextFont();
 TDEFontDialog::getFont(font);
 setSystemTextFont(font);
}

TQFont KChatDialog::nameFont() const
{
 return d->mNamePreview->font();
}

TQFont KChatDialog::textFont() const
{
 return d->mTextPreview->font();
}

TQFont KChatDialog::systemNameFont() const
{
 return d->mSystemNamePreview->font();
}

TQFont KChatDialog::systemTextFont() const
{
 return d->mSystemTextPreview->font();
}

void KChatDialog::plugChatWidget(KChatBase* widget, bool applyFonts)
{
 d->mChat = widget;
 if (applyFonts && d->mChat) {
	setNameFont(d->mChat->nameFont());
	setTextFont(d->mChat->messageFont());
	setSystemNameFont(d->mChat->systemNameFont());
	setSystemTextFont(d->mChat->systemMessageFont());
	setMaxMessages(d->mChat->maxItems());
 }
}

void KChatDialog::configureChatWidget(KChatBase* widget)
{
 if (!widget) {
	return;
 }
 widget->setNameFont(nameFont());
 widget->setMessageFont(textFont());

 widget->setSystemNameFont(systemNameFont());
 widget->setSystemMessageFont(systemTextFont());
 
 widget->setMaxItems(maxMessages());
}

void KChatDialog::slotOk()
{
 slotApply();
 KDialogBase::slotOk();
}

void KChatDialog::slotApply()
{
 configureChatWidget(d->mChat);
}

void KChatDialog::setNameFont(TQFont f)
{
 d->mNamePreview->setFont(f);
}

void KChatDialog::setTextFont(TQFont f)
{
 d->mTextPreview->setFont(f);
}

void KChatDialog::setSystemNameFont(TQFont f)
{
 d->mSystemNamePreview->setFont(f);
}

void KChatDialog::setSystemTextFont(TQFont f)
{
 d->mSystemTextPreview->setFont(f);
}

void KChatDialog::setMaxMessages(int max)
{
 d->mMaxMessages->setText(TQString::number(max));
}

int KChatDialog::maxMessages() const
{
 bool ok;
 int max = d->mMaxMessages->text().toInt(&ok);
 if (!ok) {
	return -1; // unlimited is default
 }
 return max;
}

#include "kchatdialog.moc"