bin dir cleanup
[scorecard] / src / cell-delegate.h
1 #ifndef CELLDELEGATE_H
2 #define CELLDELEGATE_H
3
4 #include <QItemDelegate>
5 #include <QEvent>
6 #include <QKeyEvent>
7 #include <QDebug>
8 //#include "cell.h"
9
10 class CellFilter : public QObject
11 {
12   Q_OBJECT
13
14 public:
15  CellFilter(QObject *parent=0) : QObject(parent) 
16   {
17     m_parent = parent;
18   }
19
20  signals:
21   void nextCell(QObject *);
22
23 protected:
24   bool eventFilter(QObject *dist, QEvent *event)
25   {
26     if (event->type() == QEvent::KeyPress) {
27       QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
28       static QString digits = QString("123456789");
29       if (digits.indexOf(keyEvent->text()) != -1) {
30         qDebug() << "Key press number";
31         int rc = QObject::eventFilter(dist, event);
32         emit nextCell(m_parent);
33         //return rc;
34         return false;
35       }
36       else {
37         qDebug() << "Key press invalid";
38         return true;
39       }
40     }
41
42   }
43  private:
44   QObject *m_parent;
45 };
46
47 class CellDelegate : public QItemDelegate
48 {
49     Q_OBJECT
50
51 public:
52     CellDelegate(QObject *parent = 0);
53     QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &,
54                           const QModelIndex &index) const;
55     void setEditorData(QWidget *editor, const QModelIndex &index) const;
56     void setModelData(QWidget *editor, QAbstractItemModel *model,
57                       const QModelIndex &index) const;
58     CellFilter *filter;
59
60  signals:
61   void nextCell(QObject *);
62
63 private slots:
64     void commitAndCloseEditor();
65
66  private:
67     QObject *m_parent;
68 };
69
70 #endif // CELLDELEGATE_H