X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmonitorscene.cpp;h=e6be3de10188933da55b54a6b60c13e3dd682076;hb=d679fbf19a2511b181570418dc7fa7c815728bcb;hp=7396cf861d2b5065f248988d8f6845acd0123f34;hpb=f41e30e6ca85c0e93ad05fd1d69119141f7424e8;p=kdenlive diff --git a/src/monitorscene.cpp b/src/monitorscene.cpp index 7396cf86..e6be3de1 100644 --- a/src/monitorscene.cpp +++ b/src/monitorscene.cpp @@ -20,12 +20,15 @@ #include "monitorscene.h" #include "renderer.h" -#include "onmonitoritems/onmonitorrectitem.h" +#include "onmonitoritems/rotoscoping/bpointitem.h" +#include "onmonitoritems/rotoscoping/splineitem.h" #include "kdenlivesettings.h" #include #include #include +#include + MonitorScene::MonitorScene(Render *renderer, QObject* parent) : QGraphicsScene(parent), @@ -33,7 +36,8 @@ MonitorScene::MonitorScene(Render *renderer, QObject* parent) : m_view(NULL), m_backgroundImage(QImage()), m_enabled(true), - m_zoom(1.0) + m_zoom(1.0), + m_groupMove(false) { setBackgroundBrush(QBrush(QColor(KdenliveSettings::window_background().name()))); @@ -61,9 +65,20 @@ MonitorScene::MonitorScene(Render *renderer, QObject* parent) : connect(m_renderer, SIGNAL(frameUpdated(QImage)), this, SLOT(slotSetBackgroundImage(QImage))); } +void MonitorScene::centerView() +{ + if (m_view) m_view->centerOn(m_frameBorder); +} + +void MonitorScene::cleanup() +{ + // Reset scene rect + setSceneRect(m_frameBorder->boundingRect()); +} + void MonitorScene::setUp() { - if (views().count() > 0) { + if (!views().isEmpty()) { m_view = views().at(0); m_view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate); } else { @@ -85,7 +100,7 @@ void MonitorScene::setEnabled(bool enabled) void MonitorScene::slotUpdateBackground() { if (m_view && m_view->isVisible()) { - if (m_lastUpdate.msecsTo(QTime::currentTime()) > 100) { + if (m_lastUpdate.msecsTo(QTime::currentTime()) > 50) { m_background->setPixmap(QPixmap::fromImage(m_backgroundImage)); m_lastUpdate = QTime::currentTime(); } @@ -127,70 +142,138 @@ void MonitorScene::slotZoomOriginal() m_view->centerOn(m_frameBorder); } -void MonitorScene::slotZoomOut() +void MonitorScene::slotZoomOut(int by) { - slotZoom(qMax(0, (int)(m_zoom * 100 - 1))); + slotZoom(qMax(0, (int)(m_zoom * 100 - by))); } -void MonitorScene::slotZoomIn() +void MonitorScene::slotZoomIn(int by) { - int newzoom = (100 * m_zoom + 0.5); - newzoom++; - slotZoom(qMin(300, newzoom)); + slotZoom(qMin(300, (int)(m_zoom * 100 + by + 0.5))); } -void MonitorScene::addItem(QGraphicsItem* item) +void MonitorScene::mousePressEvent(QGraphicsSceneMouseEvent* event) { - QGraphicsScene::addItem(item); - - /*OnMonitorRectItem *rect = qgraphicsitem_cast(item); - if (rect) { - connect(this, SIGNAL(mousePressed(QGraphicsSceneMouseEvent*)), rect, SLOT(slotMousePressed(QGraphicsSceneMouseEvent*))); - connect(this, SIGNAL(mouseReleased(QGraphicsSceneMouseEvent*)), rect, SLOT(slotMouseReleased(QGraphicsSceneMouseEvent*))); - connect(this, SIGNAL(mouseMoved(QGraphicsSceneMouseEvent*)), rect, SLOT(slotMouseMoved(QGraphicsSceneMouseEvent*))); - connect(rect, SIGNAL(actionFinished()), this, SIGNAL(actionFinished())); - connect(rect, SIGNAL(setCursor(const QCursor &)), this, SLOT(slotSetCursor(const QCursor &))); - }*/ -} + QList selected = selectedItems(); -void MonitorScene::slotSetCursor(const QCursor &cursor) -{ - if (m_view) - m_view->setCursor(cursor); -} + QGraphicsScene::mousePressEvent(event); + if (selected.count() < selectedItems().count()) { + // mouse click on item not in selection group + // -> select only this item + foreach (QGraphicsItem *item, selected) { + if (item) + item->setSelected(false); + } + } -void MonitorScene::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - emit mousePressed(event); + if (event->isAccepted() && selectedItems().count() > 1) { + // multiple items selected + mouse pressed on an item + selected = selectedItems(); + foreach (QGraphicsItem *item, selected) { + if (qgraphicsitem_cast(item)) { + // works with rotoscoping only for now + m_groupMove = true; + m_lastPos = event->scenePos(); + return; + } + } + } - if (!event->isAccepted() && m_enabled) - QGraphicsScene::mousePressEvent(event); + if (!event->isAccepted() && event->buttons() & Qt::LeftButton) { + if (event->modifiers() == Qt::ControlModifier) + m_view->setDragMode(QGraphicsView::ScrollHandDrag); + else if (event->modifiers() == Qt::ShiftModifier) + m_view->setDragMode(QGraphicsView::RubberBandDrag); + } } void MonitorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - emit mouseMoved(event); - - if (!event->isAccepted() && m_enabled) + if (m_groupMove) { + // we want to move multiple items + // rotoscoping only for now + QPointF diff = event->scenePos() - m_lastPos; + if (diff != QPointF(0, 0)) { + m_lastPos = event->scenePos(); + QList selected = selectedItems(); + int first = -1; + int i = 0; + foreach (QGraphicsItem *item, selected) { + BPointItem *bpoint = qgraphicsitem_cast(item); + if (bpoint) { + if (first < 0) + first = i; + BPoint p = bpoint->getPoint(); + p.setP(p.p + diff); + bpoint->setPoint(p); + } + ++i; + } + + if (first >= 0) { + QGraphicsItem *item = selected.at(first); + if (item->parentItem()) { + SplineItem *parent = qgraphicsitem_cast(item->parentItem()); + if (parent) + parent->updateSpline(true); + } + } + } + } else { QGraphicsScene::mouseMoveEvent(event); + } } -void MonitorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void MonitorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) { - emit mouseReleased(event); - - if (!event->isAccepted() && m_enabled) - QGraphicsScene::mouseReleaseEvent(event); + if (m_groupMove) { + QList selected = selectedItems(); + foreach (QGraphicsItem *item, selected) { + if (qgraphicsitem_cast(item) && item->parentItem()) { + SplineItem *parent = qgraphicsitem_cast(item->parentItem()); + if (parent) { + parent->updateSpline(false); + break; + } + } + } + m_groupMove = false; + } + QGraphicsScene::mouseReleaseEvent(event); + m_view->setDragMode(QGraphicsView::NoDrag); } - void MonitorScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) { - Q_UNUSED(event); + Q_UNUSED(event) if (!m_enabled) emit addKeyframe(); } +void MonitorScene::wheelEvent(QGraphicsSceneWheelEvent* event) +{ + if (event->modifiers() == Qt::ControlModifier) { + if (event->delta() > 0) { + m_view->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + slotZoomIn(5); + m_view->setTransformationAnchor(QGraphicsView::AnchorViewCenter); + } else { + slotZoomOut(5); + } + } else { + QAbstractSlider::SliderAction action; + if (event->delta() > 0) + action = QAbstractSlider::SliderSingleStepSub; + else + action = QAbstractSlider::SliderSingleStepAdd; + if (event->orientation() == Qt::Horizontal) + m_view->horizontalScrollBar()->triggerAction(action); + else + m_view->verticalScrollBar()->triggerAction(action); + } + + event->accept(); +} #include "monitorscene.moc"