# HG changeset patch # User Jeandet Alexis # Date 2013-12-31 19:35:13 # Node ID 321fbc64206b47036ca2e54c813aa53548322939 # Parent 50dc053261883e1d3882da7dc1f5663d6a2f3b6a sync diff --git a/registerwidget.cpp b/registerwidget.cpp --- a/registerwidget.cpp +++ b/registerwidget.cpp @@ -12,7 +12,11 @@ registerWidget::registerWidget(const QSt p_nameEl = new regWidgetElement(name,QFont("Utopia", 12,QFont::Bold),4,4); p_xMargins = 4; p_yMargins = 4; + this->p_timer = new QTimer(this); + this->p_timer->setInterval(1000); + this->p_cursorIndex = 0; updateBoundingRect(); + connect(p_timer,SIGNAL(timeout()),this,SLOT(blinkCursor())); } registerWidget::~registerWidget() @@ -40,9 +44,101 @@ void registerWidget::setValue(qint32 val this->repaint(); } +void registerWidget::blinkCursor() +{ + p_fieldsEl->blinkCursor(); +} + +void registerWidget::moveCursorLeft(int count) +{ + p_fieldsEl->moveCursorLeft(count); +} + +void registerWidget::moveCursorRight(int count) +{ + p_fieldsEl->moveCursorRight(count); +} + void registerWidget::updateBoundingRect() { p_boundingRect.setHeight(p_fieldsEl->boundingRect().height()+(p_yMargins*2)); p_boundingRect.setWidth(p_fieldsEl->boundingRect().width()+p_addressEl->boundingRect().width()+p_nameEl->boundingRect().width()+(p_xMargins*2)); } + + +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")); + for(int i=0;i<32;i++) + { + attributesIndex[i] = i&1; + } + updateBoundingRect(); +} + +QPoint bitfieldsElement::paint(QPainter *painter) +{ + 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 xpos=p_xMargins,dx=QFontMetrics(p_font).width("0")+2; + for(int i=0;i<(32/4);i++) + { + for(int l = 0;l<4;l++) + { + if(attributesLUT[attributesIndex[(i*4)+l]]->rw==false) + painter->fillRect(xpos-1,0,dx,p_boundingRec.height(),Qt::lightGray); + else + painter->fillRect(xpos-1,0,dx,p_boundingRec.height(),Qt::white); + painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); + xpos+=dx; + } + if(i==3) + painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+6); + else if(i<7) + painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-2,xpos+(p_xMargins/2),p_boundingRec.height()+2); + xpos+=p_xMargins; + } + painter->drawRect(0,0,p_boundingRec.width(),p_boundingRec.height()); + return QPoint(p_boundingRec.width()+4+p_xMargins,0); +} + +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); + p_boundingRec.setWidth(width); +} + +void bitfieldsElement::setValue(const QString &value) +{ + p_valueStr = value; + updateBoundingRect(); +} + +void bitfieldsElement::blinkCursor() +{ + +} + +void bitfieldsElement::moveCursorLeft(int count) +{ + p_cursorIndex+=count; + if(31 #include +#include class regWidgetElement { @@ -65,57 +66,17 @@ class bitfieldsElement: public regWidget QString description; }; public: - 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")); - for(int i=0;i<32;i++) - { - attributesIndex[i] = i&1; - } - updateBoundingRect(); - } - QPoint paint(QPainter* painter) - { - 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 xpos=p_xMargins,dx=QFontMetrics(p_font).width("0")+2; - for(int i=0;i<(32/4);i++) - { - for(int l = 0;l<4;l++) - { - if(attributesLUT[attributesIndex[(i*4)+l]]->rw==false) - painter->fillRect(xpos-1,0,dx,p_boundingRec.height(),Qt::lightGray); - else - painter->fillRect(xpos-1,0,dx,p_boundingRec.height(),Qt::white); - painter->drawText(xpos,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr.at((i*4)+l)); - xpos+=dx; - } - if(i==3) - painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-6,xpos+(p_xMargins/2),p_boundingRec.height()+6); - else if(i<7) - painter->drawLine(xpos+(p_xMargins/2),p_boundingRec.height()-2,xpos+(p_xMargins/2),p_boundingRec.height()+2); - xpos+=p_xMargins; - } - painter->drawRect(0,0,p_boundingRec.width(),p_boundingRec.height()); - return QPoint(p_boundingRec.width()+4+p_xMargins,0); - } + bitfieldsElement(const QString& value,QFont font,int xMargin,int yMargin); + QPoint paint(QPainter* painter); - void 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); - p_boundingRec.setWidth(width); - } - void setValue(const QString& value) - { - p_valueStr = value; - updateBoundingRect(); - } + void updateBoundingRect(); + void setValue(const QString& value); + void blinkCursor(); + void moveCursorLeft(int count); + void moveCursorRight(int count); private: int attributesIndex[32]; + uint p_cursorIndex; QList attributesLUT; }; @@ -130,20 +91,26 @@ public: signals: void cursorUp(int pos); void cursorDown(int pos); + void valueChanged(qint32 value); protected: void paintEvent(QPaintEvent* event); public slots: void setValue(qint32 value); + void blinkCursor(); + void moveCursorLeft(int count); + void moveCursorRight(int count); private: + QTimer* p_timer; void updateBoundingRect(); qint32 p_address; qint32 p_value; QSize p_boundingRect; int p_xMargins; int p_yMargins; + uint p_cursorIndex; regWidgetElement* p_addressEl,*p_nameEl; bitfieldsElement* p_fieldsEl; };