From 2d29ded2ead7275b92a258dcc5fd9d6f576ca257 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Sun, 9 Mar 2008 21:27:56 +0000 Subject: [PATCH 1/1] Zone selection widget svn path=/branches/KDE4/; revision=2031 --- src/customruler.cpp | 71 +++++++++++++++++++++++++++++++++++++++------ src/customruler.h | 8 +++++ src/mainwindow.cpp | 9 +++++- src/trackview.cpp | 12 ++++++++ src/trackview.h | 2 ++ 5 files changed, 92 insertions(+), 10 deletions(-) diff --git a/src/customruler.cpp b/src/customruler.cpp index 866e54e8..58f6c3d7 100644 --- a/src/customruler.cpp +++ b/src/customruler.cpp @@ -84,22 +84,48 @@ CustomRuler::CustomRuler(Timecode tc, CustomTrackView *parent) 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 / pixelPerMark() / FRAME_SIZE); + 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 / pixelPerMark() / FRAME_SIZE); + 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() { + return m_zoneStart; +} + +int CustomRuler::outPoint() { + return m_zoneEnd; } void CustomRuler::slotMoveRuler(int newPos) { - int diff = offset() - newPos; KRuler::slotNewOffset(newPos); } @@ -114,12 +140,18 @@ void CustomRuler::setPixelPerMark(double rate) { } // 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(255, 255, 255, 80))); + //kDebug()<<"RULER ZONE: "<rect().y() + e->rect().height() / 2, zoneEnd - zoneStart, e->rect().height() / 2), QBrush(QColor(133, 255, 143))); - int value = m_view->cursorPos() - offset(); + int value = m_view->cursorPos() - offset() + 4; int minval = minimum(); int maxval = maximum() + offset() - endOffset(); @@ -209,14 +241,35 @@ void CustomRuler::paintEvent(QPaintEvent * /*e*/) { } }*/ + + // 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" diff --git a/src/customruler.h b/src/customruler.h index b0b28198..d391bb96 100644 --- a/src/customruler.h +++ b/src/customruler.h @@ -6,6 +6,8 @@ #include "customtrackview.h" #include "timecode.h" +enum RULER_MOVE { RULER_CURSOR = 0, RULER_START = 1, RULER_MIDDLE = 2, RULER_END = 3 }; + class CustomRuler : public KRuler { Q_OBJECT @@ -15,6 +17,9 @@ public: virtual void mouseMoveEvent(QMouseEvent * event); void setPixelPerMark(double rate); static const int comboScale[]; + int outPoint(); + int inPoint(); + protected: virtual void paintEvent(QPaintEvent * /*e*/); @@ -22,6 +27,9 @@ private: int m_cursorPosition; Timecode m_timecode; CustomTrackView *m_view; + int m_zoneStart; + int m_zoneEnd; + RULER_MOVE m_moveCursor; public slots: void slotMoveRuler(int newPos); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 454bfd01..e115bffe 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -475,6 +475,13 @@ void MainWindow::slotEditProjectSettings() { void MainWindow::slotRenderProject() { KUrl exportFile = KUrl(KFileDialog::getSaveFileName()); if (exportFile.isEmpty()) return; + int in; + int out; + TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget(); + if (currentTab) { + in = currentTab->inPoint(); + out = currentTab->outPoint(); + } KTemporaryFile temp; temp.setAutoRemove(false); temp.setSuffix(".westley"); @@ -483,7 +490,7 @@ void MainWindow::slotRenderProject() { m_projectMonitor->saveSceneList(temp.fileName()); QStringList args; args << "-erase"; - if (0) args << "in=50" << "out=150"; + args << "in=" + QString::number(in) << "out=" + QString::number(out); args << "inigo" << "kmplayer" << temp.fileName() << exportFile.path(); QProcess::startDetached("kdenlive_render", args); } diff --git a/src/trackview.cpp b/src/trackview.cpp index 170d7598..55b6cd40 100644 --- a/src/trackview.cpp +++ b/src/trackview.cpp @@ -44,6 +44,10 @@ TrackView::TrackView(KdenliveDoc *doc, QWidget *parent) m_ruler = new CustomRuler(doc->timecode(), m_trackview); QVBoxLayout *layout = new QVBoxLayout; view->ruler_frame->setLayout(layout); + int left_margin; + int right_margin; + layout->getContentsMargins(&left_margin, 0, &right_margin, 0); + layout->setContentsMargins(left_margin, 0, right_margin, 0); layout->addWidget(m_ruler); m_headersLayout = new QVBoxLayout; @@ -81,6 +85,14 @@ int TrackView::tracksNumber() { return m_projectTracks; } +int TrackView::inPoint() { + return m_ruler->inPoint(); +} + +int TrackView::outPoint() { + return m_ruler->outPoint(); +} + void TrackView::slotClipItemSelected(ClipItem*c) { emit clipItemSelected(c); } diff --git a/src/trackview.h b/src/trackview.h index ee581858..09304cb7 100644 --- a/src/trackview.h +++ b/src/trackview.h @@ -52,6 +52,8 @@ public: int tracksNumber(); KdenliveDoc *document(); void refresh() ; + int outPoint(); + int inPoint(); public slots: void slotDeleteClip(int clipId); -- 2.39.2