//  qgu.h
//
//  Qsas - GUI Utils Header File
//
//  Tony Allen
//  Jan 2002
//
/// \file qgu.h
///  Declaration file for the main GUI classes that are used within QSAS which are: \n
///  \arg \c QguListItem \n
///  \arg \c QguListView \n
///  \arg \c QguWLinput  \n
///  \arg \c QguWindow   \n \n
///  Those classes specialise respectively the QT3 built-in classes as listed below\n
///  \arg \c QListViewItem \n
///  \arg \c QListView     \n
///  \arg \c QLineEdit     \n
///  \arg \c QMainWindow   \n\n
///  \author A J Allen    \n
///  \date    2005

#ifndef QSAS_GU_H_
#define QSAS_GU_H_

#define QGU_VERSION  "QGU V_2.0 [ Nov 2005]"

#include <string>
#include <vector>

#include <QObject>
#include <Q3ListView>
#include <QCursor>
#include <QMenu>
#include <QApplication>
#include <QMessageBox>
#include <QClipboard>

#include "qt_version.h"
#include "qsas_version.h"
#include "Qdos.h"
#include "qsw_helpwindow_qt4.h"
#include "qdutil.h"

class QguListView;
class QguListItem;

typedef enum QguAliasType_e
{
  ALIAS_FOUND=0,
  ALIAS_NOT_FOUND=1,
  ALIAS_VIRTUAL=2
} QguAliasType;

typedef enum QguAliasObjType_e
{
  ALIAS_IS_UNKNOWN=0,
  ALIAS_IS_VECTOR=1,
  ALIAS_IS_ARRAY=2,
  ALIAS_IS_OTHER=3
} QguAliasObjType;

#define Obj_Name_                   0
#define Alias_                      1


/// \var  static const char * shift_cursor_xpm
/// \brief Global variable that defines the layout of an icon for the cursor when in shift or control selection
///
static const char * shift_cursor_xpm[] = {
"16 16 3 1",
" 	c None",
"X	c #000000000000",
".	c #FFFFFFFF0000",
"X.              ",
"XX.             ",
"XXX.            ",
"XXXX.           ",
"XXXXX.          ",
"XXXXXX.         ",
"XXXXXXX.        ",
"XXXXXXXX.       ",
"XX.XX....  .    ",
"X. .XX.    .X   ",
".  .XX.    .X   ",
"    .XX.....X...",
"    .XX. XXXXXXX",
"     .     .X   ",
"           .X   ",
"           .X   "};

class QguListView;
class QguListItem;

/// \enum QguListType
/// \brief This enumeration describes the different type of item that could be used within a QSAS list view
///  

/// \var QguListType::ListTypeEntry
///  The entry within the list view is a single item

/// \var QguListType::ListTypeGroup
///  The entry within the list view is a a group of items


/// \var QguListType::ListTypeNull
/// The entry within the list view is a NULL item. Used to include separators within a list view.
///
enum QguListType { 
      ListTypeEntry,
      ListTypeGroup,
      ListTypeNull 
};


//-------------------------------------------
/// \class QguListView qgu.h
/// \brief This is the QguListView class
///
/// This class implements a list/tree view for QSAS.
/// It inherits QListView which is a built-in QT3 class
/// 
/// \remarks { 
/// This class includes Q_OBJECT which is a QT3 macro that is used in all sub-classes of QObject in order to
/// benefit from the QT's Meta object system which are signals and slots mechanisms for inter-object communication,
/// runtime type information and the dynamic property system }

class QguListView : public Q3ListView 
{
   Q_OBJECT
public:
   QguListView(QWidget *parent, const char *name=0);
   ~QguListView();
   void setRootLocked(bool);
   bool rootIsLocked();
   void reLinkItem();
   void clearSelection();
   QguListItem * findCommonRoot();
   QguListItem * findCommonFolder();
   bool isCommonAncestor(QguListItem *folder);
   void clearSelectedList();
   void setSelectedList(QguListItem *item);
   void putChildrenOnList(QguListItem *item);
   void refreshSelectedList();
   bool isOnSelectedList(QguListItem *item);
   QguListItem * findAncestorOnList(QguListItem *item);
   QguListItem * findDescendentOnList(QguListItem *item);
   QguListItem * findDescendentOnList(QguListView *lv);
   void AddToSelectedList(QguListItem *item);
   void RemoveFromSelectedList(QguListItem *item);
   QguListItem *root(QguListItem *item);
   QguListItem *getItemByName(QString name);
   virtual void getAliasArrDim(QString,Dim_var &){;}
   virtual QguAliasObjType getAliasObjectType(QString){;}
   virtual QguAliasType getAliasObject(QString,QdObject_var){;}
   virtual QdObject_var getAliasResultObject(QString){;}
   virtual void viewCurrentItem(){;}
   void QguMoveItem(QguListItem *item, QguListItem *target);
   virtual void insertEntries(QguListItem *dropAt, QguListItem *item);
   bool reNameItem(QguListItem * item);
   QguListItem *getSafeItemAbove(QguListItem * item);
   QguListItem *getSafeItemBelow(QguListItem * item);
   void addItemsInclusive(QguListItem *newItem, QguListItem *last);
   void insertListItems(QguListItem * dropAtItem);
   bool isOnDragList(QguListItem * item);
   virtual void insertDragItem(QguListItem * dropAt, QguListItem *item);
   virtual void dropEvent(QDropEvent *event);
   void emitListModified();
   void contentsMouseDoubleClickEvent( QMouseEvent *event);
   void setDragList();
   bool bSingleSelection;
   int listSize();

   int with;  ///<  Public member defining how the list view is being saved (saved with data/without data/save as)
   QCursor *ShiftCursor;    ///<  Cursor used within the list view during mulitple selection
   QMenu *RButtonMenu; ///< Popup menu invoked by clicking the mouse right button
   vector <QguListItem*> localList; ///<  A list of items highlighted on the current list view. A vector structure.
   Dim_var selectedObjDim;  ///< Used to identify the dimension of an array object to propagate component choice with multiple selection
   
   bool rootLock;    ///< Flag to signify if the root of the list view is locked
   QPoint dragPos;
   bool mousePressed;
   bool alreadySelected;
   QguListItem *dragItem;

protected:
   virtual void contentsMousePressEvent( QMouseEvent *event);
   virtual void contentsMouseReleaseEvent( QMouseEvent *event);
   virtual void contentsMouseMoveEvent( QMouseEvent *event);
   virtual void dragMoveEvent( QDragMoveEvent *event);
   virtual void dragEnterEvent(QDragEnterEvent *event);

public: 

   
signals:
   
   /// \fn void listModified()
   /// \brief Function signal that is emitted when the current list view has been modified
   /// \param     None
   /// \exception None
   /// \return    None
   ///  
   void listModified();
   
   /// \fn selectionAdded()
   /// \brief Function signal that is emitted when an item has been added to the current selection
   /// \param     None
   /// \exception None
   /// \return    None
   ///  
   void selectionAdded();
   
   /// \fn void raiseWindow()
   /// \brief Function signal that is emitted when a drag enters this widget. CAuses the parent window to be raised.
   /// \param     None
   /// \exception None
   /// \return    None
   ///  
   void raiseWindow();
   
   /// \fn void viewObjRequest()
   /// \brief Function signal that is emitted when an item is double clicked - passed to Working List
   /// \param     None
   /// \exception None
   /// \return    None
   ///  
   void viewWL_ObjRequest();

public slots:
   virtual void rightButtonPressEvent(Q3ListViewItem *item, const QPoint &P,int c);
   void deleteListItems();
   void makeGroup();
   void renameSelectedItem();
   void copy();
   void paste();
   void moveItemDown();
   void moveItemUp();
   void selectAll();
   void validateWLitems();
   void setItemChoices();
   void clearMsgBar();
   
private:

	   
};

/// \class QguListItem qgu.h
/// \brief This is the QguListItem class
///
/// This class specialises the QListViewItem class which implements a list view item.
///
/// A list view item is a multi-column object capable of displaying itself in a QListView.
///
/// It inherits QListViewItem which is a built-in QT3 class
   
Vostream& operator<<(Vostream&,QguListItem&);
Vistream& operator>>(Vistream&,QguListItem&);

class QguListItem : public Q3ListViewItem
{
  friend Vostream& operator<<(Vostream&,QguListItem&);
  friend Vistream& operator>>(Vistream&,QguListItem&);
  

public:
   QguListItem(QguListView *parent=0,  QString txt=0, QguListType type=ListTypeEntry, QguListItem *after=0);
   QguListItem(QguListItem *parent=0,  QString txt=0, QguListType type=ListTypeEntry, QguListItem *after=0);
//    ~QguListItem();
   void setLocked(bool);
   bool isLocked();
   bool nameAlreadyUsed(QString name);
   QguListType getEntryType();
   QString nameContext();   // name context on this list
   QString text(int);  
   void setText(int, QString); 
   void removeIfEmpty();
   QString getWLcontext();
   bool nameUsed(QString &name);
   void set_Selected(bool choice);
   void setChildrenSelected(bool choice);
   QguListItem * safeParent();
   QguListItem *findName(QString name);
   bool isDescendent(QguListItem * item);
   void refreshWLcontext();
   QdObject_var QguGetObject();
   virtual bool validateLink(bool valid);
   bool validateWLitems(bool valid);
   void setColour(bool valid, bool thisValid);
   QguListItem * QguGetNext();

   QguListType entryType;      ///< Enumeration that defines the type of this item
   QString WLcontext;         ///< The full name and path on the list view of this item
   int with;   ///<  Public member defining how the list item is being saved (saved with/without data/without data/save as)
   bool  isVector;
   Dim_var virtualArrDim;   // dimension object for item after component selection (used for virtual items only)
   
protected:

private:
   bool Lock;
};

/// \class QguWindow qgu.h
/// \brief This is the QguWLinput class
///
/// This class specialises the QMainWindow class which provies a main application window.
///
/// Main windows are most often used to provide menus, toolbars and a status bar around a large central widget.
///
/// It inherits QMainWindow which is a built-in QT3 class
///
/// \remarks {
/// This class includes Q_OBJECT which is a QT3 macro that is used in all sub-classes of QObject in order to
/// benefit from the QT's Meta object system which are signals and slots mechanisms for inter-object communication,
/// runtime type information and the dynamic property system }
class QguWindow:public QMainWindow
{
  Q_OBJECT

protected:
//     void dragEnterEvent(QDragEnterEvent *event);
public:

  QMenuBar *_menu_bar;      ///<  Menu bar of the current main window object

  QguWindow( QWidget *parent=0, const char *name=0 );
  /// \fn ~QguWindow()
  /// \brief Destructor of the QguWindow class
  /// \param     None
  /// \exception None
  /// \return    None
  ///
  ~QguWindow();
  QStatusBar* msgBar;       ///<  Message bar of the current main window object (also qsas window)

  /// \fn void save(Vostream&)
  /// \brief Pure virtual fuction to save the contents of this window (session/working list). Overridden in sub-classes
  /// \param     Vostream&
  /// \exception None
  /// \return    None
  ///
  virtual void save(Vostream&)=0;

  /// \fn void restore(Vistream&)
  /// \brief Pure virtual function to restore the contents of this window (session/working list). Overridden in sub-classes
  /// \param     Vistream&
  /// \exception None
  /// \return    None
  ///
  virtual void restore(Vistream&,bool replace=true)=0;

   /// \fn void status(const QString& str)
  /// \brief Function that displays the message str within the current window message bar.
  /// \param     str of const QString& type
  /// \exception None
  /// \return    None
  ///
 void status(const QString& str);

  /// \fn void status(const QString& str,int ms)
  /// \brief Function that displays the message str within the current window message bar
  /// \param     str of const QString& type
  /// \param     ms  of int            type
  /// \exception None
  /// \return    None
  ///
  void status(const QString& str,int ms);
  
  /// \fn QMenuBar* menu_bar()
  /// \brief Function that displays the message str within the current window message bar for ms milli-seconds
  /// \param     str of const QString& type
  /// \exception None
  /// \return    None
  ///
  QMenuBar* menu_bar(){ return _menu_bar;}

  /// \fn QStatusBar* status_bar()
  /// \brief Function that returns the status bar pointer of the current main window object
  /// \param     None
  /// \exception None
  /// \return    None
  ///
  QStatusBar* status_bar(){return msgBar;}

  QString _filename;        ///< Filename used to save the current session or working list content
  QString SAVE_EXTENSION;   ///< File extension used to save the current session or working list content
  bool fromSession;         ///< Flag set to denote that this window save was initiated by a 'save session'

  int with;        ///<  Public member defining how main window is being saved (saved with/without data)
  QString _saveset_filter;
  static DataNamesTable_var _saved_objects; ///< Map associating item names to QD object pointers for objects being saved
  static DataNamesTable_var _restored_objects; ///< Map associating item names to QD object pointers for objects being restored

public slots:
  virtual void save();
  //virtual void saveWith();
  virtual void saveWithOut();
  virtual void saveAs();
  //virtual void saveWithAs();
  virtual void saveWithOutAs();
  virtual void include();
  virtual void restore(bool replace=true);
  virtual void saveSession(QString);
  virtual void restoreSession(QString);
  void bringToFront();
};



# endif // QSAS_GU_H_
