Skip to content
Snippets Groups Projects
Commit 867236c3 authored by Mathias Paulin's avatar Mathias Paulin :speech_balloon:
Browse files

Add timeline - still incomplete

parent e9b3a021
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@
#include <QToolBar>
#include <Gui/SelectionManager/SelectionManager.hpp>
#include <Gui/Timeline/Timeline.hpp>
#include <Gui/Viewer/CameraManipulator.hpp>
#include <Gui/Viewer/Gizmo/GizmoManager.hpp>
#include <Gui/Viewer/Viewer.hpp>
......@@ -75,6 +76,52 @@ void MainWindow::cleanup() {
m_viewer.reset( nullptr );
}
void MainWindow::addTimelineToolBar() {
auto timelineToolbar = new QToolBar( "Timeline", this );
timelineToolbar->setAllowedAreas( Qt::BottomToolBarArea );
timelineToolbar->setVisible( false );
// Add and connect timeline
m_timeline = new Ra::Gui::Timeline( this );
m_timeline->onChangeEnd( Ra::Engine::RadiumEngine::getInstance()->getEndTime() );
// Timeline setup
connect( m_timeline, &Ra::Gui::Timeline::playClicked, this, &MainWindow::timelinePlay );
connect(
m_timeline, &Ra::Gui::Timeline::cursorChanged, this, &MainWindow::timelineGoTo );
connect( m_timeline,
&Ra::Gui::Timeline::startChanged,
this,
&MainWindow::timelineStartChanged );
connect(
m_timeline, &Ra::Gui::Timeline::endChanged, this, &MainWindow::timelineEndChanged );
connect( m_timeline,
&Ra::Gui::Timeline::setPingPong,
this,
&MainWindow::timelineSetPingPong );
connect( m_timeline, &Ra::Gui::Timeline::keyFrameChanged, [=]( Scalar ) {
emit frameUpdate();
} );
timelineToolbar->addWidget( m_timeline );
this->addToolBar( Qt::BottomToolBarArea, timelineToolbar );
auto showTimelineToolbar = new QAction( this );
showTimelineToolbar->setObjectName( QString::fromUtf8( "showTimelineToolbar" ) );
showTimelineToolbar->setCheckable( true );
showTimelineToolbar->setChecked( false );
showTimelineToolbar->setText(
QCoreApplication::translate( "MainWindow", "Timeline toolbar", nullptr ) );
showTimelineToolbar->setToolTip(
QCoreApplication::translate( "MainWindow", "Show/hide the timeline toolbar", nullptr ) );
connect( showTimelineToolbar, &QAction::triggered, timelineToolbar, &QToolBar::setVisible );
connect( timelineToolbar, &QToolBar::visibilityChanged, [showTimelineToolbar]( bool b ) {
showTimelineToolbar->setChecked( b );
} );
menuToolbars->addAction( showTimelineToolbar );
}
void MainWindow::addSelectionToolBar() {
auto selectionToolBar = new QToolBar( "Selection toolbar", this );
......@@ -175,6 +222,7 @@ void MainWindow::addSelectionToolBar() {
void MainWindow::postOpenGLInitializations() {
addSelectionToolBar();
addTimelineToolBar();
}
void MainWindow::createConnections() {
......@@ -233,7 +281,17 @@ Viewer* MainWindow::getViewer() {
return m_viewer.get();
}
void MainWindow::onFrameComplete() {}
void MainWindow::onFrameComplete() {
// update timeline only if time changed, to allow manipulation of keyframed objects
auto engine = Ra::Engine::RadiumEngine::getInstance();
if ( !Ra::Core::Math::areApproxEqual( m_timeline->getTime(), engine->getTime() ) )
{
m_lockTimeSystem = true;
m_timeline->onChangeCursor( engine->getTime() );
m_lockTimeSystem = false;
}
}
void MainWindow::activateCamera( const std::string& sceneName ) {
// If a camera is in the given scene, use it, else, use default
......@@ -365,7 +423,7 @@ Ra::Gui::SelectionManager* MainWindow::getSelectionManager() {
Ra::Gui::Timeline* MainWindow::getTimeline() {
// mus return not null ?
return nullptr;
return m_timeline;
}
void MainWindow::ItemAdded( const ItemEntry& ent ) {
......@@ -438,4 +496,41 @@ void MainWindow::onSelectionChanged( const QItemSelection& /*selected*/,
{ emit selectedItem( ItemEntry() ); }
}
void MainWindow::timelinePlay( bool play ) {
actionPlay->setChecked( play );
if ( !m_lockTimeSystem ) {
Ra::Engine::RadiumEngine::getInstance()->play( play );
// mainApp->setContinuousUpdate( play );
}
}
void MainWindow::timelineGoTo( double t ) {
if ( !m_lockTimeSystem ) {
Ra::Engine::RadiumEngine::getInstance()->setTime( Scalar( t ) );
emit frameUpdate();
}
}
void MainWindow::timelineStartChanged( double t ) {
if ( !m_lockTimeSystem ) {
Ra::Engine::RadiumEngine::getInstance()->setStartTime( Scalar( t ) );
emit frameUpdate();
}
}
void MainWindow::timelineEndChanged( double t ) {
if ( !m_lockTimeSystem ) {
Ra::Engine::RadiumEngine::getInstance()->setEndTime( Scalar( t ) );
emit frameUpdate();
}
}
void MainWindow::timelineSetPingPong( bool status ) {
if ( !m_lockTimeSystem ) {
Ra::Engine::RadiumEngine::getInstance()->setForwardBackward( status );
emit frameUpdate();
}
}
} // namespace Mara
......@@ -154,10 +154,30 @@ class MainWindow : public Ra::Gui::MainWindowInterface, private Ui::MainWindow
/// Slot to init renderers once gl is ready
void postOpenGLInitializations();
/// Slot for the user requesting to play/pause time through the timeline.
void timelinePlay( bool play );
/// Slot for the user requesting to change the current time through the timeline.
void timelineGoTo( double t );
/// Slot for the user requesting to change the start time through the timeline.
void timelineStartChanged( double t );
/// Slot for the user requesting to change the end time through the timeline.
void timelineEndChanged( double t );
/// Slot for the user requesting to change the time play mode through the timeline.
void timelineSetPingPong( bool status );
private:
/// add the selection toolbar
void addSelectionToolBar();
/// add the selection toolbar
void addTimelineToolBar();
bool m_lockTimeSystem{false};
/// create the UI connections
void createConnections();
......@@ -181,6 +201,9 @@ class MainWindow : public Ra::Gui::MainWindowInterface, private Ui::MainWindow
/// Stores the internal model of engine objects for selection and visibility.
Ra::Gui::ItemModel* m_sceneModel;
/// Timeline gui
Ra::Gui::Timeline* m_timeline{nullptr};
#ifdef SHOWTREEVIEW
/// QTreeview of the scene
QTreeView* m_sceneTreeView;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment