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


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

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


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

示例1: drawSimpleRichText

/*!
  Draw a text document into a rectangle

  \param painter Painter
  \param rect Traget rectangle
  \param flags Alignments/Text flags, see QPainter::drawText()
  \param text Text document
*/
void QwtPainter::drawSimpleRichText( QPainter *painter, const QRectF &rect,
    int flags, const QTextDocument &text )
{
    QTextDocument *txt = text.clone();

    painter->save();

    painter->setFont( txt->defaultFont() );
    qwtUnscaleFont( painter );

    txt->setDefaultFont( painter->font() );
    txt->setPageSize( QSizeF( rect.width(), QWIDGETSIZE_MAX ) );

    QAbstractTextDocumentLayout* layout = txt->documentLayout();

    const double height = layout->documentSize().height();
    double y = rect.y();
    if ( flags & Qt::AlignBottom )
        y += ( rect.height() - height );
    else if ( flags & Qt::AlignVCenter )
        y += ( rect.height() - height ) / 2;

    QAbstractTextDocumentLayout::PaintContext context;
    context.palette.setColor( QPalette::Text, painter->pen().color() );

    painter->translate( rect.x(), y );
    layout->draw( painter, context );

    painter->restore();
    delete txt;
}
开发者ID:,项目名称:,代码行数:39,代码来源:

示例2:

QTextDocument *QTextDocumentProto::clone(QObject *parent) const
{
  QTextDocument *item = qscriptvalue_cast<QTextDocument*>(thisObject());
  if (item)
    return item->clone(parent);
  return 0;
}
开发者ID:,项目名称:,代码行数:7,代码来源:

示例3: HandlePrint

QTextDocument *M_PageSize::nulldoc( QString htm )
{
  QTextDocument *doc = new QTextDocument;
  if (htm.size() > 2) {
  doc->setHtml(htm);
  }
  HandlePrint(doc);
  return doc->clone();
}
开发者ID:SorinS,项目名称:fop-miniscribus,代码行数:9,代码来源:scribemime.cpp

示例4: testFindingTables

    void testFindingTables()
    {
        // How to find all the tables in a QTextDocument?
        QTextDocument textDoc;
        QTextCursor c( &textDoc );
        QTextTable* firstTable = c.insertTable( 2, 2 );
        QTextTableCell bottomRight = firstTable->cellAt( 1, 1 );
        QTextTable* secondTable = bottomRight.firstCursorPosition().insertTable( 3, 3 ); // a nested table
        c.movePosition( QTextCursor::End );
        QTextTable* thirdTable = c.insertTable( 1, 1 );
        thirdTable->firstCursorPosition().insertText( "in table" );
        c.insertText( "Foo" );
        QList<QTextTable *> origTables;
        origTables << firstTable << secondTable << thirdTable;

        // A generic and slow solution is
        //    curs.currentTable() && !tablesFound.contains(curs.currentTable())
        // for each cursor position. Surely there's better.
        // We could jump to currentFrame().lastCursorPosition() but then it would skip
        // nested tables.
        QTextDocument* clonedDoc = textDoc.clone();
        QSet<QTextTable *> tablesFound;
        {
            QTextCursor curs(clonedDoc);
            while (!curs.atEnd()) {
                QTextTable* currentTable = curs.currentTable();
                if ( currentTable && !tablesFound.contains(currentTable) ) {
                    tablesFound.insert( currentTable );
                }
                curs.movePosition( QTextCursor::NextCharacter );
            }
            QCOMPARE( tablesFound.size(), 3 );
        }

        // Let's do something else then, let's find them by cursor position
        QList<QTextTable *> tablesByPos;
        {
            // first test
            const int firstPos = firstTable->firstCursorPosition().position();
            QTextCursor curs( clonedDoc );
            curs.setPosition( firstPos );
            QVERIFY( curs.currentTable() );

            // generic loop. works this approach is in TextDocument::breakTables now.
            Q_FOREACH( QTextTable* origTable, origTables ) {
                QTextCursor curs( clonedDoc );
                curs.setPosition( origTable->firstCursorPosition().position() );
                tablesByPos.append( curs.currentTable() );
            }
            QCOMPARE( tablesByPos.size(), 3 );
            QCOMPARE( tablesByPos.toSet(), tablesFound );
        }
开发者ID:,项目名称:,代码行数:52,代码来源:

示例5: drawSimpleRichText

/*!
  Draw a text document into a rectangle

  \param painter Painter
  \param rect Traget rectangle
  \param flags Alignments/Text flags, see QPainter::drawText()
  \param text Text document
*/
void QwtPainter::drawSimpleRichText( QPainter *painter, const QRectF &rect,
    int flags, const QTextDocument &text )
{
    QTextDocument *txt = text.clone();

    painter->save();

    QRectF unscaledRect = rect;

    if ( painter->font().pixelSize() < 0 )
    {
        const QSize res = qwtScreenResolution();

        const QPaintDevice *pd = painter->device();
        if ( pd->logicalDpiX() != res.width() ||
            pd->logicalDpiY() != res.height() )
        {
            QTransform transform;
            transform.scale( res.width() / double( pd->logicalDpiX() ),
                res.height() / double( pd->logicalDpiY() ));

            painter->setWorldTransform( transform, true );
            unscaledRect = transform.inverted().mapRect(rect);
        }
    }  

    txt->setDefaultFont( painter->font() );
    txt->setPageSize( QSizeF( unscaledRect.width(), QWIDGETSIZE_MAX ) );

    QAbstractTextDocumentLayout* layout = txt->documentLayout();

    const double height = layout->documentSize().height();
    double y = unscaledRect.y();
    if ( flags & Qt::AlignBottom )
        y += ( unscaledRect.height() - height );
    else if ( flags & Qt::AlignVCenter )
        y += ( unscaledRect.height() - height ) / 2;

    QAbstractTextDocumentLayout::PaintContext context;
    context.palette.setColor( QPalette::Text, painter->pen().color() );

    painter->translate( unscaledRect.x(), y );
    layout->draw( painter, context );

    painter->restore();
    delete txt;
}
开发者ID:FabianFrancoRoldan,项目名称:OpenPilot,代码行数:55,代码来源:qwt_painter.cpp


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