X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fsmallruler.cpp;h=89d876d8cc7cbdc3305254d9f2448c31e5faf29a;hb=b4a0ec0fffc1cbbf21d2ea9fc418885e3b34bce8;hp=28f5edb6e8ad5bbc2dfcdbc5e17336735bb05d03;hpb=e4a587eb01e15cbd4c6cd200e656e83f9a3885b0;p=kdenlive diff --git a/src/smallruler.cpp b/src/smallruler.cpp index 28f5edb6..89d876d8 100644 --- a/src/smallruler.cpp +++ b/src/smallruler.cpp @@ -18,21 +18,36 @@ ***************************************************************************/ -#include -#include +#include "smallruler.h" +#include "kdenlivesettings.h" #include +#include +#include -#include "smallruler.h" +#include +#include -SmallRuler::SmallRuler(QWidget *parent) - : QWidget(parent), m_scale(1), m_maxval(25) { +SmallRuler::SmallRuler(MonitorManager *manager, QWidget *parent) : + QWidget(parent) + ,m_cursorFramePosition(0) + ,m_scale(1) + ,m_maxval(25) + ,m_manager(manager) + ,m_overCursor(false) +{ m_zoneStart = 10; m_zoneEnd = 60; + KSharedConfigPtr config = KSharedConfig::openConfig(KdenliveSettings::colortheme()); + m_zoneBrush = KStatefulBrush(KColorScheme::View, KColorScheme::PositiveBackground, config); + + setMouseTracking(true); + setMinimumHeight(10); } -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; @@ -48,10 +63,11 @@ void SmallRuler::adjustScale(int maximum) { m_medium = 60 * 25; } m_cursorPosition = m_cursorFramePosition * m_scale; - update(); + updatePixmap(); } -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)); @@ -70,75 +86,158 @@ void SmallRuler::setZone(int start, int end) { m_zoneEnd = end; } else m_zoneEnd = end; } - update(); + updatePixmap(); +} + +void SmallRuler::setMarkers(QList < int > list) +{ + m_markers = list; + updatePixmap(); } -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)); + updatePixmap(); + + } else emit seekRenderer((int) pos); +} + +void SmallRuler::leaveEvent( QEvent * event ) +{ + Q_UNUSED(event); + if (m_overCursor) { + m_overCursor = false; + update(); + } } // virtual -void SmallRuler::mouseMoveEvent(QMouseEvent * event) { +void SmallRuler::mouseMoveEvent(QMouseEvent * event) +{ const int pos = event->x() / m_scale; - emit seekRenderer((int) pos); + if (event->button() == Qt::NoButton) { + if (qAbs(pos * m_scale - m_cursorPosition) < 6) { + if (!m_overCursor) { + m_overCursor = true; + update(); + } + } + else if (m_overCursor) { + m_overCursor = false; + update(); + } + } + if (event->buttons() & Qt::LeftButton) { + m_overCursor = true; + emit seekRenderer((int) pos); + } + else { + 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) { + setToolTip(i18n("Zone end: %1", m_manager->timecode().getTimecodeFromFrames(m_zoneEnd))); + } else if (pos > m_zoneStart && pos < m_zoneEnd) { + setToolTip(i18n("Zone duration: %1", m_manager->timecode().getTimecodeFromFrames(m_zoneEnd - m_zoneStart))); + } else setToolTip(i18n("Position: %1", m_manager->timecode().getTimecodeFromFrames(pos))); + } } -void SmallRuler::slotNewValue(int value) { +bool SmallRuler::slotNewValue(int value) +{ + if (value == m_cursorFramePosition) return false; m_cursorFramePosition = value; int oldPos = m_cursorPosition; m_cursorPosition = value * m_scale; - if (oldPos == m_cursorPosition) return; const int offset = 6; const int x = qMin(oldPos, m_cursorPosition); const int w = qAbs(oldPos - m_cursorPosition); - update(x - offset, 9, w + 2 * offset, 6); + update(x - offset, 4, w + 2 * offset, 6); + return true; +} + +int SmallRuler::position() const +{ + return m_cursorFramePosition; } //virtual -void SmallRuler::resizeEvent(QResizeEvent *) { +void SmallRuler::resizeEvent(QResizeEvent *) +{ adjustScale(m_maxval); } -// virtual -void SmallRuler::paintEvent(QPaintEvent *e) { - - QPainter p(this); - QRect r = e->rect(); - p.setClipRect(r); - +void SmallRuler::updatePixmap() +{ + m_pixmap = QPixmap(width(), height()); + m_pixmap.fill(palette().window().color()); + QPainter p(&m_pixmap); double f, fend; - p.setPen(palette().dark().color()); const int zoneStart = (int)(m_zoneStart * m_scale); const int zoneEnd = (int)(m_zoneEnd * m_scale); + p.setPen(Qt::NoPen); + p.setBrush(m_zoneBrush.brush(this)); + p.drawRect(zoneStart, height() / 2 - 1, zoneEnd - zoneStart, height() / 2); + + // 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.fillRect(QRect(zoneStart, height() / 2, zoneEnd - zoneStart, height() / 2), QBrush(QColor(133, 255, 143))); + // 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); + } + // 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.end(); + update(); +} - if (r.top() < 9) { - // draw the little marks - fend = m_scale * m_small; - if (fend > 2) for (f = 0; f < width(); f += fend) { - p.drawLine((int)f, 1, (int)f, 3); - } +// virtual +void SmallRuler::paintEvent(QPaintEvent *e) +{ - // draw medium marks - fend = m_scale * m_medium; - if (fend > 2) for (f = 0; f < width(); f += fend) { - p.drawLine((int)f, 1, (int)f, 5); - } - } + QPainter p(this); + QRect r = e->rect(); + p.setClipRect(r); + p.drawPixmap(QPointF(), m_pixmap); // draw pointer QPolygon pa(3); - pa.setPoints(3, m_cursorPosition - 5, 14, m_cursorPosition + 5, 14, m_cursorPosition/*+0*/, 9); - p.setBrush(palette().dark().color()); + pa.setPoints(3, m_cursorPosition - 6, 10, m_cursorPosition + 6, 10, m_cursorPosition/*+0*/, 4); + if (m_overCursor) p.setBrush(palette().highlight()); + else p.setBrush(palette().text().color()); + p.setPen(Qt::NoPen); p.drawPolygon(pa); } +void SmallRuler::updatePalette() +{ + KSharedConfigPtr config = KSharedConfig::openConfig(KdenliveSettings::colortheme()); + m_zoneBrush = KStatefulBrush(KColorScheme::View, KColorScheme::PositiveBackground, config); + updatePixmap(); +} + #include "smallruler.moc"