##// 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
@@ -10,13 +10,18 greaterThan(QT_MAJOR_VERSION, 4): QT +=
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,21 +1,18
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 }
@@ -27,11 +24,21 void peripheralWidget::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()))
@@ -67,6 +74,13 void peripheralWidget::keyPressEvent(QKe
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 }
@@ -108,17 +122,26 void peripheralWidget::keyPressEvent(QKe
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()
@@ -12,12 +12,14 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);
@@ -29,6 +31,8 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;
@@ -59,6 +59,16 uint registerWidget::cursorIndex(int xPo
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;
@@ -101,6 +101,8 public:
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);
1 NO CONTENT: file renamed from main.cpp to test/main.cpp
NO CONTENT: file renamed from main.cpp to test/main.cpp
@@ -3,7 +3,11
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()
@@ -11,6 +11,8 class MainWindow : public QMainWindow
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