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
);
22 painter
.setPen(Qt::NoPen
);
23 painter
.setBrush(Qt::black
);
24 painter
.drawRect(0,0,width(),height());
27 painter
.setPen(Qt::NoPen
);
28 painter
.setBrush(Qt::darkGray
);
29 painter
.drawRect(0,0,sliderPos
,height());
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
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
)
62 void MiniSlider::setValue (int value
)
65 Q_ASSERT(value
<=m_maxValue
);
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
);