void KPrAttributeHeight::updateCache(KPrAnimationCache *cache, KPrShapeAnimation *shapeAnimation, qreal value)
{
    qreal tx = 0.0, ty = 0.0;
    KoShape * shape = shapeAnimation->shape();
    KoTextBlockData * textBlockData = shapeAnimation->textBlockData();
    QTransform transform;
    if (textBlockData) {
        if (KoTextShapeData *textShapeData = dynamic_cast<KoTextShapeData*>(shape->userData())) {
            QTextDocument *textDocument = textShapeData->document();
            for (int i = 0; i < textDocument->blockCount(); i++) {
                QTextBlock textBlock = textDocument->findBlockByNumber(i);
                if (textBlock.userData() == textBlockData) {
                    QTextLayout *layout = textBlock.layout();
                    value = value * cache->pageSize().height() / layout->boundingRect().height();
                    tx = layout->minimumWidth() * cache->zoom() / 2;
                    ty = layout->boundingRect().height() * cache->zoom() / 2;
                }
            }
        }
    }
    else {
        value = value * cache->pageSize().height() / shape->size().height();
        tx = shape->size().width() * cache->zoom() / 2;
        ty = shape->size().height() * cache->zoom() / 2;
    }
    transform.translate(tx, ty).scale(1, value).translate(-tx, -ty);
    cache->update(shape, shapeAnimation->textBlockData(), "transform", transform);
}
void KPrAttributeHeight::initCache(KPrAnimationCache *animationCache, int step, KPrShapeAnimation * shapeAnimation, qreal startValue, qreal endValue)
{
    qreal v1 = 0.0, v2 = 0.0, tx = 0.0, ty = 0.0;
    KoShape * shape = shapeAnimation->shape();
    KoTextBlockData * textBlockData = shapeAnimation->textBlockData();

    if (textBlockData) {
        if (KoTextShapeData *textShapeData = dynamic_cast<KoTextShapeData*>(shape->userData())) {
            QTextDocument *textDocument = textShapeData->document();
            for (int i = 0; i < textDocument->blockCount(); i++) {
                QTextBlock textBlock = textDocument->findBlockByNumber(i);
                if (textBlock.userData() == textBlockData) {
                    QTextLayout *layout = textBlock.layout();
                    v1 = startValue * animationCache->pageSize().height() / layout->boundingRect().height();
                    v2 = endValue * animationCache->pageSize().height() / layout->boundingRect().height();
                    tx = layout->minimumWidth() * animationCache->zoom() / 2;
                    ty = layout->boundingRect().height() * animationCache->zoom() / 2;
                }
            }
        }
    }
    else {
        v1 = startValue * animationCache->pageSize().height() / shape->size().height();
        v2 = endValue * animationCache->pageSize().height() / shape->size().height();
        tx = shape->size().width() * animationCache->zoom() / 2;
        ty = shape->size().height() * animationCache->zoom() / 2;
    }
    animationCache->init(step, shape, textBlockData, "transform", QTransform().translate(tx, ty).scale(1, v1).translate(-tx, -ty));
    animationCache->init(step + 1, shape, textBlockData, "transform", QTransform().translate(tx, ty).scale(1, v2).translate(-tx, -ty));
}
void SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd(
        SyntaxHighlighter *highlighter,
        const QFuture<HighlightingResult> &future)
{
    // find block number of last result
    int lastBlockNumber = 0;
    for (int i = future.resultCount() - 1; i >= 0; --i) {
        const HighlightingResult &result = future.resultAt(i);
        if (result.line) {
            lastBlockNumber = result.line - 1;
            break;
        }
    }

    QTextDocument *doc = highlighter->document();

    const int firstBlockToClear = lastBlockNumber + 1;
    if (firstBlockToClear <= doc->blockCount())
        return;

    QTextBlock b = doc->findBlockByNumber(firstBlockToClear);

    while (b.isValid()) {
        QVector<QTextLayout::FormatRange> noFormats;
        highlighter->setExtraFormats(b, noFormats);
        b = b.next();
    }
}
Example #4
0
TextGui::TextGui(QStringList args)
    : m_debugger(NULL),
      m_syscallListener(NULL),
      m_console(std::cin, std::cout, std::cerr),
      m_spim_syscalls(&m_console, &m_syscallListener)
{

    QString filename = args.at(1);

    QFile *f = new QFile(filename);
    if (!f->exists()) {
        cerr << "error, cannot find file " << filename.toStdString() << endl;
        exit(1);
    }

    if (!f->open(QIODevice::ReadOnly | QFile::Text)) {
        cerr << "error opening file " << filename.toStdString() << endl;
        exit(1);
    }

    QTextDocument p();
    QTextDocument *doc = new QTextDocument();

    doc->setPlainText(f->readAll());
    f->close();

    if (VERBOSE) {
        cerr << "Parsing file: " << f->fileName().toStdString() << endl;
        cerr << "No Lines: " << doc->blockCount() << endl << endl;
    }

    ParseList* parseList = Parser::parseDocument(doc);


    setupPlugins();

    if (VERBOSE) cerr << "Executing the program.\n";



    // TIM, the NULL in the Debugger's constructor should be an instance of SyscallListener.
    // No more connections since it's all happening in the debugger thread.
    // Good news is it should be really easy to subclass SycallHandler and register it w/
    // an instance of SyscallListener to get the same functionality (when we have more time...)

    // ... later, never mind, it should work no; just don't need the signals/slots


    m_debugger = new Debugger(&m_syscallListener, parseList);
//   QObject::connect(m_debugger->getState(), SIGNAL(syscall(int, int)), this, SLOT(syscallReceived(int,int)));
    QObject::connect(m_debugger, SIGNAL(programTerminated(int)), this, SLOT(programTerminated(int)));
}
Example #5
0
// 遍历文本块
void MainWindow::showTextBlock()
{
    QTextDocument *document = ui->textEdit->document();
    // 获取文档的第一个文本块
    QTextBlock block = document->firstBlock();
    for(int i=0; i<document->blockCount(); i++){
        qDebug() << tr("文本块%1,文本块首行行号为:%2,长度为:%3,内容为:")
                    .arg(i).arg(block.firstLineNumber()).arg(block.length())
                 << block.text();
        // 获取下一个文本块
        block = block.next();
    }
}
Example #6
0
QString CodeEditor::getCode()
{
	QTextDocument *doc = this->document();
	int bc = doc->blockCount();
	QString str;
	for(int i=0; i<bc; ++i){
		QTextBlock block = doc->findBlockByNumber(i);
		QString s = block.text();
		str.append(s);
		if(!s.trimmed().isEmpty())
			str.append('\n');
	}

	return str;
}
Example #7
0
void Logview::logMessage(const Logger::LOG_LEVEL_T level, const QString& msg)
{
    QScrollBar* pBar = ui.logFileEdit->verticalScrollBar();
    bool atBottom = true;
    if (pBar)
    {
        if (pBar->value() < pBar->maximum())
        {
            atBottom = false;
        }
    }

    // Remove an excess of blocks
    QTextDocument* doc = ui.logFileEdit->document();
    if (doc->blockCount() >= 1999)
    {
        doc->setMaximumBlockCount(1000);
        doc->setMaximumBlockCount(2000);
    }

    QTextCursor cur = ui.logFileEdit->textCursor();


    cur.movePosition(QTextCursor::End);

    QTextCharFormat fmt = cur.charFormat();
    fmt.setForeground(QBrush(mColors[level]));
    cur.insertText(msg,fmt);

    cur.insertBlock();

    // Re-get the bar in case it just got added
    if (atBottom)
    {
        pBar = ui.logFileEdit->verticalScrollBar();
        if (pBar)
        {
            pBar->setValue(pBar->maximum());
        }
    }
}
Example #8
0
/*! \reimp
 */
void TextDocumentLayout::documentChanged(int from, int /*charsRemoved*/, int charsAdded)
{
    QTextDocument *doc = document();
    int newBlockCount = doc->blockCount();

    QTextBlock changeStartBlock = doc->findBlock(from);
    QTextBlock changeEndBlock = doc->findBlock(qMax(0, from + charsAdded - 1));

    if (changeStartBlock == changeEndBlock && newBlockCount == d->blockCount) {
        QTextBlock block = changeStartBlock;
        if (block.isValid()  && block.layout()->lineCount()) {
            QRectF oldBr = blockBoundingRect(block);
            layoutBlock(block);
            QRectF newBr = blockBoundingRect(block);
            if (newBr.height() == oldBr.height()) {
                if (!d->blockUpdate)
                    emit updateBlock(block);
                return;
            }
        }
    } else {
        QTextBlock block = changeStartBlock;
        do {
            block.clearLayout();
            if (block == changeEndBlock)
                break;
            block = block.next();
        } while(block.isValid());
    }

    if (newBlockCount != d->blockCount) {

        int changeEnd = changeEndBlock.blockNumber();
        int blockDiff = newBlockCount - d->blockCount;
        int oldChangeEnd = changeEnd - blockDiff;

        if (d->maximumWidthBlockNumber > oldChangeEnd)
            d->maximumWidthBlockNumber += blockDiff;

        d->blockCount = newBlockCount;
        if (d->blockCount == 1)
            d->maximumWidth = blockWidth(doc->firstBlock());

        if (!d->blockDocumentSizeChanged)
            emit documentSizeChanged(documentSize());

        if (blockDiff == 1 && changeEnd == newBlockCount -1 ) {
            if (!d->blockUpdate)
            {
                QTextBlock b = changeStartBlock;
                for(;;) {
                    emit updateBlock(b);
                    if (b == changeEndBlock)
                        break;
                    b = b.next();
                }
            }
            return;
        }
    }
    if (!d->blockUpdate)
        emit update(QRectF(0., -doc->documentMargin(), 1000000000., 1000000000.)); // optimization potential
}
void SemanticHighlighter::incrementalApplyExtraAdditionalFormats(
        SyntaxHighlighter *highlighter,
        const QFuture<HighlightingResult> &future,
        int from, int to,
        const QHash<int, QTextCharFormat> &kindToFormat)
{
    if (to <= from)
        return;

    const int firstResultBlockNumber = future.resultAt(from).line - 1;

    // blocks between currentBlockNumber and the last block with results will
    // be cleaned of additional extra formats if they have no results
    int currentBlockNumber = 0;
    for (int i = from - 1; i >= 0; --i) {
        const HighlightingResult &result = future.resultAt(i);
        const int blockNumber = result.line - 1;
        if (blockNumber < firstResultBlockNumber) {
            // stop! found where last format stopped
            currentBlockNumber = blockNumber + 1;
            // add previous results for the same line to avoid undoing their formats
            from = i + 1;
            break;
        }
    }

    QTextDocument *doc = highlighter->document();
    QTC_ASSERT(currentBlockNumber < doc->blockCount(), return);
    QTextBlock b = doc->findBlockByNumber(currentBlockNumber);

    HighlightingResult result = future.resultAt(from);
    for (int i = from; i < to && b.isValid(); ) {
        const int blockNumber = result.line - 1;
        QTC_ASSERT(blockNumber < doc->blockCount(), return);

        // clear formats of blocks until blockNumber
        while (currentBlockNumber < blockNumber) {
            QVector<QTextLayout::FormatRange> noFormats;
            highlighter->setExtraFormats(b, noFormats);
            b = b.next();
            ++currentBlockNumber;
        }

        // collect all the formats for the current line
        QVector<QTextLayout::FormatRange> formats;
        formats.reserve(to - from);
        forever {
            QTextLayout::FormatRange formatRange;

            formatRange.format = textCharFormatForResult(result, kindToFormat);
            if (formatRange.format.isValid()) {
                formatRange.start = result.column - 1;
                formatRange.length = result.length;
                formats.append(formatRange);
            }

            ++i;
            if (i >= to)
                break;
            result = future.resultAt(i);
            const int nextBlockNumber = result.line - 1;
            if (nextBlockNumber != blockNumber)
                break;
        }
        highlighter->setExtraFormats(b, formats);
        b = b.next();
        ++currentBlockNumber;
    }
}