# HG changeset patch # User jeandet # Date 2014-01-05 22:32:18 # Node ID 97731c51318c926513dae80cd2dd485658e84017 # Parent 34a19771729833cda0dbb3e773180989aadfcbbe improved register GUI. added bitfield range selection. diff --git a/src/peripheralwidget.cpp b/src/peripheralwidget.cpp --- a/src/peripheralwidget.cpp +++ b/src/peripheralwidget.cpp @@ -54,15 +54,28 @@ void peripheralWidget::mousePressEvent(Q void peripheralWidget::mouseMoveEvent(QMouseEvent *event) { bool match=false; - for(int i=0; ibuttons()==Qt::LeftButton) { - if(registersWdgts.at(i)->contains(event->pos())) + for(int i=0; iglobalPos(),registersWdgts.at(i)->bitFieldDesc(registersWdgts.at(i)->cursorIndex(event->pos().x())),(QWidget*)this); + if(registersWdgts.at(i)->contains(event->pos())) + { + registersWdgts.at(i)->updateSelection(registersWdgts.at(i)->cursorIndex(event->pos().x())); + } } } - if(!match)QToolTip::hideText(); + else + { + 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) @@ -158,9 +171,9 @@ void peripheralWidget::up() { if(selectedReg!=-1 && selectedReg >0) { + registersWdgts.at(selectedReg-1)->enter(registersWdgts.at(selectedReg)->cursorIndex()); registersWdgts.at(selectedReg)->leave(); selectedReg-=1; - registersWdgts.at(selectedReg)->enter(registersWdgts.at(selectedReg+1)->cursorIndex()); repaint(); } } @@ -169,9 +182,9 @@ void peripheralWidget::down() { if(selectedReg!=-1 && selectedReg <(registersWdgts.count()-1)) { + registersWdgts.at(selectedReg+1)->enter(registersWdgts.at(selectedReg)->cursorIndex()); registersWdgts.at(selectedReg)->leave(); selectedReg+=1; - registersWdgts.at(selectedReg)->enter(registersWdgts.at(selectedReg-1)->cursorIndex()); repaint(); } } diff --git a/src/peripheralwidget.h b/src/peripheralwidget.h --- a/src/peripheralwidget.h +++ b/src/peripheralwidget.h @@ -44,6 +44,7 @@ private: QList registersWdgts; int selectedReg; QTimer* p_timer; + }; #endif // PERIPHERALWIDGET_H diff --git a/src/registerwidget.cpp b/src/registerwidget.cpp --- a/src/registerwidget.cpp +++ b/src/registerwidget.cpp @@ -11,7 +11,7 @@ registerWidget::registerWidget(const QSt p_fieldsEl = new bitfieldsElement(QString("%1").arg((uint)p_value,32,2).replace(" ","0"),QFont("Utopia", 12),4,4); p_nameEl = new regWidgetElement(name,QFont("Utopia", 12,QFont::Bold),4,4); p_xMargins = 4; - p_yMargins = 4; + p_yMargins = 6; updateBoundingRect(); } @@ -57,6 +57,13 @@ uint registerWidget::cursorIndex(int xPo { return p_fieldsEl->cursorIndex(xPos-p_addressEl->boundingRect().width()); } + return 0; +} + +void registerWidget::updateSelection(int index) +{ + p_fieldsEl->updateSelection(index); + emit this->repaint(); } qint32 registerWidget::address() @@ -137,11 +144,14 @@ bitfieldsElement::bitfieldsElement(const { attributesIndex[i] = 0; } - updateBoundingRect(); + p_startSelectionIndex = -1; + p_stopSelectionIndex = -1; + p_cursorIndex = -1; + p_dx=QFontMetrics(p_font).width("0")+4; p_blinkTextBgColor = QColor(Qt::black); p_blinkTextColor = QColor(Qt::white); p_cursorBlinkEnable = false; - p_dx=QFontMetrics(p_font).width("0")+2; + updateBoundingRect(); } QPoint bitfieldsElement::paint(QPainter *painter) @@ -149,6 +159,7 @@ QPoint bitfieldsElement::paint(QPainter painter->fillRect(4,4,p_boundingRec.width(),p_boundingRec.height(),Qt::darkGray); painter->fillRect(0,0,p_boundingRec.width(),p_boundingRec.height(),Qt::white); painter->setFont(p_font); + int lastAttributeIndex = attributesIndex[31]; int xpos=p_xMargins; for(int i=0;i<(32/4);i++) { @@ -156,15 +167,26 @@ QPoint bitfieldsElement::paint(QPainter { if(p_cursorBlinkEnable == false || (31-p_cursorIndex) != ((i*4)+l)) { - if(attributesLUT[attributesIndex[31-((i*4)+l)]]->rw==false) + if(p_startSelectionIndex!=-1 && p_stopSelectionIndex!=-1 && p_startSelectionIndex <=31-((i*4)+l) && p_stopSelectionIndex >=31-((i*4)+l)) { - painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::lightGray); + QPen svg = painter->pen(); + painter->setPen(p_blinkTextColor); + painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::blue); + painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); + painter->setPen(svg); } else { - painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::white); + if(attributesLUT[attributesIndex[31-((i*4)+l)]]->rw==false) + { + painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::lightGray); + } + else + { + painter->fillRect(xpos-1,0,p_dx,p_boundingRec.height(),Qt::white); + } + painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); } - painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); } else { @@ -174,12 +196,15 @@ QPoint bitfieldsElement::paint(QPainter painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); painter->setPen(svg); } + if(lastAttributeIndex!=attributesIndex[31-((i*4)+l)]) + painter->drawLine(xpos-(p_xMargins/2),0,xpos-(p_xMargins/2),p_boundingRec.height()); + lastAttributeIndex=attributesIndex[31-((i*4)+l)]; xpos+=p_dx; } if(i==3) - painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+6); + painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+12); else if(i<7) - painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-2,xpos+(p_xMargins/2),p_boundingRec.height()+2); + painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+6); xpos+=p_xMargins; } painter->drawRect(0,0,p_boundingRec.width(),p_boundingRec.height()); @@ -189,7 +214,7 @@ QPoint bitfieldsElement::paint(QPainter void bitfieldsElement::updateBoundingRect() { p_boundingRec.setHeight(QFontMetrics(p_font).boundingRect(p_valueStr).height()+(p_yMargins*2)); - int width = (((4*(QFontMetrics(p_font).width("0") + 2)) + p_xMargins) * 8) + (p_xMargins); + int width = (((4*(p_dx)) + p_xMargins) * 8) + (p_xMargins); p_boundingRec.setWidth(width); } @@ -211,6 +236,8 @@ void bitfieldsElement::moveCursorLeft(in { p_cursorIndex = 31; } + p_startSelectionIndex = p_cursorIndex; + p_stopSelectionIndex = p_cursorIndex; } @@ -221,17 +248,24 @@ void bitfieldsElement::moveCursorRight(i { p_cursorIndex = 0; } + p_startSelectionIndex = p_cursorIndex; + p_stopSelectionIndex = p_cursorIndex; } void bitfieldsElement::enter(int index) { p_cursorIndex = index; p_cursorBlinkEnable = true; + p_startSelectionIndex = -1; + p_stopSelectionIndex = -1; } void bitfieldsElement::leave() { p_cursorBlinkEnable = false; + p_cursorIndex = -1; + p_startSelectionIndex = -1; + p_stopSelectionIndex = -1; } uint bitfieldsElement::cursorIndex() @@ -256,3 +290,48 @@ void bitfieldsElement::setFont(QFont fon p_dx=QFontMetrics(p_font).width("0")+2; updateBoundingRect(); } + +void bitfieldsElement::updateSelection(int index) +{ + if(p_cursorIndex!=-1) + { + if(p_startSelectionIndex!=-1 && p_stopSelectionIndex!= -1) + { + if(index>=p_stopSelectionIndex) + { + p_stopSelectionIndex = index; + p_cursorIndex = index; + } + else + { + p_startSelectionIndex = index; + p_cursorIndex = index; + } + } + else + { + if(index>p_cursorIndex) + { + p_startSelectionIndex = p_cursorIndex; + p_stopSelectionIndex = index; + } + else + { + p_startSelectionIndex = index; + p_stopSelectionIndex = p_cursorIndex; + } + } + } +} + + + + + + + + + + + + diff --git a/src/registerwidget.h b/src/registerwidget.h --- a/src/registerwidget.h +++ b/src/registerwidget.h @@ -79,6 +79,8 @@ public: uint cursorIndex(); uint cursorIndex(int xPos); void setFont(QFont font); + + void updateSelection(int index); int addAttribute(const QString& description,bool rw) { attributesLUT.append(new bitFieldAttribute(rw,description)); @@ -101,6 +103,8 @@ public: private: int attributesIndex[32]; uint p_cursorIndex; + uint p_startSelectionIndex; + uint p_stopSelectionIndex; bool p_cursorBlinkEnable; int p_dx; QList attributesLUT; @@ -120,6 +124,7 @@ public: QRect boundingRect(); uint cursorIndex(); uint cursorIndex(int xPos); + void updateSelection(int index); qint32 address(); qint32 value(); void setBitFieldAttribute(uint startIndex,uint stopIndex,const QString& description,bool rw)