summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2009-08-26 06:58:33 (GMT)
committerKevin Smith <git@kismith.co.uk>2009-08-26 06:58:33 (GMT)
commit887f585b613120875fe84750a2097378cbcc7560 (patch)
tree422eaf0280a6354cdcdac8b9d5e2bf54af7c7ad8 /Swift
parent5465cbdbcc065276a34ee7110560e191364f73ee (diff)
downloadswift-887f585b613120875fe84750a2097378cbcc7560.zip
swift-887f585b613120875fe84750a2097378cbcc7560.tar.bz2
Roster rendering now takes account of the text height as well as the avatar height.
Diffstat (limited to 'Swift')
-rw-r--r--Swift/QtUI/Roster/RosterDelegate.cpp38
-rw-r--r--Swift/QtUI/Roster/RosterDelegate.h4
2 files changed, 28 insertions, 14 deletions
diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp
index c6b8a8c..ae7a4b0 100644
--- a/Swift/QtUI/Roster/RosterDelegate.cpp
+++ b/Swift/QtUI/Roster/RosterDelegate.cpp
@@ -1,5 +1,6 @@
#include "RosterDelegate.h"
+#include <QApplication>
#include <QPainter>
#include <QColor>
#include <QBrush>
@@ -9,15 +10,26 @@
#include "QtTreeWidgetItem.h"
namespace Swift {
+
+RosterDelegate::RosterDelegate() : nameFont_(QApplication::font()), statusFont_(QApplication::font()) {
+ nameFont_.setPointSize(12);
+ statusFont_.setStyle(QFont::StyleItalic);
+ statusFont_.setPointSize(10);
+}
+
QSize RosterDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const {
QtTreeWidgetItem* item = static_cast<QtTreeWidgetItem*>(index.internalPointer());
- if (item && !item->isContact()) {
+ if (!item || !item->isContact()) {
return QStyledItemDelegate::sizeHint(option, index);
}
+ int sizeByAvatar = avatarSize_ + margin_ * 2;
+ QFontMetrics nameMetrics(nameFont_);
+ QFontMetrics statusMetrics(statusFont_);
+ int sizeByText = 2 * margin_ + nameMetrics.height() + statusMetrics.height();
//Doesn't work, yay! FIXME: why?
- QSize size = (option.state & QStyle::State_Selected) ? QSize(150, 80) : QSize(150, avatarSize_ + margin_ * 2);
+ //QSize size = (option.state & QStyle::State_Selected) ? QSize(150, 80) : QSize(150, avatarSize_ + margin_ * 2);
//qDebug() << "Returning size" << size;
- return size;
+ return QSize(150, sizeByText > sizeByAvatar ? sizeByText : sizeByAvatar);
}
void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
@@ -34,7 +46,10 @@ void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option
if ( option.state & QStyle::State_Selected ) {
painter->fillRect(fullRegion, option.palette.highlight());
painter->setPen(option.palette.highlightedText().color());
- }
+ } else {
+ QColor nameColor = index.data(Qt::TextColorRole).value<QColor>();
+ painter->setPen(QPen(nameColor));
+ }
QRect presenceIconRegion(QPoint(margin_, fullRegion.top()), QSize(presenceIconWidth_, fullRegion.height()));
@@ -51,22 +66,17 @@ void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option
: QIcon(":/icons/offline.png");
presenceIcon.paint(painter, presenceIconRegion, Qt::AlignBottom | Qt::AlignHCenter);
- QFont nameFont = painter->font();
- QFont statusFont = painter->font();
-
- painter->setFont(nameFont);
+ painter->setFont(nameFont_);
QRect textRegion(fullRegion.adjusted(avatarRegion.right() + margin_ * 2, 0, 0, 0));
- QFontMetrics nameMetrics(nameFont);
+ QFontMetrics nameMetrics(nameFont_);
int nameHeight = nameMetrics.height() + margin_;
QRect nameRegion(textRegion.adjusted(0, margin_, 0, 0));
- QColor nameColor = index.data(Qt::TextColorRole).value<QColor>();
- painter->setPen(QPen(nameColor));
+
painter->drawText(nameRegion, Qt::AlignTop, index.data(Qt::DisplayRole).toString());
- statusFont.setStyle(QFont::StyleItalic);
- statusFont.setPointSize(10);
- painter->setFont(statusFont);
+
+ painter->setFont(statusFont_);
painter->setPen(QPen(QColor(160,160,160)));
QRect statusTextRegion(textRegion.adjusted(0, nameHeight, 0, 0));
painter->drawText(statusTextRegion, Qt::AlignTop, index.data(StatusTextRole).toString());
diff --git a/Swift/QtUI/Roster/RosterDelegate.h b/Swift/QtUI/Roster/RosterDelegate.h
index 55775cf..dcbb665 100644
--- a/Swift/QtUI/Roster/RosterDelegate.h
+++ b/Swift/QtUI/Roster/RosterDelegate.h
@@ -2,13 +2,17 @@
#include <QStyledItemDelegate>
#include <QColor>
+#include <QFont>
namespace Swift {
class RosterDelegate : public QStyledItemDelegate {
public:
+ RosterDelegate();
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
private:
+ QFont nameFont_;
+ QFont statusFont_;
static const int avatarSize_ = 28;
static const int presenceIconHeight_ = 16;
static const int presenceIconWidth_ = 16;