|
|
#ifndef REGISTERWIDGET_H
|
|
|
#define REGISTERWIDGET_H
|
|
|
#include <QtWidgets>
|
|
|
#include <QWidget>
|
|
|
|
|
|
class regWidgetElement
|
|
|
{
|
|
|
public:
|
|
|
regWidgetElement(const QString& value,QFont font,int xMargin,int yMargin)
|
|
|
{
|
|
|
p_valueStr = value;
|
|
|
p_font = font;
|
|
|
p_xMargins = xMargin;
|
|
|
p_yMargins = yMargin;
|
|
|
updateBoundingRect();
|
|
|
}
|
|
|
void setValue(const QString& value)
|
|
|
{
|
|
|
p_valueStr = value;
|
|
|
updateBoundingRect();
|
|
|
}
|
|
|
void setFont(QFont font)
|
|
|
{
|
|
|
p_font = font;
|
|
|
updateBoundingRect();
|
|
|
}
|
|
|
QSize boundingRect(){return p_boundingRec;}
|
|
|
QString value(){return p_valueStr;}
|
|
|
const QChar at ( int position ) const{return p_valueStr.at(position);}
|
|
|
QFont font(){return p_font;}
|
|
|
int xMargin(){return p_xMargins;}
|
|
|
int yMargin(){return p_yMargins;}
|
|
|
QFontMetrics fontMetrics(){return QFontMetrics(p_font);}
|
|
|
QPoint paint(QPainter* painter)
|
|
|
{
|
|
|
painter->setFont(p_font);
|
|
|
painter->drawText(0,QFontMetrics(p_font).ascent()+p_yMargins,p_valueStr);
|
|
|
return QPoint(p_boundingRec.width(),0);
|
|
|
}
|
|
|
void updateBoundingRect()
|
|
|
{
|
|
|
p_boundingRec.setHeight(QFontMetrics(p_font).boundingRect(p_valueStr).height()+(p_yMargins*2));
|
|
|
p_boundingRec.setWidth(QFontMetrics(p_font).boundingRect(p_valueStr).width()+(p_xMargins*2));
|
|
|
}
|
|
|
|
|
|
protected:
|
|
|
QString p_valueStr;
|
|
|
QFont p_font;
|
|
|
QSize p_boundingRec;
|
|
|
int p_xMargins;
|
|
|
int p_yMargins;
|
|
|
};
|
|
|
|
|
|
class bitfieldsElement: public regWidgetElement
|
|
|
{
|
|
|
struct bitAttribute
|
|
|
{
|
|
|
bool rw;
|
|
|
int descIndex;
|
|
|
};
|
|
|
public:
|
|
|
bitfieldsElement(const QString& value,QFont font,int xMargin,int yMargin)
|
|
|
:regWidgetElement(value,font,xMargin,yMargin)
|
|
|
{
|
|
|
for(int i=0;i<32;i++)
|
|
|
{
|
|
|
attributes[i].rw = false;
|
|
|
}
|
|
|
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(attributes[(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 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);
|
|
|
}
|
|
|
private:
|
|
|
struct bitAttribute attributes[32];
|
|
|
};
|
|
|
|
|
|
|
|
|
class registerWidget : public QWidget
|
|
|
{
|
|
|
Q_OBJECT
|
|
|
public:
|
|
|
explicit registerWidget(const QString& name,qint32 address,QWidget *parent = 0);
|
|
|
~registerWidget();
|
|
|
|
|
|
signals:
|
|
|
void cursorUp(int pos);
|
|
|
void cursorDown(int pos);
|
|
|
|
|
|
protected:
|
|
|
void paintEvent(QPaintEvent* event);
|
|
|
|
|
|
public slots:
|
|
|
void setValue(qint32 value);
|
|
|
|
|
|
private:
|
|
|
void updateBoundingRect();
|
|
|
qint32 p_address;
|
|
|
qint32 p_value;
|
|
|
QSize p_boundingRect;
|
|
|
int p_xMargins;
|
|
|
int p_yMargins;
|
|
|
regWidgetElement* p_addressEl,*p_nameEl;
|
|
|
bitfieldsElement* p_fieldsEl;
|
|
|
};
|
|
|
|
|
|
#endif // REGISTERWIDGET_H
|
|
|
|