@@ -54,6 +54,18 void peripheralWidget::mousePressEvent(Q | |||
|
54 | 54 | void peripheralWidget::mouseMoveEvent(QMouseEvent *event) |
|
55 | 55 | { |
|
56 | 56 | bool match=false; |
|
57 | if(event->buttons()==Qt::LeftButton) | |
|
58 | { | |
|
59 | for(int i=0; i<registersWdgts.count();i++) | |
|
60 | { | |
|
61 | if(registersWdgts.at(i)->contains(event->pos())) | |
|
62 | { | |
|
63 | registersWdgts.at(i)->updateSelection(registersWdgts.at(i)->cursorIndex(event->pos().x())); | |
|
64 | } | |
|
65 | } | |
|
66 | } | |
|
67 | else | |
|
68 | { | |
|
57 | 69 | for(int i=0; i<registersWdgts.count();i++) |
|
58 | 70 | { |
|
59 | 71 | if(registersWdgts.at(i)->contains(event->pos())) |
@@ -64,6 +76,7 void peripheralWidget::mouseMoveEvent(QM | |||
|
64 | 76 | } |
|
65 | 77 | if(!match)QToolTip::hideText(); |
|
66 | 78 | } |
|
79 | } | |
|
67 | 80 | |
|
68 | 81 | void peripheralWidget::mouseReleaseEvent(QMouseEvent *event) |
|
69 | 82 | { |
@@ -158,9 +171,9 void peripheralWidget::up() | |||
|
158 | 171 | { |
|
159 | 172 | if(selectedReg!=-1 && selectedReg >0) |
|
160 | 173 | { |
|
174 | registersWdgts.at(selectedReg-1)->enter(registersWdgts.at(selectedReg)->cursorIndex()); | |
|
161 | 175 | registersWdgts.at(selectedReg)->leave(); |
|
162 | 176 | selectedReg-=1; |
|
163 | registersWdgts.at(selectedReg)->enter(registersWdgts.at(selectedReg+1)->cursorIndex()); | |
|
164 | 177 | repaint(); |
|
165 | 178 | } |
|
166 | 179 | } |
@@ -169,9 +182,9 void peripheralWidget::down() | |||
|
169 | 182 | { |
|
170 | 183 | if(selectedReg!=-1 && selectedReg <(registersWdgts.count()-1)) |
|
171 | 184 | { |
|
185 | registersWdgts.at(selectedReg+1)->enter(registersWdgts.at(selectedReg)->cursorIndex()); | |
|
172 | 186 | registersWdgts.at(selectedReg)->leave(); |
|
173 | 187 | selectedReg+=1; |
|
174 | registersWdgts.at(selectedReg)->enter(registersWdgts.at(selectedReg-1)->cursorIndex()); | |
|
175 | 188 | repaint(); |
|
176 | 189 | } |
|
177 | 190 | } |
@@ -44,6 +44,7 private: | |||
|
44 | 44 | QList<registerWidget*> registersWdgts; |
|
45 | 45 | int selectedReg; |
|
46 | 46 | QTimer* p_timer; |
|
47 | ||
|
47 | 48 | }; |
|
48 | 49 | |
|
49 | 50 | #endif // PERIPHERALWIDGET_H |
@@ -11,7 +11,7 registerWidget::registerWidget(const QSt | |||
|
11 | 11 | p_fieldsEl = new bitfieldsElement(QString("%1").arg((uint)p_value,32,2).replace(" ","0"),QFont("Utopia", 12),4,4); |
|
12 | 12 | p_nameEl = new regWidgetElement(name,QFont("Utopia", 12,QFont::Bold),4,4); |
|
13 | 13 | p_xMargins = 4; |
|
14 |
p_yMargins = |
|
|
14 | p_yMargins = 6; | |
|
15 | 15 | updateBoundingRect(); |
|
16 | 16 | } |
|
17 | 17 | |
@@ -57,6 +57,13 uint registerWidget::cursorIndex(int xPo | |||
|
57 | 57 | { |
|
58 | 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 | 69 | qint32 registerWidget::address() |
@@ -137,11 +144,14 bitfieldsElement::bitfieldsElement(const | |||
|
137 | 144 | { |
|
138 | 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 | 151 | p_blinkTextBgColor = QColor(Qt::black); |
|
142 | 152 | p_blinkTextColor = QColor(Qt::white); |
|
143 | 153 | p_cursorBlinkEnable = false; |
|
144 | p_dx=QFontMetrics(p_font).width("0")+2; | |
|
154 | updateBoundingRect(); | |
|
145 | 155 | } |
|
146 | 156 | |
|
147 | 157 | QPoint bitfieldsElement::paint(QPainter *painter) |
@@ -149,6 +159,7 QPoint bitfieldsElement::paint(QPainter | |||
|
149 | 159 | painter->fillRect(4,4,p_boundingRec.width(),p_boundingRec.height(),Qt::darkGray); |
|
150 | 160 | painter->fillRect(0,0,p_boundingRec.width(),p_boundingRec.height(),Qt::white); |
|
151 | 161 | painter->setFont(p_font); |
|
162 | int lastAttributeIndex = attributesIndex[31]; | |
|
152 | 163 | int xpos=p_xMargins; |
|
153 | 164 | for(int i=0;i<(32/4);i++) |
|
154 | 165 | { |
@@ -156,6 +167,16 QPoint bitfieldsElement::paint(QPainter | |||
|
156 | 167 | { |
|
157 | 168 | if(p_cursorBlinkEnable == false || (31-p_cursorIndex) != ((i*4)+l)) |
|
158 | 169 | { |
|
170 | if(p_startSelectionIndex!=-1 && p_stopSelectionIndex!=-1 && p_startSelectionIndex <=31-((i*4)+l) && p_stopSelectionIndex >=31-((i*4)+l)) | |
|
171 | { | |
|
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); | |
|
177 | } | |
|
178 | else | |
|
179 | { | |
|
159 | 180 | if(attributesLUT[attributesIndex[31-((i*4)+l)]]->rw==false) |
|
160 | 181 | { |
|
161 | 182 | painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::lightGray); |
@@ -166,6 +187,7 QPoint bitfieldsElement::paint(QPainter | |||
|
166 | 187 | } |
|
167 | 188 | painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); |
|
168 | 189 | } |
|
190 | } | |
|
169 | 191 | else |
|
170 | 192 | { |
|
171 | 193 | QPen svg = painter->pen(); |
@@ -174,12 +196,15 QPoint bitfieldsElement::paint(QPainter | |||
|
174 | 196 | painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); |
|
175 | 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 | 202 | xpos+=p_dx; |
|
178 | 203 | } |
|
179 | 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 | 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 | 208 | xpos+=p_xMargins; |
|
184 | 209 | } |
|
185 | 210 | painter->drawRect(0,0,p_boundingRec.width(),p_boundingRec.height()); |
@@ -189,7 +214,7 QPoint bitfieldsElement::paint(QPainter | |||
|
189 | 214 | void bitfieldsElement::updateBoundingRect() |
|
190 | 215 | { |
|
191 | 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 | 218 | p_boundingRec.setWidth(width); |
|
194 | 219 | } |
|
195 | 220 | |
@@ -211,6 +236,8 void bitfieldsElement::moveCursorLeft(in | |||
|
211 | 236 | { |
|
212 | 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 | 249 | p_cursorIndex = 0; |
|
223 | 250 | } |
|
251 | p_startSelectionIndex = p_cursorIndex; | |
|
252 | p_stopSelectionIndex = p_cursorIndex; | |
|
224 | 253 | } |
|
225 | 254 | |
|
226 | 255 | void bitfieldsElement::enter(int index) |
|
227 | 256 | { |
|
228 | 257 | p_cursorIndex = index; |
|
229 | 258 | p_cursorBlinkEnable = true; |
|
259 | p_startSelectionIndex = -1; | |
|
260 | p_stopSelectionIndex = -1; | |
|
230 | 261 | } |
|
231 | 262 | |
|
232 | 263 | void bitfieldsElement::leave() |
|
233 | 264 | { |
|
234 | 265 | p_cursorBlinkEnable = false; |
|
266 | p_cursorIndex = -1; | |
|
267 | p_startSelectionIndex = -1; | |
|
268 | p_stopSelectionIndex = -1; | |
|
235 | 269 | } |
|
236 | 270 | |
|
237 | 271 | uint bitfieldsElement::cursorIndex() |
@@ -256,3 +290,48 void bitfieldsElement::setFont(QFont fon | |||
|
256 | 290 | p_dx=QFontMetrics(p_font).width("0")+2; |
|
257 | 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 | 79 | uint cursorIndex(); |
|
80 | 80 | uint cursorIndex(int xPos); |
|
81 | 81 | void setFont(QFont font); |
|
82 | ||
|
83 | void updateSelection(int index); | |
|
82 | 84 | int addAttribute(const QString& description,bool rw) |
|
83 | 85 | { |
|
84 | 86 | attributesLUT.append(new bitFieldAttribute(rw,description)); |
@@ -101,6 +103,8 public: | |||
|
101 | 103 | private: |
|
102 | 104 | int attributesIndex[32]; |
|
103 | 105 | uint p_cursorIndex; |
|
106 | uint p_startSelectionIndex; | |
|
107 | uint p_stopSelectionIndex; | |
|
104 | 108 | bool p_cursorBlinkEnable; |
|
105 | 109 | int p_dx; |
|
106 | 110 | QList<bitFieldAttribute*> attributesLUT; |
@@ -120,6 +124,7 public: | |||
|
120 | 124 | QRect boundingRect(); |
|
121 | 125 | uint cursorIndex(); |
|
122 | 126 | uint cursorIndex(int xPos); |
|
127 | void updateSelection(int index); | |
|
123 | 128 | qint32 address(); |
|
124 | 129 | qint32 value(); |
|
125 | 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