update();
}
-void ClipItem::moveTo(int x, double scale, double offset, int newTrack) {
- double origX = rect().x();
- double origY = rect().y();
- bool success = true;
- if (x < 0) return;
- setRect(x * scale, origY + offset, rect().width(), rect().height());
- QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
- if (collisionList.size() == 0) m_track = newTrack;
- for (int i = 0; i < collisionList.size(); ++i) {
- QGraphicsItem *item = collisionList.at(i);
- if (item->type() == 70000) {
- if (offset == 0) {
- QRectF other = ((QGraphicsRectItem *)item)->rect();
- if (x < m_startPos.frames(m_fps)) {
- kDebug() << "COLLISION, MOVING TO------";
- m_startPos = ((ClipItem *)item)->endPos() + GenTime(1, m_fps);
- origX = m_startPos.frames(m_fps) * scale;
- } else {
- kDebug() << "COLLISION, MOVING TO+++";
- m_startPos = ((ClipItem *)item)->startPos() - m_cropDuration;
- origX = m_startPos.frames(m_fps) * scale;
- }
- }
- setRect(origX, origY, rect().width(), rect().height());
- offset = 0;
- origX = rect().x();
- success = false;
- break;
- }
- }
- if (success) {
- m_track = newTrack;
- m_startPos = GenTime(x, m_fps);
- }
- /* QList <QGraphicsItem *> childrenList = QGraphicsItem::children();
- for (int i = 0; i < childrenList.size(); ++i) {
- childrenList.at(i)->moveBy(rect().x() - origX , offset);
- }*/
-}
-
void ClipItem::resizeStart(int posx, double scale) {
GenTime durationDiff = GenTime(posx, m_fps) - m_startPos;
if (durationDiff == GenTime()) return;
else if (m_operationMode == RESIZEEND)
m_startPos = QPointF(m_dragItem->endPos().frames(m_document->fps()), m_dragItem->track());
else if (m_operationMode == TRANSITIONSTART) {
- Transition *tr = new Transition(QRect(10 , 10, 20, 20), (ClipItem*)m_dragItem, LUMA_TRANSITION, m_dragItem->startPos(), m_dragItem->startPos() + GenTime(2.5), m_document->fps());
+ Transition *tr = new Transition(QRect(m_dragItem->rect().x() , m_dragItem->rect().height() / 2, (m_dragItem->startPos() + GenTime(2.5)).frames(25.0) , m_dragItem->rect().height()), (ClipItem*)m_dragItem, LUMA_TRANSITION, m_dragItem->startPos(), m_dragItem->startPos() + GenTime(2.5), m_document->fps());
scene()->addItem(tr);
//m_dragItem->addTransition(tra);
}
QList<QGraphicsItem *> itemList = items();
for (int i = 0; i < itemList.count(); i++) {
- if (itemList.at(i)->type() == 70000) {
- ClipItem *clip = (ClipItem *)itemList.at(i);
+ if (itemList.at(i)->type() == 70000 || itemList.at(i)->type() == 70001) {
+ AbstractClipItem *clip = (AbstractClipItem *)itemList.at(i);
clip->setRect(clip->startPos().frames(m_document->fps()) * m_scale, clip->rect().y(), clip->duration().frames(m_document->fps()) * m_scale, clip->rect().height());
}
}
#include <QBrush>
#include <qdom.h>
#include <QPainter>
+#include <QGraphicsScene>
+#include <QGraphicsView>
+#include <QScrollBar>
+#include <QStyleOptionGraphicsItem>
#include <kdebug.h>
#include <KIcon>
m_transitionType = type;
m_transitionName = getTransitionName(m_transitionType);
m_fps = fps;
- GenTime duration = endTime - startTime;
-
+ m_cropDuration = endTime - startTime;
+ m_startPos = startTime;
// Default duration = 2.5 seconds
GenTime defaultTransitionDuration = GenTime(2.5);
else if (startTime > m_referenceClip->endPos()) m_transitionStart = m_referenceClip->duration() - defaultTransitionDuration;
else m_transitionStart = startTime - m_referenceClip->startPos();
- if (m_transitionStart + duration > m_referenceClip->duration())
+ if (m_transitionStart + m_cropDuration > m_referenceClip->duration())
m_transitionDuration = m_referenceClip->duration() - m_transitionStart;
- else m_transitionDuration = duration;
+ else m_transitionDuration = m_cropDuration;
m_secondClip = 0;
setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
+ setZValue(2);
}
// create a transition from XML
void Transition::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget) {
- painter->fillRect(rect(), QBrush(Qt::green));
+ QRect rectInView;//this is the rect that is visible by the user
+ if (scene()->views().size() > 0) {
+ rectInView = scene()->views()[0]->viewport()->rect();
+ rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(), scene()->views()[0]->verticalScrollBar()->value());
+ rectInView.adjust(-10, -10, 10, 10);//make view rect 10 pixel greater on each site, or repaint after scroll event
+ //kDebug() << scene()->views()[0]->viewport()->rect() << " " << scene()->views()[0]->horizontalScrollBar()->value();
+ }
+ if (rectInView.isNull())
+ return;
+ QPainterPath clippath;
+ clippath.addRect(rectInView);
+ QRectF br = rect();
+ QPainterPath roundRectPathUpper, roundRectPathLower;
+ double roundingY = 20;
+ double roundingX = 20;
+ double offset = 1;
+ painter->setClipRect(option->exposedRect);
+ if (roundingX > br.width() / 2) roundingX = br.width() / 2;
+
+ int br_endx = (int)(br.x() + br .width() - offset);
+ int br_startx = (int)(br.x() + offset);
+ int br_starty = (int)(br.y());
+ int br_halfy = (int)(br.y() + br.height() / 2 - offset);
+ int br_endy = (int)(br.y() + br.height());
+
+
+ // build path around clip
+ roundRectPathUpper.moveTo(br_endx , br_halfy);
+ roundRectPathUpper.arcTo(br_endx - roundingX , br_starty , roundingX, roundingY, 0.0, 90.0);
+ roundRectPathUpper.lineTo(br_startx + roundingX , br_starty);
+ roundRectPathUpper.arcTo(br_startx , br_starty , roundingX, roundingY, 90.0, 90.0);
+ roundRectPathUpper.lineTo(br_startx, br_halfy);
+
+ roundRectPathLower.moveTo(br_startx , br_halfy);
+ roundRectPathLower.arcTo(br_startx , br_endy - roundingY , roundingX, roundingY, 180.0, 90.0);
+ roundRectPathLower.lineTo(br_endx - roundingX , br_endy);
+ roundRectPathLower.arcTo(br_endx - roundingX , br_endy - roundingY, roundingX, roundingY, 270.0, 90.0);
+ roundRectPathLower.lineTo(br_endx , br_halfy);
+
+ QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
+
+ painter->setClipPath(resultClipPath.intersected(clippath), Qt::IntersectClip);
+ //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
+ painter->fillRect(br.intersected(rectInView), QBrush(QColor(200, 200, 0, 160)));
+ painter->setClipRect(option->exposedRect);
+ painter->drawPath(resultClipPath.intersected(clippath));
}
int Transition::type() const {