Status display WIP.
[wallplayer.git] / src / minislider.cpp
blobd0cbbe23e6a60a638b0aa7ca51bf58346f25f67a
1 #include <QMouseEvent>
2 #include <QPainter>
3 #include <QSizePolicy>
5 #include "minislider.h"
7 MiniSlider::MiniSlider (QWidget* parent)
8 : QWidget(parent), m_value(0), m_maxValue(1)
10 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred));
13 void MiniSlider::paintEvent(QPaintEvent* event)
15 QWidget::paintEvent(event);
17 QPainter painter(this);
19 int sliderPos = width()*((float)m_value/m_maxValue);
21 /* background */
22 painter.setPen(Qt::NoPen);
23 painter.setBrush(Qt::black);
24 painter.drawRect(0,0,width(),height());
26 /* bar */
27 painter.setPen(Qt::NoPen);
28 painter.setBrush(Qt::darkGray);
29 painter.drawRect(0,0,sliderPos,height());
31 /* border */
33 QPen borderPen;
34 borderPen.setWidth(2);
35 painter.setPen(borderPen);
36 painter.setBrush(Qt::NoBrush);
37 painter.drawRect(1,1,width()-1,height()-1);
41 QSize MiniSlider::minimumSizeHint() const
43 return QSize(20, 5);
46 void MiniSlider::mousePressEvent(QMouseEvent *event)
48 if (event->button() == Qt::LeftButton)
49 emit valueChanged(((float)event->x()/width())*m_maxValue);
52 void MiniSlider::mouseMoveEvent(QMouseEvent *event)
54 emit valueChanged(((float)event->x()/width())*m_maxValue);
57 void MiniSlider::setValue (double value)
59 setValue((int)value);
62 void MiniSlider::setValue (int value)
64 Q_ASSERT(value>=0);
65 Q_ASSERT(value<=m_maxValue);
67 m_value = value;
68 update();
72 void VolumeSlider::mousePressEvent(QMouseEvent *event)
74 if (event->button() == Qt::LeftButton)
75 setValue(((float)event->x()/width())*m_maxValue);
77 MiniSlider::mousePressEvent(event);
80 void VolumeSlider::mouseMoveEvent(QMouseEvent *event)
82 setValue(((float)event->x()/width())*m_maxValue);
83 MiniSlider::mouseMoveEvent(event);