...
 
Commits (4)
......@@ -37,6 +37,10 @@
#include "Backend/IFilter.h"
#include "Library/Library.h"
#ifdef HAVE_GUI
# include "Gui/timeline/Timeline.h"
#endif
Commands::Generic::Generic() :
m_valid( true )
{
......@@ -565,3 +569,81 @@ Commands::Effect::Remove::internalUndo()
{
m_helper->setTarget( m_target.get() );
}
#ifdef HAVE_GUI
Commands::Marker::Add::Add( Timeline* timeline, quint64 pos )
: m_timeline( timeline )
, m_pos( pos )
{
retranslate();
}
void
Commands::Marker::Add::internalRedo()
{
m_timeline->addMarkerImpl( m_pos );
}
void
Commands::Marker::Add::internalUndo()
{
m_timeline->removeMarkerImpl( m_pos );
}
void
Commands::Marker::Add::retranslate()
{
setText( tr( "Adding marker at %1" ).arg( m_pos ) );
}
Commands::Marker::Move::Move( Timeline* timeline, quint64 oldPos, quint64 newPos )
: m_timeline( timeline )
, m_oldPos( oldPos )
, m_newPos( newPos )
{
retranslate();
}
void
Commands::Marker::Move::internalRedo()
{
m_timeline->moveMarkerImpl( m_oldPos, m_newPos );
}
void
Commands::Marker::Move::internalUndo()
{
m_timeline->moveMarkerImpl( m_newPos, m_oldPos );
}
void
Commands::Marker::Move::retranslate()
{
setText( tr( "Moving marker from %1 to %2" ).arg( m_oldPos ).arg( m_newPos ) );
}
Commands::Marker::Remove::Remove( Timeline* timeline, quint64 pos )
: m_timeline( timeline )
, m_pos( pos )
{
retranslate();
}
void
Commands::Marker::Remove::internalRedo()
{
m_timeline->removeMarkerImpl( m_pos );
}
void
Commands::Marker::Remove::internalUndo()
{
m_timeline->addMarkerImpl( m_pos );
}
void
Commands::Marker::Remove::retranslate()
{
setText( tr( "Removing marker at %1" ).arg( m_pos ) );
}
#endif
......@@ -43,6 +43,7 @@ namespace Backend
class IInput;
}
class EffectHelper;
class Timeline;
namespace Commands
{
......@@ -220,6 +221,7 @@ namespace Commands
QUuid m_clipB;
};
}
namespace Effect
{
class Add : public Generic
......@@ -278,6 +280,54 @@ namespace Commands
std::shared_ptr<Backend::IInput> m_target;
};
}
#ifdef HAVE_GUI
// Gui commands
namespace Marker
{
class Add : public Generic
{
public:
// We use a raw pointer because it will only be accessed from Timeline itself.
// Plus, Timeline is a QObject and has a parent so we don't worry about memory leak :)
Add( Timeline* timeline, quint64 pos );
virtual void internalRedo();
virtual void internalUndo();
virtual void retranslate();
private:
Timeline* m_timeline;
quint64 m_pos;
};
class Move : public Generic
{
public:
Move( Timeline* timeline, quint64 oldPos, quint64 newPos );
virtual void internalRedo();
virtual void internalUndo();
virtual void retranslate();
private:
Timeline* m_timeline;
quint64 m_oldPos;
quint64 m_newPos;
};
class Remove : public Generic
{
public:
Remove( Timeline* timeline, quint64 pos );
virtual void internalRedo();
virtual void internalUndo();
virtual void retranslate();
private:
Timeline* m_timeline;
quint64 m_pos;
};
}
#endif
}
#endif // COMMANDS_H
......@@ -477,7 +477,7 @@ MainWindow::createStatusBar()
void
MainWindow::initializeDockWidgets()
{
m_timeline = new Timeline( this );
m_timeline = new Timeline( Core::instance()->project()->settings(), this );
setCentralWidget( m_timeline->container() );
setupLibrary();
......
......@@ -10,15 +10,16 @@ Rectangle {
visible: x < sView.flickableItem.contentX ? false : true
property int position: 0
property int lastPosition: 0
property var markerModel
onPositionChanged: {
markerModel["position"] = position;
length = Math.max( length, position + 100 );
}
onMarkerModelChanged: {
position = markerModel["position"];
lastPosition = markerModel["position"];
}
Drag.keys: ["Marker"]
......@@ -37,6 +38,17 @@ Rectangle {
drag.minimumX: 0
acceptedButtons: Qt.LeftButton | Qt.RightButton
onPressed: {
lastPosition = position;
}
onReleased: {
if ( lastPosition === position )
return;
timeline.moveMarker( lastPosition, position );
lastPosition = position;
}
onClicked: {
if ( mouse.button & Qt.RightButton ) {
markerContextMenu.popup();
......@@ -49,5 +61,15 @@ Rectangle {
marker: marker
}
}
Connections {
target: timeline
onMarkerMoved: {
if ( position === from ) {
markerModel["position"] = to;
position = to;
}
}
}
}
......@@ -23,7 +23,7 @@ Menu {
icon: StandardIcon.Question
standardButtons: StandardButton.Yes | StandardButton.No
onYes: {
removeMarker( marker.position );
timeline.removeMarker( marker.position );
}
}
}
......@@ -149,7 +149,7 @@ Rectangle {
height: markersArea.height
onClicked: {
addMarker( ptof( mouseX ) );
timeline.addMarker( ptof( mouseX ) );
}
}
......
......@@ -26,26 +26,31 @@
#include "Timeline.h"
#include "Commands/Commands.h"
#include "Main/Core.h"
#include "Workflow/MainWorkflow.h"
#include "Gui/MainWindow.h"
#include "Gui/effectsengine/EffectStack.h"
#include "ThumbnailImageProvider.h"
#include "Settings/Settings.h"
#include "Tools/VlmcDebug.h"
#include <QtQuick/QQuickView>
#include <QtQml/QQmlContext>
#include <QUrl>
Timeline::Timeline( MainWindow* parent )
Timeline::Timeline( Settings* projectSettings, MainWindow* parent )
: QObject( parent )
, m_view( new QQuickView )
, m_container( QWidget::createWindowContainer( m_view, parent ) )
, m_settings( new Settings )
{
m_container->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
m_container->setFocusPolicy( Qt::TabFocus );
auto p = new ThumbnailImageProvider;
m_view->engine()->addImageProvider( QStringLiteral( "thumbnail" ), p );
m_view->rootContext()->setContextProperty( QStringLiteral( "thumbnailProvider" ), p );
m_view->rootContext()->setContextProperty( QStringLiteral( "timeline" ), this );
m_view->rootContext()->setContextProperty( QStringLiteral( "mainwindow" ), parent );
m_view->rootContext()->setContextProperty( QStringLiteral( "workflow" ), Core::instance()->workflow() );
m_view->setSource( QUrl( QStringLiteral( "qrc:/QML/main.qml" ) ) );
......@@ -56,6 +61,13 @@ Timeline::Timeline( MainWindow* parent )
m_view->engine()->clearComponentCache();
m_view->setSource( QUrl( QStringLiteral( "qrc:/QML/main.qml" ) ) );
} );
m_settings->createVar( SettingValue::List, QStringLiteral( "markers" ), QVariantList(),
"Markers", "List of markers that the timeline uses",
SettingValue::Folders );
connect( m_settings.get(), &Settings::postLoad, this, &Timeline::postLoad, Qt::DirectConnection );
connect( m_settings.get(), &Settings::preSave, this, &Timeline::preSave, Qt::DirectConnection );
projectSettings->addSettings( QStringLiteral( "Timeline" ), *m_settings );
}
Timeline::~Timeline()
......@@ -68,3 +80,75 @@ Timeline::container()
{
return m_container;
}
void
Timeline::addMarkerImpl( quint64 pos )
{
if ( m_markers.contains( pos ) == false )
{
m_markers << pos;
emit markerAdded( pos );
}
else
vlmcCritical() << "Marker at" << pos << "has been already created.";
}
void
Timeline::moveMarkerImpl( quint64 from, quint64 to )
{
for ( int i = 0; i < m_markers.size(); ++i )
{
if ( m_markers[i] == from )
{
m_markers[i] = to;
emit markerMoved( from, to );
return;
}
}
vlmcCritical() << "Marker at" << from << "doesn't exist.";
}
void
Timeline::removeMarkerImpl( quint64 pos )
{
bool ret = m_markers.removeOne( pos );
if ( ret == true )
emit markerRemoved( pos );
else
vlmcCritical() << "Marker at" << pos << "doesn't exist.";
}
void
Timeline::addMarker( quint64 pos )
{
Core::instance()->workflow()->trigger( new Commands::Marker::Add( this, pos ) );
}
void
Timeline::moveMarker( quint64 from, quint64 to )
{
Core::instance()->workflow()->trigger( new Commands::Marker::Move( this, from, to ) );
}
void
Timeline::removeMarker( quint64 pos )
{
Core::instance()->workflow()->trigger( new Commands::Marker::Remove( this, pos ) );
}
void
Timeline::preSave()
{
QVariantList l;
for ( auto pos : m_markers )
l << pos;
m_settings->value( QStringLiteral( "markers" ) )->set( l );
}
void
Timeline::postLoad()
{
const auto& markers = m_settings->value( QStringLiteral( "markers" ) )->get().toList();
for ( auto pos : markers )
addMarkerImpl( pos.toULongLong() );
}
......@@ -29,6 +29,7 @@
class MainWindow;
class QQuickView;
class Settings;
/**
* \brief Entry point of the timeline widget.
......@@ -38,17 +39,39 @@ class Timeline : public QObject
Q_OBJECT
Q_DISABLE_COPY( Timeline )
public:
explicit Timeline( MainWindow* parent = 0 );
explicit Timeline( Settings* projectSettings, MainWindow* parent = 0 );
virtual ~Timeline();
QWidget* container();
void addMarkerImpl( quint64 pos );
void moveMarkerImpl( quint64 from, quint64 to );
void removeMarkerImpl( quint64 pos );
signals:
void markerAdded( quint64 pos );
void markerMoved( quint64 from, quint64 to );
void markerRemoved( quint64 pos );
public slots:
void addMarker( quint64 pos );
void moveMarker( quint64 from, quint64 to );
void removeMarker( quint64 pos );
private slots:
void preSave();
void postLoad();
protected:
virtual void changeEvent( QEvent *e ) { Q_UNUSED( e ) }
private:
QQuickView* m_view;
QWidget* m_container;
QList<quint64> m_markers;
std::unique_ptr<Settings> m_settings;
};
#endif // TIMELINE_H
......@@ -279,7 +279,7 @@ Item {
if ( drag.source === target || dMode === dropMode.New )
target.scrollToThis();
}
// END of for ( var i = 0; i < selectedClips.length; ++i )
// END of while ( toMove.length > 0 )
if ( dMode === dropMode.Move )
lastX = drag.source.x;
......
......@@ -703,5 +703,15 @@ Rectangle {
isCutMode = false;
}
}
Connections {
target: timeline
onMarkerAdded: {
addMarker( pos );
}
onMarkerRemoved: {
removeMarker( pos );
}
}
}
......@@ -61,10 +61,10 @@ Library::Library( Settings* vlmcSettings, Settings *projectSettings )
connect( ws, &SettingValue::changed, this, &Library::workspaceChanged );
// Setting up the project section of the Library
m_settings->createVar( SettingValue::List, QString( "medias" ), QVariantList(), "", "", SettingValue::Nothing );
connect( m_settings, &Settings::postLoad, this, &Library::postLoad, Qt::DirectConnection );
connect( m_settings, &Settings::preSave, this, &Library::preSave, Qt::DirectConnection );
projectSettings->addSettings( "Library", *m_settings );
m_settings->createVar( SettingValue::List, QStringLiteral( "medias" ), QVariantList(), "", "", SettingValue::Nothing );
connect( m_settings.get(), &Settings::postLoad, this, &Library::postLoad, Qt::DirectConnection );
connect( m_settings.get(), &Settings::preSave, this, &Library::preSave, Qt::DirectConnection );
projectSettings->addSettings( QStringLiteral( "Library" ), *m_settings );
}
void
......@@ -96,7 +96,6 @@ Library::postLoad()
Library::~Library()
{
delete m_settings;
}
void
......
......@@ -111,7 +111,7 @@ private:
private:
std::unique_ptr<medialibrary::IMediaLibrary> m_ml;
MediaLibraryModel* m_model;
Settings* m_settings;
std::unique_ptr<Settings> m_settings;
bool m_initialized;
bool m_cleanState;
......
......@@ -79,7 +79,7 @@ MainWorkflow::MainWorkflow( Settings* projectSettings, int trackCount ) :
m_settings->createVar( SettingValue::List, "tracks", QVariantList(), "", "", SettingValue::Nothing );
connect( m_settings, &Settings::postLoad, this, &MainWorkflow::postLoad, Qt::DirectConnection );
connect( m_settings, &Settings::preSave, this, &MainWorkflow::preSave, Qt::DirectConnection );
projectSettings->addSettings( "Workspace", *m_settings );
projectSettings->addSettings( QStringLiteral( "Workspace" ), *m_settings );
connect( m_undoStack.get(), &Commands::AbstractUndoStack::cleanChanged, this, &MainWorkflow::cleanChanged );
}
......