/***************************************************************************
                          kdrawchem.h  -  description
                             -------------------
    begin                : Mon Jul 15 12:24:12 CDT 2002
    copyright            : (C) 2002 by Adam Tenderholt
    email                : a-tenderholt@northwestern.edu
 ***************************************************************************/

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

#ifndef KDRAWCHEM_H
#define KDRAWCHEM_H


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

// include files for Qt

// include files for KDE
#include <kapp.h>
#include <kmainwindow.h>
#include <kaccel.h>
#include <kurl.h>
#include <klocale.h>
#include <kguiitem.h>
#include <kfiledialog.h>

#include "clipboard.h"
#include "ioiface.h"
#include "custom_rings.h"

class KAction;
class KRecentFilesAction;
class KActionMenu;
class KToggleAction;
class KToolBarPopupAction;
class KFontAction;
class KFontSizeAction;

// forward declaration of the KDrawChem classes
class KDrawChemDoc;
class KDrawChemView;


/**
  * The base class for KDrawChem application windows. It sets up the main
  * window and reads the config file as well as providing a menubar, toolbar
  * and statusbar. An instance of KDrawChemView creates your center view, which is connected
  * to the window's Doc object.
  * KDrawChemApp reimplements the methods that KMainWindow provides for main window handling and supports
  * full session management as well as using KActions.
  * @see KMainWindow
  * @see KApplication
  * @see KConfig
  *
  * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team.
  * @version KDevelop version 1.2 code generation
  */
class KDrawChemApp : public KMainWindow
{
  Q_OBJECT

  friend class KDrawChemView;

  public:
    /** construtor of KDrawChemApp, calls all init functions to create the application.
     */
    KDrawChemApp(QWidget* parent=0, const char* name=0);
    ~KDrawChemApp();
    /** opens a file specified by commandline option
     */
    void openDocumentFile(const KURL& url=0);
    /** returns a pointer to the current document connected to the KTMainWindow instance and is used by
     * the View class to access the document object's methods
     */
    KDrawChemDoc *getDocument() const;
  /** Returns a pointer to the current view */
  KDrawChemView * getView();

  protected:
    /** save general Options like all bar positions and status as well as the geometry and the recent file list to the configuration
     * file
     */
    void saveOptions();
    /** read general Options again and initialize all variables like the recent file list
     */
    void readOptions();
    /** initializes the KActions of the application */
    void initActions();
    /**++ initializes the rings-specific KActions */
    void initRingsActions();
    /** sets up the statusbar for the main window by initialzing a statuslabel.
     */
    void initStatusBar();
    /** initializes the document object of the main window that is connected to the view in initView().
     * @see initView();
     */
    void initDocument();
    /** creates the centerwidget of the KTMainWindow instance and sets it as the view
     */
    void initView();
    /** queryClose is called by KTMainWindow on each closeEvent of a window. Against the
     * default implementation (only returns true), this calles saveModified() on the document object to ask if the document shall
     * be saved if Modified; on cancel the closeEvent is rejected.
     * @see KTMainWindow#queryClose
     * @see KTMainWindow#closeEvent
     */
    virtual bool queryClose();
    /** queryExit is called by KTMainWindow when the last window of the application is going to be closed during the closeEvent().
     * Against the default implementation that just returns true, this calls saveOptions() to save the settings of the last window's
     * properties.
     * @see KTMainWindow#queryExit
     * @see KTMainWindow#closeEvent
     */
    virtual bool queryExit();
    /** saves the window properties for each open window during session end to the session config file, including saving the currently
     * opened file by a temporary filename provided by KApplication.
     * @see KTMainWindow#saveProperties
     */
    virtual void saveProperties(KConfig *_cfg);
    /** reads the session config file and restores the application's state including the last opened files and documents by reading the
     * temporary files saved by saveProperties()
     * @see KTMainWindow#readProperties
     */
    virtual void readProperties(KConfig *_cfg);

  public slots:
    /** open a new application window by creating a new instance of KDrawChemApp */
    void slotFileNewWindow();
    /** clears the document in the actual view to reuse it as the new document */
    void slotFileNew();
    /** open a file and load it into the document*/
    void slotFileOpen();
    /** opens a file from the recent files menu */
    void slotFileOpenRecent(const KURL& url);
    /** imports file into current document */
    void slotFileImport();
    /** save a document */
    void slotFileSave();
    /** save a document by a new filename*/
    void slotFileSaveAs();
    /** asks for saving if the file is modified, then closes the actual file and window*/
    void slotFileClose();
    /** print the actual file */
    void slotFilePrint();
    /** closes all open windows by calling close() on each memberList item until the list is empty, then quits the application.
     * If queryClose() returns false because the user canceled the saveModified() dialog, the closing breaks.
     */
    void slotFileQuit();
    /** put the marked text/object into the clipboard and remove
     *	it from the document
     */
    void slotEditCut();
    /** put the marked text/object into the clipboard
     */
    void slotEditCopy();
    /** paste the clipboard into the document
     */
    void slotEditPaste();

    void slotRotate90();
    void slotRotate180();
    void slotRotate270();

    void slotFlipH();
    void slotFlipV();

    /** toggles the toolbar
     */
    void slotViewToolBar();
    /** toggles the statusbar
     */
    void slotViewStatusBar();
    /** changes the statusbar contents for the standard label permanently, used to indicate current actions.
     * @param text the text that is displayed in the statusbar
     */
  void slotStatusMsg(QString text);
  /** No descriptions */
  void setMode_Select();
  //void setMode_SelectNone();
  /** Connects to view->slotMode_Erase */
  void setMode_Erase();
  /** Calls view->DrawDashLine */
  void setMode_DrawDashLine();
  /** Calls view->setMode_DrawLine */
  void setMode_DrawLine();
  /** Enables Save and Save as actions */
  void slotModified();
  /** Calls view->setMode_DrawDownLine */
  void setMode_DrawLineDown();
  /** Calls view->setMode_DrawLineUp */
  void setMode_DrawLineUp();
  /** Calls view->setMode_DrawText */
  void setMode_DrawText();
  /** Calls view->setMode_DrawArrow(btype) */
  void setMode_DrawArrow(QString btype);
  /** Calls view->setMode_DrawArrow("REGULAR") */
  void setMode_DrawArrow();
  /** No descriptions */
  void setMode_DrawArrowDash();
  /** No descriptions */
  void setMode_DrawArrowBI1();
  /** No descriptions */
  void setMode_DrawArrowRetro();
  /** No descriptions */
  void setMode_DrawArrowBI2();
  /** When this is clicked, last arrow menu item used is used. */
  void slotArrowMenuClicked();
  /** setMode_Curve* calls view->setMode_DrawCurveArrow(QString) */
  void setMode_Curve90CW();
  void setMode_Curve90CCW();
  void setMode_Curve180CW();
  void setMode_Curve180CCW();
  void setMode_Curve270CW();
  void setMode_Curve270CCW();

  void slotCurveArrowMenuClicked();
  /** Calls view->Undo() */
  void slotEditUndo();
  /** Calls view->CalcMW() */
  void calcMW();
  /** No descriptions */
  void calcEmpiricalFormula();
  /** No descriptions */
  void calcElementalAnalysis();
  /** No descriptions */
  void calcMolecularInfo();
  /** No descriptions */
  void calcIR();
  void calc13CNMR();
  void calc1HNMR();
  void inputSMILES();
  void outputSMILES();
  /** No descriptions */
  void cleanupStruct();
  /** No descriptions */
  void slotSelectAll();
  void slotDelete();
  /** setMode_DrawBracket* calls view->setModeDrawBracket(QString) */
  void setMode_DrawBracketBrace();
  /** No descriptions */
  void setMode_DrawBracketCurve();
  /** No descriptions */
  void setMode_DrawBracketSquare();
  /** No descriptions */
  void slotBracketMenuClicked();
  /** No descriptions */
  void setMode_DrawSymbolRingUp();
  /** No descriptions */
  void setMode_DrawSymbol2e();
  /** No descriptions */
  void setMode_DrawSymbol1e();
  /** No descriptions */
  void setMode_DrawSymbolDeltaMinus();
  /** No descriptions */
  void setMode_DrawSymbolDeltaPlus();
  /** No descriptions */
  void setMode_DrawSymbolMinus();
  /** No descriptions */
  void setMode_DrawSymbolPlus();
    /** No description */
    void setMode_DrawSymbolPOrbital();
  /** No descriptions */
  void slotSymbolMenuClicked();
  /** No descriptions */
  void setFontFamily(const QString& text);
  /** No descriptions */
  void setFontSize(int size);
  /** No descriptions */

  void toggleFixedBondLength();
  void toggleFixedArrowLength();
    void slotShowFixedDialog();
    void slotSetBackgroundColor();

  void toggleFontBold();
  void toggleFontItalic();
  void toggleFontUnderline();
  void toggleFontSuperscript();
  void toggleFontSubscript();

  /** No descriptions */
  void slotHasBold(bool flag);
  void slotHasItalic(bool flag);
  void slotHasUnderline(bool flag);
  void slotHasSuperscript(bool flag);
  void slotHasSubscript(bool flag);
  void slotFont(QString font);
  void slotFontSize(int size);
  /** No descriptions */
  void slotSavePicture();

  /** Used to draw pre-set rings.*/
  void slotSugar(int x);
  void slotNucleic(int x);
	void slotAmino(int x);
  void slotRing(int x);
	void slotGroup(int x);
  void slotCustom(int x);
  void slotNewRingsSize(int x);

  public:

    static IOIface interface;

private:
    void initSymbolActions();

  private:
    CustomRings* m_rings;

    /** the configuration object of the application */
    KConfig *config;
    /** view is the main widget which represents your working area. The View
     * class should handle all events of the view widget.  It is kept empty so
     * you can create your view according to your application's needs by
     * changing the view class.
     */
    KDrawChemView *view;
    /** doc represents your actual document and is created only once. It keeps
     * information such as filename and does the serialization of your files.
     */
    KDrawChemDoc *doc;
   /** _clipboard is the object that doc copies into when Copy() and Cut() are called */
    Clipboard* _clipboard;
   // KAction pointers to enable/disable actions
    KAction* fileNewWindow;
    KAction* fileNew;
    KAction* fileOpen;
    KAction* fileImport;
    KRecentFilesAction* fileOpenRecent;
    KAction* fileSave;
    KAction* fileSaveAs;
    KAction* savePicture;
    KAction* fileClose;
    KAction* filePrint;
    KAction* fileQuit;
    KAction* editCut;
    KAction* editCopy;
    KAction* editPaste;
    KAction* editUndo;
    KAction* editSelectAll;
    KAction* editDelete;

    KActionMenu* rotateMenu;

    KAction* rotate90;
    KAction* rotate180;
    KAction* rotate270;

    KActionMenu* flipMenu;

    KAction* flipH;
    KAction* flipV;

    KToggleAction* fixedBond;
    KToggleAction* fixedArrow;
    KAction* backgroundColor;
    KAction* fixedDialog;


    KAction* toolsCalcMW;
    KAction* toolsCalcEF;
    KAction* toolsCalcEA;
    KAction* toolsCalcMI;
    KAction* toolsCalcIR;
    KAction* toolsCalc13CNMR;
    KAction* toolsCalc1HNMR;
    KAction* toolsCleanupStruct;
	KAction* toolsInputSMILES;
	KAction* toolsOutputSMILES;

    KToggleAction* viewToolBar;
    KToggleAction* viewStatusBar;

    QString KDChemFilter;
    KAction* setModeSelect;
    KAction* setModeErase;
    KAction* setModeDrawLine;
    KAction* setModeDrawDashLine;
    KAction* setModeDrawUpLine;
    KAction* setModeDrawDownLine;
    KAction* setModeDrawArrow;
    KAction* setModeDrawText;

    KActionMenu* arrowMenu;
    int currentArrow;

    KToolBarPopupAction* arrowRegular;
    KToolBarPopupAction* arrowDash;
    KToolBarPopupAction* arrowBI1;
    KToolBarPopupAction* arrowBI2;
    KToolBarPopupAction* arrowRetro;

    KActionMenu* curveArrowMenu;
    int currentCurveArrow;

    KToolBarPopupAction* curve90CW;
    KToolBarPopupAction* curve90CCW;
    KToolBarPopupAction* curve180CW;
    KToolBarPopupAction* curve180CCW;
    KToolBarPopupAction* curve270CW;
    KToolBarPopupAction* curve270CCW;

    KActionMenu* bracketMenu;
    int currentBracket;

    KToolBarPopupAction* bracketSquare;
    KToolBarPopupAction* bracketCurve;
    KToolBarPopupAction* bracketBrace;

    KActionMenu* symbolMenu;
    int currentSymbol;

    KFontAction* fontAction;
    KFontSizeAction* fontSize;
    KToggleAction* setBold;
    KToggleAction* setItalic;
    KToggleAction* setUnderline;
    KToggleAction* setSuperscript;
    KToggleAction* setSubscript;

    /**  */
    KFileDialog* dialog;

    KActionMenu* ringsMenu;
    KPopupMenu* ringsPopupMenu;

    KPopupMenu* sugarMenu;
    KPopupMenu* nucleicMenu;
		KPopupMenu* aminoMenu;
    KPopupMenu* ringMenu;
		KPopupMenu* groupMenu;
    KPopupMenu* customMenu;
};

#endif // KDRAWCHEM_H


