Пример #1
0
void ObjectsScene::configurePrinter(QPrinter *printer)
{
  if(!printer)
    throw Exception(ERR_OPR_NOT_ALOC_OBJECT ,__PRETTY_FUNCTION__,__FILE__,__LINE__);

  if(paper_size!=QPrinter::Custom)
   printer->setPaperSize(paper_size);
  else
  {
    #if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0))
      //The QTBUG-33645 is fixed on Qt 5.3
      QPageLayout pl;
      QPageSize ps;
      ps=QPageSize(QSizeF(custom_paper_size.width(), custom_paper_size.height()), QPageSize::Point, QString(), QPageSize::ExactMatch);
      pl.setPageSize(ps);
      pl.setOrientation(page_orientation==QPrinter::Landscape ? QPageLayout::Landscape : QPageLayout::Portrait);
      printer->setPageSize(pl.pageSize());
    #else
      #warning "Custom page size bug (QTBUG-33645) workaround for Qt 5.2 or lower. NOTE: This issue is fixed on Qt 5.3"
      printer->setPaperSize(QSizeF(custom_paper_size.height(), custom_paper_size.width()), QPrinter::Point);
    #endif
  }

  if(paper_size==QPrinter::Custom)
  {
    if(custom_paper_size.width() > custom_paper_size.height())
      ObjectsScene::page_orientation=QPrinter::Landscape;
    else
      ObjectsScene::page_orientation=QPrinter::Portrait;
  }
  else
     printer->setOrientation(page_orientation);

  printer->setPageMargins(page_margins.left(), page_margins.top(), page_margins.width(), page_margins.height(), QPrinter::Millimeter);
}
bool QPlatformPrintDevice::isValidPageLayout(const QPageLayout &layout, int resolution) const
{
    // Check the page size is supported
    if (!supportedPageSize(layout.pageSize()).isValid())
        return false;

    // Check the margins are valid
    QMarginsF pointMargins = layout.margins(QPageLayout::Point);
    QMarginsF printMargins = printableMargins(layout.pageSize(), layout.orientation(), resolution);
    return pointMargins.left() >= printMargins.left()
           && pointMargins.right() >= printMargins.right()
           && pointMargins.top() >= printMargins.top()
           && pointMargins.bottom() >= printMargins.bottom();
}
Пример #3
0
int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    engine = new QQmlApplicationEngine();
    QPageLayout appWindow;
    appWindow.setOrientation(QPageLayout::Landscape);
    translator.load("translation_en.ts");
    app.installTranslator(&translator);
    sourceFile = "qrc:/main.qml";
    sourceUrl = QUrl(sourceFile);
    engine->load( QUrl(sourceUrl ) );
 //   MainApi *mA = new MainApi(viewer.rootContext());
    jobTimeClock = new TimeClock();
    return app.exec();
}
Пример #4
0
QDebug operator<<(QDebug dbg, const QPageLayout &layout)
{
    QDebugStateSaver saver(dbg);
    if (layout.isValid()) {
        QString output = QStringLiteral("QPageLayout(%1, %2, l:%3 r:%4 t:%5 b:%6 %7)");
        QString units;
        switch (layout.units()) {
        case QPageLayout::Millimeter:
            units = QStringLiteral("mm");
            break;
        case QPageLayout::Point:
            units = QStringLiteral("pt");
            break;
        case QPageLayout::Inch:
            units = QStringLiteral("in");
            break;
        case QPageLayout::Pica:
            units = QStringLiteral("pc");
            break;
        case QPageLayout::Didot:
            units = QStringLiteral("DD");
            break;
        case QPageLayout::Cicero:
            units = QStringLiteral("CC");
            break;
        }
        output = output.arg(layout.pageSize().name())
                       .arg(layout.orientation() == QPageLayout::Portrait ? QStringLiteral("Portrait") : QStringLiteral("Landscape"))
                       .arg(layout.margins().left())
                       .arg(layout.margins().right())
                       .arg(layout.margins().top())
                       .arg(layout.margins().bottom())
                       .arg(units);
        dbg.nospace() << output;
    } else {
        dbg.nospace() << "QPageLayout()";
    }
    return dbg;
}
Пример #5
0
void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value)
{
    Q_D(QPdfPrintEngine);

    switch (int(key)) {

    // The following keys are properties or derived values and so cannot be set
    case PPK_PageRect:
        break;
    case PPK_PaperRect:
        break;
    case PPK_PaperSources:
        break;
    case PPK_SupportsMultipleCopies:
        break;
    case PPK_SupportedResolutions:
        break;

    // The following keys are settings that are unsupported by the PDF PrintEngine
    case PPK_CustomBase:
        break;

    // The following keys are properties and settings that are supported by the PDF PrintEngine
    case PPK_CollateCopies:
        d->collate = value.toBool();
        break;
    case PPK_ColorMode:
        d->grayscale = (QPrinter::ColorMode(value.toInt()) == QPrinter::GrayScale);
        break;
    case PPK_Creator:
        d->creator = value.toString();
        break;
    case PPK_DocumentName:
        d->title = value.toString();
        break;
    case PPK_FullPage:
        if (value.toBool())
            d->m_pageLayout.setMode(QPageLayout::FullPageMode);
        else
            d->m_pageLayout.setMode(QPageLayout::StandardMode);
        break;
    case PPK_CopyCount: // fallthrough
    case PPK_NumberOfCopies:
        d->copies = value.toInt();
        break;
    case PPK_Orientation:
        d->m_pageLayout.setOrientation(QPageLayout::Orientation(value.toInt()));
        break;
    case PPK_OutputFileName:
        d->outputFileName = value.toString();
        break;
    case PPK_PageOrder:
        d->pageOrder = QPrinter::PageOrder(value.toInt());
        break;
    case PPK_PageSize: {
        QPageSize pageSize = QPageSize(QPageSize::PageSizeId(value.toInt()));
        if (pageSize.isValid())
            d->m_pageLayout.setPageSize(pageSize);
        break;
    }
    case PPK_PaperName: {
        QString name = value.toString();
        for (int i = 0; i <= QPageSize::LastPageSize; ++i) {
            QPageSize pageSize = QPageSize(QPageSize::PageSizeId(i));
            if (name == pageSize.name()) {
                d->m_pageLayout.setPageSize(pageSize);
                break;
            }
        }
        break;
    }
    case PPK_WindowsPageSize:
        d->m_pageLayout.setPageSize(QPageSize(QPageSize::id(value.toInt())));
        break;
    case PPK_PaperSource:
        d->paperSource = QPrinter::PaperSource(value.toInt());
        break;
    case PPK_PrinterName:
        d->printerName = value.toString();
        break;
    case PPK_PrinterProgram:
        d->printProgram = value.toString();
        break;
    case PPK_Resolution:
        d->resolution = value.toInt();
        break;
    case PPK_SelectionOption:
        d->selectionOption = value.toString();
        break;
    case PPK_FontEmbedding:
        d->embedFonts = value.toBool();
        break;
    case PPK_Duplex:
        d->duplex = static_cast<QPrint::DuplexMode>(value.toInt());
        break;
    case PPK_CustomPaperSize:
        d->m_pageLayout.setPageSize(QPageSize(value.toSizeF(), QPageSize::Point));
        break;
    case PPK_PageMargins: {
        QList<QVariant> margins(value.toList());
        Q_ASSERT(margins.size() == 4);
        d->m_pageLayout.setUnits(QPageLayout::Point);
        d->m_pageLayout.setMargins(QMarginsF(margins.at(0).toReal(), margins.at(1).toReal(),
                                             margins.at(2).toReal(), margins.at(3).toReal()));
        break;
    }
    case PPK_QPageSize: {
        QPageSize pageSize = value.value<QPageSize>();
        if (pageSize.isValid())
            d->m_pageLayout.setPageSize(pageSize);
        break;
    }
    case PPK_QPageMargins: {
        QPair<QMarginsF, QPageLayout::Unit> pair = value.value<QPair<QMarginsF, QPageLayout::Unit> >();
        d->m_pageLayout.setUnits(pair.second);
        d->m_pageLayout.setMargins(pair.first);
        break;
    }
    case PPK_QPageLayout: {
        QPageLayout pageLayout = value.value<QPageLayout>();
        if (pageLayout.isValid())
            d->m_pageLayout = pageLayout;
        break;
    }
    // No default so that compiler will complain if new keys added and not handled in this engine
    }
}
Пример #6
0
int QPageSetupDialog::exec()
{
    Q_D(QPageSetupDialog);

    if (d->printer->outputFormat() != QPrinter::NativeFormat)
        return Rejected;

    QWin32PrintEngine *engine = static_cast<QWin32PrintEngine*>(d->printer->paintEngine());
    QWin32PrintEnginePrivate *ep = static_cast<QWin32PrintEnginePrivate *>(engine->d_ptr.data());

    PAGESETUPDLG psd;
    memset(&psd, 0, sizeof(PAGESETUPDLG));
    psd.lStructSize = sizeof(PAGESETUPDLG);

    // we need a temp DEVMODE struct if we don't have a global DEVMODE
    HGLOBAL hDevMode = 0;
    int devModeSize = 0;
    if (!engine->globalDevMode()) {
        devModeSize = sizeof(DEVMODE) + ep->devMode->dmDriverExtra;
        hDevMode = GlobalAlloc(GHND, devModeSize);
        if (hDevMode) {
            void *dest = GlobalLock(hDevMode);
            memcpy(dest, ep->devMode, devModeSize);
            GlobalUnlock(hDevMode);
        }
        psd.hDevMode = hDevMode;
    } else {
        psd.hDevMode = engine->globalDevMode();
    }

    HGLOBAL *tempDevNames = engine->createGlobalDevNames();
    psd.hDevNames = tempDevNames;

    QWidget *parent = parentWidget();
    parent = parent ? parent->window() : QApplication::activeWindow();
    Q_ASSERT(!parent ||parent->testAttribute(Qt::WA_WState_Created));

    QWindow *parentWindow = parent->windowHandle();
    psd.hwndOwner = parentWindow ? (HWND)QGuiApplication::platformNativeInterface()->nativeResourceForWindow("handle", parentWindow) : 0;

    psd.Flags = PSD_MARGINS;
    QPageLayout layout = d->printer->pageLayout();
    switch (layout.units()) {
    case QPageLayout::Millimeter:
    case QPageLayout::Inch:
        break;
    case QPageLayout::Point:
    case QPageLayout::Pica:
    case QPageLayout::Didot:
    case QPageLayout::Cicero:
        layout.setUnits(QLocale::system().measurementSystem() == QLocale::MetricSystem ? QPageLayout::Millimeter
                                                                                       : QPageLayout::Inch);
        break;
    }
    qreal multiplier = 1.0;
    if (layout.units() == QPageLayout::Millimeter) {
        psd.Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
        multiplier = 100.0;
    } else { // QPageLayout::Inch)
        psd.Flags |= PSD_INTHOUSANDTHSOFINCHES;
        multiplier = 1000.0;
    }
    psd.rtMargin.left   = layout.margins().left() * multiplier;
    psd.rtMargin.top    = layout.margins().top() * multiplier;
    psd.rtMargin.right  = layout.margins().right() * multiplier;
    psd.rtMargin.bottom = layout.margins().bottom() * multiplier;

    QDialog::setVisible(true);
    bool result = PageSetupDlg(&psd);
    QDialog::setVisible(false);
    if (result) {
        engine->setGlobalDevMode(psd.hDevNames, psd.hDevMode);
        const QMarginsF margins(psd.rtMargin.left, psd.rtMargin.top, psd.rtMargin.right, psd.rtMargin.bottom);
        d->printer->setPageMargins(margins / multiplier, layout.units());

        // copy from our temp DEVMODE struct
        if (!engine->globalDevMode() && hDevMode) {
            void *src = GlobalLock(hDevMode);
            memcpy(ep->devMode, src, devModeSize);
            GlobalUnlock(hDevMode);
        }
    }

    if (!engine->globalDevMode() && hDevMode)
        GlobalFree(hDevMode);
    GlobalFree(tempDevNames);
    done(result);
    return result;
}