void CppOutlineWidget::onItemActivated(const QModelIndex &index) { if (!index.isValid()) return; updateTextCursor(index); m_editor->setFocus(); }
void QmlJSOutlineWidget::updateSelectionInText(const QItemSelection &selection) { if (!syncCursor()) return; if (!selection.indexes().isEmpty()) { QModelIndex index = selection.indexes().first(); updateTextCursor(index); } }
SourceViewerWidget::SourceViewerWidget(QWidget *parent) : QPlainTextEdit(parent), m_marginWidget(NULL), m_findFlags(WebWidget::NoFlagsFind), m_zoom(100) { new SyntaxHighlighter(document()); setZoom(SettingsManager::getValue(QLatin1String("Content/DefaultZoom")).toInt()); optionChanged(QLatin1String("SourceViewer/ShowLineNumbers"), SettingsManager::getValue(QLatin1String("SourceViewer/ShowLineNumbers"))); optionChanged(QLatin1String("SourceViewer/WrapLines"), SettingsManager::getValue(QLatin1String("SourceViewer/WrapLines"))); connect(this, SIGNAL(textChanged()), this, SLOT(updateSelection())); connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(updateTextCursor())); connect(SettingsManager::getInstance(), SIGNAL(valueChanged(QString,QVariant)), this, SLOT(optionChanged(QString,QVariant))); }
SourceViewerWidget::SourceViewerWidget(QWidget *parent) : QPlainTextEdit(parent), m_marginWidget(nullptr), m_findFlags(WebWidget::NoFlagsFind), m_zoom(100) { new SyntaxHighlighter(document()); setZoom(SettingsManager::getValue(SettingsManager::Content_DefaultZoomOption).toInt()); optionChanged(SettingsManager::Interface_ShowScrollBarsOption, SettingsManager::getValue(SettingsManager::Interface_ShowScrollBarsOption)); optionChanged(SettingsManager::SourceViewer_ShowLineNumbersOption, SettingsManager::getValue(SettingsManager::SourceViewer_ShowLineNumbersOption)); optionChanged(SettingsManager::SourceViewer_WrapLinesOption, SettingsManager::getValue(SettingsManager::SourceViewer_WrapLinesOption)); connect(this, SIGNAL(textChanged()), this, SLOT(updateSelection())); connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(updateTextCursor())); connect(SettingsManager::getInstance(), SIGNAL(valueChanged(int,QVariant)), this, SLOT(optionChanged(int,QVariant))); }
bool SourceViewerWidget::findText(const QString &text, WebWidget::FindFlags flags) { const bool isTheSame(text == m_findText); m_findText = text; m_findFlags = flags; if (!text.isEmpty()) { QTextDocument::FindFlags nativeFlags; if (flags.testFlag(WebWidget::BackwardFind)) { nativeFlags |= QTextDocument::FindBackward; } if (flags.testFlag(WebWidget::CaseSensitiveFind)) { nativeFlags |= QTextDocument::FindCaseSensitively; } QTextCursor findTextCursor(m_findTextAnchor); if (!isTheSame) { findTextCursor = textCursor(); } else if (!flags.testFlag(WebWidget::BackwardFind)) { findTextCursor.setPosition(findTextCursor.selectionEnd(), QTextCursor::MoveAnchor); } m_findTextAnchor = document()->find(text, findTextCursor, nativeFlags); if (m_findTextAnchor.isNull()) { m_findTextAnchor = textCursor(); m_findTextAnchor.setPosition((flags.testFlag(WebWidget::BackwardFind) ? (document()->characterCount() - 1) : 0), QTextCursor::MoveAnchor); m_findTextAnchor = document()->find(text, m_findTextAnchor, nativeFlags); } if (!m_findTextAnchor.isNull()) { const QTextCursor currentTextCursor(textCursor()); disconnect(this, SIGNAL(cursorPositionChanged()), this, SLOT(updateTextCursor())); setTextCursor(m_findTextAnchor); ensureCursorVisible(); const QPoint position(horizontalScrollBar()->value(), verticalScrollBar()->value()); setTextCursor(currentTextCursor); horizontalScrollBar()->setValue(position.x()); verticalScrollBar()->setValue(position.y()); connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(updateTextCursor())); } } m_findTextSelection = m_findTextAnchor; updateSelection(); return !m_findTextAnchor.isNull(); }