Rewrote the handling of timeline in QGraphicsView. Now we use the built in...

Rewrote the handling of timeline in QGraphicsView. Now we use the built in zoom feature instead of a hack. Also let the view handle item move. Improves speed and stability, but broke a few things: audio thumbs and clip group action broken, probably some other minor issues. I also decided to drop the rounded clips for square ones for the moment.

svn path=/branches/KDE4/; revision=2380
parent 0cbb0774
......@@ -130,6 +130,8 @@ set(kdenlive_SRCS
changespeedcommand.cpp
geometryval.cpp
wizard.cpp
customtrackscene.cpp
abstractgroupitem.cpp
)
kde4_add_kcfg_files(kdenlive_SRCS GENERATE_MOC kdenlivesettings.kcfgc )
......
......@@ -27,9 +27,10 @@
#include <KLocale>
#include "abstractclipitem.h"
#include "customtrackscene.h"
AbstractClipItem::AbstractClipItem(const ItemInfo info, const QRectF& rect, double fps): QGraphicsRectItem(rect), m_track(0), m_fps(fps), m_editedKeyframe(-1), m_selectedKeyframe(0), m_keyframeFactor(1) {
setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
setFlags(/*QGraphicsItem::ItemClipsToShape | */QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
setTrack(info.track);
m_startPos = info.startPos;
m_cropDuration = info.endPos - info.startPos;
......@@ -44,45 +45,6 @@ ItemInfo AbstractClipItem::info() const {
return itemInfo;
}
void AbstractClipItem::moveTo(int x, double scale, int offset, int newTrack, bool checkCollision) {
qreal origX = pos().x();
qreal origY = pos().y();
bool success = true;
if (x < 0) return;
//setRect(x * scale, origY + offset, rect().width(), rect().height());
//double xoffset = (x - m_startPos.frames(m_fps)) * scale;// - origX;
setPos((qreal) x * scale, (qreal) pos().y() + offset);
QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
if (collisionList.size() == 0) m_track = newTrack;
if (checkCollision)
for (int i = 0; i < collisionList.size(); ++i) {
QGraphicsItem *item = collisionList.at(i);
if (item->type() == type()) {
if (offset == 0) {
QRectF other = ((QGraphicsRectItem *)item)->rect();
if (x < m_startPos.frames(m_fps)) {
kDebug() << "COLLISION, MOVING TO------";
m_startPos = ((AbstractClipItem *)item)->endPos();
origX = (qreal) m_startPos.frames(m_fps) * scale;
} else if (x > m_startPos.frames(m_fps)) {
//kDebug() << "COLLISION, MOVING TO+++: "<<x<<", CLIP CURR POS: "<<m_startPos.frames(m_fps)<<", COLLIDING START: "<<((AbstractClipItem *)item)->startPos().frames(m_fps);
m_startPos = ((AbstractClipItem *)item)->startPos() - m_cropDuration;
origX = (qreal) m_startPos.frames(m_fps) * scale;
}
}
setPos(origX, origY);
offset = 0;
success = false;
break;
}
}
if (success) {
m_track = newTrack;
m_startPos = GenTime(x, m_fps);
}
}
GenTime AbstractClipItem::endPos() const {
return m_startPos + m_cropDuration;
}
......@@ -99,7 +61,7 @@ void AbstractClipItem::setCropStart(GenTime pos) {
m_cropStart = pos;
}
void AbstractClipItem::resizeStart(int posx, double scale) {
void AbstractClipItem::resizeStart(int posx) {
GenTime durationDiff = GenTime(posx, m_fps) - m_startPos;
if (durationDiff == GenTime()) return;
//kDebug() << "-- RESCALE: CROP=" << m_cropStart << ", DIFF = " << durationDiff;
......@@ -114,8 +76,8 @@ void AbstractClipItem::resizeStart(int posx, double scale) {
if (type() == AVWIDGET) m_cropStart += durationDiff;
m_cropDuration = m_cropDuration - durationDiff;
setRect(0, 0, (qreal) m_cropDuration.frames(m_fps) * scale - .5, rect().height());
setPos((qreal) m_startPos.frames(m_fps) * scale, pos().y());
setRect(0, 0, m_cropDuration.frames(m_fps) - 0.02, rect().height());
setPos((qreal) m_startPos.frames(m_fps), pos().y());
//setRect((double) m_startPos.frames(m_fps) * scale, rect().y(), (double) m_cropDuration.frames(m_fps) * scale, rect().height());
if (durationDiff < GenTime()) {
QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
......@@ -124,8 +86,8 @@ void AbstractClipItem::resizeStart(int posx, double scale) {
if (item->type() == type() && item->pos().x() < pos().x()) {
kDebug() << "///////// COLLISION DETECTED!!!!!!!!!";
GenTime diff = ((AbstractClipItem *)item)->endPos() + GenTime(1, m_fps) - m_startPos;
setRect(0, 0, (qreal)(m_cropDuration - diff).frames(m_fps) * scale - .5, rect().height());
setPos((qreal)(m_startPos + diff).frames(m_fps) * scale, pos().y());
setRect(0, 0, (m_cropDuration - diff).frames(m_fps) - 0.02, rect().height());
setPos((qreal)(m_startPos + diff).frames(m_fps), pos().y());
m_startPos += diff;
if (type() == AVWIDGET) m_cropStart += diff;
m_cropDuration = m_cropDuration - diff;
......@@ -135,7 +97,7 @@ void AbstractClipItem::resizeStart(int posx, double scale) {
}
}
void AbstractClipItem::resizeEnd(int posx, double scale) {
void AbstractClipItem::resizeEnd(int posx) {
GenTime durationDiff = GenTime(posx, m_fps) - endPos();
if (durationDiff == GenTime()) return;
//kDebug() << "-- RESCALE: CROP=" << m_cropStart << ", DIFF = " << durationDiff;
......@@ -145,7 +107,7 @@ void AbstractClipItem::resizeEnd(int posx, double scale) {
durationDiff = maxDuration() - m_cropDuration - m_cropStart;
}
m_cropDuration += durationDiff;
setRect(0, 0, (qreal) m_cropDuration.frames(m_fps) * scale - .5, rect().height());
setRect(0, 0, m_cropDuration.frames(m_fps) - 0.02, rect().height());
if (durationDiff > GenTime()) {
QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
for (int i = 0; i < collisionList.size(); ++i) {
......@@ -156,7 +118,7 @@ void AbstractClipItem::resizeEnd(int posx, double scale) {
kDebug() << "///////// COLLISION: " << ((AbstractClipItem *)item)->startPos().frames(25) << "x" << ((AbstractClipItem *)item)->endPos().frames(25) << ", RECT: " << ((AbstractClipItem *)item)->rect() << "-" << item->pos();
GenTime diff = ((AbstractClipItem *)item)->startPos() - GenTime(1, m_fps) - startPos();
m_cropDuration = diff;
setRect(0, 0, (qreal)(m_cropDuration.frames(m_fps)) * scale - .5, rect().height());
setRect(0, 0, (m_cropDuration.frames(m_fps)) - 0.02, rect().height());
break;
}
}
......@@ -249,14 +211,15 @@ void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF exposedRect) {
// draw line showing default value
if (isSelected()) {
x1 = br.x();
x1 = br.right();
x2 = br.right();
y1 = br.bottom() - m_keyframeDefault * maxh;
QLineF l(x1, y1, x2, y1);
QLineF l2 = painter->matrix().map(l);
painter->setPen(QColor(168, 168, 168, 180));
painter->drawLine(l);
l.translate(0, 1);
painter->drawLine(l2);
l2.translate(0, 1);
painter->setPen(QColor(108, 108, 108, 180));
painter->drawLine(l);
painter->drawLine(l2);
painter->setPen(QColor(Qt::white));
}
......@@ -265,6 +228,7 @@ void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF exposedRect) {
QColor color(Qt::blue);
x1 = br.x() + maxw * (i.key() - m_cropStart.frames(m_fps));
y1 = br.bottom() - i.value() * maxh;
QLineF l2;
while (i != m_keyframes.constEnd()) {
if (i.key() == m_selectedKeyframe) color = QColor(Qt::red);
else color = QColor(Qt::blue);
......@@ -273,14 +237,15 @@ void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF exposedRect) {
x2 = br.x() + maxw * (i.key() - m_cropStart.frames(m_fps));
y2 = br.bottom() - i.value() * maxh;
QLineF l(x1, y1, x2, y2);
painter->drawLine(l);
l2 = painter->matrix().map(l);
painter->drawLine(l2);
if (isSelected()) {
painter->fillRect(x1 - 3, y1 - 3, 6, 6, QBrush(color));
painter->fillRect(l2.x1() - 3, l2.y1() - 3, 6, 6, QBrush(color));
}
x1 = x2;
y1 = y2;
}
if (isSelected()) painter->fillRect(x1 - 3, y1 - 3, 6, 6, QBrush(color));
if (isSelected()) painter->fillRect(l2.x2() - 3, l2.y2() - 3, 6, 6, QBrush(color));
}
int AbstractClipItem::mouseOverKeyFrames(QPointF pos) {
......@@ -382,3 +347,7 @@ QRect AbstractClipItem::visibleRect() {
}
return rectInView;
}
CustomTrackScene* AbstractClipItem::projectScene() {
return static_cast <CustomTrackScene*>(scene());
}
......@@ -25,6 +25,8 @@
#include "definitions.h"
#include "gentime.h"
class CustomTrackScene;
class AbstractClipItem : public QObject , public QGraphicsRectItem {
Q_OBJECT
public:
......@@ -37,16 +39,16 @@ public:
double selectedKeyFrameValue() const;
double keyFrameFactor() const;
ItemInfo info() const;
CustomTrackScene* projectScene();
virtual OPERATIONTYPE operationMode(QPointF pos, double scale) = 0;
virtual OPERATIONTYPE operationMode(QPointF pos) = 0;
virtual GenTime startPos() const ;
virtual void setTrack(int track);
virtual GenTime endPos() const ;
virtual int track() const ;
virtual void moveTo(int x, double scale, int offset, int newTrack, bool checkCollision = true);
virtual GenTime cropStart() const ;
virtual void resizeStart(int posx, double scale);
virtual void resizeEnd(int posx, double scale);
virtual void resizeStart(int posx);
virtual void resizeEnd(int posx);
virtual GenTime duration() const;
virtual double fps() const;
virtual GenTime maxDuration() const;
......
/***************************************************************************
* Copyright (C) 2008 by Marco Gittler (g.marco@freenet.de) *
* Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QScrollBar>
#include <QToolTip>
#include <KDebug>
#include <KLocale>
#include "abstractgroupitem.h"
#include "abstractclipitem.h"
#include "kdenlivesettings.h"
#include "customtrackscene.h"
AbstractGroupItem::AbstractGroupItem(double fps): QGraphicsItemGroup(), m_fps(fps) {
setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
}
int AbstractGroupItem::type() const {
return GROUPWIDGET;
}
CustomTrackScene* AbstractGroupItem::projectScene() {
return static_cast <CustomTrackScene*>(scene());
}
QPainterPath AbstractGroupItem::groupShape(QPointF offset) {
QList<QGraphicsItem *> children = childItems();
QPainterPath path;
for (int i = 0; i < children.count(); i++) {
QRectF r = children.at(i)->sceneBoundingRect();
//kDebug()<<"// GROUP CHild: "<<r;
//r.translate(offset);
path.addRect(r);
}
return path;
}
void AbstractGroupItem::addItem(QGraphicsItem * item) {
addToGroup(item);
//fixItemRect();
}
void AbstractGroupItem::fixItemRect() {
QPointF start = boundingRect().topLeft();
if (start != QPointF(0, 0)) {
translate(0 - start.x(), 0 - start.y());
setPos(start);
}
}
// virtual
void AbstractGroupItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) {
p->fillRect(boundingRect(), QColor(200, 100, 100, 100));
}
//virtual
QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant &value) {
if (change == ItemPositionChange && scene()) {
// calculate new position.
QPointF newPos = value.toPointF();
QPainterPath sceneShape = groupShape(newPos);
QPointF start = sceneBoundingRect().topLeft();
QPointF sc = mapToScene(pos());
int posx = start.x() + newPos.x(); //projectScene()->getSnapPointForPos(start.x() + sc.x(), KdenliveSettings::snaptopoints());
//int startx = projectScene()->getSnapPointForPos(start.x(), false);
//int startx = projectScene()->getSnapPointForPos(start.x(), false);
kDebug() << "------------------------------------";
kDebug() << "BRect: " << start.x() << "diff: " << newPos.x() << ",mapd: " << start.x() - sc.x();
return newPos;
//kDebug()<<"BR: "<<start.x()<<",NP: "<<newPos.x()<<",MAPD: "<<sc.x()<<",POS: "<<pos().x();
if (start.x() <= 0) {
//kDebug()<<"/// GOING UNDER 0, POS: "<<posx<<", ADJUSTED: items.at(i)->sceneBoundingRect();
return pos();
}
//else posx -= startx;
//posx = qMax(posx, 0);
newPos.setX(posx);
//kDebug()<<"Y POS: "<<start.y() + newPos.y()<<"SCN MP: "<<sc;
int newTrack = (start.y() + newPos.y()) / KdenliveSettings::trackheight();
int oldTrack = (start.y() + pos().y()) / KdenliveSettings::trackheight();
newPos.setY((newTrack) * KdenliveSettings::trackheight() - start.y() + 1);
//if (start.y() + newPos.y() < 1) newTrack = oldTrack;
return newPos;
// Only one clip is moving
QList<QGraphicsItem*> items = scene()->items(sceneShape, Qt::IntersectsItemShape);
QList<QGraphicsItem *> children = childItems();
for (int i = 0; i < children.count(); i++) {
items.removeAll(children.at(i));
}
if (!items.isEmpty()) {
for (int i = 0; i < items.count(); i++) {
if (items.at(i)->type() == AVWIDGET) {
// Collision!
//kDebug()<<"/// COLLISION WITH ITEM: "<<items.at(i)->sceneBoundingRect();
return pos();
QPointF otherPos = items.at(i)->pos();
if ((int) otherPos.y() != (int) pos().y()) return pos();
if (pos().x() < otherPos.x()) {
// move clip just before colliding clip
int npos = (static_cast < AbstractClipItem* >(items.at(i))->startPos()).frames(m_fps) - sceneBoundingRect().width();
newPos.setX(npos);
} else {
// get pos just after colliding clip
int npos = static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps);
newPos.setX(npos);
}
return newPos;
}
}
}
return newPos;
}
return QGraphicsItem::itemChange(change, value);
}
/***************************************************************************
* Copyright (C) 2008 by Marco Gittler (g.marco@freenet.de) *
* Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef ABSTRACTGROUPITEM
#define ABSTRACTGROUPITEM
#include <QGraphicsItemGroup>
#include "definitions.h"
#include "gentime.h"
class CustomTrackScene;
class AbstractGroupItem : public QObject , public QGraphicsItemGroup {
Q_OBJECT
public:
AbstractGroupItem(double fps);
virtual int type() const;
CustomTrackScene* projectScene();
void addItem(QGraphicsItem * item);
protected:
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
private:
QPainterPath groupShape(QPointF);
void fixItemRect();
double m_fps;
};
#endif
This diff is collapsed.
......@@ -21,10 +21,11 @@
#ifndef CLIPITEM_H
#define CLIPITEM_H
#include <QTimeLine>
#include <QGraphicsRectItem>
#include <QDomElement>
#include <QGraphicsSceneMouseEvent>
#include <QTimeLine>
#include <QTimer>
#include "definitions.h"
#include "gentime.h"
......@@ -34,34 +35,35 @@
class DocClipBase;
class Transition;
class ClipItem : public AbstractClipItem {
Q_OBJECT
public:
ClipItem(DocClipBase *clip, ItemInfo info, double scale, double fps);
ClipItem(DocClipBase *clip, ItemInfo info, double fps);
virtual ~ ClipItem();
virtual void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *);
virtual int type() const;
void resizeStart(int posx, double scale);
void resizeEnd(int posx, double scale);
OPERATIONTYPE operationMode(QPointF pos, double scale);
void resizeStart(int posx);
void resizeEnd(int posx);
OPERATIONTYPE operationMode(QPointF pos);
int clipProducer() const;
int clipType() const;
DocClipBase *baseClip() const;
QString clipName() const;
QDomElement xml() const;
ClipItem *clone(double scale, ItemInfo info) const;
ClipItem *clone(ItemInfo info) const;
const EffectsList effectList();
void setFadeOut(int pos, double scale);
void setFadeIn(int pos, double scale);
void setFadeOut(int pos);
void setFadeIn(int pos);
/** Give a string list of the clip's effect names */
QStringList effectNames();
/** Add an effect to the clip and return the parameters that will be passed to Mlt */
QMap <QString, QString> addEffect(QDomElement effect, bool animate = true);
QHash <QString, QString> addEffect(QDomElement effect, bool animate = true);
/** Get the effect parameters that will be passed to Mlt */
QMap <QString, QString> getEffectArgs(QDomElement effect);
QHash <QString, QString> getEffectArgs(QDomElement effect);
/** Delete effect with id index */
void deleteEffect(QString index);
/** return the number of effects in that clip */
......@@ -104,6 +106,7 @@ protected:
virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
private:
DocClipBase *m_clip;
......@@ -115,7 +118,6 @@ private:
QString m_effectNames;
uint m_startFade;
uint m_endFade;
int m_maxTrack;
QPixmap m_startPix;
......@@ -129,7 +131,8 @@ private:
int m_selectedEffect;
double m_opacity;
QTimeLine *m_timeLine;
uint m_thumbsRequested;
bool m_startThumbRequested;
bool m_endThumbRequested;
bool m_hover;
double m_speed;
......@@ -147,15 +150,17 @@ private slots:
void slotGetStartThumb();
void slotGetEndThumb();
void slotGotAudioData();
void slotPrepareAudioThumb(double pixelForOneFrame, QPainterPath path, int startpixel, int endpixel, int channels);
void slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels);
void animate(qreal value);
public slots:
void slotSetStartThumb(QImage img);
void slotSetEndThumb(QImage img);
void slotSetStartThumb(QPixmap pix);
void slotSetEndThumb(QPixmap pix);
void slotThumbReady(int frame, QPixmap pix);
signals:
void getThumb(int, int);
void prepareAudioThumb(double, QPainterPath, int, int, int);
void prepareAudioThumb(double, int, int, int);
};
#endif
......@@ -84,18 +84,18 @@ void CustomRuler::mousePressEvent(QMouseEvent * event) {
int pos = (int)((event->x() + offset()));
m_moveCursor = RULER_CURSOR;
if (event->y() > 10) {
if (qAbs(pos - m_zoneStart * pixelPerMark() * FRAME_SIZE) < 4) m_moveCursor = RULER_START;
else if (qAbs(pos - (m_zoneStart + (m_zoneEnd - m_zoneStart) / 2) * pixelPerMark() * FRAME_SIZE) < 4) m_moveCursor = RULER_MIDDLE;
else if (qAbs(pos - m_zoneEnd * pixelPerMark() * FRAME_SIZE) < 4) m_moveCursor = RULER_END;
if (qAbs(pos - m_zoneStart * m_factor) < 4) m_moveCursor = RULER_START;
else if (qAbs(pos - (m_zoneStart + (m_zoneEnd - m_zoneStart) / 2) * m_factor) < 4) m_moveCursor = RULER_MIDDLE;
else if (qAbs(pos - m_zoneEnd * m_factor) < 4) m_moveCursor = RULER_END;
}
if (m_moveCursor == RULER_CURSOR)
m_view->setCursorPos((int) pos / pixelPerMark() / FRAME_SIZE);
m_view->setCursorPos((int) pos / m_factor);
}
// virtual
void CustomRuler::mouseMoveEvent(QMouseEvent * event) {
if (event->buttons() == Qt::LeftButton) {
int pos = (int)((event->x() + offset()) / pixelPerMark() / FRAME_SIZE);
int pos = (int)((event->x() + offset()) / m_factor);
if (pos < 0) pos = 0;
if (m_moveCursor == RULER_CURSOR) {
m_view->setCursorPos(pos);
......@@ -111,9 +111,9 @@ void CustomRuler::mouseMoveEvent(QMouseEvent * event) {
} else {
int pos = (int)((event->x() + offset()));
if (event->y() <= 10) setCursor(Qt::ArrowCursor);
else if (qAbs(pos - m_zoneStart * pixelPerMark() * FRAME_SIZE) < 4) setCursor(KCursor("left_side", Qt::SizeHorCursor));
else if (qAbs(pos - m_zoneEnd * pixelPerMark() * FRAME_SIZE) < 4) setCursor(KCursor("right_side", Qt::SizeHorCursor));
else if (qAbs(pos - (m_zoneStart + (m_zoneEnd - m_zoneStart) / 2) * pixelPerMark() * FRAME_SIZE) < 4) setCursor(Qt::SizeHorCursor);
else if (qAbs(pos - m_zoneStart * m_factor) < 4) setCursor(KCursor("left_side", Qt::SizeHorCursor));
else if (qAbs(pos - m_zoneEnd * m_factor) < 4) setCursor(KCursor("right_side", Qt::SizeHorCursor));
else if (qAbs(pos - (m_zoneStart + (m_zoneEnd - m_zoneStart) / 2) * m_factor) < 4) setCursor(Qt::SizeHorCursor);
else setCursor(Qt::ArrowCursor);
}
}
......@@ -140,12 +140,13 @@ void CustomRuler::slotMoveRuler(int newPos) {
}
void CustomRuler::slotCursorMoved(int oldpos, int newpos) {
update(oldpos - offset() - 6, 2, 17, 16);
update(newpos - offset() - 6, 2, 17, 16);
update(oldpos * m_factor - offset() - 6, 2, 17, 16);
update(newpos * m_factor - offset() - 6, 2, 17, 16);
}
void CustomRuler::setPixelPerMark(double rate) {
int scale = comboScale[(int) rate];
m_factor = 1.0 / (double) scale * FRAME_SIZE;
KRuler::setPixelPerMark(1.0 / scale);
double fend = pixelPerMark() * littleMarkDistance();
switch ((int) rate) {
......@@ -191,30 +192,21 @@ void CustomRuler::setDuration(int d) {
// virtual
void CustomRuler::paintEvent(QPaintEvent *e) {
// debug ("KRuler::drawContents, %s",(horizontal==dir)?"horizontal":"vertical");
QStylePainter p(this);
p.setClipRect(e->rect());
//p.fillRect(e->rect(), QBrush(QColor(200, 200, 200)));
//kDebug()<<"RULER ZONE: "<<m_zoneStart<<", OFF: "<<offset()<<", END: "<<m_zoneEnd<<", FACTOR: "<<pixelPerMark() * FRAME_SIZE;
int projectEnd = (int)(m_duration * pixelPerMark() * FRAME_SIZE);
const int projectEnd = (int)(m_duration * m_factor);
p.fillRect(QRect(- offset(), e->rect().y(), projectEnd, e->rect().height()), QBrush(QColor(245, 245, 245)));
int zoneStart = (int)(m_zoneStart * pixelPerMark() * FRAME_SIZE);
int zoneEnd = (int)(m_zoneEnd * pixelPerMark() * FRAME_SIZE);
const int zoneStart = (int)(m_zoneStart * m_factor);
const int zoneEnd = (int)(m_zoneEnd * m_factor);
p.fillRect(QRect(zoneStart - offset(), e->rect().y() + e->rect().height() / 2, zoneEnd - zoneStart, e->rect().height() / 2), QBrush(QColor(133, 255, 143)));
int value = m_view->cursorPos() - offset();
int minval = minimum();
int maxval = maximum() + offset() - endOffset();
const int value = m_view->cursorPos() * m_factor - offset();
const int minval = minimum();
const int maxval = maximum() + offset() - endOffset();
//ioffsetval = value-offset;
// pixelpm = (int)ppm;
// left = clip.left(),
// right = clip.right();
double f, fend,
offsetmin = (double)(minval - offset()),
offsetmax = (double)(maxval - offset()),
......@@ -248,7 +240,7 @@ void CustomRuler::paintEvent(QPaintEvent *e) {
}*/
for (f = offsetmin; f < offsetmax; f += m_textSpacing) {
QString lab = m_timecode.getTimecodeFromFrames((int)((f - offsetmin) / pixelPerMark() / FRAME_SIZE + 0.5));
QString lab = m_timecode.getTimecodeFromFrames((int)((f - offsetmin) / m_factor + 0.5));
p.drawText((int)f + 2, LABEL_SIZE, lab);
}
......@@ -302,15 +294,10 @@ void CustomRuler::paintEvent(QPaintEvent *e) {
}
// draw pointer
if (showPointer() && value >= 0) {
QPolygon pa(3);
pa.setPoints(3, value - 6, 7, value + 6, 7, value, 16);
p.setBrush(QBrush(Qt::yellow));
p.drawPolygon(pa);
}
QPolygon pa(3);