Timeline.cpp 4.3 KB
Newer Older
Ludovic Fauvet's avatar
Ludovic Fauvet committed
1 2 3
/*****************************************************************************
 * Timeline.cpp: Widget that handle the tracks
 *****************************************************************************
4
 * Copyright (C) 2008-2016 VideoLAN
Ludovic Fauvet's avatar
Ludovic Fauvet committed
5
 *
luyikei's avatar
luyikei committed
6 7
 * Authors: Ludovic Fauvet <etix@l0cal.com>
 *          Yikei Lu    <luyikei.qmltu@gmail.com>
Ludovic Fauvet's avatar
Ludovic Fauvet committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * 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.
 *****************************************************************************/

24 25 26 27
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

28
#include "Timeline.h"
29

30
#include "Commands/Commands.h"
luyikei's avatar
luyikei committed
31 32
#include "Main/Core.h"
#include "Workflow/MainWorkflow.h"
33
#include "Gui/MainWindow.h"
34
#include "Gui/effectsengine/EffectStack.h"
35
#include "ThumbnailImageProvider.h"
36 37 38
#include "Settings/Settings.h"
#include "Tools/VlmcDebug.h"
#include "MarkerManager.h"
39

luyikei's avatar
luyikei committed
40
#include <QtQuick/QQuickView>
luyikei's avatar
luyikei committed
41
#include <QtQml/QQmlContext>
luyikei's avatar
luyikei committed
42
#include <QUrl>
43

44
Timeline::Timeline( Settings* projectSettings, MainWindow* parent )
luyikei's avatar
luyikei committed
45 46 47
    : QObject( parent )
    , m_view( new QQuickView )
    , m_container( QWidget::createWindowContainer( m_view, parent ) )
48 49
    , m_markerManager( new MarkerManager )
    , m_settings( new Settings )
50
{
luyikei's avatar
luyikei committed
51 52
    m_container->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_container->setFocusPolicy( Qt::TabFocus );
53 54 55
    auto p = new ThumbnailImageProvider;
    m_view->engine()->addImageProvider( QStringLiteral( "thumbnail" ), p );
    m_view->rootContext()->setContextProperty( QStringLiteral( "thumbnailProvider" ), p );
56
    m_view->rootContext()->setContextProperty( QStringLiteral( "timeline" ), this );
57 58
    m_view->rootContext()->setContextProperty( QStringLiteral( "mainwindow" ), parent );
    m_view->rootContext()->setContextProperty( QStringLiteral( "workflow" ), Core::instance()->workflow() );
59
    m_view->setSource( QUrl( QStringLiteral( "qrc:/QML/main.qml" ) ) );
60 61 62 63 64 65 66

    connect( Core::instance()->workflow(), &MainWorkflow::cleared, this, [this]()
    {
        m_view->setSource( QUrl() );
        m_view->engine()->clearComponentCache();
        m_view->setSource( QUrl( QStringLiteral( "qrc:/QML/main.qml" ) ) );
    } );
67 68 69 70 71 72 73 74 75
    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 );
luyikei's avatar
luyikei committed
76
    projectSettings->addSettings( QStringLiteral( "Timeline" ), *m_settings );
77 78 79 80
}

Timeline::~Timeline()
{
luyikei's avatar
luyikei committed
81 82 83 84 85 86 87
    delete m_view;
}

QWidget*
Timeline::container()
{
    return m_container;
88
}
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118

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() );
}