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


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-contact-list.git;a=commitdiff;h=c9c9e46

The following commit has been merged in the master branch:
commit c9c9e46c52cb9f3aa640d51abbc51fb631c0b561
Author: Martin Klapetek <martin.klapetek at gmail.com>
Date:   Sun Feb 17 20:57:12 2013 +0100

    Improve contact list header delegate
    
     * Increased spacing
     * Increased account icon size
     * Increased header height to be the same as contact's
     * Background is now solid color (button's color)
     * Stuff is better aligned with the contacts
     * Group icons were removed (didn't bring any value, just clutter)
     * Added some code comments
    
    REVIEW: 106763
---
 abstract-contact-delegate.cpp | 107 +++++++++++++++++++-----------------------
 1 file changed, 48 insertions(+), 59 deletions(-)

diff --git a/abstract-contact-delegate.cpp b/abstract-contact-delegate.cpp
index 836913f..8b70eed 100644
--- a/abstract-contact-delegate.cpp
+++ b/abstract-contact-delegate.cpp
@@ -33,13 +33,12 @@
 #include <KDE/KIcon>
 
 #include <KTp/types.h>
-#include <KDebug>
 
-const int SPACING = 2;
-const int ACCOUNT_ICON_SIZE = 16;
+const int SPACING = 4;
+const int ACCOUNT_ICON_SIZE = 22;
 
-AbstractContactDelegate::AbstractContactDelegate(QObject* parent)
-        : QStyledItemDelegate(parent)
+AbstractContactDelegate::AbstractContactDelegate(QObject *parent)
+    : QStyledItemDelegate(parent)
 {
 }
 
@@ -47,7 +46,7 @@ AbstractContactDelegate::~AbstractContactDelegate()
 {
 }
 
-void AbstractContactDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
+void AbstractContactDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
 {
     if (index.data(KTp::RowTypeRole).toInt() == KTp::ContactRowType) {
         paintContact(painter, option, index);
@@ -56,7 +55,7 @@ void AbstractContactDelegate::paint(QPainter* painter, const QStyleOptionViewIte
     }
 }
 
-QSize AbstractContactDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
+QSize AbstractContactDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
 {
     Q_UNUSED(option);
 
@@ -83,71 +82,61 @@ void AbstractContactDelegate::paintHeader(QPainter *painter, const QStyleOptionV
 
     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));
+    //paint the background
+    QBrush bgBrush(option.palette.color(QPalette::Active, QPalette::Button).lighter(105));
+    painter->fillRect(groupRect, bgBrush);
 
-    QRect groupLabelRect = groupRect;
-    groupLabelRect.setRight(groupLabelRect.right() - SPACING);
-
-    QRect expandSignRect = groupLabelRect;
-    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(KTp::HeaderOnlineUsersRole).toString(),
-                     index.data(KTp::HeaderTotalUsersRole).toString());
+    //paint very subtle line at the bottom
+    QPen thinLinePen;
+    thinLinePen.setWidth(0);
+    thinLinePen.setColor(option.palette.color(QPalette::Active, QPalette::Button));
+    painter->setPen(thinLinePen);
+    //to get nice sharp 1px line we need to turn AA off, otherwise it will be all blurry
+    painter->setRenderHint(QPainter::Antialiasing, false);
+    painter->drawLine(groupRect.bottomLeft(), groupRect.bottomRight());
+    painter->setRenderHint(QPainter::Antialiasing, true);
 
-    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));
-    }
+    //get the proper rect for the expand sign
+    int iconSize = IconSize(KIconLoader::Toolbar);
 
-    //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);
+    QStyleOption expandSignOption = option;
+    expandSignOption.rect = groupRect;
+    expandSignOption.rect.setSize(QSize(iconSize, iconSize));
+    expandSignOption.rect.moveLeft(groupRect.left() + SPACING);
+    expandSignOption.rect.moveTop(groupRect.top() + 3);
 
-    if (option.state & QStyle::State_Selected) {
-        painter->setPen(option.palette.color(QPalette::Active, QPalette::HighlightedText));
+    //paint the expand sign
+    if (option.state & QStyle::State_Open) {
+        style->drawPrimitive(QStyle::PE_IndicatorArrowDown, &expandSignOption, painter);
     } else {
-        painter->setPen(option.palette.color(QPalette::Active, QPalette::Text));
+        style->drawPrimitive(QStyle::PE_IndicatorArrowRight, &expandSignOption, painter);
     }
 
-    painter->setFont(groupFont);
-    painter->drawText(textRect, Qt::AlignVCenter | Qt::AlignRight,
-                      optV4.fontMetrics.elidedText(groupHeaderString, Qt::ElideRight, textRect.width()));
-
+    QFont groupFont = KGlobalSettings::smallestReadableFont();
 
-    QPen thinLinePen;
-    thinLinePen.setWidth(0);
-    thinLinePen.setColor(option.palette.color(QPalette::Inactive, QPalette::Button));
+    //paint the header string
+    QRect groupLabelRect;
+    groupLabelRect.setSize(QSize(groupRect.width() - expandSignOption.rect.width(), groupRect.height()));
+    groupLabelRect.moveTo(QPoint(groupRect.left() + expandSignOption.rect.width() + SPACING * 3, groupRect.top() + 2));
 
-    painter->setPen(thinLinePen);
-    painter->setRenderHint(QPainter::Antialiasing, false);
+    QString counts = QString(" (%1/%2)").arg(index.data(KTp::HeaderOnlineUsersRole).toString(),
+                                             index.data(KTp::HeaderTotalUsersRole).toString());
 
-    QFontMetrics fm = painter->fontMetrics();
-    int groupNameWidth = fm.width(groupHeaderString);
+    QString groupHeaderString =  index.data(Qt::DisplayRole).toString().append(counts);
 
-    //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);
+    painter->setPen(option.palette.color(QPalette::Active, QPalette::Text));
+    painter->setFont(groupFont);
+    painter->drawText(groupLabelRect, Qt::AlignVCenter | Qt::AlignLeft,
+                      optV4.fontMetrics.elidedText(groupHeaderString, Qt::ElideRight, groupLabelRect.width()));
 
-    QStyleOption expandSignOption = option;
-    expandSignOption.rect = expandSignRect;
+    //paint the group icon
+    QRect groupIconRect;
+    groupIconRect.setSize(QSize(ACCOUNT_ICON_SIZE, ACCOUNT_ICON_SIZE));
+    groupIconRect.moveTo(QPoint(groupRect.right() - ACCOUNT_ICON_SIZE - 2, groupRect.top() + 2));
 
-    if (option.state & QStyle::State_Open) {
-        style->drawPrimitive(QStyle::PE_IndicatorArrowDown, &expandSignOption, painter);
-    } else {
-        style->drawPrimitive(QStyle::PE_IndicatorArrowRight, &expandSignOption, painter);
+    if (index.data(KTp::RowTypeRole).toInt() == KTp::AccountRowType) {
+        painter->drawPixmap(groupIconRect, KIcon(index.data(Qt::DecorationRole).value<QIcon>()).pixmap(32));
     }
 
     painter->restore();
@@ -157,7 +146,7 @@ QSize AbstractContactDelegate::sizeHintHeader(const QStyleOptionViewItem &option
 {
     Q_UNUSED(option)
     Q_UNUSED(index)
-    return QSize(0,20);
+    return QSize(0, qMax(ACCOUNT_ICON_SIZE + 2 * SPACING, KGlobalSettings::smallestReadableFont().pixelSize() + SPACING));
 }
 
 bool AbstractContactDelegate::helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index)

-- 
ktp-contact-list packaging



More information about the pkg-kde-commits mailing list