/***************************************************************************
 *   Copyright (C) 2004 by Hans Oischinger                                 *
 *   hans.oischinger@kdemail.net                                           *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA.             *
 ***************************************************************************/
#ifndef TIMELINEVIEW_H
#define TIMELINEVIEW_H

#include <qframe.h>
#include <qptrdict.h>
#include "visitors/visitor.h"
#include "core/coreinterfaces.h"

class ElementNode;
class AnimateTransformElement;
class AnimateLengthElement;
class AnimateNumberElement;
class QPoint;
class AnimationLabel;
/**
This class represents a visual TimeLine showing the AnimationElementItems on it.
It should always be used as a child of Timelinedocker which controls the visible 
Animationlabel via clear() and showElement()
@author Hans Oischinger
*/
class TimelineView : public QFrame,
      public Visitor,
      public ElementListenerInterface,
      public ElementSelectionListenerInterface
{
  Q_OBJECT
public:
  TimelineView(QWidget *parent = 0, const char *name = 0);
  ~TimelineView();

  /**
   * Hides all widgets on the timeline
   */
  void clear();

  /**
   * Make the AnimationLabel for Element e visible at the given ypos
   */
  void showElement(ElementNode *e, int ypos);

  // Visitor methods
  virtual bool visit( AnimateTransformElement& element );
  virtual bool visit( AnimateLengthElement& element );
  virtual bool visit( AnimateNumberElement& element );

  // Listener methods
  void onElementInserted( ElementNode* );
  void onElementRemoved( ElementNode* );
  void onElementModified( ElementNode* );
  void onSelectionModified();

  double getTimeFromPX(int px);

signals:
  void timeSliderChanged(double time);

protected:
  void paintEvent( QPaintEvent* );
  void mousePressEvent( QMouseEvent* );
  void mouseMoveEvent( QMouseEvent* );
  void timelineClicked( const QPoint& p );

  void appendAnimLabel( ElementNode* e, bool addNeighbours=false );

private:
  QPtrDict<AnimationLabel> m_elementsToLabels;
  int m_currentTLPos;
  int m_PXPerSecond;
};


#include <qlabel.h>
class AnimateElement;
class AnimationLabel : public QLabel
{
public:
  AnimationLabel(AnimateElement* element, TimelineView *parent);
  ~AnimationLabel() {}

  AnimateElement* element() const { return m_element; }

  void mousePressEvent ( QMouseEvent * e );
  void mouseReleaseEvent ( QMouseEvent * e );
  void mouseMoveEvent ( QMouseEvent * e );

protected:
  TimelineView *m_parentTLView;
  AnimateElement* m_element;
  bool m_dragactive;
  int m_xoffset;
  bool m_resizeactive;
};

#endif
