mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-18 18:38:51 +00:00
HexdumpWidget: visible lines calculation
This commit is contained in:
parent
bde54511a9
commit
c0248c8bf6
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user