Logo Search packages:      
Sourcecode: kdenlive version File versions

bool TrackPanelKeyFrameFunction::mousePressed ( Gui::KTrackPanel panel,
QMouseEvent *  event 
) [virtual]

A mouse button has been pressed. Returns true if we want to handle this event

Implements TrackPanelFunction.

Definition at line 113 of file trackpanelkeyframefunction.cpp.

References Effect::addKeyFrame(), DocTrackBase::clipSelected(), Gui::KTrackPanel::documentTrackIndex(), Effect::effectDescription(), KdenliveDoc::framesPerSecond(), DocTrackBase::getClipAt(), Gui::KTrackPanel::hasDocumentTrackIndex(), Gui::KTimeLine::mapLocalToValue(), Effect::parameter(), DocTrackBase::selectClip(), and KdenliveDoc::track().

{
    bool result = false;
    m_offset = 0;
    if (panel->hasDocumentTrackIndex()) {
      DocTrackBase *track =
          m_document->track(panel->documentTrackIndex());
      if (track) {
          GenTime mouseTime((int)m_timeline->mapLocalToValue(event->x()), m_document->framesPerSecond());
          m_clipUnderMouse = track->getClipAt(mouseTime);
          if (m_clipUnderMouse) {
            if (!track->clipSelected(m_clipUnderMouse))
                track->selectClip(m_clipUnderMouse, true);

            // #TODO: Currently only works for the first effect
            uint effectIndex = 0;
            Effect *effect = m_clipUnderMouse->selectedEffect();
            if (!effect || !m_clipUnderMouse->hasEffect()) {
                kdDebug() << "////// ERROR, EFFECT NOT FOUND" << endl;
                return false;
            }

            if (effect->parameter(0)) {
                m_offset = panel->y() - 2000;
                uint count = effect->parameter(effectIndex)->numKeyFrames();
                double factor =  effect->effectDescription().parameter(effectIndex)->max();
                for (uint i = 0; i < count; i++) {
                  uint dx1 =(uint)( effect->parameter(effectIndex)->keyframe(i)-> time() *m_clipUnderMouse->cropDuration().frames(m_document->framesPerSecond()));

                  uint dy1;
                        if (effect->effectDescription().parameter(effectIndex)->
                            type() == "double")
                        dy1 = (uint)(panel->height() - panel->height() * effect->parameter(effectIndex)->keyframe(i)->toDoubleKeyFrame()->value() / factor);
                  else dy1 = panel->height() / 2;

                  if ((fabs(m_timeline->
                            mapValueToLocal(m_clipUnderMouse->
                              trackStart().frames(m_document->
                                  framesPerSecond()) + dx1) -
                            event->x()) < s_resizeTolerance)) {
                      m_selectedKeyframe = i;
                      m_selectedKeyframeValue = event->y();
                      return true;
                  }
                }
                double dx = (m_timeline->mapLocalToValue(event->x()) -
                  m_clipUnderMouse->trackStart().frames(m_document->
                      framesPerSecond())) / m_clipUnderMouse->cropDuration().frames(m_document->framesPerSecond());
                m_refresh = true;
                if (effect->effectDescription().parameter(effectIndex)->                           type() == "double")
                m_selectedKeyframe =
                  effect->addKeyFrame(effectIndex, dx, (panel->height() - (event->y() - m_offset)) * factor / panel->height());
                else m_selectedKeyframe = effect->addKeyFrame(effectIndex, dx);


                //double dy1 = 100 - ((event->y() - m_offset)* 100 / panel->height());

                //effect->parameter(effectIndex)->interpolateKeyFrame(0.7)->value());

                return true;

            }
          }
      }
    }
    return result;
}


Generated by  Doxygen 1.6.0   Back to index