File indexing completed on 2024-07-21 03:46:58

0001 /*
0002     This file is part of the KDE games kwin4 program
0003     SPDX-FileCopyrightText: 2006 Martin Heni <kde@heni-online.de>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "chatdlg.h"
0009 
0010 // own
0011 #include "kchatdialog.h"
0012 #include "kfourinline_debug.h"
0013 #include "kwin4player.h"
0014 // KDEGames
0015 #define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API
0016 #include <libkdegamesprivate/kgame/kgamechat.h>
0017 // KF
0018 #include <KLocalizedString>
0019 // Qt
0020 #include <QDialogButtonBox>
0021 #include <QGridLayout>
0022 #include <QGroupBox>
0023 #include <QPushButton>
0024 #include <QVBoxLayout>
0025 
0026 // Constructor for the chat widget. This widget
0027 // is derived from the libkdegames chat widget
0028 ChatDlg::ChatDlg(KGame *game, QWidget *parent)
0029     : QDialog(parent)
0030     , mChat()
0031     , mChatDlg()
0032 {
0033     setWindowTitle(i18nc("@title:window", "Chat Dlg"));
0034     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
0035     QVBoxLayout *mainLayout = new QVBoxLayout;
0036     setLayout(mainLayout);
0037     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0038     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0039     connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
0040     connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
0041     okButton->setAutoDefault(false);
0042     setModal(false);
0043     setMinimumSize(QSize(200, 200));
0044 
0045     QFrame *frame = new QFrame(this);
0046 
0047     QGridLayout *mGridLayout = new QGridLayout(frame);
0048     QGroupBox *b = new QGroupBox(i18n("Chat"), frame);
0049     QVBoxLayout *gboxLay = new QVBoxLayout(b);
0050     mChat = new KGameChat(game, 10000, b);
0051     gboxLay->addWidget(mChat);
0052     mGridLayout->addWidget(b, 0, 0);
0053 
0054     QPushButton *mButton = new QPushButton(i18n("Configure..."), frame);
0055     mButton->setAutoDefault(false);
0056     mGridLayout->addWidget(mButton, 1, 1);
0057 
0058     mainLayout->addWidget(frame);
0059     mainLayout->addWidget(buttonBox);
0060     adjustSize();
0061     mChat->setFocus();
0062 
0063     mChatDlg = new KChatDialog(mChat, frame, true);
0064     connect(mButton, &QPushButton::clicked, mChatDlg, &KChatDialog::show);
0065 }
0066 
0067 // Set the player in who does the chat. This should be the local player.
0068 void ChatDlg::setPlayer(KWin4Player *p)
0069 {
0070     if (!mChat) {
0071         qCCritical(KFOURINLINE_LOG) << "ChatDlg::setPlayer::Chat not defined can't set player";
0072         return;
0073     }
0074     if (!p) {
0075         qCCritical(KFOURINLINE_LOG) << "ChatDlg::setPlayer::Player not defined can't set player";
0076         return;
0077     }
0078     mChat->setFromPlayer(p);
0079 }
0080 
0081 #include "moc_chatdlg.cpp"