Commit bb1679ab authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen
Browse files

Big positionChanged/frameChanged refactoring

This avoid deadlocks introduced in previous commit, and clarify the code.
parent 7640c316
......@@ -23,8 +23,9 @@
#include <QtDebug>
#include "GraphicsCursorItem.h"
GraphicsCursorItem::GraphicsCursorItem( const QPen& pen )
: m_pen( pen )
GraphicsCursorItem::GraphicsCursorItem( const QPen& pen ) :
m_pen( pen ),
m_manualMove( true )
{
setFlags( QGraphicsItem::ItemIgnoresTransformations | QGraphicsItem::ItemIsMovable );
setCursor( QCursor( Qt::SizeHorCursor ) );
......@@ -46,22 +47,30 @@ void GraphicsCursorItem::paint( QPainter* painter, const QStyleOptionGraphicsIte
QVariant GraphicsCursorItem::itemChange( GraphicsItemChange change, const QVariant& value )
{
//Position is changing :
if ( change == ItemPositionChange )
{
qreal posX = value.toPointF().x();
if ( posX < 0 ) posX = 0;
return QPoint( ( int ) posX, ( int ) pos().y() );
}
if ( change == ItemPositionHasChanged )
//The position HAS changed, ie we released the slider, or setPos has been called.
else if ( change == ItemPositionHasChanged )
{
emit cursorPositionChanged( ( qint64 ) pos().x() );
if ( m_manualMove == true )
emit cursorPositionChanged( ( qint64 ) pos().x() );
}
return QGraphicsItem::itemChange( change, value );
}
void GraphicsCursorItem::setCursorPos( qint64 position )
void GraphicsCursorItem::frameChanged( qint64 newFrame, GenericRenderer::FrameChangedReason reason )
{
setPos( position, pos().y() );
if ( reason != GenericRenderer::TimelineCursor )
{
m_manualMove = false;
setPos( newFrame, pos().y() );
m_manualMove = true;
}
}
void GraphicsCursorItem::setHeight( int height )
......
......@@ -30,6 +30,7 @@
#include <QPainter>
#include <QCursor>
#include <QGraphicsSceneMouseEvent>
#include "GenericRenderer.h"
class GraphicsCursorItem : public QObject, public QGraphicsItem
{
......@@ -45,14 +46,15 @@ protected:
virtual QVariant itemChange( GraphicsItemChange change, const QVariant& value );
private:
QPen m_pen;
QRectF m_boundingRect;
QPen m_pen;
QRectF m_boundingRect;
bool m_manualMove;
signals:
void cursorPositionChanged( qint64 pos );
public slots:
void setCursorPos( qint64 position );
void frameChanged( qint64 position, GenericRenderer::FrameChangedReason );
};
#endif // GRAPHICSCURSORITEM_H
......@@ -62,6 +62,7 @@ MainWindow::MainWindow( QWidget *parent ) :
{
m_ui.setupUi( this );
qRegisterMetaType<MainWorkflow::TrackType>( "MainWorkflow::TrackType" );
qRegisterMetaType<GenericRenderer::FrameChangedReason>( "GenericRenderer::FrameChangedReason" );
DockWidgetManager::instance( this )->setMainWindow( this );
initializeDockWidgets();
createStatusBar();
......
......@@ -39,12 +39,13 @@ void PreviewRuler::setRenderer( GenericRenderer* renderer )
if ( m_renderer )
{
disconnect( m_renderer, SIGNAL( positionChanged(float) ) );
disconnect( m_renderer, SIGNAL( frameChanged(qint64) ) );
disconnect( m_renderer, SIGNAL( frameChanged(qint64, GenericRenderer::FrameChangedReason ) ) );
}
m_renderer = renderer;
connect( m_renderer, SIGNAL( positionChanged(float) ), this, SLOT( update() ) );
connect( m_renderer, SIGNAL( frameChanged(qint64) ), this, SLOT( updateTimecode() ) );
connect( m_renderer, SIGNAL( frameChanged(qint64,GenericRenderer::FrameChangedReason) ),
this, SLOT( updateTimecode( qint64 ) ) );
}
void PreviewRuler::sliderChange( SliderChange change )
......@@ -210,19 +211,19 @@ void PreviewRuler::mouseReleaseEvent( QMouseEvent * event )
void PreviewRuler::setFrame( qint64 frame )
{
m_frame = frame;
emit frameChanged( frame );
setValue( frame * m_range / m_renderer->getLengthMs() );
if ( m_isSliding )
emit sliderPosChanged( frame * m_range / m_renderer->getLengthMs() );
update();
}
void PreviewRuler::updateTimecode()
void PreviewRuler::updateTimecode( qint64 frames /*= -1*/ )
{
if ( m_renderer->getLengthMs() )
{
int fps = (int)m_renderer->getFps();
qint64 frames = m_renderer->getCurrentFrame();
if ( frames == -1 )
frames = m_renderer->getCurrentFrame();
int h = frames / fps / 60 / 60;
frames -= h * fps * 60 * 60;
......
......@@ -53,7 +53,7 @@ protected:
virtual void sliderChange( SliderChange change );
private slots:
void updateTimecode();
void updateTimecode( qint64 frames = -1 );
private:
GenericRenderer* m_renderer;
......
......@@ -94,6 +94,11 @@ void PreviewWidget::positionChanged( float newPos )
m_ui->rulerWidget->setValue( (int)( newPos * 1000.0 ) );
}
void PreviewWidget::frameChanged( qint64 currentFrame )
{
if ( m_previewStopped == false )
m_ui->rulerWidget->setFrame( currentFrame );
}
void PreviewWidget::seekSliderPressed()
{
......
......@@ -62,6 +62,7 @@ private slots:
void on_pushButtonNextFrame_clicked();
void on_pushButtonPreviousFrame_clicked();
void positionChanged( float );
void frameChanged( qint64 );
void seekSliderPressed();
void seekSliderMoved( int value );
void seekSliderReleased();
......
......@@ -81,8 +81,9 @@ Timeline::Timeline( WorkflowRenderer* renderer, QWidget *parent ) :
connect( m_tracksView, SIGNAL( audioTrackAdded(GraphicsTrack*) ),
m_tracksControls, SLOT( addAudioTrack(GraphicsTrack*) ) );
connect( m_mainWorkflow, SIGNAL( frameChanged(qint64) ),
m_tracksView->tracksCursor(), SLOT( setCursorPos( qint64 ) ), Qt::QueuedConnection );
connect( m_renderer, SIGNAL( frameChanged(qint64, GenericRenderer::FrameChangedReason) ),
m_tracksView->tracksCursor(), SLOT( frameChanged( qint64, GenericRenderer::FrameChangedReason ) ),
Qt::QueuedConnection );
connect( m_tracksView->tracksCursor(), SIGNAL( cursorPositionChanged( qint64 ) ),
m_renderer, SLOT( timelineCursorChanged(qint64) ) );
......
......@@ -632,7 +632,7 @@ QList<AbstractGraphicsMediaItem*> TracksView::mediaItems( const QPoint& pos )
void TracksView::setCursorPos( qint64 pos )
{
if ( pos < 0 ) pos = 0;
m_cursorLine->setCursorPos( pos );
m_cursorLine->frameChanged( pos, GenericRenderer::TimelineCursor );
}
qint64 TracksView::cursorPos()
......
......@@ -258,8 +258,8 @@ void ClipRenderer::__positionChanged()
void ClipRenderer::__timeChanged()
{
qint64 f = qRound64( (qreal)m_mediaPlayer->getTime() / 1000 * (qreal)m_mediaPlayer->getFps() );
emit frameChanged( f );
qint64 f = qRound64( (qreal)m_mediaPlayer->getTime() / 1000.0 * (qreal)m_mediaPlayer->getFps() );
emit frameChanged( f, Renderer );
}
void ClipRenderer::__endReached()
......
......@@ -36,6 +36,12 @@ class GenericRenderer : public QObject
Q_DISABLE_COPY( GenericRenderer );
public:
enum FrameChangedReason
{
Renderer,
TimelineCursor,
PreviewCursor,
};
explicit GenericRenderer() :
m_paused( false ),
m_isRendering( false )
......@@ -152,7 +158,7 @@ signals:
void paused();
void playing();
void positionChanged( float );
void frameChanged( qint64 );
void frameChanged( qint64, GenericRenderer::FrameChangedReason );
void endReached();
};
......
......@@ -153,8 +153,8 @@ void WorkflowRenderer::startPreview()
connect( m_mediaPlayer, SIGNAL( paused() ), this, SLOT( __videoPaused() ), Qt::DirectConnection );
connect( m_mediaPlayer, SIGNAL( stopped() ), this, SLOT( __videoStopped() ) );
connect( m_mainWorkflow, SIGNAL( mainWorkflowEndReached() ), this, SLOT( __endReached() ) );
connect( m_mainWorkflow, SIGNAL( positionChanged( float ) ), this, SLOT( __positionChanged( float ) ) );
connect( m_mainWorkflow, SIGNAL( frameChanged( qint64 ) ), this, SLOT( __frameChanged( qint64 ) ) );
connect( m_mainWorkflow, SIGNAL( frameChanged( qint64 ) ),
this, SLOT( __frameChanged( qint64 ) ) );
m_mainWorkflow->setFullSpeedRender( false );
m_mainWorkflow->startRender();
......@@ -167,6 +167,7 @@ void WorkflowRenderer::startPreview()
void WorkflowRenderer::setPosition( float newPos )
{
qDebug() << "Setting position to:" << newPos;
m_mainWorkflow->setPosition( newPos );
}
......@@ -316,19 +317,9 @@ void WorkflowRenderer::__endReached()
emit endReached();
}
void WorkflowRenderer::__positionChanged()
{
qFatal("This should never be used ! Get out of here !");
}
void WorkflowRenderer::__positionChanged( float pos )
{
emit positionChanged( pos );
}
void WorkflowRenderer::__frameChanged( qint64 frame )
{
emit frameChanged( frame );
emit frameChanged( frame, Renderer );
}
void WorkflowRenderer::__videoPaused()
......
......@@ -105,8 +105,7 @@ class WorkflowRenderer : public GenericRenderer
void mediaUnloaded( const QUuid& ) {}
void timelineCursorChanged( qint64 newFrame );
void __positionChanged();
void __positionChanged( float pos );
void __positionChanged() { qFatal("Get out."); }
void __frameChanged( qint64 frame );
void __videoPaused();
void __videoStopped();
......
......@@ -155,7 +155,6 @@ void MainWorkflow::nextFrame()
++m_currentFrame;
emit frameChanged( m_currentFrame );
emit positionChanged( (float)m_currentFrame / (float)m_lengthFrame );
}
void MainWorkflow::previousFrame()
......@@ -164,7 +163,6 @@ void MainWorkflow::previousFrame()
--m_currentFrame;
emit frameChanged( m_currentFrame );
emit positionChanged( (float)m_currentFrame / (float)m_lengthFrame );
}
void MainWorkflow::setPosition( float pos )
......@@ -204,7 +202,6 @@ void MainWorkflow::stop()
m_tracks[i]->stop();
m_currentFrame = 0;
emit frameChanged( 0 );
emit positionChanged( 0 );
}
void MainWorkflow::moveClip( const QUuid& clipUuid, unsigned int oldTrack,
......@@ -271,7 +268,7 @@ void MainWorkflow::setCurrentFrame( qint64 currentFrame )
QWriteLocker lock( m_currentFrameLock );
m_currentFrame = currentFrame;
emit positionChanged( (float)m_currentFrame / (float)m_lengthFrame );
emit frameChanged( m_currentFrame );
}
Clip* MainWorkflow::getClip( const QUuid& uuid, unsigned int trackId, MainWorkflow::TrackType trackType )
......
......@@ -170,10 +170,6 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
* \brief Used to notify a change to the timeline cursor
*/
void frameChanged( qint64 currentFrame );
/**
* \brief Used to nofify a change to the PreviewWidget
*/
void positionChanged( float pos );
void mainWorkflowEndReached();
void mainWorkflowPaused();
......
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