HexdumpWidget: visible lines calculation

This commit is contained in:
Florian Märkl 2017-11-15 22:56:10 +01:00
parent bde54511a9
commit c0248c8bf6
5 changed files with 28 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -3,6 +3,7 @@
#include "utils/HexAsciiHighlighter.h"
#include "utils/HexHighlighter.h"
#include "utils/Configuration.h"
#include "utils/Helpers.h"
#include <QScrollBar>
#include <QJsonArray>
@ -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;

View File

@ -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
*/

View File

@ -59,11 +59,15 @@ protected:
private:
std::unique_ptr<Ui::HexdumpWidget> 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);