TextEditor: Use more direct approach for fallback IEditor construction

There are still a few places where the EditorWidget is the primary
object, or several of them per "visible" IEditor (e.g. Diff).
Provide a means to streamline setup there, too.

Change-Id: I14cfbd68e555ebc539e707032a0e5bef563e0a36
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
hjk
2014-08-28 18:46:39 +02:00
parent 92cab936b9
commit ec5ea375e0
9 changed files with 40 additions and 80 deletions

View File

@@ -69,28 +69,10 @@
using namespace Core;
using namespace TextEditor;
using namespace Utils;
namespace DiffEditor {
//////////////////////
class SideDiffEditor : public BaseTextEditor
{
Q_OBJECT
public:
SideDiffEditor()
{
connect(this, SIGNAL(tooltipRequested(TextEditor::BaseTextEditor*,QPoint,int)),
this, SLOT(slotTooltipRequested(TextEditor::BaseTextEditor*,QPoint,int)));
}
private slots:
void slotTooltipRequested(TextEditor::BaseTextEditor *editor,
const QPoint &globalPoint,
int position);
};
////////////////////////
/*
class MultiHighlighter : public SyntaxHighlighter
@@ -168,7 +150,7 @@ protected:
return SelectableTextEditorWidget::extraAreaWidth(markWidthPtr);
}
void applyFontSettings();
BaseTextEditor *createEditor() { return new SideDiffEditor; }
virtual QString lineNumber(int blockNumber) const;
virtual int lineNumberDigits() const;
virtual bool selectionVisible(int blockNumber) const;
@@ -209,27 +191,6 @@ private:
// MultiHighlighter *m_highlighter;
};
////////////////////////
void SideDiffEditor::slotTooltipRequested(TextEditor::BaseTextEditor *editor,
const QPoint &globalPoint,
int position)
{
SideDiffEditorWidget *ew = qobject_cast<SideDiffEditorWidget *>(editorWidget());
if (!ew)
return;
QMap<int, DiffFileInfo> fi = ew->fileInfo();
QMap<int, DiffFileInfo>::const_iterator it
= fi.constFind(ew->document()->findBlock(position).blockNumber());
if (it != fi.constEnd()) {
Utils::ToolTip::show(globalPoint, Utils::TextContent(it.value().fileName),
editor->widget());
} else {
Utils::ToolTip::hide();
}
}
////////////////////////
/*
MultiHighlighter::MultiHighlighter(SideDiffEditorWidget *editor, QTextDocument *document)
@@ -324,7 +285,8 @@ SideDiffEditorWidget::SideDiffEditorWidget(QWidget *parent)
m_lineNumberDigits(1),
m_inPaintEvent(false)
{
textDocument()->setId("DiffEditor.SideDiffEditor");
setupFallBackEditor("DiffEditor.SideDiffEditor");
DisplaySettings settings = displaySettings();
settings.m_textWrapping = false;
settings.m_displayLineNumbers = true;
@@ -334,6 +296,16 @@ SideDiffEditorWidget::SideDiffEditorWidget(QWidget *parent)
settings.m_highlightBlocks = false;
SelectableTextEditorWidget::setDisplaySettings(settings);
BaseTextEditor *editor = this->editor();
connect(editor, &BaseTextEditor::tooltipRequested, [this](BaseTextEditor *, const QPoint &point, int position) {
int block = textDocument()->document()->findBlock(position).blockNumber();
auto it = m_fileInfo.constFind(block);
if (it != m_fileInfo.constEnd())
ToolTip::show(point, TextContent(it.value().fileName), this);
else
ToolTip::hide();
});
// setCodeFoldingSupported(true);
// m_highlighter = new MultiHighlighter(this, baseTextDocument()->document());