From d6583f0f474df5ee9cc3a8ee061e9490167aa725 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Tue, 24 Jun 2014 10:53:03 +0300 Subject: Git: Add on-demand branches expanding Make "branches expanding" on demand and asynchronous. After "git show" there is clickable text: "Branches: " in description. If user clicks this text then branches for commit is triggered and done asynchronously. Task-number: QTCREATORBUG-11293 Done-with: Przemyslaw Gorszkowski Change-Id: I772cfef823d3f95e2b3060dfb5973157d81fc11a Reviewed-by: Tobias Hunger --- src/plugins/diffeditor/diffeditor.cpp | 76 +++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'src/plugins/diffeditor/diffeditor.cpp') 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 #include #include +#include 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()); + 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() << 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, -- cgit v1.2.1