summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhjk <qtc-committer@nokia.com>2011-03-23 10:45:04 +0100
committerhjk <qtc-committer@nokia.com>2011-03-23 10:49:00 +0100
commitf67e9a54c99b134e86068f7c385ea79fbeeb121b (patch)
treeb43b7cf0aa43835a6e11e4e615a3ddd22707a3aa /src
parent1e8e9612c3ea1bbe9d919b654e32c4668bd94375 (diff)
downloadqt-creator-f67e9a54c99b134e86068f7c385ea79fbeeb121b.tar.gz
Adjust mark area width to mark width.
Patch by Kevin Funk
Diffstat (limited to 'src')
-rw-r--r--src/plugins/texteditor/basetextdocument.cpp32
-rw-r--r--src/plugins/texteditor/basetextdocumentlayout.cpp1
-rw-r--r--src/plugins/texteditor/basetextdocumentlayout.h1
-rw-r--r--src/plugins/texteditor/basetexteditor.cpp3
4 files changed, 33 insertions, 4 deletions
diff --git a/src/plugins/texteditor/basetextdocument.cpp b/src/plugins/texteditor/basetextdocument.cpp
index 27e77694d8..38a668ccf3 100644
--- a/src/plugins/texteditor/basetextdocument.cpp
+++ b/src/plugins/texteditor/basetextdocument.cpp
@@ -84,6 +84,8 @@ class DocumentMarker : public ITextMarkable
public:
DocumentMarker(QTextDocument *);
+ TextMarks marks() const { return m_marksCache; }
+
// ITextMarkable
bool addMark(ITextMark *mark, int line);
TextMarks marksAt(int line) const;
@@ -92,6 +94,9 @@ public:
void updateMark(ITextMark *mark);
private:
+ double recalculateMaxMarkWidthFactor() const;
+
+ TextMarks m_marksCache; // not owned
QTextDocument *document;
};
@@ -104,22 +109,34 @@ bool DocumentMarker::addMark(TextEditor::ITextMark *mark, int line)
{
QTC_ASSERT(line >= 1, return false);
int blockNumber = line - 1;
- BaseTextDocumentLayout *documentLayout = qobject_cast<BaseTextDocumentLayout*>(document->documentLayout());
+ BaseTextDocumentLayout *documentLayout =
+ qobject_cast<BaseTextDocumentLayout*>(document->documentLayout());
QTC_ASSERT(documentLayout, return false);
QTextBlock block = document->findBlockByNumber(blockNumber);
if (block.isValid()) {
TextBlockUserData *userData = BaseTextDocumentLayout::userData(block);
userData->addMark(mark);
+ m_marksCache.append(mark);
mark->updateLineNumber(blockNumber + 1);
mark->updateBlock(block);
documentLayout->hasMarks = true;
+ documentLayout->maxMarkWidthFactor = qMax(mark->widthFactor(),
+ documentLayout->maxMarkWidthFactor);
documentLayout->requestUpdate();
return true;
}
return false;
}
+double DocumentMarker::recalculateMaxMarkWidthFactor() const
+{
+ double maxWidthFactor = 1.0;
+ foreach (const ITextMark *mark, marks())
+ maxWidthFactor = qMax(mark->widthFactor(), maxWidthFactor);
+ return maxWidthFactor;
+}
+
TextEditor::TextMarks DocumentMarker::marksAt(int line) const
{
QTC_ASSERT(line >= 1, return TextMarks());
@@ -135,6 +152,10 @@ TextEditor::TextMarks DocumentMarker::marksAt(int line) const
void DocumentMarker::removeMark(TextEditor::ITextMark *mark)
{
+ BaseTextDocumentLayout *documentLayout =
+ qobject_cast<BaseTextDocumentLayout*>(document->documentLayout());
+ QTC_ASSERT(documentLayout, return)
+
bool needUpdate = false;
QTextBlock block = document->begin();
while (block.isValid()) {
@@ -143,8 +164,12 @@ void DocumentMarker::removeMark(TextEditor::ITextMark *mark)
}
block = block.next();
}
- if (needUpdate)
+ m_marksCache.removeAll(mark);
+
+ if (needUpdate) {
+ documentLayout->maxMarkWidthFactor = recalculateMaxMarkWidthFactor();
updateMark(0);
+ }
}
bool DocumentMarker::hasMark(TextEditor::ITextMark *mark) const
@@ -163,7 +188,8 @@ bool DocumentMarker::hasMark(TextEditor::ITextMark *mark) const
void DocumentMarker::updateMark(ITextMark *mark)
{
Q_UNUSED(mark)
- BaseTextDocumentLayout *documentLayout = qobject_cast<BaseTextDocumentLayout*>(document->documentLayout());
+ BaseTextDocumentLayout *documentLayout =
+ qobject_cast<BaseTextDocumentLayout*>(document->documentLayout());
QTC_ASSERT(documentLayout, return);
documentLayout->requestUpdate();
}
diff --git a/src/plugins/texteditor/basetextdocumentlayout.cpp b/src/plugins/texteditor/basetextdocumentlayout.cpp
index a7540edb36..35ea068cfd 100644
--- a/src/plugins/texteditor/basetextdocumentlayout.cpp
+++ b/src/plugins/texteditor/basetextdocumentlayout.cpp
@@ -393,6 +393,7 @@ BaseTextDocumentLayout::BaseTextDocumentLayout(QTextDocument *doc)
:QPlainTextDocumentLayout(doc) {
lastSaveRevision = 0;
hasMarks = 0;
+ maxMarkWidthFactor = 1.0;
m_requiredWidth = 0;
}
diff --git a/src/plugins/texteditor/basetextdocumentlayout.h b/src/plugins/texteditor/basetextdocumentlayout.h
index 493fb7a238..8ecb7e5f92 100644
--- a/src/plugins/texteditor/basetextdocumentlayout.h
+++ b/src/plugins/texteditor/basetextdocumentlayout.h
@@ -189,6 +189,7 @@ public:
void emitDocumentSizeChanged() { emit documentSizeChanged(documentSize()); }
int lastSaveRevision;
bool hasMarks;
+ double maxMarkWidthFactor;
int m_requiredWidth;
void setRequiredWidth(int width);
diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index e747853753..420fcf0d2b 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -3576,7 +3576,8 @@ int BaseTextEditorWidget::extraAreaWidth(int *markWidthPtr) const
int markWidth = 0;
if (d->m_marksVisible) {
- markWidth += fm.lineSpacing();
+ markWidth += documentLayout->maxMarkWidthFactor * fm.lineSpacing();
+
// if (documentLayout->doubleMarkCount)
// markWidth += fm.lineSpacing() / 3;
space += markWidth;