[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:13:29 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-contact-list.git;a=commitdiff;h=b41e448
The following commit has been merged in the master branch:
commit b41e4481f92356e9688ea94e35854c1810647c21
Author: Martin Klapetek <martin.klapetek at gmail.com>
Date: Tue Jul 2 16:21:57 2013 +0200
Add special tooltips for Persons
They display list of child contacts sorted by their presence
Reviewed-by: David Edmundson
---
CMakeLists.txt | 2 +
tooltips/persontooltip.cpp | 136 +++++++++++++++++++++++
tooltips/{contacttooltip.h => persontooltip.h} | 24 ++--
tooltips/{contacttooltip.ui => persontooltip.ui} | 93 +++++++---------
tooltips/tooltipmanager.cpp | 10 +-
5 files changed, 202 insertions(+), 63 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a165045..40aa3fd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -51,6 +51,7 @@ set (ktp_contactlist_SRCS
tooltips/tooltipmanager.cpp
tooltips/ktooltipwindow.cpp
tooltips/contacttooltip.cpp
+ tooltips/persontooltip.cpp
)
configure_file(version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
@@ -59,6 +60,7 @@ kde4_add_ui_files (ktp_contactlist_SRCS
main-widget.ui
dialogs/remove-contact-dialog.ui
tooltips/contacttooltip.ui
+ tooltips/persontooltip.ui
)
kde4_add_executable (ktp-contactlist
diff --git a/tooltips/persontooltip.cpp b/tooltips/persontooltip.cpp
new file mode 100644
index 0000000..7b19bd9
--- /dev/null
+++ b/tooltips/persontooltip.cpp
@@ -0,0 +1,136 @@
+/*
+ * Person Tooltip
+ *
+ * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
+ * Copyright (C) 2013 Martin Klapetek <mklapetek 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 "persontooltip.h"
+
+#include "ui_persontooltip.h"
+#include "ktooltip.h"
+
+#include <KTp/types.h>
+#include <KTp/text-parser.h>
+#include <KTp/presence.h>
+
+#include <QDesktopServices>
+#include <QTextDocument>
+
+#include <KToolInvocation>
+
+bool contactLessThan(const QVariant &left, const QVariant &right)
+{
+ QModelIndex i1 = left.value<QModelIndex>();
+ QModelIndex i2 = right.value<QModelIndex>();
+
+ return KTp::Presence::sortPriority((Tp::ConnectionPresenceType)i1.data(KTp::ContactPresenceTypeRole).toInt())
+ < KTp::Presence::sortPriority((Tp::ConnectionPresenceType)i2.data(KTp::ContactPresenceTypeRole).toInt());
+}
+
+//-----------------------------------------------------------------------------
+
+PersonToolTip::PersonToolTip(const QModelIndex &index) :
+ QWidget(0),
+ ui(new Ui::PersonToolTip)
+{
+ ui->setupUi(this);
+ ui->nameLabel->setText(index.data(Qt::DisplayRole).toString());
+ ui->avatarLabel->setScaledContents(false);
+ ui->avatarLabel->setAlignment(Qt::AlignCenter);
+ ui->contactsLabel->setText(i18n("Contacts"));
+ ui->contactsWidget->setLayout(new QGridLayout(ui->contactsWidget));
+ qobject_cast<QGridLayout*>(ui->contactsWidget->layout())->setColumnStretch(1, 500);
+
+ QPixmap avatar = index.data(KTp::ContactAvatarPixmapRole).value<QPixmap>();
+ ui->avatarLabel->setPixmap(avatar);
+
+ int smallIconSize = KIconLoader::global()->currentSize(KIconLoader::Small);
+
+ ui->presenceIcon->setPixmap(KIcon(index.data(KTp::ContactPresenceIconRole).toString()).pixmap(smallIconSize, smallIconSize));
+ ui->presenceLabel->setText(index.data(KTp::ContactPresenceNameRole).toString());
+ ui->presenceMessageLabel->setText(index.data(KTp::ContactPresenceMessageRole).toString());
+
+ //collect child indexes for sorting
+ QList<QVariant> indexes;
+ for (int i = 0; i < index.model()->rowCount(index); i++) {
+ indexes << QVariant::fromValue<QModelIndex>(index.child(i, 0));
+ }
+
+ //sort indexes by presence
+ qSort(indexes.begin(), indexes.end(), contactLessThan);
+
+ //QLabel row counter
+ int row = 0;
+
+ Q_FOREACH (const QVariant &v, indexes)
+ {
+ QModelIndex i = v.value<QModelIndex>();
+ QLabel *contactPresenceLabel = new QLabel(ui->contactsWidget);
+ KIcon presenceIcon = KIcon(i.data(KTp::ContactPresenceIconRole).toString());
+ contactPresenceLabel->setPixmap(presenceIcon.pixmap(KIconLoader::SizeSmall, KIconLoader::SizeSmall));
+
+ QLabel *contactIdLabel = new QLabel(ui->contactsWidget);
+ contactIdLabel->setText(i.data(KTp::IdRole).toString());
+
+ qobject_cast<QGridLayout*>(ui->contactsWidget->layout())->addWidget(contactPresenceLabel, row, 0);
+ qobject_cast<QGridLayout*>(ui->contactsWidget->layout())->addWidget(contactIdLabel, row, 1);
+
+ row++;
+ }
+
+ connect(ui->presenceMessageLabel, SIGNAL(linkActivated(QString)), this, SLOT(openLink(QString)));
+
+ ui->blockedLabel->setShown(index.data(KTp::ContactIsBlockedRole).toBool());
+}
+
+PersonToolTip::~PersonToolTip()
+{
+ delete ui;
+}
+
+void PersonToolTip::openLink(QString url)
+{
+ KToolInvocation::invokeBrowser(url);
+ KToolTip::hideTip();
+}
+
+QString PersonToolTip::getTextWithHyperlinks(QString text)
+{
+ KTp::TextUrlData urls = KTp::TextParser::instance()->extractUrlData(text);
+ QString result;
+ int position = 0;
+
+ for (int i = 0; i < urls.fixedUrls.size(); ++i) {
+ QPair<int, int> pair = urls.urlRanges[i];
+ QString displayLink = text.mid(pair.first, pair.second);
+ QString fixedLink = urls.fixedUrls[i];
+
+ if (pair.first > position) {
+ result += Qt::escape(text.mid(position, pair.first - position));
+ }
+
+ result += QString("<a href=\"%1\">%2</a>").arg(Qt::escape(fixedLink)).arg(Qt::escape(displayLink));
+ position = pair.first + pair.second;
+ }
+
+ if (position < text.length()) {
+ result += Qt::escape(text.mid(position));
+ }
+
+ return result;
+}
diff --git a/tooltips/contacttooltip.h b/tooltips/persontooltip.h
similarity index 70%
copy from tooltips/contacttooltip.h
copy to tooltips/persontooltip.h
index 1b033be..d132433 100644
--- a/tooltips/contacttooltip.h
+++ b/tooltips/persontooltip.h
@@ -1,8 +1,8 @@
/*
- * Contact Tooltip
+ * Person Tooltip
*
* Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
- * Copyright (C) 2011 Geoffry Song <goffrie at gmail.com>
+ * Copyright (C) 2013 Martin Klapetek <mklapetek 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
@@ -19,32 +19,34 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef CONTACTTOOLTIP_H
-#define CONTACTTOOLTIP_H
+#ifndef PERSONTOOLTIP_H
+#define PERSONTOOLTIP_H
#include <QWidget>
#include <QModelIndex>
namespace Ui {
- class ContactToolTip;
+ class PersonToolTip;
}
-class ContactToolTip : public QWidget
+class PersonToolTip : public QWidget
{
Q_OBJECT
public:
- explicit ContactToolTip(const QModelIndex &index);
- ~ContactToolTip();
+ explicit PersonToolTip(const QModelIndex &index);
+ ~PersonToolTip();
- static QString getTextWithHyperlinks(QString text);
+ static QString getTextWithHyperlinks(QString text);
public slots:
void openLink(QString);
private:
- Ui::ContactToolTip *ui;
+ Ui::PersonToolTip *ui;
};
-#endif // CONTACTTOOLTIP_H
+Q_DECLARE_METATYPE(QModelIndex);
+
+#endif // PERSONTOOLTIP_H
diff --git a/tooltips/contacttooltip.ui b/tooltips/persontooltip.ui
similarity index 85%
copy from tooltips/contacttooltip.ui
copy to tooltips/persontooltip.ui
index 63e1bf2..2d97167 100644
--- a/tooltips/contacttooltip.ui
+++ b/tooltips/persontooltip.ui
@@ -1,20 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
- <class>ContactToolTip</class>
- <widget class="QWidget" name="ContactToolTip">
+ <class>PersonToolTip</class>
+ <widget class="QWidget" name="PersonToolTip">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>378</width>
- <height>114</height>
+ <height>119</height>
</rect>
</property>
- <layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,1,0,0" columnstretch="0,0,1">
+ <layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,0,0,0,0" columnstretch="0,0,0">
<property name="margin">
<number>0</number>
</property>
- <item row="0" column="0" rowspan="6">
+ <item row="3" column="2">
+ <widget class="QLabel" name="presenceMessageLabel">
+ <property name="text">
+ <string/>
+ </property>
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="7" column="0" colspan="3">
+ <widget class="QLabel" name="blockedLabel">
+ <property name="text">
+ <string>User is blocked</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" rowspan="7">
<widget class="QLabel" name="avatarLabel">
<property name="minimumSize">
<size>
@@ -39,22 +62,6 @@
</property>
</widget>
</item>
- <item row="0" column="1" rowspan="6">
- <widget class="QLabel" name="presenceIcon">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string/>
- </property>
- <property name="alignment">
- <set>Qt::AlignHCenter|Qt::AlignTop</set>
- </property>
- </widget>
- </item>
<item row="0" column="2">
<widget class="QLabel" name="nameLabel">
<property name="font">
@@ -71,8 +78,8 @@
</property>
</widget>
</item>
- <item row="1" column="2">
- <widget class="QLabel" name="idLabel">
+ <item row="4" column="2">
+ <widget class="QLabel" name="contactsLabel">
<property name="text">
<string/>
</property>
@@ -91,20 +98,23 @@
</property>
</widget>
</item>
- <item row="3" column="2">
- <widget class="QLabel" name="presenceMessageLabel">
+ <item row="0" column="1" rowspan="7">
+ <widget class="QLabel" name="presenceIcon">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="text">
<string/>
</property>
- <property name="textFormat">
- <enum>Qt::RichText</enum>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
+ <property name="alignment">
+ <set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
</widget>
</item>
- <item row="5" column="2">
+ <item row="6" column="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -120,25 +130,8 @@
</property>
</spacer>
</item>
- <item row="6" column="0" colspan="3">
- <widget class="QLabel" name="blockedLabel">
- <property name="text">
- <string>User is blocked</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignCenter</set>
- </property>
- </widget>
- </item>
- <item row="4" column="2">
- <widget class="QLabel" name="accountLabel">
- <property name="text">
- <string/>
- </property>
- <property name="textFormat">
- <enum>Qt::PlainText</enum>
- </property>
- </widget>
+ <item row="5" column="2">
+ <widget class="QWidget" name="contactsWidget" native="true"/>
</item>
</layout>
</widget>
diff --git a/tooltips/tooltipmanager.cpp b/tooltips/tooltipmanager.cpp
index 9abb9be..4246314 100644
--- a/tooltips/tooltipmanager.cpp
+++ b/tooltips/tooltipmanager.cpp
@@ -21,6 +21,7 @@
#include "ktooltip.h"
#include "contacttooltip.h"
+#include "persontooltip.h"
#include <QRect>
#include <QTimer>
@@ -149,7 +150,8 @@ void ToolTipManager::showToolTip(const QModelIndex &menuItem)
return;
}
- if (menuItem.data(KTp::RowTypeRole).toUInt() != KTp::ContactRowType) {
+ if (menuItem.data(KTp::RowTypeRole).toUInt() != KTp::ContactRowType
+ && menuItem.data(KTp::RowTypeRole).toUInt() != KTp::PersonRowType) {
return;
}
@@ -194,7 +196,11 @@ void ToolTipManager::showToolTip(const QModelIndex &menuItem)
QWidget * ToolTipManager::createTipContent(const QModelIndex &index)
{
- return new ContactToolTip(index);
+ if (index.data(KTp::RowTypeRole).toUInt() == KTp::PersonRowType) {
+ return new PersonToolTip(index);
+ } else {
+ return new ContactToolTip(index);
+ }
}
#include "tooltipmanager.moc"
--
ktp-contact-list packaging
More information about the pkg-kde-commits
mailing list