#include "kdrawchempart.h"

#include <kinstance.h>
#include <klocale.h>
#include <kaboutdata.h>

#include <qlabel.h>

extern "C"
{
    /**
     * This function is the 'main' function of this part.  It takes
     * the form 'void *init_lib<library name>()  It always returns a
     * new factory object
     */
    void *init_libkdrawchem()
    {
        return new KDrawChemFactory;
    }
};

/**
 * We need one static instance of the factory for our C 'main'
 * function
 */
KInstance *KDrawChemFactory::s_instance = 0L;

KDrawChemFactory::KDrawChemFactory()
{
}

KDrawChemFactory::~KDrawChemFactory()
{
    if (s_instance)
    {
        delete s_instance->aboutData();
        delete s_instance;
    }

    s_instance = 0;
}

QObject *KDrawChemFactory::createObject(QObject *parent, const char *name, const char*,
                               const QStringList&)
{
    QObject *obj = new KDrawChemPart((QWidget*)parent, name);
    emit objectCreated(obj);
    return obj;
}

KInstance *KDrawChemFactory::instance()
{
    if ( !s_instance )
        s_instance = new KInstance( aboutData() );
    return s_instance;
}

KAboutData *KDrawChemFactory::aboutData()
{
  KAboutData *about = new KAboutData("KDrawChem", I18N_NOOP("KDrawChem"), "0.1");
  return about;
}

KDrawChemPart::KDrawChemPart(QWidget *parent, const char *name)
    : KParts::ReadOnlyPart(parent, name)
{
  setInstance(KDrawChemFactory::instance());

  // create a canvas to insert our widget
  QWidget *canvas = new QWidget(parent);
  canvas->setFocusPolicy(QWidget::ClickFocus);
  setWidget(canvas);
  setXMLFile("kdrawchemui.rc");
  m_extension = new KDrawChemBrowserExtension(this);

  // as an example, display a blank white widget
  //widget = new QLabel(canvas);
  //widget->setText("KDrawChem");
  //widget->setAutoResize(true);
  //widget->show();

  m_view = new KDrawChemView(canvas);
	m_view->show();
	m_doc = new KDrawChemDoc(canvas);
	m_doc->addView(m_view);

}

KDrawChemPart::~KDrawChemPart()
{
    closeURL();
}

bool KDrawChemPart::openFile()
{
    //widget->setText(m_file);
	m_doc->openDocument(m_file);
    return true;
}

/*bool KDrawChemPart::closeURL()
{
    return true;
}*/

KDrawChemBrowserExtension::KDrawChemBrowserExtension(KDrawChemPart *parent)
    : KParts::BrowserExtension(parent, "KDrawChemBrowserExtension")
{
}

KDrawChemBrowserExtension::~KDrawChemBrowserExtension()
{
}

//eof


#include "kdrawchempart.moc"