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