##// END OF EJS Templates
Sync
Jeandet Alexis -
r2:50dc05326188 default
parent child
Show More
@@ -1,14 +1,14
1 #include "peripheralwidget.h"
1 #include "peripheralwidget.h"
2
2
3 peripheralWidget::peripheralWidget(const QString &name, QWidget *parent) :
3 peripheralWidget::peripheralWidget(const QString &name, QWidget *parent) :
4 QGroupBox(name,parent)
4 QGroupBox(name,parent)
5 {
5 {
6 mainLayout = new QVBoxLayout(this);
6 mainLayout = new QVBoxLayout(this);
7 for(int i=0;i<10;i++)
7 for(int i=0;i<10;i++)
8 {
8 {
9 registersWdgts.append(new registerWidget(QString("REG%1").arg(i),i*8));
9 registersWdgts.append(new registerWidget(QString("REG%1").arg(i),i*8));
10 registersWdgts.at(i)->setValue(-1);
10 registersWdgts.at(i)->setValue((i<<24)+(i<<8)+i);
11 mainLayout->addWidget(registersWdgts.at(i));
11 mainLayout->addWidget(registersWdgts.at(i));
12 }
12 }
13 setLayout(mainLayout);
13 setLayout(mainLayout);
14 }
14 }
@@ -1,137 +1,151
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
5
6 class regWidgetElement
6 class regWidgetElement
7 {
7 {
8 public:
8 public:
9 regWidgetElement(const QString& value,QFont font,int xMargin,int yMargin)
9 regWidgetElement(const QString& value,QFont font,int xMargin,int yMargin)
10 {
10 {
11 p_valueStr = value;
11 p_valueStr = value;
12 p_font = font;
12 p_font = font;
13 p_xMargins = xMargin;
13 p_xMargins = xMargin;
14 p_yMargins = yMargin;
14 p_yMargins = yMargin;
15 updateBoundingRect();
15 updateBoundingRect();
16 }
16 }
17 void setValue(const QString& value)
17 void setValue(const QString& value)
18 {
18 {
19 p_valueStr = value;
19 p_valueStr = value;
20 updateBoundingRect();
20 updateBoundingRect();
21 }
21 }
22 void setFont(QFont font)
22 void setFont(QFont font)
23 {
23 {
24 p_font = font;
24 p_font = font;
25 updateBoundingRect();
25 updateBoundingRect();
26 }
26 }
27 QSize boundingRect(){return p_boundingRec;}
27 QSize boundingRect(){return p_boundingRec;}
28 QString value(){return p_valueStr;}
28 QString value(){return p_valueStr;}
29 const QChar at ( int position ) const{return p_valueStr.at(position);}
29 const QChar at ( int position ) const{return p_valueStr.at(position);}
30 QFont font(){return p_font;}
30 QFont font(){return p_font;}
31 int xMargin(){return p_xMargins;}
31 int xMargin(){return p_xMargins;}
32 int yMargin(){return p_yMargins;}
32 int yMargin(){return p_yMargins;}
33 QFontMetrics fontMetrics(){return QFontMetrics(p_font);}
33 QFontMetrics fontMetrics(){return QFontMetrics(p_font);}
34 QPoint paint(QPainter* painter)
34 QPoint paint(QPainter* painter)
35 {
35 {
36 painter->setFont(p_font);
36 painter->setFont(p_font);
37 painter->drawText(0,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr);
37 painter->drawText(0,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr);
38 return QPoint(p_boundingRec.width(),0);
38 return QPoint(p_boundingRec.width(),0);
39 }
39 }
40 void updateBoundingRect()
40 void updateBoundingRect()
41 {
41 {
42 p_boundingRec.setHeight(QFontMetrics(p_font).boundingRect(p_valueStr).height()+(p_yMargins*2));
42 p_boundingRec.setHeight(QFontMetrics(p_font).boundingRect(p_valueStr).height()+(p_yMargins*2));
43 p_boundingRec.setWidth(QFontMetrics(p_font).boundingRect(p_valueStr).width()+(p_xMargins*2));
43 p_boundingRec.setWidth(QFontMetrics(p_font).boundingRect(p_valueStr).width()+(p_xMargins*2));
44 }
44 }
45
45
46 protected:
46 protected:
47 QString p_valueStr;
47 QString p_valueStr;
48 QFont p_font;
48 QFont p_font;
49 QSize p_boundingRec;
49 QSize p_boundingRec;
50 int p_xMargins;
50 int p_xMargins;
51 int p_yMargins;
51 int p_yMargins;
52 };
52 };
53
53
54 class bitfieldsElement: public regWidgetElement
54 class bitfieldsElement: public regWidgetElement
55 {
55 {
56 struct bitAttribute
56 class bitFieldAttribute
57 {
57 {
58 public:
59 bitFieldAttribute(bool rw,QString description)
60 {
61 this->rw = rw;
62 this->description = description;
63 }
58 bool rw;
64 bool rw;
59 int descIndex;
65 QString description;
60 };
66 };
61 public:
67 public:
62 bitfieldsElement(const QString& value,QFont font,int xMargin,int yMargin)
68 bitfieldsElement(const QString& value,QFont font,int xMargin,int yMargin)
63 :regWidgetElement(value,font,xMargin,yMargin)
69 :regWidgetElement(value,font,xMargin,yMargin)
64 {
70 {
71 this->attributesLUT.append(new bitFieldAttribute(true,"desc1"));
72 this->attributesLUT.append(new bitFieldAttribute(false,"desc2"));
65 for(int i=0;i<32;i++)
73 for(int i=0;i<32;i++)
66 {
74 {
67 attributes[i].rw = false;
75 attributesIndex[i] = i&1;
68 }
76 }
69 updateBoundingRect();
77 updateBoundingRect();
70 }
78 }
71 QPoint paint(QPainter* painter)
79 QPoint paint(QPainter* painter)
72 {
80 {
73 painter->fillRect(4,4,p_boundingRec.width(),p_boundingRec.height(),Qt::darkGray);
81 painter->fillRect(4,4,p_boundingRec.width(),p_boundingRec.height(),Qt::darkGray);
74 painter->fillRect(0,0,p_boundingRec.width(),p_boundingRec.height(),Qt::white);
82 painter->fillRect(0,0,p_boundingRec.width(),p_boundingRec.height(),Qt::white);
75 painter->setFont(p_font);
83 painter->setFont(p_font);
76 int xpos=p_xMargins,dx=QFontMetrics(p_font).width("0")+2;
84 int xpos=p_xMargins,dx=QFontMetrics(p_font).width("0")+2;
77 for(int i=0;i<(32/4);i++)
85 for(int i=0;i<(32/4);i++)
78 {
86 {
79 for(int l = 0;l<4;l++)
87 for(int l = 0;l<4;l++)
80 {
88 {
81 if(attributes[(i*4)+l].rw==false)
89 if(attributesLUT[attributesIndex[(i*4)+l]]->rw==false)
82 painter->fillRect(xpos-1,0,dx,p_boundingRec.height(),Qt::lightGray);
90 painter->fillRect(xpos-1,0,dx,p_boundingRec.height(),Qt::lightGray);
83 else
91 else
84 painter->fillRect(xpos-1,0,dx,p_boundingRec.height(),Qt::white);
92 painter->fillRect(xpos-1,0,dx,p_boundingRec.height(),Qt::white);
85 painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l));
93 painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l));
86 xpos+=dx;
94 xpos+=dx;
87 }
95 }
88 if(i==3)
96 if(i==3)
89 painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+6);
97 painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+6);
90 else if(i<7)
98 else if(i<7)
91 painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-2,xpos+(p_xMargins/2),p_boundingRec.height()+2);
99 painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-2,xpos+(p_xMargins/2),p_boundingRec.height()+2);
92 xpos+=p_xMargins;
100 xpos+=p_xMargins;
93 }
101 }
94 painter->drawRect(0,0,p_boundingRec.width(),p_boundingRec.height());
102 painter->drawRect(0,0,p_boundingRec.width(),p_boundingRec.height());
95 return QPoint(p_boundingRec.width()+4+p_xMargins,0);
103 return QPoint(p_boundingRec.width()+4+p_xMargins,0);
96 }
104 }
97
105
98 void updateBoundingRect()
106 void updateBoundingRect()
99 {
107 {
100 p_boundingRec.setHeight(QFontMetrics(p_font).boundingRect(p_valueStr).height()+(p_yMargins*2));
108 p_boundingRec.setHeight(QFontMetrics(p_font).boundingRect(p_valueStr).height()+(p_yMargins*2));
101 int width = (((4*(QFontMetrics(p_font).width("0") + 2)) + p_xMargins) * 8) + (p_xMargins);
109 int width = (((4*(QFontMetrics(p_font).width("0") + 2)) + p_xMargins) * 8) + (p_xMargins);
102 p_boundingRec.setWidth(width);
110 p_boundingRec.setWidth(width);
103 }
111 }
112 void setValue(const QString& value)
113 {
114 p_valueStr = value;
115 updateBoundingRect();
116 }
104 private:
117 private:
105 struct bitAttribute attributes[32];
118 int attributesIndex[32];
119 QList<bitFieldAttribute*> attributesLUT;
106 };
120 };
107
121
108
122
109 class registerWidget : public QWidget
123 class registerWidget : public QWidget
110 {
124 {
111 Q_OBJECT
125 Q_OBJECT
112 public:
126 public:
113 explicit registerWidget(const QString& name,qint32 address,QWidget *parent = 0);
127 explicit registerWidget(const QString& name,qint32 address,QWidget *parent = 0);
114 ~registerWidget();
128 ~registerWidget();
115
129
116 signals:
130 signals:
117 void cursorUp(int pos);
131 void cursorUp(int pos);
118 void cursorDown(int pos);
132 void cursorDown(int pos);
119
133
120 protected:
134 protected:
121 void paintEvent(QPaintEvent* event);
135 void paintEvent(QPaintEvent* event);
122
136
123 public slots:
137 public slots:
124 void setValue(qint32 value);
138 void setValue(qint32 value);
125
139
126 private:
140 private:
127 void updateBoundingRect();
141 void updateBoundingRect();
128 qint32 p_address;
142 qint32 p_address;
129 qint32 p_value;
143 qint32 p_value;
130 QSize p_boundingRect;
144 QSize p_boundingRect;
131 int p_xMargins;
145 int p_xMargins;
132 int p_yMargins;
146 int p_yMargins;
133 regWidgetElement* p_addressEl,*p_nameEl;
147 regWidgetElement* p_addressEl,*p_nameEl;
134 bitfieldsElement* p_fieldsEl;
148 bitfieldsElement* p_fieldsEl;
135 };
149 };
136
150
137 #endif // REGISTERWIDGET_H
151 #endif // REGISTERWIDGET_H
General Comments 0
You need to be logged in to leave comments. Login now