mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-12 17:36:05 +01:00
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),
|
||||
m_animCount(0),
|
||||
m_animTimer(new QTimer(this)),
|
||||
m_pixmapInset(QPixmap(volumePixmapDraw ())) {
|
||||
m_pixmapInset(QPixmap(drawVolumePixmap ())) {
|
||||
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_highlight_color = palette().color(QPalette::Highlight);
|
||||
|
||||
// BEGIN Calculate handle animation pixmaps for mouse-over effect
|
||||
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
|
||||
|
||||
drawVolumeSliderHandle();
|
||||
generateGradient();
|
||||
|
||||
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 (m_previous_theme_text_color != palette().color(QPalette::WindowText)) {
|
||||
m_pixmapInset = volumePixmapDraw();
|
||||
m_pixmapInset = drawVolumePixmap();
|
||||
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_pixmapInset);
|
||||
p.drawPixmap(offset - m_handlePixmaps[0].width() / 2 + padding, 0,
|
||||
@ -345,7 +332,7 @@ void Amarok::VolumeSlider::paletteChange(const QPalette&) {
|
||||
generateGradient();
|
||||
}
|
||||
|
||||
QPixmap Amarok::VolumeSlider::volumePixmapDraw () const {
|
||||
QPixmap Amarok::VolumeSlider::drawVolumePixmap () const {
|
||||
QPixmap pixmap(112, 36);
|
||||
pixmap.fill(Qt::transparent);
|
||||
QPainter painter(&pixmap);
|
||||
@ -366,3 +353,41 @@ QPixmap Amarok::VolumeSlider::volumePixmapDraw () const {
|
||||
// Return QPixmap
|
||||
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:
|
||||
VolumeSlider(QWidget* parent, uint max = 0);
|
||||
QPixmap volumePixmapDraw() const;
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent*);
|
||||
@ -115,6 +114,8 @@ class VolumeSlider : public Slider {
|
||||
|
||||
private:
|
||||
void generateGradient();
|
||||
QPixmap drawVolumePixmap() const;
|
||||
void drawVolumeSliderHandle();
|
||||
|
||||
VolumeSlider(const VolumeSlider&); // undefined
|
||||
VolumeSlider& operator=(const VolumeSlider&); // undefined
|
||||
@ -131,6 +132,7 @@ class VolumeSlider : public Slider {
|
||||
QPixmap m_pixmapGradient;
|
||||
|
||||
QColor m_previous_theme_text_color;
|
||||
QColor m_previous_theme_highlight_color;
|
||||
|
||||
QList<QPixmap> m_handlePixmaps;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user