/****************************************************************************
**
** Copyright (C) 1992-2004 Trolltech AS. All rights reserved.
**
** This file is part of the item views module of the Qt Toolkit.
**
** Licensees holding valid Qt Preview licenses may use this file in
** accordance with the Qt Preview License Agreement provided with the
** Software.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
** information about Qt Commercial License Agreements.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/

#ifndef QABSTRACTITEMDELEGATE_H
#define QABSTRACTITEMDELEGATE_H

#include <qobject.h>
#include <qstyleoption.h>

class QPainter;
class QModelIndex;
class QAbstractItemModel;

class Q_GUI_EXPORT QAbstractItemDelegate : public QObject
{
    Q_OBJECT

public:
    QAbstractItemDelegate(QObject *parent = 0);
    virtual ~QAbstractItemDelegate();

    // painting
    virtual void paint(QPainter *painter, const QStyleOptionViewItem &option,
                       const QAbstractItemModel *model, const QModelIndex &index) const = 0;

    virtual QSize sizeHint(const QStyleOptionViewItem &option, const QAbstractItemModel *model,
                           const QModelIndex &index) const = 0;

    // editing
    virtual QWidget *editor(QWidget *parent,
                            const QStyleOptionViewItem &option,
                            const QAbstractItemModel *model,
                            const QModelIndex &index);

    virtual void releaseEditor(QWidget *editor);

    virtual void setEditorData(QWidget *editor,
                               const QAbstractItemModel *model,
                               const QModelIndex &index) const;

    virtual void setModelData(QWidget *editor,
                              QAbstractItemModel *model,
                              const QModelIndex &index) const;

    virtual void updateEditorGeometry(QWidget *editor,
                                      const QStyleOptionViewItem &option,
                                      const QAbstractItemModel* model,
                                      const QModelIndex &index) const;

    // events for non-widget editors
    virtual bool editorEvent(QEvent *e, QAbstractItemModel* model, const QModelIndex &index);

signals:
    void commitData(QWidget *editor);
    void doneEditing(QWidget *editor);

protected:
    QString ellipsisText(const QFontMetrics &fontMetrics, int width, int align,
                         const QString &org) const;
};

#endif
