[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [ktp-contact-list] /: Show the 'phone' client type in contact list
From:       Dominik Cermak <d.cermak () arcor ! de>
Date:       2012-07-15 20:23:12
Message-ID: 20120715202312.63A43A6094 () git ! kde ! org
[Download RAW message or body]

Git commit 99f81b5bf9f6030c52903b0fde26b1dc912609c0 by Dominik Cermak.
Committed on 15/07/2012 at 22:19.
Pushed by cermak into branch 'master'.

Show the 'phone' client type in contact list

This adds a phone icon left of the presence icon for contact that are
online using a mobile phone.

BUG: 302963
FIXED-IN: 0.5
REVIEW: 105514

M  +21   -3    contact-delegate-compact.cpp
M  +21   -3    contact-delegate.cpp
M  +2    -1    main-widget.cpp

http://commits.kde.org/telepathy-contact-list/99f81b5bf9f6030c52903b0fde26b1dc912609c0


diff --git a/contact-delegate-compact.cpp b/contact-delegate-compact.cpp
index 91f3497..4a4c1a5 100644
--- a/contact-delegate-compact.cpp
+++ b/contact-delegate-compact.cpp
@@ -2,6 +2,7 @@
  * Contact Delegate - compact version
  *
  * Copyright (C) 2011 Martin Klapetek <martin.klapetek@gmail.com>
+ * Copyright (C) 2012 Dominik Cermak <d.cermak@arcor.de>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -43,6 +44,7 @@
 const int SPACING = 4;
 const int AVATAR_SIZE = 22;
 const int PRESENCE_ICON_SIZE = 16;
+const int CLIENT_TYPE_ICON_SIZE = 16;
 const int ACCOUNT_ICON_SIZE = 13;
 
 ContactDelegateCompact::ContactDelegateCompact(QObject * parent)
@@ -85,15 +87,31 @@ void ContactDelegateCompact::paintContact(QPainter * painter, \
const QStyleOption  
     KTp::Presence presence = \
index.data(AccountsModel::PresenceRole).value<KTp::Presence>();  
+    // This value is used to set the correct width for the username and the presence \
message. +    int rightIconsWidth = PRESENCE_ICON_SIZE + SPACING;
+
     QPixmap icon = presence.icon().pixmap(KIconLoader::SizeSmallMedium);
 
     QRect statusIconRect = optV4.rect;
     statusIconRect.setSize(QSize(PRESENCE_ICON_SIZE, PRESENCE_ICON_SIZE));
-    statusIconRect.moveTo(QPoint(optV4.rect.right() - PRESENCE_ICON_SIZE - SPACING,
+    statusIconRect.moveTo(QPoint(optV4.rect.right() - rightIconsWidth,
                                  optV4.rect.top() + (optV4.rect.height() - \
PRESENCE_ICON_SIZE) / 2));  
     painter->drawPixmap(statusIconRect, icon);
 
+    // Right now we only check for 'phone', as that's the most interesting type.
+    if (index.data(AccountsModel::ClientTypesRole).toStringList().contains(QLatin1String("phone"))) \
{ +        // Additional space is needed for the icons, don't add too much spacing \
between the two icons +        rightIconsWidth += CLIENT_TYPE_ICON_SIZE + (SPACING / \
2); +
+        QPixmap phone = QIcon::fromTheme("phone").pixmap(CLIENT_TYPE_ICON_SIZE);
+        QRect phoneIconRect = optV4.rect;
+        phoneIconRect.setSize(QSize(CLIENT_TYPE_ICON_SIZE, CLIENT_TYPE_ICON_SIZE));
+        phoneIconRect.moveTo(QPoint(optV4.rect.right() - rightIconsWidth,
+                                    optV4.rect.top() + (optV4.rect.height() - \
CLIENT_TYPE_ICON_SIZE) / 2)); +        painter->drawPixmap(phoneIconRect, phone);
+    }
+
     QFont nameFont = KGlobalSettings::generalFont();
 
     const QFontMetrics nameFontMetrics(nameFont);
@@ -103,14 +121,14 @@ void ContactDelegateCompact::paintContact(QPainter * painter, \
const QStyleOption  QRect userNameRect = optV4.rect;
     userNameRect.setX(iconRect.x() + iconRect.width() + SPACING * 2);
     userNameRect.setY(userNameRect.y() + (userNameRect.height()/2 - \
                nameFontMetrics.height()/2));
-    userNameRect.setWidth(userNameRect.width() - PRESENCE_ICON_SIZE - SPACING);
+    userNameRect.setWidth(userNameRect.width() - rightIconsWidth);
 
     painter->drawText(userNameRect,
                       nameFontMetrics.elidedText(optV4.text, Qt::ElideRight, \
userNameRect.width()));  
     QRect presenceMessageRect = optV4.rect;
     presenceMessageRect.setX(userNameRect.x() + \
                nameFontMetrics.boundingRect(optV4.text).width() + SPACING * 2);
-    presenceMessageRect.setWidth(optV4.rect.width() - presenceMessageRect.x() - \
PRESENCE_ICON_SIZE - SPACING); +    presenceMessageRect.setWidth(optV4.rect.width() - \
                presenceMessageRect.x() - rightIconsWidth);
     presenceMessageRect.setY(presenceMessageRect.y() + \
(presenceMessageRect.height()/2 - nameFontMetrics.height()/2));  
     QPen presenceMessagePen = painter->pen();
diff --git a/contact-delegate.cpp b/contact-delegate.cpp
index 2b8a863..af77d0e 100644
--- a/contact-delegate.cpp
+++ b/contact-delegate.cpp
@@ -4,6 +4,7 @@
  * Copyright (C) 2010-2011 Collabora Ltd. <info@collabora.co.uk>
  *   @Author Dario Freddi <dario.freddi@collabora.co.uk>
  * Copyright (C) 2011 Martin Klapetek <martin.klapetek@gmail.com>
+ * Copyright (C) 2012 Dominik Cermak <d.cermak@arcor.de>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -43,6 +44,7 @@
 const int SPACING = 4;
 const int AVATAR_SIZE = 32;
 const int PRESENCE_ICON_SIZE = 22;
+const int CLIENT_TYPE_ICON_SIZE = 22;
 const int ACCOUNT_ICON_SIZE = 13;
 
 ContactDelegate::ContactDelegate(QObject * parent)
@@ -99,19 +101,35 @@ void ContactDelegate::paintContact(QPainter *painter, const \
QStyleOptionViewItem  
     KTp::Presence presence = \
index.data(AccountsModel::PresenceRole).value<KTp::Presence>();  
+    // This value is used to set the correct width for the username and the presence \
message. +    int rightIconsWidth = PRESENCE_ICON_SIZE + SPACING;
+
     QPixmap icon = presence.icon().pixmap(KIconLoader::SizeSmallMedium);
 
     QRect statusIconRect = optV4.rect;
     statusIconRect.setSize(QSize(PRESENCE_ICON_SIZE, PRESENCE_ICON_SIZE));
-    statusIconRect.moveTo(QPoint(optV4.rect.right() - PRESENCE_ICON_SIZE - SPACING,
+    statusIconRect.moveTo(QPoint(optV4.rect.right() - rightIconsWidth,
                                  optV4.rect.top() + (optV4.rect.height() - \
PRESENCE_ICON_SIZE) / 2));  
     painter->drawPixmap(statusIconRect, icon);
 
+    // Right now we only check for 'phone', as that's the most interesting type.
+    if (index.data(AccountsModel::ClientTypesRole).toStringList().contains(QLatin1String("phone"))) \
{ +        // Additional space is needed for the icons, don't add too much spacing \
between the two icons +        rightIconsWidth += CLIENT_TYPE_ICON_SIZE + (SPACING / \
2); +
+        QPixmap phone = QIcon::fromTheme("phone").pixmap(CLIENT_TYPE_ICON_SIZE);
+        QRect phoneIconRect = optV4.rect;
+        phoneIconRect.setSize(QSize(CLIENT_TYPE_ICON_SIZE, CLIENT_TYPE_ICON_SIZE));
+        phoneIconRect.moveTo(QPoint(optV4.rect.right() - rightIconsWidth,
+                                    optV4.rect.top() + (optV4.rect.height() - \
CLIENT_TYPE_ICON_SIZE) / 2)); +        painter->drawPixmap(phoneIconRect, phone);
+    }
+
     QRect userNameRect = optV4.rect;
     userNameRect.setX(iconRect.x() + iconRect.width() + SPACING);
     userNameRect.setY(userNameRect.y() + 2);
-    userNameRect.setWidth(userNameRect.width() - PRESENCE_ICON_SIZE - SPACING);
+    userNameRect.setWidth(userNameRect.width() - rightIconsWidth);
 
     const QFontMetrics nameFontMetrics(KGlobalSettings::generalFont());
 
@@ -123,7 +141,7 @@ void ContactDelegate::paintContact(QPainter *painter, const \
QStyleOptionViewItem  QRect statusMsgRect = optV4.rect;
     statusMsgRect.setX(iconRect.x() + iconRect.width() + SPACING);
     statusMsgRect.setY(userNameRect.bottom() - statusFontMetrics.height() - 4);
-    statusMsgRect.setWidth(statusMsgRect.width() - PRESENCE_ICON_SIZE - SPACING);
+    statusMsgRect.setWidth(statusMsgRect.width() - rightIconsWidth);
 
     QColor fadingColor(m_palette->color(QPalette::Disabled, QPalette::Text));
 
diff --git a/main-widget.cpp b/main-widget.cpp
index ac4fd41..79869b8 100644
--- a/main-widget.cpp
+++ b/main-widget.cpp
@@ -111,7 +111,8 @@ MainWidget::MainWidget(QWidget *parent)
     Tp::ContactFactoryPtr contactFactory = Tp::ContactFactory::create(Tp::Features() \
                << Tp::Contact::FeatureAlias
                                                                       << \
                Tp::Contact::FeatureAvatarData
                                                                       << \
                Tp::Contact::FeatureSimplePresence
-                                                                      << \
Tp::Contact::FeatureCapabilities); +                                                  \
<< Tp::Contact::FeatureCapabilities +                                                 \
<< Tp::Contact::FeatureClientTypes);  
     Tp::ChannelFactoryPtr channelFactory = \
Tp::ChannelFactory::create(QDBusConnection::sessionBus());  


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic