示例#1
0
void MarkerWidget::contextMenuEvent( QContextMenuEvent *e )
{
    QPopupMenu m( 0, "editor_breakpointsmenu" );

    int toggleBreakPoint = 0;
//    int editBreakpoints = 0;

    QTextParagraph *p = ( (Editor*)viewManager->currentView() )->document()->firstParagraph();
    int yOffset = ( (Editor*)viewManager->currentView() )->contentsY();
    bool supports = ( (Editor*)viewManager->currentView() )->supportsBreakPoints();
    while ( p && supports ) {
	if ( e->y() >= p->rect().y() - yOffset && e->y() <= p->rect().y() + p->rect().height() - yOffset ) {
	    if ( ( (ParagData*)p->extraData() )->marker == ParagData::Breakpoint )
		toggleBreakPoint = m.insertItem( tr( "Clear Breakpoint\tF9" ) );
	    else
		toggleBreakPoint = m.insertItem( tr( "Set Breakpoint\tF9" ) );
// 	    editBreakpoints = m.insertItem( tr( "Edit Breakpoints..." ) );
	    m.insertSeparator();
	    break;
	}
	p = p->next();
    }

    const int collapseAll = m.insertItem( tr( "Collapse All" ) );
    const int expandAll = m.insertItem( tr( "Expand All" ) );
    const int collapseFunctions = m.insertItem( tr( "Collapse all Functions" ) );
    const int expandFunctions = m.insertItem( tr( "Expand all Functions" ) );

    int res = m.exec( e->globalPos() );
    if ( res == -1)
	return;

    if ( res == collapseAll ) {
	emit collapse( TRUE );
    } else if ( res == collapseFunctions ) {
	emit collapse( FALSE );
    } else if ( res == expandAll ) {
	emit expand( TRUE );
    } else if ( res == expandFunctions ) {
	emit expand( FALSE );
    } else if ( res == toggleBreakPoint ) {
	if ( ( (ParagData*)p->extraData() )->marker == ParagData::Breakpoint ) {
	    ( (ParagData*)p->extraData() )->marker = ParagData::NoMarker;
	} else {
	    bool ok;
	    isBreakpointPossible( ok, ( (Editor*)viewManager->currentView() )->text(), p->paragId() );
	    if ( ok )
		( (ParagData*)p->extraData() )->marker = ParagData::Breakpoint;
	    else
		emit showMessage( tr( "<font color=red>Can't set breakpoint here!</font>" ) );
	}
//    } else if ( res == editBreakpoints ) {
//	emit editBreakPoints();
    }
    doRepaint();
    emit markersChanged();
}
示例#2
0
void MarkerWidget::mousePressEvent( QMouseEvent *e )
{
    if ( e->button() != LeftButton )
	return;
    bool supports = ( (Editor*)viewManager->currentView() )->supportsBreakPoints();
    QTextParagraph *p = ( (Editor*)viewManager->currentView() )->document()->firstParagraph();
    int yOffset = ( (Editor*)viewManager->currentView() )->contentsY();
    while ( p ) {
	if ( e->y() >= p->rect().y() - yOffset && e->y() <= p->rect().y() + p->rect().height() - yOffset ) {
	    QTextParagraphData *d = p->extraData();
	    if ( !d )
		return;
	    ParagData *data = (ParagData*)d;
	    if ( supports && ( e->x() < width() - 15 ) ) {
		if ( data->marker == ParagData::Breakpoint ) {
		    data->marker = ParagData::NoMarker;
		} else {
		    bool ok = TRUE;
		    isBreakpointPossible( ok, ( (Editor*)viewManager->currentView() )->text(), p->paragId() );
		    if ( ok )
			data->marker = ParagData::Breakpoint;
		    else
			emit showMessage( tr( "<font color=red>Can't set breakpoint here!</font>" ) );
		}
	    } else {
		if ( data->lineState == ParagData::FunctionStart ) {
		    if ( data->functionOpen )
			emit collapseFunction( p );
		    else
			emit expandFunction( p );
		}
	    }
	    break;
	}
	p = p->next();
    }
    doRepaint();
    emit markersChanged();
}
示例#3
0
bool ParenMatcher::checkOpenParen( QTextCursor *cursor )
{
    if ( !cursor->paragraph()->extraData() )
	return FALSE;
    ParenList parenList = ( (ParagData*)cursor->paragraph()->extraData() )->parenList;

    Paren openParen, closedParen;
    QTextParagraph *closedParenParag = cursor->paragraph();

    int i = 0;
    int ignore = 0;
    bool foundOpen = FALSE;
    QChar c = cursor->paragraph()->at( cursor->index() )->c;
    for (;;) {
	if ( !foundOpen ) {
	    if ( i >= (int)parenList.count() )
		goto bye;
	    openParen = parenList[ i ];
	    if ( openParen.pos != cursor->index() ) {
		++i;
		continue;
	    } else {
		foundOpen = TRUE;
		++i;
	    }
	}
	
	if ( i >= (int)parenList.count() ) {
	    for (;;) {
		closedParenParag = closedParenParag->next();
		if ( !closedParenParag )
		    goto bye;
		if ( closedParenParag->extraData() &&
		     ( (ParagData*)closedParenParag->extraData() )->parenList.count() > 0 ) {
		    parenList = ( (ParagData*)closedParenParag->extraData() )->parenList;
		    break;
		}
	    }
	    i = 0;
	}
	
	closedParen = parenList[ i ];
	if ( closedParen.type == Paren::Open ) {
	    ignore++;
	    ++i;
	    continue;
	} else {
	    if ( ignore > 0 ) {
		ignore--;
		++i;
		continue;
	    }

	    int id = Match;
	    if ( c == '{' && closedParen.chr != '}' ||
		 c == '(' && closedParen.chr != ')' ||
		 c == '[' && closedParen.chr != ']' )
		id = Mismatch;
	    cursor->document()->setSelectionStart( id, *cursor );
	    int tidx = cursor->index();
	    QTextParagraph *tstring = cursor->paragraph();
	    cursor->setParagraph( closedParenParag );
	    cursor->setIndex( closedParen.pos + 1 );
	    cursor->document()->setSelectionEnd( id, *cursor );
	    cursor->setParagraph( tstring );
	    cursor->setIndex( tidx );
	    return TRUE;
	}
    }

 bye:
    return FALSE;
}
示例#4
0
bool ParenMatcher::checkClosedParen( QTextCursor *cursor )
{
    if ( !cursor->paragraph()->extraData() )
	return FALSE;
    ParenList parenList = ( (ParagData*)cursor->paragraph()->extraData() )->parenList;

    Paren openParen, closedParen;
    QTextParagraph *openParenParag = cursor->paragraph();

    int i = (int)parenList.count() - 1;
    int ignore = 0;
    bool foundClosed = FALSE;
    QChar c = cursor->paragraph()->at( cursor->index() - 1 )->c;
    for (;;) {
	if ( !foundClosed ) {
	    if ( i < 0 )
		goto bye;
	    closedParen = parenList[ i ];
	    if ( closedParen.pos != cursor->index() - 1 ) {
		--i;
		continue;
	    } else {
		foundClosed = TRUE;
		--i;
	    }
	}
	
	if ( i < 0 ) {
	    for (;;) {
		openParenParag = openParenParag->prev();
		if ( !openParenParag )
		    goto bye;
		if ( openParenParag->extraData() &&
		     ( (ParagData*)openParenParag->extraData() )->parenList.count() > 0 ) {
		    parenList = ( (ParagData*)openParenParag->extraData() )->parenList;
		    break;
		}
	    }
	    i = (int)parenList.count() - 1;
	}
	
	openParen = parenList[ i ];
	if ( openParen.type == Paren::Closed ) {
	    ignore++;
	    --i;
	    continue;
	} else {
	    if ( ignore > 0 ) {
		ignore--;
		--i;
		continue;
	    }
	
	    int id = Match;
	    if ( c == '}' && openParen.chr != '{' ||
		 c == ')' && openParen.chr != '(' ||
		 c == ']' && openParen.chr != '[' )
		id = Mismatch;
	    cursor->document()->setSelectionStart( id, *cursor );
	    int tidx = cursor->index();
	    QTextParagraph *tstring = cursor->paragraph();
	    cursor->setParagraph( openParenParag );
	    cursor->setIndex( openParen.pos );
	    cursor->document()->setSelectionEnd( id, *cursor );
	    cursor->setParagraph( tstring );
	    cursor->setIndex( tidx );
	    return TRUE;
	}
    }

 bye:
    return FALSE;
}
示例#5
0
void MarkerWidget::paintEvent( QPaintEvent * )
{
    buffer.fill( backgroundColor() );

    QTextParagraph *p = ( (Editor*)viewManager->currentView() )->document()->firstParagraph();
    QPainter painter( &buffer );
    int yOffset = ( (Editor*)viewManager->currentView() )->contentsY();
    while ( p ) {
	if ( !p->isVisible() ) {
	    p = p->next();
	    continue;
	}
	if ( p->rect().y() + p->rect().height() - yOffset < 0 ) {
	    p = p->next();
	    continue;
	}
	if ( p->rect().y() - yOffset > height() )
	    break;
	if ( !((p->paragId() + 1) % 10) ) {
	    painter.save();
	    painter.setPen( colorGroup().dark() );
	    painter.drawText( 0, p->rect().y() - yOffset, width() - 20, p->rect().height(),
			      Qt::AlignRight | Qt::AlignTop, QString::number( p->paragId() + 1 ) );
	    painter.restore();
	}
	ParagData *paragData = (ParagData*)p->extraData();
	if ( paragData ) {
	    switch ( paragData->marker ) {
	    case ParagData::Error:
		painter.drawPixmap( 3, p->rect().y() +
				    ( p->rect().height() - errorPixmap->height() ) / 2 -
				    yOffset, *errorPixmap );
		break;
	    case ParagData::Breakpoint:
		painter.drawPixmap( 3, p->rect().y() +
				    ( p->rect().height() - breakpointPixmap->height() ) / 2 -
				    yOffset, *breakpointPixmap );
		break;
	    default:
		break;
	    }
	    switch ( paragData->lineState ) {
	    case ParagData::FunctionStart:
		painter.setPen( colorGroup().foreground() );
		painter.setBrush( colorGroup().base() );
		painter.drawLine( width() - 11, p->rect().y() - yOffset,
				  width() - 11, p->rect().y() + p->rect().height() - yOffset );
		painter.drawRect( width() - 15, p->rect().y() + ( p->rect().height() - 9 ) / 2 - yOffset, 9, 9 );
		painter.drawLine( width() - 13, p->rect().y() + ( p->rect().height() - 9 ) / 2 - yOffset + 4,
				  width() - 9, p->rect().y() +
				  ( p->rect().height() - 9 ) / 2 - yOffset + 4 );
		if ( !paragData->functionOpen )
		    painter.drawLine( width() - 11,
				      p->rect().y() + ( p->rect().height() - 9 ) / 2 - yOffset + 2,
				      width() - 11,
				      p->rect().y() +
				      ( p->rect().height() - 9 ) / 2 - yOffset + 6 );
		break;
	    case ParagData::InFunction:
		painter.setPen( colorGroup().foreground() );
		painter.drawLine( width() - 11, p->rect().y() - yOffset,
				  width() - 11, p->rect().y() + p->rect().height() - yOffset );
		break;
	    case ParagData::FunctionEnd:
		painter.setPen( colorGroup().foreground() );
		painter.drawLine( width() - 11, p->rect().y() - yOffset,
				  width() - 11, p->rect().y() + p->rect().height() - yOffset );
		painter.drawLine( width() - 11, p->rect().y() + p->rect().height() - yOffset,
				  width() - 7, p->rect().y() + p->rect().height() - yOffset );
		break;
	    default:
		break;
	    }
	    if ( paragData->step )
		painter.drawPixmap( 3, p->rect().y() +
				    ( p->rect().height() - stepPixmap->height() ) / 2 -
				    yOffset, *stepPixmap );
	    if ( paragData->stackFrame )
		painter.drawPixmap( 3, p->rect().y() +
				    ( p->rect().height() - stackFrame->height() ) / 2 -
				    yOffset, *stackFrame );
	}
	p = p->next();
    }
    painter.end();

    bitBlt( this, 0, 0, &buffer );
}