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