ui: adapt scroll target value in code single file mode as workaround when view scrolls below last line

This commit is contained in:
Eberhard Graether
2018-04-21 04:30:55 +02:00
parent fe38cfff6a
commit 91b4e80384
4 changed files with 21 additions and 2 deletions
+1 -2
View File
@@ -274,8 +274,7 @@ void QtCodeArea::lineNumberAreaPaintEvent(QPaintEvent *event)
int QtCodeArea::lineNumberDigits() const
{
int max = qMax(1, int(getStartLineNumber()) + blockCount());
return utility::digits(max);
return utility::digits(getEndLineNumber());
}
int QtCodeArea::lineNumberAreaWidth() const
+5
View File
@@ -130,6 +130,11 @@ uint QtCodeField::getEndLineNumber() const
return m_startLineNumber + blockCount() - 1;
}
int QtCodeField::totalLineHeight() const
{
return blockBoundingRect(firstVisibleBlock()).height() * blockCount();
}
std::string QtCodeField::getCode() const
{
return m_code;
+2
View File
@@ -35,6 +35,8 @@ public:
uint getStartLineNumber() const;
uint getEndLineNumber() const;
int totalLineHeight() const;
std::string getCode() const;
std::shared_ptr<SourceLocationFile> getSourceLocationFile() const;
@@ -195,6 +195,19 @@ bool QtCodeFileSingle::requestScroll(
double percentA = double(lineNumber - 1) / m_area->getEndLineNumber();
double percentB = endLineNumber ? double(endLineNumber - 1) / m_area->getEndLineNumber() : 0.0f;
// fix percentages wrong when code area is scrollable beyond last line due to some unknown bug
{
int totalHeight = m_area->sizeHint().height();
int totalLineHeight = m_area->totalLineHeight();
if (std::abs(totalHeight - totalLineHeight) > 100)
{
double factor = totalLineHeight / double(totalHeight);
percentA *= factor;
percentB *= factor;
}
}
ensurePercentVisibleAnimated(percentA, percentB, animated, target);
m_scrollRequested = true;