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, double offset, int newTrack) {
11 double origX = rect().x();
12 double origY = rect().y();
16 setRect(x * scale, origY + offset, rect().width(), rect().height());
17 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
18 if (collisionList.size() == 0) m_track = newTrack;
19 for (int i = 0; i < collisionList.size(); ++i) {
20 QGraphicsItem *item = collisionList.at(i);
21 if (item->type() == type()) {
23 QRectF other = ((QGraphicsRectItem *)item)->rect();
24 if (x < m_startPos.frames(m_fps)) {
25 kDebug() << "COLLISION, MOVING TO------";
26 m_startPos = ((AbstractClipItem *)item)->endPos() + GenTime(1, m_fps);
27 origX = m_startPos.frames(m_fps) * scale;
29 kDebug() << "COLLISION, MOVING TO+++";
30 m_startPos = ((AbstractClipItem *)item)->startPos() - m_cropDuration;
31 origX = m_startPos.frames(m_fps) * scale;
34 setRect(origX, origY, rect().width(), rect().height());
43 m_startPos = GenTime(x, m_fps);
45 /* QList <QGraphicsItem *> childrenList = QGraphicsItem::children();
46 for (int i = 0; i < childrenList.size(); ++i) {
47 childrenList.at(i)->moveBy(rect().x() - origX , offset);
51 GenTime AbstractClipItem::endPos() const {
52 return m_startPos + m_cropDuration;
55 int AbstractClipItem::track() const {
59 GenTime AbstractClipItem::cropStart() const {
63 void AbstractClipItem::resizeStart(int posx, double scale) {
64 GenTime durationDiff = GenTime(posx, m_fps) - m_startPos;
65 if (durationDiff == GenTime()) return;
66 //kDebug() << "-- RESCALE: CROP=" << m_cropStart << ", DIFF = " << durationDiff;
68 if (m_cropStart + durationDiff < GenTime() && type() == AVWIDGET) {
69 durationDiff = GenTime() - m_cropStart;
70 } else if (durationDiff >= m_cropDuration) {
71 durationDiff = m_cropDuration - GenTime(3, m_fps);
74 m_startPos += durationDiff;
75 m_cropStart += durationDiff;
76 m_cropDuration = m_cropDuration - durationDiff;
77 setRect(m_startPos.frames(m_fps) * scale, rect().y(), m_cropDuration.frames(m_fps) * scale, rect().height());
78 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
79 for (int i = 0; i < collisionList.size(); ++i) {
80 QGraphicsItem *item = collisionList.at(i);
81 if (item->type() == type()) {
82 GenTime diff = ((AbstractClipItem *)item)->endPos() + GenTime(1, m_fps) - m_startPos;
83 setRect((m_startPos + diff).frames(m_fps) * scale, rect().y(), (m_cropDuration - diff).frames(m_fps) * scale, rect().height());
86 m_cropDuration = m_cropDuration - diff;
92 void AbstractClipItem::resizeEnd(int posx, double scale) {
93 GenTime durationDiff = GenTime(posx, m_fps) - endPos();
94 if (durationDiff == GenTime()) return;
95 //kDebug() << "-- RESCALE: CROP=" << m_cropStart << ", DIFF = " << durationDiff;
96 if (m_cropDuration + durationDiff <= GenTime()) {
97 durationDiff = GenTime() - (m_cropDuration - GenTime(3, m_fps));
98 } else if (m_cropStart + m_cropDuration + durationDiff >= m_maxDuration) {
99 durationDiff = m_maxDuration - m_cropDuration - m_cropStart;
101 m_cropDuration += durationDiff;
102 setRect(m_startPos.frames(m_fps) * scale, rect().y(), m_cropDuration.frames(m_fps) * scale, rect().height());
103 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
104 for (int i = 0; i < collisionList.size(); ++i) {
105 QGraphicsItem *item = collisionList.at(i);
106 if (item->type() == type()) {
107 GenTime diff = ((AbstractClipItem *)item)->startPos() - GenTime(1, m_fps) - startPos();
108 m_cropDuration = diff;
109 setRect(m_startPos.frames(m_fps) * scale, rect().y(), m_cropDuration.frames(m_fps) * scale, rect().height());
115 void AbstractClipItem::setFadeOut(int pos, double scale) {
119 void AbstractClipItem::setFadeIn(int pos, double scale) {
123 GenTime AbstractClipItem::duration() const {
124 return m_cropDuration;
127 GenTime AbstractClipItem::startPos() const {
131 void AbstractClipItem::setTrack(int track) {
135 double AbstractClipItem::fps() const {
139 int AbstractClipItem::fadeIn() const {
143 int AbstractClipItem::fadeOut() const {
147 GenTime AbstractClipItem::maxDuration() const {
148 return m_maxDuration;
151 QPainterPath AbstractClipItem::upperRectPart(QRectF br) {
152 QPainterPath roundRectPathUpper;
153 double roundingY = 20;
154 double roundingX = 20;
157 while (roundingX > br.width() / 2) {
158 roundingX = roundingX / 2;
159 roundingY = roundingY / 2;
161 int br_endx = (int)(br.x() + br .width() - offset);
162 int br_startx = (int)(br.x() + offset);
163 int br_starty = (int)(br.y());
164 int br_halfy = (int)(br.y() + br.height() / 2 - offset);
165 int br_endy = (int)(br.y() + br.height());
167 roundRectPathUpper.moveTo(br_endx , br_halfy);
168 roundRectPathUpper.arcTo(br_endx - roundingX , br_starty , roundingX, roundingY, 0.0, 90.0);
169 roundRectPathUpper.lineTo(br_startx + roundingX , br_starty);
170 roundRectPathUpper.arcTo(br_startx , br_starty , roundingX, roundingY, 90.0, 90.0);
171 roundRectPathUpper.lineTo(br_startx , br_halfy);
173 return roundRectPathUpper;
176 QPainterPath AbstractClipItem::lowerRectPart(QRectF br) {
177 QPainterPath roundRectPathLower;
178 double roundingY = 20;
179 double roundingX = 20;
182 int br_endx = (int)(br.x() + br .width() - offset);
183 int br_startx = (int)(br.x() + offset);
184 int br_starty = (int)(br.y());
185 int br_halfy = (int)(br.y() + br.height() / 2 - offset);
186 int br_endy = (int)(br.y() + br.height() - 1);
188 while (roundingX > br.width() / 2) {
189 roundingX = roundingX / 2;
190 roundingY = roundingY / 2;
192 roundRectPathLower.moveTo(br_startx, br_halfy);
193 roundRectPathLower.arcTo(br_startx , br_endy - roundingY , roundingX, roundingY, 180.0, 90.0);
194 roundRectPathLower.lineTo(br_endx - roundingX , br_endy);
195 roundRectPathLower.arcTo(br_endx - roundingX , br_endy - roundingY, roundingX, roundingY, 270.0, 90.0);
196 roundRectPathLower.lineTo(br_endx , br_halfy);
197 return roundRectPathLower;
200 QRect AbstractClipItem::visibleRect() {
202 if (scene()->views().size() > 0) {
203 rectInView = scene()->views()[0]->viewport()->rect();
204 rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(), scene()->views()[0]->verticalScrollBar()->value());
205 rectInView.adjust(-10, -10, 10, 10);//make view rect 10 pixel greater on each site, or repaint after scroll event
206 //kDebug() << scene()->views()[0]->viewport()->rect() << " " << scene()->views()[0]->horizontalScrollBar()->value();