[SCM] ktp-contact-list packaging branch, master, updated. debian/15.12.1-2-1070-g6c56f91
Maximiliano Curia
maxy at moszumanska.debian.org
Sat May 28 00:06:29 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-contact-list.git;a=commitdiff;h=c0554ec
The following commit has been merged in the master branch:
commit c0554ece07d3ec1e703be00938e7443c0f56cb98
Author: Martin Klapetek <martin.klapetek at gmail.com>
Date: Sat May 21 10:02:18 2011 +0200
Alternate view delegate (compact) and some delegate refactoring.
Reviewed-by: David Edmundson
REVIEW: 101389
---
CMakeLists.txt | 2 +
abstract-contact-delegate.cpp | 217 +++++++++++++++++++++
contact-delegate.h => abstract-contact-delegate.h | 36 +---
contact-delegate-compact.cpp | 168 ++++++++++++++++
add-contact-dialog.h => contact-delegate-compact.h | 33 ++--
contact-delegate.cpp | 158 +--------------
contact-delegate.h | 16 +-
contact-overlays.h | 8 +
main-widget.cpp | 79 +++++++-
main-widget.h | 7 +
10 files changed, 509 insertions(+), 215 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f2247eb..6d4a74b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,10 +20,12 @@ include_directories (${KDE4_INCLUDES}
)
set (contactlist_SRCS
+ abstract-contact-delegate.cpp
contact-view-hover-button.cpp
contact-overlays.cpp
contact-delegate-overlay.cpp
contact-delegate.cpp
+ contact-delegate-compact.cpp
account-button.cpp
accounts-model.cpp
account-filter-model.cpp
diff --git a/abstract-contact-delegate.cpp b/abstract-contact-delegate.cpp
new file mode 100644
index 0000000..db2f3de
--- /dev/null
+++ b/abstract-contact-delegate.cpp
@@ -0,0 +1,217 @@
+/*
+ * Abstract Contact Delegate - base class for other delegates
+ *
+ * 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 <QApplication>
+#include <QtGui/QStyle>
+#include <QtGui/QPainter>
+#include <QtGui/QToolTip>
+#include <QtGui/QHelpEvent>
+#include <QAbstractItemView>
+
+#include <KDE/KGlobalSettings>
+#include <KDE/KLocale>
+#include <KDE/KIconLoader>
+#include <KDE/KIcon>
+
+#include "abstract-contact-delegate.h"
+#include "accounts-model.h"
+#include "groups-model.h"
+#include "contact-model-item.h"
+
+const int SPACING = 2;
+const int ACCOUNT_ICON_SIZE = 13;
+
+AbstractContactDelegate::AbstractContactDelegate(QObject* parent)
+ : QStyledItemDelegate(parent), m_palette(0)
+{
+ m_palette = new QPalette(QApplication::palette());
+}
+
+AbstractContactDelegate::~AbstractContactDelegate()
+{
+ delete m_palette;
+}
+
+void AbstractContactDelegate::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);
+
+ QRect groupRect = optV4.rect;
+
+ QRect accountGroupRect = groupRect;
+ accountGroupRect.setSize(QSize(ACCOUNT_ICON_SIZE, ACCOUNT_ICON_SIZE));
+ accountGroupRect.moveTo(QPoint(groupRect.left() + 2, groupRect.top() + 2));
+
+ QRect groupLabelRect = groupRect;
+ groupLabelRect.setRight(groupLabelRect.right() - SPACING);
+
+ QRect expandSignRect = groupLabelRect;
+ expandSignRect.setLeft(ACCOUNT_ICON_SIZE + SPACING + SPACING);
+ expandSignRect.setRight(groupLabelRect.left() + 20); //keep it by the left side
+
+ QFont groupFont = KGlobalSettings::smallestReadableFont();
+
+ QString counts;// = QString(" (%1/%2)").arg(index.data(AccountsModel::).toString(),
+ // index.data(ModelRoles::AccountAllContactsCountRole).toString());
+
+ if (index.data(AccountsModel::ItemRole).userType() == qMetaTypeId<AccountsModelItem*>()) {
+ painter->drawPixmap(accountGroupRect, KIcon(index.data(AccountsModel::IconRole).toString())
+ .pixmap(ACCOUNT_ICON_SIZE, ACCOUNT_ICON_SIZE));
+ } else {
+ painter->drawPixmap(accountGroupRect, KIconLoader::global()->loadIcon(QString("system-users"),
+ KIconLoader::Desktop));
+ }
+
+ painter->setPen(m_palette->color(QPalette::WindowText));
+ painter->setFont(groupFont);
+ painter->drawText(groupLabelRect, Qt::AlignVCenter | Qt::AlignRight,
+ index.data(GroupsModel::GroupNameRole).toString().append(counts));
+
+ QPen thinLinePen;
+ thinLinePen.setWidth(0);
+ thinLinePen.setColor(m_palette->color(QPalette::Disabled, QPalette::Button));
+
+ painter->setPen(thinLinePen);
+ painter->setRenderHint(QPainter::Antialiasing, false);
+
+ QFontMetrics fm = painter->fontMetrics();
+ int groupNameWidth = fm.width(index.data(GroupsModel::GroupNameRole).toString());
+
+ painter->drawLine(expandSignRect.right() + SPACING * 2,
+ groupRect.y() + groupRect.height() / 2,
+ groupRect.width() - groupNameWidth - SPACING * 2,
+ groupRect.y() + groupRect.height() / 2);
+
+ painter->setRenderHint(QPainter::Antialiasing, true);
+
+ QStyleOption expandSignOption = option;
+ expandSignOption.rect = expandSignRect;
+
+ if (option.state & QStyle::State_Open) {
+ style->drawPrimitive(QStyle::PE_IndicatorArrowDown, &expandSignOption, painter);
+ } else {
+ style->drawPrimitive(QStyle::PE_IndicatorArrowRight, &expandSignOption, painter);
+ }
+
+ painter->restore();
+}
+
+QSize AbstractContactDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
+{
+ 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(AccountsModel::ItemRole).userType() != qMetaTypeId<ContactModelItem*>()) {
+ return false;
+ }
+
+ if (event->type() != QEvent::ToolTip) {
+ return false;
+ }
+
+ const QString contactAvatar = index.data(AccountsModel::AvatarRole).toString();
+ const QString displayName = index.parent().data(AccountsModel::DisplayNameRole).toString();
+ const QString cmIconPath = KIconLoader::global()->iconPath(index.parent().data(AccountsModel::IconRole).toString(), 1);
+ const QString alias = index.data(AccountsModel::AliasRole).toString();
+ const QString presenceStatus = index.data(AccountsModel::PresenceMessageRole).toString();
+ QString presenceIconPath;
+ QString presenceText;
+
+ switch (index.data(AccountsModel::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 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></td></tr>").arg(alias);
+ table += QString("<tr><td>");
+ table += QString("%2").arg(presenceStatus.isEmpty() ? presenceText : presenceStatus);
+ table += QString("</td></tr>");
+ if (index.data(AccountsModel::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;
+}
\ No newline at end of file
diff --git a/contact-delegate.h b/abstract-contact-delegate.h
similarity index 55%
copy from contact-delegate.h
copy to abstract-contact-delegate.h
index 46fea76..b6dcfc8 100644
--- a/contact-delegate.h
+++ b/abstract-contact-delegate.h
@@ -1,8 +1,6 @@
/*
- * Contact Delegate
+ * Abstract Contact Delegate - base class for other delegates
*
- * Copyright (C) 2010-2011 Collabora Ltd. <info at collabora.co.uk>
- * @Author Dario Freddi <dario.freddi at collabora.co.uk>
* Copyright (C) 2011 Martin Klapetek <martin.klapetek at gmail.com>
*
* This library is free software; you can redistribute it and/or
@@ -20,33 +18,25 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef CONTACTDELEGATE_H
-#define CONTACTDELEGATE_H
+
+#ifndef ABSTRACT_CONTACT_DELEGATE_H
+#define ABSTRACT_CONTACT_DELEGATE_H
#include <QStyledItemDelegate>
-#include "contact-delegate-overlay.h"
-class ContactDelegate : public QStyledItemDelegate, public ContactDelegateOverlayContainer
+class AbstractContactDelegate : public QStyledItemDelegate
{
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;
+ AbstractContactDelegate(QObject* parent = 0);
+ virtual ~AbstractContactDelegate();
- int fadingValue() const;
- void setFadingValue(int value);
+ virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
public Q_SLOTS:
- void hideStatusMessageSlot(const QModelIndex& index);
- void reshowStatusMessageSlot();
- void fadeOutStatusMessageSlot();
- void triggerRepaint();
/**
* Reimplements the help tooltip for the contact delegate.
*
@@ -59,13 +49,7 @@ Q_SIGNALS:
void repaintItem(QModelIndex);
protected:
- /// Returns the delegate, typically, the derived class
- virtual QAbstractItemDelegate *asDelegate() { return this; }
-
-private:
- QModelIndex m_indexForHiding;
- int m_fadingValue;
QPalette *m_palette;
};
-#endif // CONTACTDELEGATE_H
+#endif // ABSTRACT_CONTACT_DELEGATE_H
diff --git a/contact-delegate-compact.cpp b/contact-delegate-compact.cpp
new file mode 100644
index 0000000..4521a0b
--- /dev/null
+++ b/contact-delegate-compact.cpp
@@ -0,0 +1,168 @@
+/*
+ * 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-compact.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 "accounts-model.h"
+#include "contact-model-item.h"
+#include "proxy-tree-node.h"
+#include "groups-model-item.h"
+#include "groups-model.h"
+
+const int SPACING = 4;
+const int AVATAR_SIZE = 22;
+const int PRESENCE_ICON_SIZE = 16;
+const int ACCOUNT_ICON_SIZE = 13;
+
+ContactDelegateCompact::ContactDelegateCompact(QObject * parent)
+ : AbstractContactDelegate(parent)
+{
+}
+
+ContactDelegateCompact::~ContactDelegateCompact()
+{
+
+}
+
+void ContactDelegateCompact::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(AccountsModel::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 = QPixmap::fromImage(QImage(index.data(AccountsModel::AvatarRole).toString()));
+
+ bool noContactAvatar = avatar.isNull();
+
+ if (noContactAvatar) {
+ avatar = SmallIcon("im-user", KIconLoader::SizeMedium);
+ }
+
+ painter->drawPixmap(iconRect, avatar);
+
+ QPixmap icon;
+
+ switch (index.data(AccountsModel::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(AccountsModel::PresenceMessageRole).toString(),
+ Qt::ElideRight, presenceMessageRect.width()));
+ } else {
+ AbstractContactDelegate::paint(painter, option, index);
+ }
+
+ painter->restore();
+}
+
+QSize ContactDelegateCompact::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+ Q_UNUSED(option);
+ bool isContact = index.data(AccountsModel::ItemRole).userType() == qMetaTypeId<ContactModelItem*>();
+
+ if (isContact) {
+ return QSize(0, 28);
+ } else {
+ return AbstractContactDelegate::sizeHint(option, index);
+ }
+}
+
+
+#include "contact-delegate-compact.moc"
diff --git a/add-contact-dialog.h b/contact-delegate-compact.h
similarity index 54%
copy from add-contact-dialog.h
copy to contact-delegate-compact.h
index d8c9e61..4387e0c 100644
--- a/add-contact-dialog.h
+++ b/contact-delegate-compact.h
@@ -1,7 +1,7 @@
/*
- * Add contact dialog
+ * Contact Delegate - compact version
*
- * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
+ * 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
@@ -18,31 +18,22 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef ADDCONTACTDIALOG_H
-#define ADDCONTACTDIALOG_H
+#ifndef CONTACTDELEGATECOMPACT_H
+#define CONTACTDELEGATECOMPACT_H
-#include <KDialog>
+#include "abstract-contact-delegate.h"
-#include <TelepathyQt4/Types>
-
-namespace Ui {
- class AddContactDialog;
-}
-
-class AccountsModel;
-
-class AddContactDialog : public KDialog
+class ContactDelegateCompact : public AbstractContactDelegate
{
Q_OBJECT
+// Q_PROPERTY(int m_fadingValue READ fadingValue WRITE setFadingValue);
public:
- explicit AddContactDialog(AccountsModel* accountModel, QWidget *parent = 0);
- virtual ~AddContactDialog();
- Tp::AccountPtr account() const;
- const QString screenName() const;
+ ContactDelegateCompact(QObject *parent = 0);
+ ~ContactDelegateCompact();
-private:
- Ui::AddContactDialog *ui;
+ void paint(QPainter *painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
+ QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const;
};
-#endif // ADDCONTACTDIALOG_H
+#endif // CONTACTDELEGATECOMPACT_H
diff --git a/contact-delegate.cpp b/contact-delegate.cpp
index e1e444a..202ef04 100644
--- a/contact-delegate.cpp
+++ b/contact-delegate.cpp
@@ -24,10 +24,8 @@
#include <QtGui/QPainter>
#include <QtGui/QPainterPath>
-#include <QtGui/QToolTip>
#include <QApplication>
#include <QStyle>
-#include <QHelpEvent>
#include <KIconLoader>
#include <KIcon>
@@ -47,14 +45,14 @@ const int PRESENCE_ICON_SIZE = 22;
const int ACCOUNT_ICON_SIZE = 13;
ContactDelegate::ContactDelegate(QObject * parent)
- : QStyledItemDelegate(parent), ContactDelegateOverlayContainer(), m_palette(0)
+ : AbstractContactDelegate(parent)
{
- m_palette = new QPalette(QApplication::palette());
+
}
ContactDelegate::~ContactDelegate()
{
- delete m_palette;
+
}
void ContactDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
@@ -115,6 +113,9 @@ void ContactDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opt
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;
@@ -167,62 +168,7 @@ void ContactDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opt
Qt::ElideRight, statusMsgRect.width()));
} else {
- QRect groupRect = optV4.rect;
-
- QRect accountGroupRect = groupRect;
- accountGroupRect.setSize(QSize(ACCOUNT_ICON_SIZE, ACCOUNT_ICON_SIZE));
- accountGroupRect.moveTo(QPoint(groupRect.left() + 2, groupRect.top() + 2));
-
- QRect groupLabelRect = groupRect;
- groupLabelRect.setRight(groupLabelRect.right() - SPACING);
-
- QRect expandSignRect = groupLabelRect;
- expandSignRect.setLeft(ACCOUNT_ICON_SIZE + SPACING + SPACING);
- expandSignRect.setRight(groupLabelRect.left() + 20); //keep it by the left side
-
- QFont groupFont = KGlobalSettings::smallestReadableFont();
-
- QString counts;// = QString(" (%1/%2)").arg(index.data(AccountsModel::).toString(),
- // index.data(ModelRoles::AccountAllContactsCountRole).toString());
-
- if (index.data(AccountsModel::ItemRole).userType() == qMetaTypeId<AccountsModelItem*>()) {
- painter->drawPixmap(accountGroupRect, KIcon(index.data(AccountsModel::IconRole).toString())
- .pixmap(ACCOUNT_ICON_SIZE, ACCOUNT_ICON_SIZE));
- } else {
- painter->drawPixmap(accountGroupRect, KIconLoader::global()->loadIcon(QString("system-users"),
- KIconLoader::Desktop));
- }
-
- painter->setPen(m_palette->color(QPalette::WindowText));
- painter->setFont(groupFont);
- painter->drawText(groupLabelRect, Qt::AlignVCenter | Qt::AlignRight,
- index.data(GroupsModel::GroupNameRole).toString().append(counts));
-
- QPen thinLinePen;
- thinLinePen.setWidth(0);
- thinLinePen.setColor(m_palette->color(QPalette::Disabled, QPalette::Button));
-
- painter->setPen(thinLinePen);
- painter->setRenderHint(QPainter::Antialiasing, false);
-
- QFontMetrics fm = painter->fontMetrics();
- int groupNameWidth = fm.width(index.data(GroupsModel::GroupNameRole).toString());
-
- painter->drawLine(expandSignRect.right() + SPACING * 2,
- groupRect.y() + groupRect.height() / 2,
- groupRect.width() - groupNameWidth - SPACING * 2,
- groupRect.y() + groupRect.height() / 2);
-
- painter->setRenderHint(QPainter::Antialiasing, true);
-
- QStyleOption expandSignOption = option;
- expandSignOption.rect = expandSignRect;
-
- if (option.state & QStyle::State_Open) {
- style->drawPrimitive(QStyle::PE_IndicatorArrowDown, &expandSignOption, painter);
- } else {
- style->drawPrimitive(QStyle::PE_IndicatorArrowRight, &expandSignOption, painter);
- }
+ AbstractContactDelegate::paint(painter, option, index);
}
painter->restore();
@@ -236,7 +182,7 @@ QSize ContactDelegate::sizeHint(const QStyleOptionViewItem &option, const QModel
if (isContact) {
return QSize(0, 32 + 4 * SPACING);
} else {
- return QSize(0, 20);
+ return AbstractContactDelegate::sizeHint(option, index);
}
}
@@ -282,92 +228,4 @@ void ContactDelegate::triggerRepaint()
emit repaintItem(m_indexForHiding);
}
-bool ContactDelegate::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(AccountsModel::ItemRole).userType() != qMetaTypeId<ContactModelItem*>()) {
- return false;
- }
-
- if (event->type() != QEvent::ToolTip) {
- return false;
- }
-
- const QString contactAvatar = index.data(AccountsModel::AvatarRole).toString();
- const QString displayName = index.parent().data(AccountsModel::DisplayNameRole).toString();
- const QString cmIconPath = KIconLoader::global()->iconPath(index.parent().data(AccountsModel::IconRole).toString(), 1);
- const QString alias = index.data(AccountsModel::AliasRole).toString();
- const QString presenceStatus = index.data(AccountsModel::PresenceMessageRole).toString();
- QString presenceIconPath;
- QString presenceText;
-
- switch (index.data(AccountsModel::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::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.
- * -------------------------
- * | account it belongs to |
- * -------------------------
- * | Avatar | Con's Alias |
- * -------------------------
- * | | 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><th colspan='2' align='center'><img src='%2' height='16' width='16' /> %3</th>").arg(cmIconPath, displayName);
- if (contactAvatar.isEmpty() || QPixmap(contactAvatar).isNull()) {
- table += QString("<tr><td><img src='%1' width='96' /></td>").arg(KIconLoader::global()->iconPath("im-user", -1));
- } else {
- table += QString("<tr><td><img src='%1' width='96' /></td>").arg(contactAvatar);
- }
-
- table += "<td><table><tr>";
- table += QString("<td align='right'><b>%1</b></td>").arg(i18n("Alias:"));
- table += QString("<td>%1</td></tr>").arg(alias);
- table += QString("<tr><td align='right'><b>%1</b></td>").arg(i18n("Status:"));
- if (presenceStatus.isEmpty()) {
- table += QString("<td><img src='%1' height='16' width='16' /> %2</td></tr>").arg(presenceIconPath, presenceText);
- } else {
- table += QString("<td><img src='%1' height='16' width='16' /> %2</td></tr>").arg(presenceIconPath, presenceStatus);
- }
- if (index.data(AccountsModel::BlockedRole).toBool()) {
- table += QString("<td colspan='2'>%1</td></tr>").arg(i18n("User is blocked"));
- }
- table += "</table></td><tr></table>";
- QToolTip::showText(QCursor::pos(), table, view);
-
- return true;
-}
-
#include "contact-delegate.moc"
diff --git a/contact-delegate.h b/contact-delegate.h
index 46fea76..bc81bd4 100644
--- a/contact-delegate.h
+++ b/contact-delegate.h
@@ -23,11 +23,10 @@
#ifndef CONTACTDELEGATE_H
#define CONTACTDELEGATE_H
-#include <QStyledItemDelegate>
-
+#include "abstract-contact-delegate.h"
#include "contact-delegate-overlay.h"
-class ContactDelegate : public QStyledItemDelegate, public ContactDelegateOverlayContainer
+class ContactDelegate : public AbstractContactDelegate, public ContactDelegateOverlayContainer
{
Q_OBJECT
Q_PROPERTY(int m_fadingValue READ fadingValue WRITE setFadingValue);
@@ -47,16 +46,6 @@ public Q_SLOTS:
void reshowStatusMessageSlot();
void fadeOutStatusMessageSlot();
void triggerRepaint();
- /**
- * Reimplements the help tooltip for the contact delegate.
- *
- * When the user hovers over a contact it will display their information like Alias, which contact belongs to what account,
- * is this contact blocked, their status message if their is one, etc.
- */
- bool helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index);
-
-Q_SIGNALS:
- void repaintItem(QModelIndex);
protected:
/// Returns the delegate, typically, the derived class
@@ -65,7 +54,6 @@ protected:
private:
QModelIndex m_indexForHiding;
int m_fadingValue;
- QPalette *m_palette;
};
#endif // CONTACTDELEGATE_H
diff --git a/contact-overlays.h b/contact-overlays.h
index c858b73..88acbda 100644
--- a/contact-overlays.h
+++ b/contact-overlays.h
@@ -34,6 +34,8 @@ class TextChannelContactOverlay : public HoverButtonDelegateOverlay
public:
TextChannelContactOverlay(QObject* parent);
+
+public Q_SLOTS:
virtual void setActive(bool active);
Q_SIGNALS:
@@ -67,6 +69,8 @@ class AudioChannelContactOverlay : public HoverButtonDelegateOverlay
public:
AudioChannelContactOverlay(QObject* parent);
+
+public Q_SLOTS:
virtual void setActive(bool active);
Q_SIGNALS:
@@ -100,6 +104,8 @@ class VideoChannelContactOverlay : public HoverButtonDelegateOverlay
public:
VideoChannelContactOverlay(QObject* parent);
+
+public Q_SLOTS:
virtual void setActive(bool active);
Q_SIGNALS:
@@ -133,6 +139,8 @@ class FileTransferContactOverlay : public HoverButtonDelegateOverlay
public:
FileTransferContactOverlay(QObject* parent);
+
+public Q_SLOTS:
virtual void setActive(bool active);
Q_SIGNALS:
diff --git a/main-widget.cpp b/main-widget.cpp
index 98f7fd7..10ec0fb 100644
--- a/main-widget.cpp
+++ b/main-widget.cpp
@@ -58,6 +58,7 @@
#include "accounts-model.h"
#include "account-filter-model.h"
#include "contact-delegate.h"
+#include "contact-delegate-compact.h"
#include "contact-model-item.h"
#include "add-contact-dialog.h"
#include "remove-contact-dialog.h"
@@ -85,6 +86,9 @@ MainWidget::MainWidget(QWidget *parent)
m_filterBar->hide();
setWindowIcon(KIcon("telepathy"));
+ KSharedConfigPtr config = KGlobal::config();
+ KConfigGroup guiConfigGroup(config, "GUI");
+
m_userAccountNameLabel->setText(user.property(KUser::FullName).isNull() ?
user.loginName() : user.property(KUser::FullName).toString()
);
@@ -153,6 +157,29 @@ MainWidget::MainWidget(QWidget *parent)
KMenu *settingsButtonMenu = new KMenu(settingsButton);
settingsButtonMenu->addAction(i18n("Configure accounts..."), this, SLOT(showSettingsKCM()));
+
+ QActionGroup *delegateTypeGroup = new QActionGroup(this);
+ delegateTypeGroup->setExclusive(true);
+
+ KMenu *setDelegateTypeMenu = new KMenu(settingsButtonMenu);
+ setDelegateTypeMenu->setTitle(i18n("Contact list type"));
+ delegateTypeGroup->addAction(setDelegateTypeMenu->addAction(i18n("Use full list"),
+ this, SLOT(onSwitchToFullView())));
+ delegateTypeGroup->actions().last()->setCheckable(true);
+
+ if (guiConfigGroup.readEntry("selected_delegate", "full") == QLatin1String("full")) {
+ delegateTypeGroup->actions().last()->setChecked(true);
+ }
+
+ delegateTypeGroup->addAction(setDelegateTypeMenu->addAction(i18n("Use compact list"),
+ this, SLOT(onSwitchToCompactView())));
+ delegateTypeGroup->actions().last()->setCheckable(true);
+
+ if (guiConfigGroup.readEntry("selected_delegate", "full") == QLatin1String("compact")) {
+ delegateTypeGroup->actions().last()->setChecked(true);
+ }
+
+ settingsButtonMenu->addMenu(setDelegateTypeMenu);
settingsButtonMenu->addSeparator();
settingsButtonMenu->addMenu(helpMenu());
@@ -195,18 +222,25 @@ MainWidget::MainWidget(QWidget *parent)
this, SLOT(onNewAccountAdded(Tp::AccountPtr)));
m_delegate = new ContactDelegate(this);
+ m_compactDelegate = new ContactDelegateCompact(this);
m_contactsListView->header()->hide();
m_contactsListView->setRootIsDecorated(false);
m_contactsListView->setSortingEnabled(true);
m_contactsListView->setContextMenuPolicy(Qt::CustomContextMenu);
- m_contactsListView->setItemDelegate(m_delegate);
+ if (guiConfigGroup.readEntry("selected_delegate", "full") == QLatin1String("compact")) {
+ m_contactsListView->setItemDelegate(m_compactDelegate);
+ } else {
+ m_contactsListView->setItemDelegate(m_delegate);
+ }
m_contactsListView->setIndentation(0);
m_contactsListView->setMouseTracking(true);
m_contactsListView->setExpandsOnDoubleClick(false); //the expanding/collapsing is handled manually
addOverlayButtons();
+ emit enableOverlays(guiConfigGroup.readEntry("selected_delegate", "full") == QLatin1String("full"));
+
connect(m_contactsListView, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(onCustomContextMenuRequested(QPoint)));
@@ -228,9 +262,7 @@ MainWidget::MainWidget(QWidget *parent)
connect(m_presenceMessageEdit, SIGNAL(returnPressed(QString)),
this, SLOT(setCustomPresenceMessage(QString)));
- KSharedConfigPtr config = KGlobal::config();
- KConfigGroup configGroup(config, "GUI");
- if (configGroup.readEntry("pin_filterbar", true)) {
+ if (guiConfigGroup.readEntry("pin_filterbar", true)) {
toggleSearchWidget(true);
m_searchContactAction->setChecked(true);
}
@@ -633,6 +665,19 @@ void MainWidget::addOverlayButtons()
connect(videoOverlay, SIGNAL(activated(QModelIndex)),
this, SLOT(startVideoChannel(QModelIndex)));
+
+ connect(this, SIGNAL(enableOverlays(bool)),
+ textOverlay, SLOT(setActive(bool)));
+
+ connect(this, SIGNAL(enableOverlays(bool)),
+ audioOverlay, SLOT(setActive(bool)));
+
+ connect(this, SIGNAL(enableOverlays(bool)),
+ videoOverlay, SLOT(setActive(bool)));
+
+ connect(this, SIGNAL(enableOverlays(bool)),
+ fileOverlay, SLOT(setActive(bool)));
+
}
void MainWidget::toggleSearchWidget(bool show)
@@ -1173,4 +1218,30 @@ void MainWidget::onGroupContacts(bool enabled)
}
+void MainWidget::onSwitchToFullView()
+{
+ m_contactsListView->setItemDelegate(m_delegate);
+ m_contactsListView->doItemsLayout();
+
+ emit enableOverlays(true);
+
+ KSharedConfigPtr config = KGlobal::config();
+ KConfigGroup guiConfigGroup(config, "GUI");
+ guiConfigGroup.writeEntry("selected_delegate", "full");
+ guiConfigGroup.config()->sync();
+}
+
+void MainWidget::onSwitchToCompactView()
+{
+ m_contactsListView->setItemDelegate(m_compactDelegate);
+ m_contactsListView->doItemsLayout();
+
+ emit enableOverlays(false);
+
+ KSharedConfigPtr config = KGlobal::config();
+ KConfigGroup guiConfigGroup(config, "GUI");
+ guiConfigGroup.writeEntry("selected_delegate", "compact");
+ guiConfigGroup.config()->sync();
+}
+
#include "main-widget.moc"
diff --git a/main-widget.h b/main-widget.h
index 555f1f1..c763356 100644
--- a/main-widget.h
+++ b/main-widget.h
@@ -33,6 +33,7 @@
#include <KAction>
#include "ui_main-widget.h"
+class ContactDelegateCompact;
class GroupsModel;
class KMenu;
class KSelectAction;
@@ -108,6 +109,11 @@ private Q_SLOTS:
void monitorPresence(const Tp::ConnectionPtr &connection);
void onContactManagerStateChanged(Tp::ContactListState state);
void onContactManagerStateChanged(const Tp::ContactManagerPtr &contactManager, Tp::ContactListState state);
+ void onSwitchToFullView();
+ void onSwitchToCompactView();
+
+Q_SIGNALS:
+ void enableOverlays(bool);
private:
/** handle connection errors for given account. This method provides visual notification */
@@ -121,6 +127,7 @@ private:
KMenu *m_avatarButtonMenu;
KSelectAction *m_setStatusAction;
ContactDelegate *m_delegate;
+ ContactDelegateCompact *m_compactDelegate;
KAction *m_addContactAction;
KAction *m_groupContactsAction;
KAction *m_hideOfflineAction;
--
ktp-contact-list packaging
More information about the pkg-kde-commits
mailing list