1
From 41df4e6e804636de4449b6f5ba4acc8d99d09bac Mon Sep 17 00:00:00 2001
1
From dbc853171d3d2c5a72e98eab1cfe42151c8f5937 Mon Sep 17 00:00:00 2001
2
2
From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali.rohar@gmail.com>
3
Date: Wed, 17 Sep 2014 22:34:38 +0200
3
Date: Tue, 28 Oct 2014 19:00:09 +0100
4
4
Subject: [PATCH] Show emoticons in contactlist
6
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.
7
re-enables this feature for both status title and status message.
9
9
Thanks Stefan Geuns for patch!
12
12
CC: bitrain@gmail.com
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(-)
14
kopete/contactlist/contactlistmodel.cpp | 20 ++++++++-
15
kopete/contactlist/contactlistmodel.h | 2 +
16
kopete/contactlist/kopeteitemdelegate.cpp | 67 ++++++++++++++++++++++++++---
17
3 files changed, 81 insertions(+), 8 deletions(-)
19
19
diff --git a/kopete/contactlist/contactlistmodel.cpp b/kopete/contactlist/contactlistmodel.cpp
20
index e62e9bb..462e78e 100644
20
index e62e9bb..ba86811 100644
21
21
--- a/kopete/contactlist/contactlistmodel.cpp
22
22
+++ b/kopete/contactlist/contactlistmodel.cpp
23
@@ -502,13 +502,29 @@ bool ContactListModel::dropMetaContacts( int row, const QModelIndex &parent, Qt:
23
@@ -502,6 +502,22 @@ bool ContactListModel::dropMetaContacts( int row, const QModelIndex &parent, Qt:
78
70
QVariant metaContactImage( const Kopete::MetaContact* mc ) const;
79
71
QString metaContactTooltip( const Kopete::MetaContact* metaContact ) const;
80
72
diff --git a/kopete/contactlist/kopeteitemdelegate.cpp b/kopete/contactlist/kopeteitemdelegate.cpp
81
index fcefc89..905f58e 100644
73
index 674031b..371747e 100644
82
74
--- a/kopete/contactlist/kopeteitemdelegate.cpp
83
75
+++ b/kopete/contactlist/kopeteitemdelegate.cpp
84
@@ -397,7 +397,15 @@ void KopeteItemDelegate::paintItem( ContactList::LayoutItemConfig config, QPaint
76
@@ -397,7 +397,22 @@ void KopeteItemDelegate::paintItem( ContactList::LayoutItemConfig config, QPaint
87
79
QFontMetricsF fm( dlItem.font );
88
80
- idealWidth = fm.width( dlItem.text );
89
81
+ 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());
82
+ if ( role == Kopete::Items::StatusMessageRole || role == Kopete::Items::StatusTitleRole )
84
+ QList<QVariant> msgList = index.data( role ).toList();
85
+ foreach ( const QVariant &msg, msgList)
87
+ if ( msg.canConvert(QVariant::Icon) )
88
+ idealWidth += IconSize;
89
+ else if (msg.canConvert(QVariant::String) )
90
+ idealWidth += fm.width(msg.toString());
95
+ idealWidth = fm.width( dlItem.text );
98
97
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 )
100
@@ -546,12 +561,52 @@ void KopeteItemDelegate::paintItem( ContactList::LayoutItemConfig config, QPaint
113
+ const qreal IconMarginV = 1.0;
114
+ const qreal IconSize = rowHeight - 2 * IconMarginV;
115
+ QFontMetricsF fm( dlItem.font );
116
105
+ const int role = ContactList::LayoutManager::instance()->token( value ).mModelRole;
117
+ QList<QVariant> msgList = index.data( role ).toList();
119
+ foreach ( QVariant msg, msgList )
106
+ if ( role == Kopete::Items::StatusMessageRole || role == Kopete::Items::StatusTitleRole )
108
+ const qreal IconMarginV = 1.0;
109
+ const qreal IconSize = rowHeight - 2 * IconMarginV;
110
+ QFontMetricsF fm( dlItem.font );
111
+ QList<QVariant> msgList = index.data( role ).toList();
113
+ foreach ( QVariant msg, msgList )
115
+ if ( msg.canConvert(QVariant::Icon) )
119
+ msg.convert(QVariant::Icon);
120
+ QPixmap emoticonPixmap = msg.value<QIcon>().pixmap(IconSize, IconSize);
121
+ QRectF pixmapRect(currentItemX + offsetX, rowOffsetY, IconSize, IconSize);
122
+ painter->setClipRect( pixmapRect );
123
+ painter->drawPixmap( pixmapRect.topLeft(), emoticonPixmap );
124
+ offsetX += IconSize;
127
+ else if ( msg.canConvert(QVariant::String) )
131
+ const QString msgString = msg.toString();
132
+ qreal w = fm.width(msgString);
133
+ const QString text = QFontMetricsF( dlItem.font ).elidedText( msgString, Qt::ElideRight, w );
134
+ QRectF drawRect( currentItemX + offsetX, rowOffsetY, w, rowHeight );
135
+ painter->setClipRect( drawRect );
136
+ painter->drawText( drawRect, alignment, text );
121
144
- QString text = QFontMetricsF( dlItem.font ).elidedText( dlItem.text, Qt::ElideRight, itemWidth );
122
145
- QRectF drawRect( currentItemX, rowOffsetY, itemWidth, rowHeight );
123
146
- painter->setClipRect( drawRect );
124
147
- 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 );
150
+ QString text = QFontMetricsF( dlItem.font ).elidedText( dlItem.text, Qt::ElideRight, itemWidth );
151
+ QRectF drawRect( currentItemX, rowOffsetY, itemWidth, rowHeight );
152
+ painter->setClipRect( drawRect );
153
+ painter->drawText( drawRect, alignment, text );