From f68e4c8c875497e192508a32edbca246b8957dff Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 20 Dec 2015 04:10:15 +0100 Subject: [PATCH] =?UTF-8?q?Improve=20the=20star=20icon=20of=20`favoritewid?= =?UTF-8?q?get`=20*=20Use=20the=20star=20icon=20in=20its=20native=20size?= =?UTF-8?q?=20(16=20px=20=C3=97=2016=20px)=20instead=20of=20unnecessarily?= =?UTF-8?q?=20scaling=20it=20down=20by=201=20px=20*=20Center=20the=20star?= =?UTF-8?q?=20icon=20vertically?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/widgets/favoritewidget.cpp | 17 ++++++++++++----- src/widgets/favoritewidget.h | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/widgets/favoritewidget.cpp b/src/widgets/favoritewidget.cpp index 72a751daf..ed5e88e74 100644 --- a/src/widgets/favoritewidget.cpp +++ b/src/widgets/favoritewidget.cpp @@ -22,18 +22,18 @@ #include #include #include +#include #include "core/logging.h" -const int FavoriteWidget::kStarSize = 15; +const int FavoriteWidget::kStarSize = 16; FavoriteWidget::FavoriteWidget(int tab_index, bool favorite, QWidget* parent) : QWidget(parent), tab_index_(tab_index), favorite_(favorite), on_(":/star-on.png"), - off_(":/star-off.png"), - rect_(0, 0, kStarSize, kStarSize) {} + off_(":/star-off.png") {} void FavoriteWidget::SetFavorite(bool favorite) { if (favorite_ != favorite) { @@ -53,12 +53,19 @@ void FavoriteWidget::paintEvent(QPaintEvent* e) { QStylePainter p(this); if (favorite_) { - p.drawPixmap(rect_, on_); + p.drawItemPixmap(rect_, Qt::AlignVCenter, on_); } else { - p.drawPixmap(rect_, off_); + p.drawItemPixmap(rect_, Qt::AlignVCenter, off_); } } +void FavoriteWidget::resizeEvent(QResizeEvent* e) { + // ignore text descent when vertically centering + QFontMetrics fontMetrics = QFontMetrics(this->font()); + rect_ = this->rect(); + rect_.setBottom(rect_.bottom() - fontMetrics.descent()); +} + void FavoriteWidget::mouseReleaseEvent(QMouseEvent* e) { favorite_ = !favorite_; update(); diff --git a/src/widgets/favoritewidget.h b/src/widgets/favoritewidget.h index 417109eaf..b98221a9a 100644 --- a/src/widgets/favoritewidget.h +++ b/src/widgets/favoritewidget.h @@ -37,6 +37,7 @@ signals: protected: void paintEvent(QPaintEvent* e); + void resizeEvent(QResizeEvent * e); void mouseReleaseEvent(QMouseEvent* e); private: