|
| 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 |
0 commit comments