diff --git a/src/kchatdialog.cpp b/src/kchatdialog.cpp index 19fa9a0..f510743 100644 --- a/src/kchatdialog.cpp +++ b/src/kchatdialog.cpp @@ -1,285 +1,285 @@ /* This file is part of the KDE 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 "kfourinline_debug.h" #define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API #include #include #include #include #include #include #include #include #include #include #include class KChatDialogPrivate { public: KChatDialogPrivate() { mTextPage = nullptr; mNamePreview = nullptr; mTextPreview = nullptr; mSystemNamePreview = nullptr; mSystemTextPreview = nullptr; mChat = nullptr; } QFrame* mTextPage; QLabel* mNamePreview; QLabel* mTextPreview; QLabel* mSystemNamePreview; QLabel* mSystemTextPreview; QLineEdit* mMaxMessages; KChatBase* mChat; }; KChatDialog::KChatDialog(KChatBase* chat, QWidget* parent, bool modal) : QDialog(parent), d( new KChatDialogPrivate ) { setModal(modal); init(); plugChatWidget(chat); } KChatDialog::KChatDialog(QWidget* parent, bool modal) : QDialog(parent), d( new KChatDialogPrivate ) { setModal(modal); init(); } KChatDialog::~KChatDialog() { delete d; } void KChatDialog::init() { d->mTextPage = new QFrame( this ); QGridLayout* layout = new QGridLayout(d->mTextPage); setWindowTitle(i18n("Configure Chat")); buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::Apply); QWidget *mainWidget = new QWidget(this); setLayout(layout); layout->addWidget(mainWidget); QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); connect(buttonBox, &QDialogButtonBox::accepted, this, &KChatDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, this, &KChatDialog::reject); // General fonts QPushButton* nameFont = new QPushButton(i18n("Name Font..."), d->mTextPage); connect(nameFont, &QPushButton::pressed, this, &KChatDialog::slotGetNameFont); layout->addWidget(nameFont, 0, 0); QPushButton* textFont = new QPushButton(i18n("Text Font..."), d->mTextPage); connect(textFont, &QPushButton::pressed, this, &KChatDialog::slotGetTextFont); layout->addWidget(textFont, 0, 1); QFrame* messagePreview = new QFrame(d->mTextPage); messagePreview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); QHBoxLayout* messageLayout = new QHBoxLayout(messagePreview); layout->addWidget(messagePreview, 1, 0, 1, 2); d->mNamePreview = new QLabel(i18n("Player: "), messagePreview); messageLayout->addWidget(d->mNamePreview, 0); d->mTextPreview = new QLabel(i18n("This is a player message"), messagePreview); messageLayout->addWidget(d->mTextPreview, 1); layout->addItem(new QSpacerItem(0, 10), 2, 0); // System Message fonts QLabel* systemMessages = new QLabel(i18n("System Messages - Messages directly sent from the game"), d->mTextPage); layout->addWidget(systemMessages, 3, 0, 1, 2); QPushButton* systemNameFont = new QPushButton(i18n("Name Font..."), d->mTextPage); connect(systemNameFont, &QPushButton::pressed, this, &KChatDialog::slotGetSystemNameFont); layout->addWidget(systemNameFont, 4, 0); QPushButton* systemTextFont = new QPushButton(i18n("Text Font..."), d->mTextPage); connect(systemTextFont, &QPushButton::pressed, this, &KChatDialog::slotGetSystemTextFont); layout->addWidget(systemTextFont, 4, 1); QFrame* systemMessagePreview = new QFrame(d->mTextPage); systemMessagePreview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); QHBoxLayout* systemMessageLayout = new QHBoxLayout(systemMessagePreview); layout->addWidget(systemMessagePreview, 5, 0, 1, 2); d->mSystemNamePreview = new QLabel(i18n("--- Game: "), systemMessagePreview); systemMessageLayout->addWidget(d->mSystemNamePreview, 0); d->mSystemTextPreview = new QLabel(i18n("This is a system message"), systemMessagePreview); systemMessageLayout->addWidget(d->mSystemTextPreview, 1); // message count QLabel* maxMessages = new QLabel(i18n("Maximum number of messages (-1 = unlimited):"), d->mTextPage); layout->addWidget(maxMessages, 6, 0); d->mMaxMessages = new QLineEdit(d->mTextPage); d->mMaxMessages->setText(QString::number(-1)); layout->addWidget(d->mMaxMessages, 6, 1); layout->addWidget(buttonBox, 7, 0, 1, 2); connect(buttonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked, this, &KChatDialog::slotApply); connect(okButton, &QPushButton::clicked, this, &KChatDialog::slotOk); } void KChatDialog::slotGetNameFont() { QFont font = nameFont(); bool ok; font = QFontDialog::getFont(&ok, font, this); if (ok) setNameFont(font); } void KChatDialog::slotGetTextFont() { QFont font = textFont(); bool ok; font = QFontDialog::getFont(&ok, font, this); if (ok) setTextFont(font); } void KChatDialog::slotGetSystemNameFont() { QFont font = systemNameFont(); bool ok; font = QFontDialog::getFont(&ok, font, this); if (ok) setSystemNameFont(font); } void KChatDialog::slotGetSystemTextFont() { QFont font = systemTextFont(); bool ok; font = QFontDialog::getFont(&ok, font, this); if (ok) setSystemTextFont(font); } QFont KChatDialog::nameFont() const { return d->mNamePreview->font(); } QFont KChatDialog::textFont() const { return d->mTextPreview->font(); } QFont KChatDialog::systemNameFont() const { return d->mSystemNamePreview->font(); } QFont 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()); widget->saveConfig(); qCDebug(KFOURINLINE_LOG) << "Saved configuration"; } void KChatDialog::slotOk() { slotApply(); QDialog::accept(); } void KChatDialog::slotApply() { configureChatWidget(d->mChat); } -void KChatDialog::setNameFont(QFont f) +void KChatDialog::setNameFont(const QFont &f) { d->mNamePreview->setFont(f); } -void KChatDialog::setTextFont(QFont f) +void KChatDialog::setTextFont(const QFont &f) { d->mTextPreview->setFont(f); } -void KChatDialog::setSystemNameFont(QFont f) +void KChatDialog::setSystemNameFont(const QFont &f) { d->mSystemNamePreview->setFont(f); } -void KChatDialog::setSystemTextFont(QFont f) +void KChatDialog::setSystemTextFont(const QFont &f) { d->mSystemTextPreview->setFont(f); } void KChatDialog::setMaxMessages(int max) { d->mMaxMessages->setText(QString::number(max)); } int KChatDialog::maxMessages() const { bool ok; int max = d->mMaxMessages->text().toInt(&ok); if (!ok) { return -1; // unlimited is default } return max; } diff --git a/src/kchatdialog.h b/src/kchatdialog.h index 495a4de..107a2db 100644 --- a/src/kchatdialog.h +++ b/src/kchatdialog.h @@ -1,125 +1,125 @@ /* This file is part of the KDE 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. */ #ifndef __KCHATDIALOG_H__ #define __KCHATDIALOG_H__ #include class QDialogButtonBox; class QVBoxLayout; class KChatBase; class KChatDialogPrivate; /** * \class KChatDialog kchatdialog.h * */ class KChatDialog : public QDialog { Q_OBJECT public: /** * Construct a KChatDialog widget **/ explicit KChatDialog(QWidget* parent, bool modal = false); /** * Construct a KChatDialog widget which automatically configures the * @ref KChatBase widget. You probably want to use this as you don't * have to care about the configuration stuff yourself. **/ KChatDialog(KChatBase* chatWidget, QWidget* parent, bool modal = false); /** * Destruct the dialog **/ ~KChatDialog(); /** * @return The font that shall be used as the "name: " part of a normal * message. **/ QFont nameFont() const; /** * @return The font that shall be used for normal messages. **/ QFont textFont() const; /** * @return The font that shall be used as the "name: " part of a system * (game) message. **/ QFont systemNameFont() const; /** * @return The font that shall be used for a system (game) message. **/ QFont systemTextFont() const; /** * Set the widget that will be configured by the dialog. Use this if you * don't want to configure the widget yourself. * @param widget The chat widget that shall be configured * @param applyFonts Whether you want to have the current @ref KChatBase fonts as * defaults in the dialog **/ void plugChatWidget(KChatBase* widget, bool applyFonts = true); /** * Used to configure the chat widget according to the user settings. * This is called automatically if @ref plugChatWidget was called * before. * @param widget The chat widget that shall be configured **/ void configureChatWidget(KChatBase* widget); /** * @return The maximal allowed messages in the chat widget. -1 is * unlimited **/ int maxMessages() const; protected Q_SLOTS: void slotGetNameFont(); void slotGetTextFont(); void slotGetSystemNameFont(); void slotGetSystemTextFont(); virtual void slotApply(); virtual void slotOk(); private: - void setNameFont(QFont); - void setTextFont(QFont); - void setSystemNameFont(QFont); - void setSystemTextFont(QFont); + void setNameFont(const QFont&); + void setTextFont(const QFont&); + void setSystemNameFont(const QFont&); + void setSystemTextFont(const QFont&); void setMaxMessages(int max); private: void init(); private: KChatDialogPrivate* const d; QVBoxLayout* mainLayout; QDialogButtonBox* buttonBox; }; #endif diff --git a/src/score.h b/src/score.h index 929b000..7c849b9 100644 --- a/src/score.h +++ b/src/score.h @@ -1,132 +1,132 @@ #ifndef SCORE_H #define SCORE_H /* This file is part of the KDE games kwin4 program Copyright (c) 2006 Martin Heni This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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. */ // Qt includes #include class ScoreSprite; /** * The score object is a compatibility object to transfer the score between * the various players and status information entities and the score widget. */ class Score : public QObject { Q_OBJECT public: /** Construct a score object. * @param parent The parent object */ explicit Score(QObject* parent = nullptr); /** Set and update the level of the AI. * @param level The new level * @param no The player number [0,1] */ void setLevel(int level, int no) {mLevel[no] = level; update();} /** Set and update the player name. * @param name The new name * @param no The player number [0,1] */ - void setPlayerName(QString name,int no) {mName[no] = name;update();} + void setPlayerName(const QString &name,int no) {mName[no] = name;update();} /** Set and update whose turn it is (which player goes next). * @param no The player number [0,1] */ void setTurn(int no) {mTurn = no;update();} /** Set and update the amount of wins of a player. * @param amount The new amount * @param no The player number [0,1] */ void setWins(int amount, int no) {mWin[no] = amount; update();} /** Set and update the amount of losses of a player. * @param amount The new amount * @param no The player number [0,1] */ void setLosses(int amount, int no) {mLoss[no] = amount; update();} /** Set and update the amount of draws of a player. * @param amount The new amount * @param no The player number [0,1] */ void setRemis(int amount, int no) {mRemis[no] = amount; update();} /** Set and update the amount of aborted games of a player. * @param amount The new amount * @param no The player number [0,1] */ void setBreaks(int amount, int no) {mBrk[no] = amount; update();} /** Set and update the input device of a player. * @param type The new input device (KGameIO) [1,2,4,8], 8 is AI * @param no The player number [0,1] */ void setPlayedBy(int type, int no) {mInputDevice[no] = type; update();} /** Connect the score to a display sprite. This sprite will * be used for the update of the data. * @param s The display sprite */ void setDisplay(ScoreSprite* s); protected: /** Push all data into the display sprite. */ void update(); private: // The display sprite ScoreSprite* mDisplay; // The name of the players QString mName[2]; // The level of the AI(s) int mLevel[2]; // Whose turn is it int mTurn; // The amount of wins int mWin[2]; // The amount of draws int mRemis[2]; // The amount of losses int mLoss[2]; // The amount of aborted games int mBrk[2]; // The input device int mInputDevice[2]; }; #endif