[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:10 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=eb3c267

The following commit has been merged in the master branch:
commit eb3c267674045fb22bb66bc87e4a966d71a4f015
Author: Dan Vrátil <dvratil at redhat.com>
Date:   Sun Sep 15 15:53:52 2013 +0200

    Use account icon instead of name in LogViewer
    
    REVIEW: 112736
    BUG: 324919
---
 logviewer/dates-view-delegate.cpp  | 41 ++++++++++++++----------------
 logviewer/dates-view-delegate.h    |  3 +++
 logviewer/entity-view-delegate.cpp | 51 ++++++++++++--------------------------
 3 files changed, 38 insertions(+), 57 deletions(-)

diff --git a/logviewer/dates-view-delegate.cpp b/logviewer/dates-view-delegate.cpp
index af7536c..41507cd 100644
--- a/logviewer/dates-view-delegate.cpp
+++ b/logviewer/dates-view-delegate.cpp
@@ -24,12 +24,17 @@
 
 #include <KDE/KGlobalSettings>
 #include <KDE/KIconLoader>
+#include <KDE/KIcon>
 
+#include <TelepathyQt/Account>
 
 #include "dates-model.h"
 
+Q_DECLARE_METATYPE(Tp::AccountPtr)
+
 DatesViewDelegate::DatesViewDelegate(QObject* parent):
-    QStyledItemDelegate(parent)
+    QStyledItemDelegate(parent),
+    m_spacing(2)
 {
 }
 
@@ -39,10 +44,13 @@ DatesViewDelegate::~DatesViewDelegate()
 
 QSize DatesViewDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
 {
+    Q_UNUSED(option);
+
     if (index.data(DatesModel::TypeRole).toUInt() == DatesModel::GroupRow) {
         return QSize(0, qMax(22, KGlobalSettings::smallestReadableFont().pixelSize()) + 2 + 1);
     } else {
-        return QStyledItemDelegate::sizeHint(option, index);
+        return QSize(0, qMax(KIconLoader::global()->currentSize(KIconLoader::Small) + m_spacing,
+                             KGlobalSettings::smallestReadableFont().pixelSize() + 2 + 1));
     }
 }
 
@@ -132,8 +140,6 @@ void DatesViewDelegate::paintItem(QPainter* painter, const QStyleOptionViewItem&
     QStyle *style = QApplication::style();
     style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter);
 
-    const int itemWidth = option.rect.width();
-
     int iconSize = IconSize(KIconLoader::KIconLoader::Toolbar);
 
     QRect itemRect = optV4.rect;
@@ -159,11 +165,12 @@ void DatesViewDelegate::paintItem(QPainter* painter, const QStyleOptionViewItem&
         }
     }
 
+    iconSize = IconSize(KIconLoader::KIconLoader::Small);
     const QString date = index.data(Qt::DisplayRole).toString();
     QRect dateRect = itemRect;
     dateRect.setX(dateRect.x() + 20);
     dateRect.setY(dateRect.y() + (dateRect.height() / 2 - option.fontMetrics.height() / 2));
-    dateRect.setWidth(qMin(option.fontMetrics.width(date) + 8, static_cast<int>(itemWidth * 2.0 / 3.0)));
+    dateRect.setWidth(qMin(option.fontMetrics.width(date) + 8, optV4.rect.width() - iconSize - (2 * m_spacing)));
 
     if (option.state & QStyle::State_Selected) {
         painter->setPen(option.palette.color(QPalette::Active, QPalette::HighlightedText));
@@ -172,25 +179,15 @@ void DatesViewDelegate::paintItem(QPainter* painter, const QStyleOptionViewItem&
     }
     painter->drawText(dateRect, option.fontMetrics.elidedText(date, Qt::ElideRight, dateRect.width()));
 
-    const QFont hintFont = KGlobalSettings::smallestReadableFont();
-    const QFontMetrics hintFontMetrics(hintFont);
-    const QString hint = index.data(DatesModel::HintRole).toString();
-    const int hintWidth = hintFontMetrics.width(hint);
-
-    QRect hintRect = itemRect;
-    hintRect.setX(qMax(itemWidth - 8 - hintWidth, dateRect.x() + dateRect.width()));
-    hintRect.setY(hintRect.y() + (hintRect.height() - hintFontMetrics.height()));
-    hintRect.setWidth(itemWidth - hintRect.x());
+    painter->restore();
 
-    painter->setFont(hintFont);
-    if (option.state & QStyle::State_Selected) {
-        painter->setPen(option.palette.color(QPalette::QPalette::Disabled, QPalette::HighlightedText));
-    } else {
-        painter->setPen(option.palette.color(QPalette::Disabled, QPalette::Text));
+    const Tp::AccountPtr &account = index.data(DatesModel::AccountRole).value<Tp::AccountPtr>();
+    if (account) {
+        const QPixmap accountIcon = KIcon(account->iconName()).pixmap(iconSize);
+        QRect accountIconRect = optV4.rect;
+        accountIconRect.adjust(optV4.rect.width() - iconSize - m_spacing, 0, 0, 0);
+        style->drawItemPixmap(painter, accountIconRect, 0, accountIcon);
     }
-    painter->drawText(hintRect, hintFontMetrics.elidedText(hint, Qt::ElideLeft, hintRect.width()));
-
-    painter->restore();
 }
 
 
diff --git a/logviewer/dates-view-delegate.h b/logviewer/dates-view-delegate.h
index 3045e3d..484eb5c 100644
--- a/logviewer/dates-view-delegate.h
+++ b/logviewer/dates-view-delegate.h
@@ -36,6 +36,9 @@ class DatesViewDelegate : public QStyledItemDelegate
   private:
     void paintGroup(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
     void paintItem(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
+
+  private:
+    int m_spacing;
 };
 
 #endif // DATESVIEWDELEGATE_H
diff --git a/logviewer/entity-view-delegate.cpp b/logviewer/entity-view-delegate.cpp
index cbede65..0599e77 100644
--- a/logviewer/entity-view-delegate.cpp
+++ b/logviewer/entity-view-delegate.cpp
@@ -30,14 +30,12 @@
 
 #include <TelepathyQt/Account>
 
-const int SPACING = 2;
-const int ACCOUNT_ICON_SIZE = 22;
 const qreal GROUP_ICON_OPACITY = 0.6;
 
 EntityViewDelegate::EntityViewDelegate(QObject* parent):
     QStyledItemDelegate(parent),
     m_avatarSize(IconSize(KIconLoader::Toolbar)),
-    m_spacing(4)
+    m_spacing(2)
 {
 }
 
@@ -119,40 +117,23 @@ void EntityViewDelegate::paintContact(QPainter* painter, const QStyleOptionViewI
     QRect userNameRect = optV4.rect;
     userNameRect.setX(iconRect.x() + iconRect.width() + m_spacing * 2);
     userNameRect.setY(userNameRect.y() + (userNameRect.height() / 2 - nameFontMetrics.height() / 2));
+    userNameRect.setHeight(nameFontMetrics.height());
     if (isEntity) {
-        userNameRect.setWidth(qMin(nameFontMetrics.width(nameText), static_cast<int>(optV4.rect.width() * 2.0 / 3.0)));
+        userNameRect.setWidth(qMin(nameFontMetrics.width(nameText), optV4.rect.width() - m_avatarSize - (2 * m_spacing)));
     }
 
+    QTextOption textOption;
+    textOption.setWrapMode(QTextOption::NoWrap);
     painter->drawText(userNameRect,
-                      nameFontMetrics.elidedText(nameText, Qt::ElideRight, userNameRect.width()));
-
+                      nameFontMetrics.elidedText(nameText, Qt::ElideRight, userNameRect.width()), textOption);
     painter->restore();
 
-    if (isEntity) {
-        painter->save();
-
-        const QFont accountFont = KGlobalSettings::generalFont();
-        const QFontMetrics accountMetrics(accountFont);
-
-        if (option.state & QStyle::State_Selected) {
-            painter->setPen(option.palette.color(QPalette::Disabled, QPalette::HighlightedText));
-        } else {
-            painter->setPen(option.palette.color(QPalette::Disabled, QPalette::Text));
-        }
-
-        painter->setFont(accountFont);
-
-        const Tp::AccountPtr account = index.data(PersonEntityMergeModel::AccountRole).value<Tp::AccountPtr>();
-        const QString accountName = account->displayName();
-        const int accountWidth = accountMetrics.width(accountName);
-
-        QRect accountRect = optV4.rect;
-        accountRect.setX(qMax(optV4.rect.width() - (2 * m_spacing) - accountWidth, userNameRect.x() + userNameRect.width()));
-        accountRect.setY(accountRect.y() + accountRect.height() / 2 - accountMetrics.height() / 2);
-        accountRect.setWidth(optV4.rect.width() - accountRect.x());
-        painter->drawText(accountRect, accountMetrics.elidedText(accountName, Qt::ElideLeft, accountRect.width()));
-
-        painter->restore();
+    const Tp::AccountPtr &account = index.data(KTp::AccountRole).value<Tp::AccountPtr>();
+    if (isEntity && account) {
+        const QPixmap accountIcon = KIcon(account->iconName()).pixmap(m_avatarSize);
+        QRect accountIconRect = optV4.rect;
+        accountIconRect.adjust(optV4.rect.width() - m_avatarSize - m_spacing, 0, 0, 0);
+        style->drawItemPixmap(painter, accountIconRect, 0, accountIcon);
     }
 }
 
@@ -194,7 +175,7 @@ void EntityViewDelegate::paintHeader(QPainter* painter, const QStyleOptionViewIt
     painter->setRenderHint(QPainter::Antialiasing, true);
 
     //remove spacing from the sides and one point to the bottom for the 1px line
-    groupRect.adjust(SPACING, 0, -SPACING, -1);
+    groupRect.adjust(m_spacing, 0, -m_spacing, -1);
 
     //get the proper rect for the expand sign
     int iconSize = IconSize(KIconLoader::Toolbar);
@@ -215,7 +196,7 @@ void EntityViewDelegate::paintHeader(QPainter* painter, const QStyleOptionViewIt
     const QFont groupFont = KGlobalSettings::smallestReadableFont();
 
     //paint the header string
-    const QRect groupLabelRect = groupRect.adjusted(expandSignOption.rect.width() + SPACING * 2, 0, -SPACING, 0);
+    const QRect groupLabelRect = groupRect.adjusted(expandSignOption.rect.width() + m_spacing * 2, 0, -m_spacing, 0);
     const QString groupHeaderString =  index.data(Qt::DisplayRole).toString();
     const QFontMetrics groupFontMetrics(groupFont);
 
@@ -224,7 +205,7 @@ void EntityViewDelegate::paintHeader(QPainter* painter, const QStyleOptionViewIt
     painter->setPen(option.palette.color(QPalette::Active, QPalette::Text));
     painter->drawText(groupLabelRect, Qt::AlignVCenter | Qt::AlignLeft,
                       groupFontMetrics.elidedText(groupHeaderString, Qt::ElideRight,
-                                                  groupLabelRect.width() - SPACING));
+                                                  groupLabelRect.width() - m_spacing));
 
     painter->restore();
 }
@@ -234,7 +215,7 @@ QSize EntityViewDelegate::sizeHintHeader(const QStyleOptionViewItem& option, con
     Q_UNUSED(option)
     Q_UNUSED(index)
     // Add one point to the bottom for the 1px line
-    return QSize(0, qMax(ACCOUNT_ICON_SIZE, KGlobalSettings::smallestReadableFont().pixelSize()) + SPACING + 1);
+    return QSize(0, qMax(m_avatarSize, KGlobalSettings::smallestReadableFont().pixelSize()) + m_spacing + 1);
 }
 
 

-- 
ktp-text-ui packaging



More information about the pkg-kde-commits mailing list