X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fabstractgroupitem.cpp;h=f49e84d83568442b06c950906d268da461399b3b;hb=348036fe138e676772b9f035334632b41694d786;hp=f605218d144d2902b9760a4bdecf633f914aef23;hpb=cd85961a9520f2f3c909e889dacd8de539468b89;p=kdenlive diff --git a/src/abstractgroupitem.cpp b/src/abstractgroupitem.cpp index f605218d..f49e84d8 100644 --- a/src/abstractgroupitem.cpp +++ b/src/abstractgroupitem.cpp @@ -22,32 +22,43 @@ #include "abstractclipitem.h" #include "kdenlivesettings.h" #include "customtrackscene.h" +#include "customtrackview.h" #include #include #include - - -AbstractGroupItem::AbstractGroupItem(double fps): QGraphicsItemGroup(), m_fps(fps) { - setZValue(2); +#include +#include +#include + +AbstractGroupItem::AbstractGroupItem(double /* fps */) : + QObject(), + QGraphicsItemGroup() +{ + setZValue(1); setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + setAcceptDrops(true); } -int AbstractGroupItem::type() const { +int AbstractGroupItem::type() const +{ return GROUPWIDGET; } -const int AbstractGroupItem::track() const { +int AbstractGroupItem::track() const +{ return (int)(scenePos().y() / KdenliveSettings::trackheight()); } -CustomTrackScene* AbstractGroupItem::projectScene() { +CustomTrackScene* AbstractGroupItem::projectScene() +{ if (scene()) return static_cast (scene()); return NULL; } -QPainterPath AbstractGroupItem::groupShape(QPointF offset) { +QPainterPath AbstractGroupItem::groupShape(QPointF offset) +{ QPainterPath path; QList children = childItems(); for (int i = 0; i < children.count(); i++) { @@ -60,12 +71,14 @@ QPainterPath AbstractGroupItem::groupShape(QPointF offset) { return path; } -void AbstractGroupItem::addItem(QGraphicsItem * item) { +void AbstractGroupItem::addItem(QGraphicsItem * item) +{ addToGroup(item); //fixItemRect(); } -void AbstractGroupItem::fixItemRect() { +void AbstractGroupItem::fixItemRect() +{ QPointF start = boundingRect().topLeft(); if (start != QPointF(0, 0)) { translate(0 - start.x(), 0 - start.y()); @@ -73,27 +86,52 @@ void AbstractGroupItem::fixItemRect() { } } +/*ItemInfo AbstractGroupItem::info() const { + ItemInfo itemInfo; + itemInfo.startPos = m_startPos; + itemInfo.track = m_track; + return itemInfo; +}*/ + // virtual -void AbstractGroupItem::paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *) { - p->fillRect(option->exposedRect, QColor(200, 100, 100, 100)); +void AbstractGroupItem::paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *) +{ + const double scale = option->matrix.m11(); + QRect clipRect = option->exposedRect.toRect(); + clipRect.adjust(0, 0, 1 / scale + 0.5, 1); + p->fillRect(option->exposedRect, QColor(100, 100, 200, 100)); + p->setClipRect(clipRect); + QPen pen = p->pen(); + pen.setColor(QColor(200, 90, 90)); + pen.setStyle(Qt::DashLine); + p->setPen(pen); + p->drawRect(boundingRect()); } //virtual -QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant &value) { +QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant &value) +{ if (change == ItemPositionChange && scene()) { // calculate new position. const int trackHeight = KdenliveSettings::trackheight(); + QPointF start = sceneBoundingRect().topLeft(); QPointF newPos = value.toPointF(); - int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints()); + //kDebug()<<"REAL:"<getSnapPointForPos((int)(start.x() + newPos.x() - pos().x()), KdenliveSettings::snaptopoints()); + xpos = qMax(xpos, 0); - newPos.setX(xpos); + //kDebug()<<"GRP XPOS:"<tracksCount() - 1; - newTrack = qMin(newTrack, projectScene()->tracksCount() - (int)(boundingRect().height() + 5) / trackHeight); - newTrack = qMax(newTrack, 0); + int realTrack = (start.y() + newPos.y() - pos().y()) / trackHeight; + int proposedTrack = newPos.y() / trackHeight; + + int correctedTrack = qMin(realTrack, projectScene()->tracksCount() - (int)(boundingRect().height() + 5) / trackHeight); + correctedTrack = qMax(correctedTrack, 0); + + proposedTrack += (correctedTrack - realTrack); // Check if top item is a clip or a transition int offset = 0; @@ -113,32 +151,31 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant } } } - newPos.setY((int)((newTrack) * trackHeight) + offset); - if (newPos == start) return start; + newPos.setY((int)((proposedTrack) * trackHeight) + offset); + //if (newPos == start) return start; - if (newPos.x() < 0) { + /*if (newPos.x() < 0) { // If group goes below 0, adjust position to 0 return QPointF(pos().x() - start.x(), pos().y()); - } - + }*/ QPainterPath shape = groupShape(newPos - pos()); QList collindingItems = scene()->items(shape, Qt::IntersectsItemShape); for (int i = 0; i < children.count(); i++) { collindingItems.removeAll(children.at(i)); } + if (collindingItems.isEmpty()) return newPos; else { - bool forwardMove = newPos.x() > start.x(); + bool forwardMove = xpos > start.x(); int offset = 0; - const double width = sceneBoundingRect().width() + 1; for (int i = 0; i < collindingItems.count(); i++) { QGraphicsItem *collision = collindingItems.at(i); if (collision->type() == AVWIDGET) { // Collision //kDebug()<<"// COLLISION WIT:"<sceneBoundingRect(); - if (newPos.y() != start.y()) { + if (newPos.y() != pos().y()) { // Track change results in collision, restore original position - return start; + return pos(); } AbstractClipItem *item = static_cast (collision); if (forwardMove) { @@ -176,3 +213,33 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant return QGraphicsItemGroup::itemChange(change, value); } +//virtual +void AbstractGroupItem::dropEvent(QGraphicsSceneDragDropEvent * event) +{ + QString effects = QString(event->mimeData()->data("kdenlive/effectslist")); + QDomDocument doc; + doc.setContent(effects, true); + QDomElement e = doc.documentElement(); + CustomTrackView *view = (CustomTrackView *) scene()->views()[0]; + if (view) view->slotAddGroupEffect(e, this); +} + +//virtual +void AbstractGroupItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) +{ + event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist")); +} + +void AbstractGroupItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) +{ + Q_UNUSED(event); +} + +// virtual +void AbstractGroupItem::mousePressEvent(QGraphicsSceneMouseEvent * event) +{ + if (event->modifiers() & Qt::ShiftModifier) { + // User want to do a rectangle selection, so ignore the event to pass it to the view + event->ignore(); + } else QGraphicsItem::mousePressEvent(event); +}