/* This file is part of the KDE project
   Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/

#include "kdc_view.h"
#include "kdc_factory.h"
#include "kdc_part.h"
#include <render2d.h>
#include <chemdata.h>
#include <tool_xpm.h>

#include <qpainter.h>
#include <qiconset.h>
#include <kaction.h>
#include <kstdaction.h>
#include <klocale.h>
#include <kdebug.h>

KDCView::KDCView( KDCPart* part, QWidget* parent, const char* name )
    : KoView( part, parent, name )
{
    setInstance( KDCFactory::global() );
    if ( !part->isReadWrite() ) // readonly case, e.g. when embedded into konqueror
        setXMLFile( "kdc_readonly.rc" ); // simplified GUI
    else
        setXMLFile( "kdc.rc" );
    KStdAction::copy(this, SLOT( copy() ), actionCollection(), "copy" );
    KStdAction::cut(this, SLOT( cut() ), actionCollection(), "cut" );
    initActions();
    render=new Render2D(this);
    render->show();
    ChemData* data=part->getChemData();
    render->setChemData(data);
    data->setRender2D(render);
    // Note: Prefer KStdAction::* to any custom action if possible.
    //m_cut = new KAction( i18n("&Cut"), "editcut", 0, this, SLOT( cut() ),
    //                   actionCollection(), "cut");
}

void KDCView::initActions() {

  setModeSelect = new KAction(i18n("Select"),QIconSet(QPixmap(selecttool)),0,this,SLOT(setMode_Select()),actionCollection(),"set_mode_select");
  setModeErase = new KAction(i18n("Erase"),QIconSet(QPixmap(erasetool)),0,this,SLOT(setMode_Erase()),actionCollection(),"set_mode_erase");
  setModeDrawLine = new KAction(i18n("Draw line"),QIconSet(QPixmap(linetool)),0,this,SLOT(setMode_DrawLine()),actionCollection(),"set_mode_draw");
  setModeDrawDashLine = new KAction(i18n("Draw dashed line"),QIconSet(QPixmap(dashtool)),0,this,SLOT(setMode_DrawDashLine()),actionCollection(),"set_mode_drawdash");
  //setModeDrawUpLine = new KAction(i18n("Draw line up"),QIconSet(QPixmap(uptool)),0,this,SLOT(setMode_DrawLineUp()),actionCollection(),"set_mode_drawup");
  //setModeDrawDownLine = new KAction(i18n("Draw line down"),QIconSet(QPixmap(downtool)),0,this,SLOT(setMode_DrawLineDown()),actionCollection(),"set_mode_drawdown");
  //setModeDrawText = new KAction(i18n("Text"),QIconSet(QPixmap(texttool)),0,this,SLOT(setMode_DrawText()),actionCollection(),"set_mode_drawtext");

}

void KDCView::paintEvent( QPaintEvent* ev )
{
    QPainter painter;
    painter.begin( this );

    // ### TODO: Scaling

    // Let the document do the drawing
    koDocument()->paintContent( painter, ev->rect(), FALSE,1,1); // this );
    //koDocument()->getChemData()->drawAll;

    painter.end();
}

void KDCView::updateReadWrite( bool /*readwrite*/ )
{
#ifdef __GNUC__
#warning TODO
#endif
}

void KDCView::copy()
{
    kdDebug(31000) << "KDCView::copy(): COPY called" << endl;
}

void KDCView::cut()
{
    kdDebug(31000) << "KDCView::cut(): CUT called" << endl;
}

void KDCView::setMode_Select(){

  render->setMode_Select();
}

void KDCView::setMode_SelectNone(){

  render->setMode_SelectNone();
}

void KDCView::setMode_Erase(){
  render->setMode_Erase();
}

void KDCView::setMode_DrawLine(){
  render->setMode_DrawLine();
}

void KDCView::setMode_DrawDashLine(){
  render->setMode_DrawDashLine();
}

#include "kdc_view.moc"
