@@ -1,258 +1,258 | |||||
1 | #include "registerwidget.h" |
|
1 | #include "registerwidget.h" | |
2 | #include <QPaintEvent> |
|
2 | #include <QPaintEvent> | |
3 | #include <QPainter> |
|
3 | #include <QPainter> | |
4 |
|
4 | |||
5 | registerWidget::registerWidget(const QString &name, qint32 address, QObject *parent) : |
|
5 | registerWidget::registerWidget(const QString &name, qint32 address, QObject *parent) : | |
6 | QObject(parent) |
|
6 | QObject(parent) | |
7 | { |
|
7 | { | |
8 | p_address = address; |
|
8 | p_address = address; | |
9 | p_value = 0; |
|
9 | p_value = 0; | |
10 | p_addressEl = new regWidgetElement(QString("0x%1").arg(p_address,8,16).replace(" ","0"),QFont("Utopia", 12),10,4); |
|
10 | p_addressEl = new regWidgetElement(QString("0x%1").arg((uint)p_address,8,16).replace(" ","0"),QFont("Utopia", 12),10,4); | |
11 | p_fieldsEl = new bitfieldsElement(QString("%1").arg(p_value,32,2).replace(" ","0"),QFont("Utopia", 12),4,4); |
|
11 | p_fieldsEl = new bitfieldsElement(QString("%1").arg((uint)p_value,32,2).replace(" ","0"),QFont("Utopia", 12),4,4); | |
12 | p_nameEl = new regWidgetElement(name,QFont("Utopia", 12,QFont::Bold),4,4); |
|
12 | p_nameEl = new regWidgetElement(name,QFont("Utopia", 12,QFont::Bold),4,4); | |
13 | p_xMargins = 4; |
|
13 | p_xMargins = 4; | |
14 | p_yMargins = 4; |
|
14 | p_yMargins = 4; | |
15 | updateBoundingRect(); |
|
15 | updateBoundingRect(); | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 | registerWidget::~registerWidget() |
|
18 | registerWidget::~registerWidget() | |
19 | { |
|
19 | { | |
20 | delete p_addressEl; |
|
20 | delete p_addressEl; | |
21 | delete p_fieldsEl; |
|
21 | delete p_fieldsEl; | |
22 | delete p_nameEl; |
|
22 | delete p_nameEl; | |
23 | } |
|
23 | } | |
24 |
|
24 | |||
25 | int registerWidget::contains(const QPointF &point) |
|
25 | int registerWidget::contains(const QPointF &point) | |
26 | { |
|
26 | { | |
27 | return p_boundingRect.contains(point.x(),point.y()); |
|
27 | return p_boundingRect.contains(point.x(),point.y()); | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | QPoint registerWidget::paint(QPainter* painter, QPoint offset) |
|
30 | QPoint registerWidget::paint(QPainter* painter, QPoint offset) | |
31 | { |
|
31 | { | |
32 | painter->save(); |
|
32 | painter->save(); | |
33 | painter->translate(offset); |
|
33 | painter->translate(offset); | |
34 | p_boundingRect.moveTopLeft(offset); |
|
34 | p_boundingRect.moveTopLeft(offset); | |
35 | painter->translate(p_addressEl->paint(painter)); |
|
35 | painter->translate(p_addressEl->paint(painter)); | |
36 | painter->translate(p_fieldsEl->paint(painter)); |
|
36 | painter->translate(p_fieldsEl->paint(painter)); | |
37 | p_nameEl->paint(painter); |
|
37 | p_nameEl->paint(painter); | |
38 | painter->restore(); |
|
38 | painter->restore(); | |
39 | int h=p_boundingRect.height(); |
|
39 | int h=p_boundingRect.height(); | |
40 | int y=p_boundingRect.y(); |
|
40 | int y=p_boundingRect.y(); | |
41 | return QPoint(0,p_boundingRect.height()+p_boundingRect.y()+p_yMargins); |
|
41 | return QPoint(0,p_boundingRect.height()+p_boundingRect.y()+p_yMargins); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | QRect registerWidget::boundingRect() |
|
44 | QRect registerWidget::boundingRect() | |
45 | { |
|
45 | { | |
46 | return p_boundingRect; |
|
46 | return p_boundingRect; | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | uint registerWidget::cursorIndex() |
|
49 | uint registerWidget::cursorIndex() | |
50 | { |
|
50 | { | |
51 | return p_fieldsEl->cursorIndex(); |
|
51 | return p_fieldsEl->cursorIndex(); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | uint registerWidget::cursorIndex(int xPos) |
|
54 | uint registerWidget::cursorIndex(int xPos) | |
55 | { |
|
55 | { | |
56 | if(xPos>p_addressEl->boundingRect().width() && xPos<(p_addressEl->boundingRect().width()+p_fieldsEl->boundingRect().width())) |
|
56 | if(xPos>p_addressEl->boundingRect().width() && xPos<(p_addressEl->boundingRect().width()+p_fieldsEl->boundingRect().width())) | |
57 | { |
|
57 | { | |
58 | return p_fieldsEl->cursorIndex(xPos-p_addressEl->boundingRect().width()); |
|
58 | return p_fieldsEl->cursorIndex(xPos-p_addressEl->boundingRect().width()); | |
59 | } |
|
59 | } | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | qint32 registerWidget::address() |
|
62 | qint32 registerWidget::address() | |
63 | { |
|
63 | { | |
64 | return p_address; |
|
64 | return p_address; | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | qint32 registerWidget::value() |
|
67 | qint32 registerWidget::value() | |
68 | { |
|
68 | { | |
69 | return p_value; |
|
69 | return p_value; | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void registerWidget::setValue(qint32 value) |
|
72 | void registerWidget::setValue(qint32 value) | |
73 | { |
|
73 | { | |
74 | this->p_value = value; |
|
74 | this->p_value = value; | |
75 | this->p_fieldsEl->setValue(QString("%1").arg((uint)p_value,32,2).replace(" ","0")); |
|
75 | this->p_fieldsEl->setValue(QString("%1").arg((uint)p_value,32,2).replace(" ","0")); | |
76 | emit this->repaint(); |
|
76 | emit this->repaint(); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | void registerWidget::blinkCursor() |
|
79 | void registerWidget::blinkCursor() | |
80 | { |
|
80 | { | |
81 | p_fieldsEl->blinkCursor(); |
|
81 | p_fieldsEl->blinkCursor(); | |
82 | //repaint(); |
|
82 | //repaint(); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | void registerWidget::moveCursorLeft(int count) |
|
85 | void registerWidget::moveCursorLeft(int count) | |
86 | { |
|
86 | { | |
87 | p_fieldsEl->moveCursorLeft(count); |
|
87 | p_fieldsEl->moveCursorLeft(count); | |
88 | p_fieldsEl->blinkCursor(); |
|
88 | p_fieldsEl->blinkCursor(); | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | void registerWidget::moveCursorRight(int count) |
|
91 | void registerWidget::moveCursorRight(int count) | |
92 | { |
|
92 | { | |
93 | p_fieldsEl->moveCursorRight(count); |
|
93 | p_fieldsEl->moveCursorRight(count); | |
94 | p_fieldsEl->blinkCursor(); |
|
94 | p_fieldsEl->blinkCursor(); | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | void registerWidget::enter(int index) |
|
97 | void registerWidget::enter(int index) | |
98 | { |
|
98 | { | |
99 | p_fieldsEl->enter(index); |
|
99 | p_fieldsEl->enter(index); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | void registerWidget::leave() |
|
102 | void registerWidget::leave() | |
103 | { |
|
103 | { | |
104 | p_fieldsEl->leave(); |
|
104 | p_fieldsEl->leave(); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | void registerWidget::clear(int index) |
|
107 | void registerWidget::clear(int index) | |
108 | { |
|
108 | { | |
109 | p_value &= ~(1<<index); |
|
109 | p_value &= ~(1<<index); | |
110 | this->p_fieldsEl->setValue(QString("%1").arg((uint)p_value,32,2).replace(" ","0")); |
|
110 | this->p_fieldsEl->setValue(QString("%1").arg((uint)p_value,32,2).replace(" ","0")); | |
111 | emit this->repaint(); |
|
111 | emit this->repaint(); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | void registerWidget::set(int index) |
|
114 | void registerWidget::set(int index) | |
115 | { |
|
115 | { | |
116 | if(!this->p_fieldsEl->readonly(index)) |
|
116 | if(!this->p_fieldsEl->readonly(index)) | |
117 | { |
|
117 | { | |
118 | p_value |= 1<<index; |
|
118 | p_value |= 1<<index; | |
119 | this->p_fieldsEl->setValue(QString("%1").arg((uint)p_value,32,2).replace(" ","0")); |
|
119 | this->p_fieldsEl->setValue(QString("%1").arg((uint)p_value,32,2).replace(" ","0")); | |
120 | emit this->repaint(); |
|
120 | emit this->repaint(); | |
121 | } |
|
121 | } | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | void registerWidget::updateBoundingRect() |
|
124 | void registerWidget::updateBoundingRect() | |
125 | { |
|
125 | { | |
126 | p_boundingRect.setHeight(p_fieldsEl->boundingRect().height()+(p_yMargins*2)); |
|
126 | p_boundingRect.setHeight(p_fieldsEl->boundingRect().height()+(p_yMargins*2)); | |
127 | p_boundingRect.setWidth(p_fieldsEl->boundingRect().width()+p_addressEl->boundingRect().width()+p_nameEl->boundingRect().width()+(p_xMargins*2)); |
|
127 | p_boundingRect.setWidth(p_fieldsEl->boundingRect().width()+p_addressEl->boundingRect().width()+p_nameEl->boundingRect().width()+(p_xMargins*2)); | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 |
|
130 | |||
131 |
|
131 | |||
132 | bitfieldsElement::bitfieldsElement(const QString &value, QFont font, int xMargin, int yMargin) |
|
132 | bitfieldsElement::bitfieldsElement(const QString &value, QFont font, int xMargin, int yMargin) | |
133 | :regWidgetElement(value,font,xMargin,yMargin) |
|
133 | :regWidgetElement(value,font,xMargin,yMargin) | |
134 | { |
|
134 | { | |
135 | this->attributesLUT.append(new bitFieldAttribute(false,"UNSUSED")); |
|
135 | this->attributesLUT.append(new bitFieldAttribute(false,"UNSUSED")); | |
136 | for(int i=0;i<32;i++) |
|
136 | for(int i=0;i<32;i++) | |
137 | { |
|
137 | { | |
138 | attributesIndex[i] = 0; |
|
138 | attributesIndex[i] = 0; | |
139 | } |
|
139 | } | |
140 | updateBoundingRect(); |
|
140 | updateBoundingRect(); | |
141 | p_blinkTextBgColor = QColor(Qt::black); |
|
141 | p_blinkTextBgColor = QColor(Qt::black); | |
142 | p_blinkTextColor = QColor(Qt::white); |
|
142 | p_blinkTextColor = QColor(Qt::white); | |
143 | p_cursorBlinkEnable = false; |
|
143 | p_cursorBlinkEnable = false; | |
144 | p_dx=QFontMetrics(p_font).width("0")+2; |
|
144 | p_dx=QFontMetrics(p_font).width("0")+2; | |
145 | } |
|
145 | } | |
146 |
|
146 | |||
147 | QPoint bitfieldsElement::paint(QPainter *painter) |
|
147 | QPoint bitfieldsElement::paint(QPainter *painter) | |
148 | { |
|
148 | { | |
149 | painter->fillRect(4,4,p_boundingRec.width(),p_boundingRec.height(),Qt::darkGray); |
|
149 | painter->fillRect(4,4,p_boundingRec.width(),p_boundingRec.height(),Qt::darkGray); | |
150 | painter->fillRect(0,0,p_boundingRec.width(),p_boundingRec.height(),Qt::white); |
|
150 | painter->fillRect(0,0,p_boundingRec.width(),p_boundingRec.height(),Qt::white); | |
151 | painter->setFont(p_font); |
|
151 | painter->setFont(p_font); | |
152 | int xpos=p_xMargins; |
|
152 | int xpos=p_xMargins; | |
153 | for(int i=0;i<(32/4);i++) |
|
153 | for(int i=0;i<(32/4);i++) | |
154 | { |
|
154 | { | |
155 | for(int l = 0;l<4;l++) |
|
155 | for(int l = 0;l<4;l++) | |
156 | { |
|
156 | { | |
157 | if(p_cursorBlinkEnable == false || (31-p_cursorIndex) != ((i*4)+l)) |
|
157 | if(p_cursorBlinkEnable == false || (31-p_cursorIndex) != ((i*4)+l)) | |
158 | { |
|
158 | { | |
159 | if(attributesLUT[attributesIndex[31-((i*4)+l)]]->rw==false) |
|
159 | if(attributesLUT[attributesIndex[31-((i*4)+l)]]->rw==false) | |
160 | { |
|
160 | { | |
161 | painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::lightGray); |
|
161 | painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::lightGray); | |
162 | } |
|
162 | } | |
163 | else |
|
163 | else | |
164 | { |
|
164 | { | |
165 | painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::white); |
|
165 | painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::white); | |
166 | } |
|
166 | } | |
167 | painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); |
|
167 | painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); | |
168 | } |
|
168 | } | |
169 | else |
|
169 | else | |
170 | { |
|
170 | { | |
171 | QPen svg = painter->pen(); |
|
171 | QPen svg = painter->pen(); | |
172 | painter->setPen(p_blinkTextColor); |
|
172 | painter->setPen(p_blinkTextColor); | |
173 | painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),p_blinkTextBgColor); |
|
173 | painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),p_blinkTextBgColor); | |
174 | painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); |
|
174 | painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); | |
175 | painter->setPen(svg); |
|
175 | painter->setPen(svg); | |
176 | } |
|
176 | } | |
177 | xpos+=p_dx; |
|
177 | xpos+=p_dx; | |
178 | } |
|
178 | } | |
179 | if(i==3) |
|
179 | if(i==3) | |
180 | painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+6); |
|
180 | painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+6); | |
181 | else if(i<7) |
|
181 | else if(i<7) | |
182 | painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-2,xpos+(p_xMargins/2),p_boundingRec.height()+2); |
|
182 | painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-2,xpos+(p_xMargins/2),p_boundingRec.height()+2); | |
183 | xpos+=p_xMargins; |
|
183 | xpos+=p_xMargins; | |
184 | } |
|
184 | } | |
185 | painter->drawRect(0,0,p_boundingRec.width(),p_boundingRec.height()); |
|
185 | painter->drawRect(0,0,p_boundingRec.width(),p_boundingRec.height()); | |
186 | return QPoint(p_boundingRec.width()+4+p_xMargins,0); |
|
186 | return QPoint(p_boundingRec.width()+4+p_xMargins,0); | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | void bitfieldsElement::updateBoundingRect() |
|
189 | void bitfieldsElement::updateBoundingRect() | |
190 | { |
|
190 | { | |
191 | p_boundingRec.setHeight(QFontMetrics(p_font).boundingRect(p_valueStr).height()+(p_yMargins*2)); |
|
191 | p_boundingRec.setHeight(QFontMetrics(p_font).boundingRect(p_valueStr).height()+(p_yMargins*2)); | |
192 | int width = (((4*(QFontMetrics(p_font).width("0") + 2)) + p_xMargins) * 8) + (p_xMargins); |
|
192 | int width = (((4*(QFontMetrics(p_font).width("0") + 2)) + p_xMargins) * 8) + (p_xMargins); | |
193 | p_boundingRec.setWidth(width); |
|
193 | p_boundingRec.setWidth(width); | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | void bitfieldsElement::setValue(const QString &value) |
|
196 | void bitfieldsElement::setValue(const QString &value) | |
197 | { |
|
197 | { | |
198 | p_valueStr = value; |
|
198 | p_valueStr = value; | |
199 | updateBoundingRect(); |
|
199 | updateBoundingRect(); | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | void bitfieldsElement::blinkCursor() |
|
202 | void bitfieldsElement::blinkCursor() | |
203 | { |
|
203 | { | |
204 | p_cursorBlinkEnable = !p_cursorBlinkEnable; |
|
204 | p_cursorBlinkEnable = !p_cursorBlinkEnable; | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | void bitfieldsElement::moveCursorLeft(int count) |
|
207 | void bitfieldsElement::moveCursorLeft(int count) | |
208 | { |
|
208 | { | |
209 | p_cursorIndex+=count; |
|
209 | p_cursorIndex+=count; | |
210 | if(31<p_cursorIndex) |
|
210 | if(31<p_cursorIndex) | |
211 | { |
|
211 | { | |
212 | p_cursorIndex = 31; |
|
212 | p_cursorIndex = 31; | |
213 | } |
|
213 | } | |
214 |
|
214 | |||
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | void bitfieldsElement::moveCursorRight(int count) |
|
217 | void bitfieldsElement::moveCursorRight(int count) | |
218 | { |
|
218 | { | |
219 | p_cursorIndex -= count; |
|
219 | p_cursorIndex -= count; | |
220 | if(31<p_cursorIndex) |
|
220 | if(31<p_cursorIndex) | |
221 | { |
|
221 | { | |
222 | p_cursorIndex = 0; |
|
222 | p_cursorIndex = 0; | |
223 | } |
|
223 | } | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 | void bitfieldsElement::enter(int index) |
|
226 | void bitfieldsElement::enter(int index) | |
227 | { |
|
227 | { | |
228 | p_cursorIndex = index; |
|
228 | p_cursorIndex = index; | |
229 | p_cursorBlinkEnable = true; |
|
229 | p_cursorBlinkEnable = true; | |
230 | } |
|
230 | } | |
231 |
|
231 | |||
232 | void bitfieldsElement::leave() |
|
232 | void bitfieldsElement::leave() | |
233 | { |
|
233 | { | |
234 | p_cursorBlinkEnable = false; |
|
234 | p_cursorBlinkEnable = false; | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | uint bitfieldsElement::cursorIndex() |
|
237 | uint bitfieldsElement::cursorIndex() | |
238 | { |
|
238 | { | |
239 | return p_cursorIndex; |
|
239 | return p_cursorIndex; | |
240 | } |
|
240 | } | |
241 |
|
241 | |||
242 | uint bitfieldsElement::cursorIndex(int xPos) |
|
242 | uint bitfieldsElement::cursorIndex(int xPos) | |
243 | { |
|
243 | { | |
244 | uint index=0; |
|
244 | uint index=0; | |
245 | xPos-=p_xMargins; |
|
245 | xPos-=p_xMargins; | |
246 | if(xPos<p_boundingRec.width()) |
|
246 | if(xPos<p_boundingRec.width()) | |
247 | { |
|
247 | { | |
248 | index = 31 - ((4*xPos)/((4*p_dx)+p_xMargins)); |
|
248 | index = 31 - ((4*xPos)/((4*p_dx)+p_xMargins)); | |
249 | } |
|
249 | } | |
250 | return index; |
|
250 | return index; | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | void bitfieldsElement::setFont(QFont font) |
|
253 | void bitfieldsElement::setFont(QFont font) | |
254 | { |
|
254 | { | |
255 | p_font = font; |
|
255 | p_font = font; | |
256 | p_dx=QFontMetrics(p_font).width("0")+2; |
|
256 | p_dx=QFontMetrics(p_font).width("0")+2; | |
257 | updateBoundingRect(); |
|
257 | updateBoundingRect(); | |
258 | } |
|
258 | } |
General Comments 0
You need to be logged in to leave comments.
Login now