Commit 51913b59 authored by luyikei's avatar luyikei

Timeline: Save markers to the project

parent 59f726c4
......@@ -196,6 +196,7 @@ vlmc_SOURCES += \
src/Gui/settings/FolderListWidget.cpp \
src/Gui/timeline/Timeline.cpp \
src/Gui/timeline/ThumbnailImageProvider.cpp \
src/Gui/timeline/MarkerManager.cpp \
src/Gui/widgets/ExtendedLabel.cpp \
src/Gui/widgets/FramelessButton.cpp \
src/Gui/widgets/SearchLineEdit.cpp \
......@@ -303,6 +304,7 @@ nodist_vlmc_SOURCES += \
src/Gui/settings/PreferenceWidget.moc.cpp \
src/Gui/timeline/Timeline.moc.cpp \
src/Gui/timeline/ThumbnailImageProvider.moc.cpp \
src/Gui/timeline/MarkerManager.moc.cpp \
src/Gui/settings/LanguageWidget.moc.cpp \
src/Gui/import/TagWidget.moc.cpp \
src/Gui/settings/DoubleSliderWidget.moc.cpp \
......
......@@ -37,6 +37,10 @@
#include "Backend/IFilter.h"
#include "Library/Library.h"
#ifdef HAVE_GUI
# include "Gui/timeline/MarkerManager.h"
#endif
Commands::Generic::Generic() :
m_valid( true )
{
......@@ -565,3 +569,82 @@ Commands::Effect::Remove::internalUndo()
{
m_helper->setTarget( m_target.get() );
}
#ifdef HAVE_GUI
Commands::Marker::Add::Add( QSharedPointer<MarkerManager> markerManager, quint64 pos )
: m_markerManager( markerManager )
, m_pos( pos )
{
retranslate();
}
void
Commands::Marker::Add::internalRedo()
{
m_markerManager->addMarker( m_pos );
}
void
Commands::Marker::Add::internalUndo()
{
m_markerManager->removeMarker( m_pos );
}
void
Commands::Marker::Add::retranslate()
{
setText( tr( "Adding marker at %1" ).arg( m_pos ) );
}
Commands::Marker::Move::Move( QSharedPointer<MarkerManager> markerManager, quint64 oldPos, quint64 newPos )
: m_markerManager( markerManager )
, m_oldPos( oldPos )
, m_newPos( newPos )
{
retranslate();
}
void
Commands::Marker::Move::internalRedo()
{
m_markerManager->moveMarker( m_oldPos, m_newPos );
}
void
Commands::Marker::Move::internalUndo()
{
m_markerManager->moveMarker( 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( QSharedPointer<MarkerManager> markerManager, quint64 pos )
: m_markerManager( markerManager )
, m_pos( pos )
{
retranslate();
}
void
Commands::Marker::Remove::internalRedo()
{
m_markerManager->removeMarker( m_pos );
}
void
Commands::Marker::Remove::internalUndo()
{
m_markerManager->addMarker( 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 MarkerManager;
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( QSharedPointer<MarkerManager> markerManager, quint64 pos );
virtual void internalRedo();
virtual void internalUndo();
virtual void retranslate();
private:
QSharedPointer<MarkerManager> m_markerManager;
quint64 m_pos;
};
class Move : public Generic
{
public:
Move( QSharedPointer<MarkerManager> markerManager, quint64 oldPos, quint64 newPos );
virtual void internalRedo();
virtual void internalUndo();
virtual void retranslate();
private:
QSharedPointer<MarkerManager> m_markerManager;
quint64 m_oldPos;
quint64 m_newPos;
};
class Remove : public Generic
{
public:
Remove( QSharedPointer<MarkerManager> markerManager, quint64 pos );
virtual void internalRedo();
virtual void internalUndo();
virtual void retranslate();
private:
QSharedPointer<MarkerManager> m_markerManager;
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 );
}
}
}
/*****************************************************************************
* MarkerManager.cpp: Manager for markers
*****************************************************************************
* Copyright (C) 2008-2017 VideoLAN
*
* Authors: Yikei Lu <luyikei.qmltu@gmail.com>
*
* 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 "MarkerManager.h"
#include "Tools/VlmcDebug.h"
MarkerManager::MarkerManager()
{
}
void
MarkerManager::addMarker( quint64 pos )
{
if ( m_markers.contains( pos ) == false )
{
m_markers << pos;
emit markerAdded( pos );
}
else
vlmcCritical() << "Marker at" << pos << "has been already created.";
}
void
MarkerManager::moveMarker( 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
MarkerManager::removeMarker( quint64 pos )
{
bool ret = m_markers.removeOne( pos );
if ( ret == true )
emit markerRemoved( pos );
else
vlmcCritical() << "Marker at" << pos << "doesn't exist.";
}
QVariant
MarkerManager::toVariant()
{
QVariantList l;
for ( auto pos : m_markers )
l << pos;
return l;
}
void
MarkerManager::fromVariant( const QVariant& variant )
{
const auto& markers = variant.toList();
for ( auto pos : markers )
addMarker( pos.toULongLong() );
}
/*****************************************************************************
* MarkerManager.h: Manager for markers
*****************************************************************************
* Copyright (C) 2008-2017 VideoLAN
*
* Authors: Yikei Lu <luyikei.qmltu@gmail.com>
*
* 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 MARKERMANAGER_H
#define MARKERMANAGER_H
#include <QObject>
#include <QList>
#include <QVariant>
class MarkerManager : public QObject
{
Q_OBJECT
public:
MarkerManager();
void addMarker( quint64 pos );
void moveMarker( quint64 from, quint64 to );
void removeMarker( quint64 pos );
QVariant toVariant();
void fromVariant( const QVariant& variant );
signals:
void markerAdded( quint64 pos );
void markerMoved( quint64 from, quint64 to );
void markerRemoved( quint64 pos );
private:
QList<quint64> m_markers;
};
#endif // MARKERMANAGER_H
......@@ -149,7 +149,7 @@ Rectangle {
height: markersArea.height
onClicked: {
addMarker( ptof( mouseX ) );
timeline.addMarker( ptof( mouseX ) );
}
}
......
......@@ -26,26 +26,33 @@
#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 "MarkerManager.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_markerManager( new MarkerManager )
, 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 +63,16 @@ Timeline::Timeline( MainWindow* parent )
m_view->engine()->clearComponentCache();
m_view->setSource( QUrl( QStringLiteral( "qrc:/QML/main.qml" ) ) );
} );
connect( m_markerManager.data(), &MarkerManager::markerAdded, this, &Timeline::markerAdded );
connect( m_markerManager.data(), &MarkerManager::markerMoved, this, &Timeline::markerMoved );
connect( m_markerManager.data(), &MarkerManager::markerRemoved, this, &Timeline::markerRemoved );
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( "Timeline", *m_settings );
}
Timeline::~Timeline()
......@@ -68,3 +85,33 @@ Timeline::container()
{
return m_container;
}
void
Timeline::addMarker( quint64 pos )
{
Core::instance()->workflow()->trigger( new Commands::Marker::Add( m_markerManager, pos ) );
}
void
Timeline::moveMarker( quint64 from, quint64 to )
{
Core::instance()->workflow()->trigger( new Commands::Marker::Move( m_markerManager, from, to ) );
}
void
Timeline::removeMarker( quint64 pos )
{
Core::instance()->workflow()->trigger( new Commands::Marker::Remove( m_markerManager, pos ) );
}
void
Timeline::preSave()
{
m_settings->value( QStringLiteral( "markers" ) )->set( m_markerManager->toVariant() );
}
void
Timeline::postLoad()
{
m_markerManager->fromVariant( m_settings->value( QStringLiteral( "markers" ) )->get() );
}
......@@ -27,8 +27,12 @@
#include "vlmc.h"
#include "Workflow/Types.h"
#include <QSharedPointer>
class MainWindow;
class QQuickView;
class Settings;
class MarkerManager;
/**
* \brief Entry point of the timeline widget.
......@@ -38,17 +42,34 @@ 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();
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;
QSharedPointer<MarkerManager> m_markerManager;
std::unique_ptr<Settings> m_settings;
};
#endif // TIMELINE_H
......@@ -703,5 +703,15 @@ Rectangle {
isCutMode = false;
}
}
Connections {
target: timeline
onMarkerAdded: {
addMarker( pos );
}
onMarkerRemoved: {
removeMarker( pos );
}
}
}
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