~kubuntu-members/libkdegames/4.11

« back to all changes in this revision

Viewing changes to kchatdialog.cpp

  • Committer: Stefan Majewsky
  • Date: 2012-05-01 15:34:35 UTC
  • Revision ID: git-v1:82376fb5ca6f29f862641b6ca68603cb76258831
Begin to move stuff into libkdegamesprivate.

The build is now broken because I'm moving stuff without adjusting the
CMake files. But I figured it's cleaner to have the move in one commit
and the various edits in CMake and source files in the next commits.

svn path=/trunk/KDE/kdegames/libkdegames/; revision=1292461

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    This file is part of the KDE games library
3
 
    Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
4
 
 
5
 
    This library is free software; you can redistribute it and/or
6
 
    modify it under the terms of the GNU Library General Public
7
 
    License version 2 as published by the Free Software Foundation.
8
 
 
9
 
    This library is distributed in the hope that it will be useful,
10
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 
    Library General Public License for more details.
13
 
 
14
 
    You should have received a copy of the GNU Library General Public License
15
 
    along with this library; see the file COPYING.LIB.  If not, write to
16
 
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 
    Boston, MA 02110-1301, USA.
18
 
*/
19
 
 
20
 
#include "kchatdialog.h"
21
 
 
22
 
#include "kchatbase.h"
23
 
 
24
 
#include <klocale.h>
25
 
#include <kfontdialog.h>
26
 
#include <kdebug.h>
27
 
#include <klineedit.h>
28
 
 
29
 
#include <QLayout>
30
 
#include <QLabel>
31
 
#include <QPushButton>
32
 
#include <QFrame>
33
 
 
34
 
class KChatDialogPrivate
35
 
{
36
 
 public:
37
 
        KChatDialogPrivate()
38
 
        {
39
 
                mTextPage = 0;
40
 
 
41
 
                mNamePreview = 0;
42
 
                mTextPreview = 0;
43
 
                mSystemNamePreview = 0;
44
 
                mSystemTextPreview = 0;
45
 
 
46
 
                mChat = 0;
47
 
        }
48
 
 
49
 
        QFrame* mTextPage;
50
 
 
51
 
        QLabel* mNamePreview;
52
 
        QLabel* mTextPreview;
53
 
        QLabel* mSystemNamePreview;
54
 
        QLabel* mSystemTextPreview;
55
 
 
56
 
        KLineEdit* mMaxMessages;
57
 
 
58
 
        KChatBase* mChat;
59
 
};
60
 
 
61
 
KChatDialog::KChatDialog(KChatBase* chat, QWidget* parent, bool modal) 
62
 
    : KDialog(parent),
63
 
      d( new KChatDialogPrivate )
64
 
{
65
 
 setCaption(i18n("Configure Chat"));
66
 
 setButtons(Ok|Default|Apply|Cancel);
67
 
 setModal(modal);
68
 
 init();
69
 
 plugChatWidget(chat);
70
 
}
71
 
 
72
 
KChatDialog::KChatDialog(QWidget* parent, bool modal) 
73
 
    : KDialog(parent),
74
 
      d( new KChatDialogPrivate )
75
 
{
76
 
 setCaption(i18n("Configure Chat"));
77
 
 setButtons(Ok|Default|Apply|Cancel);
78
 
 setModal(modal);
79
 
 init();
80
 
//  init();
81
 
}
82
 
 
83
 
KChatDialog::~KChatDialog()
84
 
{
85
 
 delete d;
86
 
}
87
 
 
88
 
void KChatDialog::init()
89
 
{
90
 
 d->mTextPage = new QFrame( this );
91
 
 setMainWidget( d->mTextPage );
92
 
 QGridLayout* layout = new QGridLayout(d->mTextPage);
93
 
 layout->setMargin(KDialog::marginHint());
94
 
 layout->setSpacing(KDialog::spacingHint());
95
 
 
96
 
// General fonts
97
 
 QPushButton* nameFont = new QPushButton(i18n("Name Font..."), d->mTextPage);
98
 
 connect(nameFont, SIGNAL(pressed()), this, SLOT(slotGetNameFont()));
99
 
 layout->addWidget(nameFont, 0, 0);
100
 
 QPushButton* textFont = new QPushButton(i18n("Text Font..."), d->mTextPage);
101
 
 connect(textFont, SIGNAL(pressed()), this, SLOT(slotGetTextFont()));
102
 
 layout->addWidget(textFont, 0, 1);
103
 
 
104
 
 QFrame* messagePreview = new QFrame(d->mTextPage);
105
 
 messagePreview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
106
 
 QHBoxLayout* messageLayout = new QHBoxLayout(messagePreview);
107
 
 layout->addWidget(messagePreview, 1, 0, 1, 2);
108
 
 
109
 
 d->mNamePreview = new QLabel(i18n("Player: "), messagePreview);
110
 
 messageLayout->addWidget(d->mNamePreview, 0);
111
 
 d->mTextPreview = new QLabel(i18n("This is a player message"), messagePreview);
112
 
 messageLayout->addWidget(d->mTextPreview, 1);
113
 
 
114
 
 layout->addItem(new QSpacerItem(0, 10), 2, 0);
115
 
 
116
 
// System Message fonts
117
 
 QLabel* systemMessages = new QLabel(i18n("System Messages - Messages directly sent from the game"), d->mTextPage);
118
 
 layout->addWidget(systemMessages, 3, 0, 1, 2);
119
 
 QPushButton* systemNameFont = new QPushButton(i18n("Name Font..."), d->mTextPage);
120
 
 connect(systemNameFont, SIGNAL(pressed()), this, SLOT(slotGetSystemNameFont()));
121
 
 layout->addWidget(systemNameFont, 4, 0);
122
 
 QPushButton* systemTextFont = new QPushButton(i18n("Text Font..."), d->mTextPage);
123
 
 connect(systemTextFont, SIGNAL(pressed()), this, SLOT(slotGetSystemTextFont()));
124
 
 layout->addWidget(systemTextFont, 4, 1);
125
 
 
126
 
 QFrame* systemMessagePreview = new QFrame(d->mTextPage);
127
 
 systemMessagePreview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
128
 
 QHBoxLayout* systemMessageLayout = new QHBoxLayout(systemMessagePreview);
129
 
 layout->addWidget(systemMessagePreview, 5, 0, 1, 2);
130
 
 
131
 
 d->mSystemNamePreview = new QLabel(i18n("--- Game: "), systemMessagePreview);
132
 
 systemMessageLayout->addWidget(d->mSystemNamePreview, 0);
133
 
 d->mSystemTextPreview = new QLabel(i18n("This is a system message"), systemMessagePreview);
134
 
 systemMessageLayout->addWidget(d->mSystemTextPreview, 1);
135
 
 
136
 
// message count
137
 
 QLabel* maxMessages = new QLabel(i18n("Maximum number of messages (-1 = unlimited):"), d->mTextPage);
138
 
 layout->addWidget(maxMessages, 6, 0);
139
 
 d->mMaxMessages = new KLineEdit(d->mTextPage);
140
 
 d->mMaxMessages->setText(QString::number(-1));
141
 
 layout->addWidget(d->mMaxMessages, 6, 1);
142
 
 connect(this, SIGNAL(applyClicked()),this,SLOT(slotApply()));
143
 
 connect(this, SIGNAL(okClicked()),this,SLOT(slotOk()));
144
 
}
145
 
 
146
 
void KChatDialog::slotGetNameFont()
147
 
{
148
 
 QFont font = nameFont();
149
 
 KFontDialog::getFont(font);
150
 
 setNameFont(font);
151
 
}
152
 
 
153
 
void KChatDialog::slotGetTextFont()
154
 
{
155
 
 QFont font = textFont();
156
 
 KFontDialog::getFont(font);
157
 
 setTextFont(font);
158
 
}
159
 
 
160
 
void KChatDialog::slotGetSystemNameFont()
161
 
{
162
 
 QFont font = systemNameFont();
163
 
 KFontDialog::getFont(font);
164
 
 setSystemNameFont(font);
165
 
}
166
 
 
167
 
void KChatDialog::slotGetSystemTextFont()
168
 
{
169
 
 QFont font = systemTextFont();
170
 
 KFontDialog::getFont(font);
171
 
 setSystemTextFont(font);
172
 
}
173
 
 
174
 
QFont KChatDialog::nameFont() const
175
 
{
176
 
 return d->mNamePreview->font();
177
 
}
178
 
 
179
 
QFont KChatDialog::textFont() const
180
 
{
181
 
 return d->mTextPreview->font();
182
 
}
183
 
 
184
 
QFont KChatDialog::systemNameFont() const
185
 
{
186
 
 return d->mSystemNamePreview->font();
187
 
}
188
 
 
189
 
QFont KChatDialog::systemTextFont() const
190
 
{
191
 
 return d->mSystemTextPreview->font();
192
 
}
193
 
 
194
 
void KChatDialog::plugChatWidget(KChatBase* widget, bool applyFonts)
195
 
{
196
 
 d->mChat = widget;
197
 
 if (applyFonts && d->mChat) {
198
 
        setNameFont(d->mChat->nameFont());
199
 
        setTextFont(d->mChat->messageFont());
200
 
        setSystemNameFont(d->mChat->systemNameFont());
201
 
        setSystemTextFont(d->mChat->systemMessageFont());
202
 
        setMaxMessages(d->mChat->maxItems());
203
 
 }
204
 
}
205
 
 
206
 
void KChatDialog::configureChatWidget(KChatBase* widget)
207
 
{
208
 
 if (!widget) {
209
 
        return;
210
 
 }
211
 
 widget->setNameFont(nameFont());
212
 
 widget->setMessageFont(textFont());
213
 
 
214
 
 widget->setSystemNameFont(systemNameFont());
215
 
 widget->setSystemMessageFont(systemTextFont());
216
 
 
217
 
 widget->setMaxItems(maxMessages());
218
 
 widget->saveConfig();
219
 
 kDebug() << "Saved configuration";
220
 
}
221
 
 
222
 
void KChatDialog::slotOk()
223
 
{
224
 
 slotApply();
225
 
 KDialog::accept();
226
 
}
227
 
 
228
 
void KChatDialog::slotApply()
229
 
{
230
 
 configureChatWidget(d->mChat);
231
 
}
232
 
 
233
 
void KChatDialog::setNameFont(QFont f)
234
 
{
235
 
 d->mNamePreview->setFont(f);
236
 
}
237
 
 
238
 
void KChatDialog::setTextFont(QFont f)
239
 
{
240
 
 d->mTextPreview->setFont(f);
241
 
}
242
 
 
243
 
void KChatDialog::setSystemNameFont(QFont f)
244
 
{
245
 
 d->mSystemNamePreview->setFont(f);
246
 
}
247
 
 
248
 
void KChatDialog::setSystemTextFont(QFont f)
249
 
{
250
 
 d->mSystemTextPreview->setFont(f);
251
 
}
252
 
 
253
 
void KChatDialog::setMaxMessages(int max)
254
 
{
255
 
 d->mMaxMessages->setText(QString::number(max));
256
 
}
257
 
 
258
 
int KChatDialog::maxMessages() const
259
 
{
260
 
 bool ok;
261
 
 int max = d->mMaxMessages->text().toInt(&ok);
262
 
 if (!ok) {
263
 
        return -1; // unlimited is default
264
 
 }
265
 
 return max;
266
 
}
267
 
 
268
 
#include "kchatdialog.moc"