~pali/kubuntu-packaging/kopete

« back to all changes in this revision

Viewing changes to debian/patches/0001-Show-emoticons-in-contactlist.patch

  • Committer: Pali Rohár
  • Date: 2014-10-28 12:33:19 UTC
  • Revision ID: pali.rohar@gmail.com-20141028123319-psb23sas472cshnd
Add patches: 0001-Fix-bugs-in-pidgin-history-import-for-kopete.patch 0001-Show-emoticons-in-contactlist.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
5
 
 
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.
 
8
 
 
9
Thanks Stefan Geuns for patch!
 
10
 
 
11
REVIEW: 2542
 
12
CC: bitrain@gmail.com
 
13
---
 
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(-)
 
18
 
 
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:
 
24
        return false;
 
25
 }
 
26
 
 
27
+QList<QVariant> ContactListModel::emoticonStringToList( const QString &msg ) const
 
28
+{
 
29
+       QList<QVariant> l;
 
30
+       QList<KEmoticonsTheme::Token> tokenList = Kopete::Emoticons::tokenize( msg );
 
31
+
 
32
+       foreach ( const KEmoticonsTheme::Token &token, tokenList )
 
33
+       {
 
34
+               if ( token.type == KEmoticonsTheme::Image )
 
35
+                       l << QIcon(token.picPath);
 
36
+               else if ( token.type == KEmoticonsTheme::Text )
 
37
+                       l << token.text;
 
38
+       }
 
39
+
 
40
+       return l;
 
41
+}
 
42
+
 
43
 QVariant ContactListModel::metaContactData( const Kopete::MetaContact* mc, int role ) const
 
44
 {
 
45
        switch ( role )
 
46
        {
 
47
        case Qt::DisplayRole:
 
48
         case Qt::EditRole:
 
49
-               return mc->displayName();
 
50
+               return emoticonStringToList( mc->displayName() );
 
51
                break;
 
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
 
55
                return mc->status();
 
56
                break;
 
57
        case Kopete::Items::StatusMessageRole:
 
58
-               return mc->statusMessage().message();
 
59
+               return emoticonStringToList( mc->statusMessage().message() );
 
60
                break;
 
61
        case Kopete::Items::StatusTitleRole:
 
62
-               return mc->statusMessage().title();
 
63
+               return emoticonStringToList( mc->statusMessage().title() );
 
64
                break;
 
65
        case Kopete::Items::AccountIconsRole:
 
66
                {
 
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 );
 
74
 
 
75
+       QList<QVariant> emoticonStringToList( const QString &msg ) const;
 
76
+
 
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
 
85
                                else
 
86
                                {
 
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)
 
92
+                                       {
 
93
+                                               if ( msg.canConvert(QVariant::Icon) )
 
94
+                                                       idealWidth += IconSize;
 
95
+                                               else if (msg.canConvert(QVariant::String) )
 
96
+                                                       idealWidth += fm.width(msg.toString());
 
97
+                                       }
 
98
                                        dlItem.type = LayoutNormal;
 
99
                                }
 
100
 
 
101
@@ -540,18 +548,45 @@ void KopeteItemDelegate::paintItem( ContactList::LayoutItemConfig config, QPaint
 
102
                                                }
 
103
                                        }
 
104
                                }
 
105
-                               else if ( ContactList::LayoutManager::PlaceHolder )
 
106
+                               else if ( value == ContactList::LayoutManager::PlaceHolder )
 
107
                                {
 
108
                                        // Do nothing
 
109
                                }
 
110
                                else
 
111
                                {
 
112
-                                       if ( painter )
 
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();
 
118
+                                       qreal offsetX = 0;
 
119
+                                       foreach ( QVariant msg, msgList )
 
120
                                        {
 
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) )
 
126
+                                               {
 
127
+                                                       if ( painter )
 
128
+                                                       {
 
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;
 
135
+                                                       }
 
136
+                                               }
 
137
+                                               else if ( msg.canConvert(QVariant::String) )
 
138
+                                               {
 
139
+                                                       const QString msgString = msg.toString();
 
140
+                                                       if ( painter )
 
141
+                                                       {
 
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 );
 
147
+                                                               offsetX += w;
 
148
+                                                       }
 
149
+                                               }
 
150
                                        }
 
151
                                }
 
152
 
 
153
-- 
 
154
1.7.9.5
 
155