/***************************************************************************
                          dcwidget.h  -  description
                             -------------------
    begin                : Don Mai 30 2002
    copyright            : (C) 2002 by Mathias Küster
    email                : mathen@users.berlios.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef DCWIDGET_H
#define DCWIDGET_H

#include <q3listview.h>
#include <QProgressBar>
//Added by qt3to4:
#include <QPixmap>

#include <dclib/cmessagehandler.h>

/**
  *@author Mathias Küster
  */

class DC_QNumericSortItem {
public:
	/** */
	int mycol;
	/** */
	ulonglong myvalue;
	/** construtor */
	DC_QNumericSortItem() { mycol=-1;myvalue=0; };
	/** destructor */
	virtual ~DC_QNumericSortItem() {};

	/** */
	int mycompare( ulonglong v1, ulonglong v2, int col, bool ascending ) const;
};

class DC_QListViewItem : public Q3ListViewItem, public DC_QNumericSortItem {
public:
	/** construtor */
	DC_QListViewItem( Q3ListView * parent ) : Q3ListViewItem(parent) {};
	/** construtor */
	DC_QListViewItem( Q3ListViewItem * parent ) : Q3ListViewItem(parent) {};
	/** destructor */
	virtual ~DC_QListViewItem() {};

	/** */
	virtual int compare( Q3ListViewItem * i, int col, bool ascending ) const;
	/** */
	virtual QString key( int column, bool ascending ) const;
};

class DC_QSearchListViewItem : public Q3ListViewItem {
public:
	/** construtor */
	DC_QSearchListViewItem( Q3ListView * parent ) : Q3ListViewItem(parent) {
		p_data = 0;
	};
	/** construtor */
	DC_QSearchListViewItem( Q3ListViewItem * parent ) : Q3ListViewItem(parent) {};
	/** destructor */
	virtual ~DC_QSearchListViewItem() {};

	/** */
	void * p_data;
};

class DC_ListResult : public DC_QListViewItem {
public:
        /** construtor */
        DC_ListResult ( Q3ListView * parent ) : DC_QListViewItem (parent) { };
        /** construtor */
        DC_ListResult ( Q3ListViewItem * parent ) : DC_QListViewItem (parent) { };
        /** destructor */
        virtual ~DC_ListResult() { };

        /** */
        void paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int align );
	/** Re-implemented to fix sorting by slots */
	QString key( int n, bool ascending ) const;
};

class DC_QCheckListItem : public Q3CheckListItem, public DC_QNumericSortItem {
public:
	/** construtor */
	DC_QCheckListItem( Q3ListView *parent, const QString &text, const QPixmap & );
	/** construtor */
	DC_QCheckListItem( Q3ListView *parent, const QString &text, Type tt = Controller );
	/** destructor */
	virtual ~DC_QCheckListItem() {};

	/** */
	virtual void paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int align );
	/** */
	virtual int compare( Q3ListViewItem * i, int col, bool ascending ) const;
	/** */
	virtual QString key( int column, bool ascending ) const;
	/** */
	QColor colorText;
	/** */
	bool m_bSortTop;
};

#define USERLISTITEM_MAX_COLUMNS 1

class DC_UserListItem : public DC_QCheckListItem {
public:
	/** construtor */
	DC_UserListItem( Q3ListView *parent, const QString &text, const QPixmap & );
	/** construtor */
	DC_UserListItem( Q3ListView *parent, const QString &text, Type tt = Controller );
	/** destructor */
	virtual ~DC_UserListItem() {};

	/** */
	virtual void setText( int column, const QString & text );
	/** */
	virtual int compare( Q3ListViewItem * i, int col, bool ascending ) const;

	/** */
	void setCompareValue( int column, const QString & text );
	/** */
	ulonglong m_nCompareValue[USERLISTITEM_MAX_COLUMNS];
};

class DC_QProgressListItem : public Q3ListViewItem
{
public:
	/** */
	enum Type { RadioButton, CheckBox, Controller, ProgressBar };
	/** construtor */
	DC_QProgressListItem( DC_QProgressListItem *parent, const QString &text,
			      int co = 0, Type = ProgressBar );
	/** construtor */
	DC_QProgressListItem( Q3ListViewItem *parent, const QString &text,
			      int co = 0, Type = ProgressBar );
	/** construtor */
	DC_QProgressListItem( Q3ListView *parent, const QString &text,
			      int co = 0, Type = ProgressBar );
	/** destructor */
	virtual ~DC_QProgressListItem();
	
	/** */
	void paintCell( QPainter *,  const QColorGroup & cg,
			int column, int width, int alignment );
	/** */
	virtual void paintFocus( QPainter *, const QColorGroup & cg,
					const QRect & r );
	/** */
	int width( const QFontMetrics&, const Q3ListView*, int column) const;
	/** */
	void setup();

	/** */
	Type type() const { return myType; }
	/** */
	QString text() const { return Q3ListViewItem::text( 0 ); }
	/** */
	QString text( int n ) const { return Q3ListViewItem::text( n ); }
	/** */
	int rtti() const;
	/** */
	static int RTTI;
	/** */
	void SetProgressEnable( bool b ) { m_bProgressEnable=b; }
	/** */
	void setProgress( int i );
	/** */
	void resetProgress();
	/** Reimplemented so sorting is by download/upload + percentage complete */
	QString key( int n, bool ascending ) const;
	/** Set transfer state letter to d for download, u for upload etc. for sorting */
	void setTransferState( QString s );

private:
	/** */
	void init();
	/** */
	Type myType;
	/** */
	DC_QProgressListItem *exclusive;
	/** */
	int m_nColumn;
	/** */
	bool m_bProgressEnable;
	/** */
	QProgressBar * m_ProgressBar;
	/** Needed for sorting transfers by upload/download */
	QString sTransferState;
};

/** Filelist browser list view item */
class DC_FBListViewItem: public DC_QListViewItem {
public:
	/** constructor with view parent */
	DC_FBListViewItem( Q3ListView * parent ) : DC_QListViewItem( parent ) { };
	/** constructor with item parent */
	DC_FBListViewItem( Q3ListViewItem * parent ) : DC_QListViewItem( parent ) { } ;
	/** destructor */
	virtual ~DC_FBListViewItem() { };
	
	/** re-implemented to use sort top */
	virtual int compare( Q3ListViewItem * i, int col, bool ascending ) const;
	/** should this be above other items? */
	bool m_bSortTop;
};

#endif
