kchatdialog.cpp

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kchatdialog.h"
00021 
00022 #include "kchatbase.h"
00023 
00024 #include <klocale.h>
00025 #include <kfontdialog.h>
00026 #include <kdebug.h>
00027 
00028 #include <QLayout>
00029 #include <QLabel>
00030 #include <QPushButton>
00031 #include <QFrame>
00032 #include <QLineEdit>
00033 
00034 class KChatDialogPrivate
00035 {
00036  public:
00037         KChatDialogPrivate()
00038         {
00039                 mTextPage = 0;
00040 
00041                 mNamePreview = 0;
00042                 mTextPreview = 0;
00043                 mSystemNamePreview = 0;
00044                 mSystemTextPreview = 0;
00045 
00046                 mChat = 0;
00047         }
00048 
00049         QFrame* mTextPage;
00050 
00051         QLabel* mNamePreview;
00052         QLabel* mTextPreview;
00053         QLabel* mSystemNamePreview;
00054         QLabel* mSystemTextPreview;
00055 
00056         QLineEdit* mMaxMessages;
00057 
00058         KChatBase* mChat;
00059 };
00060 
00061 KChatDialog::KChatDialog(KChatBase* chat, QWidget* parent, bool modal) 
00062     : KDialog(parent),
00063       d( new KChatDialogPrivate )
00064 {
00065  setCaption(i18n("Configure Chat"));
00066  setButtons(Ok|Default|Apply|Cancel);
00067  setModal(modal);
00068  init();
00069  plugChatWidget(chat);
00070 }
00071 
00072 KChatDialog::KChatDialog(QWidget* parent, bool modal) 
00073     : KDialog(parent),
00074       d( new KChatDialogPrivate )
00075 {
00076  setCaption(i18n("Configure Chat"));
00077  setButtons(Ok|Default|Apply|Cancel);
00078  setModal(modal);
00079  init();
00080 //  init();
00081 }
00082 
00083 KChatDialog::~KChatDialog()
00084 {
00085  delete d;
00086 }
00087 
00088 void KChatDialog::init()
00089 {
00090  d->mTextPage = new QFrame( this );
00091  setMainWidget( d->mTextPage );
00092  QGridLayout* layout = new QGridLayout(d->mTextPage);
00093  layout->setMargin(KDialog::marginHint());
00094  layout->setSpacing(KDialog::spacingHint());
00095 
00096 // General fonts
00097  QPushButton* nameFont = new QPushButton(i18n("Name Font..."), d->mTextPage);
00098  connect(nameFont, SIGNAL(pressed()), this, SLOT(slotGetNameFont()));
00099  layout->addWidget(nameFont, 0, 0);
00100  QPushButton* textFont = new QPushButton(i18n("Text Font..."), d->mTextPage);
00101  connect(textFont, SIGNAL(pressed()), this, SLOT(slotGetTextFont()));
00102  layout->addWidget(textFont, 0, 1);
00103 
00104  QFrame* messagePreview = new QFrame(d->mTextPage);
00105  messagePreview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
00106  QHBoxLayout* messageLayout = new QHBoxLayout(messagePreview);
00107  layout->addWidget(messagePreview, 1, 0, 1, 2);
00108 
00109  d->mNamePreview = new QLabel(i18n("Player: "), messagePreview);
00110  messageLayout->addWidget(d->mNamePreview, 0);
00111  d->mTextPreview = new QLabel(i18n("This is a player message"), messagePreview);
00112  messageLayout->addWidget(d->mTextPreview, 1);
00113 
00114  layout->addItem(new QSpacerItem(0, 10), 2, 0);
00115  
00116 // System Message fonts
00117  QLabel* systemMessages = new QLabel(i18n("System Messages - Messages directly sent from the game"), d->mTextPage);
00118  layout->addWidget(systemMessages, 3, 0, 1, 2);
00119  QPushButton* systemNameFont = new QPushButton(i18n("Name Font..."), d->mTextPage);
00120  connect(systemNameFont, SIGNAL(pressed()), this, SLOT(slotGetSystemNameFont()));
00121  layout->addWidget(systemNameFont, 4, 0);
00122  QPushButton* systemTextFont = new QPushButton(i18n("Text Font..."), d->mTextPage);
00123  connect(systemTextFont, SIGNAL(pressed()), this, SLOT(slotGetSystemTextFont()));
00124  layout->addWidget(systemTextFont, 4, 1);
00125 
00126  QFrame* systemMessagePreview = new QFrame(d->mTextPage);
00127  systemMessagePreview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
00128  QHBoxLayout* systemMessageLayout = new QHBoxLayout(systemMessagePreview);
00129  layout->addWidget(systemMessagePreview, 5, 0, 1, 2);
00130  
00131  d->mSystemNamePreview = new QLabel(i18n("--- Game: "), systemMessagePreview);
00132  systemMessageLayout->addWidget(d->mSystemNamePreview, 0);
00133  d->mSystemTextPreview = new QLabel(i18n("This is a system message"), systemMessagePreview);
00134  systemMessageLayout->addWidget(d->mSystemTextPreview, 1);
00135 
00136 // message count
00137  QLabel* maxMessages = new QLabel(i18n("Maximum number of messages (-1 = unlimited):"), d->mTextPage);
00138  layout->addWidget(maxMessages, 6, 0);
00139  d->mMaxMessages = new QLineEdit(d->mTextPage);
00140  d->mMaxMessages->setText(QString::number(-1));
00141  layout->addWidget(d->mMaxMessages, 6, 1);
00142  connect(this, SIGNAL(applyClicked()),this,SLOT(slotApply()));
00143  connect(this, SIGNAL(okClicked()),this,SLOT(slotOk()));
00144 }
00145 
00146 void KChatDialog::slotGetNameFont()
00147 {
00148  QFont font = nameFont();
00149  KFontDialog::getFont(font);
00150  setNameFont(font);
00151 }
00152 
00153 void KChatDialog::slotGetTextFont()
00154 {
00155  QFont font = textFont();
00156  KFontDialog::getFont(font);
00157  setTextFont(font);
00158 }
00159 
00160 void KChatDialog::slotGetSystemNameFont()
00161 {
00162  QFont font = systemNameFont();
00163  KFontDialog::getFont(font);
00164  setSystemNameFont(font);
00165 }
00166 
00167 void KChatDialog::slotGetSystemTextFont()
00168 {
00169  QFont font = systemTextFont();
00170  KFontDialog::getFont(font);
00171  setSystemTextFont(font);
00172 }
00173 
00174 QFont KChatDialog::nameFont() const
00175 {
00176  return d->mNamePreview->font();
00177 }
00178 
00179 QFont KChatDialog::textFont() const
00180 {
00181  return d->mTextPreview->font();
00182 }
00183 
00184 QFont KChatDialog::systemNameFont() const
00185 {
00186  return d->mSystemNamePreview->font();
00187 }
00188 
00189 QFont KChatDialog::systemTextFont() const
00190 {
00191  return d->mSystemTextPreview->font();
00192 }
00193 
00194 void KChatDialog::plugChatWidget(KChatBase* widget, bool applyFonts)
00195 {
00196  d->mChat = widget;
00197  if (applyFonts && d->mChat) {
00198         setNameFont(d->mChat->nameFont());
00199         setTextFont(d->mChat->messageFont());
00200         setSystemNameFont(d->mChat->systemNameFont());
00201         setSystemTextFont(d->mChat->systemMessageFont());
00202         setMaxMessages(d->mChat->maxItems());
00203  }
00204 }
00205 
00206 void KChatDialog::configureChatWidget(KChatBase* widget)
00207 {
00208  if (!widget) {
00209         return;
00210  }
00211  widget->setNameFont(nameFont());
00212  widget->setMessageFont(textFont());
00213 
00214  widget->setSystemNameFont(systemNameFont());
00215  widget->setSystemMessageFont(systemTextFont());
00216  
00217  widget->setMaxItems(maxMessages());
00218  widget->saveConfig();
00219  kDebug() << "Saved configuration";
00220 }
00221 
00222 void KChatDialog::slotOk()
00223 {
00224  slotApply();
00225  KDialog::accept();
00226 }
00227 
00228 void KChatDialog::slotApply()
00229 {
00230  configureChatWidget(d->mChat);
00231 }
00232 
00233 void KChatDialog::setNameFont(QFont f)
00234 {
00235  d->mNamePreview->setFont(f);
00236 }
00237 
00238 void KChatDialog::setTextFont(QFont f)
00239 {
00240  d->mTextPreview->setFont(f);
00241 }
00242 
00243 void KChatDialog::setSystemNameFont(QFont f)
00244 {
00245  d->mSystemNamePreview->setFont(f);
00246 }
00247 
00248 void KChatDialog::setSystemTextFont(QFont f)
00249 {
00250  d->mSystemTextPreview->setFont(f);
00251 }
00252 
00253 void KChatDialog::setMaxMessages(int max)
00254 {
00255  d->mMaxMessages->setText(QString::number(max));
00256 }
00257 
00258 int KChatDialog::maxMessages() const
00259 {
00260  bool ok;
00261  int max = d->mMaxMessages->text().toInt(&ok);
00262  if (!ok) {
00263         return -1; // unlimited is default
00264  }
00265  return max;
00266 }
00267 
00268 #include "kchatdialog.moc"

Generated on Sun Mar 16 08:02:52 2008 for Libkdegames by  doxygen 1.5.3