Ejemplo n.º 1
0
void TextDocument::drawBackground(QPainter* painter, const QRect& bounds)
{
    if (d.highlights.isEmpty() && d.lowlight == -1)
        return;

    const int margin = qCeil(documentMargin());
    const QAbstractTextDocumentLayout* layout = documentLayout();

    static QPointer<TextLowlight> lowlightFrame = 0;
    if (!lowlightFrame)
        lowlightFrame = new TextLowlight(static_cast<QWidget*>(painter->device()));

    static QPointer<TextHighlight> highlightFrame = 0;
    if (!highlightFrame)
        highlightFrame = new TextHighlight(static_cast<QWidget*>(painter->device()));

    if (d.lowlight != -1) {
        const QAbstractTextDocumentLayout* layout = documentLayout();
        const int margin = qCeil(documentMargin());
        const QTextBlock to = findBlockByNumber(d.lowlight);
        if (to.isValid()) {
            QRect br = layout->blockBoundingRect(to).toAlignedRect();
            br.setTop(0);
            if (bounds.intersects(br)) {
                br.adjust(-margin - 1, 0, margin + 1, 2);
                painter->translate(br.topLeft());
                lowlightFrame->setGeometry(br);
                lowlightFrame->render(painter);
                painter->translate(-br.topLeft());
            }
        }
    }

    foreach (int highlight, d.highlights) {
        QTextBlock block = findBlockByNumber(highlight);
        if (block.isValid()) {
            QRect br = layout->blockBoundingRect(block).toAlignedRect();
            if (bounds.intersects(br)) {
                br.adjust(-margin - 1, 0, margin + 1, 2);
                painter->translate(br.topLeft());
                highlightFrame->setGeometry(br);
                highlightFrame->render(painter);
                painter->translate(-br.topLeft());
            }
        }
    }
}
Ejemplo n.º 2
0
void TextDocument::updateBlock(int number)
{
    if (d.visible) {
        QTextBlock block = findBlockByNumber(number);
        if (block.isValid())
            QMetaObject::invokeMethod(documentLayout(), "updateBlock", Q_ARG(QTextBlock, block));
    }
}
Ejemplo n.º 3
0
void TextModelLavaan::contentChangedHandler()
{
	_changed = true;
	_content = toPlainText();

	QTextBlock current = findBlockByNumber(_currentBlock);
	checkBlock(current);
}
Ejemplo n.º 4
0
void TextDocument::drawForeground(QPainter* painter, const QRect& bounds)
{
    const int num = blockCount() - d.uc;
    if (num > 0) {
        const QPen oldPen = painter->pen();
        const QBrush oldBrush = painter->brush();
        painter->setBrush(Qt::NoBrush);
        painter->setPen(QPen(QPalette().color(QPalette::Mid), 1, Qt::DashLine));
        QTextBlock block = findBlockByNumber(num);
        if (block.isValid()) {
            QRect br = documentLayout()->blockBoundingRect(block).toAlignedRect();
            if (bounds.intersects(br)) {
                QLine line(br.topLeft(), br.topRight());
                line.translate(0, -2);
                painter->drawLine(line);
            }
        }
        painter->setPen(oldPen);
        painter->setBrush(oldBrush);
    }
}
Ejemplo n.º 5
0
void TextModelLavaan::checkEverything()
{
	bool foundError = false;

	for (int i = 0; i < blockCount(); i++)
	{
		QTextBlock block = findBlockByNumber(i);

		checkBlock(block);
		BlockStatus *status = blockStatus(block);

		if (foundError == false && status->isError())
		{
			setErrorState(true, status->message, i, status->pos, status->length);
			foundError = true;

			QTextCursor cursor(block);

			blockSignals(true);

			/*QTextCharFormat format;

			format.setUnderlineStyle(QTextCharFormat::WaveUnderline);
			format.setUnderlineColor(Qt::red);

			if (status->length == -1)
			{
				if (i != _currentBlock)
				{
					if (status->inserted == false)
					{
						cursor.movePosition(QTextCursor::StartOfBlock);
						cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, status->pos);

						cursor.insertText(" ");
						cursor.insertText("    ", format);
						status->inserted = true;
					}
					else
					{
						cursor.movePosition(QTextCursor::StartOfBlock);
						cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, status->pos + 1);
						cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 4);

						cursor.mergeCharFormat(format);
					}
				}
			}
			else
			{
				cursor.movePosition(QTextCursor::StartOfBlock);
				cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, status->pos);
				cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, status->length);

				cursor.mergeCharFormat(format);
			}*/

			qDebug() << "error " << status->pos << " " << status->length << "\n";

			blockSignals(false);
		}
	}

	if ( ! foundError)
		setErrorState(false);
}