#include "abstractclipitem.h"
#include "kdenlivesettings.h"
#include "customtrackscene.h"
+#include "customtrackview.h"
#include <KDebug>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
+#include <QDomDocument>
+#include <QMimeData>
AbstractGroupItem::AbstractGroupItem(double fps): QGraphicsItemGroup(), m_fps(fps) {
setZValue(2);
setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
+ setAcceptDrops(true);
}
int AbstractGroupItem::type() const {
}
}
+/*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));
+ 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
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());
+ int xpos = projectScene()->getSnapPointForPos((int)(start.x() + newPos.x() - scenePos().x() + 0.5), KdenliveSettings::snaptopoints());
+
xpos = qMax(xpos, 0);
- newPos.setX(xpos);
+ newPos.setX((int)(scenePos().x() + xpos - (int) start.x()));
- QPointF start = pos();
//int startTrack = (start.y() + trackHeight / 2) / trackHeight;
- int newTrack = (newPos.y()) / trackHeight;
- //kDebug()<<"// GROUP NEW T:"<<newTrack<<",START T:"<<startTrack<<",MAX:"<<projectScene()->tracksCount() - 1;
+
+ int newTrack = (start.y() + newPos.y() - scenePos().y()) / trackHeight;
+ int currTrack = start.y() / trackHeight;
+ int currTrack2 = newPos.y() / trackHeight;
+
newTrack = qMin(newTrack, projectScene()->tracksCount() - (int)(boundingRect().height() + 5) / trackHeight);
newTrack = qMax(newTrack, 0);
}
}
}
- newPos.setY((int)((newTrack) * trackHeight) + offset);
- if (newPos == start) return start;
+ newPos.setY((int)((currTrack2) * 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<QGraphicsItem*> 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;
for (int i = 0; i < collindingItems.count(); i++) {
QGraphicsItem *collision = collindingItems.at(i);
if (collision->type() == AVWIDGET) {
// Collision
//kDebug()<<"// COLLISION WIT:"<<collision->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 <AbstractClipItem *>(collision);
if (forwardMove) {
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);
+}