Improve the appearance of the artist info view, make individual sections collapsable.
This commit is contained in:
parent
a85c292118
commit
f017587099
@ -1,5 +1,5 @@
|
||||
QScrollArea {
|
||||
background: palette(base);
|
||||
background: qpalette(base);
|
||||
}
|
||||
|
||||
QTextEdit {
|
||||
|
@ -131,6 +131,7 @@ set(SOURCES
|
||||
songinfo/artistinfofetcher.cpp
|
||||
songinfo/artistinfoprovider.cpp
|
||||
songinfo/artistinfoview.cpp
|
||||
songinfo/collapsibleinfoheader.cpp
|
||||
songinfo/collapsibleinfopane.cpp
|
||||
songinfo/echonestartistinfo.cpp
|
||||
songinfo/htmlscraper.cpp
|
||||
@ -267,6 +268,7 @@ set(HEADERS
|
||||
songinfo/artistinfofetcher.h
|
||||
songinfo/artistinfoprovider.h
|
||||
songinfo/artistinfoview.h
|
||||
songinfo/collapsibleinfoheader.h
|
||||
songinfo/collapsibleinfopane.h
|
||||
songinfo/echonestartistinfo.h
|
||||
songinfo/htmlscraper.h
|
||||
|
@ -43,7 +43,9 @@ ArtistInfoView::ArtistInfoView(QWidget *parent)
|
||||
QWidget* container_widget = new QWidget;
|
||||
container_widget->setLayout(container_);
|
||||
container_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
|
||||
container_widget->setBackgroundRole(QPalette::Base);
|
||||
container_->setSizeConstraint(QLayout::SetMinAndMaxSize);
|
||||
container_->setContentsMargins(0, 0, 0, 0);
|
||||
scroll_area_->setWidget(container_widget);
|
||||
scroll_area_->setWidgetResizable(true);
|
||||
|
||||
|
110
src/songinfo/collapsibleinfoheader.cpp
Normal file
110
src/songinfo/collapsibleinfoheader.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
/* This file is part of Clementine.
|
||||
|
||||
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 "collapsibleinfoheader.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QStyleOption>
|
||||
|
||||
const int CollapsibleInfoHeader::kHeight = 20;
|
||||
|
||||
CollapsibleInfoHeader::CollapsibleInfoHeader(QWidget* parent)
|
||||
: QWidget(parent),
|
||||
expanded_(true),
|
||||
hovering_(false)
|
||||
{
|
||||
setMinimumHeight(kHeight);
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
setCursor(QCursor(Qt::PointingHandCursor));
|
||||
}
|
||||
|
||||
void CollapsibleInfoHeader::SetTitle(const QString& title) {
|
||||
title_ = title;
|
||||
update();
|
||||
}
|
||||
|
||||
void CollapsibleInfoHeader::SetExpanded(bool expanded) {
|
||||
expanded_ = expanded;
|
||||
|
||||
emit ExpandedToggled(expanded);
|
||||
if (expanded)
|
||||
emit Expanded();
|
||||
else
|
||||
emit Collapsed();
|
||||
}
|
||||
|
||||
void CollapsibleInfoHeader::enterEvent(QEvent*) {
|
||||
hovering_ = true;
|
||||
update();
|
||||
}
|
||||
|
||||
void CollapsibleInfoHeader::leaveEvent(QEvent*) {
|
||||
hovering_ = false;
|
||||
update();
|
||||
}
|
||||
|
||||
void CollapsibleInfoHeader::paintEvent(QPaintEvent* e) {
|
||||
QPainter p(this);
|
||||
|
||||
QRect indicator_rect(0, 0, height(), height());
|
||||
QRect text_rect(rect());
|
||||
text_rect.setLeft(height() + 6);
|
||||
|
||||
// Draw the background
|
||||
const QColor bg_color_1(palette().color(QPalette::Highlight).lighter(120));
|
||||
const QColor bg_color_2(palette().color(QPalette::Highlight).darker(120));
|
||||
const QColor bg_border(palette().color(QPalette::Dark));
|
||||
QLinearGradient bg_brush(rect().topLeft(), rect().bottomLeft());
|
||||
bg_brush.setColorAt(0.0, bg_color_1);
|
||||
bg_brush.setColorAt(0.5, bg_color_1);
|
||||
bg_brush.setColorAt(0.5, bg_color_2);
|
||||
bg_brush.setColorAt(1.0, bg_color_2);
|
||||
|
||||
p.setPen(Qt::NoPen);
|
||||
p.fillRect(rect(), bg_brush);
|
||||
|
||||
p.setPen(bg_border);
|
||||
p.drawLine(rect().topLeft(), rect().topRight());
|
||||
p.drawLine(rect().bottomLeft(), rect().bottomRight());
|
||||
|
||||
// Draw the expand/collapse indicator
|
||||
QStyleOption opt;
|
||||
opt.initFrom(this);
|
||||
opt.rect = indicator_rect;
|
||||
opt.state |= QStyle::State_Children;
|
||||
if (expanded_)
|
||||
opt.state |= QStyle::State_Open;
|
||||
if (hovering_)
|
||||
opt.state |= QStyle::State_Active;
|
||||
|
||||
// Have to use the application's style here because using the widget's style
|
||||
// will trigger QStyleSheetStyle's recursion guard (I don't know why).
|
||||
QApplication::style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, &p, this);
|
||||
|
||||
// Draw the title text
|
||||
QFont bold_font(font());
|
||||
bold_font.setBold(true);
|
||||
p.setFont(bold_font);
|
||||
|
||||
p.setPen(palette().color(QPalette::HighlightedText));
|
||||
p.drawText(text_rect, Qt::AlignLeft | Qt::AlignVCenter, title_);
|
||||
}
|
||||
|
||||
void CollapsibleInfoHeader::mouseReleaseEvent(QMouseEvent* e) {
|
||||
SetExpanded(!expanded_);
|
||||
}
|
55
src/songinfo/collapsibleinfoheader.h
Normal file
55
src/songinfo/collapsibleinfoheader.h
Normal file
@ -0,0 +1,55 @@
|
||||
/* This file is part of Clementine.
|
||||
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef COLLAPSIBLEINFOHEADER_H
|
||||
#define COLLAPSIBLEINFOHEADER_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class CollapsibleInfoHeader : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CollapsibleInfoHeader(QWidget* parent = 0);
|
||||
|
||||
static const int kHeight;
|
||||
|
||||
bool expanded() const { return expanded_; }
|
||||
bool hovering() const { return hovering_; }
|
||||
const QString& title() const { return title_; }
|
||||
|
||||
public slots:
|
||||
void SetExpanded(bool expanded);
|
||||
void SetTitle(const QString& title);
|
||||
|
||||
signals:
|
||||
void Expanded();
|
||||
void Collapsed();
|
||||
void ExpandedToggled(bool expanded);
|
||||
|
||||
protected:
|
||||
void enterEvent(QEvent*);
|
||||
void leaveEvent(QEvent*);
|
||||
void paintEvent(QPaintEvent* e);
|
||||
void mouseReleaseEvent(QMouseEvent*);
|
||||
|
||||
private:
|
||||
bool expanded_;
|
||||
bool hovering_;
|
||||
QString title_;
|
||||
};
|
||||
|
||||
#endif // COLLAPSIBLEINFOHEADER_H
|
@ -14,31 +14,31 @@
|
||||
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "collapsibleinfoheader.h"
|
||||
#include "collapsibleinfopane.h"
|
||||
|
||||
#include <QStylePainter>
|
||||
#include <QStyleOption>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
const int CollapsibleInfoPane::kTitleHeight = 20;
|
||||
|
||||
CollapsibleInfoPane::CollapsibleInfoPane(QWidget* parent)
|
||||
: QWidget(parent),
|
||||
widget_(NULL),
|
||||
expanded_(true)
|
||||
header_(new CollapsibleInfoHeader(this)),
|
||||
widget_(NULL)
|
||||
{
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(0, kTitleHeight, 0, 0);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(3);
|
||||
layout->setSizeConstraint(QLayout::SetMinAndMaxSize);
|
||||
setLayout(layout);
|
||||
|
||||
layout->addWidget(header_);
|
||||
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
|
||||
setMinimumHeight(kTitleHeight);
|
||||
|
||||
connect(header_, SIGNAL(ExpandedToggled(bool)), SLOT(ExpandedToggled(bool)));
|
||||
}
|
||||
|
||||
void CollapsibleInfoPane::SetTitle(const QString& title) {
|
||||
title_ = title;
|
||||
update();
|
||||
header_->SetTitle(title);
|
||||
}
|
||||
|
||||
void CollapsibleInfoPane::SetWidget(QWidget* widget) {
|
||||
@ -50,50 +50,13 @@ void CollapsibleInfoPane::SetWidget(QWidget* widget) {
|
||||
}
|
||||
|
||||
void CollapsibleInfoPane::Collapse() {
|
||||
expanded_ = false;
|
||||
update();
|
||||
header_->SetExpanded(false);
|
||||
}
|
||||
|
||||
void CollapsibleInfoPane::Expand() {
|
||||
expanded_ = true;
|
||||
update();
|
||||
header_->SetExpanded(true);
|
||||
}
|
||||
|
||||
void CollapsibleInfoPane::paintEvent(QPaintEvent* e) {
|
||||
QStylePainter p(this);
|
||||
|
||||
QRect title_rect(0, 0, width(), kTitleHeight);
|
||||
QRect indicator_rect(0, 0, kTitleHeight, kTitleHeight);
|
||||
QRect text_rect(title_rect);
|
||||
text_rect.setLeft(kTitleHeight + 6);
|
||||
|
||||
// Draw the background
|
||||
const QColor bg_color_1(palette().color(QPalette::Highlight));
|
||||
const QColor bg_color_2(palette().color(QPalette::Highlight).lighter(125));
|
||||
const QColor bg_border(palette().color(QPalette::Dark));
|
||||
QLinearGradient bg_brush(title_rect.topLeft(), title_rect.bottomLeft());
|
||||
bg_brush.setColorAt(0.0, bg_color_1);
|
||||
bg_brush.setColorAt(0.5, bg_color_2);
|
||||
bg_brush.setColorAt(1.0, bg_color_1);
|
||||
|
||||
p.setPen(bg_border);
|
||||
p.drawLine(title_rect.topLeft(), title_rect.topRight());
|
||||
p.drawLine(title_rect.bottomLeft(), title_rect.bottomRight());
|
||||
|
||||
p.setPen(Qt::NoPen);
|
||||
p.fillRect(title_rect, bg_brush);
|
||||
|
||||
// Draw the expand/collapse indicator
|
||||
QStyleOption opt;
|
||||
opt.initFrom(this);
|
||||
opt.rect = indicator_rect;
|
||||
opt.state |= QStyle::State_Children;
|
||||
if (expanded_)
|
||||
opt.state |= QStyle::State_Open;
|
||||
|
||||
p.drawPrimitive(QStyle::PE_IndicatorBranch, opt);
|
||||
|
||||
// Draw the title text
|
||||
p.setPen(palette().color(QPalette::HighlightedText));
|
||||
p.drawText(text_rect, Qt::AlignLeft | Qt::AlignVCenter, title_);
|
||||
void CollapsibleInfoPane::ExpandedToggled(bool expanded) {
|
||||
widget_->setVisible(expanded);
|
||||
}
|
||||
|
@ -19,14 +19,14 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class CollapsibleInfoHeader;
|
||||
|
||||
class CollapsibleInfoPane : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CollapsibleInfoPane(QWidget* parent = 0);
|
||||
|
||||
static const int kTitleHeight;
|
||||
|
||||
void SetTitle(const QString& title);
|
||||
void SetWidget(QWidget* widget);
|
||||
|
||||
@ -34,13 +34,12 @@ public slots:
|
||||
void Expand();
|
||||
void Collapse();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* e);
|
||||
private slots:
|
||||
void ExpandedToggled(bool expanded);
|
||||
|
||||
private:
|
||||
QString title_;
|
||||
CollapsibleInfoHeader* header_;
|
||||
QWidget* widget_;
|
||||
bool expanded_;
|
||||
};
|
||||
|
||||
#endif // COLLAPSIBLEINFOPANE_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user