[SCM] ktp-contact-applet packaging branch, master, updated. debian/15.12.1-1-966-gde83ac5
Maximiliano Curia
maxy at moszumanska.debian.org
Sat May 28 00:17:53 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-desktop-applets.git;a=commitdiff;h=2bb6f70
The following commit has been merged in the master branch:
commit 2bb6f7008fa4bfff93d8d8bf6cdc6968a4048f89
Author: David Edmundson <kde at davidedmundson.co.uk>
Date: Wed Feb 6 23:32:05 2013 +0000
Use against new models
---
contact/CMakeLists.txt | 2 +-
contact/src/abstract-contact-delegate.cpp | 177 +++++++++++-------------------
contact/src/abstract-contact-delegate.h | 12 +-
contact/src/applet_config.cpp | 54 +++------
contact/src/applet_config.h | 11 +-
contact/src/contact-delegate.cpp | 169 ----------------------------
contact/src/contact-delegate.h | 39 -------
7 files changed, 95 insertions(+), 369 deletions(-)
diff --git a/contact/CMakeLists.txt b/contact/CMakeLists.txt
index b3234c8..b253031 100644
--- a/contact/CMakeLists.txt
+++ b/contact/CMakeLists.txt
@@ -9,7 +9,7 @@ include_directories(
set(plasma_applet_ktp_contact_SRCS
src/abstract-contact-delegate.cpp
src/applet_config.cpp
- src/contact-delegate.cpp
+ src/contact-delegate-compact.cpp
src/contact-wrapper.cpp
src/telepathy-contact.cpp
)
diff --git a/contact/src/abstract-contact-delegate.cpp b/contact/src/abstract-contact-delegate.cpp
index fed5bcd..836913f 100644
--- a/contact/src/abstract-contact-delegate.cpp
+++ b/contact/src/abstract-contact-delegate.cpp
@@ -20,7 +20,7 @@
#include "abstract-contact-delegate.h"
-#include <QApplication>
+#include <QtGui/QApplication>
#include <QtGui/QStyle>
#include <QtGui/QPainter>
#include <QtGui/QToolTip>
@@ -32,27 +32,44 @@
#include <KDE/KIconLoader>
#include <KDE/KIcon>
-#include <KTp/Models/contacts-model.h>
-#include <KTp/Models/accounts-model-item.h>
-#include <KTp/Models/groups-model.h>
-#include <KTp/Models/contact-model-item.h>
+#include <KTp/types.h>
+#include <KDebug>
const int SPACING = 2;
-const int ACCOUNT_ICON_SIZE = 13;
+const int ACCOUNT_ICON_SIZE = 16;
AbstractContactDelegate::AbstractContactDelegate(QObject* parent)
- : QStyledItemDelegate(parent), m_palette(0)
+ : QStyledItemDelegate(parent)
{
- m_palette = new QPalette(QApplication::palette());
}
AbstractContactDelegate::~AbstractContactDelegate()
{
- delete m_palette;
}
void AbstractContactDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
+ if (index.data(KTp::RowTypeRole).toInt() == KTp::ContactRowType) {
+ paintContact(painter, option, index);
+ } else {
+ paintHeader(painter, option, index);
+ }
+}
+
+QSize AbstractContactDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
+{
+ Q_UNUSED(option);
+
+ if (index.data(KTp::RowTypeRole).toInt() == KTp::ContactRowType) {
+ return sizeHintContact(option, index);
+ } else {
+ return sizeHintHeader(option, index);
+ }
+}
+
+
+void AbstractContactDelegate::paintHeader(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
QStyleOptionViewItemV4 optV4 = option;
initStyleOption(&optV4, index);
@@ -74,41 +91,53 @@ void AbstractContactDelegate::paint(QPainter* painter, const QStyleOptionViewIte
groupLabelRect.setRight(groupLabelRect.right() - SPACING);
QRect expandSignRect = groupLabelRect;
- expandSignRect.setLeft(ACCOUNT_ICON_SIZE + SPACING + SPACING);
+ expandSignRect.setLeft(ACCOUNT_ICON_SIZE + (SPACING*5));
expandSignRect.setRight(groupLabelRect.left() + 20); //keep it by the left side
QFont groupFont = KGlobalSettings::smallestReadableFont();
- QString counts = QString(" (%1/%2)").arg(index.data(ContactsModel::OnlineUsersCountRole).toString(),
- index.data(ContactsModel::TotalUsersCountRole).toString());
+ QString counts = QString(" (%1/%2)").arg(index.data(KTp::HeaderOnlineUsersRole).toString(),
+ index.data(KTp::HeaderTotalUsersRole).toString());
- if (index.data(ContactsModel::ItemRole).userType() == qMetaTypeId<AccountsModelItem*>()) {
- painter->drawPixmap(accountGroupRect, KIcon(index.data(ContactsModel::IconRole).toString())
- .pixmap(ACCOUNT_ICON_SIZE, ACCOUNT_ICON_SIZE));
+ if (index.data(KTp::RowTypeRole).toInt() == KTp::AccountRowType) {
+ painter->drawPixmap(accountGroupRect, KIcon(index.data(Qt::DecorationRole).value<QIcon>()).pixmap(32));
} else {
painter->drawPixmap(accountGroupRect, KIconLoader::global()->loadIcon(QString("system-users"),
- KIconLoader::Desktop));
+ KIconLoader::Desktop));
+ }
+
+ //create an area for text which does not overlap with the icons.
+ QRect textRect = groupLabelRect.adjusted(ACCOUNT_ICON_SIZE + (SPACING*4),0,0,0);
+ QString groupHeaderString = index.data(Qt::DisplayRole).toString().append(counts);
+
+ if (option.state & QStyle::State_Selected) {
+ painter->setPen(option.palette.color(QPalette::Active, QPalette::HighlightedText));
+ } else {
+ painter->setPen(option.palette.color(QPalette::Active, QPalette::Text));
}
- painter->setPen(m_palette->color(QPalette::WindowText));
painter->setFont(groupFont);
- painter->drawText(groupLabelRect, Qt::AlignVCenter | Qt::AlignRight,
- index.data(GroupsModel::GroupNameRole).toString().append(counts));
+ painter->drawText(textRect, Qt::AlignVCenter | Qt::AlignRight,
+ optV4.fontMetrics.elidedText(groupHeaderString, Qt::ElideRight, textRect.width()));
+
QPen thinLinePen;
thinLinePen.setWidth(0);
- thinLinePen.setColor(m_palette->color(QPalette::Disabled, QPalette::Button));
+ thinLinePen.setColor(option.palette.color(QPalette::Inactive, QPalette::Button));
painter->setPen(thinLinePen);
painter->setRenderHint(QPainter::Antialiasing, false);
QFontMetrics fm = painter->fontMetrics();
- int groupNameWidth = fm.width(index.data(GroupsModel::GroupNameRole).toString().append(counts));
-
- painter->drawLine(expandSignRect.right() + SPACING * 2,
- groupRect.y() + groupRect.height() / 2,
- groupRect.width() - groupNameWidth - SPACING * 2,
- groupRect.y() + groupRect.height() / 2);
+ int groupNameWidth = fm.width(groupHeaderString);
+
+ //show a horizontal line padding the header if there is any space left.
+ if (groupNameWidth < textRect.width()) {
+ painter->drawLine(expandSignRect.right() + SPACING * 4,
+ groupRect.y() + groupRect.height() / 2,
+ groupRect.width() - groupNameWidth - SPACING * 2,
+ groupRect.y() + groupRect.height() / 2);
+ }
painter->setRenderHint(QPainter::Antialiasing, true);
@@ -124,100 +153,18 @@ void AbstractContactDelegate::paint(QPainter* painter, const QStyleOptionViewIte
painter->restore();
}
-QSize AbstractContactDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
+QSize AbstractContactDelegate::sizeHintHeader(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
Q_UNUSED(option)
Q_UNUSED(index)
- return QSize(0, 20);
+ return QSize(0,20);
}
-
bool AbstractContactDelegate::helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index)
{
- Q_UNUSED(option);
-
- // Check and make sure that we only want it to work on contacts and nothing else.
- if (index.data(ContactsModel::ItemRole).userType() != qMetaTypeId<ContactModelItem*>()) {
- return false;
- }
-
- if (event->type() != QEvent::ToolTip) {
- return false;
- }
-
- const QString contactAvatar = index.data(ContactsModel::AvatarRole).toString();
- const QString displayName = index.parent().data(ContactsModel::DisplayNameRole).toString();
- const QString cmIconPath = KIconLoader::global()->iconPath(index.parent().data(ContactsModel::IconRole).toString(), 1);
- const QString alias = index.data(ContactsModel::AliasRole).toString();
- const QString id = index.data(ContactsModel::IdRole).toString();
- const QString presenceStatus = index.data(ContactsModel::PresenceMessageRole).toString();
- QString presenceIconPath;
- QString presenceText;
-
- switch (index.data(ContactsModel::PresenceTypeRole).toUInt()) {
- case Tp::ConnectionPresenceTypeAvailable:
- presenceIconPath = KIconLoader::global()->iconPath("user-online", 1);
- presenceText = i18nc("This is an IM user status", "Online");
- break;
- case Tp::ConnectionPresenceTypeAway:
- presenceIconPath = KIconLoader::global()->iconPath("user-away", 1);
- presenceText = i18nc("This is an IM user status", "Away");
- break;
- case Tp::ConnectionPresenceTypeExtendedAway:
- presenceIconPath = KIconLoader::global()->iconPath("user-away-extended", 1);
- presenceText = i18nc("This is an IM user status", "Away");
- break;
- case Tp::ConnectionPresenceTypeBusy:
- presenceIconPath = KIconLoader::global()->iconPath("user-busy", 1);
- presenceText = i18nc("This is an IM user status", "Busy");
- break;
- case Tp::ConnectionPresenceTypeHidden:
- presenceIconPath = KIconLoader::global()->iconPath("user-invisible", 1);
- presenceText = i18nc("This is an IM user status", "Invisible");
- break;
- case Tp::ConnectionPresenceTypeOffline:
- presenceIconPath = KIconLoader::global()->iconPath("user-offline", 1);
- presenceText = i18nc("This is an IM user status", "Offline");
- break;
- default:
- presenceIconPath = KIconLoader::global()->iconPath("task-attention", 1);
- // What presence Text should be here??
- break;
- }
-
- /* The tooltip is composed of a HTML table to display the items in it of the contact.
- * ---------------------------
- * | | Con's Alias |
- * | Avatar | (Con's Id) |
- * | ----------------
- * | | Con's Status*|
- * ---------------------------
- * | Contact is blocked* |
- * ---------------------------
- * * Display actual status name if contact has no custom status message.
- * * Contact is blocked will only show if the contact is blocked, else no display.
- */
-
- QString table;
- table += QString("<table><tr><td rowspan='2' width='96'>");
- if (contactAvatar.isEmpty() || QPixmap(contactAvatar).isNull()) {
- table += QString("<img src='%1' width='96' />").arg(KIconLoader::global()->iconPath("im-user", -1));
- } else {
- table += QString("<img src='%1' width='96' />").arg(contactAvatar);
- }
-
- table += QString("</td>");
- table += QString("<td rowspan='2'><img src='%1' height='16' width='16' /> </td>").arg(presenceIconPath);
- table += QString("<td><b>%1</b><br>(%2)</td></tr>").arg(alias).arg(id);
- table += QString("<tr><td>");
- table += QString("%2").arg(presenceStatus.isEmpty() ? presenceText : presenceStatus);
- table += QString("</td></tr>");
- if (index.data(ContactsModel::BlockedRole).toBool()) {
- table += QString("<tr><td colspan='2'>%1</td></tr>").arg(i18n("User is blocked"));
- }
- table += QString("</table>");
-
- QToolTip::showText(QCursor::pos(), table, view);
-
- return true;
+ Q_UNUSED(event)
+ Q_UNUSED(view)
+ Q_UNUSED(option)
+ Q_UNUSED(index)
+ return false;
}
diff --git a/contact/src/abstract-contact-delegate.h b/contact/src/abstract-contact-delegate.h
index b6dcfc8..b96e027 100644
--- a/contact/src/abstract-contact-delegate.h
+++ b/contact/src/abstract-contact-delegate.h
@@ -22,7 +22,7 @@
#ifndef ABSTRACT_CONTACT_DELEGATE_H
#define ABSTRACT_CONTACT_DELEGATE_H
-#include <QStyledItemDelegate>
+#include <QtGui/QStyledItemDelegate>
class AbstractContactDelegate : public QStyledItemDelegate
@@ -49,7 +49,15 @@ Q_SIGNALS:
void repaintItem(QModelIndex);
protected:
- QPalette *m_palette;
+ /** Paint contact items. Pure virtual, items should be subclass this for painting*/
+ virtual void paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const = 0;
+ /** The size hint for painting contact items*/
+ virtual QSize sizeHintContact(const QStyleOptionViewItem& option, const QModelIndex& index) const = 0;
+
+private:
+ /** Paints header items*/
+ void paintHeader(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ QSize sizeHintHeader(const QStyleOptionViewItem& option, const QModelIndex& index) const;
};
#endif // ABSTRACT_CONTACT_DELEGATE_H
diff --git a/contact/src/applet_config.cpp b/contact/src/applet_config.cpp
index 64910c8..52fff50 100644
--- a/contact/src/applet_config.cpp
+++ b/contact/src/applet_config.cpp
@@ -18,12 +18,9 @@
***************************************************************************/
#include "applet_config.h"
-#include "contact-delegate.h"
+#include "contact-delegate-compact.h"
#include <KTp/Models/contacts-model.h>
-#include <KTp/Models/contact-model-item.h>
-#include <KTp/Models/groups-model.h>
-#include <KTp/Models/accounts-filter-model.h>
#include <KDebug>
#include <KPushButton>
@@ -31,8 +28,6 @@
AppletConfig::AppletConfig(const Tp::AccountManagerPtr &accountManager, QWidget* parent)
: KDialog(parent)
, m_model(0)
- , m_modelFilter(0)
- , m_groupsModel(0)
, m_accountManager(accountManager)
{
QWidget *widget = new QWidget(this);
@@ -47,53 +42,42 @@ AppletConfig::AppletConfig(const Tp::AccountManagerPtr &accountManager, QWidget*
AppletConfig::~AppletConfig()
{
- m_groupsModel->deleteLater();
m_model->deleteLater();
- m_modelFilter->deleteLater();
}
void AppletConfig::enableGroupsView(bool enable)
{
if (enable) {
- m_modelFilter->setSourceModel(m_groupsModel);
+ m_model->setGroupMode(KTp::ContactsModel::GroupGrouping);
} else {
- m_modelFilter->setSourceModel(m_model);
+ m_model->setGroupMode(KTp::ContactsModel::AccountGrouping);
}
}
void AppletConfig::enableOfflineContacts(bool enable)
{
- m_modelFilter->setPresenceTypeFilterFlags(enable ? AccountsFilterModel::DoNotFilterByPresence : AccountsFilterModel::ShowOnlyConnected);
+ m_model->setPresenceTypeFilterFlags(enable ? KTp::ContactsFilterModel::DoNotFilterByPresence : KTp::ContactsFilterModel::ShowOnlyConnected);
}
void AppletConfig::setupContactsList()
{
// prepare models
- m_model = new ContactsModel(this);
+ m_model = new KTp::ContactsModel(this);
m_model->setAccountManager(m_accountManager);
- m_groupsModel = new GroupsModel(m_model, this);
- m_modelFilter = new AccountsFilterModel(this);
- // setup model visualization type
- if (ui.showGroups->isChecked()) {
- m_modelFilter->setSourceModel(m_groupsModel);
- } else {
- m_modelFilter->setSourceModel(m_model);
- }
-
- m_modelFilter->setDynamicSortFilter(true);
- m_modelFilter->setPresenceTypeFilterFlags(ui.showOfflineContacts->isChecked() ? AccountsFilterModel::DoNotFilterByPresence : AccountsFilterModel::ShowOnlyConnected);
- m_modelFilter->setSortMode(AccountsFilterModel::SortByPresence);
+ m_model->setDynamicSortFilter(true);
+ m_model->setPresenceTypeFilterFlags(ui.showOfflineContacts->isChecked() ? KTp::ContactsFilterModel::DoNotFilterByPresence : KTp::ContactsFilterModel::ShowOnlyConnected);
+ m_model->setSortRole(Qt::DisplayRole);
// set model for the contacts tree view
- ui.contactsList->setModel(m_modelFilter);
+ ui.contactsList->setModel(m_model);
// disable ok button until a list item is selected
button(Ok)->setEnabled(false);
ui.contactsList->header()->hide();
ui.contactsList->setRootIsDecorated(false);
- ui.contactsList->setItemDelegate(new ContactDelegate());
+ ui.contactsList->setItemDelegate(new ContactDelegateCompact());
ui.contactsList->setSortingEnabled(true);
ui.contactsList->sortByColumn(0, Qt::AscendingOrder);
ui.contactsList->setSelectionMode(QAbstractItemView::SingleSelection);
@@ -108,9 +92,9 @@ void AppletConfig::setupContactsList()
void AppletConfig::contactListClicked(const QModelIndex& index)
{
- if (index.data(ContactsModel::TypeRole).toUInt() == ContactsModel::ContactRowType) {
+ if (index.data(KTp::RowTypeRole).toInt() == KTp::ContactRowType) {
button(Ok)->setEnabled(true);
- } else if (index.data(ContactsModel::TypeRole).toUInt() == ContactsModel::AccountRowType) {
+ } else {
button(Ok)->setEnabled(false);
if (ui.contactsList->isExpanded(index)) {
@@ -118,14 +102,12 @@ void AppletConfig::contactListClicked(const QModelIndex& index)
} else {
ui.contactsList->expand(index);
}
- } else {
- button(Ok)->setEnabled(false);
}
}
void AppletConfig::contactListDoubleClicked(const QModelIndex& index)
{
- if (index.data(ContactsModel::TypeRole).toUInt() == ContactsModel::ContactRowType) {
+ if (index.data(KTp::RowTypeRole).toUInt() == KTp::ContactRowType) {
button(Ok)->setEnabled(true);
slotButtonClicked(Ok);
}
@@ -136,13 +118,11 @@ void AppletConfig::slotButtonClicked(int button)
QModelIndex selectedItem = ui.contactsList->currentIndex();
if (button == KDialog::Ok && selectedItem.isValid()) {
- if (selectedItem.data(ContactsModel::ItemRole).userType() == qMetaTypeId<ContactModelItem*>()) {
- ContactModelItem *item = selectedItem.data(ContactsModel::ItemRole).value<ContactModelItem*>();
-
- // retrieve account related to the contact
- Tp::AccountPtr account = m_model->accountForContactItem(item);
+ if (selectedItem.data(KTp::RowTypeRole).toInt() == KTp::ContactRowType) {
+ KTp::ContactPtr contact = selectedItem.data(KTp::ContactRole).value<KTp::ContactPtr>();
+ Tp::AccountPtr account = selectedItem.data(KTp::AccountRole).value<Tp::AccountPtr>();
- setNewContact(item->contact(), account);
+ setNewContact(contact, account);
accept();
}
} else if (button == KDialog::Cancel) {
diff --git a/contact/src/applet_config.h b/contact/src/applet_config.h
index 95da7da..772b7cf 100644
--- a/contact/src/applet_config.h
+++ b/contact/src/applet_config.h
@@ -29,9 +29,10 @@ namespace Ui {
class Config;
}
-class ContactsModel;
-class AccountsFilterModel;
-class GroupsModel;
+namespace KTp
+{
+ class ContactsModel;
+}
class AppletConfig : public KDialog
{
@@ -56,9 +57,7 @@ private slots:
private:
void setupContactsList(); /** prepare the contacts to be show in the list */
- ContactsModel *m_model;
- AccountsFilterModel *m_modelFilter;
- GroupsModel *m_groupsModel;
+ KTp::ContactsModel *m_model;
Tp::AccountManagerPtr m_accountManager;
Ui::Config ui;
diff --git a/contact/src/contact-delegate.cpp b/contact/src/contact-delegate.cpp
deleted file mode 100644
index bfc7e16..0000000
--- a/contact/src/contact-delegate.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Contact Delegate - compact version
- *
- * Copyright (C) 2011 Martin Klapetek <martin.klapetek at gmail.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "contact-delegate.h"
-
-#include <QtGui/QPainter>
-#include <QtGui/QPainterPath>
-#include <QtGui/QToolTip>
-#include <QApplication>
-#include <QStyle>
-#include <QHelpEvent>
-
-#include <KIconLoader>
-#include <KIcon>
-#include <KDebug>
-#include <KGlobalSettings>
-#include <KDE/KLocale>
-
-#include <KTp/Models/contacts-model.h>
-#include <KTp/Models/contact-model-item.h>
-#include <KTp/Models/proxy-tree-node.h>
-#include <KTp/Models/groups-model-item.h>
-#include <KTp/Models/groups-model.h>
-
-const int SPACING = 4;
-const int AVATAR_SIZE = 22;
-const int PRESENCE_ICON_SIZE = 16;
-const int ACCOUNT_ICON_SIZE = 13;
-
-ContactDelegate::ContactDelegate(QObject * parent)
- : AbstractContactDelegate(parent)
-{
-}
-
-ContactDelegate::~ContactDelegate()
-{
-
-}
-
-void ContactDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
-{
- QStyleOptionViewItemV4 optV4 = option;
- initStyleOption(&optV4, index);
-
- painter->save();
-
- painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing);
- painter->setClipRect(optV4.rect);
-
- QStyle *style = QApplication::style();
- style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter);
-
- bool isContact = index.data(ContactsModel::ItemRole).userType() == qMetaTypeId<ContactModelItem*>();
-
- if (isContact) {
- QRect iconRect = optV4.rect;
- iconRect.setSize(QSize(AVATAR_SIZE, AVATAR_SIZE));
- iconRect.moveTo(QPoint(iconRect.x() + SPACING, iconRect.y() + SPACING));
-
- QPixmap avatar;
- avatar.load(index.data(ContactsModel::AvatarRole).toString());
-
- bool noContactAvatar = avatar.isNull();
-
- if (noContactAvatar) {
- avatar = SmallIcon("im-user", KIconLoader::SizeMedium);
- }
-
- painter->drawPixmap(iconRect, avatar);
-
- QPixmap icon;
-
- switch (index.data(ContactsModel::PresenceTypeRole).toInt()) {
- case Tp::ConnectionPresenceTypeAvailable:
- icon = SmallIcon("user-online", KIconLoader::SizeSmallMedium);
- break;
- case Tp::ConnectionPresenceTypeAway:
- icon = SmallIcon("user-away", KIconLoader::SizeSmallMedium);
- break;
- case Tp::ConnectionPresenceTypeExtendedAway:
- icon = SmallIcon("user-away-extended", KIconLoader::SizeSmallMedium);
- break;
- case Tp::ConnectionPresenceTypeBusy:
- icon = SmallIcon("user-busy", KIconLoader::SizeSmallMedium);
- break;
- case Tp::ConnectionPresenceTypeHidden:
- icon = SmallIcon("user-invisible", KIconLoader::SizeSmallMedium);
- break;
- case Tp::ConnectionPresenceTypeOffline:
- icon = SmallIcon("user-offline", KIconLoader::SizeSmallMedium);
- break;
- default:
- icon = SmallIcon("task-attention", KIconLoader::SizeSmallMedium);
- break;
- }
-
- QRect statusIconRect = optV4.rect;
- statusIconRect.setSize(QSize(PRESENCE_ICON_SIZE, PRESENCE_ICON_SIZE));
- statusIconRect.moveTo(QPoint(optV4.rect.right() - PRESENCE_ICON_SIZE - SPACING,
- optV4.rect.top() + (optV4.rect.height() - PRESENCE_ICON_SIZE) / 2));
-
- painter->drawPixmap(statusIconRect, icon);
-
- QFont nameFont = KGlobalSettings::smallestReadableFont();
- nameFont.setPointSize(nameFont.pointSize() + 1);
-
- const QFontMetrics nameFontMetrics(nameFont);
-
- painter->setFont(nameFont);
-
- 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);
-
- 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.setY(presenceMessageRect.y() + (presenceMessageRect.height()/2 - nameFontMetrics.height()/2));
-
- QPen presenceMessagePen = painter->pen();
- presenceMessagePen.setColor(m_palette->color(QPalette::Disabled, QPalette::Text));
-
- painter->setPen(presenceMessagePen);
-
- painter->drawText(presenceMessageRect,
- nameFontMetrics.elidedText(index.data(ContactsModel::PresenceMessageRole).toString(),
- Qt::ElideRight, presenceMessageRect.width()));
- } else {
- AbstractContactDelegate::paint(painter, option, index);
- }
-
- painter->restore();
-}
-
-QSize ContactDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
-{
- Q_UNUSED(option);
- bool isContact = index.data(ContactsModel::ItemRole).userType() == qMetaTypeId<ContactModelItem*>();
-
- if (isContact) {
- return QSize(0, 28);
- } else {
- return AbstractContactDelegate::sizeHint(option, index);
- }
-}
-
-
-// #include "contact-delegate.moc"
diff --git a/contact/src/contact-delegate.h b/contact/src/contact-delegate.h
deleted file mode 100644
index 4b37fdc..0000000
--- a/contact/src/contact-delegate.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Contact Delegate - compact version
- *
- * Copyright (C) 2011 Martin Klapetek <martin.klapetek at gmail.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef CONTACTDELEGATECOMPACT_H
-#define CONTACTDELEGATECOMPACT_H
-
-#include "abstract-contact-delegate.h"
-
-class ContactDelegate : public AbstractContactDelegate
-{
- Q_OBJECT
-// Q_PROPERTY(int m_fadingValue READ fadingValue WRITE setFadingValue);
-
-public:
- ContactDelegate(QObject *parent = 0);
- ~ContactDelegate();
-
- void paint(QPainter *painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
- QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const;
-};
-
-#endif // CONTACTDELEGATECOMPACT_H
--
ktp-contact-applet packaging
More information about the pkg-kde-commits
mailing list