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