#ifndef DSRGLWINDOW_H
#define DSRGLWINDOW_H

#include "molecule.h"
#include "dsrgui.h"

class DSRGlWindow : public QGLWidget
{
  Q_OBJECT

public:
  DSRGlWindow(QWidget *parent, Molecule *m, DSRMol header, QString fragment);
  virtual ~DSRGlWindow();
  CEnvironment xd;        //!< MyAtom list of the molecule
  CEnvironment selFragAt; //! MyAtom list of selected fragment atoms
  CEnvironment fita;      //! MyAtom list of atoms where the fragment is fitted to plus the surrounding
  Connection bonds;       //!< MyBond list of the fragment molecule bonds
  Connection fitabonds;   //!< MyBond list of the target molecule bonds
  Molecule *m_molecule;
  QString source_atoms;
  QCheckBox *showFit;
  QCheckBox *showFitLabel;
public slots:
  void display_fragment(DSRMol frag, bool clear_sel=true);
  void makeInfo();
  void clear_molecule();
  void set_label_color();
  void mousePressEvent(QMouseEvent *event);
signals:
  void sourceStringChanged();
  void updateInfo(QString);
protected:
  void initializeGL();
  void resizeGL(int width, int height);
  void paintGL();
  void mouseMoveEvent(QMouseEvent *event); 
  void wheelEvent(QWheelEvent *event);
private:  
  inline void __RotateCS( double c, double s, double& X, double& Y ) ;
  void glTranslateL( const double dx, const double dy, const double dz );
  void glRotateL( const double dang, const double x, const double y, const double z );
  QFont myFont; //!< a font for the atom labels
  Molecule mole;
  QColor dsrLabelColor;
  GLint vp[4];
  void draw();
  double L, moux, mouy;
  void tryfit();
  virtual QSize sizeHint() const;
  virtual QSize minimumSizeHint() const;
};

#endif // DSRGLWINDOW_H
