/****************************************************************************
** $Id: quickqtwidgets.h  beta1   edited Dec 10 13:07 $
**
** Copyright (C) 2001-2002 Trolltech AS.  All rights reserved.
**
** This file is part of the Qt Script for Applications framework (QSA).
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding a valid QSA Beta Evaluation Version license may use
** this file in accordance with the QSA Beta Evaluation Version License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
**   information about QSA Commercial License Agreements.
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
*****************************************************************************/

#ifndef QUICKQTWIDGETS_H
#define QUICKQTWIDGETS_H

#include "quickdispatchobject.h"
#include <qobject.h>
#include <qlistview.h>
#include <qlistbox.h>

class QWidget;
class QDateEdit;
class QTable;
class QWidgetFactory;
class QPopupMenu;
class QLayout;
class QWidgetStack;
class QHBoxLayout;
class QVBoxLayout;
class QListBox;
class QComboBox;
class QTextEdit;

class QuickWidgetInterface : public QObject
{
    Q_OBJECT
    Q_PROPERTY( int x READ x WRITE setX )
    Q_PROPERTY( int y READ y WRITE setY )
    Q_PROPERTY( int width READ width WRITE setWidth )
    Q_PROPERTY( int height READ height WRITE setHeight )

public:
    QuickWidgetInterface( QWidget *wid );

    void setX( int x );
    void setY( int y );
    void setWidth( int w );
    void setHeight( int h );
    int x() const;
    int y() const;
    int width() const;
    int height() const;

signals:
    void mousePressed( int x, int y, int button );
    void mouseMoved( int x, int y, int state );
    void mouseReleased( int x, int y, int button );
    void mouseDoubleClicked( int x, int y, int button );
    void keyPressed( int key, int ascii, int state, const QString &text );
    void wheelRotated( int x, int y, int delta, int state );
    void resized( int oldWidth, int oldHeight );
    void init();
    void shown();
    void hidden();
    void closed();

public slots:
    QObjectList *children( bool recursive ) const;
    QObject *child( const QString &name ) const;


protected:
    bool eventFilter( QObject *, QEvent *e );

private:
    QWidget *wid;
    bool inited;

};

class QuickWidgetStackInterface : public QObject
{
    Q_OBJECT

public:
    QuickWidgetStackInterface( QWidgetStack *m );

public slots:
    void addWidget( QWidget *widget, int id );
    void removeWidget( QWidget *widget );
    QWidget *widget( int id ) const;
    int id( QWidget *widget ) const;
    QWidget *visibleWidget() const;

private:
    QWidgetStack *widgetstack;

};

class QObjectListPtr : public QuickPtrDispatchObject
{
    Q_OBJECT
    Q_PROPERTY( int count READ count )

public:
    QObjectListPtr( QObjectList *l );
    int count() const;

public slots:
    QObject *at( int i ) const;

private:
    QObjectList *list() const;

};

class QuickHBoxLayoutInterface : public QObject
{
    Q_OBJECT
    Q_PROPERTY( bool autoAdd READ autoAdd WRITE setAutoAdd )

public:
    QuickHBoxLayoutInterface( QHBoxLayout *l );

    bool autoAdd() const;

public slots:
    void addSpacing( int size );
    void addStretch( int stretch );
    void addWidget( QWidget *widget, int stretch );
    void setAutoAdd( bool b );

private:
    QHBoxLayout *lay;

};

class QuickVBoxLayoutInterface : public QObject
{
    Q_OBJECT
    Q_PROPERTY( bool autoAdd READ autoAdd WRITE setAutoAdd )

public:
    QuickVBoxLayoutInterface( QVBoxLayout *l );

    bool autoAdd() const;

public slots:
    void addSpacing( int size );
    void addStretch( int stretch );
    void addWidget( QWidget *widget, int stretch );
    void setAutoAdd( bool b );

private:
    QVBoxLayout *lay;

};

class QuickPopupMenuInterface : public QObject
{
    Q_OBJECT

public:
    QuickPopupMenuInterface( QPopupMenu *m );

public slots:
    int exec();
    int insertItem( const QString &text );
    int insertItem( const QString &text, int id );
    int insertItem( const QString &text, int id, int index );
    int insertSeparator();

private:
    QPopupMenu *popup;
};

class QuickDateEditInterface : public QObject
{
    Q_OBJECT

    Q_PROPERTY( int day READ day WRITE setDay )
    Q_PROPERTY( int month READ month WRITE setMonth )
    Q_PROPERTY( int year READ year WRITE setYear )

public:
    QuickDateEditInterface( QDateEdit *de );

    void setDay( int d );
    void setMonth( int m );
    void setYear( int y );
    int day() const;
    int month() const;
    int year() const;

private:
    QDateEdit *dateEdit;

};

class QuickTableInterface : public QObject
{
    Q_OBJECT

    Q_PROPERTY( int currentRow READ currentRow )
    Q_PROPERTY( int currentColumn READ currentColumn )

public:
    QuickTableInterface( QTable* t );

    int currentRow() const;
    int currentColumn() const;

public slots:
    QString text( int row, int col ) const;
    void setText( int row, int col, const QString &text );
    void setHorizontalLabel( int column, const QString &text );
    void setVerticalLabel( int column, const QString &text );

private:
    QTable *table;

};


class QuickListViewInterface : public QObject
{
    Q_OBJECT

public:
    QuickListViewInterface( QListView* lv );

public slots:
    QListViewItem *currentItem() const;
    QListViewItem *findItem( const QString &text, int column ) const;
    QListViewItem *firstChild() const;
    QListViewItem *lastItem() const;
    void ensureItemVisible( QListViewItem *item );
    void setSelected( QListViewItem *item, bool selected );
    void clearSelection();
    void setCurrentItem( QListViewItem *item );
    void setColumnWidth( int column, int w );
    void setSorting( int column );
    void sort();

private:
    QListView *listview;

};

class QuickListBoxInterface : public QObject
{
    Q_OBJECT

public:
    QuickListBoxInterface( QListBox* lb );

public slots:
    void insertItem( const QString &text, int index );
    void removeItem( int index );
    void changeItem( const QString &text, int index );
    void setSelected( int item, bool select );
    bool isSelected( int item ) const;
    void sort( bool ascending );
    void sort() { sort( TRUE ); }
    QString text( int index ) const;

private:
    QListBox *listbox;

};

class QuickComboBoxInterface : public QObject
{
    Q_OBJECT

public:
    QuickComboBoxInterface( QComboBox* lb );

public slots:
    void insertItem( const QString &text, int index );
    void removeItem( int index );
    void changeItem( const QString &text, int index );
    void setCurrentItem( int index );
    QString text( int index ) const;

private:
    QComboBox *combobox;

};

class QListViewItemPtr : public QuickPtrDispatchObject
{
    Q_OBJECT
    Q_PROPERTY( bool open READ isOpen WRITE setOpen )
    Q_PROPERTY( bool selected READ isSelected WRITE setSelected )

public:
    QListViewItemPtr( QListViewItem *i );

    bool isOpen() const;
    bool isSelected() const;

public slots:
    QString text( int column ) const;
    void setText( int column, const QString &text );
    QListViewItem *parent() const;
    void setOpen( bool open );
    void setSelected( bool selected );
    QListViewItem *itemAbove();
    QListViewItem *itemBelow();
    void remove();

private:
    QListViewItem *item() const;

};

class QListBoxItemPtr : public QuickPtrDispatchObject
{
    Q_OBJECT

public:
    QListBoxItemPtr( QListBoxItem *i );


public slots:
    QString text() const;

private:
    QListBoxItem *item() const;
};

class QuickToolTip : public QuickUnnamedObject
{
    Q_OBJECT

public:
    QuickToolTip();

public slots:
    void add( QWidget *widget, const QString &text );
    void remove( QWidget *widget );

};

class QuickWhatsThis : public QuickUnnamedObject
{
    Q_OBJECT

public:
    QuickWhatsThis();

public slots:
    void add( QWidget *widget, const QString &text );
    void remove( QWidget *widget );

};

class QuickWidgetFactory : public QuickUnnamedObject
{
    Q_OBJECT

public:
    QuickWidgetFactory();
    ~QuickWidgetFactory();

public slots:
    QWidget *createWidget( const QString &className, QWidget *parent, const char *name );
    QWidget *createForm( const QString &xmlContents );
    QLayout *createBoxLayout( const QString &className, QWidget *parent, const char *name );
    QLayout *createBoxLayout( const QString &className, QLayout *parent, const char *name );
    QWidget *createFormFromFile( const QString &xmlFile );

private:
    QWidgetFactory *factory;

};

class QuickTextEditInterface : public QObject
{
    Q_OBJECT

public:
    QuickTextEditInterface( QTextEdit *te );

public slots:
    bool replace( const QString &find, const QString &replace, bool cs, bool wo,
		  bool forward, bool startAtCursor, bool replaceAll );
    bool find( const QString &expr, bool cs, bool wo, bool forward );

private:
    QTextEdit *textedit;

};

#endif
