diff --git a/src/peripheralwidget.cpp b/src/peripheralwidget.cpp --- a/src/peripheralwidget.cpp +++ b/src/peripheralwidget.cpp @@ -53,7 +53,16 @@ void peripheralWidget::mousePressEvent(Q void peripheralWidget::mouseMoveEvent(QMouseEvent *event) { - + bool match=false; + for(int i=0; icontains(event->pos())) + { + match = true; + QToolTip::showText(event->globalPos(),registersWdgts.at(i)->bitFieldDesc(registersWdgts.at(i)->cursorIndex(event->pos().x())),(QWidget*)this); + } + } + if(!match)QToolTip::hideText(); } void peripheralWidget::mouseReleaseEvent(QMouseEvent *event) @@ -80,6 +89,7 @@ void peripheralWidget::keyPressEvent(QKe case Qt::Key_R: qint32 value; value = emit readRegSig(registersWdgts.at(selectedReg)->address()); + registersWdgts.at(selectedReg)->setValue(value); break; default: break; diff --git a/src/peripheralwidget.h b/src/peripheralwidget.h --- a/src/peripheralwidget.h +++ b/src/peripheralwidget.h @@ -7,13 +7,21 @@ #include #include #include "registerwidget.h" - +/* + * TODO ADD an outdated marker + * Show outdated registers with a different color for example +*/ class peripheralWidget : public QWidget { Q_OBJECT public: explicit peripheralWidget(const QString& name,qint32 baseAddress, QWidget *parent = 0); - + registerWidget* registerAt(int index) + { + if(index>=0 && indexp_fieldsEl->setValue(QString("%1").arg((uint)p_value,32,2).replace(" ","0")); - emit this->repaint(); + if(!this->p_fieldsEl->readonly(index)) + { + p_value |= 1<p_fieldsEl->setValue(QString("%1").arg((uint)p_value,32,2).replace(" ","0")); + emit this->repaint(); + } } void registerWidget::updateBoundingRect() @@ -129,11 +132,10 @@ void registerWidget::updateBoundingRect( bitfieldsElement::bitfieldsElement(const QString &value, QFont font, int xMargin, int yMargin) :regWidgetElement(value,font,xMargin,yMargin) { - this->attributesLUT.append(new bitFieldAttribute(true,"desc1")); - this->attributesLUT.append(new bitFieldAttribute(false,"desc2")); + this->attributesLUT.append(new bitFieldAttribute(false,"UNSUSED")); for(int i=0;i<32;i++) { - attributesIndex[i] = i&1; + attributesIndex[i] = 0; } updateBoundingRect(); p_blinkTextBgColor = QColor(Qt::black); @@ -154,7 +156,7 @@ QPoint bitfieldsElement::paint(QPainter { if(p_cursorBlinkEnable == false || (31-p_cursorIndex) != ((i*4)+l)) { - if(attributesLUT[attributesIndex[(i*4)+l]]->rw==false) + if(attributesLUT[attributesIndex[31-((i*4)+l)]]->rw==false) { painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::lightGray); } diff --git a/src/registerwidget.h b/src/registerwidget.h --- a/src/registerwidget.h +++ b/src/registerwidget.h @@ -79,6 +79,25 @@ public: uint cursorIndex(); uint cursorIndex(int xPos); void setFont(QFont font); + int addAttribute(const QString& description,bool rw) + { + attributesLUT.append(new bitFieldAttribute(rw,description)); + return attributesLUT.count()-1; + } + int setAttribute(int bitIndex,int attributeIndex) + { + attributesIndex[bitIndex]=attributeIndex; + } + QString description(int bitIndex) + { + return attributesLUT.at(attributesIndex[bitIndex])->description; + } + bool readonly(int bitIndex) + { + if(bitIndex>=0 && bitIndex<32) + return !attributesLUT.at(attributesIndex[bitIndex])->rw; + return false; + } private: int attributesIndex[32]; uint p_cursorIndex; @@ -103,6 +122,22 @@ public: uint cursorIndex(int xPos); qint32 address(); qint32 value(); + void setBitFieldAttribute(uint startIndex,uint stopIndex,const QString& description,bool rw) + { + if(startIndex<=stopIndex && stopIndex<32) + { + int index= p_fieldsEl->addAttribute(description,rw ); + for(uint i=startIndex;i<=stopIndex;i++) + { + p_fieldsEl->setAttribute(i,index); + } + } + } + QString bitFieldDesc(int bitIndex) + { + return p_fieldsEl->description(bitIndex); + } + signals: void cursorUp(int pos); void cursorDown(int pos); diff --git a/src/socregsviewer.h b/src/socregsviewer.h --- a/src/socregsviewer.h +++ b/src/socregsviewer.h @@ -5,6 +5,8 @@ #include #include "peripheralwidget.h" + + class socRegsViewer : public QScrollArea { Q_OBJECT