/***********************************************************************
*           See Accompanying licence file QSAS_licence                 *
***********************************************************************/
#ifndef _QWUI_H
#define _QWUI_H

#include <string>
#include <vector>
#include <qfiledialog.h>
#include <qstatusbar.h>

#include <qlayout.h>
#include <qobject.h>
#include "qt_version.h"
#include "Qdos.h"

#if QT_VERSION < 0x040000
#include "qsw_helpwindow.h"
#include "qgu.h"
#include "qbu.h"
#else
#include "qsw_helpwindow_qt4.h"
#include "qgu_qt4.h"
#include "qbu_qt4.h"
#endif

#include "qtpl.h"
#include "qdutil.h"
#include "qprofile.h"

extern QFont defaultFont; // Initialised with default size at startup

class qwuiWindow;

#define QWUI_VERSION_ID "WL_2.01"

class QwlListItem;

Vostream& operator<<(Vostream&,QwlListItem&);
Vistream& operator>>(Vistream&,QwlListItem&);
   

// WL List Item class


class QwlListItem : public QguListItem 
{

public:

   QwlListItem(QguListView *parent=0,  QString txt=0, QguListType type=ListTypeEntry, QguListItem *after=0);
   QwlListItem(QguListItem *parent=0,  QString txt=0, QguListType type=ListTypeEntry, QguListItem *after=0);

   ~QwlListItem();
   void QwlDeleteChildren();
   QString addItemAtAnchor ( QString name, bool reuse=0);
 
private:
   
};



// WL List View class

class QwlListView;

Vostream& operator<<(Vostream&,QwlListView&);
Vistream& operator>>(Vistream&,QwlListView&);


class QwlListView : public QguListView 
{
   Q_OBJECT
  friend Vostream& operator<<(Vostream&,QwlListView&);
  friend Vistream& operator>>(Vistream&,QwlListView&);
   
public:
  QwlListView(QWidget *parent, const char *name=0);
  ~QwlListView();
  QwlListItem *insertOnWL(QguListItem *head, QString name,
                     QguListType type, bool lock, QguListItem *after);
  void insertDragItem(QwlListItem * dropAt, QwlListItem *item);
  void refreshWLcontext();
  bool reNameItem(QwlListItem * item);
  virtual void insertEntries(QwlListItem *dropAt, QwlListItem *item);
  void insertListItems(QwlListItem * dropAtItem);
  void deleteItems(bool askFirst);
  bool nameUsedAtWLroot(QString newName);

  QwlListItem *Data;
  QwlListItem *Time;
  QwlListItem *Constant;


protected:
   void contentsMouseDoubleClickEvent( QMouseEvent *event);
   void dropEvent( QDropEvent *event);

   
signals:
  void viewObjRequest();

public slots:
  void makeGroup();
  void paste();
  void renameSelectedItem();
  void deleteListItems();
  void clearCacheSelected();
  void duplicateItem();
  void deleteItemTT();

private:


};
   
class qwuiWindow : public QguWindow
{
   Q_OBJECT

public:
   qwuiWindow(QWidget *parent=0, const char *name=0);
   void makeWindows();
   QCheckBox *StripBadData;
   QCheckBox *StripFills;
#if QT_VERSION < 0x040000
   static QHBox *toggleBar;
#else
   static QWidget *toggleBar;
#endif
   void Qwui_msgBox(const char *  );
   void addFolderToMenu(const char *folder, qtplMenu *menu, bool first = true);
   virtual void save(Vostream& v_os);
   virtual void restore(Vistream& v_is, bool replace=true);
   
   QwlListView *WorkingList;
   qtplMenu * timeOps;
   qtplMenu * mathOps;
   qtplMenu * filterOps;
   qtplMenu * statOps;
   qtplMenu * unitOps;
   qtplMenu * eventTableOps;
   vector <qtplMenu *> pluginFolders;
   QString qsas_home;
   QswHelpWindow *help_window;
   QString _sessionFolder;

signals:
  void saveSessionRequest(QString );
  void restoreSessionRequest(QString);
  void clearListRequest();
  void WLmodified();
  void openQdaWindow(const char *);
  void runStaticPlugin(const char *);
   
public slots:
   void setPreferences();
   void launchManual();
   void launchManMainW();
   void launchManSampleW();
   void launchManDataH();
   void launchManSaveRestore();
   void launchVersion();
   void launchContact();
   void makeGroup();
   void issueReName();
   void selectAllData();
   void selectAllTimeIntervals();
   void deleteItemTT();
   void deleteAllDataItems();
   void deleteAllTimeIntervalItems();
   void deleteListItem();
   void clearCache();
   void clearCacheSelected();
   void saveSession();
   void saveSessionAs();
   void restoreSession();
   void saveWL();
   void saveWLAs();
   void issueDuplicate();

  
protected:
   void closeEvent( QCloseEvent* );
   void dragMoveEvent( QDragMoveEvent *event);

private:
//   QWidget * grid;
   QWidget* centralW;
   QVBoxLayout * centralBox;
   
};
 

void  setStandardConstants(QguListItem *WLconsts);



class SessionFolderDialog : public QFileDialog {

Q_OBJECT

  
  QStatusBar* _status_bar;
  QMenuBar *_menu_bar;
  
public slots:
  QString getSessionFolder();
  
signals:
  
public:
  SessionFolderDialog( QWidget *parent=0, const char *name=0 );
  ~SessionFolderDialog(){;}
  void status(const QString& str)  {_status_bar->message(str);}
  QMenuBar* menu_bar(){ return _menu_bar;}
  QLabel * label;
  
protected:

private slots:
  
};

// Qwui Utilities

QString QwuiPutOnWL(QdObject_var obj, const char * objName, const char * List, bool replace=0);
QSize qsasGUISize();

#endif

/**********************************************************************/

