@@ -1,253 +1,258 | |||||
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 | int peripheralWidget::count() | |||
|
21 | { | |||
|
22 | return registersWdgts.count(); | |||
|
23 | } | |||
|
24 | ||||
20 | void peripheralWidget::blinkCursor() |
|
25 | void peripheralWidget::blinkCursor() | |
21 | { |
|
26 | { | |
22 | if(selectedReg!=-1) |
|
27 | if(selectedReg!=-1) | |
23 | registersWdgts.at(selectedReg)->blinkCursor(); |
|
28 | registersWdgts.at(selectedReg)->blinkCursor(); | |
24 | repaint(); |
|
29 | repaint(); | |
25 | } |
|
30 | } | |
26 |
|
31 | |||
27 | void peripheralWidget::addRegister(const QString &name, qint32 address) |
|
32 | void peripheralWidget::addRegister(const QString &name, qint32 address) | |
28 | { |
|
33 | { | |
29 | /*TODO Should regs by address*/ |
|
34 | /*TODO Should regs by address*/ | |
30 | registersWdgts.append(new registerWidget(name,address)); |
|
35 | registersWdgts.append(new registerWidget(name,address)); | |
31 | connect(registersWdgts.last(),SIGNAL(repaint()),this,SLOT(repaint())); |
|
36 | connect(registersWdgts.last(),SIGNAL(repaint()),this,SLOT(repaint())); | |
32 | } |
|
37 | } | |
33 |
|
38 | |||
34 | void peripheralWidget::leave() |
|
39 | void peripheralWidget::leave() | |
35 | { |
|
40 | { | |
36 | if(selectedReg!=-1) |
|
41 | if(selectedReg!=-1) | |
37 | { |
|
42 | { | |
38 | p_timer->stop(); |
|
43 | p_timer->stop(); | |
39 | registersWdgts.at(selectedReg)->leave(); |
|
44 | registersWdgts.at(selectedReg)->leave(); | |
40 | selectedReg = -1; |
|
45 | selectedReg = -1; | |
41 | repaint(); |
|
46 | repaint(); | |
42 | } |
|
47 | } | |
43 | } |
|
48 | } | |
44 |
|
49 | |||
45 | void peripheralWidget::enter(int cursorIndex, bool fromTop) |
|
50 | void peripheralWidget::enter(int cursorIndex, bool fromTop) | |
46 | { |
|
51 | { | |
47 | if(cursorIndex>=0 && cursorIndex<32) |
|
52 | if(cursorIndex>=0 && cursorIndex<32) | |
48 | { |
|
53 | { | |
49 | if(fromTop) |
|
54 | if(fromTop) | |
50 | { |
|
55 | { | |
51 | registersWdgts.at(0)->enter(cursorIndex); |
|
56 | registersWdgts.at(0)->enter(cursorIndex); | |
52 | selectedReg = 0; |
|
57 | selectedReg = 0; | |
53 | } |
|
58 | } | |
54 | else |
|
59 | else | |
55 | { |
|
60 | { | |
56 | registersWdgts.at(registersWdgts.count()-1)->enter(cursorIndex); |
|
61 | registersWdgts.at(registersWdgts.count()-1)->enter(cursorIndex); | |
57 | selectedReg = registersWdgts.count()-1; |
|
62 | selectedReg = registersWdgts.count()-1; | |
58 | } |
|
63 | } | |
59 | p_timer->start(); |
|
64 | p_timer->start(); | |
60 | this->setFocus(); |
|
65 | this->setFocus(); | |
61 | } |
|
66 | } | |
62 | } |
|
67 | } | |
63 |
|
68 | |||
64 | void peripheralWidget::mousePressEvent(QMouseEvent *event) |
|
69 | void peripheralWidget::mousePressEvent(QMouseEvent *event) | |
65 | { |
|
70 | { | |
66 | p_timer->stop(); |
|
71 | p_timer->stop(); | |
67 | if(selectedReg!=-1) |
|
72 | if(selectedReg!=-1) | |
68 | { |
|
73 | { | |
69 | registersWdgts.at(selectedReg)->leave(); |
|
74 | registersWdgts.at(selectedReg)->leave(); | |
70 | selectedReg = -1; |
|
75 | selectedReg = -1; | |
71 | } |
|
76 | } | |
72 | for(int i=0; i<registersWdgts.count();i++) |
|
77 | for(int i=0; i<registersWdgts.count();i++) | |
73 | { |
|
78 | { | |
74 | if(registersWdgts.at(i)->contains(event->pos())) |
|
79 | if(registersWdgts.at(i)->contains(event->pos())) | |
75 | { |
|
80 | { | |
76 | registersWdgts.at(i)->enter(registersWdgts.at(i)->cursorIndex(event->pos().x())); |
|
81 | registersWdgts.at(i)->enter(registersWdgts.at(i)->cursorIndex(event->pos().x())); | |
77 | selectedReg = i; |
|
82 | selectedReg = i; | |
78 | p_timer->start(); |
|
83 | p_timer->start(); | |
79 | emit clicked(this); |
|
84 | emit clicked(this); | |
80 | } |
|
85 | } | |
81 | } |
|
86 | } | |
82 | repaint(); |
|
87 | repaint(); | |
83 | } |
|
88 | } | |
84 |
|
89 | |||
85 | void peripheralWidget::mouseMoveEvent(QMouseEvent *event) |
|
90 | void peripheralWidget::mouseMoveEvent(QMouseEvent *event) | |
86 | { |
|
91 | { | |
87 | bool match=false; |
|
92 | bool match=false; | |
88 | if(event->buttons()==Qt::LeftButton) |
|
93 | if(event->buttons()==Qt::LeftButton) | |
89 | { |
|
94 | { | |
90 | for(int i=0; i<registersWdgts.count();i++) |
|
95 | for(int i=0; i<registersWdgts.count();i++) | |
91 | { |
|
96 | { | |
92 | if(registersWdgts.at(i)->contains(event->pos())) |
|
97 | if(registersWdgts.at(i)->contains(event->pos())) | |
93 | { |
|
98 | { | |
94 | registersWdgts.at(i)->updateSelection(registersWdgts.at(i)->cursorIndex(event->pos().x())); |
|
99 | registersWdgts.at(i)->updateSelection(registersWdgts.at(i)->cursorIndex(event->pos().x())); | |
95 | } |
|
100 | } | |
96 | } |
|
101 | } | |
97 | } |
|
102 | } | |
98 | else |
|
103 | else | |
99 | { |
|
104 | { | |
100 | for(int i=0; i<registersWdgts.count();i++) |
|
105 | for(int i=0; i<registersWdgts.count();i++) | |
101 | { |
|
106 | { | |
102 | if(registersWdgts.at(i)->contains(event->pos())) |
|
107 | if(registersWdgts.at(i)->contains(event->pos())) | |
103 | { |
|
108 | { | |
104 | match = true; |
|
109 | match = true; | |
105 | int bitfieldIndex=registersWdgts.at(i)->cursorIndex(event->pos().x()); |
|
110 | int bitfieldIndex=registersWdgts.at(i)->cursorIndex(event->pos().x()); | |
106 |
|
111 | |||
107 | QString toolTipText ="<b>< font color='Black'>"+registersWdgts.at(i)->bitFieldName(bitfieldIndex) +"</b><br />"; |
|
112 | 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>"; |
|
113 | 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 />"; |
|
114 | toolTipText+= " Decimal=<b>< font color='BlueViolet'>"+registersWdgts.at(i)->bitFieldToDec(bitfieldIndex)+"</b><br />"; | |
110 | toolTipText+= registersWdgts.at(i)->bitFieldDesc(bitfieldIndex); |
|
115 | toolTipText+= registersWdgts.at(i)->bitFieldDesc(bitfieldIndex); | |
111 | QToolTip::showText(event->globalPos(),toolTipText,(QWidget*)this); |
|
116 | QToolTip::showText(event->globalPos(),toolTipText,(QWidget*)this); | |
112 | } |
|
117 | } | |
113 | } |
|
118 | } | |
114 | if(!match)QToolTip::hideText(); |
|
119 | if(!match)QToolTip::hideText(); | |
115 | } |
|
120 | } | |
116 | } |
|
121 | } | |
117 |
|
122 | |||
118 | void peripheralWidget::mouseReleaseEvent(QMouseEvent *event) |
|
123 | void peripheralWidget::mouseReleaseEvent(QMouseEvent *event) | |
119 | { |
|
124 | { | |
120 | Q_UNUSED(event) |
|
125 | Q_UNUSED(event) | |
121 | } |
|
126 | } | |
122 |
|
127 | |||
123 | void peripheralWidget::keyPressEvent(QKeyEvent *event) |
|
128 | void peripheralWidget::keyPressEvent(QKeyEvent *event) | |
124 | { |
|
129 | { | |
125 | if(this->selectedReg!=-1){ |
|
130 | if(this->selectedReg!=-1){ | |
126 | if(event->modifiers()==Qt::ControlModifier) |
|
131 | if(event->modifiers()==Qt::ControlModifier) | |
127 | { |
|
132 | { | |
128 | switch(event->key()) |
|
133 | switch(event->key()) | |
129 | { |
|
134 | { | |
130 | case Qt::Key_Up: |
|
135 | case Qt::Key_Up: | |
131 | registersWdgts.at(selectedReg)->set(registersWdgts.at(selectedReg)->cursorIndex()); |
|
136 | registersWdgts.at(selectedReg)->set(registersWdgts.at(selectedReg)->cursorIndex()); | |
132 | break; |
|
137 | break; | |
133 | case Qt::Key_Down: |
|
138 | case Qt::Key_Down: | |
134 | registersWdgts.at(selectedReg)->clear(registersWdgts.at(selectedReg)->cursorIndex()); |
|
139 | registersWdgts.at(selectedReg)->clear(registersWdgts.at(selectedReg)->cursorIndex()); | |
135 | break; |
|
140 | break; | |
136 | case Qt::Key_W: |
|
141 | case Qt::Key_W: | |
137 | emit writeRegSig(registersWdgts.at(selectedReg)->address(),registersWdgts.at(selectedReg)->value()); |
|
142 | emit writeRegSig(registersWdgts.at(selectedReg)->address(),registersWdgts.at(selectedReg)->value()); | |
138 | registersWdgts.at(selectedReg)->setUpdated(true); |
|
143 | registersWdgts.at(selectedReg)->setUpdated(true); | |
139 | registersWdgts.at(selectedReg)->repaint(); |
|
144 | registersWdgts.at(selectedReg)->repaint(); | |
140 | break; |
|
145 | break; | |
141 | case Qt::Key_R: |
|
146 | case Qt::Key_R: | |
142 | qint32 value; |
|
147 | qint32 value; | |
143 | value = emit readRegSig(registersWdgts.at(selectedReg)->address()); |
|
148 | value = emit readRegSig(registersWdgts.at(selectedReg)->address()); | |
144 | registersWdgts.at(selectedReg)->setValue(value); |
|
149 | registersWdgts.at(selectedReg)->setValue(value); | |
145 | break; |
|
150 | break; | |
146 | default: |
|
151 | default: | |
147 | break; |
|
152 | break; | |
148 | } |
|
153 | } | |
149 | } |
|
154 | } | |
150 | else |
|
155 | else | |
151 | { |
|
156 | { | |
152 | switch(event->key()) |
|
157 | switch(event->key()) | |
153 | { |
|
158 | { | |
154 | case Qt::Key_0: |
|
159 | case Qt::Key_0: | |
155 | registersWdgts.at(selectedReg)->clear(registersWdgts.at(selectedReg)->cursorIndex()); |
|
160 | registersWdgts.at(selectedReg)->clear(registersWdgts.at(selectedReg)->cursorIndex()); | |
156 | registersWdgts.at(selectedReg)->moveCursorRight(1); |
|
161 | registersWdgts.at(selectedReg)->moveCursorRight(1); | |
157 | break; |
|
162 | break; | |
158 | case Qt::Key_1: |
|
163 | case Qt::Key_1: | |
159 | registersWdgts.at(selectedReg)->set(registersWdgts.at(selectedReg)->cursorIndex()); |
|
164 | registersWdgts.at(selectedReg)->set(registersWdgts.at(selectedReg)->cursorIndex()); | |
160 | registersWdgts.at(selectedReg)->moveCursorRight(1); |
|
165 | registersWdgts.at(selectedReg)->moveCursorRight(1); | |
161 | break; |
|
166 | break; | |
162 | case Qt::Key_Right: |
|
167 | case Qt::Key_Right: | |
163 | registersWdgts.at(selectedReg)->moveCursorRight(1); |
|
168 | registersWdgts.at(selectedReg)->moveCursorRight(1); | |
164 | this->repaint(); |
|
169 | this->repaint(); | |
165 | break; |
|
170 | break; | |
166 | case Qt::Key_Left: |
|
171 | case Qt::Key_Left: | |
167 | registersWdgts.at(selectedReg)->moveCursorLeft(1); |
|
172 | registersWdgts.at(selectedReg)->moveCursorLeft(1); | |
168 | this->repaint(); |
|
173 | this->repaint(); | |
169 | break; |
|
174 | break; | |
170 | case Qt::Key_Up: |
|
175 | case Qt::Key_Up: | |
171 | up(); |
|
176 | up(); | |
172 | break; |
|
177 | break; | |
173 | case Qt::Key_Down: |
|
178 | case Qt::Key_Down: | |
174 | down(); |
|
179 | down(); | |
175 | break; |
|
180 | break; | |
176 | case Qt::Key_W: |
|
181 | case Qt::Key_W: | |
177 | emit writeRegSig(registersWdgts.at(selectedReg)->address(),registersWdgts.at(selectedReg)->value()); |
|
182 | emit writeRegSig(registersWdgts.at(selectedReg)->address(),registersWdgts.at(selectedReg)->value()); | |
178 | registersWdgts.at(selectedReg)->setUpdated(true); |
|
183 | registersWdgts.at(selectedReg)->setUpdated(true); | |
179 | registersWdgts.at(selectedReg)->repaint(); |
|
184 | registersWdgts.at(selectedReg)->repaint(); | |
180 | break; |
|
185 | break; | |
181 | case Qt::Key_R: |
|
186 | case Qt::Key_R: | |
182 | qint32 value; |
|
187 | qint32 value; | |
183 | value = emit readRegSig(registersWdgts.at(selectedReg)->address()); |
|
188 | value = emit readRegSig(registersWdgts.at(selectedReg)->address()); | |
184 | registersWdgts.at(selectedReg)->setValue(value); |
|
189 | registersWdgts.at(selectedReg)->setValue(value); | |
185 | break; |
|
190 | break; | |
186 | default: |
|
191 | default: | |
187 | break; |
|
192 | break; | |
188 | } |
|
193 | } | |
189 | } |
|
194 | } | |
190 |
|
195 | |||
191 | } |
|
196 | } | |
192 | } |
|
197 | } | |
193 |
|
198 | |||
194 | void peripheralWidget::paintEvent(QPaintEvent *event) |
|
199 | void peripheralWidget::paintEvent(QPaintEvent *event) | |
195 | { |
|
200 | { | |
196 | Q_UNUSED(event) |
|
201 | Q_UNUSED(event) | |
197 |
|
202 | |||
198 | QPainter painter(this); |
|
203 | QPainter painter(this); | |
199 | QPoint offset=QPoint(0,0); |
|
204 | QPoint offset=QPoint(0,0); | |
200 | int nameWidth = fontMetrics().width(p_header); |
|
205 | int nameWidth = fontMetrics().width(p_header); | |
201 | if(registersWdgts.count()==0) |
|
206 | if(registersWdgts.count()==0) | |
202 | { |
|
207 | { | |
203 | setMinimumSize(2*nameWidth+10,fontMetrics().height()+10); |
|
208 | setMinimumSize(2*nameWidth+10,fontMetrics().height()+10); | |
204 | } |
|
209 | } | |
205 | painter.drawText((this->minimumWidth()/2)-nameWidth,4,fontMetrics().width(p_header),fontMetrics().height()+4,Qt::AlignCenter,p_header); |
|
210 | painter.drawText((this->minimumWidth()/2)-nameWidth,4,fontMetrics().width(p_header),fontMetrics().height()+4,Qt::AlignCenter,p_header); | |
206 | offset+=QPoint(0,fontMetrics().height()+8); |
|
211 | offset+=QPoint(0,fontMetrics().height()+8); | |
207 | for(int i=0;i<registersWdgts.count();i++) |
|
212 | for(int i=0;i<registersWdgts.count();i++) | |
208 | { |
|
213 | { | |
209 | offset = registersWdgts.at(i)->paint(&painter,offset); |
|
214 | offset = registersWdgts.at(i)->paint(&painter,offset); | |
210 | } |
|
215 | } | |
211 | if(registersWdgts.count()>0) |
|
216 | if(registersWdgts.count()>0) | |
212 | { |
|
217 | { | |
213 | setMinimumSize(registersWdgts.first()->boundingRect().width(),offset.y()); |
|
218 | setMinimumSize(registersWdgts.first()->boundingRect().width(),offset.y()); | |
214 | } |
|
219 | } | |
215 | updateGeometry(); |
|
220 | updateGeometry(); | |
216 |
|
221 | |||
217 | } |
|
222 | } | |
218 |
|
223 | |||
219 | void peripheralWidget::up() |
|
224 | void peripheralWidget::up() | |
220 | { |
|
225 | { | |
221 | if(selectedReg!=-1) |
|
226 | if(selectedReg!=-1) | |
222 | { |
|
227 | { | |
223 | if(selectedReg >0) |
|
228 | if(selectedReg >0) | |
224 | { |
|
229 | { | |
225 | registersWdgts.at(selectedReg-1)->enter(registersWdgts.at(selectedReg)->cursorIndex()); |
|
230 | registersWdgts.at(selectedReg-1)->enter(registersWdgts.at(selectedReg)->cursorIndex()); | |
226 | registersWdgts.at(selectedReg)->leave(); |
|
231 | registersWdgts.at(selectedReg)->leave(); | |
227 | selectedReg-=1; |
|
232 | selectedReg-=1; | |
228 | repaint(); |
|
233 | repaint(); | |
229 | } |
|
234 | } | |
230 | else |
|
235 | else | |
231 | { |
|
236 | { | |
232 | emit upSig(this,registersWdgts.at(selectedReg)->cursorIndex()); |
|
237 | emit upSig(this,registersWdgts.at(selectedReg)->cursorIndex()); | |
233 | } |
|
238 | } | |
234 | } |
|
239 | } | |
235 | } |
|
240 | } | |
236 |
|
241 | |||
237 | void peripheralWidget::down() |
|
242 | void peripheralWidget::down() | |
238 | { |
|
243 | { | |
239 | if(selectedReg!=-1) |
|
244 | if(selectedReg!=-1) | |
240 | { |
|
245 | { | |
241 | if(selectedReg <(registersWdgts.count()-1)) |
|
246 | if(selectedReg <(registersWdgts.count()-1)) | |
242 | { |
|
247 | { | |
243 | registersWdgts.at(selectedReg+1)->enter(registersWdgts.at(selectedReg)->cursorIndex()); |
|
248 | registersWdgts.at(selectedReg+1)->enter(registersWdgts.at(selectedReg)->cursorIndex()); | |
244 | registersWdgts.at(selectedReg)->leave(); |
|
249 | registersWdgts.at(selectedReg)->leave(); | |
245 | selectedReg+=1; |
|
250 | selectedReg+=1; | |
246 | repaint(); |
|
251 | repaint(); | |
247 | } |
|
252 | } | |
248 | else |
|
253 | else | |
249 | { |
|
254 | { | |
250 | emit downSig(this,registersWdgts.at(selectedReg)->cursorIndex()); |
|
255 | emit downSig(this,registersWdgts.at(selectedReg)->cursorIndex()); | |
251 | } |
|
256 | } | |
252 | } |
|
257 | } | |
253 | } |
|
258 | } |
@@ -1,61 +1,62 | |||||
1 | #ifndef PERIPHERALWIDGET_H |
|
1 | #ifndef PERIPHERALWIDGET_H | |
2 | #define PERIPHERALWIDGET_H |
|
2 | #define PERIPHERALWIDGET_H | |
3 |
|
3 | |||
4 | #include <QWidget> |
|
4 | #include <QWidget> | |
5 | #include <QGroupBox> |
|
5 | #include <QGroupBox> | |
6 | #include <QVBoxLayout> |
|
6 | #include <QVBoxLayout> | |
7 | #include <QList> |
|
7 | #include <QList> | |
8 | #include <QTimer> |
|
8 | #include <QTimer> | |
9 | #include "registerwidget.h" |
|
9 | #include "registerwidget.h" | |
10 | #if defined(SOCEXPLORER_SDK_BUILD) |
|
10 | #if defined(SOCEXPLORER_SDK_BUILD) | |
11 | # define SOCEXPLORER_SDK_EXPORT Q_DECL_EXPORT |
|
11 | # define SOCEXPLORER_SDK_EXPORT Q_DECL_EXPORT | |
12 | #else |
|
12 | #else | |
13 | # define SOCEXPLORER_SDK_EXPORT Q_DECL_IMPORT |
|
13 | # define SOCEXPLORER_SDK_EXPORT Q_DECL_IMPORT | |
14 | #endif |
|
14 | #endif | |
15 |
|
15 | |||
16 | /* |
|
16 | /* | |
17 | * TODO ADD an outdated marker |
|
17 | * TODO ADD an outdated marker | |
18 | * Show outdated registers with a different color for example |
|
18 | * Show outdated registers with a different color for example | |
19 | */ |
|
19 | */ | |
20 | class SOCEXPLORER_SDK_EXPORT peripheralWidget : public QWidget |
|
20 | class SOCEXPLORER_SDK_EXPORT peripheralWidget : public QWidget | |
21 | { |
|
21 | { | |
22 | Q_OBJECT |
|
22 | Q_OBJECT | |
23 | public: |
|
23 | public: | |
24 | explicit peripheralWidget(const QString& name,qint32 baseAddress, QWidget *parent = 0); |
|
24 | explicit peripheralWidget(const QString& name,qint32 baseAddress, QWidget *parent = 0); | |
25 | registerWidget* registerAt(int index) |
|
25 | registerWidget* registerAt(int index) | |
26 | { |
|
26 | { | |
27 | if(index>=0 && index<registersWdgts.count()) |
|
27 | if(index>=0 && index<registersWdgts.count()) | |
28 | return registersWdgts.at(index); |
|
28 | return registersWdgts.at(index); | |
29 | return NULL; |
|
29 | return NULL; | |
30 | } |
|
30 | } | |
|
31 | int count(); | |||
31 | signals: |
|
32 | signals: | |
32 | void writeRegSig(qint32 address,qint32 value); |
|
33 | void writeRegSig(qint32 address,qint32 value); | |
33 | qint32 readRegSig(qint32 address); |
|
34 | qint32 readRegSig(qint32 address); | |
34 | void clicked(peripheralWidget* sender); |
|
35 | void clicked(peripheralWidget* sender); | |
35 | void upSig(peripheralWidget* sender,int cursorIndex); |
|
36 | void upSig(peripheralWidget* sender,int cursorIndex); | |
36 | void downSig(peripheralWidget* sender,int cursorIndex); |
|
37 | void downSig(peripheralWidget* sender,int cursorIndex); | |
37 | public slots: |
|
38 | public slots: | |
38 | void blinkCursor(); |
|
39 | void blinkCursor(); | |
39 | void addRegister(const QString& name,qint32 address); |
|
40 | void addRegister(const QString& name,qint32 address); | |
40 | void leave(); |
|
41 | void leave(); | |
41 | void enter(int cursorIndex,bool fromTop=true); |
|
42 | void enter(int cursorIndex,bool fromTop=true); | |
42 | protected: |
|
43 | protected: | |
43 | void mousePressEvent(QMouseEvent *event); |
|
44 | void mousePressEvent(QMouseEvent *event); | |
44 | void mouseMoveEvent(QMouseEvent *event); |
|
45 | void mouseMoveEvent(QMouseEvent *event); | |
45 | void mouseReleaseEvent(QMouseEvent *event); |
|
46 | void mouseReleaseEvent(QMouseEvent *event); | |
46 | void keyPressEvent(QKeyEvent * event); |
|
47 | void keyPressEvent(QKeyEvent * event); | |
47 | void paintEvent(QPaintEvent* event); |
|
48 | void paintEvent(QPaintEvent* event); | |
48 |
|
49 | |||
49 | private: |
|
50 | private: | |
50 | void up(); |
|
51 | void up(); | |
51 | void down(); |
|
52 | void down(); | |
52 | QString p_name; |
|
53 | QString p_name; | |
53 | QString p_header; |
|
54 | QString p_header; | |
54 | qint32 p_baseAddress; |
|
55 | qint32 p_baseAddress; | |
55 | QList<registerWidget*> registersWdgts; |
|
56 | QList<registerWidget*> registersWdgts; | |
56 | int selectedReg; |
|
57 | int selectedReg; | |
57 | QTimer* p_timer; |
|
58 | QTimer* p_timer; | |
58 |
|
59 | |||
59 | }; |
|
60 | }; | |
60 |
|
61 | |||
61 | #endif // PERIPHERALWIDGET_H |
|
62 | #endif // PERIPHERALWIDGET_H |
@@ -1,82 +1,92 | |||||
1 | #include "socregsviewer.h" |
|
1 | #include "socregsviewer.h" | |
2 |
|
2 | |||
3 | socRegsViewer::socRegsViewer(const QString &name, QWidget *parent) : |
|
3 | socRegsViewer::socRegsViewer(const QString &name, QWidget *parent) : | |
4 | QScrollArea(parent) |
|
4 | QScrollArea(parent) | |
5 | { |
|
5 | { | |
6 | p_name = name; |
|
6 | p_name = name; | |
7 | p_scrollAreaWdgt = new QWidget(this); |
|
7 | p_scrollAreaWdgt = new QWidget(this); | |
8 | p_scrollAreaWdgtLayout = new QGridLayout(p_scrollAreaWdgt); |
|
8 | p_scrollAreaWdgtLayout = new QGridLayout(p_scrollAreaWdgt); | |
9 | //p_layout = new QGridLayout(this); |
|
9 | //p_layout = new QGridLayout(this); | |
10 | p_nameLabel = new QLabel(name); |
|
10 | p_nameLabel = new QLabel(name); | |
11 | setWidget(p_scrollAreaWdgt); |
|
11 | setWidget(p_scrollAreaWdgt); | |
12 | setWidgetResizable(true); |
|
12 | setWidgetResizable(true); | |
13 | p_scrollAreaWdgt->setLayout(p_scrollAreaWdgtLayout); |
|
13 | p_scrollAreaWdgt->setLayout(p_scrollAreaWdgtLayout); | |
14 | p_scrollAreaWdgtLayout->addWidget(p_nameLabel,0,0,1,1); |
|
14 | p_scrollAreaWdgtLayout->addWidget(p_nameLabel,0,0,1,1); | |
15 | } |
|
15 | } | |
16 |
|
16 | |||
17 | peripheralWidget *socRegsViewer::peripheral(int index) |
|
17 | peripheralWidget *socRegsViewer::peripheral(int index) | |
18 | { |
|
18 | { | |
19 | if(index>=0 && index<p_peripherals.count()) |
|
19 | if(index>=0 && index<p_peripherals.count()) | |
20 | { |
|
20 | { | |
21 | return p_peripherals.at(index); |
|
21 | return p_peripherals.at(index); | |
22 | } |
|
22 | } | |
23 | return NULL; |
|
23 | return NULL; | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | void socRegsViewer::addPeripheral(peripheralWidget *peripheral) |
|
26 | void socRegsViewer::addPeripheral(peripheralWidget *peripheral) | |
27 | { |
|
27 | { | |
28 | if(peripheral!=NULL) |
|
28 | if(peripheral!=NULL) | |
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*))); |
|
32 | connect(peripheral,SIGNAL(clicked(peripheralWidget*)),this,SLOT(periphClicked(peripheralWidget*))); | |
33 | connect(peripheral,SIGNAL(upSig(peripheralWidget*,int)),this,SLOT(periphUp(peripheralWidget*,int))); |
|
33 | connect(peripheral,SIGNAL(upSig(peripheralWidget*,int)),this,SLOT(periphUp(peripheralWidget*,int))); | |
34 | connect(peripheral,SIGNAL(downSig(peripheralWidget*,int)),this,SLOT(periphDown(peripheralWidget*,int))); |
|
34 | connect(peripheral,SIGNAL(downSig(peripheralWidget*,int)),this,SLOT(periphDown(peripheralWidget*,int))); | |
35 | } |
|
35 | } | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | void socRegsViewer::periphClicked(peripheralWidget *sender) |
|
38 | void socRegsViewer::periphClicked(peripheralWidget *sender) | |
39 | { |
|
39 | { | |
40 | peripheralWidget * item; |
|
40 | peripheralWidget * item; | |
41 | if(sender!=NULL) |
|
41 | if(sender!=NULL) | |
42 | { |
|
42 | { | |
43 | for(int i=0;i<p_peripherals.count();i++) |
|
43 | for(int i=0;i<p_peripherals.count();i++) | |
44 | { |
|
44 | { | |
45 | item = p_peripherals.at(i); |
|
45 | item = p_peripherals.at(i); | |
46 | if(item!=sender) |
|
46 | if(item!=sender) | |
47 | { |
|
47 | { | |
48 | item->leave(); |
|
48 | item->leave(); | |
49 | } |
|
49 | } | |
50 | } |
|
50 | } | |
51 | } |
|
51 | } | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | void socRegsViewer::periphUp(peripheralWidget *sender, int cursorIndex) |
|
54 | void socRegsViewer::periphUp(peripheralWidget *sender, int cursorIndex) | |
55 | { |
|
55 | { | |
56 | int index; |
|
56 | int index,senderIndex; | |
57 | if(sender!=NULL) |
|
57 | if(sender!=NULL) | |
58 | { |
|
58 | { | |
59 | index = p_peripherals.indexOf(sender); |
|
59 | index =senderIndex= p_peripherals.indexOf(sender); | |
60 |
|
|
60 | while(index!=-1 && index!=0) | |
61 | { |
|
61 | { | |
62 |
p_peripherals.at(index)-> |
|
62 | if(p_peripherals.at(index-1)->count()>0) | |
|
63 | { | |||
|
64 | p_peripherals.at(senderIndex)->leave(); | |||
63 | p_peripherals.at(index-1)->enter(cursorIndex,false); |
|
65 | p_peripherals.at(index-1)->enter(cursorIndex,false); | |
64 | ensureWidgetVisible(p_peripherals.at(index-1)); |
|
66 | ensureWidgetVisible(p_peripherals.at(index-1)); | |
|
67 | break; | |||
|
68 | } | |||
|
69 | index--; | |||
65 | } |
|
70 | } | |
66 | } |
|
71 | } | |
67 | } |
|
72 | } | |
68 |
|
73 | |||
69 | void socRegsViewer::periphDown(peripheralWidget *sender, int cursorIndex) |
|
74 | void socRegsViewer::periphDown(peripheralWidget *sender, int cursorIndex) | |
70 | { |
|
75 | { | |
71 | int index; |
|
76 | int index,senderIndex; | |
72 | if(sender!=NULL) |
|
77 | if(sender!=NULL) | |
73 | { |
|
78 | { | |
74 |
index |
|
79 | index=senderIndex= p_peripherals.indexOf(sender); | |
75 |
|
|
80 | while((index!=-1) && (index<(p_peripherals.count()-1))) | |
76 | { |
|
81 | { | |
77 |
p_peripherals.at(index)-> |
|
82 | if(p_peripherals.at(index+1)->count()>0) | |
|
83 | { | |||
|
84 | p_peripherals.at(senderIndex)->leave(); | |||
78 | p_peripherals.at(index+1)->enter(cursorIndex); |
|
85 | p_peripherals.at(index+1)->enter(cursorIndex); | |
79 | ensureWidgetVisible(p_peripherals.at(index+1)); |
|
86 | ensureWidgetVisible(p_peripherals.at(index+1)); | |
|
87 | break; | |||
|
88 | } | |||
|
89 | index++; | |||
80 | } |
|
90 | } | |
81 | } |
|
91 | } | |
82 | } |
|
92 | } |
General Comments 0
You need to be logged in to leave comments.
Login now