Commit c2dc2f2c authored by Jan Möbius's avatar Jan Möbius

Added animation delete button

Fixed bug, where combo box ui update crashed when animations where added or deleted  (still more tests needed!)



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@13093 383ad7c9-94d9-4d36-a494-682f7c89f535
parent ef858c8d
......@@ -96,8 +96,10 @@ void SkeletalAnimationPlugin::initializePlugin()
connect( pToolbox_->sbFPS, SIGNAL(valueChanged ( int )), this, SLOT( changeFPS(int) ) );
connect( pToolbox_->cbSkipFrames, SIGNAL(stateChanged(int)), this, SLOT(slotSkipFramesChanged(int)) );
connect( pToolbox_->pbAddAnimation, SIGNAL(clicked()), this, SLOT(slotAddAnimation()) );
connect( pToolbox_->pbDeleteAnimation, SIGNAL(clicked()), this, SLOT(slotDeleteAnimation()) );
pToolbox_->pbAddAnimation->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"addAnimation.png") );
pToolbox_->pbDeleteAnimation->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"deleteAnimation.png") );
pToolbox_->cbMethod->addItem("Linear Blend Skinning");
pToolbox_->cbMethod->addItem("Dual Quaternion Blend Skinning");
......@@ -367,7 +369,7 @@ void SkeletalAnimationPlugin::slotObjectUpdated( int _id, const UpdateType /*_ty
if ( !newHandle.isValid() ) //refPose
pToolbox_->cbAnimation->setCurrentIndex( 0 );
else
pToolbox_->cbAnimation->setCurrentIndex( newHandle.animationIndex()+1 );
setComboBoxPosition(newHandle.animationIndex());
}
//check if animationCount changed
......@@ -658,10 +660,15 @@ void SkeletalAnimationPlugin::UpdateUI()
// create the reference pose
pToolbox_->cbAnimation->addItem("Reference Pose");
// create the other poses
for(unsigned int i = 0; i < skeleton->animationCount(); ++i)
pToolbox_->cbAnimation->addItem(skeleton->animationName(i).c_str());
pToolbox_->cbAnimation->setCurrentIndex(hAni.animationIndex() + 1);
Skeleton::AnimationIterator animations = skeleton->animationsBegin();
while ( animations ) {
AnimationHandle anim = *animations;
pToolbox_->cbAnimation->addItem(skeleton->animationName(anim.animationIndex()).c_str(),QVariant(anim.animationIndex()));
++animations;
}
setComboBoxPosition(hAni.animationIndex());
// get the number of frames in the animation
pToolbox_->hsFrame->setEnabled(true);
......@@ -932,7 +939,32 @@ void SkeletalAnimationPlugin::slotAddAnimation()
emit updatedObject(activeSkeletons_[0], UPDATE_ALL);
//select the new animation
pToolbox_->cbAnimation->setCurrentIndex( pToolbox_->cbAnimation->count()-1 );
setComboBoxPosition(handle.animationIndex());
}
}
//------------------------------------------------------------------------------
void SkeletalAnimationPlugin::slotDeleteAnimation()
{
int iAnimation = pToolbox_->cbAnimation->currentIndex();
unsigned int animationIndex = pToolbox_->cbAnimation->itemData(iAnimation).toUInt();
if ( iAnimation == 0 ) {
emit log(LOGERR,"Reference pose could never be removed!");
} else {
pToolbox_->cbAnimation->removeItem(iAnimation);
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS, DataType(DATA_SKELETON)) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
SkeletonObject* skeletonObject = dynamic_cast<SkeletonObject*>(*o_it);
Skeleton* skeleton = PluginFunctions::skeleton(skeletonObject);
skeleton->removeAnimation(AnimationHandle(animationIndex));
}
UpdateUI();
}
}
......@@ -941,19 +973,40 @@ void SkeletalAnimationPlugin::slotAddAnimation()
/**
* @brief Returns a handle describing the current frame in the active animation
*
* This information is derived from the corresponding combobox and slider.
* This information is derived from the corresponding combo box and slider.
*/
AnimationHandle SkeletalAnimationPlugin::currentAnimationHandle()
{
int iAnimation = pToolbox_->cbAnimation->currentIndex();
unsigned int animationId = pToolbox_->cbAnimation->itemData(iAnimation).toUInt();
if(iAnimation == 0)
return AnimationHandle(); //This will be the reference pose, i.e. an empty animation
else if(iAnimation > 0)
return AnimationHandle(iAnimation - 1, pToolbox_->hsFrame->value());
return AnimationHandle(animationId, pToolbox_->hsFrame->value());
return AnimationHandle(); // should not happen
}
//------------------------------------------------------------------------------
/**
* @brief Sets the animations combo box to the right entry
*
*/
void SkeletalAnimationPlugin::setComboBoxPosition(unsigned int _animationIndex)
{
for ( int i = 0 ; i < pToolbox_->cbAnimation->count(); ++i ) {
unsigned int animationId = pToolbox_->cbAnimation->itemData(i).toUInt();
if ( animationId == _animationIndex ) {
pToolbox_->cbAnimation->setCurrentIndex(i);
return;
}
}
}
//------------------------------------------------------------------------------
Q_EXPORT_PLUGIN2(skeletalAnimationplugin, SkeletalAnimationPlugin);
......@@ -125,6 +125,7 @@ public slots:
//@}
void UpdateUI();
void setComboBoxPosition(unsigned int _animationIndex);
void checkObjectSelection();
private slots:
......@@ -142,6 +143,7 @@ private slots:
void slotFrameChanged(int /*_index*/);
void slotSkipFramesChanged(int _state);
void slotAddAnimation();
void slotDeleteAnimation();
void animate();
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>328</width>
<height>283</height>
<width>319</width>
<height>284</height>
</rect>
</property>
<property name="windowTitle">
......@@ -65,6 +65,13 @@
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QToolButton" name="pbDeleteAnimation">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment