2010-10-10 19:59:23 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-10-10 19:59:23 +02:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "songplaystats.h"
|
|
|
|
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
const int SongPlayStats::kIconSize = 16;
|
|
|
|
const int SongPlayStats::kLineSpacing = 2;
|
|
|
|
const int SongPlayStats::kIconTextSpacing = 6;
|
2010-10-10 21:25:53 +02:00
|
|
|
const int SongPlayStats::kMargin = 4;
|
2010-10-10 19:59:23 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
SongPlayStats::SongPlayStats(QWidget* parent) : QWidget(parent) {
|
2010-10-10 19:59:23 +02:00
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SongPlayStats::AddItem(const QIcon& icon, const QString& text) {
|
|
|
|
items_ << Item(icon, text);
|
|
|
|
updateGeometry();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize SongPlayStats::sizeHint() const {
|
2014-02-07 16:34:20 +01:00
|
|
|
return QSize(100, kMargin * 2 + items_.count() * kIconSize +
|
|
|
|
(items_.count() - 1) * kLineSpacing);
|
2010-10-10 19:59:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SongPlayStats::paintEvent(QPaintEvent*) {
|
|
|
|
QPainter p(this);
|
|
|
|
|
2010-10-10 21:25:53 +02:00
|
|
|
int y = kMargin;
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const Item& item : items_) {
|
2014-02-07 16:34:20 +01:00
|
|
|
const QRect line(kMargin, y, width() - kMargin * 2, kIconSize);
|
2010-10-10 19:59:23 +02:00
|
|
|
const QRect icon_rect(line.topLeft(), QSize(kIconSize, kIconSize));
|
2014-02-07 16:34:20 +01:00
|
|
|
const QRect text_rect(
|
|
|
|
icon_rect.topRight() + QPoint(kIconTextSpacing, 0),
|
|
|
|
QSize(line.width() - icon_rect.width() - kIconTextSpacing,
|
|
|
|
line.height()));
|
2010-10-10 19:59:23 +02:00
|
|
|
|
|
|
|
p.drawPixmap(icon_rect, item.icon_.pixmap(kIconSize));
|
|
|
|
p.drawText(text_rect, item.text_);
|
|
|
|
|
|
|
|
y += line.height() + kLineSpacing;
|
|
|
|
}
|
|
|
|
}
|