##// END OF EJS Templates
Improved bitfield tooltip, improved register navigation with keyboard.
Jeandet Alexis -
r11:93fabd3c8cad default
parent child
Show More
@@ -31,6 +31,36 void peripheralWidget::addRegister(const
31 connect(registersWdgts.last(),SIGNAL(repaint()),this,SLOT(repaint()));
31 connect(registersWdgts.last(),SIGNAL(repaint()),this,SLOT(repaint()));
32 }
32 }
33
33
34 void peripheralWidget::leave()
35 {
36 if(selectedReg!=-1)
37 {
38 p_timer->stop();
39 registersWdgts.at(selectedReg)->leave();
40 selectedReg = -1;
41 repaint();
42 }
43 }
44
45 void peripheralWidget::enter(int cursorIndex, bool fromTop)
46 {
47 if(cursorIndex>=0 && cursorIndex<32)
48 {
49 if(fromTop)
50 {
51 registersWdgts.at(0)->enter(cursorIndex);
52 selectedReg = 0;
53 }
54 else
55 {
56 registersWdgts.at(registersWdgts.count()-1)->enter(cursorIndex);
57 selectedReg = registersWdgts.count()-1;
58 }
59 p_timer->start();
60 this->setFocus();
61 }
62 }
63
34 void peripheralWidget::mousePressEvent(QMouseEvent *event)
64 void peripheralWidget::mousePressEvent(QMouseEvent *event)
35 {
65 {
36 p_timer->stop();
66 p_timer->stop();
@@ -46,6 +76,7 void peripheralWidget::mousePressEvent(Q
46 registersWdgts.at(i)->enter(registersWdgts.at(i)->cursorIndex(event->pos().x()));
76 registersWdgts.at(i)->enter(registersWdgts.at(i)->cursorIndex(event->pos().x()));
47 selectedReg = i;
77 selectedReg = i;
48 p_timer->start();
78 p_timer->start();
79 emit clicked(this);
49 }
80 }
50 }
81 }
51 repaint();
82 repaint();
@@ -71,7 +102,13 void peripheralWidget::mouseMoveEvent(QM
71 if(registersWdgts.at(i)->contains(event->pos()))
102 if(registersWdgts.at(i)->contains(event->pos()))
72 {
103 {
73 match = true;
104 match = true;
74 QToolTip::showText(event->globalPos(),registersWdgts.at(i)->bitFieldDesc(registersWdgts.at(i)->cursorIndex(event->pos().x())),(QWidget*)this);
105 int bitfieldIndex=registersWdgts.at(i)->cursorIndex(event->pos().x());
106
107 QString toolTipText ="<b>< font color='Black'>"+registersWdgts.at(i)->bitFieldName(bitfieldIndex) +"</b><br />";
108 toolTipText+= "Hexadecimal=<b>< font color='Blue'>"+registersWdgts.at(i)->bitFieldToHex(bitfieldIndex)+"</b>";
109 toolTipText+= " Decimal=<b>< font color='BlueViolet'>"+registersWdgts.at(i)->bitFieldToDec(bitfieldIndex)+"</b><br />";
110 toolTipText+= registersWdgts.at(i)->bitFieldDesc(bitfieldIndex);
111 QToolTip::showText(event->globalPos(),toolTipText,(QWidget*)this);
75 }
112 }
76 }
113 }
77 if(!match)QToolTip::hideText();
114 if(!match)QToolTip::hideText();
@@ -169,22 +206,36 void peripheralWidget::paintEvent(QPaint
169
206
170 void peripheralWidget::up()
207 void peripheralWidget::up()
171 {
208 {
172 if(selectedReg!=-1 && selectedReg >0)
209 if(selectedReg!=-1)
173 {
210 {
174 registersWdgts.at(selectedReg-1)->enter(registersWdgts.at(selectedReg)->cursorIndex());
211 if(selectedReg >0)
175 registersWdgts.at(selectedReg)->leave();
212 {
176 selectedReg-=1;
213 registersWdgts.at(selectedReg-1)->enter(registersWdgts.at(selectedReg)->cursorIndex());
177 repaint();
214 registersWdgts.at(selectedReg)->leave();
215 selectedReg-=1;
216 repaint();
217 }
218 else
219 {
220 emit upSig(this,registersWdgts.at(selectedReg)->cursorIndex());
221 }
178 }
222 }
179 }
223 }
180
224
181 void peripheralWidget::down()
225 void peripheralWidget::down()
182 {
226 {
183 if(selectedReg!=-1 && selectedReg <(registersWdgts.count()-1))
227 if(selectedReg!=-1)
184 {
228 {
185 registersWdgts.at(selectedReg+1)->enter(registersWdgts.at(selectedReg)->cursorIndex());
229 if(selectedReg <(registersWdgts.count()-1))
186 registersWdgts.at(selectedReg)->leave();
230 {
187 selectedReg+=1;
231 registersWdgts.at(selectedReg+1)->enter(registersWdgts.at(selectedReg)->cursorIndex());
188 repaint();
232 registersWdgts.at(selectedReg)->leave();
233 selectedReg+=1;
234 repaint();
235 }
236 else
237 {
238 emit downSig(this,registersWdgts.at(selectedReg)->cursorIndex());
239 }
189 }
240 }
190 }
241 }
@@ -31,9 +31,14 public:
31 signals:
31 signals:
32 void writeRegSig(qint32 address,qint32 value);
32 void writeRegSig(qint32 address,qint32 value);
33 qint32 readRegSig(qint32 address);
33 qint32 readRegSig(qint32 address);
34 void clicked(peripheralWidget* sender);
35 void upSig(peripheralWidget* sender,int cursorIndex);
36 void downSig(peripheralWidget* sender,int cursorIndex);
34 public slots:
37 public slots:
35 void blinkCursor();
38 void blinkCursor();
36 void addRegister(const QString& name,qint32 address);
39 void addRegister(const QString& name,qint32 address);
40 void leave();
41 void enter(int cursorIndex,bool fromTop=true);
37 protected:
42 protected:
38 void mousePressEvent(QMouseEvent *event);
43 void mousePressEvent(QMouseEvent *event);
39 void mouseMoveEvent(QMouseEvent *event);
44 void mouseMoveEvent(QMouseEvent *event);
@@ -76,6 +76,59 qint32 registerWidget::value()
76 return p_value;
76 return p_value;
77 }
77 }
78
78
79 void registerWidget::setBitFieldAttribute(uint startIndex, uint stopIndex, const QString &name, const QString &description, bool rw)
80 {
81 if(startIndex<=stopIndex && stopIndex<32)
82 {
83 int index= p_fieldsEl->addAttribute(name,description,rw );
84 for(uint i=startIndex;i<=stopIndex;i++)
85 {
86 p_fieldsEl->setAttribute(i,index);
87 }
88 }
89 }
90
91 QString registerWidget::bitFieldDesc(int bitIndex)
92 {
93 if(bitIndex>=0 && bitIndex<32)
94 {
95 return p_fieldsEl->description(bitIndex);
96 }
97 return QString("Out of range");
98 }
99
100 QString registerWidget::bitFieldName(int bitIndex)
101 {
102 if(bitIndex>=0 && bitIndex<32)
103 {
104 return p_fieldsEl->name(bitIndex);
105 }
106 return QString("Out of range");
107 }
108
109 QString registerWidget::bitFieldToHex(int bitIndex)
110 {
111 if(bitIndex>=0 && bitIndex<32)
112 {
113 return p_fieldsEl->valueHex(bitIndex);
114 }
115 return QString("Out of range");
116 }
117
118 QString registerWidget::bitFieldToDec(int bitIndex)
119 {
120 if(bitIndex>=0 && bitIndex<32)
121 {
122 return p_fieldsEl->valueDec(bitIndex);
123 }
124 return QString("Out of range");
125 }
126
127 QString registerWidget::bitFieldToBin(int bitIndex)
128 {
129
130 }
131
79 void registerWidget::setValue(qint32 value)
132 void registerWidget::setValue(qint32 value)
80 {
133 {
81 this->p_value = value;
134 this->p_value = value;
@@ -139,7 +192,7 void registerWidget::updateBoundingRect(
139 bitfieldsElement::bitfieldsElement(const QString &value, QFont font, int xMargin, int yMargin)
192 bitfieldsElement::bitfieldsElement(const QString &value, QFont font, int xMargin, int yMargin)
140 :regWidgetElement(value,font,xMargin,yMargin)
193 :regWidgetElement(value,font,xMargin,yMargin)
141 {
194 {
142 this->attributesLUT.append(new bitFieldAttribute(false,"UNSUSED"));
195 this->attributesLUT.append(new bitFieldAttribute(false,"UNSUSED","UNSUSED"));
143 for(int i=0;i<32;i++)
196 for(int i=0;i<32;i++)
144 {
197 {
145 attributesIndex[i] = 0;
198 attributesIndex[i] = 0;
@@ -57,13 +57,15 class bitfieldsElement: public regWidget
57 class bitFieldAttribute
57 class bitFieldAttribute
58 {
58 {
59 public:
59 public:
60 bitFieldAttribute(bool rw,QString description)
60 bitFieldAttribute(bool rw,QString name,QString description)
61 {
61 {
62 this->rw = rw;
62 this->rw = rw;
63 this->Name = name;
63 this->description = description;
64 this->description = description;
64 }
65 }
65 bool rw;
66 bool rw;
66 QString description;
67 QString description;
68 QString Name;
67 };
69 };
68 public:
70 public:
69 bitfieldsElement(const QString& value,QFont font,int xMargin,int yMargin);
71 bitfieldsElement(const QString& value,QFont font,int xMargin,int yMargin);
@@ -79,20 +81,34 public:
79 uint cursorIndex();
81 uint cursorIndex();
80 uint cursorIndex(int xPos);
82 uint cursorIndex(int xPos);
81 void setFont(QFont font);
83 void setFont(QFont font);
82
83 void updateSelection(int index);
84 void updateSelection(int index);
84 int addAttribute(const QString& description,bool rw)
85 int addAttribute(const QString& name,const QString& description,bool rw)
85 {
86 {
86 attributesLUT.append(new bitFieldAttribute(rw,description));
87 attributesLUT.append(new bitFieldAttribute(rw,name,description));
87 return attributesLUT.count()-1;
88 return attributesLUT.count()-1;
88 }
89 }
90
89 int setAttribute(int bitIndex,int attributeIndex)
91 int setAttribute(int bitIndex,int attributeIndex)
90 {
92 {
91 attributesIndex[bitIndex]=attributeIndex;
93 if(bitIndex>=0 && bitIndex<32 && attributeIndex>=0 && attributeIndex<(attributesLUT.count()))
94 {
95 attributesIndex[bitIndex]=attributeIndex;
96 return 0;
97 }
98 return -1;
92 }
99 }
100
93 QString description(int bitIndex)
101 QString description(int bitIndex)
94 {
102 {
95 return attributesLUT.at(attributesIndex[bitIndex])->description;
103 if(bitIndex>=0 && bitIndex<32)
104 return attributesLUT.at(attributesIndex[bitIndex])->description;
105 return QString("");
106 }
107 QString name(int bitIndex)
108 {
109 if(bitIndex>=0 && bitIndex<32)
110 return attributesLUT.at(attributesIndex[bitIndex])->Name;
111 return QString("");
96 }
112 }
97 bool readonly(int bitIndex)
113 bool readonly(int bitIndex)
98 {
114 {
@@ -100,7 +116,50 public:
100 return !attributesLUT.at(attributesIndex[bitIndex])->rw;
116 return !attributesLUT.at(attributesIndex[bitIndex])->rw;
101 return false;
117 return false;
102 }
118 }
119 QString valueHex(int index)
120 {
121 if(index>=0 && index<32)
122 {
123 return "0x" + QString::number(p_valueUint(index),16);
124 }
125 return QString("");
126 }
127 QString valueDec(int index)
128 {
129 if(index>=0 && index<32)
130 {
131 return QString::number(p_valueUint(index),10);
132 }
133 return QString("");
134 }
103 private:
135 private:
136 uint p_valueUint(int index)
137 {
138 uint value;
139 int attributeIndex = attributesIndex[index];
140 int startIndex = index;
141 int stopIndex=0;
142 while (startIndex>0)
143 {
144 if(attributesIndex[startIndex-1]==attributeIndex)
145 startIndex--;
146 else
147 break;
148 }
149 stopIndex = startIndex;
150 while (stopIndex<32)
151 {
152 if(attributesIndex[stopIndex+1]==attributeIndex)
153 stopIndex++;
154 else
155 break;
156 }
157 bool ok;
158 value = p_valueStr.toUInt(&ok,2);
159 value = (uint)0xFFFFFFFF & (value<<(31-stopIndex));
160 value = (uint)0xFFFFFFFF & (value>>(31-stopIndex+startIndex));
161 return value;
162 }
104 int attributesIndex[32];
163 int attributesIndex[32];
105 uint p_cursorIndex;
164 uint p_cursorIndex;
106 uint p_startSelectionIndex;
165 uint p_startSelectionIndex;
@@ -127,22 +186,12 public:
127 void updateSelection(int index);
186 void updateSelection(int index);
128 qint32 address();
187 qint32 address();
129 qint32 value();
188 qint32 value();
130 void setBitFieldAttribute(uint startIndex,uint stopIndex,const QString& description,bool rw)
189 void setBitFieldAttribute(uint startIndex,uint stopIndex,const QString& name,const QString& description,bool rw);
131 {
190 QString bitFieldDesc(int bitIndex);
132 if(startIndex<=stopIndex && stopIndex<32)
191 QString bitFieldName(int bitIndex);
133 {
192 QString bitFieldToHex(int bitIndex);
134 int index= p_fieldsEl->addAttribute(description,rw );
193 QString bitFieldToDec(int bitIndex);
135 for(uint i=startIndex;i<=stopIndex;i++)
194 QString bitFieldToBin(int bitIndex);
136 {
137 p_fieldsEl->setAttribute(i,index);
138 }
139 }
140 }
141 QString bitFieldDesc(int bitIndex)
142 {
143 return p_fieldsEl->description(bitIndex);
144 }
145
146 signals:
195 signals:
147 void cursorUp(int pos);
196 void cursorUp(int pos);
148 void cursorDown(int pos);
197 void cursorDown(int pos);
@@ -29,5 +29,54 void socRegsViewer::addPeripheral(periph
29 {
29 {
30 p_peripherals.append(peripheral);
30 p_peripherals.append(peripheral);
31 p_scrollAreaWdgtLayout->addWidget(peripheral,p_peripherals.count(),0,1,-1);
31 p_scrollAreaWdgtLayout->addWidget(peripheral,p_peripherals.count(),0,1,-1);
32 connect(peripheral,SIGNAL(clicked(peripheralWidget*)),this,SLOT(periphClicked(peripheralWidget*)));
33 connect(peripheral,SIGNAL(upSig(peripheralWidget*,int)),this,SLOT(periphUp(peripheralWidget*,int)));
34 connect(peripheral,SIGNAL(downSig(peripheralWidget*,int)),this,SLOT(periphDown(peripheralWidget*,int)));
35 }
36 }
37
38 void socRegsViewer::periphClicked(peripheralWidget *sender)
39 {
40 peripheralWidget * item;
41 if(sender!=NULL)
42 {
43 for(int i=0;i<p_peripherals.count();i++)
44 {
45 item = p_peripherals.at(i);
46 if(item!=sender)
47 {
48 item->leave();
49 }
50 }
32 }
51 }
33 }
52 }
53
54 void socRegsViewer::periphUp(peripheralWidget *sender, int cursorIndex)
55 {
56 int index;
57 if(sender!=NULL)
58 {
59 index = p_peripherals.indexOf(sender);
60 if(index!=-1 && index!=0)
61 {
62 p_peripherals.at(index)->leave();
63 p_peripherals.at(index-1)->enter(cursorIndex,false);
64 ensureWidgetVisible(p_peripherals.at(index-1));
65 }
66 }
67 }
68
69 void socRegsViewer::periphDown(peripheralWidget *sender, int cursorIndex)
70 {
71 int index;
72 if(sender!=NULL)
73 {
74 index = p_peripherals.indexOf(sender);
75 if(index!=-1 && index<(p_peripherals.count()-1))
76 {
77 p_peripherals.at(index)->leave();
78 p_peripherals.at(index+1)->enter(cursorIndex);
79 ensureWidgetVisible(p_peripherals.at(index+1));
80 }
81 }
82 }
@@ -22,7 +22,9 signals:
22
22
23 public slots:
23 public slots:
24 void addPeripheral(peripheralWidget* peripheral);
24 void addPeripheral(peripheralWidget* peripheral);
25
25 void periphClicked(peripheralWidget* sender);
26 void periphUp(peripheralWidget* sender,int cursorIndex);
27 void periphDown(peripheralWidget* sender,int cursorIndex);
26 private:
28 private:
27 QWidget* p_scrollAreaWdgt;
29 QWidget* p_scrollAreaWdgt;
28 QString p_name;
30 QString p_name;
General Comments 0
You need to be logged in to leave comments. Login now