# HG changeset patch # User Jeandet Alexis # Date 2014-01-08 21:16:24 # Node ID 93fabd3c8cadef8de9f56707ff253ec9f80cef42 # Parent 8481400aecb7016f59a5049b4552a543a4bce43c Improved bitfield tooltip, improved register navigation with keyboard. diff --git a/src/peripheralwidget.cpp b/src/peripheralwidget.cpp --- a/src/peripheralwidget.cpp +++ b/src/peripheralwidget.cpp @@ -31,6 +31,36 @@ void peripheralWidget::addRegister(const connect(registersWdgts.last(),SIGNAL(repaint()),this,SLOT(repaint())); } +void peripheralWidget::leave() +{ + if(selectedReg!=-1) + { + p_timer->stop(); + registersWdgts.at(selectedReg)->leave(); + selectedReg = -1; + repaint(); + } +} + +void peripheralWidget::enter(int cursorIndex, bool fromTop) +{ + if(cursorIndex>=0 && cursorIndex<32) + { + if(fromTop) + { + registersWdgts.at(0)->enter(cursorIndex); + selectedReg = 0; + } + else + { + registersWdgts.at(registersWdgts.count()-1)->enter(cursorIndex); + selectedReg = registersWdgts.count()-1; + } + p_timer->start(); + this->setFocus(); + } +} + void peripheralWidget::mousePressEvent(QMouseEvent *event) { p_timer->stop(); @@ -46,6 +76,7 @@ void peripheralWidget::mousePressEvent(Q registersWdgts.at(i)->enter(registersWdgts.at(i)->cursorIndex(event->pos().x())); selectedReg = i; p_timer->start(); + emit clicked(this); } } repaint(); @@ -71,7 +102,13 @@ void peripheralWidget::mouseMoveEvent(QM if(registersWdgts.at(i)->contains(event->pos())) { match = true; - QToolTip::showText(event->globalPos(),registersWdgts.at(i)->bitFieldDesc(registersWdgts.at(i)->cursorIndex(event->pos().x())),(QWidget*)this); + int bitfieldIndex=registersWdgts.at(i)->cursorIndex(event->pos().x()); + + QString toolTipText ="< font color='Black'>"+registersWdgts.at(i)->bitFieldName(bitfieldIndex) +"
"; + toolTipText+= "Hexadecimal=< font color='Blue'>"+registersWdgts.at(i)->bitFieldToHex(bitfieldIndex)+""; + toolTipText+= " Decimal=< font color='BlueViolet'>"+registersWdgts.at(i)->bitFieldToDec(bitfieldIndex)+"
"; + toolTipText+= registersWdgts.at(i)->bitFieldDesc(bitfieldIndex); + QToolTip::showText(event->globalPos(),toolTipText,(QWidget*)this); } } if(!match)QToolTip::hideText(); @@ -169,22 +206,36 @@ void peripheralWidget::paintEvent(QPaint void peripheralWidget::up() { - if(selectedReg!=-1 && selectedReg >0) + if(selectedReg!=-1) { - registersWdgts.at(selectedReg-1)->enter(registersWdgts.at(selectedReg)->cursorIndex()); - registersWdgts.at(selectedReg)->leave(); - selectedReg-=1; - repaint(); + if(selectedReg >0) + { + registersWdgts.at(selectedReg-1)->enter(registersWdgts.at(selectedReg)->cursorIndex()); + registersWdgts.at(selectedReg)->leave(); + selectedReg-=1; + repaint(); + } + else + { + emit upSig(this,registersWdgts.at(selectedReg)->cursorIndex()); + } } } void peripheralWidget::down() { - if(selectedReg!=-1 && selectedReg <(registersWdgts.count()-1)) + if(selectedReg!=-1) { - registersWdgts.at(selectedReg+1)->enter(registersWdgts.at(selectedReg)->cursorIndex()); - registersWdgts.at(selectedReg)->leave(); - selectedReg+=1; - repaint(); + if(selectedReg <(registersWdgts.count()-1)) + { + registersWdgts.at(selectedReg+1)->enter(registersWdgts.at(selectedReg)->cursorIndex()); + registersWdgts.at(selectedReg)->leave(); + selectedReg+=1; + repaint(); + } + else + { + emit downSig(this,registersWdgts.at(selectedReg)->cursorIndex()); + } } } diff --git a/src/peripheralwidget.h b/src/peripheralwidget.h --- a/src/peripheralwidget.h +++ b/src/peripheralwidget.h @@ -31,9 +31,14 @@ public: signals: void writeRegSig(qint32 address,qint32 value); qint32 readRegSig(qint32 address); + void clicked(peripheralWidget* sender); + void upSig(peripheralWidget* sender,int cursorIndex); + void downSig(peripheralWidget* sender,int cursorIndex); public slots: void blinkCursor(); void addRegister(const QString& name,qint32 address); + void leave(); + void enter(int cursorIndex,bool fromTop=true); protected: void mousePressEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); diff --git a/src/registerwidget.cpp b/src/registerwidget.cpp --- a/src/registerwidget.cpp +++ b/src/registerwidget.cpp @@ -76,6 +76,59 @@ qint32 registerWidget::value() return p_value; } +void registerWidget::setBitFieldAttribute(uint startIndex, uint stopIndex, const QString &name, const QString &description, bool rw) +{ + if(startIndex<=stopIndex && stopIndex<32) + { + int index= p_fieldsEl->addAttribute(name,description,rw ); + for(uint i=startIndex;i<=stopIndex;i++) + { + p_fieldsEl->setAttribute(i,index); + } + } +} + +QString registerWidget::bitFieldDesc(int bitIndex) +{ + if(bitIndex>=0 && bitIndex<32) + { + return p_fieldsEl->description(bitIndex); + } + return QString("Out of range"); +} + +QString registerWidget::bitFieldName(int bitIndex) +{ + if(bitIndex>=0 && bitIndex<32) + { + return p_fieldsEl->name(bitIndex); + } + return QString("Out of range"); +} + +QString registerWidget::bitFieldToHex(int bitIndex) +{ + if(bitIndex>=0 && bitIndex<32) + { + return p_fieldsEl->valueHex(bitIndex); + } + return QString("Out of range"); +} + +QString registerWidget::bitFieldToDec(int bitIndex) +{ + if(bitIndex>=0 && bitIndex<32) + { + return p_fieldsEl->valueDec(bitIndex); + } + return QString("Out of range"); +} + +QString registerWidget::bitFieldToBin(int bitIndex) +{ + +} + void registerWidget::setValue(qint32 value) { this->p_value = value; @@ -139,7 +192,7 @@ void registerWidget::updateBoundingRect( bitfieldsElement::bitfieldsElement(const QString &value, QFont font, int xMargin, int yMargin) :regWidgetElement(value,font,xMargin,yMargin) { - this->attributesLUT.append(new bitFieldAttribute(false,"UNSUSED")); + this->attributesLUT.append(new bitFieldAttribute(false,"UNSUSED","UNSUSED")); for(int i=0;i<32;i++) { attributesIndex[i] = 0; diff --git a/src/registerwidget.h b/src/registerwidget.h --- a/src/registerwidget.h +++ b/src/registerwidget.h @@ -57,13 +57,15 @@ class bitfieldsElement: public regWidget class bitFieldAttribute { public: - bitFieldAttribute(bool rw,QString description) + bitFieldAttribute(bool rw,QString name,QString description) { this->rw = rw; + this->Name = name; this->description = description; } bool rw; QString description; + QString Name; }; public: bitfieldsElement(const QString& value,QFont font,int xMargin,int yMargin); @@ -79,20 +81,34 @@ public: uint cursorIndex(); uint cursorIndex(int xPos); void setFont(QFont font); - void updateSelection(int index); - int addAttribute(const QString& description,bool rw) + int addAttribute(const QString& name,const QString& description,bool rw) { - attributesLUT.append(new bitFieldAttribute(rw,description)); + attributesLUT.append(new bitFieldAttribute(rw,name,description)); return attributesLUT.count()-1; } + int setAttribute(int bitIndex,int attributeIndex) { - attributesIndex[bitIndex]=attributeIndex; + if(bitIndex>=0 && bitIndex<32 && attributeIndex>=0 && attributeIndex<(attributesLUT.count())) + { + attributesIndex[bitIndex]=attributeIndex; + return 0; + } + return -1; } + QString description(int bitIndex) { - return attributesLUT.at(attributesIndex[bitIndex])->description; + if(bitIndex>=0 && bitIndex<32) + return attributesLUT.at(attributesIndex[bitIndex])->description; + return QString(""); + } + QString name(int bitIndex) + { + if(bitIndex>=0 && bitIndex<32) + return attributesLUT.at(attributesIndex[bitIndex])->Name; + return QString(""); } bool readonly(int bitIndex) { @@ -100,7 +116,50 @@ public: return !attributesLUT.at(attributesIndex[bitIndex])->rw; return false; } + QString valueHex(int index) + { + if(index>=0 && index<32) + { + return "0x" + QString::number(p_valueUint(index),16); + } + return QString(""); + } + QString valueDec(int index) + { + if(index>=0 && index<32) + { + return QString::number(p_valueUint(index),10); + } + return QString(""); + } private: + uint p_valueUint(int index) + { + uint value; + int attributeIndex = attributesIndex[index]; + int startIndex = index; + int stopIndex=0; + while (startIndex>0) + { + if(attributesIndex[startIndex-1]==attributeIndex) + startIndex--; + else + break; + } + stopIndex = startIndex; + while (stopIndex<32) + { + if(attributesIndex[stopIndex+1]==attributeIndex) + stopIndex++; + else + break; + } + bool ok; + value = p_valueStr.toUInt(&ok,2); + value = (uint)0xFFFFFFFF & (value<<(31-stopIndex)); + value = (uint)0xFFFFFFFF & (value>>(31-stopIndex+startIndex)); + return value; + } int attributesIndex[32]; uint p_cursorIndex; uint p_startSelectionIndex; @@ -127,22 +186,12 @@ public: void updateSelection(int index); 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); - } - + void setBitFieldAttribute(uint startIndex,uint stopIndex,const QString& name,const QString& description,bool rw); + QString bitFieldDesc(int bitIndex); + QString bitFieldName(int bitIndex); + QString bitFieldToHex(int bitIndex); + QString bitFieldToDec(int bitIndex); + QString bitFieldToBin(int bitIndex); signals: void cursorUp(int pos); void cursorDown(int pos); diff --git a/src/socregsviewer.cpp b/src/socregsviewer.cpp --- a/src/socregsviewer.cpp +++ b/src/socregsviewer.cpp @@ -29,5 +29,54 @@ void socRegsViewer::addPeripheral(periph { p_peripherals.append(peripheral); p_scrollAreaWdgtLayout->addWidget(peripheral,p_peripherals.count(),0,1,-1); + connect(peripheral,SIGNAL(clicked(peripheralWidget*)),this,SLOT(periphClicked(peripheralWidget*))); + connect(peripheral,SIGNAL(upSig(peripheralWidget*,int)),this,SLOT(periphUp(peripheralWidget*,int))); + connect(peripheral,SIGNAL(downSig(peripheralWidget*,int)),this,SLOT(periphDown(peripheralWidget*,int))); + } +} + +void socRegsViewer::periphClicked(peripheralWidget *sender) +{ + peripheralWidget * item; + if(sender!=NULL) + { + for(int i=0;ileave(); + } + } } } + +void socRegsViewer::periphUp(peripheralWidget *sender, int cursorIndex) +{ + int index; + if(sender!=NULL) + { + index = p_peripherals.indexOf(sender); + if(index!=-1 && index!=0) + { + p_peripherals.at(index)->leave(); + p_peripherals.at(index-1)->enter(cursorIndex,false); + ensureWidgetVisible(p_peripherals.at(index-1)); + } + } +} + +void socRegsViewer::periphDown(peripheralWidget *sender, int cursorIndex) +{ + int index; + if(sender!=NULL) + { + index = p_peripherals.indexOf(sender); + if(index!=-1 && index<(p_peripherals.count()-1)) + { + p_peripherals.at(index)->leave(); + p_peripherals.at(index+1)->enter(cursorIndex); + ensureWidgetVisible(p_peripherals.at(index+1)); + } + } +} diff --git a/src/socregsviewer.h b/src/socregsviewer.h --- a/src/socregsviewer.h +++ b/src/socregsviewer.h @@ -22,7 +22,9 @@ signals: public slots: void addPeripheral(peripheralWidget* peripheral); - + void periphClicked(peripheralWidget* sender); + void periphUp(peripheralWidget* sender,int cursorIndex); + void periphDown(peripheralWidget* sender,int cursorIndex); private: QWidget* p_scrollAreaWdgt; QString p_name;