]> git.sesse.net Git - kdenlive/blobdiff - src/clipitem.cpp
Fix wrong usage of QDomElement, which will help with bug:
[kdenlive] / src / clipitem.cpp
index d22f3b75664f7798c28fc0715a9ba50eb58bf183..773a810ab504216c929f683e40f0587b66a49d43 100644 (file)
@@ -28,6 +28,7 @@
 #include "kthumb.h"
 
 #include <KDebug>
+#include <KIcon>
 
 #include <QPainter>
 #include <QTimer>
 #include <QGraphicsScene>
 #include <QMimeData>
 
-
 ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, bool generateThumbs)
-        : AbstractClipItem(info, QRectF(), fps), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), audioThumbWasDrawn(false), m_opacity(1.0), m_timeLine(0), m_startThumbRequested(false), m_endThumbRequested(false), m_startFade(0), m_endFade(0), m_hover(false), m_selectedEffect(-1), m_speed(speed), framePixelWidth(0), m_startPix(QPixmap()), m_endPix(QPixmap()) {
+        : AbstractClipItem(info, QRectF(), fps), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), audioThumbWasDrawn(false), m_opacity(1.0), m_timeLine(0), m_startThumbRequested(false), m_endThumbRequested(false), m_startFade(0), m_endFade(0), m_hover(false), m_selectedEffect(-1), m_speed(speed), framePixelWidth(0), m_startPix(QPixmap()), m_endPix(QPixmap()), m_videoOnly(false), m_audioOnly(false)  {
     setZValue(1);
     setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (double)(KdenliveSettings::trackheight() - 2));
     setPos(info.startPos.frames(fps), (double)(info.track * KdenliveSettings::trackheight()) + 1);
 
+    m_videoPix = KIcon("video-x-generic").pixmap(QSize(15, 15));
+    m_audioPix = KIcon("audio-x-generic").pixmap(QSize(15, 15));
+
     if (m_speed == 1.0) m_clipName = clip->name();
     else {
         m_clipName = clip->name() + " - " + QString::number(m_speed * 100, 'f', 0) + '%';
@@ -104,7 +107,7 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, b
 ClipItem::~ClipItem() {
     if (startThumbTimer) delete startThumbTimer;
     if (endThumbTimer) delete endThumbTimer;
-    if (m_timeLine) m_timeLine;
+    if (m_timeLine) delete m_timeLine;
 }
 
 ClipItem *ClipItem::clone(ItemInfo info) const {
@@ -516,7 +519,7 @@ void ClipItem::flashClip() {
     m_timeLine->start();
 }
 
-void ClipItem::animate(qreal value) {
+void ClipItem::animate(qreal /*value*/) {
     QRectF r = boundingRect();
     r.setHeight(20);
     update(r);
@@ -529,8 +532,10 @@ void ClipItem::paint(QPainter *painter,
     /*if (parentItem()) m_opacity = 0.5;
     else m_opacity = 1.0;
     painter->setOpacity(m_opacity);*/
-    QBrush paintColor = brush();
-    if (isSelected()) paintColor = QBrush(QColor(79, 93, 121));
+    QBrush paintColor;
+    if (parentItem()) paintColor = QBrush(QColor(255, 248, 149));
+    else paintColor = brush();
+    if (isSelected() || parentItem() && parentItem()->isSelected()) paintColor = QBrush(paintColor.color().darker());
     QRectF br = rect();
     QRectF exposed = option->exposedRect;
     QRectF mapped = painter->matrix().mapRect(br);
@@ -712,10 +717,16 @@ void ClipItem::paint(QPainter *painter,
     }
 
     // Draw clip name
+
     QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignHCenter | Qt::AlignVCenter, ' ' + m_clipName + ' ');
     painter->fillRect(txtBounding, QBrush(QColor(0, 0, 0, 150)));
     //painter->setPen(QColor(0, 0, 0, 180));
     //painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
+    if (m_videoOnly) {
+        painter->drawPixmap(txtBounding.topLeft() - QPointF(17, -1), m_videoPix);
+    } else if (m_audioOnly) {
+        painter->drawPixmap(txtBounding.topLeft() - QPointF(17, -1), m_audioPix);
+    }
     txtBounding.translate(QPointF(1, 1));
     painter->setPen(QColor(255, 255, 255, 255));
     painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
@@ -731,12 +742,10 @@ void ClipItem::paint(QPainter *painter,
 
 
     // draw frame around clip
-    if (isSelected()) {
+    if (isSelected() || parentItem() && parentItem()->isSelected()) {
         pen.setColor(Qt::red);
-        //pen.setWidth(2);
     } else {
         pen.setColor(Qt::black);
-        //pen.setWidth(1);
     }
 
     // draw effect or transition keyframes
@@ -745,9 +754,6 @@ void ClipItem::paint(QPainter *painter,
     painter->setMatrixEnabled(true);
 
     // draw clip border
-
-    //kDebug()<<"/// ITEM PAINTING:: exposed="<<exposed<<", RECT = "<<rect();
-
     // expand clip rect to allow correct painting of clip border
     exposed.setRight(exposed.right() + 1 / scale + 0.5);
     exposed.setBottom(exposed.bottom() + 1);
@@ -956,7 +962,7 @@ void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
 }
 
 //virtual
-void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e) {
+void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent */*e*/) {
     //if (e->pos().x() < 20) m_hover = true;
     if (isItemLocked()) return;
     m_hover = true;
@@ -980,7 +986,7 @@ void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
     update(r.right() - width, r.y() + height, width, height);
 }
 
-void ClipItem::resizeStart(int posx, double speed) {
+void ClipItem::resizeStart(int posx, double /*speed*/) {
     const int min = (startPos() - cropStart()).frames(m_fps);
     if (posx < min) posx = min;
     if (posx == startPos().frames(m_fps)) return;
@@ -995,7 +1001,7 @@ void ClipItem::resizeStart(int posx, double speed) {
     }
 }
 
-void ClipItem::resizeEnd(int posx, double speed, bool updateKeyFrames) {
+void ClipItem::resizeEnd(int posx, double /*speed*/, bool updateKeyFrames) {
     const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps) + 1;
     if (posx > max) posx = max;
     if (posx == endPos().frames(m_fps)) return;
@@ -1051,7 +1057,7 @@ void ClipItem::checkEffectsKeyframesPos(const int previous, const int current, b
 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value) {
     if (change == ItemPositionChange && scene()) {
         // calculate new position.
-        if (parentItem()) return pos();
+        //if (parentItem()) return pos();
         QPointF newPos = value.toPointF();
         //kDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++";
         int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
@@ -1382,13 +1388,32 @@ void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
     Q_UNUSED(event);
 }
+
 void ClipItem::addTransition(Transition* t) {
     m_transitionsList.append(t);
-    CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
+    //CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
     QDomDocument doc;
     QDomElement e = doc.documentElement();
     //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
 }
+
+void ClipItem::setVideoOnly(bool force) {
+    m_videoOnly = force;
+}
+
+void ClipItem::setAudioOnly(bool force) {
+    m_audioOnly = force;
+}
+
+bool ClipItem::isAudioOnly() const {
+    return m_audioOnly;
+}
+
+bool ClipItem::isVideoOnly() const {
+    return m_videoOnly;
+}
+
+
 // virtual
 /*
 void CustomTrackView::mousePressEvent ( QMouseEvent * event )