@@ -1,14 +1,144 | |||
|
1 | 1 | #include "peripheralwidget.h" |
|
2 | 2 | |
|
3 | 3 | peripheralWidget::peripheralWidget(const QString &name, QWidget *parent) : |
|
4 | QGroupBox(name,parent) | |
|
4 | QWidget(parent) | |
|
5 | 5 | { |
|
6 | mainLayout = new QVBoxLayout(this); | |
|
6 | p_name = name; | |
|
7 | p_timer = new QTimer(this); | |
|
8 | p_timer->setInterval(500); | |
|
7 | 9 | for(int i=0;i<10;i++) |
|
8 | 10 | { |
|
9 |
registersWdgts.append(new registerWidget(QString("REG%1").arg(i),i* |
|
|
11 | registersWdgts.append(new registerWidget(QString("REG%1").arg(i),i*4)); | |
|
10 | 12 | registersWdgts.at(i)->setValue((i<<24)+(i<<8)+i); |
|
11 | mainLayout->addWidget(registersWdgts.at(i)); | |
|
13 | connect(registersWdgts.at(i),SIGNAL(repaint()),this,SLOT(repaint())); | |
|
14 | } | |
|
15 | setAttribute(Qt::WA_AlwaysShowToolTips); | |
|
16 | setMouseTracking(true); | |
|
17 | setFocusPolicy(Qt::StrongFocus); | |
|
18 | selectedReg = -1; | |
|
19 | connect(p_timer,SIGNAL(timeout()),this,SLOT(blinkCursor())); | |
|
20 | setFont(QFont("Utopia", 14,QFont::Bold)); | |
|
21 | } | |
|
22 | ||
|
23 | void peripheralWidget::blinkCursor() | |
|
24 | { | |
|
25 | if(selectedReg!=-1) | |
|
26 | registersWdgts.at(selectedReg)->blinkCursor(); | |
|
27 | repaint(); | |
|
28 | } | |
|
29 | ||
|
30 | void peripheralWidget::mousePressEvent(QMouseEvent *event) | |
|
31 | { | |
|
32 | p_timer->stop(); | |
|
33 | if(selectedReg!=-1) | |
|
34 | registersWdgts.at(selectedReg)->leave(); | |
|
35 | for(int i=0; i<registersWdgts.count();i++) | |
|
36 | { | |
|
37 | if(registersWdgts.at(i)->contains(event->pos())) | |
|
38 | { | |
|
39 | registersWdgts.at(i)->enter(registersWdgts.at(i)->cursorIndex(event->pos().x())); | |
|
40 | selectedReg = i; | |
|
41 | p_timer->start(); | |
|
42 | } | |
|
12 | 43 | } |
|
13 | setLayout(mainLayout); | |
|
44 | repaint(); | |
|
45 | } | |
|
46 | ||
|
47 | void peripheralWidget::mouseMoveEvent(QMouseEvent *event) | |
|
48 | { | |
|
49 | ||
|
50 | } | |
|
51 | ||
|
52 | void peripheralWidget::mouseReleaseEvent(QMouseEvent *event) | |
|
53 | { | |
|
54 | ||
|
14 | 55 | } |
|
56 | ||
|
57 | void peripheralWidget::keyPressEvent(QKeyEvent *event) | |
|
58 | { | |
|
59 | if(this->selectedReg!=-1){ | |
|
60 | if(event->modifiers()==Qt::ControlModifier) | |
|
61 | { | |
|
62 | switch(event->key()) | |
|
63 | { | |
|
64 | case Qt::Key_Up: | |
|
65 | registersWdgts.at(selectedReg)->set(registersWdgts.at(selectedReg)->cursorIndex()); | |
|
66 | break; | |
|
67 | case Qt::Key_Down: | |
|
68 | registersWdgts.at(selectedReg)->clear(registersWdgts.at(selectedReg)->cursorIndex()); | |
|
69 | break; | |
|
70 | default: | |
|
71 | break; | |
|
72 | } | |
|
73 | } | |
|
74 | else | |
|
75 | { | |
|
76 | switch(event->key()) | |
|
77 | { | |
|
78 | case Qt::Key_0: | |
|
79 | registersWdgts.at(selectedReg)->clear(registersWdgts.at(selectedReg)->cursorIndex()); | |
|
80 | registersWdgts.at(selectedReg)->moveCursorRight(1); | |
|
81 | break; | |
|
82 | case Qt::Key_1: | |
|
83 | registersWdgts.at(selectedReg)->set(registersWdgts.at(selectedReg)->cursorIndex()); | |
|
84 | registersWdgts.at(selectedReg)->moveCursorRight(1); | |
|
85 | break; | |
|
86 | case Qt::Key_Right: | |
|
87 | registersWdgts.at(selectedReg)->moveCursorRight(1); | |
|
88 | this->repaint(); | |
|
89 | break; | |
|
90 | case Qt::Key_Left: | |
|
91 | registersWdgts.at(selectedReg)->moveCursorLeft(1); | |
|
92 | this->repaint(); | |
|
93 | break; | |
|
94 | case Qt::Key_Up: | |
|
95 | up(); | |
|
96 | break; | |
|
97 | case Qt::Key_Down: | |
|
98 | down(); | |
|
99 | break; | |
|
100 | default: | |
|
101 | break; | |
|
102 | } | |
|
103 | } | |
|
104 | ||
|
105 | } | |
|
106 | } | |
|
107 | ||
|
108 | void peripheralWidget::paintEvent(QPaintEvent *event) | |
|
109 | { | |
|
110 | Q_UNUSED(event) | |
|
111 | QPainter painter(this); | |
|
112 | QPoint offset=QPoint(0,0); | |
|
113 | int nameWidth = fontMetrics().width(p_name); | |
|
114 | painter.drawText((this->minimumWidth()/2)-nameWidth,4,fontMetrics().width(p_name),fontMetrics().height()+4,Qt::AlignCenter,p_name); | |
|
115 | offset+=QPoint(0,fontMetrics().height()+8); | |
|
116 | for(int i=0;i<registersWdgts.count();i++) | |
|
117 | { | |
|
118 | offset = registersWdgts.at(i)->paint(&painter,offset); | |
|
119 | } | |
|
120 | setMinimumSize(registersWdgts.first()->boundingRect().width(),offset.y()); | |
|
121 | updateGeometry(); | |
|
122 | } | |
|
123 | ||
|
124 | void peripheralWidget::up() | |
|
125 | { | |
|
126 | if(selectedReg!=-1 && selectedReg >0) | |
|
127 | { | |
|
128 | registersWdgts.at(selectedReg)->leave(); | |
|
129 | selectedReg-=1; | |
|
130 | registersWdgts.at(selectedReg)->enter(registersWdgts.at(selectedReg+1)->cursorIndex()); | |
|
131 | repaint(); | |
|
132 | } | |
|
133 | } | |
|
134 | ||
|
135 | void peripheralWidget::down() | |
|
136 | { | |
|
137 | if(selectedReg!=-1 && selectedReg <(registersWdgts.count()-1)) | |
|
138 | { | |
|
139 | registersWdgts.at(selectedReg)->leave(); | |
|
140 | selectedReg+=1; | |
|
141 | registersWdgts.at(selectedReg)->enter(registersWdgts.at(selectedReg-1)->cursorIndex()); | |
|
142 | repaint(); | |
|
143 | } | |
|
144 | } |
@@ -1,26 +1,37 | |||
|
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 | #include <QTimer> | |
|
8 | 9 | #include "registerwidget.h" |
|
9 | 10 | |
|
10 |
class peripheralWidget : public Q |
|
|
11 | class peripheralWidget : public QWidget | |
|
11 | 12 | { |
|
12 | 13 | Q_OBJECT |
|
13 | 14 | public: |
|
14 | 15 | explicit peripheralWidget(const QString& name, QWidget *parent = 0); |
|
15 | 16 | |
|
16 | 17 | signals: |
|
17 | 18 | |
|
18 | 19 | public slots: |
|
20 | void blinkCursor(); | |
|
21 | protected: | |
|
22 | void mousePressEvent(QMouseEvent *event); | |
|
23 | void mouseMoveEvent(QMouseEvent *event); | |
|
24 | void mouseReleaseEvent(QMouseEvent *event); | |
|
25 | void keyPressEvent(QKeyEvent * event); | |
|
26 | void paintEvent(QPaintEvent* event); | |
|
19 | 27 | |
|
20 | 28 | private: |
|
21 | QVBoxLayout* mainLayout; | |
|
29 | void up(); | |
|
30 | void down(); | |
|
31 | QString p_name; | |
|
22 | 32 | QList<registerWidget*> registersWdgts; |
|
23 | ||
|
33 | int selectedReg; | |
|
34 | QTimer* p_timer; | |
|
24 | 35 | }; |
|
25 | 36 | |
|
26 | 37 | #endif // PERIPHERALWIDGET_H |
@@ -1,144 +1,246 | |||
|
1 | 1 | #include "registerwidget.h" |
|
2 | 2 | #include <QPaintEvent> |
|
3 | 3 | #include <QPainter> |
|
4 | 4 | |
|
5 |
registerWidget::registerWidget(const QString &name, qint32 address, Q |
|
|
6 |
Q |
|
|
5 | registerWidget::registerWidget(const QString &name, qint32 address, QObject *parent) : | |
|
6 | QObject(parent) | |
|
7 | 7 | { |
|
8 | 8 | p_address = address; |
|
9 | 9 | p_value = 0; |
|
10 |
p_addressEl = new regWidgetElement(QString("0x%1").arg(p_address,8,16).replace(" ","0"),QFont("Utopia", 12), |
|
|
10 | p_addressEl = new regWidgetElement(QString("0x%1").arg(p_address,8,16).replace(" ","0"),QFont("Utopia", 12),10,4); | |
|
11 | 11 | p_fieldsEl = new bitfieldsElement(QString("%1").arg(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 = 4; |
|
15 | this->p_timer = new QTimer(this); | |
|
16 | this->p_timer->setInterval(1000); | |
|
17 | this->p_cursorIndex = 0; | |
|
18 | 15 | updateBoundingRect(); |
|
19 | connect(p_timer,SIGNAL(timeout()),this,SLOT(blinkCursor())); | |
|
20 | 16 | } |
|
21 | 17 | |
|
22 | 18 | registerWidget::~registerWidget() |
|
23 | 19 | { |
|
24 | 20 | delete p_addressEl; |
|
25 | 21 | delete p_fieldsEl; |
|
26 | 22 | delete p_nameEl; |
|
27 | 23 | } |
|
28 | 24 | |
|
29 |
|
|
|
25 | int registerWidget::contains(const QPointF &point) | |
|
26 | { | |
|
27 | return p_boundingRect.contains(point.x(),point.y()); | |
|
28 | } | |
|
29 | ||
|
30 | QPoint registerWidget::paint(QPainter* painter, QPoint offset) | |
|
30 | 31 | { |
|
31 | Q_UNUSED(event) | |
|
32 | QPainter painter(this); | |
|
33 | painter.translate(p_addressEl->paint(&painter)); | |
|
34 |
painter |
|
|
35 |
p |
|
|
36 | setMinimumSize(p_boundingRect); | |
|
37 |
|
|
|
32 | painter->save(); | |
|
33 | painter->translate(offset); | |
|
34 | p_boundingRect.moveTopLeft(offset); | |
|
35 | painter->translate(p_addressEl->paint(painter)); | |
|
36 | painter->translate(p_fieldsEl->paint(painter)); | |
|
37 | p_nameEl->paint(painter); | |
|
38 | painter->restore(); | |
|
39 | int h=p_boundingRect.height(); | |
|
40 | int y=p_boundingRect.y(); | |
|
41 | return QPoint(0,p_boundingRect.height()+p_boundingRect.y()+p_yMargins); | |
|
42 | } | |
|
43 | ||
|
44 | QRect registerWidget::boundingRect() | |
|
45 | { | |
|
46 | return p_boundingRect; | |
|
47 | } | |
|
48 | ||
|
49 | uint registerWidget::cursorIndex() | |
|
50 | { | |
|
51 | return p_fieldsEl->cursorIndex(); | |
|
52 | } | |
|
53 | ||
|
54 | uint registerWidget::cursorIndex(int xPos) | |
|
55 | { | |
|
56 | if(xPos>p_addressEl->boundingRect().width() && xPos<(p_addressEl->boundingRect().width()+p_fieldsEl->boundingRect().width())) | |
|
57 | { | |
|
58 | return p_fieldsEl->cursorIndex(xPos-p_addressEl->boundingRect().width()); | |
|
59 | } | |
|
38 | 60 | } |
|
39 | 61 | |
|
40 | 62 | void registerWidget::setValue(qint32 value) |
|
41 | 63 | { |
|
42 | 64 | this->p_value = value; |
|
43 | this->p_fieldsEl->setValue(QString("%1").arg(p_value,32,2).replace(" ","0")); | |
|
44 | this->repaint(); | |
|
65 | this->p_fieldsEl->setValue(QString("%1").arg((uint)p_value,32,2).replace(" ","0")); | |
|
66 | emit this->repaint(); | |
|
45 | 67 | } |
|
46 | 68 | |
|
47 | 69 | void registerWidget::blinkCursor() |
|
48 | 70 | { |
|
49 |
|
|
|
71 | p_fieldsEl->blinkCursor(); | |
|
72 | //repaint(); | |
|
50 | 73 | } |
|
51 | 74 | |
|
52 | 75 | void registerWidget::moveCursorLeft(int count) |
|
53 | 76 | { |
|
54 | 77 | p_fieldsEl->moveCursorLeft(count); |
|
78 | p_fieldsEl->blinkCursor(); | |
|
55 | 79 | } |
|
56 | 80 | |
|
57 | 81 | void registerWidget::moveCursorRight(int count) |
|
58 | 82 | { |
|
59 | 83 | p_fieldsEl->moveCursorRight(count); |
|
84 | p_fieldsEl->blinkCursor(); | |
|
85 | } | |
|
86 | ||
|
87 | void registerWidget::enter(int index) | |
|
88 | { | |
|
89 | p_fieldsEl->enter(index); | |
|
90 | } | |
|
91 | ||
|
92 | void registerWidget::leave() | |
|
93 | { | |
|
94 | p_fieldsEl->leave(); | |
|
95 | } | |
|
96 | ||
|
97 | void registerWidget::clear(int index) | |
|
98 | { | |
|
99 | p_value &= ~(1<<index); | |
|
100 | this->p_fieldsEl->setValue(QString("%1").arg((uint)p_value,32,2).replace(" ","0")); | |
|
101 | emit this->repaint(); | |
|
102 | } | |
|
103 | ||
|
104 | void registerWidget::set(int index) | |
|
105 | { | |
|
106 | p_value |= 1<<index; | |
|
107 | this->p_fieldsEl->setValue(QString("%1").arg((uint)p_value,32,2).replace(" ","0")); | |
|
108 | emit this->repaint(); | |
|
60 | 109 | } |
|
61 | 110 | |
|
62 | 111 | void registerWidget::updateBoundingRect() |
|
63 | 112 | { |
|
64 | 113 | p_boundingRect.setHeight(p_fieldsEl->boundingRect().height()+(p_yMargins*2)); |
|
65 | 114 | p_boundingRect.setWidth(p_fieldsEl->boundingRect().width()+p_addressEl->boundingRect().width()+p_nameEl->boundingRect().width()+(p_xMargins*2)); |
|
66 | 115 | } |
|
67 | 116 | |
|
68 | 117 | |
|
69 | 118 | |
|
70 | 119 | bitfieldsElement::bitfieldsElement(const QString &value, QFont font, int xMargin, int yMargin) |
|
71 | 120 | :regWidgetElement(value,font,xMargin,yMargin) |
|
72 | 121 | { |
|
73 | 122 | this->attributesLUT.append(new bitFieldAttribute(true,"desc1")); |
|
74 | 123 | this->attributesLUT.append(new bitFieldAttribute(false,"desc2")); |
|
75 | 124 | for(int i=0;i<32;i++) |
|
76 | 125 | { |
|
77 | 126 | attributesIndex[i] = i&1; |
|
78 | 127 | } |
|
79 | 128 | updateBoundingRect(); |
|
129 | p_blinkTextBgColor = QColor(Qt::black); | |
|
130 | p_blinkTextColor = QColor(Qt::white); | |
|
131 | p_cursorBlinkEnable = false; | |
|
132 | p_dx=QFontMetrics(p_font).width("0")+2; | |
|
80 | 133 | } |
|
81 | 134 | |
|
82 | 135 | QPoint bitfieldsElement::paint(QPainter *painter) |
|
83 | 136 | { |
|
84 | 137 | painter->fillRect(4,4,p_boundingRec.width(),p_boundingRec.height(),Qt::darkGray); |
|
85 | 138 | painter->fillRect(0,0,p_boundingRec.width(),p_boundingRec.height(),Qt::white); |
|
86 | 139 | painter->setFont(p_font); |
|
87 | int xpos=p_xMargins,dx=QFontMetrics(p_font).width("0")+2; | |
|
140 | int xpos=p_xMargins; | |
|
88 | 141 | for(int i=0;i<(32/4);i++) |
|
89 | 142 | { |
|
90 | 143 | for(int l = 0;l<4;l++) |
|
91 | 144 | { |
|
92 | if(attributesLUT[attributesIndex[(i*4)+l]]->rw==false) | |
|
93 | painter->fillRect(xpos-1,0,dx,p_boundingRec.height(),Qt::lightGray); | |
|
145 | if(p_cursorBlinkEnable == false || (31-p_cursorIndex) != ((i*4)+l)) | |
|
146 | { | |
|
147 | if(attributesLUT[attributesIndex[(i*4)+l]]->rw==false) | |
|
148 | { | |
|
149 | painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::lightGray); | |
|
150 | } | |
|
151 | else | |
|
152 | { | |
|
153 | painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::white); | |
|
154 | } | |
|
155 | painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); | |
|
156 | } | |
|
94 | 157 | else |
|
95 | painter->fillRect(xpos-1,0,dx,p_boundingRec.height(),Qt::white); | |
|
96 | painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); | |
|
97 | xpos+=dx; | |
|
158 | { | |
|
159 | QPen svg = painter->pen(); | |
|
160 | painter->setPen(p_blinkTextColor); | |
|
161 | painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),p_blinkTextBgColor); | |
|
162 | painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); | |
|
163 | painter->setPen(svg); | |
|
164 | } | |
|
165 | xpos+=p_dx; | |
|
98 | 166 | } |
|
99 | 167 | if(i==3) |
|
100 | 168 | painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+6); |
|
101 | 169 | else if(i<7) |
|
102 | 170 | painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-2,xpos+(p_xMargins/2),p_boundingRec.height()+2); |
|
103 | 171 | xpos+=p_xMargins; |
|
104 | 172 | } |
|
105 | 173 | painter->drawRect(0,0,p_boundingRec.width(),p_boundingRec.height()); |
|
106 | 174 | return QPoint(p_boundingRec.width()+4+p_xMargins,0); |
|
107 | 175 | } |
|
108 | 176 | |
|
109 | 177 | void bitfieldsElement::updateBoundingRect() |
|
110 | 178 | { |
|
111 | 179 | p_boundingRec.setHeight(QFontMetrics(p_font).boundingRect(p_valueStr).height()+(p_yMargins*2)); |
|
112 | 180 | int width = (((4*(QFontMetrics(p_font).width("0") + 2)) + p_xMargins) * 8) + (p_xMargins); |
|
113 | 181 | p_boundingRec.setWidth(width); |
|
114 | 182 | } |
|
115 | 183 | |
|
116 | 184 | void bitfieldsElement::setValue(const QString &value) |
|
117 | 185 | { |
|
118 | 186 | p_valueStr = value; |
|
119 | 187 | updateBoundingRect(); |
|
120 | 188 | } |
|
121 | 189 | |
|
122 | 190 | void bitfieldsElement::blinkCursor() |
|
123 | 191 | { |
|
124 | ||
|
192 | p_cursorBlinkEnable = !p_cursorBlinkEnable; | |
|
125 | 193 | } |
|
126 | 194 | |
|
127 | 195 | void bitfieldsElement::moveCursorLeft(int count) |
|
128 | 196 | { |
|
129 | 197 | p_cursorIndex+=count; |
|
130 | 198 | if(31<p_cursorIndex) |
|
131 | 199 | { |
|
132 | 200 | p_cursorIndex = 31; |
|
133 | 201 | } |
|
134 | 202 | |
|
135 | 203 | } |
|
136 | 204 | |
|
137 | 205 | void bitfieldsElement::moveCursorRight(int count) |
|
138 | 206 | { |
|
139 | 207 | p_cursorIndex -= count; |
|
140 | 208 | if(31<p_cursorIndex) |
|
141 | 209 | { |
|
142 | 210 | p_cursorIndex = 0; |
|
143 | 211 | } |
|
144 | 212 | } |
|
213 | ||
|
214 | void bitfieldsElement::enter(int index) | |
|
215 | { | |
|
216 | p_cursorIndex = index; | |
|
217 | p_cursorBlinkEnable = true; | |
|
218 | } | |
|
219 | ||
|
220 | void bitfieldsElement::leave() | |
|
221 | { | |
|
222 | p_cursorBlinkEnable = false; | |
|
223 | } | |
|
224 | ||
|
225 | uint bitfieldsElement::cursorIndex() | |
|
226 | { | |
|
227 | return p_cursorIndex; | |
|
228 | } | |
|
229 | ||
|
230 | uint bitfieldsElement::cursorIndex(int xPos) | |
|
231 | { | |
|
232 | uint index=0; | |
|
233 | xPos-=p_xMargins; | |
|
234 | if(xPos<p_boundingRec.width()) | |
|
235 | { | |
|
236 | index = 31 - ((4*xPos)/((4*p_dx)+p_xMargins)); | |
|
237 | } | |
|
238 | return index; | |
|
239 | } | |
|
240 | ||
|
241 | void bitfieldsElement::setFont(QFont font) | |
|
242 | { | |
|
243 | p_font = font; | |
|
244 | p_dx=QFontMetrics(p_font).width("0")+2; | |
|
245 | updateBoundingRect(); | |
|
246 | } |
@@ -1,118 +1,130 | |||
|
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 | 60 | bitFieldAttribute(bool rw,QString description) |
|
61 | 61 | { |
|
62 | 62 | this->rw = rw; |
|
63 | 63 | this->description = description; |
|
64 | 64 | } |
|
65 | 65 | bool rw; |
|
66 | 66 | QString description; |
|
67 | 67 | }; |
|
68 | 68 | public: |
|
69 | 69 | bitfieldsElement(const QString& value,QFont font,int xMargin,int yMargin); |
|
70 | 70 | QPoint paint(QPainter* painter); |
|
71 | 71 | |
|
72 | 72 | void updateBoundingRect(); |
|
73 | 73 | void setValue(const QString& value); |
|
74 | 74 | void blinkCursor(); |
|
75 | 75 | void moveCursorLeft(int count); |
|
76 | 76 | void moveCursorRight(int count); |
|
77 | void enter(int index); | |
|
78 | void leave(); | |
|
79 | uint cursorIndex(); | |
|
80 | uint cursorIndex(int xPos); | |
|
81 | void setFont(QFont font); | |
|
77 | 82 | private: |
|
78 | 83 | int attributesIndex[32]; |
|
79 | 84 | uint p_cursorIndex; |
|
85 | bool p_cursorBlinkEnable; | |
|
86 | int p_dx; | |
|
80 | 87 | QList<bitFieldAttribute*> attributesLUT; |
|
88 | QColor p_blinkTextColor,p_blinkTextBgColor; | |
|
89 | ||
|
81 | 90 | }; |
|
82 | 91 | |
|
83 | 92 | |
|
84 |
class registerWidget : public Q |
|
|
93 | class registerWidget : public QObject | |
|
85 | 94 | { |
|
86 | 95 | Q_OBJECT |
|
87 | 96 | public: |
|
88 |
explicit registerWidget(const QString& name,qint32 address,Q |
|
|
97 | explicit registerWidget(const QString& name,qint32 address,QObject *parent = 0); | |
|
89 | 98 | ~registerWidget(); |
|
90 | ||
|
99 | int contains(const QPointF &point); | |
|
100 | QPoint paint(QPainter* painter,QPoint offset); | |
|
101 | QRect boundingRect(); | |
|
102 | uint cursorIndex(); | |
|
103 | uint cursorIndex(int xPos); | |
|
91 | 104 | signals: |
|
92 | 105 | void cursorUp(int pos); |
|
93 | 106 | void cursorDown(int pos); |
|
94 | 107 | void valueChanged(qint32 value); |
|
95 | ||
|
96 | protected: | |
|
97 | void paintEvent(QPaintEvent* event); | |
|
108 | void repaint(); | |
|
98 | 109 | |
|
99 | 110 | public slots: |
|
100 | 111 | void setValue(qint32 value); |
|
101 | 112 | void blinkCursor(); |
|
102 | 113 | void moveCursorLeft(int count); |
|
103 | 114 | void moveCursorRight(int count); |
|
104 | ||
|
115 | void enter(int index=0); | |
|
116 | void leave(); | |
|
117 | void clear(int index); | |
|
118 | void set(int index); | |
|
105 | 119 | private: |
|
106 | QTimer* p_timer; | |
|
107 | 120 | void updateBoundingRect(); |
|
108 | 121 | qint32 p_address; |
|
109 | 122 | qint32 p_value; |
|
110 |
Q |
|
|
123 | QRect p_boundingRect; | |
|
111 | 124 | int p_xMargins; |
|
112 | 125 | int p_yMargins; |
|
113 | uint p_cursorIndex; | |
|
114 | 126 | regWidgetElement* p_addressEl,*p_nameEl; |
|
115 | 127 | bitfieldsElement* p_fieldsEl; |
|
116 | 128 | }; |
|
117 | 129 | |
|
118 | 130 | #endif // REGISTERWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now