~kubuntu-members/libkdegames/4.11

« back to all changes in this revision

Viewing changes to kchatbaseitemdelegate.cpp

  • Committer: Stefan Majewsky
  • Date: 2012-05-01 15:34:35 UTC
  • Revision ID: git-v1:82376fb5ca6f29f862641b6ca68603cb76258831
Begin to move stuff into libkdegamesprivate.

The build is now broken because I'm moving stuff without adjusting the
CMake files. But I figured it's cleaner to have the move in one commit
and the various edits in CMake and source files in the next commits.

svn path=/trunk/KDE/kdegames/libkdegames/; revision=1292461

Show diffs side-by-side

added added

removed removed

Lines of Context:
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"