X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fcustomruler.cpp;h=98baa6372c3f7a7f54af763bec936f393d40c9f6;hb=b691c7f8faddc1d7f2bf6acdba5cee879e810548;hp=6897335549b2ab4bb6b985f152350c018f65057a;hpb=5a3f12fb8be6a6f0ef2b7d0e75cb30646a6ba613;p=kdenlive diff --git a/src/customruler.cpp b/src/customruler.cpp index 68973355..98baa637 100644 --- a/src/customruler.cpp +++ b/src/customruler.cpp @@ -18,12 +18,15 @@ ***************************************************************************/ #include "customruler.h" +#include "kdenlivesettings.h" #include #include #include #include +#include +#include #include #include @@ -58,13 +61,14 @@ CustomRuler::CustomRuler(Timecode tc, CustomTrackView *parent) : m_view(parent), m_duration(0), m_offset(0), - m_clickedGuide(-1) + m_clickedGuide(-1), + m_mouseMove(NO_MOVE) { setFont(KGlobalSettings::toolBarFont()); QFontMetricsF fontMetrics(font()); LABEL_SIZE = fontMetrics.ascent() - 2; m_scale = 3; - m_zoneColor = QColor(133, 255, 143); + m_zoneColor = KStatefulBrush(KColorScheme::View, KColorScheme::PositiveBackground, KSharedConfig::openConfig(KdenliveSettings::colortheme())).brush(this).color(); littleMarkDistance = FRAME_SIZE; mediumMarkDistance = FRAME_SIZE * m_timecode.fps(); bigMarkDistance = FRAME_SIZE * m_timecode.fps() * 60; @@ -79,6 +83,8 @@ CustomRuler::CustomRuler(Timecode tc, CustomTrackView *parent) : connect(m_deleteGuide , SIGNAL(triggered()), this, SLOT(slotDeleteGuide())); QAction *delAllGuides = m_contextMenu->addAction(KIcon("edit-delete"), i18n("Delete All Guides")); connect(delAllGuides, SIGNAL(triggered()), m_view, SLOT(slotDeleteAllGuides())); + m_goMenu = m_contextMenu->addMenu(i18n("Go To")); + connect(m_goMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotGoToGuide(QAction *))); setMouseTracking(true); setMinimumHeight(20); } @@ -101,13 +107,27 @@ void CustomRuler::slotDeleteGuide() m_view->slotDeleteGuide(m_clickedGuide); } +void CustomRuler::slotGoToGuide(QAction *act) +{ + m_view->setCursorPos(act->data().toInt(), true); + m_view->initCursorPos(act->data().toInt()); +} + void CustomRuler::setZone(QPoint p) { - int min = qMin(m_zoneStart, p.x()); - int max = qMax(m_zoneEnd, p.y()); m_zoneStart = p.x(); m_zoneEnd = p.y(); - update(min * m_factor - 2, 0, (max - min) * m_factor + 4, height()); + update(); +} + +void CustomRuler::mouseReleaseEvent(QMouseEvent * /*event*/) +{ + if (m_moveCursor == RULER_START || m_moveCursor == RULER_END || m_moveCursor == RULER_MIDDLE) { + emit zoneMoved(m_zoneStart, m_zoneEnd); + m_view->setDocumentModified(); + } + m_mouseMove = NO_MOVE; + } // virtual @@ -118,6 +138,7 @@ void CustomRuler::mousePressEvent(QMouseEvent * event) m_clickedGuide = m_view->hasGuide((int)(pos / m_factor), (int)(5 / m_factor + 1)); m_editGuide->setEnabled(m_clickedGuide > 0); m_deleteGuide->setEnabled(m_clickedGuide > 0); + m_view->buildGuidesMenu(m_goMenu); m_contextMenu->exec(event->globalPos()); return; } @@ -128,22 +149,42 @@ void CustomRuler::mousePressEvent(QMouseEvent * event) if (qAbs(pos - m_zoneStart * m_factor) < 4) m_moveCursor = RULER_START; else if (qAbs(pos - (m_zoneStart + (m_zoneEnd - m_zoneStart) / 2) * m_factor) < 4) m_moveCursor = RULER_MIDDLE; else if (qAbs(pos - m_zoneEnd * m_factor) < 4) m_moveCursor = RULER_END; + m_view->updateSnapPoints(NULL); } - if (m_moveCursor == RULER_CURSOR) + if (m_moveCursor == RULER_CURSOR) { m_view->setCursorPos((int) pos / m_factor); + m_clickPoint = event->pos(); + m_startRate = m_rate; + } } // virtual void CustomRuler::mouseMoveEvent(QMouseEvent * event) { if (event->buttons() == Qt::LeftButton) { - int pos = (int)((event->x() + offset()) / m_factor); + int pos; + if (m_moveCursor == RULER_START || m_moveCursor == RULER_END) { + pos = m_view->getSnapPointForPos((int)((event->x() + offset()) / m_factor)); + } else pos = (int)((event->x() + offset()) / m_factor); int zoneStart = m_zoneStart; int zoneEnd = m_zoneEnd; if (pos < 0) pos = 0; if (m_moveCursor == RULER_CURSOR) { - m_view->setCursorPos(pos); - m_view->slotCheckPositionScrolling(); + QPoint diff = event->pos() - m_clickPoint; + if (m_mouseMove == NO_MOVE) { + if (!KdenliveSettings::verticalzoom() || qAbs(diff.x()) >= QApplication::startDragDistance()) { + m_mouseMove = HORIZONTAL_MOVE; + } else if (qAbs(diff.y()) >= QApplication::startDragDistance()) { + m_mouseMove = VERTICAL_MOVE; + } else return; + } + if (m_mouseMove == HORIZONTAL_MOVE) { + m_view->setCursorPos(pos); + m_view->slotCheckPositionScrolling(); + } else { + int verticalDiff = m_startRate - (diff.y()) / 7; + if (verticalDiff != m_rate) emit adjustZoom(verticalDiff); + } return; } else if (m_moveCursor == RULER_START) m_zoneStart = pos; else if (m_moveCursor == RULER_END) m_zoneEnd = pos; @@ -153,8 +194,6 @@ void CustomRuler::mouseMoveEvent(QMouseEvent * event) m_zoneStart += move; m_zoneEnd += move; } - emit zoneMoved(m_zoneStart, m_zoneEnd); - m_view->setDocumentModified(); int min = qMin(m_zoneStart, zoneStart); int max = qMax(m_zoneEnd, zoneEnd); @@ -165,16 +204,20 @@ void CustomRuler::mouseMoveEvent(QMouseEvent * event) if (event->y() <= 10) setCursor(Qt::ArrowCursor); else if (qAbs(pos - m_zoneStart * m_factor) < 4) { setCursor(KCursor("left_side", Qt::SizeHorCursor)); - setToolTip(i18n("Zone start: %1", m_timecode.getTimecodeFromFrames(m_zoneStart))); + if (KdenliveSettings::frametimecode()) setToolTip(i18n("Zone start: %1", m_zoneStart)); + else setToolTip(i18n("Zone start: %1", m_timecode.getTimecodeFromFrames(m_zoneStart))); } else if (qAbs(pos - m_zoneEnd * m_factor) < 4) { setCursor(KCursor("right_side", Qt::SizeHorCursor)); - setToolTip(i18n("Zone end: %1", m_timecode.getTimecodeFromFrames(m_zoneEnd))); + if (KdenliveSettings::frametimecode()) setToolTip(i18n("Zone end: %1", m_zoneEnd)); + else setToolTip(i18n("Zone end: %1", m_timecode.getTimecodeFromFrames(m_zoneEnd))); } else if (qAbs(pos - (m_zoneStart + (m_zoneEnd - m_zoneStart) / 2) * m_factor) < 4) { setCursor(Qt::SizeHorCursor); - setToolTip(i18n("Zone duration: %1", m_timecode.getTimecodeFromFrames(m_zoneEnd - m_zoneStart))); + if (KdenliveSettings::frametimecode()) setToolTip(i18n("Zone duration: %1", m_zoneEnd - m_zoneStart)); + else setToolTip(i18n("Zone duration: %1", m_timecode.getTimecodeFromFrames(m_zoneEnd - m_zoneStart))); } else { setCursor(Qt::ArrowCursor); - setToolTip(QString()); + if (KdenliveSettings::frametimecode()) setToolTip(i18n("Position: %1", (int)(pos / m_factor))); + else setToolTip(i18n("Position: %1", m_timecode.getTimecodeFromFrames(pos / m_factor))); } } } @@ -218,9 +261,10 @@ void CustomRuler::slotCursorMoved(int oldpos, int newpos) } else update(qMin(oldpos, newpos) * m_factor - offset() - 6, 0, qAbs(oldpos - newpos) * m_factor + 17, height()); } -void CustomRuler::setPixelPerMark(double rate) +void CustomRuler::setPixelPerMark(int rate) { - int scale = comboScale[(int) rate]; + int scale = comboScale[rate]; + m_rate = rate; m_factor = 1.0 / (double) scale * FRAME_SIZE; m_scale = 1.0 / (double) scale; double fend = m_scale * littleMarkDistance; @@ -237,7 +281,7 @@ void CustomRuler::setPixelPerMark(double rate) mediumMarkDistance = (double) FRAME_SIZE * m_timecode.fps(); bigMarkDistance = (double) FRAME_SIZE * m_timecode.fps() * 60; } - switch ((int) rate) { + switch (rate) { case 0: m_textSpacing = fend; break; @@ -300,18 +344,23 @@ void CustomRuler::paintEvent(QPaintEvent *e) const int value = m_view->cursorPos() * m_factor - m_offset; int minval = (e->rect().left() + m_offset) / FRAME_SIZE - 1; const int maxval = (e->rect().right() + m_offset) / FRAME_SIZE + 1; - if (minval < 0) minval = 0; + if (minval < 0) + minval = 0; double f, fend; const int offsetmax = maxval * FRAME_SIZE; - p.setPen(palette().dark().color()); + p.setPen(palette().text().color()); // draw time labels int offsetmin = (e->rect().left() + m_offset) / m_textSpacing; offsetmin = offsetmin * m_textSpacing; for (f = offsetmin; f < offsetmax; f += m_textSpacing) { - QString lab = m_timecode.getTimecodeFromFrames((int)(f / m_factor + 0.5)); + QString lab; + if (KdenliveSettings::frametimecode()) + lab = QString::number((int)(f / m_factor + 0.5)); + else + lab = m_timecode.getTimecodeFromFrames((int)(f / m_factor + 0.5)); p.drawText(f - m_offset + 2, LABEL_SIZE, lab); } @@ -319,22 +368,28 @@ void CustomRuler::paintEvent(QPaintEvent *e) offsetmin = offsetmin * littleMarkDistance; // draw the little marks fend = m_scale * littleMarkDistance; - if (fend > 5) for (f = offsetmin - m_offset; f < offsetmax - m_offset; f += fend) + if (fend > 5) { + for (f = offsetmin - m_offset; f < offsetmax - m_offset; f += fend) p.drawLine((int)f, LITTLE_MARK_X1, (int)f, LITTLE_MARK_X2); + } offsetmin = (e->rect().left() + m_offset) / mediumMarkDistance; offsetmin = offsetmin * mediumMarkDistance; // draw medium marks fend = m_scale * mediumMarkDistance; - if (fend > 5) for (f = offsetmin - m_offset - fend; f < offsetmax - m_offset + fend; f += fend) + if (fend > 5) { + for (f = offsetmin - m_offset - fend; f < offsetmax - m_offset + fend; f += fend) p.drawLine((int)f, MIDDLE_MARK_X1, (int)f, MIDDLE_MARK_X2); + } offsetmin = (e->rect().left() + m_offset) / bigMarkDistance; offsetmin = offsetmin * bigMarkDistance; // draw big marks fend = m_scale * bigMarkDistance; - if (fend > 5) for (f = offsetmin - m_offset; f < offsetmax - m_offset; f += fend) + if (fend > 5) { + for (f = offsetmin - m_offset; f < offsetmax - m_offset; f += fend) p.drawLine((int)f, BIG_MARK_X1, (int)f, BIG_MARK_X2); + } // draw zone cursors int off = offset();