]> git.sesse.net Git - kdenlive/blobdiff - src/abstractgroupitem.cpp
Cleanup audio thumbnails thread handling
[kdenlive] / src / abstractgroupitem.cpp
index c7e0b88cf0d58ce80e244c05026742b3510bf1be..ee0d69f4a1cd2e5a3cfa2da19ec97d76f3c75af9 100644 (file)
 #include <QMimeData>
 
 
-AbstractGroupItem::AbstractGroupItem(double fps): QGraphicsItemGroup(), m_fps(fps) {
+AbstractGroupItem::AbstractGroupItem(double fps) :
+        QObject(),
+        QGraphicsItemGroup(),
+        m_fps(fps)
+{
     setZValue(2);
     setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
     setAcceptDrops(true);
 }
 
-int AbstractGroupItem::type() const {
+int AbstractGroupItem::type() const
+{
     return GROUPWIDGET;
 }
 
-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 <CustomTrackScene*>(scene());
     return NULL;
 }
 
-QPainterPath AbstractGroupItem::groupShape(QPointF offset) {
+QPainterPath AbstractGroupItem::groupShape(QPointF offset)
+{
     QPainterPath path;
     QList<QGraphicsItem *> children = childItems();
     for (int i = 0; i < children.count(); i++) {
@@ -64,12 +72,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());
@@ -85,7 +95,8 @@ void AbstractGroupItem::fixItemRect() {
 }*/
 
 // virtual
-void AbstractGroupItem::paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *) {
+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);
@@ -99,25 +110,29 @@ void AbstractGroupItem::paint(QPainter *p, const QStyleOptionGraphicsItem *optio
 }
 
 //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)(start.x() + newPos.x() - scenePos().x() + 0.5), KdenliveSettings::snaptopoints());
+        //kDebug()<<"REAL:"<<start.x()<<", PROPOSED:"<<(int)(start.x() - pos().x() + newPos.x());
+        int xpos = projectScene()->getSnapPointForPos((int)(start.x() + newPos.x() - pos().x()), KdenliveSettings::snaptopoints());
 
         xpos = qMax(xpos, 0);
-        newPos.setX((int)(scenePos().x() + xpos - (int) start.x()));
+        //kDebug()<<"GRP XPOS:"<<xpos<<", START:"<<start.x()<<",NEW:"<<newPos.x()<<"; SCENE:"<<scenePos().x()<<",POS:"<<pos().x();
+        newPos.setX((int)(pos().x() + xpos - (int) start.x()));
 
         //int startTrack = (start.y() + trackHeight / 2) / trackHeight;
 
-        int newTrack = (start.y() + newPos.y() - scenePos().y()) / trackHeight;
-        int currTrack = start.y() / trackHeight;
-        int currTrack2 = newPos.y() / trackHeight;
+        int realTrack = (start.y() + newPos.y() - pos().y()) / trackHeight;
+        int proposedTrack = newPos.y() / trackHeight;
 
-        newTrack = qMin(newTrack, projectScene()->tracksCount() - (int)(boundingRect().height() + 5) / trackHeight);
-        newTrack = qMax(newTrack, 0);
+        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;
@@ -137,7 +152,7 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant
                 }
             }
         }
-        newPos.setY((int)((currTrack2) * trackHeight) + offset);
+        newPos.setY((int)((proposedTrack) * trackHeight) + offset);
         //if (newPos == start) return start;
 
         /*if (newPos.x() < 0) {
@@ -200,7 +215,8 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant
 }
 
 //virtual
-void AbstractGroupItem::dropEvent(QGraphicsSceneDragDropEvent * event) {
+void AbstractGroupItem::dropEvent(QGraphicsSceneDragDropEvent * event)
+{
     QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
     QDomDocument doc;
     doc.setContent(effects, true);
@@ -210,10 +226,12 @@ void AbstractGroupItem::dropEvent(QGraphicsSceneDragDropEvent * event) {
 }
 
 //virtual
-void AbstractGroupItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
+void AbstractGroupItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
+{
     event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
 }
 
-void AbstractGroupItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
+void AbstractGroupItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
+{
     Q_UNUSED(event);
 }