Merge pull request #5042 from narunlifescience/master
volume slider handle glow effect using system theme
This commit is contained in:
commit
c6e56813ef
@ -195,32 +195,14 @@ Amarok::VolumeSlider::VolumeSlider(QWidget* parent, uint max)
|
|||||||
: Amarok::Slider(Qt::Horizontal, parent, max),
|
: Amarok::Slider(Qt::Horizontal, parent, max),
|
||||||
m_animCount(0),
|
m_animCount(0),
|
||||||
m_animTimer(new QTimer(this)),
|
m_animTimer(new QTimer(this)),
|
||||||
m_pixmapInset(QPixmap(volumePixmapDraw ())) {
|
m_pixmapInset(QPixmap(drawVolumePixmap ())) {
|
||||||
setFocusPolicy(Qt::NoFocus);
|
setFocusPolicy(Qt::NoFocus);
|
||||||
|
|
||||||
// Store window text color to check theme change at paintEvent
|
// Store theme colors to check theme change at paintEvent
|
||||||
m_previous_theme_text_color = palette().color(QPalette::WindowText);
|
m_previous_theme_text_color = palette().color(QPalette::WindowText);
|
||||||
|
m_previous_theme_highlight_color = palette().color(QPalette::Highlight);
|
||||||
|
|
||||||
// BEGIN Calculate handle animation pixmaps for mouse-over effect
|
drawVolumeSliderHandle();
|
||||||
QImage pixmapHandle(":volumeslider-handle.png");
|
|
||||||
QImage pixmapHandleGlow(":volumeslider-handle_glow.png");
|
|
||||||
|
|
||||||
float opacity = 0.0;
|
|
||||||
const float step = 1.0 / ANIM_MAX;
|
|
||||||
QImage dst;
|
|
||||||
for (int i = 0; i < ANIM_MAX; ++i) {
|
|
||||||
dst = pixmapHandle.copy();
|
|
||||||
|
|
||||||
QPainter p(&dst);
|
|
||||||
p.setOpacity(opacity);
|
|
||||||
p.drawImage(0, 0, pixmapHandleGlow);
|
|
||||||
p.end();
|
|
||||||
|
|
||||||
m_handlePixmaps.append(QPixmap::fromImage(dst));
|
|
||||||
opacity += step;
|
|
||||||
}
|
|
||||||
// END
|
|
||||||
|
|
||||||
generateGradient();
|
generateGradient();
|
||||||
|
|
||||||
setMinimumWidth(m_pixmapInset.width());
|
setMinimumWidth(m_pixmapInset.width());
|
||||||
@ -306,10 +288,15 @@ void Amarok::VolumeSlider::paintEvent(QPaintEvent*) {
|
|||||||
|
|
||||||
// If theme changed since last paintEvent, redraw the volume pixmap with new theme colors
|
// If theme changed since last paintEvent, redraw the volume pixmap with new theme colors
|
||||||
if (m_previous_theme_text_color != palette().color(QPalette::WindowText)) {
|
if (m_previous_theme_text_color != palette().color(QPalette::WindowText)) {
|
||||||
m_pixmapInset = volumePixmapDraw();
|
m_pixmapInset = drawVolumePixmap();
|
||||||
m_previous_theme_text_color = palette().color(QPalette::WindowText);
|
m_previous_theme_text_color = palette().color(QPalette::WindowText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_previous_theme_highlight_color != palette().color(QPalette::Highlight)) {
|
||||||
|
drawVolumeSliderHandle();
|
||||||
|
m_previous_theme_highlight_color = palette().color(QPalette::Highlight);
|
||||||
|
}
|
||||||
|
|
||||||
p.drawPixmap(0, 0, m_pixmapGradient, 0, 0, offset + padding, 0);
|
p.drawPixmap(0, 0, m_pixmapGradient, 0, 0, offset + padding, 0);
|
||||||
p.drawPixmap(0, 0, m_pixmapInset);
|
p.drawPixmap(0, 0, m_pixmapInset);
|
||||||
p.drawPixmap(offset - m_handlePixmaps[0].width() / 2 + padding, 0,
|
p.drawPixmap(offset - m_handlePixmaps[0].width() / 2 + padding, 0,
|
||||||
@ -345,7 +332,7 @@ void Amarok::VolumeSlider::paletteChange(const QPalette&) {
|
|||||||
generateGradient();
|
generateGradient();
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap Amarok::VolumeSlider::volumePixmapDraw () const {
|
QPixmap Amarok::VolumeSlider::drawVolumePixmap () const {
|
||||||
QPixmap pixmap(112, 36);
|
QPixmap pixmap(112, 36);
|
||||||
pixmap.fill(Qt::transparent);
|
pixmap.fill(Qt::transparent);
|
||||||
QPainter painter(&pixmap);
|
QPainter painter(&pixmap);
|
||||||
@ -366,3 +353,41 @@ QPixmap Amarok::VolumeSlider::volumePixmapDraw () const {
|
|||||||
// Return QPixmap
|
// Return QPixmap
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Amarok::VolumeSlider::drawVolumeSliderHandle() {
|
||||||
|
QImage pixmapHandle(":volumeslider-handle.png");
|
||||||
|
QImage pixmapHandleGlow(":/volumeslider-handle_glow.png");
|
||||||
|
|
||||||
|
QImage pixmapHandleGlow_image(pixmapHandleGlow.size(), QImage::Format_ARGB32_Premultiplied);
|
||||||
|
QPainter painter(&pixmapHandleGlow_image);
|
||||||
|
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||||
|
|
||||||
|
// repaint volume slider handle glow image with theme highlight color
|
||||||
|
painter.fillRect(pixmapHandleGlow_image.rect(), QBrush(palette().color(QPalette::Highlight)));
|
||||||
|
painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||||
|
painter.drawImage(0, 0, pixmapHandleGlow);
|
||||||
|
|
||||||
|
// Overlay the volume slider handle image
|
||||||
|
painter.setCompositionMode(QPainter::CompositionMode_SourceAtop);
|
||||||
|
painter.drawImage(0, 0, pixmapHandle);
|
||||||
|
|
||||||
|
// BEGIN Calculate handle animation pixmaps for mouse-over effect
|
||||||
|
float opacity = 0.0;
|
||||||
|
const float step = 1.0 / ANIM_MAX;
|
||||||
|
QImage dst;
|
||||||
|
m_handlePixmaps.clear();
|
||||||
|
for (int i = 0; i < ANIM_MAX; ++i) {
|
||||||
|
dst = pixmapHandle.copy();
|
||||||
|
|
||||||
|
QPainter p(&dst);
|
||||||
|
p.setOpacity(opacity);
|
||||||
|
p.drawImage(0, 0, pixmapHandleGlow_image);
|
||||||
|
p.end();
|
||||||
|
|
||||||
|
m_handlePixmaps.append(QPixmap::fromImage(dst));
|
||||||
|
opacity += step;
|
||||||
|
}
|
||||||
|
// END
|
||||||
|
}
|
||||||
|
@ -98,7 +98,6 @@ class VolumeSlider : public Slider {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
VolumeSlider(QWidget* parent, uint max = 0);
|
VolumeSlider(QWidget* parent, uint max = 0);
|
||||||
QPixmap volumePixmapDraw() const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void paintEvent(QPaintEvent*);
|
virtual void paintEvent(QPaintEvent*);
|
||||||
@ -115,6 +114,8 @@ class VolumeSlider : public Slider {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void generateGradient();
|
void generateGradient();
|
||||||
|
QPixmap drawVolumePixmap() const;
|
||||||
|
void drawVolumeSliderHandle();
|
||||||
|
|
||||||
VolumeSlider(const VolumeSlider&); // undefined
|
VolumeSlider(const VolumeSlider&); // undefined
|
||||||
VolumeSlider& operator=(const VolumeSlider&); // undefined
|
VolumeSlider& operator=(const VolumeSlider&); // undefined
|
||||||
@ -131,6 +132,7 @@ class VolumeSlider : public Slider {
|
|||||||
QPixmap m_pixmapGradient;
|
QPixmap m_pixmapGradient;
|
||||||
|
|
||||||
QColor m_previous_theme_text_color;
|
QColor m_previous_theme_text_color;
|
||||||
|
QColor m_previous_theme_highlight_color;
|
||||||
|
|
||||||
QList<QPixmap> m_handlePixmaps;
|
QList<QPixmap> m_handlePixmaps;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user