• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

libkdegames

kchatbaseitemdelegate.cpp

Go to the documentation of this file.
00001 /*
00002     This file is part of the KDE games library
00003     Copyright (C) 2007 Gael de Chalendar (aka Kleag) <kleag@free.fr>
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 "kchatbaseitemdelegate.h"
00021 #include "kchatbasemodel.h"
00022 
00023 #include <kdebug.h>
00024 #include <klocale.h>
00025 #include <QPainter>
00026 
00027 KChatBaseItemDelegate::KChatBaseItemDelegate(QObject *parent) : 
00028   QAbstractItemDelegate(parent)
00029 {
00030 }
00031 
00032 KChatBaseItemDelegate::~KChatBaseItemDelegate()
00033 {
00034 }
00035 
00036 void KChatBaseItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
00037                 const QModelIndex &index) const
00038 {
00039 //  kDebug() << "KChatBaseItemDelegate::paint";
00040  KChatBaseMessage m  = index.model()->data(index, Qt::DisplayRole).value<KChatBaseMessage>();
00041  paint(painter, option, index,m.first, m.second);
00042 }
00043 
00044 void KChatBaseItemDelegate::paint(QPainter *painter, 
00045                   const QStyleOptionViewItem &option,
00046                   const QModelIndex &index,
00047                    const QString& sender,
00048                    const QString& message) const
00049 {
00050 //  kDebug() << "KChatBaseItemDelegate::paint";
00051  QFontMetrics fm = painter->fontMetrics();
00052  painter->setFont(((KChatBaseModel*)index.model())->nameFont());
00053  painter->drawText(option.rect.x(), 
00054            QFontMetrics(option.font).height()+option.rect.y(), i18n("%1: ",sender));
00055  painter->setFont(((KChatBaseModel*)index.model())->messageFont());
00056  painter->drawText(option.rect.x() + 3 + QFontMetrics(((KChatBaseModel*)index.model())->nameFont()).width(i18n("%1: ",sender)),
00057            QFontMetrics(option.font).height()+option.rect.y(), message);
00058 }
00059 
00060 QSize KChatBaseItemDelegate::sizeHint(const QStyleOptionViewItem &  option ,
00061             const QModelIndex &  index ) const
00062 {
00063 //   kDebug() << "KChatBaseItemDelegate::sizeHint";
00064   KChatBaseMessage m  = index.model()->data(index, Qt::DisplayRole).value<KChatBaseMessage>();
00065   return sizeHint(option, index, m.first, m.second);
00066 }
00067 
00068 QSize KChatBaseItemDelegate::sizeHint(const QStyleOptionViewItem &  option ,
00069             const QModelIndex &  index,
00070                    const QString& sender,
00071                    const QString& message ) const
00072 {
00073 //   kDebug() << "KChatBaseItemDelegate::sizeHint";
00074   int w = 0;
00075   w += 6;
00076   w += QFontMetrics(option.font).width(sender+i18n("%1: ",sender));
00077   w += QFontMetrics(option.font).width(message);
00078   int h = 0;
00079   h += 2;
00080   if (QFontMetrics(((KChatBaseModel*)index.model())->nameFont()).lineSpacing() > 
00081     QFontMetrics(((KChatBaseModel*)index.model())->messageFont()).lineSpacing()) 
00082   {
00083     h += QFontMetrics(((KChatBaseModel*)index.model())->nameFont()).lineSpacing();
00084   } 
00085   else 
00086   {
00087     h += QFontMetrics(((KChatBaseModel*)index.model())->messageFont()).lineSpacing();
00088   }
00089   return QSize(w,h);
00090 }
00091 
00092 #include "kchatbaseitemdelegate.moc"

libkdegames

Skip menu "libkdegames"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • kblackbox
  • kgoldrunner
  • kmahjongg
  • ksquares
  • libkdegames
  •   highscore
  •   kgame
  •   kggzgames
  •   kggzmod
  •   kggznet
  • libkmahjongg
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal