Commit 381a60b7 authored by hjk's avatar hjk
Browse files

BaseTextEditor: make ITextMarks draggable



Change-Id: I36fd6d49ec99975d059f201aa23db11dd80e4ad6
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 03ec0b17
...@@ -2497,6 +2497,7 @@ BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate() ...@@ -2497,6 +2497,7 @@ BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate()
m_codeAssistant(new CodeAssistant), m_codeAssistant(new CodeAssistant),
m_assistRelevantContentAdded(false), m_assistRelevantContentAdded(false),
m_cursorBlockNumber(-1), m_cursorBlockNumber(-1),
m_markDragging(false),
m_autoCompleter(new AutoCompleter), m_autoCompleter(new AutoCompleter),
m_indenter(new Indenter), m_indenter(new Indenter),
m_clipboardAssistProvider(new Internal::ClipboardAssistProvider) m_clipboardAssistProvider(new Internal::ClipboardAssistProvider)
...@@ -4363,6 +4364,7 @@ void BaseTextEditorWidget::extraAreaMouseEvent(QMouseEvent *e) ...@@ -4363,6 +4364,7 @@ void BaseTextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
int markWidth; int markWidth;
extraAreaWidth(&markWidth); extraAreaWidth(&markWidth);
const bool inMarkArea = e->pos().x() <= markWidth && e->pos().x() >= 0;
if (d->m_codeFoldingVisible if (d->m_codeFoldingVisible
&& e->type() == QEvent::MouseMove && e->buttons() == 0) { // mouse tracking && e->type() == QEvent::MouseMove && e->buttons() == 0) { // mouse tracking
...@@ -4383,15 +4385,22 @@ void BaseTextEditorWidget::extraAreaMouseEvent(QMouseEvent *e) ...@@ -4383,15 +4385,22 @@ void BaseTextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
// Set whether the mouse cursor is a hand or normal arrow // Set whether the mouse cursor is a hand or normal arrow
if (e->type() == QEvent::MouseMove) { if (e->type() == QEvent::MouseMove) {
bool hand = (e->pos().x() <= markWidth); if (inMarkArea) {
if (hand) {
//Find line by cursor position //Find line by cursor position
int line = cursor.blockNumber() + 1; int line = cursor.blockNumber() + 1;
emit editor()->markTooltipRequested(editor(), mapToGlobal(e->pos()), line); emit editor()->markTooltipRequested(editor(), mapToGlobal(e->pos()), line);
} }
if (hand != (d->m_extraArea->cursor().shape() == Qt::PointingHandCursor)) if (e->buttons() & Qt::LeftButton) {
d->m_extraArea->setCursor(hand ? Qt::PointingHandCursor : Qt::ArrowCursor); int dist = (e->pos() - d->m_markDragStart).manhattanLength();
if (dist > QApplication::startDragDistance())
d->m_markDragging = true;
}
if (d->m_markDragging)
d->m_extraArea->setCursor(inMarkArea ? Qt::DragMoveCursor : Qt::ForbiddenCursor);
else if (inMarkArea != (d->m_extraArea->cursor().shape() == Qt::PointingHandCursor))
d->m_extraArea->setCursor(inMarkArea ? Qt::PointingHandCursor : Qt::ArrowCursor);
} }
if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonDblClick) { if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonDblClick) {
...@@ -4409,7 +4418,7 @@ void BaseTextEditorWidget::extraAreaMouseEvent(QMouseEvent *e) ...@@ -4409,7 +4418,7 @@ void BaseTextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
toggleBlockVisible(c); toggleBlockVisible(c);
d->moveCursorVisible(false); d->moveCursorVisible(false);
} }
} else if (d->m_lineNumbersVisible && e->pos().x() > markWidth) { } else if (d->m_lineNumbersVisible && !inMarkArea) {
QTextCursor selection = cursor; QTextCursor selection = cursor;
selection.setVisualNavigation(true); selection.setVisualNavigation(true);
d->extraAreaSelectionAnchorBlockNumber = selection.blockNumber(); d->extraAreaSelectionAnchorBlockNumber = selection.blockNumber();
...@@ -4418,6 +4427,8 @@ void BaseTextEditorWidget::extraAreaMouseEvent(QMouseEvent *e) ...@@ -4418,6 +4427,8 @@ void BaseTextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
setTextCursor(selection); setTextCursor(selection);
} else { } else {
d->extraAreaToggleMarkBlockNumber = cursor.blockNumber(); d->extraAreaToggleMarkBlockNumber = cursor.blockNumber();
d->m_markDragging = false;
d->m_markDragStart = e->pos();
} }
} }
} else if (d->extraAreaSelectionAnchorBlockNumber >= 0) { } else if (d->extraAreaSelectionAnchorBlockNumber >= 0) {
...@@ -4451,25 +4462,38 @@ void BaseTextEditorWidget::extraAreaMouseEvent(QMouseEvent *e) ...@@ -4451,25 +4462,38 @@ void BaseTextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
if (e->type() == QEvent::MouseButtonRelease && e->button() == Qt::LeftButton) { if (e->type() == QEvent::MouseButtonRelease && e->button() == Qt::LeftButton) {
int n = d->extraAreaToggleMarkBlockNumber; int n = d->extraAreaToggleMarkBlockNumber;
d->extraAreaToggleMarkBlockNumber = -1; d->extraAreaToggleMarkBlockNumber = -1;
if (cursor.blockNumber() == n) { const bool sameLine = cursor.blockNumber() == n;
if (TextBlockUserData *data = static_cast<TextBlockUserData *>(cursor.block().userData())) { const bool wasDragging = d->m_markDragging;
foreach (ITextMark *mark, data->marks()) { d->m_markDragging = false;
QTextBlock block = cursor.document()->findBlockByNumber(n);
if (TextBlockUserData *data = static_cast<TextBlockUserData *>(block.userData())) {
foreach (ITextMark *mark, data->marks()) {
if (sameLine) {
if (mark->isClickable()) { if (mark->isClickable()) {
mark->clicked(); mark->clicked();
return; return;
} }
} else {
if (wasDragging && mark->isDraggable()) {
if (inMarkArea) {
mark->dragToLine(cursor.blockNumber() + 1);
d->m_extraArea->setCursor(Qt::PointingHandCursor);
} else {
d->m_extraArea->setCursor(Qt::ArrowCursor);
}
return;
}
} }
} }
int line = n + 1;
ITextEditor::MarkRequestKind kind;
if (QApplication::keyboardModifiers() & Qt::ShiftModifier)
kind = ITextEditor::BookmarkRequest;
else
kind = ITextEditor::BreakpointRequest;
emit editor()->markRequested(editor(), line, kind);
} }
int line = n + 1;
ITextEditor::MarkRequestKind kind;
if (QApplication::keyboardModifiers() & Qt::ShiftModifier)
kind = ITextEditor::BookmarkRequest;
else
kind = ITextEditor::BreakpointRequest;
emit editor()->markRequested(editor(), line, kind);
} }
} }
} }
......
...@@ -292,6 +292,9 @@ public: ...@@ -292,6 +292,9 @@ public:
QPointer<BaseTextEditorAnimator> m_animator; QPointer<BaseTextEditorAnimator> m_animator;
int m_cursorBlockNumber; int m_cursorBlockNumber;
QPoint m_markDragStart;
bool m_markDragging;
QScopedPointer<AutoCompleter> m_autoCompleter; QScopedPointer<AutoCompleter> m_autoCompleter;
QScopedPointer<Indenter> m_indenter; QScopedPointer<Indenter> m_indenter;
......
...@@ -110,6 +110,16 @@ bool ITextMark::isClickable() const ...@@ -110,6 +110,16 @@ bool ITextMark::isClickable() const
void ITextMark::clicked() void ITextMark::clicked()
{} {}
bool ITextMark::isDraggable() const
{
return false;
}
void ITextMark::dragToLine(int lineNumber)
{
Q_UNUSED(lineNumber);
}
ITextMarkable *ITextMark::markableInterface() const ITextMarkable *ITextMark::markableInterface() const
{ {
return m_markableInterface; return m_markableInterface;
......
...@@ -76,6 +76,8 @@ public: ...@@ -76,6 +76,8 @@ public:
virtual void removedFromEditor(); virtual void removedFromEditor();
virtual bool isClickable() const; virtual bool isClickable() const;
virtual void clicked(); virtual void clicked();
virtual bool isDraggable() const;
virtual void dragToLine(int lineNumber);
void setIcon(const QIcon &icon); void setIcon(const QIcon &icon);
// call this if the icon has changed. // call this if the icon has changed.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment