More color tuning
[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 CellDelegate : public QItemDelegate
56 {
57     Q_OBJECT
58
59 public:
60     CellDelegate(QObject *parent = 0);
61     QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &,
62                           const QModelIndex &index) const;
63     void setEditorData(QWidget *editor, const QModelIndex &index) const;
64     void setModelData(QWidget *editor, QAbstractItemModel *model,
65                       const QModelIndex &index) const;
66     CellFilter *filter;
67
68  signals:
69   void nextCell(QObject *);
70
71 private slots:
72     void commitAndCloseEditor();
73
74  private:
75     QObject *m_parent;
76 };
77
78 #endif // CELLDELEGATE_H