diff options
-rw-r--r-- | src/plugins/qnx/bardescriptoreditor.cpp | 34 | ||||
-rw-r--r-- | src/plugins/qnx/bardescriptoreditor.h | 7 |
2 files changed, 40 insertions, 1 deletions
diff --git a/src/plugins/qnx/bardescriptoreditor.cpp b/src/plugins/qnx/bardescriptoreditor.cpp index 159e074a7f..bb92fc4e99 100644 --- a/src/plugins/qnx/bardescriptoreditor.cpp +++ b/src/plugins/qnx/bardescriptoreditor.cpp @@ -38,11 +38,15 @@ #include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/task.h> #include <projectexplorer/taskhub.h> -#include <utils/qtcassert.h> #include <texteditor/texteditorconstants.h> #include <texteditor/basetexteditor.h> +#include <texteditor/tabsettings.h> +#include <utils/linecolumnlabel.h> +#include <utils/qtcassert.h> #include <QAction> +#include <QStyle> +#include <QTextBlock> #include <QToolBar> using namespace ProjectExplorer; @@ -83,6 +87,17 @@ BarDescriptorEditor::BarDescriptorEditor(BarDescriptorEditorWidget *editorWidget generalAction->setChecked(true); + m_cursorPositionLabel = new Utils::LineColumnLabel; + const int spacing = editorWidget->style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing) / 2; + m_cursorPositionLabel->setContentsMargins(spacing, 0, spacing, 0); + + QWidget *spacer = new QWidget; + spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + m_toolBar->addWidget(spacer); + + m_cursorPositionAction = m_toolBar->addWidget(m_cursorPositionLabel); + connect(editorWidget->sourceWidget(), SIGNAL(cursorPositionChanged()), this, SLOT(updateCursorPosition())); + setContext(Core::Context(Constants::QNX_BAR_DESCRIPTOR_EDITOR_CONTEXT, TextEditor::Constants::C_TEXTEDITOR)); } @@ -133,6 +148,7 @@ void BarDescriptorEditor::setActivePage(BarDescriptorEditor::EditorPage page) if (page == Source) { editorWidget->setXmlSource(m_file->xmlSource()); + updateCursorPosition(); } else if (prevPage == Source) { TaskHub::clearTasks(Constants::QNX_TASK_CATEGORY_BARDESCRIPTOR); QString errorMsg; @@ -150,8 +166,24 @@ void BarDescriptorEditor::setActivePage(BarDescriptorEditor::EditorPage page) } } + m_cursorPositionAction->setVisible(page == Source); editorWidget->setCurrentIndex(page); } +void BarDescriptorEditor::updateCursorPosition() +{ + BarDescriptorEditorWidget *editorWidget = qobject_cast<BarDescriptorEditorWidget *>(widget()); + QTC_ASSERT(editorWidget, return); + + const QTextCursor cursor = editorWidget->sourceWidget()->textCursor(); + const QTextBlock block = cursor.block(); + const int line = block.blockNumber() + 1; + const int column = cursor.position() - block.position(); + m_cursorPositionLabel->setText(tr("Line: %1, Col: %2").arg(line).arg(editorWidget->sourceWidget()->tabSettings().columnAt(block.text(), column)+1), + tr("Line: 9999, Col: 999")); + if (!block.isVisible()) + editorWidget->sourceWidget()->ensureCursorVisible(); +} + } // namespace Internal } // namespace Qnx diff --git a/src/plugins/qnx/bardescriptoreditor.h b/src/plugins/qnx/bardescriptoreditor.h index da07c43030..d03a2a8139 100644 --- a/src/plugins/qnx/bardescriptoreditor.h +++ b/src/plugins/qnx/bardescriptoreditor.h @@ -39,6 +39,10 @@ class QActionGroup; class QToolBar; QT_END_NAMESPACE +namespace Utils { +class LineColumnLabel; +} + namespace Qnx { namespace Internal { @@ -67,6 +71,7 @@ public: private slots: void changeEditorPage(QAction *action); + void updateCursorPosition(); private: void setActivePage(EditorPage page); @@ -75,6 +80,8 @@ private: QToolBar *m_toolBar; QActionGroup *m_actionGroup; + Utils::LineColumnLabel *m_cursorPositionLabel; + QAction *m_cursorPositionAction; }; } // namespace Internal |