[SCM] ktp-text-ui packaging branch, master, updated. debian/15.12.1-1-1918-gdf4b0ec
Maximiliano Curia
maxy at moszumanska.debian.org
Sat May 28 00:24:36 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=2328624
The following commit has been merged in the master branch:
commit 23286244705b19dd5cce8b77f2c68ee55c4a58d7
Author: David Edmundson <kde at davidedmundson.co.uk>
Date: Mon Apr 14 20:33:15 2014 +0200
Add delegate for participants list
REVIEW: 117569
---
lib/CMakeLists.txt | 1 +
lib/channel-contact-model.cpp | 43 ++++++++-----
lib/channel-contact-model.h | 4 --
lib/chat-widget.cpp | 5 +-
lib/contact-delegate.cpp | 138 ++++++++++++++++++++++++++++++++++++++++++
lib/contact-delegate.h | 46 ++++++++++++++
6 files changed, 218 insertions(+), 19 deletions(-)
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index d640536..a2716b0 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -13,6 +13,7 @@ set(ktpchat_SRCS
chat-style-plist-file-reader.cpp
chat-text-edit.cpp
chat-search-bar.cpp
+ contact-delegate.cpp
notify-filter.cpp
text-chat-config.cpp
)
diff --git a/lib/channel-contact-model.cpp b/lib/channel-contact-model.cpp
index df8c491..68b79c0 100644
--- a/lib/channel-contact-model.cpp
+++ b/lib/channel-contact-model.cpp
@@ -23,6 +23,8 @@
#include <KDebug>
#include <KIcon>
+#include <KTp/types.h>
+
Q_DECLARE_METATYPE(Tp::ContactPtr)
ChannelContactModel::ChannelContactModel(const Tp::TextChannelPtr &channel, QObject *parent)
@@ -77,27 +79,40 @@ int ChannelContactModel::rowCount(const QModelIndex &parent) const
QVariant ChannelContactModel::data(const QModelIndex &index, int role) const
{
- if(!index.isValid()) {
+ if (!index.isValid()) {
return QVariant();
}
int row = index.row();
- switch (role) {
- case Qt::DisplayRole:
- return QVariant(m_contacts[row]->alias());
-
- case Qt::DecorationRole:
- {
- const Tp::ContactPtr contact = m_contacts[row];
- if (TextChatConfig::instance()->showOthersTyping() && (m_channel->chatState(contact) == Tp::ChannelChatStateComposing)) {
- return KIcon(QLatin1String("document-edit"));
-
- }
- return KTp::Presence(contact->presence()).icon();
+ KTp::ContactPtr contact = KTp::ContactPtr::qObjectCast(m_contacts[row]);
+ if (!contact) {
+ return QVariant();
}
- case ContactRole:
+ switch (role) {
+ case Qt::DisplayRole:
+ return QVariant(contact->alias());
+
+ case KTp::ContactClientTypesRole:
+ return contact->clientTypes();
+ case KTp::ContactAvatarPathRole:
+ return contact->avatarData().fileName;
+ case KTp::ContactAvatarPixmapRole:
+ return contact->avatarPixmap();
+ case KTp::ContactGroupsRole:
+ return contact->groups();
+
+ case KTp::ContactPresenceNameRole:
+ return contact->presence().displayString();
+ case KTp::ContactPresenceMessageRole:
+ return contact->presence().statusMessage();
+ case KTp::ContactPresenceTypeRole:
+ return contact->presence().type();
+ case KTp::ContactPresenceIconRole:
+ return contact->presence().iconName();
+
+ case KTp::ContactRole:
return QVariant::fromValue(m_contacts[row]);
default:
diff --git a/lib/channel-contact-model.h b/lib/channel-contact-model.h
index 7e0ae45..94419f9 100644
--- a/lib/channel-contact-model.h
+++ b/lib/channel-contact-model.h
@@ -40,10 +40,6 @@ class ChannelContactModel : public QAbstractListModel
{
Q_OBJECT
public:
- enum Roles {
- ContactRole = Qt::UserRole + 1
- };
-
explicit ChannelContactModel(const Tp::TextChannelPtr &channel, QObject *parent = 0);
void setTextChannel(const Tp::TextChannelPtr &channel);
diff --git a/lib/chat-widget.cpp b/lib/chat-widget.cpp
index 5afed20..3929e45 100644
--- a/lib/chat-widget.cpp
+++ b/lib/chat-widget.cpp
@@ -27,6 +27,7 @@
#include "channel-contact-model.h"
#include "notify-filter.h"
#include "text-chat-config.h"
+#include "contact-delegate.h"
#include <QtGui/QKeyEvent>
#include <QtGui/QAction>
@@ -144,6 +145,8 @@ ChatWidget::ChatWidget(const Tp::TextChannelPtr & channel, const Tp::AccountPtr
this, SLOT(onShowContactDetailsClicked()));
d->ui.contactsView->setContextMenuPolicy(Qt::CustomContextMenu);
+ d->ui.contactsView->setItemDelegate(new ContactDelegate(this));
+
connect(d->ui.contactsView, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(onContactsViewContextMenuRequested(QPoint)));
}
@@ -1162,7 +1165,7 @@ void ChatWidget::onContactsViewContextMenuRequested(const QPoint& point)
return;
}
- const KTp::ContactPtr contact = KTp::ContactPtr::qObjectCast<Tp::Contact>(index.data(ChannelContactModel::ContactRole).value<Tp::ContactPtr>());
+ const KTp::ContactPtr contact = KTp::ContactPtr::qObjectCast<Tp::Contact>(index.data(KTp::ContactRole).value<Tp::ContactPtr>());
bool isSelfContact = ((Tp::ContactPtr) contact == textChannel()->groupSelfContact());
d->contactsMenu->findChild<QAction*>(QLatin1String("OpenChatWindowAction"))->setEnabled(!isSelfContact);
diff --git a/lib/contact-delegate.cpp b/lib/contact-delegate.cpp
new file mode 100644
index 0000000..a66ff32
--- /dev/null
+++ b/lib/contact-delegate.cpp
@@ -0,0 +1,138 @@
+/*
+ * Contact Delegate - compact version
+ *
+ * Copyright (C) 2011 Martin Klapetek <martin.klapetek at gmail.com>
+ * Copyright (C) 2012 Dominik Cermak <d.cermak at arcor.de>
+ * Copyright (C) 2014 David Edmundson <davidedmundson at kde.org>
+ *
+ * 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 <KStandardDirs>
+
+#include <KTp/types.h>
+
+ContactDelegate::ContactDelegate(QObject *parent)
+ : QStyledItemDelegate(parent)
+{
+ m_spacing = 4;
+ m_avatarSize = IconSize(KIconLoader::Toolbar);
+ m_presenceIconSize = IconSize(KIconLoader::Small);
+ m_clientTypeIconSize = IconSize(KIconLoader::Small);
+}
+
+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, &optV4, painter);
+
+ QRect iconRect = optV4.rect;
+ iconRect.setSize(QSize(m_avatarSize, m_avatarSize));
+ iconRect.moveTo(QPoint(iconRect.x() + m_spacing, iconRect.y() + m_spacing));
+
+ QPixmap avatar(qvariant_cast<QPixmap>(index.data(KTp::ContactAvatarPixmapRole)));
+
+ if (!avatar.isNull()) {
+ style->drawItemPixmap(painter, iconRect, Qt::AlignCenter, avatar.scaled(iconRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
+ }
+
+ // This value is used to set the correct width for the username and the presence message.
+ int rightIconsWidth = m_presenceIconSize + m_spacing;
+
+ QPixmap icon = KIcon(index.data(KTp::ContactPresenceIconRole).toString()).pixmap(KIconLoader::SizeSmallMedium);
+
+ QRect statusIconRect = optV4.rect;
+
+ statusIconRect.setSize(QSize(m_presenceIconSize, m_presenceIconSize));
+ statusIconRect.moveTo(QPoint(optV4.rect.right() - (rightIconsWidth),
+ optV4.rect.top() + (optV4.rect.height() - m_presenceIconSize) / 2));
+
+ painter->drawPixmap(statusIconRect, icon);
+
+ // Right now we only check for 'phone', as that's the most interesting type.
+ if (index.data(KTp::ContactClientTypesRole).toStringList().contains(QLatin1String("phone"))) {
+ // Additional space is needed for the icons, don't add too much spacing between the two icons
+ rightIconsWidth += m_clientTypeIconSize + m_spacing;
+
+ QPixmap phone = QIcon::fromTheme(QLatin1String("phone")).pixmap(m_clientTypeIconSize);
+ QRect phoneIconRect = optV4.rect;
+ phoneIconRect.setSize(QSize(m_clientTypeIconSize, m_clientTypeIconSize));
+ phoneIconRect.moveTo(QPoint(optV4.rect.right() - rightIconsWidth,
+ optV4.rect.top() + (optV4.rect.height() - m_clientTypeIconSize) / 2));
+ painter->drawPixmap(phoneIconRect, phone);
+ }
+
+ QFont nameFont;
+ nameFont = KGlobalSettings::generalFont();
+
+ const QFontMetrics nameFontMetrics(nameFont);
+
+ 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->setFont(nameFont);
+
+ QRect userNameRect = optV4.rect;
+ userNameRect.setX(iconRect.x() + iconRect.width() + m_spacing * 2);
+ userNameRect.setY(userNameRect.y() + (userNameRect.height()/2 - nameFontMetrics.height()/2));
+ userNameRect.setWidth(userNameRect.width() - rightIconsWidth);
+
+ QString nameText = index.data(Qt::DisplayRole).toString();
+
+ painter->drawText(userNameRect,
+ nameFontMetrics.elidedText(nameText, Qt::ElideRight, userNameRect.width()));
+
+ painter->restore();
+}
+
+QSize ContactDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+ Q_UNUSED(option);
+ Q_UNUSED(index);
+
+ return QSize(0, qMax(m_avatarSize + 2 * m_spacing, KGlobalSettings::smallestReadableFont().pixelSize() + m_spacing));
+}
+
+#include "contact-delegate.moc"
diff --git a/lib/contact-delegate.h b/lib/contact-delegate.h
new file mode 100644
index 0000000..ea29a1b
--- /dev/null
+++ b/lib/contact-delegate.h
@@ -0,0 +1,46 @@
+/*
+ * Contact Delegate - compact version
+ *
+ * Copyright (C) 2011 Martin Klapetek <martin.klapetek at gmail.com>
+ * Copyright (C) 2014 David Edmundson <davidedmundson at kde.org>
+ *
+ * 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 <QStyledItemDelegate>
+
+
+#ifndef CONTACTDELEGATE_H
+#define CONTACTDELEGATE_H
+
+class ContactDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+
+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;
+
+private:
+ int m_spacing;
+ int m_avatarSize;
+ int m_presenceIconSize;
+ int m_clientTypeIconSize;
+};
+
+#endif // CONTACTDELEGATECOMPACT_H
--
ktp-text-ui packaging
More information about the pkg-kde-commits
mailing list