Introduce user mode (Basic and Pro)
[scorecard] / src / cell-delegate.h
1 /*
2  * Copyright (C) 2009 Sakari Poussa
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, version 2.
7  */
8
9 #ifndef CELLDELEGATE_H
10 #define CELLDELEGATE_H
11
12 #include <QItemDelegate>
13 #include <QEvent>
14 #include <QKeyEvent>
15 #include <QDebug>
16 //#include "cell.h"
17
18 class CellFilter : public QObject
19 {
20   Q_OBJECT
21
22 public:
23  CellFilter(QObject *parent=0) : QObject(parent) 
24   {
25     m_parent = parent;
26   }
27
28  signals:
29   void nextCell(QObject *);
30
31 protected:
32   bool eventFilter(QObject *dist, QEvent *event)
33   {
34     if (event->type() == QEvent::KeyPress) {
35       QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
36       static QString digits = QString("123456789");
37       if (digits.indexOf(keyEvent->text()) != -1) {
38         qDebug() << "Key press number";
39         int rc = QObject::eventFilter(dist, event);
40         emit nextCell(m_parent);
41         //return rc;
42         return false;
43       }
44       else {
45         qDebug() << "Key press invalid";
46         return true;
47       }
48     }
49
50   }
51  private:
52   QObject *m_parent;
53 };
54
55 class RowDelegate : public QItemDelegate
56 {
57     Q_OBJECT
58
59 public:
60     RowDelegate(QObject *parent = 0);
61
62 private slots:
63     void commitAndCloseEditor();
64
65  private:
66     QObject *m_parent;
67 };
68
69 class CellDelegate : public QItemDelegate
70 {
71     Q_OBJECT
72
73 public:
74     CellDelegate(QObject *parent = 0);
75     QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &,
76                           const QModelIndex &index) const;
77     void setEditorData(QWidget *editor, const QModelIndex &index) const;
78     void setModelData(QWidget *editor, QAbstractItemModel *model,
79                       const QModelIndex &index) const;
80     CellFilter *filter;
81
82  signals:
83   void nextCell(QObject *);
84
85 private slots:
86     void commitAndCloseEditor();
87
88  private:
89     QObject *m_parent;
90 };
91
92 #endif // CELLDELEGATE_H