From f68ed8248917cc588ec8a4110873461a6e361a6d Mon Sep 17 00:00:00 2001 From: karliss Date: Thu, 25 Apr 2019 11:49:10 +0300 Subject: [PATCH] Use same font size for all text in hexdump widget. (#1485) --- src/widgets/HexdumpWidget.cpp | 39 ++++++++++++++++++++++------------- src/widgets/HexdumpWidget.h | 3 +++ src/widgets/HexdumpWidget.ui | 16 +++++++++++++- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/widgets/HexdumpWidget.cpp b/src/widgets/HexdumpWidget.cpp index 7cb99072..303046ce 100644 --- a/src/widgets/HexdumpWidget.cpp +++ b/src/widgets/HexdumpWidget.cpp @@ -133,6 +133,10 @@ HexdumpWidget::HexdumpWidget(MainWindow *main, QAction *action) : connect(seekable, &CutterSeekable::seekableSeekChanged, this, &HexdumpWidget::onSeekChanged); connect(&rangeDialog, &QDialog::accepted, this, &HexdumpWidget::on_rangeDialogAccepted); + addAction(ui->actionResetZoom); + connect(ui->actionResetZoom, &QAction::triggered, this, &HexdumpWidget::zoomReset); + defaultFontSize = ui->hexHexText->font().pointSizeF(); + format = Format::Hex; initParsing(); selectHexPreview(); @@ -1103,11 +1107,7 @@ void HexdumpWidget::wheelEvent(QWheelEvent *event) if (!numDegrees.isNull()) { const QPoint numSteps = numDegrees / 15; if ( 0 != numSteps.y() ) { - if (numSteps.y() > 0) { - zoomIn(1); - } else if ( numSteps.y() < 0 ) { - zoomOut(1); - } + zoomIn(numSteps.y() > 0 ? 1 : -1); } } event->accept(); @@ -1196,20 +1196,21 @@ void HexdumpWidget::showOffsets(bool show) void HexdumpWidget::zoomIn(int range) { - ui->hexOffsetText->zoomIn(range); - ui->hexASCIIText->zoomIn(range); ui->hexHexText->zoomIn(range); - - updateWidths(); + syncScale(); } void HexdumpWidget::zoomOut(int range) { - ui->hexOffsetText->zoomOut(range); - ui->hexASCIIText->zoomOut(range); - ui->hexHexText->zoomOut(range); + zoomIn(-range); +} - updateWidths(); +void HexdumpWidget::zoomReset() +{ + QFont font(ui->hexHexText->font()); + font.setPointSizeF(defaultFontSize); + ui->hexHexText->setFont(font); + syncScale(); } void HexdumpWidget::updateWidths() @@ -1219,8 +1220,18 @@ void HexdumpWidget::updateWidths() ui->hexHexText->document()->setTextWidth(idealWidth); ui->hexOffsetText->document()->adjustSize(); - ui->hexOffsetText->setFixedWidth(ui->hexOffsetText->document()->size().width()); + ui->hexOffsetText->setFixedWidth(ui->hexOffsetText->document()->size().width() + 1); ui->hexASCIIText->document()->adjustSize(); ui->hexASCIIText->setMinimumWidth(ui->hexASCIIText->document()->size().width()); } + +void HexdumpWidget::syncScale() +{ + ui->hexOffsetText->setFont(ui->hexHexText->font()); + ui->hexASCIIText->setFont(ui->hexHexText->font()); + ui->offsetHeaderLabel->setFont(ui->hexHexText->font()); + ui->hexHeaderLabel->setFont(ui->hexHexText->font()); + ui->asciiHeaderLabel->setFont(ui->hexHexText->font()); + updateWidths(); +} diff --git a/src/widgets/HexdumpWidget.h b/src/widgets/HexdumpWidget.h index 8668009f..9b1d5caa 100644 --- a/src/widgets/HexdumpWidget.h +++ b/src/widgets/HexdumpWidget.h @@ -53,6 +53,7 @@ public slots: void zoomIn(int range = 1); void zoomOut(int range = 1); + void zoomReset(); void toggleSync(); protected: @@ -102,6 +103,7 @@ private: int hexAddressToPosition(RVA address); int asciiAddressToPosition(RVA address); void updateWidths(); + void syncScale(); void updateParseWindow(RVA start_address, int size); void clearParseWindow(); @@ -113,6 +115,7 @@ private: HexdumpRangeDialog rangeDialog; QAction syncAction; CutterSeekable *seekable; + qreal defaultFontSize; private slots: void onSeekChanged(RVA addr); diff --git a/src/widgets/HexdumpWidget.ui b/src/widgets/HexdumpWidget.ui index a1fbe4be..00a779ec 100644 --- a/src/widgets/HexdumpWidget.ui +++ b/src/widgets/HexdumpWidget.ui @@ -911,9 +911,23 @@ Select Block... + + + true + + + Reset zoom + + + Ctrl+0 + + + Qt::WindowShortcut + + - \ No newline at end of file +