Skip to content

Commit

Permalink
Merge pull request #5035 from narunlifescience/master
Browse files Browse the repository at this point in the history
Volume pixmap render on the fly using system theme
  • Loading branch information
hatstand committed Sep 16, 2015
2 parents 74781cb + 785a7ee commit 8757cb3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
1 change: 0 additions & 1 deletion data/data.qrc
Expand Up @@ -408,7 +408,6 @@
<file>volumeslider-gradient.png</file>
<file>volumeslider-handle_glow.png</file>
<file>volumeslider-handle.png</file>
<file>volumeslider-inset.png</file>
<file>vk/add.png</file>
<file>vk/bookmarks.png</file>
<file>vk/delete.png</file>
Expand Down
Binary file modified data/volumeslider-gradient.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed data/volumeslider-inset.png
Binary file not shown.
33 changes: 32 additions & 1 deletion src/widgets/sliderwidget.cpp
Expand Up @@ -195,9 +195,12 @@ Amarok::VolumeSlider::VolumeSlider(QWidget* parent, uint max)
: Amarok::Slider(Qt::Horizontal, parent, max),
m_animCount(0),
m_animTimer(new QTimer(this)),
m_pixmapInset(QPixmap(":volumeslider-inset.png")) {
m_pixmapInset(QPixmap(volumePixmapDraw ())) {
setFocusPolicy(Qt::NoFocus);

// Store window text color to check theme change at paintEvent
m_previous_theme_text_color = palette().color(QPalette::WindowText);

// BEGIN Calculate handle animation pixmaps for mouse-over effect
QImage pixmapHandle(":volumeslider-handle.png");
QImage pixmapHandleGlow(":volumeslider-handle_glow.png");
Expand Down Expand Up @@ -301,6 +304,12 @@ void Amarok::VolumeSlider::paintEvent(QPaintEvent*) {
const int padding = 7;
const int offset = int(double((width() - 2 * padding) * value()) / maximum());

// If theme changed since last paintEvent, redraw the volume pixmap with new theme colors
if (m_previous_theme_text_color != palette().color(QPalette::WindowText)) {
m_pixmapInset = volumePixmapDraw();
m_previous_theme_text_color = palette().color(QPalette::WindowText);
}

p.drawPixmap(0, 0, m_pixmapGradient, 0, 0, offset + padding, 0);
p.drawPixmap(0, 0, m_pixmapInset);
p.drawPixmap(offset - m_handlePixmaps[0].width() / 2 + padding, 0,
Expand Down Expand Up @@ -335,3 +344,25 @@ void Amarok::VolumeSlider::leaveEvent(QEvent*) {
void Amarok::VolumeSlider::paletteChange(const QPalette&) {
generateGradient();
}

QPixmap Amarok::VolumeSlider::volumePixmapDraw () const {
QPixmap pixmap(112, 36);
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
QPen pen(palette().color(QPalette::WindowText), 0.3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
painter.setPen(pen);

painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
// Draw volume control pixmap
QPolygon poly;
poly << QPoint(6, 21) << QPoint(104, 21)
<< QPoint(104, 7) << QPoint(6, 16)
<< QPoint(6, 21);
QPainterPath path;
path.addPolygon(poly);
painter.drawPolygon(poly);
painter.drawLine(6, 29, 104, 29);
// Return QPixmap
return pixmap;
}
3 changes: 3 additions & 0 deletions src/widgets/sliderwidget.h
Expand Up @@ -98,6 +98,7 @@ class VolumeSlider : public Slider {

public:
VolumeSlider(QWidget* parent, uint max = 0);
QPixmap volumePixmapDraw() const;

protected:
virtual void paintEvent(QPaintEvent*);
Expand Down Expand Up @@ -129,6 +130,8 @@ class VolumeSlider : public Slider {
QPixmap m_pixmapInset;
QPixmap m_pixmapGradient;

QColor m_previous_theme_text_color;

QList<QPixmap> m_handlePixmaps;
};
}
Expand Down

0 comments on commit 8757cb3

Please sign in to comment.