File indexing completed on 2024-09-29 06:39:20

0001 /***************************************************************************
0002                           KsirkChatItem.cpp  -  description
0003                              -------------------
0004     begin                : Mon Sep 26 2006
0005     copyright            : (C) 2006-2007 by Gaƫl de Chalendar (aka Kleag)
0006     email                : kleag@free.fr
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either either version 2
0014    of the License, or (at your option) any later version.of the License, or     *
0015  *   (at your option) any later version.                                   *
0016  *                                                                         *
0017  *   You should have received a copy of the GNU General Public License
0018  *   along with this program; if not, write to the Free Software
0019  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0020  *   02110-1301, USA
0021  ***************************************************************************/
0022 #include "KsirkChatModel.h"
0023 #include "player.h"
0024 
0025 #include <KLocalizedString>
0026 
0027 #include <QLayout>
0028 #include <QApplication>
0029 #include <QColorDialog>
0030 #include <QInputDialog>
0031 namespace Ksirk
0032 {
0033    class KGameWindow;
0034 }
0035 
0036 // namespace GameLogic
0037 // {
0038 
0039 
0040 KsirkChatModel::KsirkChatModel(QObject* parent, Ksirk::KGameWindow* game)
0041      : KChatBaseModel(parent), m_messages(), m_game(game)
0042 {
0043 }
0044 
0045 int KsirkChatModel::rowCount(const QModelIndex &parent) const
0046 {
0047 //   qCDebug(KSIRK_LOG) << "KsirkChatModel::rowCount";
0048   if (parent.isValid())
0049     return 0;
0050   else
0051     return m_messages.size();
0052 }
0053 
0054 QVariant KsirkChatModel::data(const QModelIndex &index, int role) const
0055 {
0056   if (!index.isValid())
0057     return QVariant();
0058 
0059   if (role == Qt::DisplayRole)
0060   {
0061     KsirkChatItem p = m_messages[index.row()];
0062     return QVariant::fromValue(p);
0063   }
0064   return QVariant();
0065 }
0066 
0067 void KsirkChatModel::addMessage(const KsirkChatItem& message)
0068 {
0069   QString msg;
0070   if ((QString(message.first)).length() == 0) {
0071      msg = i18n("No message...");
0072   } else {
0073     msg = i18n("<b>%1:</b> %2", message.first, message.second);
0074      if (msg.length() > 77) {
0075         msg.resize(64);
0076         msg += " ...";
0077      }
0078   }
0079   m_game->titleChatMessage()->setText(msg);
0080 
0081   int row;
0082   row = m_messages.size();
0083   beginInsertRows(QModelIndex(), row, row);
0084   m_messages.push_back(message);
0085   endInsertRows();
0086 }
0087 
0088 void KsirkChatModel::addMessage(const QString& fromName, const QString& text)
0089 {
0090   addMessage(KsirkChatItem(fromName,text));
0091 }
0092 
0093 
0094 
0095 
0096 // } // closing namespace GameLogic
0097 
0098 // } // closing namespace Ksirk
0099 
0100 #include "moc_KsirkChatModel.cpp"