X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcustomruler.cpp;h=824856653f1cca9e1a66c9e3e9f42840e67a41fd;hb=55ab81618b3e7e332109350167dcc3d094658336;hp=029f52c269d5f9f8fea3e083d7a0b0293d99d5ee;hpb=ce68de86827a11cd0dc96465fba021b2f7ceea55;p=kdenlive diff --git a/src/customruler.cpp b/src/customruler.cpp index 029f52c2..82485665 100644 --- a/src/customruler.cpp +++ b/src/customruler.cpp @@ -44,6 +44,8 @@ static int littleMarkDistance; static int mediumMarkDistance; static int bigMarkDistance; +#define SEEK_INACTIVE (-1) + #include "definitions.h" const int CustomRuler::comboScale[] = { 1, 2, 5, 10, 25, 50, 125, 250, 500, 750, 1500, 3000, 6000, 12000}; @@ -54,9 +56,11 @@ CustomRuler::CustomRuler(Timecode tc, CustomTrackView *parent) : m_view(parent), m_duration(0), m_offset(0), + m_lastSeekPosition(SEEK_INACTIVE), m_clickedGuide(-1), m_rate(-1), - m_mouseMove(NO_MOVE) + m_mouseMove(NO_MOVE), + m_cursorColor(palette().text()) { setFont(KGlobalSettings::toolBarFont()); QFontMetricsF fontMetrics(font()); @@ -123,7 +127,7 @@ void CustomRuler::slotDeleteGuide() void CustomRuler::slotGoToGuide(QAction *act) { - m_view->setCursorPos(act->data().toInt(), true); + m_view->seekCursorPos(act->data().toInt()); m_view->initCursorPos(act->data().toInt()); } @@ -166,7 +170,7 @@ void CustomRuler::mousePressEvent(QMouseEvent * event) m_view->updateSnapPoints(NULL); } if (m_moveCursor == RULER_CURSOR) { - m_view->setCursorPos((int) pos / m_factor); + m_view->seekCursorPos((int) pos / m_factor); m_clickPoint = event->pos(); m_startRate = m_rate; } @@ -193,7 +197,7 @@ void CustomRuler::mouseMoveEvent(QMouseEvent * event) } else return; } if (m_mouseMove == HORIZONTAL_MOVE) { - m_view->setCursorPos(pos); + m_view->seekCursorPos(pos); m_view->slotCheckPositionScrolling(); } else { int verticalDiff = m_startRate - (diff.y()) / 7; @@ -208,13 +212,22 @@ void CustomRuler::mouseMoveEvent(QMouseEvent * event) m_zoneStart += move; m_zoneEnd += move; } - int min = qMin(m_zoneStart, zoneStart); int max = qMax(m_zoneEnd, zoneEnd); update(min * m_factor - m_offset - 2, 0, (max - min) * m_factor + 4, height()); } else { - int pos = (int)((event->x() + offset())); + int pos = (int)((event->x() + m_offset)); + if (m_cursorColor == palette().text() && qAbs(pos - m_view->cursorPos() * m_factor) < 7) { + // Mouse is over cursor + m_cursorColor = palette().highlight(); + update(m_view->cursorPos() * m_factor - m_offset - 10, 0, 20, height()); + } + else if (m_cursorColor == palette().highlight() && qAbs(pos - m_view->cursorPos() * m_factor) >= 7) { + m_cursorColor = palette().text(); + update(m_view->cursorPos() * m_factor - m_offset - 10, 0, 20, height()); + } + if (event->y() <= 10) setCursor(Qt::ArrowCursor); else if (qAbs(pos - m_zoneStart * m_factor) < 4) { setCursor(KCursor("left_side", Qt::SizeHorCursor)); @@ -237,6 +250,16 @@ void CustomRuler::mouseMoveEvent(QMouseEvent * event) } +// virtual +void CustomRuler::leaveEvent(QEvent * event) +{ + QWidget::leaveEvent(event); + if (m_cursorColor == palette().highlight()) { + m_cursorColor = palette().text(); + update(); + } +} + // virtual void CustomRuler::wheelEvent(QWheelEvent * e) { @@ -269,10 +292,41 @@ int CustomRuler::offset() const void CustomRuler::slotCursorMoved(int oldpos, int newpos) { - if (qAbs(oldpos - newpos) * m_factor > m_textSpacing) { - update(oldpos * m_factor - offset() - 6, BIG_MARK_X, 14, MAX_HEIGHT - BIG_MARK_X); - update(newpos * m_factor - offset() - 6, BIG_MARK_X, 14, MAX_HEIGHT - BIG_MARK_X); - } else update(qMin(oldpos, newpos) * m_factor - offset() - 6, BIG_MARK_X, qAbs(oldpos - newpos) * m_factor + 14, MAX_HEIGHT - BIG_MARK_X); + int min = qMin(oldpos, newpos); + int max = qMax(oldpos, newpos); + if (m_lastSeekPosition != SEEK_INACTIVE) { + if (m_lastSeekPosition == newpos) { + m_lastSeekPosition = SEEK_INACTIVE; + } + else { + min = qMin(min, m_lastSeekPosition); + max = qMax(max, m_lastSeekPosition); + } + } + update(min * m_factor - m_offset - 6, BIG_MARK_X, (max - min) * m_factor + 14, MAX_HEIGHT - BIG_MARK_X); +} + +void CustomRuler::updateRuler() +{ + // Update requested seek position + int min = SEEK_INACTIVE; + int max = SEEK_INACTIVE; + if (m_lastSeekPosition != SEEK_INACTIVE) { + min = max = m_lastSeekPosition; + } + m_lastSeekPosition = m_view->seekPosition(); + if (m_lastSeekPosition != SEEK_INACTIVE) { + if (min == SEEK_INACTIVE) { + min = max = m_lastSeekPosition; + } + else { + min = qMin(min, m_lastSeekPosition); + max = qMax(max, m_lastSeekPosition); + } + } + if (min != SEEK_INACTIVE) { + update(min * m_factor - offset() - 3, BIG_MARK_X, (max - min) * m_factor + 6, MAX_HEIGHT - BIG_MARK_X); + } } void CustomRuler::setPixelPerMark(int rate) @@ -345,18 +399,16 @@ void CustomRuler::setDuration(int d) void CustomRuler::paintEvent(QPaintEvent *e) { QStylePainter p(this); - p.setClipRect(e->rect()); - - // Draw background - //p.fillRect(0, 0, m_duration * m_factor - m_offset, MAX_HEIGHT, palette().alternateBase().color()); + const QRect &paintRect = e->rect(); + p.setClipRect(paintRect); // Draw zone background const int zoneStart = (int)(m_zoneStart * m_factor); const int zoneEnd = (int)(m_zoneEnd * m_factor); p.fillRect(zoneStart - m_offset, LABEL_SIZE + 2, zoneEnd - zoneStart, MAX_HEIGHT - LABEL_SIZE - 2, m_zoneColor); - int minval = (e->rect().left() + m_offset) / FRAME_SIZE - 1; - const int maxval = (e->rect().right() + m_offset) / FRAME_SIZE + 1; + int minval = (paintRect.left() + m_offset) / FRAME_SIZE - 1; + const int maxval = (paintRect.right() + m_offset) / FRAME_SIZE + 1; if (minval < 0) minval = 0; @@ -367,8 +419,8 @@ void CustomRuler::paintEvent(QPaintEvent *e) p.setPen(palette().text().color()); // draw time labels - if (e->rect().y() < LABEL_SIZE) { - offsetmin = (e->rect().left() + m_offset) / m_textSpacing; + if (paintRect.y() < LABEL_SIZE) { + offsetmin = (paintRect.left() + m_offset) / m_textSpacing; offsetmin = offsetmin * m_textSpacing; for (f = offsetmin; f < offsetmax; f += m_textSpacing) { QString lab; @@ -380,7 +432,7 @@ void CustomRuler::paintEvent(QPaintEvent *e) } } - offsetmin = (e->rect().left() + m_offset) / littleMarkDistance; + offsetmin = (paintRect.left() + m_offset) / littleMarkDistance; offsetmin = offsetmin * littleMarkDistance; // draw the little marks fend = m_scale * littleMarkDistance; @@ -389,7 +441,7 @@ void CustomRuler::paintEvent(QPaintEvent *e) p.drawLine((int)f, LITTLE_MARK_X, (int)f, MAX_HEIGHT); } - offsetmin = (e->rect().left() + m_offset) / mediumMarkDistance; + offsetmin = (paintRect.left() + m_offset) / mediumMarkDistance; offsetmin = offsetmin * mediumMarkDistance; // draw medium marks fend = m_scale * mediumMarkDistance; @@ -398,7 +450,7 @@ void CustomRuler::paintEvent(QPaintEvent *e) p.drawLine((int)f, MIDDLE_MARK_X, (int)f, MAX_HEIGHT); } - offsetmin = (e->rect().left() + m_offset) / bigMarkDistance; + offsetmin = (paintRect.left() + m_offset) / bigMarkDistance; offsetmin = offsetmin * bigMarkDistance; // draw big marks fend = m_scale * bigMarkDistance; @@ -427,11 +479,17 @@ void CustomRuler::paintEvent(QPaintEvent *e) } // draw pointer - const int value = m_view->cursorPos() * m_factor - m_offset; + const int value = m_view->cursorPos() * m_factor - m_offset; QPolygon pa(3); pa.setPoints(3, value - 6, BIG_MARK_X, value + 6, BIG_MARK_X, value, MAX_HEIGHT - 1); - p.setBrush(palette().highlight()); + p.setBrush(m_cursorColor); + p.setPen(Qt::NoPen); p.drawPolygon(pa); + + if (m_lastSeekPosition != SEEK_INACTIVE && m_lastSeekPosition != m_view->cursorPos()) { + p.fillRect(m_lastSeekPosition * m_factor - m_offset - 1, BIG_MARK_X, 3, MAX_HEIGHT - 1, palette().highlight()); + } + } #include "customruler.moc"