• 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.14
  • 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
QModelIndex
EmoticonThemeItem::EmoticonPixmaps
Definition: emoticonthemeitem.h:31
QPixmap::width
int width() const
QPainter::font
const QFont & font() const
QFont
QList::at
const T & at(int i) const
QPainter::save
void save()
QPoint
QPoint::x
int x() const
QPoint::y
int y() const
QFont::setBold
void setBold(bool enable)
QPixmap::scaledToHeight
QPixmap scaledToHeight(int height, Qt::TransformationMode mode) const
QPainter::setFont
void setFont(const QFont &font)
QList::count
int count(const T &value) const
QList::append
void append(const T &value)
QStyleOptionViewItem
QObject
QPainter::setPen
void setPen(const QColor &color)
QPainter::drawPixmap
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
QPainter
QPainter::drawText
void drawText(const QPointF &position, const QString &text)
EmoticonThemeDelegate::EmoticonThemeDelegate
EmoticonThemeDelegate(QObject *parent=0)
Definition: emoticonthemedelegate.cpp:24
QString
QList
QPixmap::load
bool load(const QString &fileName, const char *format, QFlags< Qt::ImageConversionFlag > flags)
emoticonthemeitem.h
QStringList
QPixmap
QPixmap::isNull
bool isNull() const
QSize
QPixmap::height
int height() const
emoticonthemedelegate.h
QPainter::restore
void restore()
QModelIndex::model
const QAbstractItemModel * model() const
QModelIndex::data
QVariant data(int role) const
EmoticonThemeDelegate::sizeHint
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: emoticonthemedelegate.cpp:93
QApplication::style
QStyle * style()
QSize::height
int height() const
QPoint::setX
void setX(int x)
QPoint::setY
void setY(int y)
QPainter::translate
void translate(const QPointF &offset)
QStyle::drawPrimitive
virtual void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const =0
QAbstractItemModel
QAbstractItemModel::setData
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
QVariant::toString
QString toString() const
QVariant
QStyledItemDelegate
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:29:08 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