1 #ifndef CANDATAGRID_H
2 #define CANDATAGRID_H
3 
4 #include <QWidget>
5 
6 namespace Ui {
7 class CANDataGrid;
8 }
9 
10 /*
11  * CANDataGrid is a custom QT widget that proves that it's possible to shoehorn 12x too much crap into one widget. The purported
12  * goal of the widget was to show an 8x8 grid of bits that show whether each bit in a given message is set or not. It allows one to quickly
13  * visualize the bits within a CAN frame's data bytes. From there it evolved to also show whether a given bit was freshly set recently, freshly
14  * unset recently, or has stayed set or unset for a while. It can also gray out bytes that don't exist in the current CAN frame.
15  * This is handled by the calling code.
16  *
17  * After that functionality was added so it could also emit a signal when it is clicked. The signal will tell you which "bit" cell was clicked.
18  *
19  * Then, support was added for modifying the text color of each cell. This can be used for whatever the calling code wants. An example is
20  * FlowView that uses all of the above functionality plus this functionality in order to show which bits are set as triggers for stopping
21  * the flowview playback.
22  *
23  * Now the control also tracks which signal is using which bit. Currently this is not used for graphical output. I tried but couldn't make it look
24  * like I wanted. So, it's un-used as of yet.
25  */
26 
27 enum GridTextState
28 {
29     NORMAL,
30     BOLD_BLUE,
31     INVERT
32 };
33 
34 class CANDataGrid : public QWidget
35 {
36     Q_OBJECT
37 
38 public:
39     explicit CANDataGrid(QWidget *parent = 0);
40     ~CANDataGrid();
41     void paintEvent(QPaintEvent *event);
42     void setReference(unsigned char *, bool);
43     void updateData(unsigned char *, bool);
44     void setUsed(unsigned char *, bool);
45     void saveImage(QString filename, int width, int height);
46     void setCellTextState(int x, int y, GridTextState state);
47     GridTextState getCellTextState(int x, int y);
48     void setUsedSignalNum(int bit, unsigned char signal);
49     unsigned char getUsedSignalNum(int bit);
50 
51 protected:
52     void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
53 
54 signals:
55     void gridClicked(int x,int y);
56 
57 private:
58     Ui::CANDataGrid *ui;
59     unsigned char refData[8];
60     unsigned char data[8];
61     unsigned char usedData[8];
62     unsigned char usedSignalNum[64]; //allows a full char per 64 bits we track so we can specify which signal claims this bit
63     GridTextState textStates[8][8];
64     QPoint upperLeft, gridSize;
65 };
66 
67 #endif // CANDATAGRID_H
68