1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-23 16:28:19 +01:00

Merge pull request #5163 from Ede123/star_icon

Improve the star icon of `favoritewidget`
This commit is contained in:
John Maguire 2015-12-22 14:28:23 +00:00
commit 0c97803f11
2 changed files with 13 additions and 5 deletions

View File

@ -22,18 +22,18 @@
#include <QSize>
#include <QStyle>
#include <QStylePainter>
#include <QFontMetrics>
#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();

View File

@ -37,6 +37,7 @@ signals:
protected:
void paintEvent(QPaintEvent* e);
void resizeEvent(QResizeEvent * e);
void mouseReleaseEvent(QMouseEvent* e);
private: