ui: Added single file mode to code view

* Added navigation to top of code view for iterating references and switching between list and single file mode
* current file name and reference count is shown on top in single file mode
* refactored scrolling to location or line via request system
* added parameters animated and toTop to scrolling system
* refactored class hierarchy and removed unused stuff in list mode
This commit is contained in:
Eberhard Graether
2017-01-09 00:48:20 +01:00
parent 79937b21f0
commit 2bdc9b19a2
34 changed files with 1472 additions and 530 deletions
+56 -18
View File
@@ -1,5 +1,7 @@
#include "qt/element/QtCodeArea.h"
#include <algorithm>
#include <QApplication>
#include <QFont>
#include <QHBoxLayout>
@@ -151,21 +153,24 @@ QtCodeArea::~QtCodeArea()
QSize QtCodeArea::sizeHint() const
{
QTextBlock block = firstVisibleBlock();
float height = blockBoundingGeometry(block).translated(contentOffset()).top();
QTextBlock block = document()->firstBlock();
double height = 0;
double width = lineNumberAreaWidth() + blockBoundingGeometry(block).translated(contentOffset()).left();
while (block.isValid())
{
height += blockBoundingRect(block).height();
width = std::max(blockBoundingRect(block).width(), width);
block = block.next();
}
if (horizontalScrollBar()->isVisible())
if (horizontalScrollBar()->minimum() != horizontalScrollBar()->maximum())
{
height += horizontalScrollBar()->height();
}
return QSize(0, height + 5);
return QSize(width + 1, height + 5);
}
uint QtCodeArea::getStartLineNumber() const
@@ -275,31 +280,65 @@ uint QtCodeArea::getLineNumberForLocationId(Id locationId) const
return 0;
}
int QtCodeArea::getStartLineNumberOfFirstActiveScope() const
uint QtCodeArea::getStartLineNumberOfFirstActiveLocationOfTokenId(Id tokenId) const
{
int firstActiveLine = 0;
for (const Annotation& annotation : m_annotations)
{
if (annotation.locationType == LocationType::LOCATION_SCOPE && annotation.isActive)
if (annotation.locationType == LocationType::LOCATION_TOKEN && annotation.isActive)
{
if (firstActiveLine && firstActiveLine != annotation.startLine)
if (annotation.tokenId == tokenId)
{
return annotation.startLine;
if (!firstActiveLine || firstActiveLine == annotation.startLine)
{
return getStartLineNumber();
}
else
{
return annotation.startLine;
}
}
else
{
return getStartLineNumber();
firstActiveLine = annotation.startLine;
}
}
else if (annotation.isActive)
{
firstActiveLine = annotation.startLine;
}
}
return 0;
}
Id QtCodeArea::getLocationIdOfFirstActiveLocationOfTokenId(Id tokenId) const
{
for (const Annotation& annotation : m_annotations)
{
if (annotation.locationType == LocationType::LOCATION_TOKEN && annotation.isActive)
{
if (annotation.tokenId == tokenId)
{
return annotation.locationId;
}
}
}
return 0;
}
uint QtCodeArea::getActiveLocationCount() const
{
uint count = 0;
for (const Annotation& annotation : m_annotations)
{
if (annotation.locationType == LocationType::LOCATION_TOKEN && (annotation.isActive || annotation.isFocused))
{
count++;
}
}
return count;
}
QRectF QtCodeArea::getLineRectForLineNumber(uint lineNumber) const
{
if (lineNumber < getStartLineNumber())
@@ -338,8 +377,6 @@ void QtCodeArea::showEvent(QShowEvent* event)
{
int tabWidth = ApplicationSettings::getInstance()->getCodeTabWidth();
setTabStopWidth(tabWidth * fontMetrics().width('9'));
setFixedHeight(sizeHint().height());
}
void QtCodeArea::paintEvent(QPaintEvent* event)
@@ -563,12 +600,13 @@ void QtCodeArea::clearSelection()
QTextCursor cursor = textCursor();
cursor.clearSelection();
QScrollBar* scrollbar = horizontalScrollBar();
int scrollValue = horizontalScrollBar()->value();
int horizontalValue = horizontalScrollBar()->value();
int verticalValue = verticalScrollBar()->value();
setTextCursor(cursor);
scrollbar->setValue(scrollValue);
horizontalScrollBar()->setValue(horizontalValue);
verticalScrollBar()->setValue(verticalValue);
}
void QtCodeArea::setIDECursorPosition()