libkdegames Library API Documentation

kchatdialog.cpp

00001 /* 00002 This file is part of the KDE games library 00003 Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de) 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License version 2 as published by the Free Software Foundation. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #include "kchatdialog.h" 00021 00022 #include "kchatbase.h" 00023 00024 #include <klocale.h> 00025 #include <kfontdialog.h> 00026 00027 #include <qlayout.h> 00028 #include <qlabel.h> 00029 #include <qpushbutton.h> 00030 00031 class KChatDialogPrivate 00032 { 00033 public: 00034 KChatDialogPrivate() 00035 { 00036 mTextPage = 0; 00037 00038 mNamePreview = 0; 00039 mTextPreview = 0; 00040 mSystemNamePreview = 0; 00041 mSystemTextPreview = 0; 00042 00043 mChat = 0; 00044 } 00045 00046 QFrame* mTextPage; 00047 00048 QLabel* mNamePreview; 00049 QLabel* mTextPreview; 00050 QLabel* mSystemNamePreview; 00051 QLabel* mSystemTextPreview; 00052 00053 QLineEdit* mMaxMessages; 00054 00055 KChatBase* mChat; 00056 }; 00057 00058 KChatDialog::KChatDialog(KChatBase* chat, QWidget* parent, bool modal) 00059 // : KDialogBase(Tabbed, i18n("Configure Chat"), Ok|Default|Apply|Cancel, Ok, parent, 0, modal, true) 00060 : KDialogBase(Plain, i18n("Configure Chat"), Ok|Default|Apply|Cancel, Ok, parent, 0, modal, true) 00061 { 00062 init(); 00063 plugChatWidget(chat); 00064 } 00065 00066 KChatDialog::KChatDialog(QWidget* parent, bool modal) 00067 // : KDialogBase(Tabbed, i18n("Configure Chat"), Ok|Default|Apply|Cancel, Ok, parent, 0, modal, true) 00068 : KDialogBase(Plain, i18n("Configure Chat"), Ok|Default|Apply|Cancel, Ok, parent, 0, modal, true) 00069 { 00070 init(); 00071 } 00072 00073 KChatDialog::~KChatDialog() 00074 { 00075 delete d; 00076 } 00077 00078 void KChatDialog::init() 00079 { 00080 d = new KChatDialogPrivate; 00081 // d->mTextPage = addPage(i18n("&Messages"));// not a good name - game Messages? 00082 d->mTextPage = plainPage(); 00083 QGridLayout* layout = new QGridLayout(d->mTextPage, 7, 2, KDialog::marginHint(), KDialog::spacingHint()); 00084 00085 // General fonts 00086 QPushButton* nameFont = new QPushButton(i18n("Name Font..."), d->mTextPage); 00087 connect(nameFont, SIGNAL(pressed()), this, SLOT(slotGetNameFont())); 00088 layout->addWidget(nameFont, 0, 0); 00089 QPushButton* textFont = new QPushButton(i18n("Text Font..."), d->mTextPage); 00090 connect(textFont, SIGNAL(pressed()), this, SLOT(slotGetTextFont())); 00091 layout->addWidget(textFont, 0, 1); 00092 00093 QFrame* messagePreview = new QFrame(d->mTextPage); 00094 messagePreview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); 00095 QHBoxLayout* messageLayout = new QHBoxLayout(messagePreview); 00096 layout->addMultiCellWidget(messagePreview, 1, 1, 0, 1); 00097 00098 d->mNamePreview = new QLabel(i18n("Player: "), messagePreview); 00099 messageLayout->addWidget(d->mNamePreview, 0); 00100 d->mTextPreview = new QLabel(i18n("This is a player message"), messagePreview); 00101 messageLayout->addWidget(d->mTextPreview, 1); 00102 00103 layout->addRowSpacing(2, 10); 00104 00105 // System Message fonts 00106 QLabel* systemMessages = new QLabel(i18n("System Messages - Messages directly sent from the game"), d->mTextPage); 00107 layout->addMultiCellWidget(systemMessages, 3, 3, 0, 1); 00108 QPushButton* systemNameFont = new QPushButton(i18n("Name Font..."), d->mTextPage); 00109 connect(systemNameFont, SIGNAL(pressed()), this, SLOT(slotGetSystemNameFont())); 00110 layout->addWidget(systemNameFont, 4, 0); 00111 QPushButton* systemTextFont = new QPushButton(i18n("Text Font..."), d->mTextPage); 00112 connect(systemTextFont, SIGNAL(pressed()), this, SLOT(slotGetSystemTextFont())); 00113 layout->addWidget(systemTextFont, 4, 1); 00114 00115 QFrame* systemMessagePreview = new QFrame(d->mTextPage); 00116 systemMessagePreview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); 00117 QHBoxLayout* systemMessageLayout = new QHBoxLayout(systemMessagePreview); 00118 layout->addMultiCellWidget(systemMessagePreview, 5, 5, 0, 1); 00119 00120 d->mSystemNamePreview = new QLabel(i18n("--- Game: "), systemMessagePreview); 00121 systemMessageLayout->addWidget(d->mSystemNamePreview, 0); 00122 d->mSystemTextPreview = new QLabel(i18n("This is a system message"), systemMessagePreview); 00123 systemMessageLayout->addWidget(d->mSystemTextPreview, 1); 00124 00125 // message count 00126 QLabel* maxMessages = new QLabel(i18n("Maximal number of messages (-1 = unlimited):"), d->mTextPage); 00127 layout->addWidget(maxMessages, 6, 0); 00128 d->mMaxMessages = new QLineEdit(d->mTextPage); 00129 d->mMaxMessages->setText(QString::number(-1)); 00130 layout->addWidget(d->mMaxMessages, 6, 1); 00131 } 00132 00133 void KChatDialog::slotGetNameFont() 00134 { 00135 QFont font = nameFont(); 00136 KFontDialog::getFont(font); 00137 setNameFont(font); 00138 } 00139 00140 void KChatDialog::slotGetTextFont() 00141 { 00142 QFont font = textFont(); 00143 KFontDialog::getFont(font); 00144 setTextFont(font); 00145 } 00146 00147 void KChatDialog::slotGetSystemNameFont() 00148 { 00149 QFont font = systemNameFont(); 00150 KFontDialog::getFont(font); 00151 setSystemNameFont(font); 00152 } 00153 00154 void KChatDialog::slotGetSystemTextFont() 00155 { 00156 QFont font = systemTextFont(); 00157 KFontDialog::getFont(font); 00158 setSystemTextFont(font); 00159 } 00160 00161 QFont KChatDialog::nameFont() const 00162 { 00163 return d->mNamePreview->font(); 00164 } 00165 00166 QFont KChatDialog::textFont() const 00167 { 00168 return d->mTextPreview->font(); 00169 } 00170 00171 QFont KChatDialog::systemNameFont() const 00172 { 00173 return d->mSystemNamePreview->font(); 00174 } 00175 00176 QFont KChatDialog::systemTextFont() const 00177 { 00178 return d->mSystemTextPreview->font(); 00179 } 00180 00181 void KChatDialog::plugChatWidget(KChatBase* widget, bool applyFonts) 00182 { 00183 d->mChat = widget; 00184 if (applyFonts && d->mChat) { 00185 setNameFont(d->mChat->nameFont()); 00186 setTextFont(d->mChat->messageFont()); 00187 setSystemNameFont(d->mChat->systemNameFont()); 00188 setSystemTextFont(d->mChat->systemMessageFont()); 00189 setMaxMessages(d->mChat->maxItems()); 00190 } 00191 } 00192 00193 void KChatDialog::configureChatWidget(KChatBase* widget) 00194 { 00195 if (!widget) { 00196 return; 00197 } 00198 widget->setNameFont(nameFont()); 00199 widget->setMessageFont(textFont()); 00200 00201 widget->setSystemNameFont(systemNameFont()); 00202 widget->setSystemMessageFont(systemTextFont()); 00203 00204 widget->setMaxItems(maxMessages()); 00205 } 00206 00207 void KChatDialog::slotOk() 00208 { 00209 slotApply(); 00210 KDialogBase::slotOk(); 00211 } 00212 00213 void KChatDialog::slotApply() 00214 { 00215 configureChatWidget(d->mChat); 00216 } 00217 00218 void KChatDialog::setNameFont(QFont f) 00219 { 00220 d->mNamePreview->setFont(f); 00221 } 00222 00223 void KChatDialog::setTextFont(QFont f) 00224 { 00225 d->mTextPreview->setFont(f); 00226 } 00227 00228 void KChatDialog::setSystemNameFont(QFont f) 00229 { 00230 d->mSystemNamePreview->setFont(f); 00231 } 00232 00233 void KChatDialog::setSystemTextFont(QFont f) 00234 { 00235 d->mSystemTextPreview->setFont(f); 00236 } 00237 00238 void KChatDialog::setMaxMessages(int max) 00239 { 00240 d->mMaxMessages->setText(QString::number(max)); 00241 } 00242 00243 int KChatDialog::maxMessages() const 00244 { 00245 bool ok; 00246 int max = d->mMaxMessages->text().toInt(&ok); 00247 if (!ok) { 00248 return -1; // unlimited is default 00249 } 00250 return max; 00251 } 00252 00253 #include "kchatdialog.moc"
KDE Logo
This file is part of the documentation for libkdegames Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Sep 21 12:08:02 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003