Skip to content

Commit e68bf3c

Browse files
author
hoshiryu
committed
Add keyframe editor ;
1 parent 709c812 commit e68bf3c

17 files changed

+3536
-6
lines changed

Diff for: cmake/filelistGuiBase.cmake

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
set( guibase_sources
22
BaseApplication.cpp
3+
KeyFrameEditor/KeyFrameEditor.cpp
4+
KeyFrameEditor/KeyFrameEditorFrame.cpp
5+
KeyFrameEditor/KeyFrameEditorFrameScale.cpp
6+
KeyFrameEditor/KeyFrameEditorScrollArea.cpp
7+
KeyFrameEditor/KeyFrameEditorTimeScale.cpp
8+
KeyFrameEditor/KeyFrameEditorValueScale.cpp
39
SelectionManager/SelectionManager.cpp
410
Timeline/HelpDialog.cpp
511
Timeline/TimelineFrameSelector.cpp
@@ -30,6 +36,12 @@ set( guibase_headers
3036
BaseApplication.hpp
3137
MainWindowInterface.hpp
3238
RaGuiBase.hpp
39+
KeyFrameEditor/KeyFrameEditor.h
40+
KeyFrameEditor/KeyFrameEditorFrame.h
41+
KeyFrameEditor/KeyFrameEditorFrameScale.h
42+
KeyFrameEditor/KeyFrameEditorScrollArea.h
43+
KeyFrameEditor/KeyFrameEditorTimeScale.h
44+
KeyFrameEditor/KeyFrameEditorValueScale.h
3345
SelectionManager/SelectionManager.hpp
3446
Timeline/HelpDialog.hpp
3547
Timeline/Configurations.h
@@ -63,6 +75,7 @@ set( guibase_inlines
6375
)
6476

6577
set( guibase_uis
78+
KeyFrameEditor/KeyFrameEditor.ui
6679
Timeline/HelpDialog.ui
6780
Timeline/Timeline.ui
6881
)

Diff for: src/GuiBase/KeyFrameEditor/KeyFrameEditor.cpp

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#include "ui_KeyFrameEditor.h"
2+
#include <GuiBase/KeyFrameEditor/KeyFrameEditor.h>
3+
#include <GuiBase/KeyFrameEditor/KeyFrameEditorFrame.h>
4+
5+
#include <Core/Animation/KeyFramedValue.hpp>
6+
7+
#include <fstream>
8+
#include <iostream>
9+
10+
#include <QFileDialog>
11+
#include <QResizeEvent>
12+
13+
namespace Ra::GuiBase {
14+
15+
KeyFrameEditor::KeyFrameEditor( Scalar maxTime, QWidget* parent ) :
16+
QDialog( parent ),
17+
ui( new Ui::KeyFrameEditor ) {
18+
ui->setupUi( this );
19+
20+
// set sizePolicy to allow zoom in scrollArea
21+
ui->scrollAreaWidgetContents->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Preferred );
22+
// first draw of ruler with current width (default in Timeline.ui) of dialog
23+
ui->scrollArea->onDrawRuler( width() - 2,
24+
height() - 2 ); // left/right border width = 2 *1 pixel
25+
26+
// --- SET INTERNAL REFERENCES ---
27+
ui->m_editorFrame->setEditorUi( ui );
28+
ui->m_timeScale->setScrollArea( ui->scrollArea );
29+
ui->m_valueScale->setScrollArea( ui->scrollArea );
30+
ui->m_frameScale->setScrollArea( ui->scrollArea );
31+
ui->m_frameScale->setEditorFrame( ui->m_editorFrame );
32+
33+
// set duration
34+
ui->m_editorFrame->setDuration( maxTime );
35+
36+
// --- CREATE INTERNAL CONNECTIONS ---
37+
connect( ui->m_editorFrame, &KeyFrameEditorFrame::updated, [=]() { update(); } );
38+
39+
// --- CONNECT INTERNAL SIGNALS TO EXTERNAL SIGNALS ---
40+
connect( ui->m_editorFrame,
41+
&KeyFrameEditorFrame::cursorChanged,
42+
this,
43+
&KeyFrameEditor::cursorChanged );
44+
connect( ui->m_editorFrame,
45+
&KeyFrameEditorFrame::keyFrameChanged,
46+
this,
47+
&KeyFrameEditor::keyFrameChanged );
48+
connect( ui->m_editorFrame,
49+
&KeyFrameEditorFrame::keyFrameAdded,
50+
this,
51+
&KeyFrameEditor::keyFrameAdded );
52+
connect( ui->m_editorFrame,
53+
&KeyFrameEditorFrame::keyFrameDeleted,
54+
this,
55+
&KeyFrameEditor::keyFrameDeleted );
56+
connect( ui->m_editorFrame,
57+
&KeyFrameEditorFrame::keyFrameMoved,
58+
this,
59+
&KeyFrameEditor::keyFrameMoved );
60+
connect( ui->m_editorFrame,
61+
&KeyFrameEditorFrame::keyFramesMoved,
62+
this,
63+
&KeyFrameEditor::keyFramesMoved );
64+
}
65+
66+
KeyFrameEditor::~KeyFrameEditor() {
67+
delete ui;
68+
}
69+
70+
void KeyFrameEditor::onChangeCursor( Scalar time ) {
71+
ui->m_editorFrame->onChangeCursor( time, false );
72+
update();
73+
}
74+
75+
void KeyFrameEditor::onChangeDuration( Scalar duration ) {
76+
ui->m_editorFrame->setDuration( duration );
77+
update();
78+
}
79+
80+
void KeyFrameEditor::onUpdateKeyFrames( Scalar currentTime ) {
81+
ui->m_editorFrame->onUpdateKeyFrames( currentTime );
82+
}
83+
84+
void KeyFrameEditor::resizeEvent( QResizeEvent* event ) {
85+
86+
ui->scrollArea->onDrawRuler( event->size().width() - 2, event->size().height() - 2 );
87+
}
88+
89+
void KeyFrameEditor::setKeyFramedValue( const std::string& name, KeyFrame* frame ) {
90+
ui->m_valueName->setText( QString::fromStdString( name ) );
91+
ui->m_editorFrame->setKeyFramedValue( frame );
92+
}
93+
94+
} // namespace Ra::GuiBase

Diff for: src/GuiBase/KeyFrameEditor/KeyFrameEditor.h

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#ifndef RADIUMENGINE_KEYFRAME_EDITOR_H
2+
#define RADIUMENGINE_KEYFRAME_EDITOR_H
3+
4+
#include <GuiBase/RaGuiBase.hpp>
5+
6+
#include <map>
7+
#include <vector>
8+
9+
#include <QDialog>
10+
#include <QGraphicsEllipseItem>
11+
#include <QGraphicsLineItem>
12+
#include <QGraphicsScene>
13+
14+
#include <Core/CoreMacros.hpp>
15+
16+
namespace Ra::Core::Animation {
17+
class KeyFramedValueBase;
18+
}
19+
20+
namespace Ui {
21+
class KeyFrameEditor;
22+
} // namespace Ui
23+
24+
namespace Ra::GuiBase {
25+
26+
class RA_GUIBASE_API KeyFrameEditor : public QDialog
27+
{
28+
Q_OBJECT
29+
public:
30+
using KeyFrame = Ra::Core::Animation::KeyFramedValueBase;
31+
explicit KeyFrameEditor( Scalar maxTime = 0, QWidget* parent = nullptr );
32+
~KeyFrameEditor() override;
33+
34+
/// Set the KeyFramedValue to edit.
35+
void setKeyFramedValue( const std::string& name, KeyFrame* frame );
36+
37+
signals:
38+
/// Emitted when the user changes the current time in the editor frame.
39+
void cursorChanged( Scalar time );
40+
41+
/// Emitted when the user changes a keyframe's value in the editor frame.
42+
void keyFrameChanged( Scalar time );
43+
44+
/// Emitted when the user adds a keyframe to the KeyFramedValue in the editor frame.
45+
void keyFrameAdded( Scalar time );
46+
47+
/// Emitted when the user removes a keyframe from the KeyFramedValue in the editor frame.
48+
void keyFrameDeleted( Scalar time );
49+
50+
/// Emitted when the user changes a keyframe's time in the editor frame.
51+
void keyFrameMoved( Scalar time0, Scalar time1 );
52+
53+
/// Emitted when the user offsets keyframes time in the editor frame.
54+
void keyFramesMoved( Scalar time, Scalar offset );
55+
56+
public slots:
57+
/// Update the editor frame to match the given time.
58+
void onChangeCursor( Scalar time );
59+
60+
/// Update the editor frame to match the given duration.
61+
void onChangeDuration( Scalar duration );
62+
63+
/// Update the editor frame to match the updated KeyFramedValue.
64+
void onUpdateKeyFrames( Scalar currentTime );
65+
66+
protected:
67+
void resizeEvent( QResizeEvent* ev ) override;
68+
69+
private:
70+
Ui::KeyFrameEditor* ui;
71+
};
72+
73+
} // namespace Ra::GuiBase
74+
75+
#endif // RADIUMENGINE_KEYFRAME_EDITOR_H

0 commit comments

Comments
 (0)