当前位置: 首页>>代码示例>>C++>>正文


C++ QTextDocument::blockSignals方法代码示例

本文整理汇总了C++中QTextDocument::blockSignals方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocument::blockSignals方法的具体用法?C++ QTextDocument::blockSignals怎么用?C++ QTextDocument::blockSignals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTextDocument的用法示例。


在下文中一共展示了QTextDocument::blockSignals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: loadFile

void Document::loadFile(const QString& filename, int position)
{
    if (filename.isEmpty()) {
        return;
    }

    // Cache contents
    QFile::copy(filename, g_cache_path + m_cache_filename);

    // Load text area contents
    QTextDocument* document = m_text->document();
    m_text->blockSignals(true);
    document->blockSignals(true);

    document->setUndoRedoEnabled(false);
    if (!m_rich_text) {
        QFile file(filename);
        if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
            QTextStream stream(&file);
            stream.setCodec(QTextCodec::codecForName("UTF-8"));
            stream.setAutoDetectUnicode(true);

            QTextCursor cursor(document);
            while (!stream.atEnd()) {
                cursor.insertText(stream.read(8192));
                QApplication::processEvents();
            }
            file.close();
        }
    } else {
        QFile file(filename);
        if (file.open(QIODevice::ReadOnly)) {
            RTF::Reader reader;
            reader.read(&file, document);
            file.close();
            if (reader.hasError()) {
                QMessageBox::warning(this, tr("Sorry"), reader.errorString());
            }
        }
    }
    document->setUndoRedoEnabled(true);
    document->setModified(false);

    document->blockSignals(false);
    m_text->blockSignals(false);

    // Restore cursor position
    scrollBarRangeChanged(m_scrollbar->minimum(), m_scrollbar->maximum());
    QTextCursor cursor = m_text->textCursor();
    if (position != -1) {
        cursor.setPosition(position);
    } else {
        cursor.movePosition(QTextCursor::End);
    }
    m_text->setTextCursor(cursor);
    centerCursor(true);

    // Update details
    m_cached_stats.clear();
    calculateWordCount();
    m_highlighter->rehighlight();
}
开发者ID:Fusion,项目名称:focuswriter,代码行数:62,代码来源:document.cpp

示例2: loadFromXml

void loadFromXml( mlt_producer producer, QGraphicsScene *scene, const char *templateXml, const char *templateText )
{
	scene->clear();
	mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
	QDomDocument doc;
	QString data = QString::fromUtf8(templateXml);
	QString replacementText = QString::fromUtf8(templateText);
	doc.setContent(data);
	QDomElement title = doc.documentElement();

	// Check for invalid title
	if ( title.isNull() || title.tagName() != "kdenlivetitle" ) return;
	
	// Check title locale
	if ( title.hasAttribute( "LC_NUMERIC" ) ) {
	    QString locale = title.attribute( "LC_NUMERIC" );
	    QLocale::setDefault( locale );
	}
	
        int originalWidth;
        int originalHeight;
	if ( title.hasAttribute("width") ) {
            originalWidth = title.attribute("width").toInt();
            originalHeight = title.attribute("height").toInt();
            scene->setSceneRect(0, 0, originalWidth, originalHeight);
        }
        else {
            originalWidth = scene->sceneRect().width();
            originalHeight = scene->sceneRect().height();
        }
        if ( title.hasAttribute( "out" ) ) {
            mlt_properties_set_position( producer_props, "_animation_out", title.attribute( "out" ).toDouble() );
        }
        else {
            mlt_properties_set_position( producer_props, "_animation_out", mlt_producer_get_out( producer ) );
        }
        
	mlt_properties_set_int( producer_props, "_original_width", originalWidth );
	mlt_properties_set_int( producer_props, "_original_height", originalHeight );

	QDomNode node;
	QDomNodeList items = title.elementsByTagName("item");
        for ( int i = 0; i < items.count(); i++ )
	{
		QGraphicsItem *gitem = NULL;
		node = items.item( i );
		QDomNamedNodeMap nodeAttributes = node.attributes();
		int zValue = nodeAttributes.namedItem( "z-index" ).nodeValue().toInt();
		if ( zValue > -1000 )
		{
			if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsTextItem" )
			{
				QDomNamedNodeMap txtProperties = node.namedItem( "content" ).attributes();
				QFont font( txtProperties.namedItem( "font" ).nodeValue() );
				QDomNode propsNode = txtProperties.namedItem( "font-bold" );
				if ( !propsNode.isNull() )
				{
					// Old: Bold/Not bold.
					font.setBold( propsNode.nodeValue().toInt() );
				}
				else
				{
					// New: Font weight (QFont::)
					font.setWeight( txtProperties.namedItem( "font-weight" ).nodeValue().toInt() );
				}
				font.setItalic( txtProperties.namedItem( "font-italic" ).nodeValue().toInt() );
				font.setUnderline( txtProperties.namedItem( "font-underline" ).nodeValue().toInt() );
				// Older Kdenlive version did not store pixel size but point size
				if ( txtProperties.namedItem( "font-pixel-size" ).isNull() )
				{
					QFont f2;
					f2.setPointSize( txtProperties.namedItem( "font-size" ).nodeValue().toInt() );
					font.setPixelSize( QFontInfo( f2 ).pixelSize() );
				}
				else
					font.setPixelSize( txtProperties.namedItem( "font-pixel-size" ).nodeValue().toInt() );
				QColor col( stringToColor( txtProperties.namedItem( "font-color" ).nodeValue() ) );
				QString text = node.namedItem( "content" ).firstChild().nodeValue();
				if ( !replacementText.isEmpty() )
				{
					text = text.replace( "%s", replacementText );
				}
				QGraphicsTextItem *txt = scene->addText(text, font);
				if (txtProperties.namedItem("font-outline").nodeValue().toDouble()>0.0){
					QTextDocument *doc = txt->document();
					// Make sure some that the text item does not request refresh by itself
					doc->blockSignals(true);
					QTextCursor cursor(doc);
					cursor.select(QTextCursor::Document);
					QTextCharFormat format;
					format.setTextOutline(
							QPen(QColor( stringToColor( txtProperties.namedItem( "font-outline-color" ).nodeValue() ) ),
							txtProperties.namedItem("font-outline").nodeValue().toDouble(),
							Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin)
					);
					format.setForeground(QBrush(col));

					cursor.mergeCharFormat(format);
				} else {
					txt->setDefaultTextColor( col );
//.........这里部分代码省略.........
开发者ID:agpanarin,项目名称:mlt,代码行数:101,代码来源:kdenlivetitle_wrapper.cpp


注:本文中的QTextDocument::blockSignals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。