Skip to content

Commit

Permalink
feat: add setting for numerical base of addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
hut8 committed May 22, 2023
1 parent 1a6d569 commit ed28c4d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/hobbits-plugins/displays/Hex/hex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Hex::Hex() :
QList<ParameterDelegate::ParameterInfo> infos = {
{"font_size", ParameterDelegate::ParameterType::Integer},
{"column_grouping", ParameterDelegate::ParameterType::Integer},
{"address_display_base", ParameterDelegate::ParameterType::Integer},
{"show_headers", ParameterDelegate::ParameterType::Boolean}
};

Expand Down Expand Up @@ -130,14 +131,16 @@ QSharedPointer<DisplayResult> Hex::renderOverlay(QSize viewportSize, const Param

QSize fontSize = DisplayHelper::textSize(DisplayHelper::monoFont(m_lastParams.value("font_size").toInt()), "0");
int columnGrouping = m_lastParams.value("column_grouping").toInt();
int addressDisplayBase = m_lastParams.value("address_display_base").toInt();

auto overlay = DisplayHelper::drawHeadersFull(
viewportSize,
headerOffset(parameters),
m_handle,
QSizeF(double(fontSize.width()) / 4.0, DisplayHelper::textRowHeight(fontSize.height())),
columnGrouping,
columnGrouping > 1 ? 1 : 0);
columnGrouping > 1 ? 1 : 0,
addressDisplayBase);

return DisplayResult::result(overlay, parameters);
}
Expand Down
2 changes: 2 additions & 0 deletions src/hobbits-plugins/displays/Hex/hexform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ HexForm::HexForm(QSharedPointer<ParameterDelegate> delegate):
ui->setupUi(this);

connect(ui->sb_columnGrouping, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
connect(ui->sb_addressDisplayBase, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
connect(ui->hs_fontSize, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
connect(ui->cb_showHeaders, SIGNAL(stateChanged(int)), this, SIGNAL(changed()));

m_paramHelper->addSliderIntParameter("font_size", ui->hs_fontSize);
m_paramHelper->addCheckBoxBoolParameter("show_headers", ui->cb_showHeaders);
m_paramHelper->addSpinBoxIntParameter("column_grouping", ui->sb_columnGrouping);
m_paramHelper->addSpinBoxIntParameter("address_display_base", ui->sb_addressDisplayBase);
}

HexForm::~HexForm()
Expand Down
20 changes: 13 additions & 7 deletions src/hobbits-widgets/displayhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ QImage DisplayHelper::drawHeadersFull(QSize viewportSize,
QSharedPointer<DisplayHandle> handle,
QSizeF bitSize,
int columnGrouping,
int groupMargin)
int groupMargin,
int addressDisplayBase)
{
if (offset.x() == 0 && offset.y() == 0) {
return QImage();
Expand All @@ -315,15 +316,20 @@ QImage DisplayHelper::drawHeadersFull(QSize viewportSize,
DisplayHelper::drawFramesHeader(&painter,
QSize(offset.x(), viewportSize.height() - offset.y()),
handle,
bitSize.height());
bitSize.height(),
Qt::Vertical,
1,
0,
addressDisplayBase);

DisplayHelper::drawFramesHeader(&painter,
QSize(viewportSize.width() - offset.x(), offset.y()),
handle,
bitSize.width(),
Qt::Horizontal,
columnGrouping,
groupMargin);
groupMargin,
addressDisplayBase);

return headers;
}
Expand All @@ -334,7 +340,8 @@ void DisplayHelper::drawFramesHeader(QPainter *painter,
double frameHeight,
int orientation,
int grouping,
int groupMargin)
int groupMargin,
int addressDisplayBase)
{
painter->save();

Expand Down Expand Up @@ -395,7 +402,7 @@ void DisplayHelper::drawFramesHeader(QPainter *painter,
textSize,
fontSize.height(),
textAlign,
QString("%1").arg(i + offset));
QString("%1").arg(i + offset, 0, addressDisplayBase));
}

if (highlightOffset >= 0) {
Expand Down Expand Up @@ -429,7 +436,7 @@ void DisplayHelper::drawFramesHeader(QPainter *painter,
painter->drawText(
textRect,
textAlign,
QString("%1").arg(highlightOffset));
QString("%1").arg(highlightOffset, 0, addressDisplayBase));
}

painter->restore();
Expand Down Expand Up @@ -662,4 +669,3 @@ void DisplayHelper::sendHoverUpdate(QSharedPointer<DisplayHandle> handle, QPoint

handle->setBitHover(true, diff.x(), diff.y());
}

6 changes: 4 additions & 2 deletions src/hobbits-widgets/displayhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ namespace DisplayHelper
QSharedPointer<DisplayHandle> displayHandle,
QSizeF bitSize,
int columnGrouping = 1,
int groupMargin = 0);
int groupMargin = 0,
int addressDisplayBase = 10);

void HOBBITSWIDGETSSHARED_EXPORT drawFramesHeader(QPainter *painter,
QSize viewportSize,
QSharedPointer<DisplayHandle> displayHandle,
double frameHeight,
int orientation = Qt::Vertical,
int grouping = 1,
int groupMargin = 0);
int groupMargin = 0,
int addressDisplayBase = 10);


void HOBBITSWIDGETSSHARED_EXPORT drawHoverBox(QPainter *painter,
Expand Down

0 comments on commit ed28c4d

Please sign in to comment.