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