/***************************************************************************
    copyright            : (C) 2005-2007 by Robby Stephenson
    email                : robby@periapsis.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of version 2 of the GNU General Public License as  *
 *   published by the Free Software Foundation;                            *
 *                                                                         *
 ***************************************************************************/

#ifndef TELLICO_LOANVIEW_H
#define TELLICO_LOANVIEW_H

#include "gui/listview.h"
#include "observer.h"
#include "borroweritem.h"

#include <tqdict.h>

namespace Tellico {
  namespace Data {
    class Borrower;
  }

/**
 * @author Robby Stephenson
 */
class LoanView : public GUI::ListView, public Observer {
Q_OBJECT
  

public:
  LoanView(TQWidget* parent, const char* name=0);

  virtual bool isSelectable(GUI::ListViewItem*) const;

  virtual void addCollection(Data::CollPtr coll);

  virtual void addField(Data::CollPtr, Data::FieldPtr);
  virtual void modifyField(Data::CollPtr, Data::FieldPtr, Data::FieldPtr);
  virtual void removeField(Data::CollPtr, Data::FieldPtr);

  virtual void    addBorrower(Data::BorrowerPtr);
  virtual void modifyBorrower(Data::BorrowerPtr);

private slots:
  /**
   * Handles the appearance of the popup menu.
   *
   * @param item A pointer to the item underneath the mouse
   * @param point The location point
   * @param col The column number, not currently used
   */
  void contextMenuRequested(TQListViewItem* item, const TQPoint& point, int col);
  void slotExpanded(TQListViewItem* item);
  void slotCollapsed(TQListViewItem* item);
  void slotCheckIn();
  void slotModifyLoan();

private:
  virtual void setSorting(int column, bool ascending = true);
  void resetComparisons();

  bool m_notSortedYet;
  TQDict<BorrowerItem> m_itemDict;
};

} // end namespace

#endif
