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

kopete/kopete

emoticonthemedelegate.cpp

Go to the documentation of this file.
00001 /*
00002     emoticonthemedelegate  -  Kopete Emoticon Theme Delegate
00003 
00004     Copyright (c) 2007      by Gustavo Pichorim Boiko  <gustavo.boiko@kdemail.net>
00005 
00006     Kopete    (c) 2007      by the Kopete developers  <kopete-devel@kde.org>
00007 
00008     *************************************************************************
00009     *                                                                       *
00010     * This program is free software; you can redistribute it and/or modify  *
00011     * it under the terms of the GNU General Public License as published by  *
00012     * the Free Software Foundation; either version 2 of the License, or     *
00013     * (at your option) any later version.                                   *
00014     *                                                                       *
00015     *************************************************************************
00016 */
00017 
00018 #include "emoticonthemedelegate.h"
00019 #include "emoticonthemeitem.h" // for the enum
00020 #include <QModelIndex>
00021 #include <QPainter>
00022 #include <QApplication>
00023 
00024 EmoticonThemeDelegate::EmoticonThemeDelegate(QObject *parent)
00025 : QStyledItemDelegate(parent)
00026 {
00027 }
00028 
00029 void EmoticonThemeDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
00030 {
00031     QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter);
00032 
00033     QString theme = index.data().toString();
00034 
00035     QVariant v = index.data(EmoticonThemeItem::EmoticonPixmaps);
00036     QList<QVariant> pixmapList = qvariant_cast<QList<QVariant> >(v);
00037 
00038     painter->save();
00039         painter->translate(option.rect.topLeft());
00040         if (option.state & QStyle::State_Selected)
00041             painter->setPen(option.palette.color(QPalette::Normal, QPalette::HighlightedText));
00042         else
00043             painter->setPen(option.palette.color(QPalette::Normal, QPalette::Text));
00044         QFont f = painter->font();
00045         f.setBold(true);
00046         painter->setFont(f);
00047         painter->drawText(10,20, theme);
00048 
00049         QSize s = sizeHint(option, index);
00050 
00051         // draw the emoticons themselves
00052         QPoint top(10, 22);
00053         int maxHeight = s.height() - top.y() - 2;
00054         int middle = (maxHeight / 2) + top.y();
00055         QStringList emotes = qvariant_cast<QStringList>(index.data(Qt::UserRole));
00056         int count = 0;
00057         foreach(const QString &emote, emotes)
00058         {
00059             QPixmap pix;
00060 
00061             // check if we have already loaded the requested pixmap
00062             if (count < pixmapList.count())
00063             {
00064                 pix = pixmapList.at(count++).value<QPixmap>();
00065             }
00066             else
00067             {
00068                 pix.load(emote);
00069                 pixmapList.append(pix);
00070             }
00071 
00072             if (pix.isNull())
00073                 continue;
00074 
00075             if (top.x() + pix.width() > option.rect.width() - 10)
00076                 break;
00077 
00078             // check if the emoticon height is bigger than the maximum allowed
00079             if (pix.height() > maxHeight)
00080                 pix = pix.scaledToHeight(maxHeight);
00081             
00082             top.setY(middle - pix.height()/2);
00083             painter->drawPixmap(top, pix);
00084             top.setX(top.x() + pix.width() + 2);
00085         }
00086     painter->restore();
00087 
00088     // set the pixmapList as data of the index
00089     QAbstractItemModel *model = const_cast<QAbstractItemModel*>(index.model());
00090     model->setData(index, pixmapList, EmoticonThemeItem::EmoticonPixmaps);
00091 }
00092 
00093 QSize EmoticonThemeDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
00094 {
00095     Q_UNUSED(option);
00096     Q_UNUSED(index);
00097 
00098     return QSize(100,100);
00099 }
00100 

kopete/kopete

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

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork 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