Esempio n. 1
0
QDocumentCursor QDocumentCursorTest::str2cur(const QString &s){
	QStringList sl=s.split("|");
	if (sl.size()==2) return doc->cursor(sl[0].toInt(),sl[1].toInt());
	else if (sl.size()==4) return doc->cursor(sl[0].toInt(),sl[1].toInt(),sl[2].toInt(),sl[3].toInt());
	else return QDocumentCursor();
	
}
void QSearchReplacePanel::on_cbSelection_toggled(bool on)
{
        if ( m_search )
                m_search->setScope(on ? editor()->cursor() : QDocumentCursor());
        
        leFind->setFocus();
}
QDocumentCursor cursorFromValue(const QScriptValue& value){
	QDocumentCursor * c = qobject_cast<QDocumentCursor*> (value.toQObject());
	if (!c) {
		if (value.engine() && value.engine()->currentContext()) value.engine()->currentContext()->throwError(scriptengine::tr("Expected cursor object"));
		return QDocumentCursor();
	}
	return *c;
}
QDocumentCursor CursorHistory::currentPos() {
	if (!currentEntryValid()) {
		validate();
	}
	if (!currentEntryValid()) {
		qDebug() << "invalid current position in CursorHistory";
		return QDocumentCursor();
	}
	return (*currentEntry).toCursor();
}
QDocumentCursor CursorHistory::forward(const QDocumentCursor &currentCursor) {
	Q_UNUSED(currentCursor);
	CursorPosList::iterator next = nextValidEntry(currentEntry);
	if (currentEntry == history.end() || next == history.end()) {
		updateNavActions();
		return QDocumentCursor();
	}
	currentEntry = next;
	updateNavActions();
	return currentPos();
}
/*!
	\internal
*/
void QCodeCompletionEngine::run()
{
	if ( m_cur.isNull() )
		return;
	
	//qDebug("complete!");
	
	complete(m_cur, m_trig);
	
	m_cur = QDocumentCursor();
	m_trig.clear();
}
void QSearchReplacePanel::on_cbCursor_toggled(bool on)
{
        if ( m_search )
        {
                m_search->setOrigin(on ? editor()->cursor() : QDocumentCursor());
                
                if ( cbHighlight->isChecked() )
                        m_search->next(false);
        }
        
        leFind->setFocus();
}
Esempio n. 8
0
/*!
	\brief Clear matches
	
	This function should be called anytime you perform a search with the HighlightAll option,
	once you're done iterating over the matches.
*/
void QDocumentSearch::clearMatches()
{
	if ( !m_editor || !m_editor->document() )
		return;
	
	//qDebug("clearing matches");
	m_cursor = QDocumentCursor();
	
	if ( m_group != -1 )
	{
		m_editor->document()->clearMatches(m_group);
		m_editor->document()->flushMatches(m_group);
		m_group = -1;
	}
	
	m_highlight.clear();
}
QDocumentCursor CursorHistory::back(const QDocumentCursor &currentCursor) {
	if (currentEntry == history.begin()) {
		updateNavActions();
		return QDocumentCursor();
	}

	// insert currentCursor to be able to go back
	if (currentCursor.isValid() && insertPos(currentCursor, false)) {
		currentEntry--;
	}

	CursorPosition pos(currentCursor);
	if (pos.isValid() && !pos.equals(*currentEntry)) {
		updateNavActions();
		return currentPos();
	}

	currentEntry = prevValidEntry(currentEntry);
	updateNavActions();
	return currentPos();
}
Esempio n. 10
0
/*!
	\return A cursor pointing to the n-th index match
	\param idx index of the match to lookup
	
	The cursor returned, if valid, delimits the match through its selection.
*/
QDocumentCursor QDocumentSearch::match(int idx) const
{
	return idx >= 0 && idx < m_highlight.count() ? m_highlight.at(idx) : QDocumentCursor();
}
QDocumentCursor getHighlightedSelectionIntern(QEditor* ed, const QString& str){
	int minLine, minCol, maxLine, maxCol;
	getHighlightedSelectionIntern(ed,minLine, minCol, maxLine, maxCol, str);
	if (minLine==-1 || maxLine==-1) return QDocumentCursor();
	return ed->document()->cursor(minLine, minCol, maxLine, maxCol);
}
void QSearchReplacePanel::on_leFind_textEdited(const QString& text)
{
        bool hadSearch = m_search;
        QDocumentCursor cur = editor()->cursor();
        
        if ( m_search ) 
        {
                cur = m_search->cursor();
                
                m_search->setSearchText(text);
                
                if ( cbCursor->isChecked() )
                {
                        QDocumentCursor c = cur;
                        c.setColumnNumber(qMin(c.anchorColumnNumber(), c.columnNumber()));
                        
                        m_search->setCursor(c);
                }
        } else {
                // TODO : make incremental search optional
                init();
        }
        
        if ( text.isEmpty() )
        {
                leFind->setStyleSheet(QString());
                return;
        }
        
        m_search->setOption(QDocumentSearch::Silent, true);
        
        find(0);
        
        m_search->setOption(QDocumentSearch::Silent, false);
        
        if ( m_search->cursor().isNull() )
        {
                leFind->setStyleSheet("QLineEdit { background: red; color : white; }");
                
                if ( hadSearch )
                {
                        m_search->setCursor(cur);
                        
                        // figure out whether other matches are availables
                        QDocumentSearch::Options opts = m_search->options();
                        opts &= ~QDocumentSearch::HighlightAll;
                        opts |= QDocumentSearch::Silent;
                        
                        QDocumentSearch temp(editor(), text, opts);
                        temp.setOrigin(QDocumentCursor());
                        temp.setScope(m_search->scope());
                        temp.next(true);
                        
                        if ( temp.cursor().isValid() )
                        {
                                // other match found from doc start
                                leFind->setStyleSheet("QLineEdit { background: yellow; color : black; }");
                                m_search->setCursor(cur.document()->cursor(0,0));
                                find(0);
                        }
                }
        } else {
                leFind->setStyleSheet(QString());
                editor()->setCursor(m_search->cursor());
        }
}