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

kopete/kopete

  • sources
  • kde-4.12
  • kdenetwork
  • kopete
  • kopete
  • config
  • chatwindow
emoticonthemedelegate.cpp
Go to the documentation of this file.
1 /*
2  emoticonthemedelegate - Kopete Emoticon Theme Delegate
3 
4  Copyright (c) 2007 by Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
5 
6  Kopete (c) 2007 by the Kopete developers <kopete-devel@kde.org>
7 
8  *************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  *************************************************************************
16 */
17 
18 #include "emoticonthemedelegate.h"
19 #include "emoticonthemeitem.h" // for the enum
20 #include <QModelIndex>
21 #include <QPainter>
22 #include <QApplication>
23 
24 EmoticonThemeDelegate::EmoticonThemeDelegate(QObject *parent)
25 : QStyledItemDelegate(parent)
26 {
27 }
28 
29 void EmoticonThemeDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
30 {
31  QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter);
32 
33  QString theme = index.data().toString();
34 
35  QVariant v = index.data(EmoticonThemeItem::EmoticonPixmaps);
36  QList<QVariant> pixmapList = qvariant_cast<QList<QVariant> >(v);
37 
38  painter->save();
39  painter->translate(option.rect.topLeft());
40  if (option.state & QStyle::State_Selected)
41  painter->setPen(option.palette.color(QPalette::Normal, QPalette::HighlightedText));
42  else
43  painter->setPen(option.palette.color(QPalette::Normal, QPalette::Text));
44  QFont f = painter->font();
45  f.setBold(true);
46  painter->setFont(f);
47  painter->drawText(10,20, theme);
48 
49  QSize s = sizeHint(option, index);
50 
51  // draw the emoticons themselves
52  QPoint top(10, 22);
53  int maxHeight = s.height() - top.y() - 2;
54  int middle = (maxHeight / 2) + top.y();
55  QStringList emotes = qvariant_cast<QStringList>(index.data(Qt::UserRole));
56  int count = 0;
57  foreach(const QString &emote, emotes)
58  {
59  QPixmap pix;
60 
61  // check if we have already loaded the requested pixmap
62  if (count < pixmapList.count())
63  {
64  pix = pixmapList.at(count++).value<QPixmap>();
65  }
66  else
67  {
68  pix.load(emote);
69  pixmapList.append(pix);
70  }
71 
72  if (pix.isNull())
73  continue;
74 
75  if (top.x() + pix.width() > option.rect.width() - 10)
76  break;
77 
78  // check if the emoticon height is bigger than the maximum allowed
79  if (pix.height() > maxHeight)
80  pix = pix.scaledToHeight(maxHeight);
81 
82  top.setY(middle - pix.height()/2);
83  painter->drawPixmap(top, pix);
84  top.setX(top.x() + pix.width() + 2);
85  }
86  painter->restore();
87 
88  // set the pixmapList as data of the index
89  QAbstractItemModel *model = const_cast<QAbstractItemModel*>(index.model());
90  model->setData(index, pixmapList, EmoticonThemeItem::EmoticonPixmaps);
91 }
92 
93 QSize EmoticonThemeDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
94 {
95  Q_UNUSED(option);
96  Q_UNUSED(index);
97 
98  return QSize(100,100);
99 }
100 
EmoticonThemeDelegate::paint
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: emoticonthemedelegate.cpp:29
EmoticonThemeItem::EmoticonPixmaps
Definition: emoticonthemeitem.h:31
QObject
QStyledItemDelegate
EmoticonThemeDelegate::EmoticonThemeDelegate
EmoticonThemeDelegate(QObject *parent=0)
Definition: emoticonthemedelegate.cpp:24
emoticonthemeitem.h
QAbstractItemModel
emoticonthemedelegate.h
EmoticonThemeDelegate::sizeHint
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: emoticonthemedelegate.cpp:93
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/kopete

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

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

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