1
From 41df4e6e804636de4449b6f5ba4acc8d99d09bac Mon Sep 17 00:00:00 2001
2
From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali.rohar@gmail.com>
3
Date: Wed, 17 Sep 2014 22:34:38 +0200
4
Subject: [PATCH] Show emoticons in contactlist
6
The contactlist no longer shows emoticons in recent kopete versions. This patch
7
re-enables this feature for both the contacts their display name and status message.
9
Thanks Stefan Geuns for patch!
14
kopete/contactlist/contactlistmodel.cpp | 22 +++++++++++--
15
kopete/contactlist/contactlistmodel.h | 2 ++
16
kopete/contactlist/kopeteitemdelegate.cpp | 49 ++++++++++++++++++++++++-----
17
3 files changed, 63 insertions(+), 10 deletions(-)
19
diff --git a/kopete/contactlist/contactlistmodel.cpp b/kopete/contactlist/contactlistmodel.cpp
20
index e62e9bb..462e78e 100644
21
--- a/kopete/contactlist/contactlistmodel.cpp
22
+++ b/kopete/contactlist/contactlistmodel.cpp
23
@@ -502,13 +502,29 @@ bool ContactListModel::dropMetaContacts( int row, const QModelIndex &parent, Qt:
27
+QList<QVariant> ContactListModel::emoticonStringToList( const QString &msg ) const
30
+ QList<KEmoticonsTheme::Token> tokenList = Kopete::Emoticons::tokenize( msg );
32
+ foreach ( const KEmoticonsTheme::Token &token, tokenList )
34
+ if ( token.type == KEmoticonsTheme::Image )
35
+ l << QIcon(token.picPath);
36
+ else if ( token.type == KEmoticonsTheme::Text )
43
QVariant ContactListModel::metaContactData( const Kopete::MetaContact* mc, int role ) const
49
- return mc->displayName();
50
+ return emoticonStringToList( mc->displayName() );
52
case Qt::AccessibleTextRole:
53
return i18nc("%1 is display name, %2 is status (connected/away/etc.)", "%1 (%2)", mc->displayName(), mc->statusString());
54
@@ -535,10 +551,10 @@ QVariant ContactListModel::metaContactData( const Kopete::MetaContact* mc, int r
57
case Kopete::Items::StatusMessageRole:
58
- return mc->statusMessage().message();
59
+ return emoticonStringToList( mc->statusMessage().message() );
61
case Kopete::Items::StatusTitleRole:
62
- return mc->statusMessage().title();
63
+ return emoticonStringToList( mc->statusMessage().title() );
65
case Kopete::Items::AccountIconsRole:
67
diff --git a/kopete/contactlist/contactlistmodel.h b/kopete/contactlist/contactlistmodel.h
68
index 4ec3143..e977fa1 100644
69
--- a/kopete/contactlist/contactlistmodel.h
70
+++ b/kopete/contactlist/contactlistmodel.h
71
@@ -82,6 +82,8 @@ protected:
72
typedef QPair<Kopete::Group*, Kopete::MetaContact*> GroupMetaContactPair;
73
virtual bool dropMetaContacts( int row, const QModelIndex &parent, Qt::DropAction action, const QList<GroupMetaContactPair> &items );
75
+ QList<QVariant> emoticonStringToList( const QString &msg ) const;
77
QVariant metaContactData( const Kopete::MetaContact* mc, int role ) const;
78
QVariant metaContactImage( const Kopete::MetaContact* mc ) const;
79
QString metaContactTooltip( const Kopete::MetaContact* metaContact ) const;
80
diff --git a/kopete/contactlist/kopeteitemdelegate.cpp b/kopete/contactlist/kopeteitemdelegate.cpp
81
index fcefc89..905f58e 100644
82
--- a/kopete/contactlist/kopeteitemdelegate.cpp
83
+++ b/kopete/contactlist/kopeteitemdelegate.cpp
84
@@ -397,7 +397,15 @@ void KopeteItemDelegate::paintItem( ContactList::LayoutItemConfig config, QPaint
87
QFontMetricsF fm( dlItem.font );
88
- idealWidth = fm.width( dlItem.text );
89
+ const int role = ContactList::LayoutManager::instance()->token( value ).mModelRole;
90
+ QList<QVariant> msgList = index.data( role ).toList();
91
+ foreach ( const QVariant &msg, msgList)
93
+ if ( msg.canConvert(QVariant::Icon) )
94
+ idealWidth += IconSize;
95
+ else if (msg.canConvert(QVariant::String) )
96
+ idealWidth += fm.width(msg.toString());
98
dlItem.type = LayoutNormal;
101
@@ -540,18 +548,45 @@ void KopeteItemDelegate::paintItem( ContactList::LayoutItemConfig config, QPaint
105
- else if ( ContactList::LayoutManager::PlaceHolder )
106
+ else if ( value == ContactList::LayoutManager::PlaceHolder )
113
+ const qreal IconMarginV = 1.0;
114
+ const qreal IconSize = rowHeight - 2 * IconMarginV;
115
+ QFontMetricsF fm( dlItem.font );
116
+ const int role = ContactList::LayoutManager::instance()->token( value ).mModelRole;
117
+ QList<QVariant> msgList = index.data( role ).toList();
119
+ foreach ( QVariant msg, msgList )
121
- QString text = QFontMetricsF( dlItem.font ).elidedText( dlItem.text, Qt::ElideRight, itemWidth );
122
- QRectF drawRect( currentItemX, rowOffsetY, itemWidth, rowHeight );
123
- painter->setClipRect( drawRect );
124
- painter->drawText( drawRect, alignment, text );
125
+ if ( msg.canConvert(QVariant::Icon) )
129
+ msg.convert(QVariant::Icon);
130
+ QPixmap emoticonPixmap = msg.value<QIcon>().pixmap(IconSize, IconSize);
131
+ QRectF pixmapRect(currentItemX + offsetX, rowOffsetY, IconSize, IconSize);
132
+ painter->setClipRect( pixmapRect );
133
+ painter->drawPixmap( pixmapRect.topLeft(), emoticonPixmap );
134
+ offsetX += IconSize;
137
+ else if ( msg.canConvert(QVariant::String) )
139
+ const QString msgString = msg.toString();
142
+ qreal w = fm.width(msgString);
143
+ const QString text = QFontMetricsF( dlItem.font ).elidedText( msgString, Qt::ElideRight, w );
144
+ QRectF drawRect( currentItemX + offsetX, rowOffsetY, w, rowHeight );
145
+ painter->setClipRect( drawRect );
146
+ painter->drawText( drawRect, alignment, text );