diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2014-06-24 10:53:03 +0300 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2014-06-24 11:19:28 +0200 |
commit | d6583f0f474df5ee9cc3a8ee061e9490167aa725 (patch) | |
tree | 802fdfbe38603191147860fe20deed1af1ea89ee /src/plugins/diffeditor/diffeditor.cpp | |
parent | 281aa9e0d69d8ca8aa4e70bb755b4c5b3d58491b (diff) | |
download | qt-creator-d6583f0f474df5ee9cc3a8ee061e9490167aa725.tar.gz |
Git: Add on-demand branches expanding
Make "branches expanding" on demand and asynchronous.
After "git show" there is clickable text: "Branches: <Expand>" in
description. If user clicks this text then branches for commit is
triggered and done asynchronously.
Task-number: QTCREATORBUG-11293
Done-with: Przemyslaw Gorszkowski <pgorszkowski@gmail.com>
Change-Id: I772cfef823d3f95e2b3060dfb5973157d81fc11a
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
Diffstat (limited to 'src/plugins/diffeditor/diffeditor.cpp')
-rw-r--r-- | src/plugins/diffeditor/diffeditor.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/plugins/diffeditor/diffeditor.cpp b/src/plugins/diffeditor/diffeditor.cpp index 2d0405666f..d18e7bbfb2 100644 --- a/src/plugins/diffeditor/diffeditor.cpp +++ b/src/plugins/diffeditor/diffeditor.cpp @@ -52,6 +52,7 @@ #include <QComboBox> #include <QFileInfo> #include <QTextCodec> +#include <QTextBlock> static const char settingsGroupC[] = "DiffEditor"; static const char diffEditorTypeKeyC[] = "DiffEditorType"; @@ -74,6 +75,9 @@ public: DescriptionEditorWidget(QWidget *parent = 0); virtual QSize sizeHint() const; +signals: + void expandBranchesRequested(); + public slots: void setDisplaySettings(const DisplaySettings &ds); @@ -84,6 +88,15 @@ protected: editor->document()->setId("DiffEditor.DescriptionEditor"); return editor; } + void mouseMoveEvent(QMouseEvent *e); + void mouseReleaseEvent(QMouseEvent *e); + + bool findContentsUnderCursor(const QTextCursor &cursor); + void highlightCurrentContents(); + void handleCurrentContents(); + +private: + QTextCursor m_currentCursor; }; DescriptionEditorWidget::DescriptionEditorWidget(QWidget *parent) @@ -118,6 +131,67 @@ void DescriptionEditorWidget::setDisplaySettings(const DisplaySettings &ds) BaseTextEditorWidget::setDisplaySettings(settings); } +void DescriptionEditorWidget::mouseMoveEvent(QMouseEvent *e) +{ + if (e->buttons()) { + TextEditor::BaseTextEditorWidget::mouseMoveEvent(e); + return; + } + + Qt::CursorShape cursorShape; + + const QTextCursor cursor = cursorForPosition(e->pos()); + if (findContentsUnderCursor(cursor)) { + highlightCurrentContents(); + cursorShape = Qt::PointingHandCursor; + } else { + setExtraSelections(OtherSelection, QList<QTextEdit::ExtraSelection>()); + cursorShape = Qt::IBeamCursor; + } + + TextEditor::BaseTextEditorWidget::mouseMoveEvent(e); + viewport()->setCursor(cursorShape); +} + +void DescriptionEditorWidget::mouseReleaseEvent(QMouseEvent *e) +{ + if (e->button() == Qt::LeftButton && !(e->modifiers() & Qt::ShiftModifier)) { + const QTextCursor cursor = cursorForPosition(e->pos()); + if (findContentsUnderCursor(cursor)) { + handleCurrentContents(); + e->accept(); + return; + } + } + + TextEditor::BaseTextEditorWidget::mouseReleaseEvent(e); +} + +bool DescriptionEditorWidget::findContentsUnderCursor(const QTextCursor &cursor) +{ + m_currentCursor = cursor; + return cursor.block().text() == QLatin1String(Constants::EXPAND_BRANCHES); +} + +void DescriptionEditorWidget::highlightCurrentContents() +{ + QTextEdit::ExtraSelection sel; + sel.cursor = m_currentCursor; + sel.cursor.select(QTextCursor::LineUnderCursor); + sel.format.setFontUnderline(true); + setExtraSelections(BaseTextEditorWidget::OtherSelection, + QList<QTextEdit::ExtraSelection>() << sel); + +} + +void DescriptionEditorWidget::handleCurrentContents() +{ + m_currentCursor.select(QTextCursor::LineUnderCursor); + m_currentCursor.removeSelectedText(); + m_currentCursor.insertText(QLatin1String("Branches: Expanding...")); + emit expandBranchesRequested(); +} + } // namespace Internal ///////////////////////////////// DiffEditor ////////////////////////////////// @@ -179,6 +253,8 @@ void DiffEditor::ctor() setWidget(splitter); + connect(m_descriptionWidget, SIGNAL(expandBranchesRequested()), + m_document->controller(), SLOT(expandBranchesRequested())); connect(TextEditorSettings::instance(), SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)), m_descriptionWidget, |