diff --git a/src/utils/Helpers.cpp b/src/utils/Helpers.cpp index e8f7fa70..05effc2d 100644 --- a/src/utils/Helpers.cpp +++ b/src/utils/Helpers.cpp @@ -137,4 +137,15 @@ namespace qhelpers widget->setMaximumHeight(max); } + + int getMaxFullyDisplayedLines(QPlainTextEdit *plainTextEdit) + { + QFontMetrics fontMetrics(plainTextEdit->document()->defaultFont()); + return (plainTextEdit->height() + - (plainTextEdit->contentsMargins().top() + + plainTextEdit->contentsMargins().bottom() + + (int)(plainTextEdit->document()->documentMargin() * 2))) + / fontMetrics.lineSpacing(); + } + } // end namespace diff --git a/src/utils/Helpers.h b/src/utils/Helpers.h index b7ffae5a..84174ef4 100644 --- a/src/utils/Helpers.h +++ b/src/utils/Helpers.h @@ -40,6 +40,9 @@ namespace qhelpers SizePolicyMinMax forceWidth(QWidget *widget, int width); SizePolicyMinMax forceHeight(QWidget *widget, int height); + + + int getMaxFullyDisplayedLines(QPlainTextEdit *plainTextEdit); } #endif // HELPERS_H diff --git a/src/widgets/DisassemblyWidget.cpp b/src/widgets/DisassemblyWidget.cpp index 63fe7a5c..5a242f78 100644 --- a/src/widgets/DisassemblyWidget.cpp +++ b/src/widgets/DisassemblyWidget.cpp @@ -3,6 +3,7 @@ #include "utils/HexAsciiHighlighter.h" #include "utils/HexHighlighter.h" #include "utils/Configuration.h" +#include "utils/Helpers.h" #include #include @@ -186,12 +187,7 @@ void DisassemblyWidget::scrollInstructions(int count) void DisassemblyWidget::updateMaxLines() { - QFontMetrics fontMetrics(mDisasTextEdit->document()->defaultFont()); - int currentMaxLines = (mDisasTextEdit->height() - - (mDisasTextEdit->contentsMargins().top() + mDisasTextEdit->contentsMargins().bottom() - + (int)(mDisasTextEdit->document()->documentMargin() * 2))) - / fontMetrics.lineSpacing(); - + int currentMaxLines = qhelpers::getMaxFullyDisplayedLines(mDisasTextEdit); if (currentMaxLines != maxLines) { maxLines = currentMaxLines; diff --git a/src/widgets/HexdumpWidget.cpp b/src/widgets/HexdumpWidget.cpp index 00316326..4d7c8f9a 100644 --- a/src/widgets/HexdumpWidget.cpp +++ b/src/widgets/HexdumpWidget.cpp @@ -184,6 +184,8 @@ void HexdumpWidget::refresh(RVA addr) addr = Core()->getOffset(); } + updateVisibleLines(); // TODO: only on resize + RCoreLocked lcore = Core()->core(); // Prevent further scroll disconnect(ui->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled())); @@ -243,6 +245,12 @@ void HexdumpWidget::refresh(RVA addr) } + +void HexdumpWidget::updateVisibleLines() +{ + visibleLines = qhelpers::getMaxFullyDisplayedLines(ui->hexHexText); +} + /* * Content management functions */ diff --git a/src/widgets/HexdumpWidget.h b/src/widgets/HexdumpWidget.h index 4f54dd14..d713eb3b 100644 --- a/src/widgets/HexdumpWidget.h +++ b/src/widgets/HexdumpWidget.h @@ -59,11 +59,15 @@ protected: private: std::unique_ptr ui; + int visibleLines; + RVA topOffset; RVA bottomOffset; void refresh(RVA addr = RVA_INVALID); + void updateVisibleLines(); + private slots: void on_seekChanged(RVA addr); void raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type);