summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2017-12-01 13:29:12 +0100
committerEike Ziller <eike.ziller@qt.io>2017-12-07 12:49:26 +0000
commit508a9bdb2460c19f0be2fb99628304f01aa12557 (patch)
tree163aa16e692f9197c4aad39a56fd5b2bd5a98efb /src
parenta6dfae7f100c349345282134c8dcd47bfc0f8452 (diff)
downloadqt-creator-508a9bdb2460c19f0be2fb99628304f01aa12557.tar.gz
Move line/column label functionality into single place
Create a LineColumnLabel class that aggregates the functionality that was before spread through the editor widget and factory classes. Change-Id: I6ba316174b2f690a0b146bdd606c6f8ed985ec20 Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/libs/utils/fixedsizeclicklabel.h1
-rw-r--r--src/plugins/texteditor/texteditor.cpp69
-rw-r--r--src/plugins/texteditor/texteditor.h3
3 files changed, 48 insertions, 25 deletions
diff --git a/src/libs/utils/fixedsizeclicklabel.h b/src/libs/utils/fixedsizeclicklabel.h
index c34b69f63f..8f61dfcfbb 100644
--- a/src/libs/utils/fixedsizeclicklabel.h
+++ b/src/libs/utils/fixedsizeclicklabel.h
@@ -39,6 +39,7 @@ public:
explicit FixedSizeClickLabel(QWidget *parent = 0);
void setText(const QString &text, const QString &maxText);
+ using QLabel::setText;
QSize sizeHint() const;
QString maxText() const;
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp
index 9571e5e190..54d3cb2318 100644
--- a/src/plugins/texteditor/texteditor.cpp
+++ b/src/plugins/texteditor/texteditor.cpp
@@ -69,7 +69,6 @@
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/coreconstants.h>
-#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/infobar.h>
#include <coreplugin/manhattanstyle.h>
#include <coreplugin/find/basetextfind.h>
@@ -170,6 +169,43 @@ static QString QString_toLower(const QString &str)
return str.toLower();
}
+class LineColumnLabel : public FixedSizeClickLabel
+{
+ Q_OBJECT
+public:
+ LineColumnLabel(TextEditorWidget *parent)
+ : FixedSizeClickLabel(parent)
+ , m_editor(parent)
+ {
+ setMaxText(TextEditorWidget::tr("Line: 9999, Col: 999"));
+ connect(m_editor, &QPlainTextEdit::cursorPositionChanged, this, &LineColumnLabel::update);
+ connect(this, &FixedSizeClickLabel::clicked, ActionManager::instance(), [this] {
+ emit m_editor->activateEditor(EditorManager::IgnoreNavigationHistory);
+ QTimer::singleShot(0, ActionManager::instance(), [] {
+ if (Command *cmd = ActionManager::command(Core::Constants::GOTO)) {
+ if (QAction *act = cmd->action())
+ act->trigger();
+ }
+ });
+ });
+ }
+
+private:
+ void update()
+ {
+ const QTextCursor cursor = m_editor->textCursor();
+ const QTextBlock block = cursor.block();
+ const int line = block.blockNumber() + 1;
+ const int column = cursor.position() - block.position();
+ setText(
+ TextEditorWidget::tr("Line: %1, Col: %2")
+ .arg(line)
+ .arg(m_editor->textDocument()->tabSettings().columnAt(block.text(), column) + 1));
+ }
+
+ TextEditorWidget *m_editor;
+};
+
class TextEditorAnimator : public QObject
{
Q_OBJECT
@@ -566,7 +602,7 @@ public:
TextEditorWidget *q;
QToolBar *m_toolBar = nullptr;
QWidget *m_stretchWidget = nullptr;
- FixedSizeClickLabel *m_cursorPositionLabel = nullptr;
+ LineColumnLabel *m_cursorPositionLabel = nullptr;
FixedSizeClickLabel *m_fileEncodingLabel = nullptr;
QAction *m_cursorPositionLabelAction = nullptr;
QAction *m_fileEncodingLabelAction = nullptr;
@@ -760,7 +796,7 @@ TextEditorWidgetPrivate::TextEditorWidgetPrivate(TextEditorWidget *parent)
m_toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
m_toolBar->addWidget(m_stretchWidget);
- m_cursorPositionLabel = new FixedSizeClickLabel;
+ m_cursorPositionLabel = new LineColumnLabel(q);
const int spacing = q->style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing) / 2;
m_cursorPositionLabel->setContentsMargins(spacing, 0, spacing, 0);
@@ -7854,18 +7890,8 @@ void BaseTextEditor::select(int toPos)
void TextEditorWidgetPrivate::updateCursorPosition()
{
- const QTextCursor cursor = q->textCursor();
- const QTextBlock block = cursor.block();
- const int line = block.blockNumber() + 1;
- const int column = cursor.position() - block.position();
- m_cursorPositionLabel->show();
- m_cursorPositionLabel->setText(TextEditorWidget::tr("Line: %1, Col: %2").arg(line)
- .arg(q->textDocument()->tabSettings().columnAt(block.text(),
- column)+1),
- TextEditorWidget::tr("Line: 9999, Col: 999"));
m_contextHelpId.clear();
-
- if (!block.isVisible())
+ if (!q->textCursor().block().isVisible())
q->ensureCursorVisible();
}
@@ -8593,21 +8619,16 @@ BaseTextEditor *TextEditorFactoryPrivate::createEditorHelper(const TextDocumentP
widget->d->m_codeAssistant.configure(widget);
widget->d->m_commentDefinition = m_commentDefinition;
- QObject::connect(widget, &TextEditorWidget::activateEditor,
- [editor]() { EditorManager::activateEditor(editor); });
+ QObject::connect(widget,
+ &TextEditorWidget::activateEditor,
+ [editor](EditorManager::OpenEditorFlags flags) {
+ EditorManager::activateEditor(editor, flags);
+ });
if (m_useGenericHighlighter)
widget->setupGenericHighlighter();
widget->finalizeInitialization();
editor->finalizeInitialization();
-
- QObject::connect(widget->d->m_cursorPositionLabel, &FixedSizeClickLabel::clicked, [editor] {
- EditorManager::activateEditor(editor, EditorManager::IgnoreNavigationHistory);
- if (Command *cmd = ActionManager::command(Core::Constants::GOTO)) {
- if (QAction *act = cmd->action())
- act->trigger();
- }
- });
return editor;
}
diff --git a/src/plugins/texteditor/texteditor.h b/src/plugins/texteditor/texteditor.h
index cd8fcec05a..2eafc32293 100644
--- a/src/plugins/texteditor/texteditor.h
+++ b/src/plugins/texteditor/texteditor.h
@@ -29,6 +29,7 @@
#include "blockrange.h"
#include "codeassist/assistenums.h"
+#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/editormanager/ieditorfactory.h>
@@ -566,7 +567,7 @@ signals:
void tooltipOverrideRequested(TextEditor::TextEditorWidget *widget,
const QPoint &globalPos, int position, bool *handled);
void tooltipRequested(const QPoint &globalPos, int position);
- void activateEditor();
+ void activateEditor(Core::EditorManager::OpenEditorFlags flags = 0);
protected:
virtual void slotCursorPositionChanged(); // Used in VcsBase