Commit 31876eb4 authored by Ludovic Fauvet's avatar Ludovic Fauvet

Timeline cursor react to mouse movements

parent b463c010
......@@ -21,6 +21,7 @@
*****************************************************************************/
#include <QScrollBar>
#include <QMouseEvent>
#include "TracksView.h"
TracksView::TracksView( QGraphicsScene* scene, QWidget* parent )
......@@ -37,8 +38,13 @@ TracksView::TracksView( QGraphicsScene* scene, QWidget* parent )
setAcceptDrops( true );
setContentsMargins( 0, 0, 0, 0 );
// Adjust the height using the number of tracks
const int maxHeight = m_tracksHeight * m_tracksCount;
setSceneRect( 0, 0, sceneRect().width(), maxHeight );
m_cursorPos = 0;
m_cursorLine = m_scene->addLine(0, 0, 0, maxHeight);
m_cursorLine->setZValue(100);
}
void TracksView::setDuration( int duration )
......@@ -76,3 +82,33 @@ void TracksView::drawBackground( QPainter* painter, const QRectF& rect )
if ( height() > lowerLimit )
painter->fillRect( QRectF ( r.left(), lowerLimit, r.width(), height() - lowerLimit ), QBrush( base ) );
}
void TracksView::mouseMoveEvent( QMouseEvent* event )
{
int xPos = event->x();
int mappedXPos = ( int )( mapToScene( event->pos() ).x() + 0.5 );
if ( event->buttons() == Qt::LeftButton && event->modifiers() == Qt::NoModifier )
{
setCursorPos( mappedXPos );
}
QGraphicsView::mouseMoveEvent( event );
}
void TracksView::mousePressEvent( QMouseEvent* event )
{
int xPos = event->x();
int mappedXPos = ( int )( mapToScene( event->pos() ).x() + 0.5 );
if ( event->buttons() == Qt::LeftButton && event->modifiers() == Qt::NoModifier )
{
setCursorPos( mappedXPos );
}
QGraphicsView::mousePressEvent( event );
}
void TracksView::setCursorPos(int pos)
{
m_cursorPos = pos;
m_cursorLine->setPos(m_cursorPos, 0);
}
......@@ -24,6 +24,7 @@
#define TRACKSVIEW_H
#include <QGraphicsView>
#include <QGraphicsLineItem>
class TracksView : public QGraphicsView
{
......@@ -33,16 +34,22 @@ public:
TracksView( QGraphicsScene* scene, QWidget* parent = 0 );
void setDuration( int duration );
int duration() { return m_projectDuration; }
void setCursorPos(int pos);
protected:
virtual void resizeEvent( QResizeEvent* event );
virtual void drawBackground( QPainter* painter, const QRectF& rect );
virtual void mouseMoveEvent( QMouseEvent* event );
virtual void mousePressEvent( QMouseEvent* event );
private:
QGraphicsScene* m_scene;
int m_tracksHeight;
int m_tracksCount;
int m_projectDuration;
int m_cursorPos;
QGraphicsLineItem* m_cursorLine;
};
#endif // TRACKSVIEW_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment