#ifndef LANDED_HELPERS
#define LANDED_HELPERS

#include <QStyledItemDelegate>
#include <QApplication>
#include <QTableWidgetItem>
#include <QLineEdit>
#include <QPushButton>
#include <QKeyEvent>
#include <QObject>
#include <QLabel>
#include <QTextDocument>
#include <QPainter>


class LED : public QWidget
{
 Q_OBJECT
 public:
  LED(QWidget*, int=24);

 private:
  bool on_;
  int size_;

 private:
  void paintEvent(QPaintEvent*);

 public:
  void setOn(void);
  void setOff(void);
  void set(bool);
  bool on(void) const;

};

class ClearLineEdit : public QLineEdit
{
  Q_OBJECT
 
public:
  ClearLineEdit(QWidget *parent = 0);
 
protected:
  void resizeEvent(QResizeEvent *);
				  
private slots:
  void updateCloseButton(const QString &text);
  
private:
  QPushButton btnClear_;
};


//helper class for detector shape list
class DetectorListWidgetItem : public QTableWidgetItem
{
public:
  //just the name of the shape will do
  DetectorListWidgetItem(QString, int, bool=true);

  int index;

};

//widget to control number of decimal places displayed in hit list
class DoubleItemDelegate : public QStyledItemDelegate
{
  Q_OBJECT

  public:
  DoubleItemDelegate(int , QObject* =NULL);

 private:
  int dp_;

 public:
  int getDP(void) const;
  void setDP(int);
  QString displayText(const QVariant&, const QLocale&) const;
  
};

class RichTextDelegate : public QStyledItemDelegate {
public:
  RichTextDelegate(QObject* = NULL);
    Qt::Alignment alignment() { return alignment_; }
    void setAlignment(Qt::Alignment alignment = Qt::AlignCenter) { alignment_ = alignment; }

protected:
    ~RichTextDelegate();
    void paint(QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const;
    QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const;

private:
    Qt::Alignment alignment_;
    QLabel *label_;
    QTextDocument *doc_;
};

//doobery to stop spinners from intercepting keyboard shortcuts
class ShortcutEater : public QObject
{
  Q_OBJECT
 public:
  ShortcutEater(QWidget*);

 protected:
  QWidget* parent_;

 protected:
  bool eventFilter(QObject*, QEvent*);
};

#endif //ifndef LANDED_HELPERS
