##// END OF EJS Templates
removed warnings
Jeandet Alexis -
r13:8ee59f35313b default
parent child
Show More
@@ -1,241 +1,241
1 #include "peripheralwidget.h"
1 #include "peripheralwidget.h"
2
2
3 peripheralWidget::peripheralWidget(const QString &name, qint32 baseAddress, QWidget *parent) :
3 peripheralWidget::peripheralWidget(const QString &name, qint32 baseAddress, QWidget *parent) :
4 QWidget(parent)
4 QWidget(parent)
5 {
5 {
6 p_name = name;
6 p_name = name;
7 p_timer = new QTimer(this);
7 p_timer = new QTimer(this);
8 p_timer->setInterval(500);
8 p_timer->setInterval(500);
9 p_baseAddress = baseAddress;
9 p_baseAddress = baseAddress;
10 p_header = p_name + QString(" @0x%1").arg((uint)p_baseAddress,8,16);
10 p_header = p_name + QString(" @0x%1").arg((uint)p_baseAddress,8,16);
11 setAttribute(Qt::WA_AlwaysShowToolTips);
11 setAttribute(Qt::WA_AlwaysShowToolTips);
12 setMouseTracking(true);
12 setMouseTracking(true);
13 setFocusPolicy(Qt::StrongFocus);
13 setFocusPolicy(Qt::StrongFocus);
14 selectedReg = -1;
14 selectedReg = -1;
15 registersWdgts.clear();
15 registersWdgts.clear();
16 connect(p_timer,SIGNAL(timeout()),this,SLOT(blinkCursor()));
16 connect(p_timer,SIGNAL(timeout()),this,SLOT(blinkCursor()));
17 setFont(QFont("Utopia", 14,QFont::Bold));
17 setFont(QFont("Utopia", 14,QFont::Bold));
18 }
18 }
19
19
20 void peripheralWidget::blinkCursor()
20 void peripheralWidget::blinkCursor()
21 {
21 {
22 if(selectedReg!=-1)
22 if(selectedReg!=-1)
23 registersWdgts.at(selectedReg)->blinkCursor();
23 registersWdgts.at(selectedReg)->blinkCursor();
24 repaint();
24 repaint();
25 }
25 }
26
26
27 void peripheralWidget::addRegister(const QString &name, qint32 address)
27 void peripheralWidget::addRegister(const QString &name, qint32 address)
28 {
28 {
29 /*TODO Should regs by address*/
29 /*TODO Should regs by address*/
30 registersWdgts.append(new registerWidget(name,address));
30 registersWdgts.append(new registerWidget(name,address));
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()
34 void peripheralWidget::leave()
35 {
35 {
36 if(selectedReg!=-1)
36 if(selectedReg!=-1)
37 {
37 {
38 p_timer->stop();
38 p_timer->stop();
39 registersWdgts.at(selectedReg)->leave();
39 registersWdgts.at(selectedReg)->leave();
40 selectedReg = -1;
40 selectedReg = -1;
41 repaint();
41 repaint();
42 }
42 }
43 }
43 }
44
44
45 void peripheralWidget::enter(int cursorIndex, bool fromTop)
45 void peripheralWidget::enter(int cursorIndex, bool fromTop)
46 {
46 {
47 if(cursorIndex>=0 && cursorIndex<32)
47 if(cursorIndex>=0 && cursorIndex<32)
48 {
48 {
49 if(fromTop)
49 if(fromTop)
50 {
50 {
51 registersWdgts.at(0)->enter(cursorIndex);
51 registersWdgts.at(0)->enter(cursorIndex);
52 selectedReg = 0;
52 selectedReg = 0;
53 }
53 }
54 else
54 else
55 {
55 {
56 registersWdgts.at(registersWdgts.count()-1)->enter(cursorIndex);
56 registersWdgts.at(registersWdgts.count()-1)->enter(cursorIndex);
57 selectedReg = registersWdgts.count()-1;
57 selectedReg = registersWdgts.count()-1;
58 }
58 }
59 p_timer->start();
59 p_timer->start();
60 this->setFocus();
60 this->setFocus();
61 }
61 }
62 }
62 }
63
63
64 void peripheralWidget::mousePressEvent(QMouseEvent *event)
64 void peripheralWidget::mousePressEvent(QMouseEvent *event)
65 {
65 {
66 p_timer->stop();
66 p_timer->stop();
67 if(selectedReg!=-1)
67 if(selectedReg!=-1)
68 {
68 {
69 registersWdgts.at(selectedReg)->leave();
69 registersWdgts.at(selectedReg)->leave();
70 selectedReg = -1;
70 selectedReg = -1;
71 }
71 }
72 for(int i=0; i<registersWdgts.count();i++)
72 for(int i=0; i<registersWdgts.count();i++)
73 {
73 {
74 if(registersWdgts.at(i)->contains(event->pos()))
74 if(registersWdgts.at(i)->contains(event->pos()))
75 {
75 {
76 registersWdgts.at(i)->enter(registersWdgts.at(i)->cursorIndex(event->pos().x()));
76 registersWdgts.at(i)->enter(registersWdgts.at(i)->cursorIndex(event->pos().x()));
77 selectedReg = i;
77 selectedReg = i;
78 p_timer->start();
78 p_timer->start();
79 emit clicked(this);
79 emit clicked(this);
80 }
80 }
81 }
81 }
82 repaint();
82 repaint();
83 }
83 }
84
84
85 void peripheralWidget::mouseMoveEvent(QMouseEvent *event)
85 void peripheralWidget::mouseMoveEvent(QMouseEvent *event)
86 {
86 {
87 bool match=false;
87 bool match=false;
88 if(event->buttons()==Qt::LeftButton)
88 if(event->buttons()==Qt::LeftButton)
89 {
89 {
90 for(int i=0; i<registersWdgts.count();i++)
90 for(int i=0; i<registersWdgts.count();i++)
91 {
91 {
92 if(registersWdgts.at(i)->contains(event->pos()))
92 if(registersWdgts.at(i)->contains(event->pos()))
93 {
93 {
94 registersWdgts.at(i)->updateSelection(registersWdgts.at(i)->cursorIndex(event->pos().x()));
94 registersWdgts.at(i)->updateSelection(registersWdgts.at(i)->cursorIndex(event->pos().x()));
95 }
95 }
96 }
96 }
97 }
97 }
98 else
98 else
99 {
99 {
100 for(int i=0; i<registersWdgts.count();i++)
100 for(int i=0; i<registersWdgts.count();i++)
101 {
101 {
102 if(registersWdgts.at(i)->contains(event->pos()))
102 if(registersWdgts.at(i)->contains(event->pos()))
103 {
103 {
104 match = true;
104 match = true;
105 int bitfieldIndex=registersWdgts.at(i)->cursorIndex(event->pos().x());
105 int bitfieldIndex=registersWdgts.at(i)->cursorIndex(event->pos().x());
106
106
107 QString toolTipText ="<b>< font color='Black'>"+registersWdgts.at(i)->bitFieldName(bitfieldIndex) +"</b><br />";
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>";
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 />";
109 toolTipText+= " Decimal=<b>< font color='BlueViolet'>"+registersWdgts.at(i)->bitFieldToDec(bitfieldIndex)+"</b><br />";
110 toolTipText+= registersWdgts.at(i)->bitFieldDesc(bitfieldIndex);
110 toolTipText+= registersWdgts.at(i)->bitFieldDesc(bitfieldIndex);
111 QToolTip::showText(event->globalPos(),toolTipText,(QWidget*)this);
111 QToolTip::showText(event->globalPos(),toolTipText,(QWidget*)this);
112 }
112 }
113 }
113 }
114 if(!match)QToolTip::hideText();
114 if(!match)QToolTip::hideText();
115 }
115 }
116 }
116 }
117
117
118 void peripheralWidget::mouseReleaseEvent(QMouseEvent *event)
118 void peripheralWidget::mouseReleaseEvent(QMouseEvent *event)
119 {
119 {
120
120 Q_UNUSED(event)
121 }
121 }
122
122
123 void peripheralWidget::keyPressEvent(QKeyEvent *event)
123 void peripheralWidget::keyPressEvent(QKeyEvent *event)
124 {
124 {
125 if(this->selectedReg!=-1){
125 if(this->selectedReg!=-1){
126 if(event->modifiers()==Qt::ControlModifier)
126 if(event->modifiers()==Qt::ControlModifier)
127 {
127 {
128 switch(event->key())
128 switch(event->key())
129 {
129 {
130 case Qt::Key_Up:
130 case Qt::Key_Up:
131 registersWdgts.at(selectedReg)->set(registersWdgts.at(selectedReg)->cursorIndex());
131 registersWdgts.at(selectedReg)->set(registersWdgts.at(selectedReg)->cursorIndex());
132 break;
132 break;
133 case Qt::Key_Down:
133 case Qt::Key_Down:
134 registersWdgts.at(selectedReg)->clear(registersWdgts.at(selectedReg)->cursorIndex());
134 registersWdgts.at(selectedReg)->clear(registersWdgts.at(selectedReg)->cursorIndex());
135 break;
135 break;
136 case Qt::Key_W:
136 case Qt::Key_W:
137 emit writeRegSig(registersWdgts.at(selectedReg)->address(),registersWdgts.at(selectedReg)->value());
137 emit writeRegSig(registersWdgts.at(selectedReg)->address(),registersWdgts.at(selectedReg)->value());
138 break;
138 break;
139 case Qt::Key_R:
139 case Qt::Key_R:
140 qint32 value;
140 qint32 value;
141 value = emit readRegSig(registersWdgts.at(selectedReg)->address());
141 value = emit readRegSig(registersWdgts.at(selectedReg)->address());
142 registersWdgts.at(selectedReg)->setValue(value);
142 registersWdgts.at(selectedReg)->setValue(value);
143 break;
143 break;
144 default:
144 default:
145 break;
145 break;
146 }
146 }
147 }
147 }
148 else
148 else
149 {
149 {
150 switch(event->key())
150 switch(event->key())
151 {
151 {
152 case Qt::Key_0:
152 case Qt::Key_0:
153 registersWdgts.at(selectedReg)->clear(registersWdgts.at(selectedReg)->cursorIndex());
153 registersWdgts.at(selectedReg)->clear(registersWdgts.at(selectedReg)->cursorIndex());
154 registersWdgts.at(selectedReg)->moveCursorRight(1);
154 registersWdgts.at(selectedReg)->moveCursorRight(1);
155 break;
155 break;
156 case Qt::Key_1:
156 case Qt::Key_1:
157 registersWdgts.at(selectedReg)->set(registersWdgts.at(selectedReg)->cursorIndex());
157 registersWdgts.at(selectedReg)->set(registersWdgts.at(selectedReg)->cursorIndex());
158 registersWdgts.at(selectedReg)->moveCursorRight(1);
158 registersWdgts.at(selectedReg)->moveCursorRight(1);
159 break;
159 break;
160 case Qt::Key_Right:
160 case Qt::Key_Right:
161 registersWdgts.at(selectedReg)->moveCursorRight(1);
161 registersWdgts.at(selectedReg)->moveCursorRight(1);
162 this->repaint();
162 this->repaint();
163 break;
163 break;
164 case Qt::Key_Left:
164 case Qt::Key_Left:
165 registersWdgts.at(selectedReg)->moveCursorLeft(1);
165 registersWdgts.at(selectedReg)->moveCursorLeft(1);
166 this->repaint();
166 this->repaint();
167 break;
167 break;
168 case Qt::Key_Up:
168 case Qt::Key_Up:
169 up();
169 up();
170 break;
170 break;
171 case Qt::Key_Down:
171 case Qt::Key_Down:
172 down();
172 down();
173 break;
173 break;
174 default:
174 default:
175 break;
175 break;
176 }
176 }
177 }
177 }
178
178
179 }
179 }
180 }
180 }
181
181
182 void peripheralWidget::paintEvent(QPaintEvent *event)
182 void peripheralWidget::paintEvent(QPaintEvent *event)
183 {
183 {
184 Q_UNUSED(event)
184 Q_UNUSED(event)
185
185
186 QPainter painter(this);
186 QPainter painter(this);
187 QPoint offset=QPoint(0,0);
187 QPoint offset=QPoint(0,0);
188 int nameWidth = fontMetrics().width(p_header);
188 int nameWidth = fontMetrics().width(p_header);
189 if(registersWdgts.count()==0)
189 if(registersWdgts.count()==0)
190 {
190 {
191 setMinimumSize(2*nameWidth+10,fontMetrics().height()+10);
191 setMinimumSize(2*nameWidth+10,fontMetrics().height()+10);
192 }
192 }
193 painter.drawText((this->minimumWidth()/2)-nameWidth,4,fontMetrics().width(p_header),fontMetrics().height()+4,Qt::AlignCenter,p_header);
193 painter.drawText((this->minimumWidth()/2)-nameWidth,4,fontMetrics().width(p_header),fontMetrics().height()+4,Qt::AlignCenter,p_header);
194 offset+=QPoint(0,fontMetrics().height()+8);
194 offset+=QPoint(0,fontMetrics().height()+8);
195 for(int i=0;i<registersWdgts.count();i++)
195 for(int i=0;i<registersWdgts.count();i++)
196 {
196 {
197 offset = registersWdgts.at(i)->paint(&painter,offset);
197 offset = registersWdgts.at(i)->paint(&painter,offset);
198 }
198 }
199 if(registersWdgts.count()>0)
199 if(registersWdgts.count()>0)
200 {
200 {
201 setMinimumSize(registersWdgts.first()->boundingRect().width(),offset.y());
201 setMinimumSize(registersWdgts.first()->boundingRect().width(),offset.y());
202 }
202 }
203 updateGeometry();
203 updateGeometry();
204
204
205 }
205 }
206
206
207 void peripheralWidget::up()
207 void peripheralWidget::up()
208 {
208 {
209 if(selectedReg!=-1)
209 if(selectedReg!=-1)
210 {
210 {
211 if(selectedReg >0)
211 if(selectedReg >0)
212 {
212 {
213 registersWdgts.at(selectedReg-1)->enter(registersWdgts.at(selectedReg)->cursorIndex());
213 registersWdgts.at(selectedReg-1)->enter(registersWdgts.at(selectedReg)->cursorIndex());
214 registersWdgts.at(selectedReg)->leave();
214 registersWdgts.at(selectedReg)->leave();
215 selectedReg-=1;
215 selectedReg-=1;
216 repaint();
216 repaint();
217 }
217 }
218 else
218 else
219 {
219 {
220 emit upSig(this,registersWdgts.at(selectedReg)->cursorIndex());
220 emit upSig(this,registersWdgts.at(selectedReg)->cursorIndex());
221 }
221 }
222 }
222 }
223 }
223 }
224
224
225 void peripheralWidget::down()
225 void peripheralWidget::down()
226 {
226 {
227 if(selectedReg!=-1)
227 if(selectedReg!=-1)
228 {
228 {
229 if(selectedReg <(registersWdgts.count()-1))
229 if(selectedReg <(registersWdgts.count()-1))
230 {
230 {
231 registersWdgts.at(selectedReg+1)->enter(registersWdgts.at(selectedReg)->cursorIndex());
231 registersWdgts.at(selectedReg+1)->enter(registersWdgts.at(selectedReg)->cursorIndex());
232 registersWdgts.at(selectedReg)->leave();
232 registersWdgts.at(selectedReg)->leave();
233 selectedReg+=1;
233 selectedReg+=1;
234 repaint();
234 repaint();
235 }
235 }
236 else
236 else
237 {
237 {
238 emit downSig(this,registersWdgts.at(selectedReg)->cursorIndex());
238 emit downSig(this,registersWdgts.at(selectedReg)->cursorIndex());
239 }
239 }
240 }
240 }
241 }
241 }
@@ -1,390 +1,393
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((uint)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((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 = 6;
14 p_yMargins = 6;
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();
40 int y=p_boundingRect.y();
41 return QPoint(0,p_boundingRect.height()+p_boundingRect.y()+p_yMargins);
39 return QPoint(0,p_boundingRect.height()+p_boundingRect.y()+p_yMargins);
42 }
40 }
43
41
44 QRect registerWidget::boundingRect()
42 QRect registerWidget::boundingRect()
45 {
43 {
46 return p_boundingRect;
44 return p_boundingRect;
47 }
45 }
48
46
49 uint registerWidget::cursorIndex()
47 uint registerWidget::cursorIndex()
50 {
48 {
51 return p_fieldsEl->cursorIndex();
49 return p_fieldsEl->cursorIndex();
52 }
50 }
53
51
54 uint registerWidget::cursorIndex(int xPos)
52 uint registerWidget::cursorIndex(int xPos)
55 {
53 {
56 if(xPos>p_addressEl->boundingRect().width() && xPos<(p_addressEl->boundingRect().width()+p_fieldsEl->boundingRect().width()))
54 if(xPos>p_addressEl->boundingRect().width() && xPos<(p_addressEl->boundingRect().width()+p_fieldsEl->boundingRect().width()))
57 {
55 {
58 return p_fieldsEl->cursorIndex(xPos-p_addressEl->boundingRect().width());
56 return p_fieldsEl->cursorIndex(xPos-p_addressEl->boundingRect().width());
59 }
57 }
60 return 0;
58 return 0;
61 }
59 }
62
60
63 void registerWidget::updateSelection(int index)
61 void registerWidget::updateSelection(int index)
64 {
62 {
65 p_fieldsEl->updateSelection(index);
63 p_fieldsEl->updateSelection(index);
66 emit this->repaint();
64 emit this->repaint();
67 }
65 }
68
66
69 qint32 registerWidget::address()
67 qint32 registerWidget::address()
70 {
68 {
71 return p_address;
69 return p_address;
72 }
70 }
73
71
74 qint32 registerWidget::value()
72 qint32 registerWidget::value()
75 {
73 {
76 return p_value;
74 return p_value;
77 }
75 }
78
76
79 void registerWidget::setBitFieldAttribute(uint startIndex, uint stopIndex, const QString &name, const QString &description, bool rw)
77 void registerWidget::setBitFieldAttribute(uint startIndex, uint stopIndex, const QString &name, const QString &description, bool rw)
80 {
78 {
81 if(startIndex<=stopIndex && stopIndex<32)
79 if(startIndex<=stopIndex && stopIndex<32)
82 {
80 {
83 int index= p_fieldsEl->addAttribute(name,description,rw );
81 int index= p_fieldsEl->addAttribute(name,description,rw );
84 for(uint i=startIndex;i<=stopIndex;i++)
82 for(uint i=startIndex;i<=stopIndex;i++)
85 {
83 {
86 p_fieldsEl->setAttribute(i,index);
84 p_fieldsEl->setAttribute(i,index);
87 }
85 }
88 }
86 }
89 }
87 }
90
88
91 QString registerWidget::bitFieldDesc(int bitIndex)
89 QString registerWidget::bitFieldDesc(int bitIndex)
92 {
90 {
93 if(bitIndex>=0 && bitIndex<32)
91 if(bitIndex>=0 && bitIndex<32)
94 {
92 {
95 return p_fieldsEl->description(bitIndex);
93 return p_fieldsEl->description(bitIndex);
96 }
94 }
97 return QString("Out of range");
95 return QString("Out of range");
98 }
96 }
99
97
100 QString registerWidget::bitFieldName(int bitIndex)
98 QString registerWidget::bitFieldName(int bitIndex)
101 {
99 {
102 if(bitIndex>=0 && bitIndex<32)
100 if(bitIndex>=0 && bitIndex<32)
103 {
101 {
104 return p_fieldsEl->name(bitIndex);
102 return p_fieldsEl->name(bitIndex);
105 }
103 }
106 return QString("Out of range");
104 return QString("Out of range");
107 }
105 }
108
106
109 QString registerWidget::bitFieldToHex(int bitIndex)
107 QString registerWidget::bitFieldToHex(int bitIndex)
110 {
108 {
111 if(bitIndex>=0 && bitIndex<32)
109 if(bitIndex>=0 && bitIndex<32)
112 {
110 {
113 return p_fieldsEl->valueHex(bitIndex);
111 return p_fieldsEl->valueHex(bitIndex);
114 }
112 }
115 return QString("Out of range");
113 return QString("Out of range");
116 }
114 }
117
115
118 QString registerWidget::bitFieldToDec(int bitIndex)
116 QString registerWidget::bitFieldToDec(int bitIndex)
119 {
117 {
120 if(bitIndex>=0 && bitIndex<32)
118 if(bitIndex>=0 && bitIndex<32)
121 {
119 {
122 return p_fieldsEl->valueDec(bitIndex);
120 return p_fieldsEl->valueDec(bitIndex);
123 }
121 }
124 return QString("Out of range");
122 return QString("Out of range");
125 }
123 }
126
124
127 QString registerWidget::bitFieldToBin(int bitIndex)
125 QString registerWidget::bitFieldToBin(int bitIndex)
128 {
126 {
129
127 if(bitIndex>=0 && bitIndex<32)
128 {
129 // TODO do the convertion
130 return p_fieldsEl->valueDec(bitIndex);
131 }
132 return QString("Out of range");
130 }
133 }
131
134
132 void registerWidget::setValue(qint32 value)
135 void registerWidget::setValue(qint32 value)
133 {
136 {
134 this->p_value = value;
137 this->p_value = value;
135 this->p_fieldsEl->setValue(QString("%1").arg((uint)p_value,32,2).replace(" ","0"));
138 this->p_fieldsEl->setValue(QString("%1").arg((uint)p_value,32,2).replace(" ","0"));
136 emit this->repaint();
139 emit this->repaint();
137 }
140 }
138
141
139 void registerWidget::blinkCursor()
142 void registerWidget::blinkCursor()
140 {
143 {
141 p_fieldsEl->blinkCursor();
144 p_fieldsEl->blinkCursor();
142 //repaint();
145 //repaint();
143 }
146 }
144
147
145 void registerWidget::moveCursorLeft(int count)
148 void registerWidget::moveCursorLeft(int count)
146 {
149 {
147 p_fieldsEl->moveCursorLeft(count);
150 p_fieldsEl->moveCursorLeft(count);
148 p_fieldsEl->blinkCursor();
151 p_fieldsEl->blinkCursor();
149 }
152 }
150
153
151 void registerWidget::moveCursorRight(int count)
154 void registerWidget::moveCursorRight(int count)
152 {
155 {
153 p_fieldsEl->moveCursorRight(count);
156 p_fieldsEl->moveCursorRight(count);
154 p_fieldsEl->blinkCursor();
157 p_fieldsEl->blinkCursor();
155 }
158 }
156
159
157 void registerWidget::enter(int index)
160 void registerWidget::enter(int index)
158 {
161 {
159 p_fieldsEl->enter(index);
162 p_fieldsEl->enter(index);
160 }
163 }
161
164
162 void registerWidget::leave()
165 void registerWidget::leave()
163 {
166 {
164 p_fieldsEl->leave();
167 p_fieldsEl->leave();
165 }
168 }
166
169
167 void registerWidget::clear(int index)
170 void registerWidget::clear(int index)
168 {
171 {
169 p_value &= ~(1<<index);
172 p_value &= ~(1<<index);
170 this->p_fieldsEl->setValue(QString("%1").arg((uint)p_value,32,2).replace(" ","0"));
173 this->p_fieldsEl->setValue(QString("%1").arg((uint)p_value,32,2).replace(" ","0"));
171 emit this->repaint();
174 emit this->repaint();
172 }
175 }
173
176
174 void registerWidget::set(int index)
177 void registerWidget::set(int index)
175 {
178 {
176 if(!this->p_fieldsEl->readonly(index))
179 if(!this->p_fieldsEl->readonly(index))
177 {
180 {
178 p_value |= 1<<index;
181 p_value |= 1<<index;
179 this->p_fieldsEl->setValue(QString("%1").arg((uint)p_value,32,2).replace(" ","0"));
182 this->p_fieldsEl->setValue(QString("%1").arg((uint)p_value,32,2).replace(" ","0"));
180 emit this->repaint();
183 emit this->repaint();
181 }
184 }
182 }
185 }
183
186
184 void registerWidget::updateBoundingRect()
187 void registerWidget::updateBoundingRect()
185 {
188 {
186 p_boundingRect.setHeight(p_fieldsEl->boundingRect().height()+(p_yMargins*2));
189 p_boundingRect.setHeight(p_fieldsEl->boundingRect().height()+(p_yMargins*2));
187 p_boundingRect.setWidth(p_fieldsEl->boundingRect().width()+p_addressEl->boundingRect().width()+p_nameEl->boundingRect().width()+(p_xMargins*2));
190 p_boundingRect.setWidth(p_fieldsEl->boundingRect().width()+p_addressEl->boundingRect().width()+p_nameEl->boundingRect().width()+(p_xMargins*2));
188 }
191 }
189
192
190
193
191
194
192 bitfieldsElement::bitfieldsElement(const QString &value, QFont font, int xMargin, int yMargin)
195 bitfieldsElement::bitfieldsElement(const QString &value, QFont font, int xMargin, int yMargin)
193 :regWidgetElement(value,font,xMargin,yMargin)
196 :regWidgetElement(value,font,xMargin,yMargin)
194 {
197 {
195 this->attributesLUT.append(new bitFieldAttribute(false,"UNSUSED","UNSUSED"));
198 this->attributesLUT.append(new bitFieldAttribute(false,"UNSUSED","UNSUSED"));
196 for(int i=0;i<32;i++)
199 for(int i=0;i<32;i++)
197 {
200 {
198 attributesIndex[i] = 0;
201 attributesIndex[i] = 0;
199 }
202 }
200 p_startSelectionIndex = -1;
203 p_startSelectionIndex = -1;
201 p_stopSelectionIndex = -1;
204 p_stopSelectionIndex = -1;
202 p_cursorIndex = -1;
205 p_cursorIndex = -1;
203 p_dx=QFontMetrics(p_font).width("0")+4;
206 p_dx=QFontMetrics(p_font).width("0")+4;
204 p_blinkTextBgColor = QColor(Qt::black);
207 p_blinkTextBgColor = QColor(Qt::black);
205 p_blinkTextColor = QColor(Qt::white);
208 p_blinkTextColor = QColor(Qt::white);
206 p_cursorBlinkEnable = false;
209 p_cursorBlinkEnable = false;
207 updateBoundingRect();
210 updateBoundingRect();
208 }
211 }
209
212
210 QPoint bitfieldsElement::paint(QPainter *painter)
213 QPoint bitfieldsElement::paint(QPainter *painter)
211 {
214 {
212 painter->fillRect(4,4,p_boundingRec.width(),p_boundingRec.height(),Qt::darkGray);
215 painter->fillRect(4,4,p_boundingRec.width(),p_boundingRec.height(),Qt::darkGray);
213 painter->fillRect(0,0,p_boundingRec.width(),p_boundingRec.height(),Qt::white);
216 painter->fillRect(0,0,p_boundingRec.width(),p_boundingRec.height(),Qt::white);
214 painter->setFont(p_font);
217 painter->setFont(p_font);
215 int lastAttributeIndex = attributesIndex[31];
218 int lastAttributeIndex = attributesIndex[31];
216 int xpos=p_xMargins;
219 int xpos=p_xMargins;
217 for(int i=0;i<(32/4);i++)
220 for(int i=0;i<(32/4);i++)
218 {
221 {
219 for(int l = 0;l<4;l++)
222 for(int l = 0;l<4;l++)
220 {
223 {
221 if(p_cursorBlinkEnable == false || (31-p_cursorIndex) != ((i*4)+l))
224 if(p_cursorBlinkEnable == false || (31-(int)p_cursorIndex) != ((i*4)+l))
222 {
225 {
223 if(p_startSelectionIndex!=-1 && p_stopSelectionIndex!=-1 && p_startSelectionIndex <=31-((i*4)+l) && p_stopSelectionIndex >=31-((i*4)+l))
226 if((int)p_startSelectionIndex!=-1 && (int)p_stopSelectionIndex!=-1 && p_startSelectionIndex <=(uint)31-(uint)((i*4)+l) && p_stopSelectionIndex >=(uint)31-(uint)((i*4)+l))
224 {
227 {
225 QPen svg = painter->pen();
228 QPen svg = painter->pen();
226 painter->setPen(p_blinkTextColor);
229 painter->setPen(p_blinkTextColor);
227 painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::blue);
230 painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::blue);
228 painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l));
231 painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l));
229 painter->setPen(svg);
232 painter->setPen(svg);
230 }
233 }
231 else
234 else
232 {
235 {
233 if(attributesLUT[attributesIndex[31-((i*4)+l)]]->rw==false)
236 if(attributesLUT[attributesIndex[31-((i*4)+l)]]->rw==false)
234 {
237 {
235 painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::lightGray);
238 painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::lightGray);
236 }
239 }
237 else
240 else
238 {
241 {
239 painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::white);
242 painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::white);
240 }
243 }
241 painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l));
244 painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l));
242 }
245 }
243 }
246 }
244 else
247 else
245 {
248 {
246 QPen svg = painter->pen();
249 QPen svg = painter->pen();
247 painter->setPen(p_blinkTextColor);
250 painter->setPen(p_blinkTextColor);
248 painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),p_blinkTextBgColor);
251 painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),p_blinkTextBgColor);
249 painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l));
252 painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l));
250 painter->setPen(svg);
253 painter->setPen(svg);
251 }
254 }
252 if(lastAttributeIndex!=attributesIndex[31-((i*4)+l)])
255 if(lastAttributeIndex!=attributesIndex[31-((i*4)+l)])
253 painter->drawLine(xpos-(p_xMargins/2),0,xpos-(p_xMargins/2),p_boundingRec.height());
256 painter->drawLine(xpos-(p_xMargins/2),0,xpos-(p_xMargins/2),p_boundingRec.height());
254 lastAttributeIndex=attributesIndex[31-((i*4)+l)];
257 lastAttributeIndex=attributesIndex[31-((i*4)+l)];
255 xpos+=p_dx;
258 xpos+=p_dx;
256 }
259 }
257 if(i==3)
260 if(i==3)
258 painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+12);
261 painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+12);
259 else if(i<7)
262 else if(i<7)
260 painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+6);
263 painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+6);
261 xpos+=p_xMargins;
264 xpos+=p_xMargins;
262 }
265 }
263 painter->drawRect(0,0,p_boundingRec.width(),p_boundingRec.height());
266 painter->drawRect(0,0,p_boundingRec.width(),p_boundingRec.height());
264 return QPoint(p_boundingRec.width()+4+p_xMargins,0);
267 return QPoint(p_boundingRec.width()+4+p_xMargins,0);
265 }
268 }
266
269
267 void bitfieldsElement::updateBoundingRect()
270 void bitfieldsElement::updateBoundingRect()
268 {
271 {
269 p_boundingRec.setHeight(QFontMetrics(p_font).boundingRect(p_valueStr).height()+(p_yMargins*2));
272 p_boundingRec.setHeight(QFontMetrics(p_font).boundingRect(p_valueStr).height()+(p_yMargins*2));
270 int width = (((4*(p_dx)) + p_xMargins) * 8) + (p_xMargins);
273 int width = (((4*(p_dx)) + p_xMargins) * 8) + (p_xMargins);
271 p_boundingRec.setWidth(width);
274 p_boundingRec.setWidth(width);
272 }
275 }
273
276
274 void bitfieldsElement::setValue(const QString &value)
277 void bitfieldsElement::setValue(const QString &value)
275 {
278 {
276 p_valueStr = value;
279 p_valueStr = value;
277 updateBoundingRect();
280 updateBoundingRect();
278 }
281 }
279
282
280 void bitfieldsElement::blinkCursor()
283 void bitfieldsElement::blinkCursor()
281 {
284 {
282 p_cursorBlinkEnable = !p_cursorBlinkEnable;
285 p_cursorBlinkEnable = !p_cursorBlinkEnable;
283 }
286 }
284
287
285 void bitfieldsElement::moveCursorLeft(int count)
288 void bitfieldsElement::moveCursorLeft(int count)
286 {
289 {
287 p_cursorIndex+=count;
290 p_cursorIndex+=count;
288 if(31<p_cursorIndex)
291 if(31<p_cursorIndex)
289 {
292 {
290 p_cursorIndex = 31;
293 p_cursorIndex = 31;
291 }
294 }
292 p_startSelectionIndex = p_cursorIndex;
295 p_startSelectionIndex = p_cursorIndex;
293 p_stopSelectionIndex = p_cursorIndex;
296 p_stopSelectionIndex = p_cursorIndex;
294
297
295 }
298 }
296
299
297 void bitfieldsElement::moveCursorRight(int count)
300 void bitfieldsElement::moveCursorRight(int count)
298 {
301 {
299 p_cursorIndex -= count;
302 p_cursorIndex -= count;
300 if(31<p_cursorIndex)
303 if(31<p_cursorIndex)
301 {
304 {
302 p_cursorIndex = 0;
305 p_cursorIndex = 0;
303 }
306 }
304 p_startSelectionIndex = p_cursorIndex;
307 p_startSelectionIndex = p_cursorIndex;
305 p_stopSelectionIndex = p_cursorIndex;
308 p_stopSelectionIndex = p_cursorIndex;
306 }
309 }
307
310
308 void bitfieldsElement::enter(int index)
311 void bitfieldsElement::enter(int index)
309 {
312 {
310 p_cursorIndex = index;
313 p_cursorIndex = index;
311 p_cursorBlinkEnable = true;
314 p_cursorBlinkEnable = true;
312 p_startSelectionIndex = -1;
315 p_startSelectionIndex = -1;
313 p_stopSelectionIndex = -1;
316 p_stopSelectionIndex = -1;
314 }
317 }
315
318
316 void bitfieldsElement::leave()
319 void bitfieldsElement::leave()
317 {
320 {
318 p_cursorBlinkEnable = false;
321 p_cursorBlinkEnable = false;
319 p_cursorIndex = -1;
322 p_cursorIndex = -1;
320 p_startSelectionIndex = -1;
323 p_startSelectionIndex = -1;
321 p_stopSelectionIndex = -1;
324 p_stopSelectionIndex = -1;
322 }
325 }
323
326
324 uint bitfieldsElement::cursorIndex()
327 uint bitfieldsElement::cursorIndex()
325 {
328 {
326 return p_cursorIndex;
329 return p_cursorIndex;
327 }
330 }
328
331
329 uint bitfieldsElement::cursorIndex(int xPos)
332 uint bitfieldsElement::cursorIndex(int xPos)
330 {
333 {
331 uint index=0;
334 uint index=0;
332 xPos-=p_xMargins;
335 xPos-=p_xMargins;
333 if(xPos<p_boundingRec.width())
336 if(xPos<p_boundingRec.width())
334 {
337 {
335 index = 31 - ((4*xPos)/((4*p_dx)+p_xMargins));
338 index = 31 - ((4*xPos)/((4*p_dx)+p_xMargins));
336 }
339 }
337 return index;
340 return index;
338 }
341 }
339
342
340 void bitfieldsElement::setFont(QFont font)
343 void bitfieldsElement::setFont(QFont font)
341 {
344 {
342 p_font = font;
345 p_font = font;
343 p_dx=QFontMetrics(p_font).width("0")+2;
346 p_dx=QFontMetrics(p_font).width("0")+2;
344 updateBoundingRect();
347 updateBoundingRect();
345 }
348 }
346
349
347 void bitfieldsElement::updateSelection(int index)
350 void bitfieldsElement::updateSelection(int index)
348 {
351 {
349 if(p_cursorIndex!=-1)
352 if((int)p_cursorIndex!=-1)
350 {
353 {
351 if(p_startSelectionIndex!=-1 && p_stopSelectionIndex!= -1)
354 if((int)p_startSelectionIndex!=-1 && (int)p_stopSelectionIndex!= -1)
352 {
355 {
353 if(index>=p_stopSelectionIndex)
356 if((uint)index>=p_stopSelectionIndex)
354 {
357 {
355 p_stopSelectionIndex = index;
358 p_stopSelectionIndex = index;
356 p_cursorIndex = index;
359 p_cursorIndex = index;
357 }
360 }
358 else
361 else
359 {
362 {
360 p_startSelectionIndex = index;
363 p_startSelectionIndex = index;
361 p_cursorIndex = index;
364 p_cursorIndex = index;
362 }
365 }
363 }
366 }
364 else
367 else
365 {
368 {
366 if(index>p_cursorIndex)
369 if((uint)index>p_cursorIndex)
367 {
370 {
368 p_startSelectionIndex = p_cursorIndex;
371 p_startSelectionIndex = p_cursorIndex;
369 p_stopSelectionIndex = index;
372 p_stopSelectionIndex = index;
370 }
373 }
371 else
374 else
372 {
375 {
373 p_startSelectionIndex = index;
376 p_startSelectionIndex = index;
374 p_stopSelectionIndex = p_cursorIndex;
377 p_stopSelectionIndex = p_cursorIndex;
375 }
378 }
376 }
379 }
377 }
380 }
378 }
381 }
379
382
380
383
381
384
382
385
383
386
384
387
385
388
386
389
387
390
388
391
389
392
390
393
General Comments 0
You need to be logged in to leave comments. Login now