Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cmake/filelistGuiBase.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
set( guibase_sources
BaseApplication.cpp
RadiumWindow/SimpleWindow.cpp
KeyFrameEditor/KeyFrameEditor.cpp
KeyFrameEditor/KeyFrameEditorFrame.cpp
KeyFrameEditor/KeyFrameEditorFrameScale.cpp
KeyFrameEditor/KeyFrameEditorScrollArea.cpp
KeyFrameEditor/KeyFrameEditorTimeScale.cpp
KeyFrameEditor/KeyFrameEditorValueScale.cpp
SelectionManager/SelectionManager.cpp
Timeline/HelpDialog.cpp
Timeline/TimelineFrameSelector.cpp
Expand Down Expand Up @@ -33,6 +39,12 @@ set(guibase_headers
RaGuiBase.hpp
RadiumWindow/SimpleWindow.hpp
RadiumWindow/SimpleWindowFactory.hpp
KeyFrameEditor/KeyFrameEditor.hpp
KeyFrameEditor/KeyFrameEditorFrame.hpp
KeyFrameEditor/KeyFrameEditorFrameScale.hpp
KeyFrameEditor/KeyFrameEditorScrollArea.hpp
KeyFrameEditor/KeyFrameEditorTimeScale.hpp
KeyFrameEditor/KeyFrameEditorValueScale.hpp
SelectionManager/SelectionManager.hpp
Timeline/HelpDialog.hpp
Timeline/Configurations.hpp
Expand Down Expand Up @@ -66,6 +78,7 @@ set( guibase_inlines
)

set( guibase_uis
KeyFrameEditor/KeyFrameEditor.ui
Timeline/HelpDialog.ui
Timeline/Timeline.ui
)
Expand Down
94 changes: 94 additions & 0 deletions src/GuiBase/KeyFrameEditor/KeyFrameEditor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include "ui_KeyFrameEditor.h"
#include <GuiBase/KeyFrameEditor/KeyFrameEditor.hpp>
#include <GuiBase/KeyFrameEditor/KeyFrameEditorFrame.hpp>

#include <Core/Animation/KeyFramedValue.hpp>

#include <fstream>
#include <iostream>

#include <QFileDialog>
#include <QResizeEvent>

namespace Ra::GuiBase {

KeyFrameEditor::KeyFrameEditor( Scalar maxTime, QWidget* parent ) :
QDialog( parent ),
ui( new Ui::KeyFrameEditor ) {
ui->setupUi( this );

// set sizePolicy to allow zoom in scrollArea
ui->scrollAreaWidgetContents->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Preferred );
// first draw of ruler with current width (default in Timeline.ui) of dialog
ui->scrollArea->onDrawRuler( width() - 2,
height() - 2 ); // left/right border width = 2 *1 pixel

// --- SET INTERNAL REFERENCES ---
ui->m_editorFrame->setEditorUi( ui );
ui->m_timeScale->setScrollArea( ui->scrollArea );
ui->m_valueScale->setScrollArea( ui->scrollArea );
ui->m_frameScale->setScrollArea( ui->scrollArea );
ui->m_frameScale->setEditorFrame( ui->m_editorFrame );

// set duration
ui->m_editorFrame->setDuration( maxTime );

// --- CREATE INTERNAL CONNECTIONS ---
connect( ui->m_editorFrame, &KeyFrameEditorFrame::updated, [=]() { update(); } );

// --- CONNECT INTERNAL SIGNALS TO EXTERNAL SIGNALS ---
connect( ui->m_editorFrame,
&KeyFrameEditorFrame::cursorChanged,
this,
&KeyFrameEditor::cursorChanged );
connect( ui->m_editorFrame,
&KeyFrameEditorFrame::keyFrameChanged,
this,
&KeyFrameEditor::keyFrameChanged );
connect( ui->m_editorFrame,
&KeyFrameEditorFrame::keyFrameAdded,
this,
&KeyFrameEditor::keyFrameAdded );
connect( ui->m_editorFrame,
&KeyFrameEditorFrame::keyFrameDeleted,
this,
&KeyFrameEditor::keyFrameDeleted );
connect( ui->m_editorFrame,
&KeyFrameEditorFrame::keyFrameMoved,
this,
&KeyFrameEditor::keyFrameMoved );
connect( ui->m_editorFrame,
&KeyFrameEditorFrame::keyFramesMoved,
this,
&KeyFrameEditor::keyFramesMoved );
}

KeyFrameEditor::~KeyFrameEditor() {
delete ui;
}

void KeyFrameEditor::onChangeCursor( Scalar time ) {
ui->m_editorFrame->onChangeCursor( time, false );
update();
}

void KeyFrameEditor::onChangeDuration( Scalar duration ) {
ui->m_editorFrame->setDuration( duration );
update();
}

void KeyFrameEditor::onUpdateKeyFrames( Scalar currentTime ) {
ui->m_editorFrame->onUpdateKeyFrames( currentTime );
}

void KeyFrameEditor::resizeEvent( QResizeEvent* event ) {

ui->scrollArea->onDrawRuler( event->size().width() - 2, event->size().height() - 2 );
}

void KeyFrameEditor::setKeyFramedValue( const std::string& name, KeyFrame* frame ) {
ui->m_valueName->setText( QString::fromStdString( name ) );
ui->m_editorFrame->setKeyFramedValue( frame );
}

} // namespace Ra::GuiBase
72 changes: 72 additions & 0 deletions src/GuiBase/KeyFrameEditor/KeyFrameEditor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#pragma once

#include <GuiBase/RaGuiBase.hpp>

#include <map>
#include <vector>

#include <QDialog>
#include <QGraphicsEllipseItem>
#include <QGraphicsLineItem>
#include <QGraphicsScene>

#include <Core/CoreMacros.hpp>

namespace Ra::Core::Animation {
class KeyFramedValueBase;
}

namespace Ui {
class KeyFrameEditor;
} // namespace Ui

namespace Ra::GuiBase {

class RA_GUIBASE_API KeyFrameEditor : public QDialog
{
Q_OBJECT
public:
using KeyFrame = Ra::Core::Animation::KeyFramedValueBase;
explicit KeyFrameEditor( Scalar maxTime = 0, QWidget* parent = nullptr );
~KeyFrameEditor() override;

/// Set the KeyFramedValue to edit.
void setKeyFramedValue( const std::string& name, KeyFrame* frame );

signals:
/// Emitted when the user changes the current time in the editor frame.
void cursorChanged( Scalar time );

/// Emitted when the user changes a keyframe's value in the editor frame.
void keyFrameChanged( size_t i );

/// Emitted when the user adds a keyframe to the KeyFramedValue in the editor frame.
void keyFrameAdded( Scalar time );

/// Emitted when the user removes a keyframe from the KeyFramedValue in the editor frame.
void keyFrameDeleted( size_t i );

/// Emitted when the user changes a keyframe's time in the editor frame.
void keyFrameMoved( size_t i, Scalar time1 );

/// Emitted when the user offsets keyframes time in the editor frame.
void keyFramesMoved( size_t first, Scalar offset );

public slots:
/// Update the editor frame to match the given time.
void onChangeCursor( Scalar time );

/// Update the editor frame to match the given duration.
void onChangeDuration( Scalar duration );

/// Update the editor frame to match the updated KeyFramedValue.
void onUpdateKeyFrames( Scalar currentTime );

protected:
void resizeEvent( QResizeEvent* ev ) override;

private:
Ui::KeyFrameEditor* ui {nullptr};
};

} // namespace Ra::GuiBase
Loading