@@ -12,7 +12,11 registerWidget::registerWidget(const QSt | |||
|
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; | |
|
15 | 18 | updateBoundingRect(); |
|
19 | connect(p_timer,SIGNAL(timeout()),this,SLOT(blinkCursor())); | |
|
16 | 20 | } |
|
17 | 21 | |
|
18 | 22 | registerWidget::~registerWidget() |
@@ -40,9 +44,101 void registerWidget::setValue(qint32 val | |||
|
40 | 44 | this->repaint(); |
|
41 | 45 | } |
|
42 | 46 | |
|
47 | void registerWidget::blinkCursor() | |
|
48 | { | |
|
49 | p_fieldsEl->blinkCursor(); | |
|
50 | } | |
|
51 | ||
|
52 | void registerWidget::moveCursorLeft(int count) | |
|
53 | { | |
|
54 | p_fieldsEl->moveCursorLeft(count); | |
|
55 | } | |
|
56 | ||
|
57 | void registerWidget::moveCursorRight(int count) | |
|
58 | { | |
|
59 | p_fieldsEl->moveCursorRight(count); | |
|
60 | } | |
|
61 | ||
|
43 | 62 | void registerWidget::updateBoundingRect() |
|
44 | 63 | { |
|
45 | 64 | p_boundingRect.setHeight(p_fieldsEl->boundingRect().height()+(p_yMargins*2)); |
|
46 | 65 | p_boundingRect.setWidth(p_fieldsEl->boundingRect().width()+p_addressEl->boundingRect().width()+p_nameEl->boundingRect().width()+(p_xMargins*2)); |
|
47 | 66 | } |
|
48 | 67 | |
|
68 | ||
|
69 | ||
|
70 | bitfieldsElement::bitfieldsElement(const QString &value, QFont font, int xMargin, int yMargin) | |
|
71 | :regWidgetElement(value,font,xMargin,yMargin) | |
|
72 | { | |
|
73 | this->attributesLUT.append(new bitFieldAttribute(true,"desc1")); | |
|
74 | this->attributesLUT.append(new bitFieldAttribute(false,"desc2")); | |
|
75 | for(int i=0;i<32;i++) | |
|
76 | { | |
|
77 | attributesIndex[i] = i&1; | |
|
78 | } | |
|
79 | updateBoundingRect(); | |
|
80 | } | |
|
81 | ||
|
82 | QPoint bitfieldsElement::paint(QPainter *painter) | |
|
83 | { | |
|
84 | painter->fillRect(4,4,p_boundingRec.width(),p_boundingRec.height(),Qt::darkGray); | |
|
85 | painter->fillRect(0,0,p_boundingRec.width(),p_boundingRec.height(),Qt::white); | |
|
86 | painter->setFont(p_font); | |
|
87 | int xpos=p_xMargins,dx=QFontMetrics(p_font).width("0")+2; | |
|
88 | for(int i=0;i<(32/4);i++) | |
|
89 | { | |
|
90 | for(int l = 0;l<4;l++) | |
|
91 | { | |
|
92 | if(attributesLUT[attributesIndex[(i*4)+l]]->rw==false) | |
|
93 | painter->fillRect(xpos-1,0,dx,p_boundingRec.height(),Qt::lightGray); | |
|
94 | 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; | |
|
98 | } | |
|
99 | if(i==3) | |
|
100 | painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+6); | |
|
101 | else if(i<7) | |
|
102 | painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-2,xpos+(p_xMargins/2),p_boundingRec.height()+2); | |
|
103 | xpos+=p_xMargins; | |
|
104 | } | |
|
105 | painter->drawRect(0,0,p_boundingRec.width(),p_boundingRec.height()); | |
|
106 | return QPoint(p_boundingRec.width()+4+p_xMargins,0); | |
|
107 | } | |
|
108 | ||
|
109 | void bitfieldsElement::updateBoundingRect() | |
|
110 | { | |
|
111 | p_boundingRec.setHeight(QFontMetrics(p_font).boundingRect(p_valueStr).height()+(p_yMargins*2)); | |
|
112 | int width = (((4*(QFontMetrics(p_font).width("0") + 2)) + p_xMargins) * 8) + (p_xMargins); | |
|
113 | p_boundingRec.setWidth(width); | |
|
114 | } | |
|
115 | ||
|
116 | void bitfieldsElement::setValue(const QString &value) | |
|
117 | { | |
|
118 | p_valueStr = value; | |
|
119 | updateBoundingRect(); | |
|
120 | } | |
|
121 | ||
|
122 | void bitfieldsElement::blinkCursor() | |
|
123 | { | |
|
124 | ||
|
125 | } | |
|
126 | ||
|
127 | void bitfieldsElement::moveCursorLeft(int count) | |
|
128 | { | |
|
129 | p_cursorIndex+=count; | |
|
130 | if(31<p_cursorIndex) | |
|
131 | { | |
|
132 | p_cursorIndex = 31; | |
|
133 | } | |
|
134 | ||
|
135 | } | |
|
136 | ||
|
137 | void bitfieldsElement::moveCursorRight(int count) | |
|
138 | { | |
|
139 | p_cursorIndex -= count; | |
|
140 | if(31<p_cursorIndex) | |
|
141 | { | |
|
142 | p_cursorIndex = 0; | |
|
143 | } | |
|
144 | } |
@@ -2,6 +2,7 | |||
|
2 | 2 | #define REGISTERWIDGET_H |
|
3 | 3 | #include <QtWidgets> |
|
4 | 4 | #include <QWidget> |
|
5 | #include <QTimer> | |
|
5 | 6 | |
|
6 | 7 | class regWidgetElement |
|
7 | 8 | { |
@@ -65,57 +66,17 class bitfieldsElement: public regWidget | |||
|
65 | 66 | QString description; |
|
66 | 67 | }; |
|
67 | 68 | public: |
|
68 | bitfieldsElement(const QString& value,QFont font,int xMargin,int yMargin) | |
|
69 | :regWidgetElement(value,font,xMargin,yMargin) | |
|
70 | { | |
|
71 | this->attributesLUT.append(new bitFieldAttribute(true,"desc1")); | |
|
72 | this->attributesLUT.append(new bitFieldAttribute(false,"desc2")); | |
|
73 | for(int i=0;i<32;i++) | |
|
74 | { | |
|
75 | attributesIndex[i] = i&1; | |
|
76 | } | |
|
77 | updateBoundingRect(); | |
|
78 | } | |
|
79 | QPoint paint(QPainter* painter) | |
|
80 | { | |
|
81 | painter->fillRect(4,4,p_boundingRec.width(),p_boundingRec.height(),Qt::darkGray); | |
|
82 | painter->fillRect(0,0,p_boundingRec.width(),p_boundingRec.height(),Qt::white); | |
|
83 | painter->setFont(p_font); | |
|
84 | int xpos=p_xMargins,dx=QFontMetrics(p_font).width("0")+2; | |
|
85 | for(int i=0;i<(32/4);i++) | |
|
86 | { | |
|
87 | for(int l = 0;l<4;l++) | |
|
88 | { | |
|
89 | if(attributesLUT[attributesIndex[(i*4)+l]]->rw==false) | |
|
90 | painter->fillRect(xpos-1,0,dx,p_boundingRec.height(),Qt::lightGray); | |
|
91 | else | |
|
92 | painter->fillRect(xpos-1,0,dx,p_boundingRec.height(),Qt::white); | |
|
93 | painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); | |
|
94 | xpos+=dx; | |
|
95 | } | |
|
96 | if(i==3) | |
|
97 | painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+6); | |
|
98 | else if(i<7) | |
|
99 | painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-2,xpos+(p_xMargins/2),p_boundingRec.height()+2); | |
|
100 | xpos+=p_xMargins; | |
|
101 | } | |
|
102 | painter->drawRect(0,0,p_boundingRec.width(),p_boundingRec.height()); | |
|
103 | return QPoint(p_boundingRec.width()+4+p_xMargins,0); | |
|
104 | } | |
|
69 | bitfieldsElement(const QString& value,QFont font,int xMargin,int yMargin); | |
|
70 | QPoint paint(QPainter* painter); | |
|
105 | 71 | |
|
106 | void updateBoundingRect() | |
|
107 | { | |
|
108 | p_boundingRec.setHeight(QFontMetrics(p_font).boundingRect(p_valueStr).height()+(p_yMargins*2)); | |
|
109 | int width = (((4*(QFontMetrics(p_font).width("0") + 2)) + p_xMargins) * 8) + (p_xMargins); | |
|
110 | p_boundingRec.setWidth(width); | |
|
111 | } | |
|
112 | void setValue(const QString& value) | |
|
113 | { | |
|
114 | p_valueStr = value; | |
|
115 | updateBoundingRect(); | |
|
116 | } | |
|
72 | void updateBoundingRect(); | |
|
73 | void setValue(const QString& value); | |
|
74 | void blinkCursor(); | |
|
75 | void moveCursorLeft(int count); | |
|
76 | void moveCursorRight(int count); | |
|
117 | 77 | private: |
|
118 | 78 | int attributesIndex[32]; |
|
79 | uint p_cursorIndex; | |
|
119 | 80 | QList<bitFieldAttribute*> attributesLUT; |
|
120 | 81 | }; |
|
121 | 82 | |
@@ -130,20 +91,26 public: | |||
|
130 | 91 | signals: |
|
131 | 92 | void cursorUp(int pos); |
|
132 | 93 | void cursorDown(int pos); |
|
94 | void valueChanged(qint32 value); | |
|
133 | 95 | |
|
134 | 96 | protected: |
|
135 | 97 | void paintEvent(QPaintEvent* event); |
|
136 | 98 | |
|
137 | 99 | public slots: |
|
138 | 100 | void setValue(qint32 value); |
|
101 | void blinkCursor(); | |
|
102 | void moveCursorLeft(int count); | |
|
103 | void moveCursorRight(int count); | |
|
139 | 104 | |
|
140 | 105 | private: |
|
106 | QTimer* p_timer; | |
|
141 | 107 | void updateBoundingRect(); |
|
142 | 108 | qint32 p_address; |
|
143 | 109 | qint32 p_value; |
|
144 | 110 | QSize p_boundingRect; |
|
145 | 111 | int p_xMargins; |
|
146 | 112 | int p_yMargins; |
|
113 | uint p_cursorIndex; | |
|
147 | 114 | regWidgetElement* p_addressEl,*p_nameEl; |
|
148 | 115 | bitfieldsElement* p_fieldsEl; |
|
149 | 116 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now