Exemplo n.º 1
0
void qceEqual(const QDocumentCursor& c, const QDocumentCursor& expected, const QString& message){
	QEQUAL2(c.hasSelection(),expected.hasSelection(), " got-total: "+cur2str(c)+" expected-total: "+cur2str(expected)+" more: "+message);
	QEQUAL2(c.anchorLineNumber(),expected.anchorLineNumber(), " got-total: "+cur2str(c)+" expected-total: "+cur2str(expected)+" more: "+message);
	QEQUAL2(c.anchorColumnNumber(),expected.anchorColumnNumber(), " got-total: "+cur2str(c)+" expected-total: "+cur2str(expected)+" more: "+message);
	QEQUAL2(c.lineNumber(),expected.lineNumber(), " got-total: "+cur2str(c)+" expected-total: "+cur2str(expected)+" more: "+message);
	QEQUAL2(c.columnNumber(),expected.columnNumber(), " got-total: "+cur2str(c)+" expected-total: "+cur2str(expected)+" more: "+message);
}
Exemplo n.º 2
0
int LatexTables::findNextToken(QDocumentCursor &cur,QStringList tokens,bool keepAnchor,bool backwards){
	int pos=-1;
	int nextToken=-1;
	int offset=0;
	QDocumentCursor::MoveOperation mvNextLine= backwards ? QDocumentCursor::PreviousLine : QDocumentCursor::NextLine;
	QDocumentCursor::MoveOperation mvNextChar= backwards ? QDocumentCursor::Left : QDocumentCursor::Right;
	QDocumentCursor::MoveOperation mvStartOfLine= backwards ? QDocumentCursor::EndOfLine : QDocumentCursor::StartOfLine;
	QDocumentCursor::MoveFlag mvFlag= keepAnchor ? QDocumentCursor::KeepAnchor : QDocumentCursor::MoveAnchor;
	do{
		QString line=cur.line().text();
		if(backwards){
			offset=line.length();
		}
		line=LatexParser::cutComment(line);
		if(backwards){
			offset=offset-line.length();
			QString help;
			foreach(const QChar& elem,line)
				help.prepend(elem);
			
			line=help;
		}
		
		if(line.contains("\\end{")&&!backwards) {
			nextToken=-2;
			break;
		}
		if(line.contains("{nigeb\\")&&backwards) {
			nextToken=-2;
			break;
		}
		
		pos=-1;
		for(int i=0;i<tokens.count();i++){
			QString elem=tokens.at(i);
			int colNumber= cur.columnNumber();
			if(backwards) colNumber=line.length()+offset-colNumber ;
			int zw=line.indexOf(elem,colNumber);
			if(zw>-1) {
				if(pos>zw || pos==-1){
					pos=zw;
					nextToken=i;
				}
			}
		}
		if(pos<0){
			if(!backwards&&cur.lineNumber()>=cur.document()->lineCount()-1) break;
			if(backwards&&cur.lineNumber()<=0) break;
			cur.movePosition(1,mvNextLine,mvFlag);
			cur.movePosition(1,mvStartOfLine,mvFlag);
		}
	}while(pos<0);
	if(pos>-1) {
		cur.movePosition(1,mvStartOfLine,mvFlag);
		cur.movePosition(pos+tokens.at(nextToken).length()+offset,mvNextChar,mvFlag);
	}
	return nextToken;
}
Exemplo n.º 3
0
/*!

*/
bool QHexPanel::paint(QPainter *p, QEditor *e)
{
//    qWarning("drawing Hex panel... [%i, %i, %i, %i]",
//            geometry().x(),
//            geometry().y(),
//            geometry().width(),
//            geometry().height());

#if 1
    //hexeditor->resize(geometry().size());

#else
    static QPixmap _warn(":/warning.png"), _mod(":/save.png");

    QString s;
    int xpos = 10;
    QDocumentCursor c = e->cursor();
    const QFontMetrics fm(fontMetrics());

    const int ls = fm.lineSpacing();
    const int ascent = fm.ascent() + 3;

    s = tr("Line : %1 Visual column : %2 Text column : %3")
            .arg(c.lineNumber() + 1)
            .arg(c.visualColumnNumber())
            .arg(c.columnNumber());

    p->drawText(xpos, ascent, s);
    xpos += fm.width(s) + 10;

    int sz = qMin(height(), _mod.height());
    //int lastMod = d->lastModified().secsTo(QDateTime::currentDateTime());
    //QString timeDiff = tr("(%1 min %2 s ago)").arg(lastMod / 60).arg(lastMod % 60);

    //xpos += 10;
    if ( e->isContentModified() )
    {
        p->drawPixmap(xpos, (height() - sz) / 2, sz, sz, _mod);
        //xpos += sz;
        //xpos += 10;
        //p->drawText(xpos, ascent, timeDiff);
    }
    xpos += sz + 10;
    //xpos += fm.width(timeDiff);
    //xpos += 20;

//	s = editor()->flag(QEditor::Overwrite) ? tr("OVERWRITE") : tr("INSERT");
//	p->drawText(xpos, ascent, s);
//	xpos += fm.width(s) + 10;


#endif
    return true;
}
Exemplo n.º 4
0
/*!

*/
void QStatusPanel::paint(QPainter *p, QEditor *e)
{
        //qDebug("drawing status panel... [%i, %i, %i, %i]",
        //              geometry().x(),
        //              geometry().y(),
        //              geometry().width(),
        //              geometry().height());
        static QPixmap _warn(":/warning.png");
        
        QString s;
        int xpos = 10;
        QDocumentCursor c = e->cursor();
        const QFontMetrics fm(fontMetrics());
        
        const int ls = fm.lineSpacing();
        const int ascent = fm.ascent() + 3;
        
        s = tr("Line : %1 Visual column : %2 Text column : %3")
                        .arg(c.lineNumber() + 1)
                        .arg(c.visualColumnNumber())
                        .arg(c.columnNumber());
        
        p->drawText(xpos, ascent, s);
        xpos += fm.width(s) + 10;
        
        // TODO : draw icon to show mod status
        
        s = editor()->flag(QEditor::Overwrite) ? tr("OVERWRITE") : tr("INSERT");
        p->drawText(xpos, ascent, s);
        xpos += fm.width(s) + 10;
        
        
        m_conflictSpot = 0;
        
        if ( editor()->isInConflict() )
        {
                s =  tr("Conflict");
                int w = fm.width(s) + 30;
                
                if ( xpos + w + _warn.width() < width() )
                {
                        m_conflictSpot = width() - (w + _warn.width());
                        p->drawText(width() - w + 15, ascent, s);
                        p->drawPixmap(m_conflictSpot, (ls - _warn.height()) / 2 + 2, _warn);
                } else if ( xpos + _warn.width() < width() ) {
                        m_conflictSpot = width() - _warn.width();
                        p->drawPixmap(m_conflictSpot, (ls - _warn.height()) / 2 + 2, _warn);
                }
        }
        
        setFixedHeight(ls + 4);
}
Exemplo n.º 5
0
bool LatexTables::inTableEnv(QDocumentCursor &cur){
	QDocumentCursor c(cur);
	int result=findNextToken(c,QStringList(),false,true);
	if(result!=-2) return false;
	if(c.lineNumber()==cur.lineNumber()) return false;
	QString line=c.line().text();
	int pos=line.indexOf("\\begin");
	if(pos>-1){
		QStringList values;
		LatexParser::resolveCommandOptions(line,pos,values);
		QString env=values.takeFirst();
		if(!env.startsWith("{")||!env.endsWith("}")) return -1;
		env=env.mid(1);
		env.chop(1);
		if(tabularNames.contains(env,Qt::CaseSensitive)||tabularNamesWithOneOption.contains(env,Qt::CaseSensitive)){
			int result=findNextToken(c,QStringList());
			if(result!=-2) return false;
			if(c.lineNumber()>cur.lineNumber()) return true;
		}
	}
	return false;
}
Exemplo n.º 6
0
int LatexTables::getColumn(QDocumentCursor &cur){
	QDocumentCursor c(cur);
	QStringList tokens("\\\\");
	int result=findNextToken(c,tokens,true,true);
	if(result==0) c.movePosition(2,QDocumentCursor::Right,QDocumentCursor::KeepAnchor);
	if(c.lineNumber()==cur.lineNumber() && c.selectedText().contains(QRegExp("^\\s*$"))){
		c.movePosition(1,QDocumentCursor::EndOfLine,QDocumentCursor::KeepAnchor);
		QString zw=c.selectedText();
		if(zw.contains(QRegExp("^\\s*$"))) return -1;
	}
	
	c.clearSelection();
	
	tokens << "\\&" << "&";
	int col=0;
	
	do{
		result=findNextToken(c,tokens);
		if(c.lineNumber()>cur.lineNumber()|| (c.lineNumber()==cur.lineNumber() && c.columnNumber()>cur.columnNumber())) break;
		if(result==2) col++;
	}while(result>0);
	return col;
}
Exemplo n.º 7
0
/*!

*/
bool QStatusPanel::paint(QPainter *p, QEditor *e)
{
	//qDebug("drawing status panel... [%i, %i, %i, %i]",
	//		geometry().x(),
	//		geometry().y(),
	//		geometry().width(),
	//		geometry().height());
	static QPixmap _warn(":/warning.png"), _mod(":/save.png");
	
	QString s;
	int xpos = 10;
	QDocumentCursor c = e->cursor();
	const QFontMetrics fm(fontMetrics());
	
	const int ls = fm.lineSpacing();
	const int ascent = fm.ascent() + 3;
	
	s = tr("Line : %1 Visual column : %2 Text column : %3")
			.arg(c.lineNumber() + 1)
			.arg(c.visualColumnNumber())
			.arg(c.columnNumber());
	
	p->drawText(xpos, ascent, s);
	xpos += fm.width(s) + 10;
	
	int sz = qMin(height(), _mod.height());
	//int lastMod = d->lastModified().secsTo(QDateTime::currentDateTime());
	//QString timeDiff = tr("(%1 min %2 s ago)").arg(lastMod / 60).arg(lastMod % 60);
	
	//xpos += 10;
	if ( e->isContentModified() )
	{
		p->drawPixmap(xpos, (height() - sz) / 2, sz, sz, _mod);
		//xpos += sz;
		//xpos += 10;
		//p->drawText(xpos, ascent, timeDiff);
	}
	xpos += sz + 10;
	//xpos += fm.width(timeDiff);
	//xpos += 20;
	
	s = editor()->flag(QEditor::Overwrite) ? tr("OVERWRITE") : tr("INSERT");
	p->drawText(xpos, ascent, s);
	xpos += fm.width(s) + 10;
	
	m_conflictSpot = 0;
	
	if ( editor()->isInConflict() )
	{
		s =  tr("Conflict");
		int w = fm.width(s) + 30;
		
		if ( xpos + w + _warn.width() < width() )
		{
			m_conflictSpot = width() - (w + _warn.width());
			p->drawText(width() - w + 15, ascent, s);
			p->drawPixmap(m_conflictSpot, (ls - _warn.height()) / 2 + 2, _warn);
		} else if ( xpos + _warn.width() < width() ) {
			m_conflictSpot = width() - _warn.width();
			p->drawPixmap(m_conflictSpot, (ls - _warn.height()) / 2 + 2, _warn);
		}
	}
	
	setFixedHeight(ls + 4);
	
	QTimer::singleShot(1000, this, SLOT( update() ) );
	
	return true;
}
Exemplo n.º 8
0
QString cur2str(const QDocumentCursor &c){
	if (c.hasSelection()) return QString("%1|%2|%3|%4").arg(c.anchorLineNumber()).arg(c.anchorColumnNumber()).arg(c.lineNumber()).arg(c.columnNumber());
	return QString("%1|%2").arg(c.lineNumber()).arg(c.columnNumber());
}