• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

libkdegames/libkdegamesprivate

  • sources
  • kde-4.14
  • kdegames
  • libkdegames
  • libkdegamesprivate
kchatbaseitemdelegate.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the KDE games library
3  Copyright (C) 2007 Gael de Chalendar (aka Kleag) <kleag@free.fr>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "kchatbaseitemdelegate.h"
21 #include "kchatbasemodel.h"
22 
23 #include <kdebug.h>
24 #include <klocale.h>
25 #include <QPainter>
26 
27 KChatBaseItemDelegate::KChatBaseItemDelegate(QObject *parent) :
28  QAbstractItemDelegate(parent)
29 {
30 }
31 
32 KChatBaseItemDelegate::~KChatBaseItemDelegate()
33 {
34 }
35 
36 void KChatBaseItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
37  const QModelIndex &index) const
38 {
39 // kDebug() << "KChatBaseItemDelegate::paint";
40  KChatBaseMessage m = index.model()->data(index, Qt::DisplayRole).value<KChatBaseMessage>();
41  paint(painter, option, index,m.first, m.second);
42 }
43 
44 void KChatBaseItemDelegate::paint(QPainter *painter,
45  const QStyleOptionViewItem &option,
46  const QModelIndex &index,
47  const QString& sender,
48  const QString& message) const
49 {
50 // kDebug() << "KChatBaseItemDelegate::paint";
51  QFontMetrics fm = painter->fontMetrics();
52  painter->setFont(((KChatBaseModel*)index.model())->nameFont());
53  painter->drawText(option.rect.x(),
54  QFontMetrics(option.font).height()+option.rect.y(), i18n("%1: ",sender));
55  painter->setFont(((KChatBaseModel*)index.model())->messageFont());
56  painter->drawText(option.rect.x() + 3 + QFontMetrics(((KChatBaseModel*)index.model())->nameFont()).width(i18n("%1: ",sender)),
57  QFontMetrics(option.font).height()+option.rect.y(), message);
58 }
59 
60 QSize KChatBaseItemDelegate::sizeHint(const QStyleOptionViewItem & option ,
61  const QModelIndex & index ) const
62 {
63 // kDebug() << "KChatBaseItemDelegate::sizeHint";
64  KChatBaseMessage m = index.model()->data(index, Qt::DisplayRole).value<KChatBaseMessage>();
65  return sizeHint(option, index, m.first, m.second);
66 }
67 
68 QSize KChatBaseItemDelegate::sizeHint(const QStyleOptionViewItem & option ,
69  const QModelIndex & index,
70  const QString& sender,
71  const QString& message ) const
72 {
73 // kDebug() << "KChatBaseItemDelegate::sizeHint";
74  int w = 0;
75  w += 6;
76  w += QFontMetrics(option.font).width(sender+i18n("%1: ",sender));
77  w += QFontMetrics(option.font).width(message);
78  int h = 0;
79  h += 2;
80  if (QFontMetrics(((KChatBaseModel*)index.model())->nameFont()).lineSpacing() >
81  QFontMetrics(((KChatBaseModel*)index.model())->messageFont()).lineSpacing())
82  {
83  h += QFontMetrics(((KChatBaseModel*)index.model())->nameFont()).lineSpacing();
84  }
85  else
86  {
87  h += QFontMetrics(((KChatBaseModel*)index.model())->messageFont()).lineSpacing();
88  }
89  return QSize(w,h);
90 }
91 
92 #include "kchatbaseitemdelegate.moc"
QModelIndex
KChatBaseMessage
The class of the elements stored in the chat list model.
Definition: kchatbasemodel.h:41
KChatBaseItemDelegate::paint
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Reimplementation of the default paint method.
Definition: kchatbaseitemdelegate.cpp:36
QVariant::value
T value() const
QFontMetrics
QPainter::setFont
void setFont(const QFont &font)
QStyleOptionViewItem
QObject
QPainter
QPainter::drawText
void drawText(const QPointF &position, const QString &text)
QAbstractItemModel::data
virtual QVariant data(const QModelIndex &index, int role) const =0
QString
KChatBaseItemDelegate::KChatBaseItemDelegate
KChatBaseItemDelegate(QObject *parent=0)
Constructs a KChatBaseItemDelegate object.
Definition: kchatbaseitemdelegate.cpp:27
kchatbasemodel.h
QSize
QFontMetrics::width
int width(const QString &text, int len) const
QModelIndex::model
const QAbstractItemModel * model() const
KChatBaseItemDelegate::sizeHint
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Reimplementation of the default sizeHint.
Definition: kchatbaseitemdelegate.cpp:60
KChatBaseItemDelegate::~KChatBaseItemDelegate
virtual ~KChatBaseItemDelegate()
Destruct a KChatBaseItemDelegate object.
Definition: kchatbaseitemdelegate.cpp:32
QPainter::fontMetrics
QFontMetrics fontMetrics() const
QFontMetrics::height
int height() const
kchatbaseitemdelegate.h
KChatBaseModel
The model used to store messages displayed in the chat dialog messages list.
Definition: kchatbasemodel.h:76
QAbstractItemDelegate
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:50 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdegames/libkdegamesprivate

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

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal