/****************************************************************************
** $Id: quickeditorinterfaceimpl.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 QUICKEDITORINTERFACEIMPL_H
#define QUICKEDITORINTERFACEIMPL_H

#include <editorinterface.h>
#include <actioninterface.h>
#include <qobject.h>
#include <qguardedptr.h>

class QTimer;
class ViewManager;
struct DesignerInterface;
class QAction;
class QTextEdit;

class QuickEditorInterfaceImpl : public QObject, public EditorInterface,
				 public QComponentInformationInterface, public ActionInterface
{
    Q_OBJECT

public:
    QuickEditorInterfaceImpl();
    virtual ~QuickEditorInterfaceImpl();

    QRESULT queryInterface( const QUuid&, QUnknownInterface **iface );
    unsigned long addRef();
    unsigned long release();

    QString name() const { return "Qt Script"; }
    QString description() const { return "Qt Script Editor"; }
    QString version() const { return "0.1"; }
    QString author() const { return "Trolltech AS"; }
    QStringList featureList() const;

    QWidget *editor( bool readonly, QWidget *parent, QUnknownInterface *designerIface );

    void setText( const QString &txt );
    QString text() const;
    bool isUndoAvailable() const;
    bool isRedoAvailable() const;
    void undo();
    void redo();
    void cut();
    void copy();
    void paste();
    void selectAll();
    bool find( const QString &expr, bool cs, bool wo, bool forward, bool startAtCursor );
    bool replace( const QString &find, const QString &replace, bool cs, bool wo,
		  bool forward, bool startAtCursor, bool replaceAll );
    void gotoLine( int line );
    void indent();
    void scrollTo( const QString &txt, const QString &first );
    void splitView();
    void setContext( QObject *this_ );
    void readSettings();

    void setError( int line );
    void setStep( int line );
    void clearStep();
    void clearStackFrame();
    void setStackFrame( int line );
    void setModified( bool b );
    bool isModified() const;

    int numLines() const;

    void breakPoints( QValueList<uint> & ) const;
    void setBreakPoints( const QValueList<uint> & );

    void setMode( Mode m );

    void onBreakPointChange( QObject *receiver, const char *slot );

    QAction* create( const QString&, QObject* parent = 0 );
    QString group( const QString & ) const;
    bool location( const QString &name, Location l ) const;
    void connectTo( QUnknownInterface *appInterface );

    ViewManager *view_manager() const { return viewManager; }
    bool hasDesignerInterface() const { return !!dIface; }

    void toggleDebugger( bool enable );

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

private slots:
    void modificationChanged( bool m );
    void update();
    void intervalChanged();
    void toggleBreakpoint();
    void editBreakpoints();
    void isBreakpointPossible( bool &possible, const QString &code, int line );

private:
    QTextEdit *activeEditor( QuickEditorInterfaceImpl **iface ) const;

private:
    QGuardedPtr<ViewManager> viewManager;
    ulong ref;
    DesignerInterface *dIface;
    QTimer *updateTimer;
    QAction *actionToggleBreakPoint;
    QAction *actionEditBreakpoints;
    static bool debuggerEnabled;

};

#endif
