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);
|
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
|
} // end namespace
|
||||||
|
@ -40,6 +40,9 @@ namespace qhelpers
|
|||||||
|
|
||||||
SizePolicyMinMax forceWidth(QWidget *widget, int width);
|
SizePolicyMinMax forceWidth(QWidget *widget, int width);
|
||||||
SizePolicyMinMax forceHeight(QWidget *widget, int height);
|
SizePolicyMinMax forceHeight(QWidget *widget, int height);
|
||||||
|
|
||||||
|
|
||||||
|
int getMaxFullyDisplayedLines(QPlainTextEdit *plainTextEdit);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // HELPERS_H
|
#endif // HELPERS_H
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "utils/HexAsciiHighlighter.h"
|
#include "utils/HexAsciiHighlighter.h"
|
||||||
#include "utils/HexHighlighter.h"
|
#include "utils/HexHighlighter.h"
|
||||||
#include "utils/Configuration.h"
|
#include "utils/Configuration.h"
|
||||||
|
#include "utils/Helpers.h"
|
||||||
|
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
@ -186,12 +187,7 @@ void DisassemblyWidget::scrollInstructions(int count)
|
|||||||
|
|
||||||
void DisassemblyWidget::updateMaxLines()
|
void DisassemblyWidget::updateMaxLines()
|
||||||
{
|
{
|
||||||
QFontMetrics fontMetrics(mDisasTextEdit->document()->defaultFont());
|
int currentMaxLines = qhelpers::getMaxFullyDisplayedLines(mDisasTextEdit);
|
||||||
int currentMaxLines = (mDisasTextEdit->height() -
|
|
||||||
(mDisasTextEdit->contentsMargins().top() + mDisasTextEdit->contentsMargins().bottom()
|
|
||||||
+ (int)(mDisasTextEdit->document()->documentMargin() * 2)))
|
|
||||||
/ fontMetrics.lineSpacing();
|
|
||||||
|
|
||||||
if (currentMaxLines != maxLines)
|
if (currentMaxLines != maxLines)
|
||||||
{
|
{
|
||||||
maxLines = currentMaxLines;
|
maxLines = currentMaxLines;
|
||||||
|
@ -184,6 +184,8 @@ void HexdumpWidget::refresh(RVA addr)
|
|||||||
addr = Core()->getOffset();
|
addr = Core()->getOffset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateVisibleLines(); // TODO: only on resize
|
||||||
|
|
||||||
RCoreLocked lcore = Core()->core();
|
RCoreLocked lcore = Core()->core();
|
||||||
// Prevent further scroll
|
// Prevent further scroll
|
||||||
disconnect(ui->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled()));
|
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
|
* Content management functions
|
||||||
*/
|
*/
|
||||||
|
@ -59,11 +59,15 @@ protected:
|
|||||||
private:
|
private:
|
||||||
std::unique_ptr<Ui::HexdumpWidget> ui;
|
std::unique_ptr<Ui::HexdumpWidget> ui;
|
||||||
|
|
||||||
|
int visibleLines;
|
||||||
|
|
||||||
RVA topOffset;
|
RVA topOffset;
|
||||||
RVA bottomOffset;
|
RVA bottomOffset;
|
||||||
|
|
||||||
void refresh(RVA addr = RVA_INVALID);
|
void refresh(RVA addr = RVA_INVALID);
|
||||||
|
|
||||||
|
void updateVisibleLines();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_seekChanged(RVA addr);
|
void on_seekChanged(RVA addr);
|
||||||
void raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type);
|
void raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type);
|
||||||
|
Loading…
Reference in New Issue
Block a user