@@ -54,15 +54,28 void peripheralWidget::mousePressEvent(Q | |||||
54 | void peripheralWidget::mouseMoveEvent(QMouseEvent *event) |
|
54 | void peripheralWidget::mouseMoveEvent(QMouseEvent *event) | |
55 | { |
|
55 | { | |
56 | bool match=false; |
|
56 | bool match=false; | |
57 | for(int i=0; i<registersWdgts.count();i++) |
|
57 | if(event->buttons()==Qt::LeftButton) | |
58 | { |
|
58 | { | |
59 | if(registersWdgts.at(i)->contains(event->pos())) |
|
59 | for(int i=0; i<registersWdgts.count();i++) | |
60 | { |
|
60 | { | |
61 | match = true; |
|
61 | if(registersWdgts.at(i)->contains(event->pos())) | |
62 | QToolTip::showText(event->globalPos(),registersWdgts.at(i)->bitFieldDesc(registersWdgts.at(i)->cursorIndex(event->pos().x())),(QWidget*)this); |
|
62 | { | |
|
63 | registersWdgts.at(i)->updateSelection(registersWdgts.at(i)->cursorIndex(event->pos().x())); | |||
|
64 | } | |||
63 | } |
|
65 | } | |
64 | } |
|
66 | } | |
65 | if(!match)QToolTip::hideText(); |
|
67 | else | |
|
68 | { | |||
|
69 | for(int i=0; i<registersWdgts.count();i++) | |||
|
70 | { | |||
|
71 | if(registersWdgts.at(i)->contains(event->pos())) | |||
|
72 | { | |||
|
73 | match = true; | |||
|
74 | QToolTip::showText(event->globalPos(),registersWdgts.at(i)->bitFieldDesc(registersWdgts.at(i)->cursorIndex(event->pos().x())),(QWidget*)this); | |||
|
75 | } | |||
|
76 | } | |||
|
77 | if(!match)QToolTip::hideText(); | |||
|
78 | } | |||
66 | } |
|
79 | } | |
67 |
|
80 | |||
68 | void peripheralWidget::mouseReleaseEvent(QMouseEvent *event) |
|
81 | void peripheralWidget::mouseReleaseEvent(QMouseEvent *event) | |
@@ -158,9 +171,9 void peripheralWidget::up() | |||||
158 | { |
|
171 | { | |
159 | if(selectedReg!=-1 && selectedReg >0) |
|
172 | if(selectedReg!=-1 && selectedReg >0) | |
160 | { |
|
173 | { | |
|
174 | registersWdgts.at(selectedReg-1)->enter(registersWdgts.at(selectedReg)->cursorIndex()); | |||
161 | registersWdgts.at(selectedReg)->leave(); |
|
175 | registersWdgts.at(selectedReg)->leave(); | |
162 | selectedReg-=1; |
|
176 | selectedReg-=1; | |
163 | registersWdgts.at(selectedReg)->enter(registersWdgts.at(selectedReg+1)->cursorIndex()); |
|
|||
164 | repaint(); |
|
177 | repaint(); | |
165 | } |
|
178 | } | |
166 | } |
|
179 | } | |
@@ -169,9 +182,9 void peripheralWidget::down() | |||||
169 | { |
|
182 | { | |
170 | if(selectedReg!=-1 && selectedReg <(registersWdgts.count()-1)) |
|
183 | if(selectedReg!=-1 && selectedReg <(registersWdgts.count()-1)) | |
171 | { |
|
184 | { | |
|
185 | registersWdgts.at(selectedReg+1)->enter(registersWdgts.at(selectedReg)->cursorIndex()); | |||
172 | registersWdgts.at(selectedReg)->leave(); |
|
186 | registersWdgts.at(selectedReg)->leave(); | |
173 | selectedReg+=1; |
|
187 | selectedReg+=1; | |
174 | registersWdgts.at(selectedReg)->enter(registersWdgts.at(selectedReg-1)->cursorIndex()); |
|
|||
175 | repaint(); |
|
188 | repaint(); | |
176 | } |
|
189 | } | |
177 | } |
|
190 | } |
@@ -44,6 +44,7 private: | |||||
44 | QList<registerWidget*> registersWdgts; |
|
44 | QList<registerWidget*> registersWdgts; | |
45 | int selectedReg; |
|
45 | int selectedReg; | |
46 | QTimer* p_timer; |
|
46 | QTimer* p_timer; | |
|
47 | ||||
47 | }; |
|
48 | }; | |
48 |
|
49 | |||
49 | #endif // PERIPHERALWIDGET_H |
|
50 | #endif // PERIPHERALWIDGET_H |
@@ -11,7 +11,7 registerWidget::registerWidget(const QSt | |||||
11 | p_fieldsEl = new bitfieldsElement(QString("%1").arg((uint)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 = |
|
14 | p_yMargins = 6; | |
15 | updateBoundingRect(); |
|
15 | updateBoundingRect(); | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
@@ -57,6 +57,13 uint registerWidget::cursorIndex(int xPo | |||||
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 | return 0; | |||
|
61 | } | |||
|
62 | ||||
|
63 | void registerWidget::updateSelection(int index) | |||
|
64 | { | |||
|
65 | p_fieldsEl->updateSelection(index); | |||
|
66 | emit this->repaint(); | |||
60 | } |
|
67 | } | |
61 |
|
68 | |||
62 | qint32 registerWidget::address() |
|
69 | qint32 registerWidget::address() | |
@@ -137,11 +144,14 bitfieldsElement::bitfieldsElement(const | |||||
137 | { |
|
144 | { | |
138 | attributesIndex[i] = 0; |
|
145 | attributesIndex[i] = 0; | |
139 | } |
|
146 | } | |
140 | updateBoundingRect(); |
|
147 | p_startSelectionIndex = -1; | |
|
148 | p_stopSelectionIndex = -1; | |||
|
149 | p_cursorIndex = -1; | |||
|
150 | p_dx=QFontMetrics(p_font).width("0")+4; | |||
141 | p_blinkTextBgColor = QColor(Qt::black); |
|
151 | p_blinkTextBgColor = QColor(Qt::black); | |
142 | p_blinkTextColor = QColor(Qt::white); |
|
152 | p_blinkTextColor = QColor(Qt::white); | |
143 | p_cursorBlinkEnable = false; |
|
153 | p_cursorBlinkEnable = false; | |
144 | p_dx=QFontMetrics(p_font).width("0")+2; |
|
154 | updateBoundingRect(); | |
145 | } |
|
155 | } | |
146 |
|
156 | |||
147 | QPoint bitfieldsElement::paint(QPainter *painter) |
|
157 | QPoint bitfieldsElement::paint(QPainter *painter) | |
@@ -149,6 +159,7 QPoint bitfieldsElement::paint(QPainter | |||||
149 | painter->fillRect(4,4,p_boundingRec.width(),p_boundingRec.height(),Qt::darkGray); |
|
159 | 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); |
|
160 | painter->fillRect(0,0,p_boundingRec.width(),p_boundingRec.height(),Qt::white); | |
151 | painter->setFont(p_font); |
|
161 | painter->setFont(p_font); | |
|
162 | int lastAttributeIndex = attributesIndex[31]; | |||
152 | int xpos=p_xMargins; |
|
163 | int xpos=p_xMargins; | |
153 | for(int i=0;i<(32/4);i++) |
|
164 | for(int i=0;i<(32/4);i++) | |
154 | { |
|
165 | { | |
@@ -156,15 +167,26 QPoint bitfieldsElement::paint(QPainter | |||||
156 | { |
|
167 | { | |
157 | if(p_cursorBlinkEnable == false || (31-p_cursorIndex) != ((i*4)+l)) |
|
168 | if(p_cursorBlinkEnable == false || (31-p_cursorIndex) != ((i*4)+l)) | |
158 | { |
|
169 | { | |
159 | if(attributesLUT[attributesIndex[31-((i*4)+l)]]->rw==false) |
|
170 | if(p_startSelectionIndex!=-1 && p_stopSelectionIndex!=-1 && p_startSelectionIndex <=31-((i*4)+l) && p_stopSelectionIndex >=31-((i*4)+l)) | |
160 | { |
|
171 | { | |
161 | painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::lightGray); |
|
172 | QPen svg = painter->pen(); | |
|
173 | painter->setPen(p_blinkTextColor); | |||
|
174 | painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::blue); | |||
|
175 | painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); | |||
|
176 | painter->setPen(svg); | |||
162 | } |
|
177 | } | |
163 | else |
|
178 | else | |
164 | { |
|
179 | { | |
165 | painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::white); |
|
180 | if(attributesLUT[attributesIndex[31-((i*4)+l)]]->rw==false) | |
|
181 | { | |||
|
182 | painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::lightGray); | |||
|
183 | } | |||
|
184 | else | |||
|
185 | { | |||
|
186 | painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::white); | |||
|
187 | } | |||
|
188 | painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); | |||
166 | } |
|
189 | } | |
167 | painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); |
|
|||
168 | } |
|
190 | } | |
169 | else |
|
191 | else | |
170 | { |
|
192 | { | |
@@ -174,12 +196,15 QPoint bitfieldsElement::paint(QPainter | |||||
174 | painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); |
|
196 | painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); | |
175 | painter->setPen(svg); |
|
197 | painter->setPen(svg); | |
176 | } |
|
198 | } | |
|
199 | if(lastAttributeIndex!=attributesIndex[31-((i*4)+l)]) | |||
|
200 | painter->drawLine(xpos-(p_xMargins/2),0,xpos-(p_xMargins/2),p_boundingRec.height()); | |||
|
201 | lastAttributeIndex=attributesIndex[31-((i*4)+l)]; | |||
177 | xpos+=p_dx; |
|
202 | xpos+=p_dx; | |
178 | } |
|
203 | } | |
179 | if(i==3) |
|
204 | if(i==3) | |
180 |
painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+ |
|
205 | painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+12); | |
181 | else if(i<7) |
|
206 | else if(i<7) | |
182 |
painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()- |
|
207 | painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+6); | |
183 | xpos+=p_xMargins; |
|
208 | xpos+=p_xMargins; | |
184 | } |
|
209 | } | |
185 | painter->drawRect(0,0,p_boundingRec.width(),p_boundingRec.height()); |
|
210 | painter->drawRect(0,0,p_boundingRec.width(),p_boundingRec.height()); | |
@@ -189,7 +214,7 QPoint bitfieldsElement::paint(QPainter | |||||
189 | void bitfieldsElement::updateBoundingRect() |
|
214 | void bitfieldsElement::updateBoundingRect() | |
190 | { |
|
215 | { | |
191 | p_boundingRec.setHeight(QFontMetrics(p_font).boundingRect(p_valueStr).height()+(p_yMargins*2)); |
|
216 | p_boundingRec.setHeight(QFontMetrics(p_font).boundingRect(p_valueStr).height()+(p_yMargins*2)); | |
192 |
int width = (((4*( |
|
217 | int width = (((4*(p_dx)) + p_xMargins) * 8) + (p_xMargins); | |
193 | p_boundingRec.setWidth(width); |
|
218 | p_boundingRec.setWidth(width); | |
194 | } |
|
219 | } | |
195 |
|
220 | |||
@@ -211,6 +236,8 void bitfieldsElement::moveCursorLeft(in | |||||
211 | { |
|
236 | { | |
212 | p_cursorIndex = 31; |
|
237 | p_cursorIndex = 31; | |
213 | } |
|
238 | } | |
|
239 | p_startSelectionIndex = p_cursorIndex; | |||
|
240 | p_stopSelectionIndex = p_cursorIndex; | |||
214 |
|
241 | |||
215 | } |
|
242 | } | |
216 |
|
243 | |||
@@ -221,17 +248,24 void bitfieldsElement::moveCursorRight(i | |||||
221 | { |
|
248 | { | |
222 | p_cursorIndex = 0; |
|
249 | p_cursorIndex = 0; | |
223 | } |
|
250 | } | |
|
251 | p_startSelectionIndex = p_cursorIndex; | |||
|
252 | p_stopSelectionIndex = p_cursorIndex; | |||
224 | } |
|
253 | } | |
225 |
|
254 | |||
226 | void bitfieldsElement::enter(int index) |
|
255 | void bitfieldsElement::enter(int index) | |
227 | { |
|
256 | { | |
228 | p_cursorIndex = index; |
|
257 | p_cursorIndex = index; | |
229 | p_cursorBlinkEnable = true; |
|
258 | p_cursorBlinkEnable = true; | |
|
259 | p_startSelectionIndex = -1; | |||
|
260 | p_stopSelectionIndex = -1; | |||
230 | } |
|
261 | } | |
231 |
|
262 | |||
232 | void bitfieldsElement::leave() |
|
263 | void bitfieldsElement::leave() | |
233 | { |
|
264 | { | |
234 | p_cursorBlinkEnable = false; |
|
265 | p_cursorBlinkEnable = false; | |
|
266 | p_cursorIndex = -1; | |||
|
267 | p_startSelectionIndex = -1; | |||
|
268 | p_stopSelectionIndex = -1; | |||
235 | } |
|
269 | } | |
236 |
|
270 | |||
237 | uint bitfieldsElement::cursorIndex() |
|
271 | uint bitfieldsElement::cursorIndex() | |
@@ -256,3 +290,48 void bitfieldsElement::setFont(QFont fon | |||||
256 | p_dx=QFontMetrics(p_font).width("0")+2; |
|
290 | p_dx=QFontMetrics(p_font).width("0")+2; | |
257 | updateBoundingRect(); |
|
291 | updateBoundingRect(); | |
258 | } |
|
292 | } | |
|
293 | ||||
|
294 | void bitfieldsElement::updateSelection(int index) | |||
|
295 | { | |||
|
296 | if(p_cursorIndex!=-1) | |||
|
297 | { | |||
|
298 | if(p_startSelectionIndex!=-1 && p_stopSelectionIndex!= -1) | |||
|
299 | { | |||
|
300 | if(index>=p_stopSelectionIndex) | |||
|
301 | { | |||
|
302 | p_stopSelectionIndex = index; | |||
|
303 | p_cursorIndex = index; | |||
|
304 | } | |||
|
305 | else | |||
|
306 | { | |||
|
307 | p_startSelectionIndex = index; | |||
|
308 | p_cursorIndex = index; | |||
|
309 | } | |||
|
310 | } | |||
|
311 | else | |||
|
312 | { | |||
|
313 | if(index>p_cursorIndex) | |||
|
314 | { | |||
|
315 | p_startSelectionIndex = p_cursorIndex; | |||
|
316 | p_stopSelectionIndex = index; | |||
|
317 | } | |||
|
318 | else | |||
|
319 | { | |||
|
320 | p_startSelectionIndex = index; | |||
|
321 | p_stopSelectionIndex = p_cursorIndex; | |||
|
322 | } | |||
|
323 | } | |||
|
324 | } | |||
|
325 | } | |||
|
326 | ||||
|
327 | ||||
|
328 | ||||
|
329 | ||||
|
330 | ||||
|
331 | ||||
|
332 | ||||
|
333 | ||||
|
334 | ||||
|
335 | ||||
|
336 | ||||
|
337 |
@@ -79,6 +79,8 public: | |||||
79 | uint cursorIndex(); |
|
79 | uint cursorIndex(); | |
80 | uint cursorIndex(int xPos); |
|
80 | uint cursorIndex(int xPos); | |
81 | void setFont(QFont font); |
|
81 | void setFont(QFont font); | |
|
82 | ||||
|
83 | void updateSelection(int index); | |||
82 | int addAttribute(const QString& description,bool rw) |
|
84 | int addAttribute(const QString& description,bool rw) | |
83 | { |
|
85 | { | |
84 | attributesLUT.append(new bitFieldAttribute(rw,description)); |
|
86 | attributesLUT.append(new bitFieldAttribute(rw,description)); | |
@@ -101,6 +103,8 public: | |||||
101 | private: |
|
103 | private: | |
102 | int attributesIndex[32]; |
|
104 | int attributesIndex[32]; | |
103 | uint p_cursorIndex; |
|
105 | uint p_cursorIndex; | |
|
106 | uint p_startSelectionIndex; | |||
|
107 | uint p_stopSelectionIndex; | |||
104 | bool p_cursorBlinkEnable; |
|
108 | bool p_cursorBlinkEnable; | |
105 | int p_dx; |
|
109 | int p_dx; | |
106 | QList<bitFieldAttribute*> attributesLUT; |
|
110 | QList<bitFieldAttribute*> attributesLUT; | |
@@ -120,6 +124,7 public: | |||||
120 | QRect boundingRect(); |
|
124 | QRect boundingRect(); | |
121 | uint cursorIndex(); |
|
125 | uint cursorIndex(); | |
122 | uint cursorIndex(int xPos); |
|
126 | uint cursorIndex(int xPos); | |
|
127 | void updateSelection(int index); | |||
123 | qint32 address(); |
|
128 | qint32 address(); | |
124 | qint32 value(); |
|
129 | qint32 value(); | |
125 | void setBitFieldAttribute(uint startIndex,uint stopIndex,const QString& description,bool rw) |
|
130 | void setBitFieldAttribute(uint startIndex,uint stopIndex,const QString& description,bool rw) |
General Comments 0
You need to be logged in to leave comments.
Login now