***************************************************************************/
-#include <QMouseEvent>
-#include <QStylePainter>
+#include "smallruler.h"
#include <KDebug>
-#include "smallruler.h"
-
+#include <QMouseEvent>
+#include <QStylePainter>
-SmallRuler::SmallRuler(QWidget *parent)
- : QWidget(parent), m_scale(1), m_maxval(25) {
+SmallRuler::SmallRuler(QWidget *parent) :
+ QWidget(parent),
+ m_scale(1),
+ m_maxval(25)
+{
m_zoneStart = 10;
m_zoneEnd = 60;
+ m_zoneColor = QColor(133, 255, 143);
}
-void SmallRuler::adjustScale(int maximum) {
+void SmallRuler::adjustScale(int maximum)
+{
m_maxval = maximum;
m_scale = (double) width() / (double) maximum;
if (m_scale == 0) m_scale = 1;
update();
}
-void SmallRuler::setZone(int start, int end) {
+void SmallRuler::setZone(int start, int end)
+{
if (start != -1) {
if (end != -1 && start >= end) {
m_zoneEnd = qMin(m_maxval, end + (start - m_zoneStart));
update();
}
-QPoint SmallRuler::zone() {
+QPoint SmallRuler::zone()
+{
return QPoint(m_zoneStart, m_zoneEnd);
}
// virtual
-void SmallRuler::mousePressEvent(QMouseEvent * event) {
+void SmallRuler::mousePressEvent(QMouseEvent * event)
+{
const int pos = event->x() / m_scale;
- emit seekRenderer((int) pos);
+ if (event->button() == Qt::RightButton) {
+ // Right button clicked, move selection zone
+ if (qAbs(pos - m_zoneStart) < qAbs(pos - m_zoneEnd)) m_zoneStart = pos;
+ else m_zoneEnd = pos;
+ emit zoneChanged(QPoint(m_zoneStart, m_zoneEnd));
+ update();
+
+ } else emit seekRenderer((int) pos);
}
// virtual
-void SmallRuler::mouseMoveEvent(QMouseEvent * event) {
+void SmallRuler::mouseMoveEvent(QMouseEvent * event)
+{
const int pos = event->x() / m_scale;
- emit seekRenderer((int) pos);
+ if (event->buttons() & Qt::LeftButton) emit seekRenderer((int) pos);
}
-void SmallRuler::slotNewValue(int value) {
+void SmallRuler::slotNewValue(int value)
+{
m_cursorFramePosition = value;
int oldPos = m_cursorPosition;
m_cursorPosition = value * m_scale;
}
//virtual
-void SmallRuler::resizeEvent(QResizeEvent *) {
+void SmallRuler::resizeEvent(QResizeEvent *)
+{
adjustScale(m_maxval);
}
// virtual
-void SmallRuler::paintEvent(QPaintEvent *e) {
+void SmallRuler::paintEvent(QPaintEvent *e)
+{
QPainter p(this);
QRect r = e->rect();
const int zoneStart = (int)(m_zoneStart * m_scale);
const int zoneEnd = (int)(m_zoneEnd * m_scale);
- p.fillRect(QRect(zoneStart, height() / 2, zoneEnd - zoneStart, height() / 2), QBrush(QColor(133, 255, 143)));
+ p.fillRect(zoneStart, height() / 2, zoneEnd - zoneStart, height() / 2, m_zoneColor);
if (r.top() < 9) {
// draw the little marks