@@ -1,221 +1,226 | |||||
1 | #ifndef REGISTERWIDGET_H |
|
1 | #ifndef REGISTERWIDGET_H | |
2 | #define REGISTERWIDGET_H |
|
2 | #define REGISTERWIDGET_H | |
3 | #include <QtWidgets> |
|
3 | #include <QtWidgets> | |
4 | #include <QWidget> |
|
4 | #include <QWidget> | |
5 | #include <QTimer> |
|
5 | #include <QTimer> | |
|
6 | #if defined(LPPMON_SDK_BUILD) | |||
|
7 | # define LPPMON_SDK_EXPORT Q_DECL_EXPORT | |||
|
8 | #else | |||
|
9 | # define LPPMON_SDK_EXPORT Q_DECL_IMPORT | |||
|
10 | #endif | |||
6 |
|
11 | |||
7 | class regWidgetElement |
|
12 | class LPPMON_SDK_EXPORT regWidgetElement | |
8 | { |
|
13 | { | |
9 | public: |
|
14 | public: | |
10 | regWidgetElement(const QString& value,QFont font,int xMargin,int yMargin) |
|
15 | regWidgetElement(const QString& value,QFont font,int xMargin,int yMargin) | |
11 | { |
|
16 | { | |
12 | p_valueStr = value; |
|
17 | p_valueStr = value; | |
13 | p_font = font; |
|
18 | p_font = font; | |
14 | p_xMargins = xMargin; |
|
19 | p_xMargins = xMargin; | |
15 | p_yMargins = yMargin; |
|
20 | p_yMargins = yMargin; | |
16 | updateBoundingRect(); |
|
21 | updateBoundingRect(); | |
17 | } |
|
22 | } | |
18 | void setValue(const QString& value) |
|
23 | void setValue(const QString& value) | |
19 | { |
|
24 | { | |
20 | p_valueStr = value; |
|
25 | p_valueStr = value; | |
21 | updateBoundingRect(); |
|
26 | updateBoundingRect(); | |
22 | } |
|
27 | } | |
23 | void setFont(QFont font) |
|
28 | void setFont(QFont font) | |
24 | { |
|
29 | { | |
25 | p_font = font; |
|
30 | p_font = font; | |
26 | updateBoundingRect(); |
|
31 | updateBoundingRect(); | |
27 | } |
|
32 | } | |
28 | QSize boundingRect(){return p_boundingRec;} |
|
33 | QSize boundingRect(){return p_boundingRec;} | |
29 | QString value(){return p_valueStr;} |
|
34 | QString value(){return p_valueStr;} | |
30 | const QChar at ( int position ) const{return p_valueStr.at(position);} |
|
35 | const QChar at ( int position ) const{return p_valueStr.at(position);} | |
31 | QFont font(){return p_font;} |
|
36 | QFont font(){return p_font;} | |
32 | int xMargin(){return p_xMargins;} |
|
37 | int xMargin(){return p_xMargins;} | |
33 | int yMargin(){return p_yMargins;} |
|
38 | int yMargin(){return p_yMargins;} | |
34 | QFontMetrics fontMetrics(){return QFontMetrics(p_font);} |
|
39 | QFontMetrics fontMetrics(){return QFontMetrics(p_font);} | |
35 | QPoint paint(QPainter* painter) |
|
40 | QPoint paint(QPainter* painter) | |
36 | { |
|
41 | { | |
37 | painter->setFont(p_font); |
|
42 | painter->setFont(p_font); | |
38 | painter->drawText(0,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr); |
|
43 | painter->drawText(0,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr); | |
39 | return QPoint(p_boundingRec.width(),0); |
|
44 | return QPoint(p_boundingRec.width(),0); | |
40 | } |
|
45 | } | |
41 | void updateBoundingRect() |
|
46 | void updateBoundingRect() | |
42 | { |
|
47 | { | |
43 | p_boundingRec.setHeight(QFontMetrics(p_font).boundingRect(p_valueStr).height()+(p_yMargins*2)); |
|
48 | p_boundingRec.setHeight(QFontMetrics(p_font).boundingRect(p_valueStr).height()+(p_yMargins*2)); | |
44 | p_boundingRec.setWidth(QFontMetrics(p_font).boundingRect(p_valueStr).width()+(p_xMargins*2)); |
|
49 | p_boundingRec.setWidth(QFontMetrics(p_font).boundingRect(p_valueStr).width()+(p_xMargins*2)); | |
45 | } |
|
50 | } | |
46 |
|
51 | |||
47 | protected: |
|
52 | protected: | |
48 | QString p_valueStr; |
|
53 | QString p_valueStr; | |
49 | QFont p_font; |
|
54 | QFont p_font; | |
50 | QSize p_boundingRec; |
|
55 | QSize p_boundingRec; | |
51 | int p_xMargins; |
|
56 | int p_xMargins; | |
52 | int p_yMargins; |
|
57 | int p_yMargins; | |
53 | }; |
|
58 | }; | |
54 |
|
59 | |||
55 | class bitfieldsElement: public regWidgetElement |
|
60 | class LPPMON_SDK_EXPORT bitfieldsElement: public regWidgetElement | |
56 | { |
|
61 | { | |
57 | class bitFieldAttribute |
|
62 | class bitFieldAttribute | |
58 | { |
|
63 | { | |
59 | public: |
|
64 | public: | |
60 | bitFieldAttribute(bool rw,QString name,QString description) |
|
65 | bitFieldAttribute(bool rw,QString name,QString description) | |
61 | { |
|
66 | { | |
62 | this->rw = rw; |
|
67 | this->rw = rw; | |
63 | this->Name = name; |
|
68 | this->Name = name; | |
64 | this->description = description; |
|
69 | this->description = description; | |
65 | } |
|
70 | } | |
66 | bool rw; |
|
71 | bool rw; | |
67 | QString description; |
|
72 | QString description; | |
68 | QString Name; |
|
73 | QString Name; | |
69 | }; |
|
74 | }; | |
70 | public: |
|
75 | public: | |
71 | bitfieldsElement(const QString& value,QFont font,int xMargin,int yMargin); |
|
76 | bitfieldsElement(const QString& value,QFont font,int xMargin,int yMargin); | |
72 | QPoint paint(QPainter* painter); |
|
77 | QPoint paint(QPainter* painter); | |
73 |
|
78 | |||
74 | void updateBoundingRect(); |
|
79 | void updateBoundingRect(); | |
75 | void setValue(const QString& value); |
|
80 | void setValue(const QString& value); | |
76 | void blinkCursor(); |
|
81 | void blinkCursor(); | |
77 | void moveCursorLeft(int count); |
|
82 | void moveCursorLeft(int count); | |
78 | void moveCursorRight(int count); |
|
83 | void moveCursorRight(int count); | |
79 | void enter(int index); |
|
84 | void enter(int index); | |
80 | void leave(); |
|
85 | void leave(); | |
81 | uint cursorIndex(); |
|
86 | uint cursorIndex(); | |
82 | uint cursorIndex(int xPos); |
|
87 | uint cursorIndex(int xPos); | |
83 | void setFont(QFont font); |
|
88 | void setFont(QFont font); | |
84 | void updateSelection(int index); |
|
89 | void updateSelection(int index); | |
85 | int addAttribute(const QString& name,const QString& description,bool rw) |
|
90 | int addAttribute(const QString& name,const QString& description,bool rw) | |
86 | { |
|
91 | { | |
87 | attributesLUT.append(new bitFieldAttribute(rw,name,description)); |
|
92 | attributesLUT.append(new bitFieldAttribute(rw,name,description)); | |
88 | return attributesLUT.count()-1; |
|
93 | return attributesLUT.count()-1; | |
89 | } |
|
94 | } | |
90 |
|
95 | |||
91 | int setAttribute(int bitIndex,int attributeIndex) |
|
96 | int setAttribute(int bitIndex,int attributeIndex) | |
92 | { |
|
97 | { | |
93 | if(bitIndex>=0 && bitIndex<32 && attributeIndex>=0 && attributeIndex<(attributesLUT.count())) |
|
98 | if(bitIndex>=0 && bitIndex<32 && attributeIndex>=0 && attributeIndex<(attributesLUT.count())) | |
94 | { |
|
99 | { | |
95 | attributesIndex[bitIndex]=attributeIndex; |
|
100 | attributesIndex[bitIndex]=attributeIndex; | |
96 | return 0; |
|
101 | return 0; | |
97 | } |
|
102 | } | |
98 | return -1; |
|
103 | return -1; | |
99 | } |
|
104 | } | |
100 |
|
105 | |||
101 | QString description(int bitIndex) |
|
106 | QString description(int bitIndex) | |
102 | { |
|
107 | { | |
103 | if(bitIndex>=0 && bitIndex<32) |
|
108 | if(bitIndex>=0 && bitIndex<32) | |
104 | return attributesLUT.at(attributesIndex[bitIndex])->description; |
|
109 | return attributesLUT.at(attributesIndex[bitIndex])->description; | |
105 | return QString(""); |
|
110 | return QString(""); | |
106 | } |
|
111 | } | |
107 | QString name(int bitIndex) |
|
112 | QString name(int bitIndex) | |
108 | { |
|
113 | { | |
109 | if(bitIndex>=0 && bitIndex<32) |
|
114 | if(bitIndex>=0 && bitIndex<32) | |
110 | return attributesLUT.at(attributesIndex[bitIndex])->Name; |
|
115 | return attributesLUT.at(attributesIndex[bitIndex])->Name; | |
111 | return QString(""); |
|
116 | return QString(""); | |
112 | } |
|
117 | } | |
113 | bool readonly(int bitIndex) |
|
118 | bool readonly(int bitIndex) | |
114 | { |
|
119 | { | |
115 | if(bitIndex>=0 && bitIndex<32) |
|
120 | if(bitIndex>=0 && bitIndex<32) | |
116 | return !attributesLUT.at(attributesIndex[bitIndex])->rw; |
|
121 | return !attributesLUT.at(attributesIndex[bitIndex])->rw; | |
117 | return false; |
|
122 | return false; | |
118 | } |
|
123 | } | |
119 | QString valueHex(int index) |
|
124 | QString valueHex(int index) | |
120 | { |
|
125 | { | |
121 | if(index>=0 && index<32) |
|
126 | if(index>=0 && index<32) | |
122 | { |
|
127 | { | |
123 | return "0x" + QString::number(p_valueUint(index),16); |
|
128 | return "0x" + QString::number(p_valueUint(index),16); | |
124 | } |
|
129 | } | |
125 | return QString(""); |
|
130 | return QString(""); | |
126 | } |
|
131 | } | |
127 | QString valueDec(int index) |
|
132 | QString valueDec(int index) | |
128 | { |
|
133 | { | |
129 | if(index>=0 && index<32) |
|
134 | if(index>=0 && index<32) | |
130 | { |
|
135 | { | |
131 | return QString::number(p_valueUint(index),10); |
|
136 | return QString::number(p_valueUint(index),10); | |
132 | } |
|
137 | } | |
133 | return QString(""); |
|
138 | return QString(""); | |
134 | } |
|
139 | } | |
135 | private: |
|
140 | private: | |
136 | uint p_valueUint(int index) |
|
141 | uint p_valueUint(int index) | |
137 | { |
|
142 | { | |
138 | uint value; |
|
143 | uint value; | |
139 | int attributeIndex = attributesIndex[index]; |
|
144 | int attributeIndex = attributesIndex[index]; | |
140 | int startIndex = index; |
|
145 | int startIndex = index; | |
141 | int stopIndex=0; |
|
146 | int stopIndex=0; | |
142 | while (startIndex>0) |
|
147 | while (startIndex>0) | |
143 | { |
|
148 | { | |
144 | if(attributesIndex[startIndex-1]==attributeIndex) |
|
149 | if(attributesIndex[startIndex-1]==attributeIndex) | |
145 | startIndex--; |
|
150 | startIndex--; | |
146 | else |
|
151 | else | |
147 | break; |
|
152 | break; | |
148 | } |
|
153 | } | |
149 | stopIndex = startIndex; |
|
154 | stopIndex = startIndex; | |
150 | while (stopIndex<32) |
|
155 | while (stopIndex<32) | |
151 | { |
|
156 | { | |
152 | if(attributesIndex[stopIndex+1]==attributeIndex) |
|
157 | if(attributesIndex[stopIndex+1]==attributeIndex) | |
153 | stopIndex++; |
|
158 | stopIndex++; | |
154 | else |
|
159 | else | |
155 | break; |
|
160 | break; | |
156 | } |
|
161 | } | |
157 | bool ok; |
|
162 | bool ok; | |
158 | value = p_valueStr.toUInt(&ok,2); |
|
163 | value = p_valueStr.toUInt(&ok,2); | |
159 | value = (uint)0xFFFFFFFF & (value<<(31-stopIndex)); |
|
164 | value = (uint)0xFFFFFFFF & (value<<(31-stopIndex)); | |
160 | value = (uint)0xFFFFFFFF & (value>>(31-stopIndex+startIndex)); |
|
165 | value = (uint)0xFFFFFFFF & (value>>(31-stopIndex+startIndex)); | |
161 | return value; |
|
166 | return value; | |
162 | } |
|
167 | } | |
163 | int attributesIndex[32]; |
|
168 | int attributesIndex[32]; | |
164 | uint p_cursorIndex; |
|
169 | uint p_cursorIndex; | |
165 | uint p_startSelectionIndex; |
|
170 | uint p_startSelectionIndex; | |
166 | uint p_stopSelectionIndex; |
|
171 | uint p_stopSelectionIndex; | |
167 | bool p_cursorBlinkEnable; |
|
172 | bool p_cursorBlinkEnable; | |
168 | int p_dx; |
|
173 | int p_dx; | |
169 | QList<bitFieldAttribute*> attributesLUT; |
|
174 | QList<bitFieldAttribute*> attributesLUT; | |
170 | QColor p_blinkTextColor,p_blinkTextBgColor; |
|
175 | QColor p_blinkTextColor,p_blinkTextBgColor; | |
171 |
|
176 | |||
172 | }; |
|
177 | }; | |
173 |
|
178 | |||
174 |
|
179 | |||
175 | class registerWidget : public QObject |
|
180 | class LPPMON_SDK_EXPORT registerWidget : public QObject | |
176 | { |
|
181 | { | |
177 | Q_OBJECT |
|
182 | Q_OBJECT | |
178 | public: |
|
183 | public: | |
179 | explicit registerWidget(const QString& name,qint32 address,QObject *parent = 0); |
|
184 | explicit registerWidget(const QString& name,qint32 address,QObject *parent = 0); | |
180 | ~registerWidget(); |
|
185 | ~registerWidget(); | |
181 | int contains(const QPointF &point); |
|
186 | int contains(const QPointF &point); | |
182 | QPoint paint(QPainter* painter,QPoint offset); |
|
187 | QPoint paint(QPainter* painter,QPoint offset); | |
183 | QRect boundingRect(); |
|
188 | QRect boundingRect(); | |
184 | uint cursorIndex(); |
|
189 | uint cursorIndex(); | |
185 | uint cursorIndex(int xPos); |
|
190 | uint cursorIndex(int xPos); | |
186 | void updateSelection(int index); |
|
191 | void updateSelection(int index); | |
187 | qint32 address(); |
|
192 | qint32 address(); | |
188 | qint32 value(); |
|
193 | qint32 value(); | |
189 | void setBitFieldAttribute(uint startIndex,uint stopIndex,const QString& name,const QString& description,bool rw); |
|
194 | void setBitFieldAttribute(uint startIndex,uint stopIndex,const QString& name,const QString& description,bool rw); | |
190 | QString bitFieldDesc(int bitIndex); |
|
195 | QString bitFieldDesc(int bitIndex); | |
191 | QString bitFieldName(int bitIndex); |
|
196 | QString bitFieldName(int bitIndex); | |
192 | QString bitFieldToHex(int bitIndex); |
|
197 | QString bitFieldToHex(int bitIndex); | |
193 | QString bitFieldToDec(int bitIndex); |
|
198 | QString bitFieldToDec(int bitIndex); | |
194 | QString bitFieldToBin(int bitIndex); |
|
199 | QString bitFieldToBin(int bitIndex); | |
195 | signals: |
|
200 | signals: | |
196 | void cursorUp(int pos); |
|
201 | void cursorUp(int pos); | |
197 | void cursorDown(int pos); |
|
202 | void cursorDown(int pos); | |
198 | void valueChanged(qint32 value); |
|
203 | void valueChanged(qint32 value); | |
199 | void repaint(); |
|
204 | void repaint(); | |
200 |
|
205 | |||
201 | public slots: |
|
206 | public slots: | |
202 | void setValue(qint32 value); |
|
207 | void setValue(qint32 value); | |
203 | void blinkCursor(); |
|
208 | void blinkCursor(); | |
204 | void moveCursorLeft(int count); |
|
209 | void moveCursorLeft(int count); | |
205 | void moveCursorRight(int count); |
|
210 | void moveCursorRight(int count); | |
206 | void enter(int index=0); |
|
211 | void enter(int index=0); | |
207 | void leave(); |
|
212 | void leave(); | |
208 | void clear(int index); |
|
213 | void clear(int index); | |
209 | void set(int index); |
|
214 | void set(int index); | |
210 | private: |
|
215 | private: | |
211 | void updateBoundingRect(); |
|
216 | void updateBoundingRect(); | |
212 | qint32 p_address; |
|
217 | qint32 p_address; | |
213 | qint32 p_value; |
|
218 | qint32 p_value; | |
214 | QRect p_boundingRect; |
|
219 | QRect p_boundingRect; | |
215 | int p_xMargins; |
|
220 | int p_xMargins; | |
216 | int p_yMargins; |
|
221 | int p_yMargins; | |
217 | regWidgetElement* p_addressEl,*p_nameEl; |
|
222 | regWidgetElement* p_addressEl,*p_nameEl; | |
218 | bitfieldsElement* p_fieldsEl; |
|
223 | bitfieldsElement* p_fieldsEl; | |
219 | }; |
|
224 | }; | |
220 |
|
225 | |||
221 | #endif // REGISTERWIDGET_H |
|
226 | #endif // REGISTERWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now