##// 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 11 TARGET = PeripheralWidget
12 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\
16 mainwindow.cpp \
17 peripheralwidget.cpp \
18 registerwidget.cpp
21 SOURCES += test/main.cpp \
22 test/mainwindow.cpp \
23 $$PERIPHERAL_WDGT_SOURCES
19 24
20 HEADERS += mainwindow.h \
21 peripheralwidget.h \
22 registerwidget.h
25 HEADERS += test/mainwindow.h \
26 $$PERIPHERAL_WDGT_HEADERS
27
@@ -1,21 +1,18
1 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 4 QWidget(parent)
5 5 {
6 6 p_name = name;
7 7 p_timer = new QTimer(this);
8 8 p_timer->setInterval(500);
9 for(int i=0;i<10;i++)
10 {
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 }
9 p_baseAddress = baseAddress;
10 p_header = p_name + QString(" @0x%1").arg((uint)p_baseAddress,8,16);
15 11 setAttribute(Qt::WA_AlwaysShowToolTips);
16 12 setMouseTracking(true);
17 13 setFocusPolicy(Qt::StrongFocus);
18 14 selectedReg = -1;
15 registersWdgts.clear();
19 16 connect(p_timer,SIGNAL(timeout()),this,SLOT(blinkCursor()));
20 17 setFont(QFont("Utopia", 14,QFont::Bold));
21 18 }
@@ -27,11 +24,21 void peripheralWidget::blinkCursor()
27 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 34 void peripheralWidget::mousePressEvent(QMouseEvent *event)
31 35 {
32 36 p_timer->stop();
33 37 if(selectedReg!=-1)
38 {
34 39 registersWdgts.at(selectedReg)->leave();
40 selectedReg = -1;
41 }
35 42 for(int i=0; i<registersWdgts.count();i++)
36 43 {
37 44 if(registersWdgts.at(i)->contains(event->pos()))
@@ -67,6 +74,13 void peripheralWidget::keyPressEvent(QKe
67 74 case Qt::Key_Down:
68 75 registersWdgts.at(selectedReg)->clear(registersWdgts.at(selectedReg)->cursorIndex());
69 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 84 default:
71 85 break;
72 86 }
@@ -108,17 +122,26 void peripheralWidget::keyPressEvent(QKe
108 122 void peripheralWidget::paintEvent(QPaintEvent *event)
109 123 {
110 124 Q_UNUSED(event)
125
111 126 QPainter painter(this);
112 127 QPoint offset=QPoint(0,0);
113 int nameWidth = fontMetrics().width(p_name);
114 painter.drawText((this->minimumWidth()/2)-nameWidth,4,fontMetrics().width(p_name),fontMetrics().height()+4,Qt::AlignCenter,p_name);
128 int nameWidth = fontMetrics().width(p_header);
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 134 offset+=QPoint(0,fontMetrics().height()+8);
116 135 for(int i=0;i<registersWdgts.count();i++)
117 136 {
118 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 143 updateGeometry();
144
122 145 }
123 146
124 147 void peripheralWidget::up()
@@ -12,12 +12,14 class peripheralWidget : public QWidget
12 12 {
13 13 Q_OBJECT
14 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 17 signals:
18
18 void writeRegSig(qint32 address,qint32 value);
19 qint32 readRegSig(qint32 address);
19 20 public slots:
20 21 void blinkCursor();
22 void addRegister(const QString& name,qint32 address);
21 23 protected:
22 24 void mousePressEvent(QMouseEvent *event);
23 25 void mouseMoveEvent(QMouseEvent *event);
@@ -29,6 +31,8 private:
29 31 void up();
30 32 void down();
31 33 QString p_name;
34 QString p_header;
35 qint32 p_baseAddress;
32 36 QList<registerWidget*> registersWdgts;
33 37 int selectedReg;
34 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 72 void registerWidget::setValue(qint32 value)
63 73 {
64 74 this->p_value = value;
@@ -101,6 +101,8 public:
101 101 QRect boundingRect();
102 102 uint cursorIndex();
103 103 uint cursorIndex(int xPos);
104 qint32 address();
105 qint32 value();
104 106 signals:
105 107 void cursorUp(int pos);
106 108 void cursorDown(int pos);
1 NO CONTENT: file renamed from main.cpp to test/main.cpp
@@ -3,7 +3,11
3 3 MainWindow::MainWindow(QWidget *parent)
4 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 13 MainWindow::~MainWindow()
@@ -11,6 +11,8 class MainWindow : public QMainWindow
11 11 public:
12 12 MainWindow(QWidget *parent = 0);
13 13 ~MainWindow();
14
15 peripheralWidget* testWidget;
14 16 };
15 17
16 18 #endif // MAINWINDOW_H
General Comments 0
You need to be logged in to leave comments. Login now