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


C++ QPrinter::getPageMargins方法代码示例

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


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

示例1: optionPageMargins

QStringList FilePrinter::optionPageMargins( QPrinter &printer )
{
    if (printer.printEngine()->property(QPrintEngine::PPK_PageMargins).isNull()) {
        return QStringList();
    } else {
        qreal l, t, r, b;
        printer.getPageMargins( &l, &t, &r, &b, QPrinter::Point );
        return QStringList("-o") << QString("page-left=%1").arg(l)
                       <<  "-o"  << QString("page-top=%1").arg(t)
                       <<  "-o"  << QString("page-right=%1").arg(r)
                       <<  "-o"  << QString("page-bottom=%1").arg(b);
    }
}
开发者ID:Saljack,项目名称:osp-okular,代码行数:13,代码来源:fileprinter.cpp

示例2: writeSettings

void KatePrinter::writeSettings(QPrinter& printer)
{
  KSharedConfigPtr config = KGlobal::config();
  KConfigGroup group(config, "Kate Print Settings");
  KConfigGroup margins(&group, "Margins");

  qreal left, right, top, bottom;
  printer.getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);

  margins.writeEntry( "left", left);
  margins.writeEntry( "top", top);
  margins.writeEntry( "right", right);
  margins.writeEntry( "bottom", bottom);
}
开发者ID:niteshnarayanlal,项目名称:Kate,代码行数:14,代码来源:kateprinter.cpp

示例3: readSettings

//BEGIN KatePrinter
void KatePrinter::readSettings(QPrinter& printer)
{
  // NOTE: Saving & loading the margins works around QPrinter/QPrintDialog bugs:
  // - https://bugreports.qt.nokia.com/browse/QTBUG-15351
  // - https://bugs.kde.org/show_bug.cgi?id=205802
  // - https://bugs.kde.org/show_bug.cgi?id=180051
  // Changing the margins now works. However, when you reopen the print dialog
  // later, the WRONG margins are displayed. The correct ones are still used.
  // This is a critical bug in Qt.

  KSharedConfigPtr config = KGlobal::config();
  KConfigGroup group(config, "Kate Print Settings");
  KConfigGroup margins(&group, "Margins");

  qreal left, right, top, bottom;
  printer.getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);

  left = margins.readEntry("left", left);
  top = margins.readEntry("top", top);
  right = margins.readEntry("right", right);
  bottom = margins.readEntry("bottom", bottom);

  printer.setPageMargins(left, top, right, bottom, QPrinter::Millimeter);
}
开发者ID:niteshnarayanlal,项目名称:Kate,代码行数:25,代码来源:kateprinter.cpp

示例4: getPageMargins

void QPrinterProto::getPageMargins(qreal *left, qreal *top, qreal *right, qreal *bottom, QPrinter::Unit unit) const
{
  QPrinter *item = qscriptvalue_cast<QPrinter*>(thisObject());
  if (item)
    item->getPageMargins(left, top, right, bottom, unit);
}
开发者ID:AlFoX,项目名称:qt-client,代码行数:6,代码来源:qprinterproto.cpp

示例5: printScene

void SceneImageExporter::printScene(QGraphicsScene *scene, QPrinter& printer,
                                    QString fileName, QString documentName,
                                    int printingFlags)
{

    if (!fileName.isEmpty() && fileName != "" && fileName.endsWith(".pdf",Qt::CaseInsensitive))
    {
        printer.setOutputFormat(QPrinter::PdfFormat);
        printer.setOutputFileName(fileName);
    }
    else {
        //set page margins if I have to print on paper.
        printer.setPageMargins(10,10,10,10,QPrinter::Millimeter);
    }


    QPainter painter(&printer);

    QRectF sceneRect = scene->sceneRect();
    double sceneRatio = scene->sceneRect().width()/scene->sceneRect().height();
    qreal left,top,right,bottom;
    printer.getPageMargins(&left,&top,&right,&bottom,QPrinter::DevicePixel);
    QRect pageRect = QRect(
            printer.pageRect().top()+top,
            printer.pageRect().left()+left,
            printer.pageRect().width()-(left+right),
            printer.pageRect().height()-(top+bottom));

    int xSize, ySize, dxSize, dySize, xPages, yPages;
    double fWidth, fHeight, fHeightStep, fWidthStep;
    double pageRectRatio = (double)pageRect.width()/(double)pageRect.height();

    xSize = (int)((double)(3*pageRect.width()) * 1.0);
    ySize = (int)((double)(3*pageRect.height()) * .9);
    dxSize = (int)((double)(3*pageRect.width()) * .05);
    dySize = (int)((double)(3*pageRect.height()) * .05);

    xPages = 1+ (((int)sceneRect.width()) / xSize);
    yPages = 1+ (((int)sceneRect.height()) / ySize);

    if (SIEOptions::ScaleToSceneHeight(printingFlags)) {
        yPages = 1;
        xPages = 1+(int)( (double)yPages *sceneRatio);
        ySize = (int) ((double)scene->sceneRect().height()*.9);
        xSize = (int) ( (double)ySize * pageRectRatio);
        dySize = (int) (.05 * (double)scene->sceneRect().height()*.9);
        dxSize = (int) ( .05 *(double)ySize * pageRectRatio);

    }

    if (SIEOptions::ScaleToSceneWidth(printingFlags)) {
        xPages = 1;
        yPages = 1+(int)( (double)yPages / sceneRatio);
    }


    fWidth = 1.0* (double)pageRect.width();
    fHeight = .9* (double)pageRect.height();
    fHeightStep = .15* (double)pageRect.height();
    fWidthStep = fHeightStep * sceneRatio;

    bool bNewPage = false;
    double fWidth2 = fWidth * .9;
    double fHeight2 = fHeight * .9;

    QPainterPath path;
    QRectF rectOuter;
    rectOuter.setLeft((double)pageRect.left());
    rectOuter.setTop((double)pageRect.top());
    rectOuter.setWidth(fWidth2);
    rectOuter.setHeight(fHeight2);

    path.addRect(rectOuter);

    QRectF rectInner(rectOuter);
    rectInner.setTopLeft(QPointF(
            rectInner.left()+fWidth2/20,
            rectInner.top()+fHeight2/20));
    rectInner.setSize(QSizeF(fWidth2*.9,fHeight2*.9));
    path.addRect(rectInner);


    painter.begin(&printer);

    QBrush shadowBrush = QBrush(QColor(192,192,192,64));
    QBrush transparent = QBrush(QColor(192,192,192,16));
    //QPen pen = QPen(QColor (65,65,65,192));
    QPen pen = QPen(QColor (255,0,0,192));
    QFont font = QFont("Droid Sans");
    font.setBold(true);
    font.setPointSizeF(16.0);

    QFont fontb = QFont("Droid Sans");
    fontb.setBold(false);
    fontb.setPointSizeF(11.0);


    //double fh = fHeightStep / yPages;
    //double fw = fWidthStep / xPages;

//.........这里部分代码省略.........
开发者ID:maxlambertini,项目名称:Warp2010,代码行数:101,代码来源:sceneimageexporter.cpp

示例6: GraphicsSceneToPrinter

void SceneImageExporter::GraphicsSceneToPrinter(
        QGraphicsScene *scene, QPrinter& printer,
        QString fileName, QString documentName __attribute__((unused)),
        bool bSizeToOneSheet)
{
    if (!fileName.isEmpty() && fileName != "" && fileName.endsWith(".pdf",Qt::CaseInsensitive))
    {
        printer.setOutputFormat(QPrinter::PdfFormat);
        printer.setOutputFileName(fileName);
    }

    // When printing, use full page mode, IE ignore hardware margins. It's up
    // to users to set them as they desire.
    printer.setFullPage(true);
    printer.setPaperSize(QSizeF(PrintingPreferences::prefs().selectedMeasure().width(),
                                PrintingPreferences::prefs().selectedMeasure().height()),
                         QPrinter::Millimeter);
    printer.setPageMargins(PrintingPreferences::prefs().leftMargin(),
                           PrintingPreferences::prefs().topMargin(),
                           PrintingPreferences::prefs().rightMargin(),
                           PrintingPreferences::prefs().bottomMargin(),
                           QPrinter::Millimeter);


    if (!bSizeToOneSheet) {

        //here, I print using selected sheets and divisions.
        QPainter painter(&printer);
        qreal left,top,right,bottom;
        printer.getPageMargins(&left,&top,&right,&bottom,QPrinter::DevicePixel);

        // get the FULL PAGE RECTANGLE and adjust margins.
        QRectF pageRect = printer.paperRect();
        pageRect.adjust(left,top,-right, -bottom);


        //get height/width page rect ratio
        double pageRatio = pageRect.width()/pageRect.height();

        //get scene rectangle and calculating pages.
        int stepY = PrintingPreferences::prefs().yDivisions();
        QRectF sceneRect = scene->sceneRect();
        double scene_dy = sceneRect.height()/( (double)stepY);
        double scene_dx = scene_dy * pageRatio;


        double o_scene_dx = scene_dx * 1.1;
        double o_scene_dy = scene_dy * 1.1;

        double o_rect_dx = pageRect.width() / 1.1;
        double o_rect_dy = pageRect.height() / 1.1;

        double odx = ( pageRect.width() -o_rect_dx)/2.0;
        double ody = (pageRect.height() - o_rect_dy)/ 2.0;

        QRectF pageRectInner = QRectF (pageRect.left() + odx,
                                       pageRect.top() + ody,
                                       o_rect_dx, o_rect_dy);

        int stepX = 1+ (int)(sceneRect.width() / scene_dx);

        //ok, calculated my boxes. NOW, let's print everything out.
        QColor transparent(0,0,0,0);
        QColor transBorder (0,0,0,128);
        QPen pen (transBorder);
        pen.setStyle(Qt::DotLine);
        QBrush brush(transparent);

        bool bNewPage = false;

        for (int y = 0; y < stepY; y++) {
            for (int x = 0; x < stepX; x++) {
                if (bNewPage)
                    printer.newPage();
                else
                    bNewPage = true;

                //I've already got my target rectangle
                QRectF sourceRect = QRectF (
                        sceneRect.left()+((double)x * scene_dx  + (o_scene_dx - scene_dx)/2.0 ),
                        sceneRect.top()+((double)y * scene_dy + (o_scene_dy - scene_dy)/2.0),
                        o_scene_dx,o_scene_dy);


                scene->render(&painter,pageRect, sourceRect);

                QBrush oldBrush = painter.brush();
                QPen oldPen = painter.pen();

                //qDebug() << "pageRect " << pageRect;
                //qDebug() << "pageRectInner " << pageRectInner;

                painter.setPen(pen);
                painter.setBrush(brush);
                painter.drawRect(pageRect);
                painter.drawRect(pageRectInner);

                painter.setPen(oldPen);
                painter.setBrush(oldBrush);

//.........这里部分代码省略.........
开发者ID:maxlambertini,项目名称:Warp2010,代码行数:101,代码来源:sceneimageexporter.cpp

示例7: PageGraphicsSceneToPrinter

void SceneImageExporter::PageGraphicsSceneToPrinter(QGraphicsScene *scene, QPrinter &printer,
                                                    QList<SectorRectHolder>& pageRegions, QString fileName,
                                                    QString documentName __attribute__((unused)))
{
    PrintingPreferences &pref  __attribute__ ((unused))  = PrintingPreferences::prefs();
    //qDebug()  << pref.yDivisions();
    //qDebug()  << pref.selectedMeasure();
    //qDebug() << pref.measures();

    if (!fileName.isEmpty() && fileName != "" && fileName.endsWith(".pdf",Qt::CaseInsensitive))
    {
        printer.setOutputFormat(QPrinter::PdfFormat);
        printer.setOutputFileName(fileName);
    }

    // When printing, use full page mode, IE ignore hardware margins. It's up
    // to users to set them as they desire.
    printer.setFullPage(true);
    printer.setPaperSize(QSizeF(PrintingPreferences::prefs().selectedMeasure().width(),
                                PrintingPreferences::prefs().selectedMeasure().height()),
                         QPrinter::Millimeter);
    printer.setPageMargins(PrintingPreferences::prefs().leftMargin(),
                           PrintingPreferences::prefs().topMargin(),
                           PrintingPreferences::prefs().rightMargin(),
                           PrintingPreferences::prefs().bottomMargin(),
                           QPrinter::Millimeter);

    //here, I print using selected sheets and divisions.
    QPainter painter(&printer);
    qreal left,top,right,bottom;
    printer.getPageMargins(&left,&top,&right,&bottom,QPrinter::DevicePixel);

    // get the FULL PAGE RECTANGLE and adjust margins.
    QRectF pageRect = printer.paperRect();
    pageRect.adjust(left,top,-right, -bottom);


    QColor transparent(0,0,0,0);
    QColor transBorder (0,0,0,128);
    QPen pen (transBorder);
    pen.setStyle(Qt::DotLine);
    QBrush brush;

    QGraphicsScene sceneFirst;
    QPen pen2 (QColor(0,0,0));
    pen2.setStyle(Qt::DotLine);
    pen2.setWidthF(2.0);
    QBrush brush2;
    for (int h = 0; h < pageRegions.count(); h++)
    {
        QRectF rect = pageRegions[h].rectInner();
        sceneFirst.addRect (rect.left(), rect.top(), rect.width(),rect.height(),pen2, brush2);
        rect = pageRegions[h].rectOuter();
        sceneFirst.addRect (rect.left(), rect.top(), rect.width(),rect.height(),pen2, brush2);
    }
    scene->render(&painter, pageRect, scene->itemsBoundingRect(),Qt::KeepAspectRatio);
    sceneFirst.render(&painter,pageRect, sceneFirst.sceneRect(),Qt::KeepAspectRatio);


    for (int h = 0; h < pageRegions.count(); h++)
    {
        QRectF rect = pageRegions[h].rectOuter();
        double ratio = rect.width()/rect.height();
        QRectF rectTarget = QRectF(pageRect.left(), pageRect.top(), pageRect.width(), pageRect.width()/ratio);
        printer.newPage();
        scene->render(&painter,rectTarget, rect);
        painter.setPen(pen2);
        painter.setBrush(brush);
        painter.drawRect(rectTarget);
        QRectF rect2 = pageRegions[h].rectInner();
        double ratioX = rectTarget.width()/rect.width();
        double ratioY = rectTarget.height()/rect.height();

        double dy = rect2.top()-rect.top();
        double dx = rect2.left() - rect.left();

        //qDebug() << "rect outer: " << rect
        //        <<  "\nrect inner: " << rect2
        //        << "\nrect target: " << rectTarget
        //        << "\nx: " << dx << ",y:" << dy;

        QRectF rectTarget2 (rectTarget.top()+ dx*ratioX,
                            rectTarget.left()+dy*ratioY,
                            rect2.width()*ratioX,
                            rect2.height()*ratioY);
        painter.drawRect(rectTarget2);

    }
    painter.end();
}
开发者ID:maxlambertini,项目名称:Warp2010,代码行数:90,代码来源:sceneimageexporter.cpp


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