From de7ee8e38a2dfaab9fde40a7916c8212f5859d68 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Sat, 26 Jun 2010 20:21:31 +0100 Subject: Elide text in the various roster views. Resolves: #426 diff --git a/Swift/QtUI/ChatList/ChatListDelegate.cpp b/Swift/QtUI/ChatList/ChatListDelegate.cpp index ac05b07..274a10a 100644 --- a/Swift/QtUI/ChatList/ChatListDelegate.cpp +++ b/Swift/QtUI/ChatList/ChatListDelegate.cpp @@ -72,13 +72,13 @@ void ChatListDelegate::paintMUC(QPainter* painter, const QStyleOptionViewItem& o int nameHeight = nameMetrics.height() + common_.verticalMargin; QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0)); - painter->drawText(nameRegion, Qt::AlignTop, item->data(Qt::DisplayRole).toString()); + DelegateCommons::drawElidedText(painter, nameRegion, item->data(Qt::DisplayRole).toString()); painter->setFont(common_.detailFont); painter->setPen(QPen(QColor(160,160,160))); QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0)); - painter->drawText(detailRegion, Qt::AlignTop, item->data(DetailTextRole).toString()); + DelegateCommons::drawElidedText(painter, detailRegion, item->data(DetailTextRole).toString()); painter->restore(); } diff --git a/Swift/QtUI/EventViewer/TwoLineDelegate.cpp b/Swift/QtUI/EventViewer/TwoLineDelegate.cpp index 2437a44..08491b9 100644 --- a/Swift/QtUI/EventViewer/TwoLineDelegate.cpp +++ b/Swift/QtUI/EventViewer/TwoLineDelegate.cpp @@ -48,13 +48,13 @@ void TwoLineDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio int nameHeight = nameMetrics.height() + common_.verticalMargin; QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0)); - painter->drawText(nameRegion, Qt::AlignTop, event->data(firstRole_).toString()); + DelegateCommons::drawElidedText(painter, nameRegion, event->data(firstRole_).toString()); painter->setFont(common_.detailFont); painter->setPen(QPen(QColor(160,160,160))); QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0)); - painter->drawText(detailRegion, Qt::AlignTop, event->data(secondRole_).toString()); + DelegateCommons::drawElidedText(painter, detailRegion, event->data(secondRole_).toString()); painter->restore(); } diff --git a/Swift/QtUI/Roster/DelegateCommons.cpp b/Swift/QtUI/Roster/DelegateCommons.cpp index 3cd3695..164b80f 100644 --- a/Swift/QtUI/Roster/DelegateCommons.cpp +++ b/Swift/QtUI/Roster/DelegateCommons.cpp @@ -7,7 +7,18 @@ #include "DelegateCommons.h" namespace Swift { + + +void DelegateCommons::drawElidedText(QPainter* painter, const QRect& region, const QString& text) { + QString adjustedText(painter->fontMetrics().elidedText(text, Qt::ElideRight, region.width(), Qt::TextShowMnemonic)); + painter->drawText(region, Qt::AlignTop, adjustedText); +} + + const int DelegateCommons::horizontalMargin = 2; const int DelegateCommons::verticalMargin = 2; const int DelegateCommons::farLeftMargin = 2; + + + } diff --git a/Swift/QtUI/Roster/DelegateCommons.h b/Swift/QtUI/Roster/DelegateCommons.h index ac5efc4..9213ef5 100644 --- a/Swift/QtUI/Roster/DelegateCommons.h +++ b/Swift/QtUI/Roster/DelegateCommons.h @@ -8,6 +8,9 @@ #include #include +#include +#include +#include namespace Swift { class DelegateCommons { @@ -18,6 +21,8 @@ namespace Swift { detailFont.setPointSize(nameFont.pointSize() - detailFontSizeDrop); } + static void drawElidedText(QPainter* painter, const QRect& region, const QString& text); + int detailFontSizeDrop; QFont nameFont; QFont detailFont; diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp index b7ba71b..f5dcbd6 100644 --- a/Swift/QtUI/Roster/RosterDelegate.cpp +++ b/Swift/QtUI/Roster/RosterDelegate.cpp @@ -105,20 +105,22 @@ void RosterDelegate::paintContact(QPainter* painter, const QStyleOptionViewItem& int nameHeight = nameMetrics.height() + common_.verticalMargin; QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0)); - painter->drawText(nameRegion, Qt::AlignTop, index.data(Qt::DisplayRole).toString()); + DelegateCommons::drawElidedText(painter, nameRegion, index.data(Qt::DisplayRole).toString()); painter->setFont(common_.detailFont); painter->setPen(QPen(QColor(160,160,160))); QRect statusTextRegion(textRegion.adjusted(0, nameHeight, 0, 0)); - painter->drawText(statusTextRegion, Qt::AlignTop, index.data(StatusTextRole).toString()); + DelegateCommons::drawElidedText(painter, statusTextRegion, index.data(StatusTextRole).toString()); painter->restore(); } + const int RosterDelegate::avatarSize_ = 20; const int RosterDelegate::presenceIconHeight_ = 16; const int RosterDelegate::presenceIconWidth_ = 16; } + -- cgit v0.10.2-6-g49f6