1
/* This file is part of Clementine.
2
Copyright 2010, David Sansome <me@davidsansome.com>
4
Clementine is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
9
Clementine is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
18
#include "tooltipresultwidget.h"
19
#include "core/logging.h"
23
const int TooltipResultWidget::kBorder = 15;
24
const int TooltipResultWidget::kSpacing = 3;
25
const int TooltipResultWidget::kTrackNumSpacing = 6;
26
const int TooltipResultWidget::kLineHeight = 1;
27
const int TooltipResultWidget::kIconSize = 16;
29
TooltipResultWidget::TooltipResultWidget(const SearchProvider::Result& result,
31
: QAbstractButton(parent),
33
kTextHeight(fontMetrics().height()),
34
kTrackNoWidth(fontMetrics().width("0000")),
35
bold_metrics_(fontMetrics())
38
bold_font_.setBold(true);
39
bold_metrics_ = QFontMetrics(bold_font_);
41
size_hint_ = CalculateSizeHint();
44
setAutoExclusive(true);
47
QSize TooltipResultWidget::sizeHint() const {
51
QSize TooltipResultWidget::CalculateSizeHint() const {
56
h += kSpacing + kIconSize + kSpacing + kLineHeight;
57
w = qMax(w, kBorder + kTrackNoWidth + kTrackNumSpacing +
58
bold_metrics_.width(TitleText()) + kBorder);
60
switch (result_.type_) {
61
case globalsearch::Type_Track:
62
case globalsearch::Type_Stream:
65
case globalsearch::Type_Album:
66
if (result_.album_songs_.isEmpty())
70
h += kSpacing + kSpacing * (result_.album_songs_.count() - 1) +
71
kTextHeight * result_.album_songs_.count();
72
foreach (const Song& song, result_.album_songs_) {
73
w = qMax(w, kBorder + kTrackNoWidth + kTrackNumSpacing +
74
fontMetrics().width(song.TitleWithCompilationArtist()) +
78
h += kSpacing + kLineHeight;
86
QString TooltipResultWidget::TitleText() const {
87
return result_.provider_->name();
90
void TooltipResultWidget::paintEvent(QPaintEvent*) {
93
const QColor text_color = palette().color(QPalette::BrightText);
95
const qreal line_opacity = 0.1 + (isChecked() ? 0.2 : 0.0);
96
const qreal track_opacity = 0.1 + (isChecked() ? 0.5 : 0.0);
97
const qreal text_opacity = 0.4 + (isChecked() ? 0.5 : 0.0);
102
QRect text_rect(kBorder + kTrackNoWidth + kTrackNumSpacing, y,
103
width() - kBorder*2 - kTrackNoWidth - kTrackNumSpacing, kIconSize);
104
p.setFont(bold_font_);
105
p.setPen(text_color);
106
p.setOpacity(text_opacity);
107
p.drawText(text_rect, Qt::AlignVCenter, TitleText());
110
QRect icon_rect(text_rect.left() - kTrackNumSpacing - kIconSize, y,
111
kIconSize, kIconSize);
112
p.drawPixmap(icon_rect, result_.provider_->icon().pixmap(kIconSize));
115
y += kIconSize + kSpacing;
116
p.setOpacity(line_opacity);
117
p.setPen(text_color);
118
p.drawLine(0, y, width(), y);
121
switch (result_.type_) {
122
case globalsearch::Type_Track:
123
case globalsearch::Type_Stream:
126
case globalsearch::Type_Album:
127
if (result_.album_songs_.isEmpty())
135
foreach (const Song& song, result_.album_songs_) {
136
QRect number_rect(kBorder, y, kTrackNoWidth, kTextHeight);
137
if (song.track() > 0) {
139
p.setOpacity(track_opacity);
140
p.drawText(number_rect, Qt::AlignRight | Qt::AlignHCenter,
141
QString::number(song.track()));
145
QRect title_rect(number_rect.right() + kTrackNumSpacing, y,
146
width() - number_rect.right() - kTrackNumSpacing - kBorder,
148
p.setOpacity(text_opacity);
149
p.drawText(title_rect, song.TitleWithCompilationArtist());
151
y += kTextHeight + kSpacing;
155
p.setOpacity(line_opacity);
156
p.drawLine(0, y, width(), y);