/***************************************************************************
 *   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 ATTRIBUTELISTVIEW_H
#define ATTRIBUTELISTVIEW_H

#include "core/coreinterfaces.h"
#include <klistview.h>

class Attribute;
class ElementNode;
class AttributeListViewItem;
/**
@author Hans Oischinger
*/
class AttributeListView : public KListView, public ElementListenerInterface, public ElementSelectionListenerInterface
{
  Q_OBJECT
public:
  AttributeListView(QWidget *parent = 0, const char *name = 0);
  ~AttributeListView();

  void onElementInserted( ElementNode* );
  void onElementRemoved( ElementNode* );
  void onElementModified( ElementNode* );

  void onSelectionModified();

public slots:
  void setElement(ElementNode* );
  virtual void clear();

protected slots:
  void onCurrentChanged( QListViewItem* );

protected:
  ElementNode* m_element;
  AttributeListViewItem* m_lastSelectedItem;
};


class QHBox;
/**
AttributeListViewItem Base Class
@author Hans Oischinger
*/
class AttributeListViewItem : public KListViewItem, public QObject
{
public:
  AttributeListViewItem( ElementNode *holder, Attribute* attribute, QListView *parent, QListViewItem *after );
  ~AttributeListViewItem();

  virtual Attribute* attribute() const =0;

  /**
   * Show the Editor Widget
   */
  virtual void showEditor();

  /**
   * Hide the Editor Widget
   */
  virtual void hideEditor();

protected:
  /**
   * Called when item is being clicked or space key pressed
   */
  virtual void activate();

  /**
   * Set the position of the Editor according to the ListViewItemPos
   */
  virtual void placeEditWidget();

  /**
   * Create a Containerwidget and place the editor widget and a SET-Button onto it
   * @param text Text for the button
   * @return A Containerwidget for the editor and button
   */
  virtual QWidget* createEditWidget();

  ElementNode *m_element; // The Element our attribute belongs to
  QHBox* m_editorContainer;
  QWidget* m_editor;  // The edit widget itself... must be set by an inherited class
};


class LengthAttribute;
class AnimatedLength;
class KLineEdit;
/**
LengthListViewItem Class
@author Hans Oischinger
*/
class LengthListViewItem : public AttributeListViewItem
{
  Q_OBJECT
public:
  LengthListViewItem( ElementNode *holder, LengthAttribute* attribute,
                      QListView *parent = 0, QListViewItem *after = 0 );
  /**
   * Call this if you want to be able to record animation with the editor
   * @param holder Element that posesses the Attribute
   * @param attribute Animated attribute that contains the baseVal or animVal to be displayed
   * @param showAnimVal if true animVal will be used, else baseVal (default)
   */
  LengthListViewItem( ElementNode *holder, AnimatedLength* attribute, bool showAnimVal = false,
                      QListView *parent = 0, QListViewItem *after = 0 );
  ~LengthListViewItem();

  virtual Attribute* attribute() const;
  virtual void showEditor();

protected slots:
  void slotEdited();

protected:
  void readFromAttr();

  LengthAttribute* m_attr;
  AnimatedLength* m_animAttr;
  KLineEdit *m_lineEdit;
};


class Number;
class AnimatedNumber;
/**
NumberListViewItem
@author Hans Oischinger
 */
class NumberListViewItem : public AttributeListViewItem
{
  Q_OBJECT
public:
  NumberListViewItem( ElementNode *holder, Number* attribute, QListView *parent, QListViewItem *after );
  /**
   * Call this if you want to be able to record animation with the editor
   * @param holder Element that posesses the Attribute
   * @param attribute Animated attribute that contains the baseVal or animVal to be displayed
   * @param showAnimVal if true animVal will be used, else baseVal (default)
   */
  NumberListViewItem( ElementNode *holder, AnimatedNumber* attribute, bool showAnimVal = false,
                      QListView *parent = 0, QListViewItem *after = 0 );
  ~NumberListViewItem();

  virtual Attribute* attribute() const;
  virtual void showEditor();

protected slots:
  void slotEdited();

protected:
  void readFromAttr();

  Number* m_attr;
  AnimatedNumber* m_animAttr;
  KLineEdit *m_lineEdit;
};


class FillAttribute;
/**
FillAttrListViewItem
@author Hans Oischinger
 */
class FillAttrListViewItem: public AttributeListViewItem
{
  Q_OBJECT
public:
  FillAttrListViewItem( ElementNode *holder, FillAttribute* attribute, QListView *parent, QListViewItem *after );
  ~FillAttrListViewItem();

  virtual Attribute* attribute() const;

protected:
  FillAttribute* m_attr;
};


class StrokeAttribute;
/**
StrokeAttrListViewItem
@author Hans Oischinger
 */
class StrokeAttrListViewItem: public AttributeListViewItem
{
  Q_OBJECT
public:
  StrokeAttrListViewItem( ElementNode *holder, StrokeAttribute* attribute, QListView *parent, QListViewItem *after );
  ~StrokeAttrListViewItem();

  virtual Attribute* attribute() const;

protected:
  StrokeAttribute* m_attr;
};


class ColorAttribute;
class AnimatedColor;
class KColorButton;
/**
ColorListViewItem
@author Hans Oischinger
 */
class ColorListViewItem: public AttributeListViewItem
{
  Q_OBJECT
public:
  ColorListViewItem( ElementNode *holder, ColorAttribute* attribute, QListView *parent, QListViewItem *after );
  /**
   * Call this if you want to be able to record animation with the editor
   * @param holder Element that posesses the Attribute
   * @param attribute Animated attribute that contains the baseVal or animVal to be displayed
   * @param showAnimVal if true animVal will be used, else baseVal (default)
   */
  ColorListViewItem( ElementNode *holder, AnimatedColor* attribute, bool showAnimVal = false,
                      QListView *parent = 0, QListViewItem *after = 0 );
  ~ColorListViewItem();

  virtual Attribute* attribute() const;
  virtual void showEditor();

protected slots:
  void slotEdited(const QColor &color);

protected:
  void readFromAttr();

  ColorAttribute* m_attr;
  AnimatedColor *m_animAttr;
  KColorButton *m_colorButton;
};


class Transform;
/**
TransformListViewItem
@author Hans Oischinger
*/
class TransformListViewItem : public AttributeListViewItem
{
  Q_OBJECT
public:
  TransformListViewItem( ElementNode *holder, Transform* attribute, QListView *parent, QListViewItem *after );
  ~TransformListViewItem();

  virtual Attribute* attribute() const;

protected:
  Transform* m_attr;
};


class Enumeration;
/**
EnumListViewItem
@author Hans Oischinger
 */
class EnumListViewItem : public AttributeListViewItem
{
  Q_OBJECT
public:
  EnumListViewItem( ElementNode *holder, Enumeration* attribute, QListView *parent, QListViewItem *after );
  ~EnumListViewItem();

  virtual Attribute* attribute() const;

protected:
  Enumeration* m_attr;
};


class URIReference;
/**
URIRefListViewItem
@author Hans Oischinger
 */
class URIRefListViewItem : public AttributeListViewItem
{
  Q_OBJECT
public:
  URIRefListViewItem( ElementNode *holder, URIReference* attribute, QListView *parent, QListViewItem *after );
  ~URIRefListViewItem();

  virtual Attribute* attribute() const;

protected:
  URIReference* m_attr;
};


class TimeAttribute;
/**
URIRefListViewItem
@author Hans Oischinger
 */
class TimeListViewItem : public AttributeListViewItem
{
  Q_OBJECT
public:
  TimeListViewItem( ElementNode *holder, TimeAttribute* attribute, QListView *parent, QListViewItem *after);
  ~TimeListViewItem();

  virtual Attribute* attribute() const;

protected:
  TimeAttribute* m_attr;
};

#endif
