summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-02-22 21:15:59 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-02-22 21:15:59 (GMT)
commitf0142e0ea71a1f89b8c46ab6bde7e188c0bc79f4 (patch)
treea3149bac20c7859e17d574ad5c1bf19096d20de8
parent66105a538fca090f9d251a7173ad79ae2f5727e5 (diff)
downloadswift-f0142e0ea71a1f89b8c46ab6bde7e188c0bc79f4.zip
swift-f0142e0ea71a1f89b8c46ab6bde7e188c0bc79f4.tar.bz2
Fixed rounded rectangles not drawing background properly.
-rw-r--r--Swift/QtUI/QtRosterHeader.cpp20
-rw-r--r--Swift/QtUI/Roster/RosterDelegate.cpp15
2 files changed, 21 insertions, 14 deletions
diff --git a/Swift/QtUI/QtRosterHeader.cpp b/Swift/QtUI/QtRosterHeader.cpp
index 1dc513b..18bb980 100644
--- a/Swift/QtUI/QtRosterHeader.cpp
+++ b/Swift/QtUI/QtRosterHeader.cpp
@@ -78,17 +78,21 @@ void QtRosterHeader::setAvatar(const QString& path) {
}
// Apply a rounded rectangle mask
- // FIXME: We shouldn't go via a 128x128 pixmap
+ // FIXME:
+ // - We shouldn't go via a 128x128 pixmap
+ // - Something tells me we can do this with clever composition mode +
+ // 1 drawRectangle on the avatarPixmap, but i haven't figured it out yet.
QPixmap avatarPixmap = avatar.pixmap(128, 128);
- QPixmap mask(avatarPixmap.size());
- QPainter maskPainter(&mask);
- maskPainter.fillRect(mask.rect(), Qt::white);
+ QPixmap maskedAvatar(avatarPixmap.size());
+ maskedAvatar.fill(QColor(0, 0, 0, 0));
+ QPainter maskPainter(&maskedAvatar);
maskPainter.setBrush(Qt::black);
- maskPainter.drawRoundedRect(mask.rect(), 13, 13);
- avatarPixmap.setMask(mask.createMaskFromColor(Qt::white));
- avatarPixmap = avatarPixmap.scaled(avatarSize_, avatarSize_, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ maskPainter.drawRoundedRect(maskedAvatar.rect(), 13, 13);
+ maskPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
+ maskPainter.drawPixmap(0, 0, avatarPixmap);
+ maskPainter.end();
- avatarLabel_->setPixmap(avatarPixmap);
+ avatarLabel_->setPixmap(maskedAvatar.scaled(avatarSize_, avatarSize_, Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
void QtRosterHeader::setNick(const QString& nick) {
diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp
index 5f6e778..47ae948 100644
--- a/Swift/QtUI/Roster/RosterDelegate.cpp
+++ b/Swift/QtUI/Roster/RosterDelegate.cpp
@@ -93,13 +93,16 @@ void RosterDelegate::paintContact(QPainter* painter, const QStyleOptionViewItem&
// Apply a rounded rectangle mask
// FIXME: We shouldn't go via a 128x128 pixmap
QPixmap avatarPixmap = avatar.pixmap(128, 128);
- QPixmap mask(avatarPixmap.size());
- QPainter maskPainter(&mask);
- maskPainter.fillRect(mask.rect(), Qt::white);
+ QPixmap maskedAvatar(avatarPixmap.size());
+ maskedAvatar.fill(QColor(0, 0, 0, 0));
+ QPainter maskPainter(&maskedAvatar);
maskPainter.setBrush(Qt::black);
- maskPainter.drawRoundedRect(mask.rect(), 13, 13);
- avatarPixmap.setMask(mask.createMaskFromColor(Qt::white));
- avatarPixmap = avatarPixmap.scaled(avatarRegion.height(), avatarRegion.width(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ 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);
painter->drawPixmap(avatarRegion.topLeft() + QPoint(((avatarRegion.width() - avatarPixmap.width()) / 2), (avatarRegion.height() - avatarPixmap.height()) / 2), avatarPixmap);