template<> void
QConsoleWidget::_pf<void, UpdateAfterEditorBlockFormat>(
        QConsoleWidget * thisp
        ) {
    //TODO: UpdateAfterEditorBlockFormat
    auto doc_ = thisp->document();
    auto block_ = doc_->findBlock(thisp->promptEndPos_);
    block_ = block_.next();
    while (block_.isValid()){
        {
            QTextCursor cursor_(block_);
            cursor_.setPosition(block_.position());
            cursor_.select(QTextCursor::BlockUnderCursor);
            cursor_.mergeCharFormat(thisp->thisp->textCharFormat);
            thisp->setTextCursor(cursor_);
        }
        {
            QTextCursor cursor_(block_);
            auto bf_ = block_.blockFormat();
            bf_.setTextIndent(0);
            cursor_.setBlockFormat(bf_);
            thisp->setTextCursor(cursor_);
            block_ = block_.next();
        }
    }

}
Beispiel #2
0
/*!
  \since 4.7

  Returns the resolved text direction.

  If the block has no explicit direction set, it will resolve the
  direction from the blocks content. Returns either Qt::LeftToRight
  or Qt::RightToLeft.

  \sa QTextFormat::layoutDirection(), QString::isRightToLeft(), Qt::LayoutDirection
*/
Qt::LayoutDirection QTextBlock::textDirection() const
{
    Qt::LayoutDirection dir = blockFormat().layoutDirection();
    if (dir != Qt::LayoutDirectionAuto)
        return dir;

    dir = p->defaultTextOption.textDirection();
    if (dir != Qt::LayoutDirectionAuto)
        return dir;

    const QString buffer = p->buffer();

    const int pos = position();
    QTextDocumentPrivate::FragmentIterator it = p->find(pos);
    QTextDocumentPrivate::FragmentIterator end = p->find(pos + length() - 1); // -1 to omit the block separator char
    for (; it != end; ++it) {
        const QTextFragmentData * const frag = it.value();
        const QChar *p = buffer.constData() + frag->stringPosition;
        const QChar * const end = p + frag->size_array[0];
        while (p < end) {
            switch(QChar::direction(p->unicode()))
            {
            case QChar::DirL:
                return Qt::LeftToRight;
            case QChar::DirR:
            case QChar::DirAL:
                return Qt::RightToLeft;
            default:
                break;
            }
            ++p;
        }
    }
    return Qt::LeftToRight;
}
Beispiel #3
0
/*!
    If the block represents a list item, returns the list that the item belongs
    to; otherwise returns 0.
*/
QTextList *QTextBlock::textList() const
{
    if (!isValid())
        return 0;

    const QTextBlockFormat fmt = blockFormat();
    QTextObject *obj = p->document()->objectForFormat(fmt);
    return qobject_cast<QTextList *>(obj);
}
void QConsoleWidget::endEvals() {
	/* 
	当此函栈反解的时候eval才结束
	提前结束eval会出现逻辑错误
	*/
	class EndEvalsLock__ {
		QConsoleWidget * __this_0_;
	public:
		EndEvalsLock__(QConsoleWidget * _t_):
			__this_0_(_t_){
			__this_0_->isEvaling_ = true;
		}
		~EndEvalsLock__() {
			__this_0_->isEvaling_ = false;
		}
	};
	EndEvalsLock__ __lock__this__(this);

	bool need_update_charFormate__ = false;
    do{//: get all command information here
        auto doc_ = this->document();
        doc_->clearUndoRedoStacks();
        auto block_ = doc_->findBlock( this->promptEndPos_);
		
		/*
		当clear and save 时调用
		*/
		if (block_.isValid() == false) { 
			need_update_charFormate__ = true;
			break; 
		}
		
		{
			QTextCursor tc_( block_ );
			auto bf_ = block_.blockFormat();
			bf_.setTextIndent(0);
			tc_.setBlockFormat( bf_ );
			this->setTextCursor(tc_);
		}

	} while (0);

    setPrompt( getPrompt() );
    this->setUndoRedoEnabled(true);
	_pf<void, EnableActions>(this);

	if ( need_update_charFormate__ ) {
		this->updateCharFormat();
	}
}
template<> void
QConsoleWidget::_pf<void, UpdateOnEditorBlockFormat>(
        QConsoleWidget * thisp
        ) {
    auto doc_ = thisp->document();
    auto block_ = doc_->findBlock( thisp->promptEndPos_ );
    if(block_.isValid()) {
		 
		{
			QTextCursor cursor_ = thisp->textCursor();
			cursor_.setPosition(thisp->promptEndPos_);
			thisp->setTextCursor(cursor_);
		}

        {
            QTextCursor cursor_(block_);
			cursor_.setPosition(thisp->promptEndPos_);
            cursor_.select(QTextCursor::BlockUnderCursor);
            cursor_.mergeCharFormat( thisp->thisp->textCharFormat );
            thisp->setTextCursor( cursor_ );
        }

		{
			QTextCursor cursor_ = thisp->textCursor();
			cursor_.clearSelection();
			thisp->setTextCursor(cursor_);
		}

        {
            QTextCursor cursor_(block_);
            auto bf_ = block_.blockFormat();
            bf_.setTextIndent( thisp->thisp->width() );
            cursor_.mergeBlockFormat(bf_);
            thisp->setTextCursor(cursor_);
        }

		 
    }
    else {
        return;
    }
    _pf<void, UpdatePromptWidget>(thisp);
    _pf<void, MoveToEnd>(thisp);
}
KoShape *KPrPlaceholderTextStrategy::createShape(KoDocumentResourceManager *documentResources)
{
    KoShape * shape = KPrPlaceholderStrategy::createShape(documentResources);
    if ( m_textShape ) {
        KoTextShapeData * data = qobject_cast<KoTextShapeData*>( m_textShape->userData() );
        KoTextShapeData * newData = qobject_cast<KoTextShapeData*>( shape->userData() );
        if ( data && newData ) {
            QTextCursor cursor( data->document() );
            QTextCursor newCursor( newData->document() );
            KoTextDocument textDocument( newData->document() );

            QTextBlockFormat blockFormat( cursor.blockFormat() );
            newCursor.setBlockFormat( blockFormat );

            QTextCharFormat chatFormat( cursor.blockCharFormat() );
            newCursor.setBlockCharFormat( chatFormat );
        }
    }
    return shape;
}