X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fsmallruler.cpp;h=24a016dd30ee2d2aeac4ef09a3199ca34d7c55ff;hb=51513e687f4f6d239370cfe7c7886ce2f8754d03;hp=f138b972c5e11275439720f9d4fc484b78e4e27b;hpb=ffbd98f8303b09f3fd4f7cf2c74c20080c7fd115;p=kdenlive diff --git a/src/smallruler.cpp b/src/smallruler.cpp index f138b972..24a016dd 100644 --- a/src/smallruler.cpp +++ b/src/smallruler.cpp @@ -19,24 +19,38 @@ #include "smallruler.h" +#include "kdenlivesettings.h" #include +#include +#include #include #include -SmallRuler::SmallRuler(MonitorManager *manager, QWidget *parent) : - QWidget(parent), - m_scale(1), - m_maxval(25), - m_manager(manager) +#define SEEK_INACTIVE (-1) + + +SmallRuler::SmallRuler(MonitorManager *manager, Render *render, QWidget *parent) : + QWidget(parent) + ,m_cursorFramePosition(0) + ,m_scale(1) + ,m_maxval(25) + ,m_manager(manager) + ,m_render(render) + ,m_lastSeekPosition(SEEK_INACTIVE) + ,m_cursorColor(palette().text()) { m_zoneStart = 10; m_zoneEnd = 60; - m_zoneColor = QColor(133, 255, 143); + KSharedConfigPtr config = KSharedConfig::openConfig(KdenliveSettings::colortheme()); + m_zoneBrush = KStatefulBrush(KColorScheme::View, KColorScheme::PositiveBackground, config); + setMouseTracking(true); + setMinimumHeight(10); } + void SmallRuler::adjustScale(int maximum) { m_maxval = maximum; @@ -53,10 +67,23 @@ void SmallRuler::adjustScale(int maximum) m_small = 30 * 25; m_medium = 60 * 25; } - m_cursorPosition = m_cursorFramePosition * m_scale; updatePixmap(); } +void SmallRuler::setZoneStart() +{ + int pos = m_render->requestedSeekPosition; + if (pos == SEEK_INACTIVE) pos = m_render->seekFramePosition(); + setZone(pos, -1); +} + +void SmallRuler::setZoneEnd() +{ + int pos = m_render->requestedSeekPosition; + if (pos == SEEK_INACTIVE) pos = m_render->seekFramePosition(); + setZone(-1, pos); +} + void SmallRuler::setZone(int start, int end) { if (start != -1) { @@ -80,7 +107,7 @@ void SmallRuler::setZone(int start, int end) updatePixmap(); } -void SmallRuler::setMarkers(QList < int > list) +void SmallRuler::setMarkers(QList < CommentedTime > list) { m_markers = list; updatePixmap(); @@ -102,15 +129,43 @@ void SmallRuler::mousePressEvent(QMouseEvent * event) emit zoneChanged(QPoint(m_zoneStart, m_zoneEnd)); updatePixmap(); - } else emit seekRenderer((int) pos); + } else { + m_render->seekToFrame(pos); + m_lastSeekPosition = pos; + update(); + } +} + +// virtual +void SmallRuler::leaveEvent(QEvent * event) +{ + QWidget::leaveEvent(event); + if (m_cursorColor == palette().highlight()) { + m_cursorColor = palette().text(); + update(); + } } // virtual void SmallRuler::mouseMoveEvent(QMouseEvent * event) { + QWidget::mouseMoveEvent(event); const int pos = event->x() / m_scale; - if (event->buttons() & Qt::LeftButton) emit seekRenderer((int) pos); + if (event->buttons() & Qt::LeftButton) { + m_render->seekToFrame(pos); + m_lastSeekPosition = pos; + update(); + } else { + if (m_cursorColor == palette().text() && qAbs(pos - m_cursorFramePosition) * m_scale < 7) { + // Mouse is over cursor + m_cursorColor = palette().highlight(); + update(); + } + else if (m_cursorColor == palette().highlight() && qAbs(pos - m_cursorFramePosition) * m_scale >= 7) { + m_cursorColor = palette().text(); + update(); + } if (qAbs((pos - m_zoneStart) * m_scale) < 4) { setToolTip(i18n("Zone start: %1", m_manager->timecode().getTimecodeFromFrames(m_zoneStart))); } else if (qAbs((pos - m_zoneEnd) * m_scale) < 4) { @@ -121,19 +176,28 @@ void SmallRuler::mouseMoveEvent(QMouseEvent * event) } } +void SmallRuler::refreshRuler() +{ + m_lastSeekPosition = SEEK_INACTIVE; + update(); +} + bool SmallRuler::slotNewValue(int value) { + if (value == m_cursorFramePosition) return false; + if (value == m_lastSeekPosition) m_lastSeekPosition = SEEK_INACTIVE; m_cursorFramePosition = value; - int oldPos = m_cursorPosition; + /*int oldPos = m_cursorPosition; m_cursorPosition = value * m_scale; - if (oldPos == m_cursorPosition) return false; const int offset = 6; const int x = qMin(oldPos, m_cursorPosition); const int w = qAbs(oldPos - m_cursorPosition); - update(x - offset, 4, w + 2 * offset, 6); + update(x - offset, 0, w + 2 * offset, height());*/ + update(); return true; } + //virtual void SmallRuler::resizeEvent(QResizeEvent *) { @@ -144,32 +208,37 @@ void SmallRuler::updatePixmap() { m_pixmap = QPixmap(width(), height()); m_pixmap.fill(palette().window().color()); + m_lastSeekPosition = SEEK_INACTIVE; QPainter p(&m_pixmap); double f, fend; const int zoneStart = (int)(m_zoneStart * m_scale); const int zoneEnd = (int)(m_zoneEnd * m_scale); - p.fillRect(zoneStart, height() / 2 - 1, zoneEnd - zoneStart, height() / 2, m_zoneColor); + p.setPen(Qt::NoPen); + p.setBrush(m_zoneBrush.brush(this)); + p.drawRect(zoneStart, height() / 2 - 1, zoneEnd - zoneStart, height() / 2); - // draw markers - if (!m_markers.isEmpty()) { - p.setPen(Qt::red); - for (int i = 0; i < m_markers.count(); i++) { - p.drawLine(m_markers.at(i) * m_scale, 0, m_markers.at(i) * m_scale, 9); - } - } - p.setPen(palette().dark().color()); + // draw ruler + p.setPen(palette().text().color()); // draw the little marks fend = m_scale * m_small; if (fend > 2) for (f = 0; f < width(); f += fend) { - p.drawLine((int)f, 0, (int)f, 3); - } + p.drawLine((int)f, 0, (int)f, 3); + } // draw medium marks fend = m_scale * m_medium; if (fend > 2) for (f = 0; f < width(); f += fend) { - p.drawLine((int)f, 0, (int)f, 6); + p.drawLine((int)f, 0, (int)f, 6); + } + // draw markers + if (!m_markers.isEmpty()) { + for (int i = 0; i < m_markers.count(); i++) { + int pos = m_markers.at(i).time().frames(m_manager->timecode().fps()) * m_scale; + p.setPen(CommentedTime::markerColor(m_markers.at(i).markerType())); + p.drawLine(pos, 0, pos, 9); } + } p.end(); update(); } @@ -183,12 +252,25 @@ void SmallRuler::paintEvent(QPaintEvent *e) p.setClipRect(r); p.drawPixmap(QPointF(), m_pixmap); + int cursorPos = m_cursorFramePosition * m_scale; // draw pointer QPolygon pa(3); - pa.setPoints(3, m_cursorPosition - 5, 10, m_cursorPosition + 5, 10, m_cursorPosition/*+0*/, 5); - p.setBrush(palette().dark().color()); + pa.setPoints(3, cursorPos - 6, 10, cursorPos + 6, 10, cursorPos/*+0*/, 4); + p.setBrush(m_cursorColor); p.setPen(Qt::NoPen); p.drawPolygon(pa); + + // Draw seeking pointer + if (m_lastSeekPosition != SEEK_INACTIVE && m_lastSeekPosition != m_cursorFramePosition) { + p.fillRect(m_lastSeekPosition * m_scale - 1, 0, 3, height(), palette().highlight()); + } +} + +void SmallRuler::updatePalette() +{ + KSharedConfigPtr config = KSharedConfig::openConfig(KdenliveSettings::colortheme()); + m_zoneBrush = KStatefulBrush(KColorScheme::View, KColorScheme::PositiveBackground, config); + updatePixmap(); } #include "smallruler.moc"