};
CustomRuler::CustomRuler(Timecode tc, CustomTrackView *parent)
- : KRuler(parent), m_timecode(tc), m_view(parent) {
+ : KRuler(parent), m_timecode(tc), m_view(parent), m_duration(0) {
slotNewOffset(0);
setRulerMetricStyle(KRuler::Pixel);
setLength(1024);
setLittleMarkDistance(FRAME_SIZE);
setMediumMarkDistance(FRAME_SIZE * 25);
setBigMarkDistance(FRAME_SIZE * 25 * 60);
+ m_zoneStart = 50;
+ m_zoneEnd = 250;
}
// virtual
void CustomRuler::mousePressEvent(QMouseEvent * event) {
- int pos = (event->x() + offset());
- m_view->setCursorPos(pos);
+ m_view->activateMonitor();
+ int pos = (event->x() + offset()) / pixelPerMark() / FRAME_SIZE;
+ m_moveCursor = RULER_CURSOR;
+ if (event->y() > 10) {
+ if (abs(pos - m_zoneStart) < 4) m_moveCursor = RULER_START;
+ else if (abs(pos - (m_zoneStart + (m_zoneEnd - m_zoneStart) / 2)) < 4) m_moveCursor = RULER_MIDDLE;
+ else if (abs(pos - m_zoneEnd) < 4) m_moveCursor = RULER_END;
+ }
+ if (m_moveCursor == RULER_CURSOR)
+ m_view->setCursorPos(pos);
}
// virtual
void CustomRuler::mouseMoveEvent(QMouseEvent * event) {
- int pos = (event->x() + offset());
- m_view->setCursorPos(pos);
+ int pos = (event->x() + offset()) / pixelPerMark() / FRAME_SIZE;
+ if (m_moveCursor == RULER_CURSOR) {
+ m_view->setCursorPos(pos);
+ return;
+ } else if (m_moveCursor == RULER_START) m_zoneStart = pos;
+ else if (m_moveCursor == RULER_END) m_zoneEnd = pos;
+ else if (m_moveCursor == RULER_MIDDLE) {
+ int move = pos - (m_zoneStart + (m_zoneEnd - m_zoneStart) / 2);
+ m_zoneStart += move;
+ m_zoneEnd += move;
+ }
+ update();
+}
+
+int CustomRuler::inPoint() const {
+ return m_zoneStart;
+}
+
+int CustomRuler::outPoint() const {
+ return m_zoneEnd;
}
void CustomRuler::slotMoveRuler(int newPos) {
- int diff = offset() - newPos;
KRuler::slotNewOffset(newPos);
}
KRuler::setPixelPerMark(1.0 / scale);
}
+void CustomRuler::setDuration(int d) {
+ m_duration = d;
+ update();
+}
+
// virtual
-void CustomRuler::paintEvent(QPaintEvent * /*e*/) {
+void CustomRuler::paintEvent(QPaintEvent *e) {
// debug ("KRuler::drawContents, %s",(horizontal==dir)?"horizontal":"vertical");
QStylePainter p(this);
+ p.setClipRect(e->rect());
+
+ //p.fillRect(e->rect(), QBrush(QColor(200, 200, 200)));
+ //kDebug()<<"RULER ZONE: "<<m_zoneStart<<", OFF: "<<offset()<<", END: "<<m_zoneEnd<<", FACTOR: "<<pixelPerMark() * FRAME_SIZE;
+ int projectEnd = m_duration * pixelPerMark() * FRAME_SIZE;
+ p.fillRect(QRect(- offset(), e->rect().y(), projectEnd, e->rect().height()), QBrush(QColor(245, 245, 245)));
+
+
+ int zoneStart = m_zoneStart * pixelPerMark() * FRAME_SIZE;
+ int zoneEnd = m_zoneEnd * pixelPerMark() * FRAME_SIZE;
- int value = m_view->cursorPos() - offset();
+ p.fillRect(QRect(zoneStart - offset(), e->rect().y() + e->rect().height() / 2, zoneEnd - zoneStart, e->rect().height() / 2), QBrush(QColor(133, 255, 143)));
+
+ int value = m_view->cursorPos() - offset() + 4;
int minval = minimum();
int maxval = maximum() + offset() - endOffset();
}
}*/
+
+ // draw zone cursors
+ int off = offset();
+ if (zoneStart > 0) {
+ QPolygon pa(4);
+ pa.setPoints(4, zoneStart - off + 3, 9, zoneStart - off, 9, zoneStart - off, 18, zoneStart - off + 3, 18);
+ p.drawPolyline(pa);
+ }
+
+ if (zoneEnd > 0) {
+ QRect rec(zoneStart - off + (zoneEnd - zoneStart) / 2 - 4, 9, 8, 9);
+ p.fillRect(rec, QColor(255, 255, 255, 150));
+ p.drawRect(rec);
+
+ QPolygon pa(4);
+ pa.setPoints(4, zoneEnd - off - 3, 9, zoneEnd - off, 9, zoneEnd - off, 18, zoneEnd - off - 3, 18);
+ p.drawPolyline(pa);
+ }
+
// draw pointer
if (showPointer() && value > 0) {
- QPolygon pa(4);
- pa.setPoints(3, value - 6, 9, value + 6, 9, value/*+0*/, 16);
+ QPolygon pa(3);
+ pa.setPoints(3, value - 6, 7, value + 6, 7, value, 16);
p.setBrush(QBrush(Qt::yellow));
p.drawPolygon(pa);
}
+
+
}
#include "customruler.moc"