diff options
| author | Manjeet Dahiya <manjeetdahiya@gmail.com> | 2010-09-08 09:23:18 +0000 |
|---|---|---|
| committer | Manjeet Dahiya <manjeetdahiya@gmail.com> | 2010-09-08 09:23:18 +0000 |
| commit | da88f5f0bb5e73bc69bf7ed3962691622b1ae4f9 (patch) | |
| tree | c3686f7649785a2bfcc2c637a1588acdb8a721e8 /examples/GuiClient/rosterItem.h | |
| parent | 3431f5a37174b7eb8490672686db68df2b48e35f (diff) | |
| download | qxmpp-da88f5f0bb5e73bc69bf7ed3962691622b1ae4f9.tar.gz | |
add Gui Client example
Diffstat (limited to 'examples/GuiClient/rosterItem.h')
| -rw-r--r-- | examples/GuiClient/rosterItem.h | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/examples/GuiClient/rosterItem.h b/examples/GuiClient/rosterItem.h new file mode 100644 index 00000000..94e2d0bc --- /dev/null +++ b/examples/GuiClient/rosterItem.h @@ -0,0 +1,144 @@ +#ifndef ROSTERITEM_H
+#define ROSTERITEM_H
+
+#include <QStandardItem>
+#include <QItemDelegate>
+#include <QPainter>
+#include "QXmppPresence.h"
+
+class rosterItem : public QStandardItem
+{
+
+public:
+ enum userRoles
+ {
+ StatusText = Qt::UserRole + 2,
+ StatusType,
+ PresenceType,
+ BareJid,
+ Avatar
+ };
+
+ rosterItem(const QString& bareJid);
+
+ void setName(const QString& name);
+ QString getName();
+ void setBareJid(const QString& bareJid);
+ void setStatusText(const QString& text);
+ void setStatusType(QXmppPresence::Status::Type type);
+ void setPresenceType(QXmppPresence::Type type);
+ void setAvatar(const QImage& image);
+ QImage getAvatar();
+ QString getBareJid();
+ QString getStatusText();
+ QXmppPresence::Status::Type getStatusType();
+ QXmppPresence::Type getPresenceType();
+};
+
+class ItemDelegate : public QItemDelegate
+{
+public:
+ ItemDelegate()
+ {
+ }
+
+ QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
+ {
+ return QSize(44, 36);
+ }
+
+ void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
+ {
+ painter->save();
+ painter->setRenderHint(QPainter::TextAntialiasing);
+ QVariant value = index.data(Qt::DecorationRole);
+
+ QColor selectedBg(60, 140, 222);
+ QColor alternateBg(239, 245, 254);
+ QColor selectedText(Qt::white);
+
+ QColor nameTextColor(Qt::black);
+ QColor statusTextColor(Qt::darkGray);
+
+ QPixmap pixmap;
+ if(value.type() == QVariant::Icon)
+ {
+ QIcon icon = qvariant_cast<QIcon>(value);
+ pixmap = icon.pixmap(QSize(16, 16), QIcon::Normal, QIcon::On);
+ }
+
+ QPen penDivision;
+// if(index.row() % 2)
+// painter->fillRect(option.rect, alternateBg);
+
+ if (option.state & QStyle::State_Selected)
+ {
+ painter->fillRect(option.rect, selectedBg);
+// painter->fillRect(option.rect, option.palette.highlight());
+// penDivision.setColor(option.palette.highlight().color());
+ penDivision.setColor(selectedBg);
+ nameTextColor = selectedText;
+ statusTextColor = selectedText;
+ }
+ else
+ {
+ penDivision.setColor(QColor(244, 244, 244));
+ }
+
+ QRect rect = option.rect;
+ rect.setWidth(pixmap.width());
+ rect.setHeight(pixmap.height());
+ rect.moveTop(rect.y() + (option.rect.height() - pixmap.height())/2);
+ rect.moveLeft(rect.left() + 2);
+ painter->drawPixmap(rect, pixmap);
+
+ rect = option.rect;
+ rect.setLeft(rect.x() + pixmap.width() + 8);
+ rect.moveTop(rect.y() + 3);
+ QFont font;
+ painter->setFont(font);
+ painter->setPen(nameTextColor);
+ if(!index.data(Qt::DisplayRole).toString().isEmpty())
+ painter->drawText(rect, index.data(Qt::DisplayRole).toString());
+ else
+ painter->drawText(rect, index.data(rosterItem::BareJid).toString());
+
+ painter->setPen(statusTextColor);
+ rect.setTop(rect.y() + rect.height()/2);
+ rect.moveTop(rect.y() - 3);
+ painter->drawText(rect, index.data(rosterItem::StatusText).toString());
+
+ penDivision.setWidth(0);
+ painter->setPen(penDivision);
+
+ rect = option.rect;
+ QPoint left = rect.bottomLeft();
+ left.setX(left.x() + 4);
+ QPoint right = rect.bottomRight();
+ right.setX(right.x() - 4);
+ painter->drawLine(left, right);
+
+ QImage image;
+ value = index.data(rosterItem::Avatar);
+ if(value.type() == QVariant::Image)
+ {
+ image = qvariant_cast<QImage>(value);
+ }
+
+ pixmap = QPixmap(":/icons/resource/avatar.png");
+ rect = option.rect;
+ rect.setWidth(pixmap.width());
+ rect.setHeight(pixmap.height());
+ rect.moveTop(rect.y() + (option.rect.height() - pixmap.height())/2);
+ rect.moveLeft(option.rect.x() + option.rect.width() - pixmap.width() - 2);
+
+ if(image.isNull())
+ painter->drawPixmap(rect, pixmap);
+ else
+ painter->drawImage(rect, image);
+
+ painter->restore();
+ }
+};
+
+#endif // ROSTERITEM_H
|
