diff options
Diffstat (limited to 'Swift/QtUI/Roster')
-rw-r--r-- | Swift/QtUI/Roster/RosterDelegate.cpp | 31 | ||||
-rw-r--r-- | Swift/QtUI/Roster/RosterModel.cpp | 10 | ||||
-rw-r--r-- | Swift/QtUI/Roster/RosterModel.h | 2 |
3 files changed, 20 insertions, 23 deletions
diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp index 47ae948..aaa6236 100644 --- a/Swift/QtUI/Roster/RosterDelegate.cpp +++ b/Swift/QtUI/Roster/RosterDelegate.cpp @@ -12,6 +12,7 @@ #include <QBrush> #include <QFontMetrics> #include <QPainterPath> +#include <QFileInfo> #include <QPolygon> #include <qdebug.h> #include <QBitmap> @@ -21,6 +22,7 @@ #include "QtTreeWidget.h" #include "RosterModel.h" +#include "QtScaledAvatarCache.h" namespace Swift { @@ -86,23 +88,18 @@ void RosterDelegate::paintContact(QPainter* painter, const QStyleOptionViewItem& int calculatedAvatarSize = presenceIconRegion.height(); //This overlaps the presenceIcon, so must be painted first QRect avatarRegion(QPoint(presenceIconRegion.right() - presenceIconWidth_ / 2, presenceIconRegion.top()), QSize(calculatedAvatarSize, calculatedAvatarSize)); - QIcon avatar = index.data(AvatarRole).isValid() && !index.data(AvatarRole).value<QIcon>().isNull() - ? index.data(AvatarRole).value<QIcon>() - : QIcon(":/icons/avatar.png"); - - // Apply a rounded rectangle mask - // FIXME: We shouldn't go via a 128x128 pixmap - QPixmap avatarPixmap = avatar.pixmap(128, 128); - QPixmap maskedAvatar(avatarPixmap.size()); - maskedAvatar.fill(QColor(0, 0, 0, 0)); - QPainter maskPainter(&maskedAvatar); - maskPainter.setBrush(Qt::black); - maskPainter.drawRoundedRect(maskedAvatar.rect(), 13, 13); - maskPainter.setCompositionMode(QPainter::CompositionMode_SourceIn); - maskPainter.drawPixmap(0, 0, avatarPixmap); - maskPainter.end(); - - avatarPixmap = maskedAvatar.scaled(avatarRegion.height(), avatarRegion.width(), Qt::KeepAspectRatio, Qt::SmoothTransformation); + + QPixmap avatarPixmap; + if (index.data(AvatarRole).isValid() && !index.data(AvatarRole).value<QString>().isNull()) { + QString avatarPath = index.data(AvatarRole).value<QString>(); + QString scaledAvatarPath = QtScaledAvatarCache(avatarRegion.height()).getScaledAvatarPath(avatarPath); + if (QFileInfo(scaledAvatarPath).exists()) { + avatarPixmap.load(scaledAvatarPath); + } + } + if (avatarPixmap.isNull()) { + avatarPixmap = QPixmap(":/icons/avatar.png").scaled(avatarRegion.height(), avatarRegion.width(), Qt::KeepAspectRatio, Qt::SmoothTransformation); + } painter->drawPixmap(avatarRegion.topLeft() + QPoint(((avatarRegion.width() - avatarPixmap.width()) / 2), (avatarRegion.height() - avatarPixmap.height()) / 2), avatarPixmap); diff --git a/Swift/QtUI/Roster/RosterModel.cpp b/Swift/QtUI/Roster/RosterModel.cpp index 2399a21..1fc20dd 100644 --- a/Swift/QtUI/Roster/RosterModel.cpp +++ b/Swift/QtUI/Roster/RosterModel.cpp @@ -135,12 +135,12 @@ QString RosterModel::getToolTip(RosterItem* item) const { return tip; } -QIcon RosterModel::getAvatar(RosterItem* item) const { +QString RosterModel::getAvatar(RosterItem* item) const { ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item); - if (!contact) return QIcon(); - std::string path = contact->getAvatarPath(); - - return path.empty() ? QIcon() : QIcon(P2QSTRING(path)); + if (!contact) { + return ""; + } + return QString(contact->getAvatarPath().c_str()); } QString RosterModel::getStatusText(RosterItem* item) const { diff --git a/Swift/QtUI/Roster/RosterModel.h b/Swift/QtUI/Roster/RosterModel.h index 964f680..bd34e9c 100644 --- a/Swift/QtUI/Roster/RosterModel.h +++ b/Swift/QtUI/Roster/RosterModel.h @@ -44,7 +44,7 @@ namespace Swift { QColor getTextColor(RosterItem* item) const; QColor getBackgroundColor(RosterItem* item) const; QString getToolTip(RosterItem* item) const; - QIcon getAvatar(RosterItem* item) const; + QString getAvatar(RosterItem* item) const; QString getStatusText(RosterItem* item) const; QIcon getPresenceIcon(RosterItem* item) const; int getChildCount(RosterItem* item) const; |