1 #include "abstractclipitem.h"
3 #include <QGraphicsScene>
4 #include <QGraphicsView>
7 AbstractClipItem::AbstractClipItem(const QRectF& rect): QGraphicsRectItem(rect), m_startFade(0), m_endFade(0) {
8 setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
10 void AbstractClipItem::moveTo(int x, double scale, int offset, int newTrack) {
11 double origX = rect().x();
12 double origY = rect().y();
15 setRect(x * scale, origY + offset, rect().width(), rect().height());
16 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
17 if (collisionList.size() == 0) m_track = newTrack;
18 for (int i = 0; i < collisionList.size(); ++i) {
19 QGraphicsItem *item = collisionList.at(i);
20 if (item->type() == type()) {
22 QRectF other = ((QGraphicsRectItem *)item)->rect();
23 if (x < m_startPos.frames(m_fps)) {
24 kDebug() << "COLLISION, MOVING TO------";
25 m_startPos = ((AbstractClipItem *)item)->endPos() + GenTime(1, m_fps);
26 origX = m_startPos.frames(m_fps) * scale;
28 kDebug() << "COLLISION, MOVING TO+++";
29 m_startPos = ((AbstractClipItem *)item)->startPos() - m_cropDuration;
30 origX = m_startPos.frames(m_fps) * scale;
33 setRect(origX, origY, rect().width(), rect().height());
42 m_startPos = GenTime(x, m_fps);
44 /* QList <QGraphicsItem *> childrenList = QGraphicsItem::children();
45 for (int i = 0; i < childrenList.size(); ++i) {
46 childrenList.at(i)->moveBy(rect().x() - origX , offset);
50 GenTime AbstractClipItem::endPos() const {
51 return m_startPos + m_cropDuration;
54 int AbstractClipItem::track() const {
58 GenTime AbstractClipItem::cropStart() const {
62 void AbstractClipItem::resizeStart(int posx, double scale) {
63 GenTime durationDiff = GenTime(posx, m_fps) - m_startPos;
64 if (durationDiff == GenTime()) return;
65 //kDebug() << "-- RESCALE: CROP=" << m_cropStart << ", DIFF = " << durationDiff;
67 if (m_cropStart + durationDiff < GenTime() && type() == AVWIDGET) {
68 durationDiff = GenTime() - m_cropStart;
69 } else if (durationDiff >= m_cropDuration) {
70 durationDiff = m_cropDuration - GenTime(3, m_fps);
73 m_startPos += durationDiff;
74 m_cropStart += durationDiff;
75 m_cropDuration = m_cropDuration - durationDiff;
76 setRect(m_startPos.frames(m_fps) * scale, rect().y(), m_cropDuration.frames(m_fps) * scale, rect().height());
77 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
78 for (int i = 0; i < collisionList.size(); ++i) {
79 QGraphicsItem *item = collisionList.at(i);
80 if (item->type() == type()) {
81 GenTime diff = ((AbstractClipItem *)item)->endPos() + GenTime(1, m_fps) - m_startPos;
82 setRect((m_startPos + diff).frames(m_fps) * scale, rect().y(), (m_cropDuration - diff).frames(m_fps) * scale, rect().height());
85 m_cropDuration = m_cropDuration - diff;
91 void AbstractClipItem::resizeEnd(int posx, double scale) {
92 GenTime durationDiff = GenTime(posx, m_fps) - endPos();
93 if (durationDiff == GenTime()) return;
94 //kDebug() << "-- RESCALE: CROP=" << m_cropStart << ", DIFF = " << durationDiff;
95 if (m_cropDuration + durationDiff <= GenTime()) {
96 durationDiff = GenTime() - (m_cropDuration - GenTime(3, m_fps));
97 } else if (m_cropStart + m_cropDuration + durationDiff >= m_maxDuration) {
98 durationDiff = m_maxDuration - m_cropDuration - m_cropStart;
100 m_cropDuration += durationDiff;
101 setRect(m_startPos.frames(m_fps) * scale, rect().y(), m_cropDuration.frames(m_fps) * scale, rect().height());
102 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
103 for (int i = 0; i < collisionList.size(); ++i) {
104 QGraphicsItem *item = collisionList.at(i);
105 if (item->type() == type()) {
106 GenTime diff = ((AbstractClipItem *)item)->startPos() - GenTime(1, m_fps) - startPos();
107 m_cropDuration = diff;
108 setRect(m_startPos.frames(m_fps) * scale, rect().y(), m_cropDuration.frames(m_fps) * scale, rect().height());
114 void AbstractClipItem::setFadeOut(int pos, double scale) {
118 void AbstractClipItem::setFadeIn(int pos, double scale) {
122 GenTime AbstractClipItem::duration() const {
123 return m_cropDuration;
126 GenTime AbstractClipItem::startPos() const {
130 void AbstractClipItem::setTrack(int track) {
134 double AbstractClipItem::fps() const {
138 int AbstractClipItem::fadeIn() const {
142 int AbstractClipItem::fadeOut() const {
146 GenTime AbstractClipItem::maxDuration() const {
147 return m_maxDuration;
150 QPainterPath AbstractClipItem::upperRectPart(QRectF br) {
151 QPainterPath roundRectPathUpper;
152 double roundingY = 20;
153 double roundingX = 20;
156 while (roundingX > br.width() / 2) {
157 roundingX = roundingX / 2;
158 roundingY = roundingY / 2;
160 int br_endx = (int)(br.x() + br .width() - offset);
161 int br_startx = (int)(br.x() + offset);
162 int br_starty = (int)(br.y());
163 int br_halfy = (int)(br.y() + br.height() / 2 - offset);
164 int br_endy = (int)(br.y() + br.height());
166 roundRectPathUpper.moveTo(br_endx , br_halfy);
167 roundRectPathUpper.arcTo(br_endx - roundingX , br_starty , roundingX, roundingY, 0.0, 90.0);
168 roundRectPathUpper.lineTo(br_startx + roundingX , br_starty);
169 roundRectPathUpper.arcTo(br_startx , br_starty , roundingX, roundingY, 90.0, 90.0);
170 roundRectPathUpper.lineTo(br_startx , br_halfy);
172 return roundRectPathUpper;
175 QPainterPath AbstractClipItem::lowerRectPart(QRectF br) {
176 QPainterPath roundRectPathLower;
177 double roundingY = 20;
178 double roundingX = 20;
181 int br_endx = (int)(br.x() + br .width() - offset);
182 int br_startx = (int)(br.x() + offset);
183 int br_starty = (int)(br.y());
184 int br_halfy = (int)(br.y() + br.height() / 2 - offset);
185 int br_endy = (int)(br.y() + br.height() - 1);
187 while (roundingX > br.width() / 2) {
188 roundingX = roundingX / 2;
189 roundingY = roundingY / 2;
191 roundRectPathLower.moveTo(br_startx, br_halfy);
192 roundRectPathLower.arcTo(br_startx , br_endy - roundingY , roundingX, roundingY, 180.0, 90.0);
193 roundRectPathLower.lineTo(br_endx - roundingX , br_endy);
194 roundRectPathLower.arcTo(br_endx - roundingX , br_endy - roundingY, roundingX, roundingY, 270.0, 90.0);
195 roundRectPathLower.lineTo(br_endx , br_halfy);
196 return roundRectPathLower;
199 QRect AbstractClipItem::visibleRect() {
201 if (scene()->views().size() > 0) {
202 rectInView = scene()->views()[0]->viewport()->rect();
203 rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(), scene()->views()[0]->verticalScrollBar()->value());
204 rectInView.adjust(-10, -10, 10, 10);//make view rect 10 pixel greater on each site, or repaint after scroll event
205 //kDebug() << scene()->views()[0]->viewport()->rect() << " " << scene()->views()[0]->horizontalScrollBar()->value();