コード例 #1
0
ファイル: qcupsprintengine.cpp プロジェクト: crobertd/qtbase
void QCupsPrintEnginePrivate::setPaperSize()
{
    if (QCUPSSupport::isAvailable()) {
        QCUPSSupport cups;
        QPdf::PaperSize size = QPdf::paperSize(QPrinter::PaperSize(printerPaperSize));

        if (cups.currentPPD()) {
            const ppd_option_t* pageSizes = cups.pageSizes();
            for (int i = 0; i < pageSizes->num_choices; ++i) {
                QByteArray cupsPageSize = pageSizes->choices[i].choice;
                QRect tmpCupsPaperRect = cups.paperRect(cupsPageSize);
                QRect tmpCupsPageRect = cups.pageRect(cupsPageSize);

                if (qAbs(size.width - tmpCupsPaperRect.width()) < 5  && qAbs(size.height - tmpCupsPaperRect.height()) < 5) {
                    cupsPaperRect = tmpCupsPaperRect;
                    cupsPageRect = tmpCupsPageRect;

                    leftMargin = cupsPageRect.x() - cupsPaperRect.x();
                    topMargin = cupsPageRect.y() - cupsPaperRect.y();
                    rightMargin = cupsPaperRect.right() - cupsPageRect.right();
                    bottomMargin = cupsPaperRect.bottom() - cupsPageRect.bottom();

                    updatePaperSize();
                    break;
                }
            }
        }
    }
}
コード例 #2
0
/**
 * Updates all unit labels that depend on the global unit.
 */
void QG_DlgOptionsDrawing::updateUnitLabels() {
    RS2::Unit u = (RS2::Unit)cbUnit->currentIndex();
    QString sign = RS_Units::unitToSign(u);
    lDimUnit1->setText(sign);
    lDimUnit2->setText(sign);
    lDimUnit3->setText(sign);
    lDimUnit4->setText(sign);
    lDimUnit5->setText(sign);
    lDimUnit6->setText(sign);
    //have to update paper size when unit changes
    updatePaperSize();
}
コード例 #3
0
/**
 * Sets the graphic and updates the GUI to match the drawing.
 */
void QG_DlgOptionsDrawing::setGraphic(RS_Graphic* g) {
    graphic = g;

    if (graphic==NULL) {
        std::cout<<" QG_DlgOptionsDrawing::setGraphic(NULL)\n";
        return;
    }

    // main drawing unit:
    int insunits = graphic->getVariableInt("$INSUNITS", 0);
    cbUnit->setCurrentIndex( cbUnit->findText(
                                 RS_Units::unitToString(RS_FilterDXFRW::numberToUnit(insunits))));

    // units / length format:
    int lunits = graphic->getVariableInt("$LUNITS", 2);
    cbLengthFormat->setCurrentIndex(lunits-1);

    // units length precision:
    int luprec = graphic->getVariableInt("$LUPREC", 4);
    updateLengthPrecision();
    cbLengthPrecision->setCurrentIndex(luprec);

    // units / angle format:
    int aunits = graphic->getVariableInt("$AUNITS", 0);
    cbAngleFormat->setCurrentIndex(aunits);

    // units angle precision:
    int auprec = graphic->getVariableInt("$AUPREC", 2);
    updateAnglePrecision();
    cbAnglePrecision->setCurrentIndex(auprec);

    // paper format:
    bool landscape;
    RS2::PaperFormat format = graphic->getPaperFormat(&landscape);
    RS_DEBUG->print("QG_DlgOptionsDrawing::setGraphic: paper format is: %d", (int)format);
    cbPaperFormat->setCurrentIndex((int)format);

    // paper orientation:
    if (landscape) {
        rbLandscape->setChecked(true);
    } else {
        rbPortrait->setChecked(true);
    }

    // Grid:
    cbGridOn->setChecked(graphic->isGridOn());
    //    RS_SETTINGS->beginGroup("/Appearance");
    //    cbIsometricGrid->setChecked(static_cast<bool>(RS_SETTINGS->readNumEntry("/IsometricGrid", 0)));
    //    RS_SETTINGS->endGroup();

    //    graphic->setIsometricGrid(cbIsometricGrid->isChecked());
    rbIsometricGrid->setChecked(graphic->isIsometricGrid());
    rbOrthogonalGrid->setChecked(! rbIsometricGrid->isChecked());


    rbIsometricGrid->setDisabled(!cbGridOn->isChecked());
    rbOrthogonalGrid->setDisabled(!cbGridOn->isChecked());
    RS2::CrosshairType chType=graphic->getCrosshairType();
    switch(chType){
    case RS2::LeftCrosshair:
        rbCrosshairLeft->setChecked(true);
        break;
    case RS2::TopCrosshair:
        rbCrosshairTop->setChecked(true);
        break;
        //    case RS2::RightCrosshair:
        //        rbCrosshairRight->setChecked(true);
        //        break;
    default:
        rbCrosshairRight->setChecked(true);
        break;
    }
    if(rbOrthogonalGrid->isChecked() || ! cbGridOn->isChecked() ){
        rbCrosshairLeft->setDisabled(true);
        rbCrosshairTop->setDisabled(true);
        rbCrosshairRight->setDisabled(true);
    }else{
        rbCrosshairLeft->setDisabled(false);
        rbCrosshairTop->setDisabled(false);
        rbCrosshairRight->setDisabled(false);
    }

    spacing = graphic->getVariableVector("$GRIDUNIT",
                                                   RS_Vector(0.0,0.0));
    cbXSpacing->setEditText( QString("%1").arg(spacing.x));
    cbYSpacing->setEditText( QString("%1").arg(spacing.y));

    if (cbXSpacing->currentText()=="0") {
        cbXSpacing->setEditText(tr("auto"));
    }
    if (cbYSpacing->currentText()=="0") {
        cbYSpacing->setEditText(tr("auto"));
    }
    cbXSpacing->setEnabled(cbGridOn->isChecked() && rbOrthogonalGrid->isChecked());
    cbYSpacing->setEnabled(cbGridOn->isChecked());

    // dimension text height:
    RS2::Unit unit = (RS2::Unit)cbUnit->currentIndex();

    // dimension general factor:
    double dimfactor = graphic->getVariableDouble("$DIMLFAC", 1.0);
    cbDimFactor->setEditText(QString("%1").arg(dimfactor));

    // dimension general scale:
    double dimscale = graphic->getVariableDouble("$DIMSCALE", 1.0);
    cbDimScale->setEditText(QString("%1").arg(dimscale));

    double dimtxt = graphic->getVariableDouble("$DIMTXT",
                                               RS_Units::convert(2.5, RS2::Millimeter, unit));
    //RLZ    cbDimTextHeight->setCurrentText(QString("%1").arg(dimtxt));
    cbDimTextHeight->setEditText(QString("%1").arg(dimtxt));

    // dimension extension line extension:
    double dimexe = graphic->getVariableDouble("$DIMEXE",
                                               RS_Units::convert(1.25, RS2::Millimeter, unit));
    //RLZ    cbDimExe->setCurrentText(QString("%1").arg(dimexe));
    cbDimExe->setEditText(QString("%1").arg(dimexe));

    // dimension extension line offset:
    double dimexo = graphic->getVariableDouble("$DIMEXO",
                                               RS_Units::convert(0.625, RS2::Millimeter, unit));
    //RLZ    cbDimExo->setCurrentText(QString("%1").arg(dimexo));
    cbDimExo->setEditText(QString("%1").arg(dimexo));

    // dimension line gap:
    double dimgap = graphic->getVariableDouble("$DIMGAP",
                                               RS_Units::convert(0.625, RS2::Millimeter, unit));
    //RLZ    cbDimGap->setCurrentText(QString("%1").arg(dimgap));
    cbDimGap->setEditText(QString("%1").arg(dimgap));

    // dimension arrow size:
    double dimasz = graphic->getVariableDouble("$DIMASZ",
                                               RS_Units::convert(2.5, RS2::Millimeter, unit));
    //RLZ    cbDimAsz->setCurrentText(QString("%1").arg(dimasz));
    cbDimAsz->setEditText(QString("%1").arg(dimasz));
    // dimension tick size:
    double dimtsz = graphic->getVariableDouble("$DIMTSZ", 0.);
    cbDimTsz->setEditText(QString("%1").arg(dimtsz));
    // dimension alignment:
    int dimtih = graphic->getVariableInt("$DIMTIH", 0);
    cbDimTih->setCurrentIndex(dimtih);
    // spline line segments per patch:
    int splinesegs = graphic->getVariableInt("$SPLINESEGS", 8);
    //RLZ    cbSplineSegs->setCurrentText(QString("%1").arg(splinesegs));
    cbSplineSegs->setEditText(QString("%1").arg(splinesegs));

    RS_DEBUG->print("QG_DlgOptionsDrawing::setGraphic: splinesegs is: %d",
                    splinesegs);

    // encoding:
    /*
    QString encoding = graphic->getVariableString("$DWGCODEPAGE",
                                                  "ANSI_1252");
    encoding=RS_System::getEncoding(encoding);
    cbEncoding->setEditText(encoding);
    */

    updatePaperSize();
    updatePreview();
    updateUnitLabels();
}
コード例 #4
0
ファイル: qcupsprintengine.cpp プロジェクト: crobertd/qtbase
void QCupsPrintEnginePrivate::setCupsDefaults()
{
    if (QCUPSSupport::isAvailable()) {
        int cupsPrinterIndex = -1;
        QCUPSSupport cups;

        const cups_dest_t* printers = cups.availablePrinters();
        int prnCount = cups.availablePrintersCount();
        for (int i = 0; i <  prnCount; ++i) {
            QString name = QString::fromLocal8Bit(printers[i].name);
            if (name == printerName) {
                cupsPrinterIndex = i;
                break;
            }
        }

        if (cupsPrinterIndex < 0)
            return;

        cups.setCurrentPrinter(cupsPrinterIndex);

        if (cups.currentPPD()) {
            const ppd_option_t *ppdDuplex = cups.ppdOption("Duplex");
            if (ppdDuplex) {
                if (qstrcmp(ppdDuplex->defchoice, "DuplexTumble") == 0)
                    duplex = QPrinter::DuplexShortSide;
                else if (qstrcmp(ppdDuplex->defchoice, "DuplexNoTumble") == 0)
                    duplex = QPrinter::DuplexLongSide;
                else
                    duplex = QPrinter::DuplexNone;
            }

            grayscale = !cups.currentPPD()->color_device;

            const ppd_option_t *ppdCollate = cups.ppdOption("Collate");
            if (ppdCollate)
                collate = qstrcmp(ppdCollate->defchoice, "True") == 0;

            const ppd_option_t* pageSizes = cups.pageSizes();
            QByteArray cupsPageSize;
            for (int i = 0; i < pageSizes->num_choices; ++i) {
                if (static_cast<int>(pageSizes->choices[i].marked) == 1)
                    cupsPageSize = pageSizes->choices[i].choice;
            }

            cupsOptions = cups.options();
            cupsPaperRect = cups.paperRect(cupsPageSize);
            cupsPageRect = cups.pageRect(cupsPageSize);

            for (int ps = 0; ps < QPrinter::NPageSize; ++ps) {
                QPdf::PaperSize size = QPdf::paperSize(QPrinter::PaperSize(ps));
                if (qAbs(size.width - cupsPaperRect.width()) < 5 && qAbs(size.height - cupsPaperRect.height()) < 5) {
                    printerPaperSize = static_cast<QPrinter::PaperSize>(ps);

                    leftMargin = cupsPageRect.x() - cupsPaperRect.x();
                    topMargin = cupsPageRect.y() - cupsPaperRect.y();
                    rightMargin = cupsPaperRect.right() - cupsPageRect.right();
                    bottomMargin = cupsPaperRect.bottom() - cupsPageRect.bottom();

                    updatePaperSize();
                    break;
                }
            }
        }
    }
}
コード例 #5
0
void QG_DlgOptionsDrawing::on_rbLandscape_toggled(bool /*checked*/)
{
	updatePaperSize();
}
コード例 #6
0
/**
 * Sets the graphic and updates the GUI to match the drawing.
 */
void QG_DlgOptionsDrawing::setGraphic(RS_Graphic* g) {
    graphic = g;

	if (graphic==nullptr) {
		std::cout<<" QG_DlgOptionsDrawing::setGraphic(nullptr)\n";
        return;
    }

    // main drawing unit:
    int insunits = graphic->getVariableInt("$INSUNITS", 0);
    cbUnit->setCurrentIndex( cbUnit->findText(
                                 RS_Units::unitToString(RS_FilterDXFRW::numberToUnit(insunits))));

    // units / length format:
    int lunits = graphic->getVariableInt("$LUNITS", 2);
    cbLengthFormat->setCurrentIndex(lunits-1);

    // units length precision:
    int luprec = graphic->getVariableInt("$LUPREC", 4);
    updateCBLengthPrecision(cbLengthFormat, cbLengthPrecision);
    cbLengthPrecision->setCurrentIndex(luprec);

    // units / angle format:
    int aunits = graphic->getVariableInt("$AUNITS", 0);
    cbAngleFormat->setCurrentIndex(aunits);

    // units angle precision:
    int auprec = graphic->getVariableInt("$AUPREC", 2);
    updateCBAnglePrecision(cbAngleFormat, cbAnglePrecision);
    cbAnglePrecision->setCurrentIndex(auprec);

    // paper format:
    bool landscape;
    RS2::PaperFormat format = graphic->getPaperFormat(&landscape);
	RS_DEBUG->print("QG_DlgOptionsDrawing::setGraphic: paper format is: %d", (int)format);
    cbPaperFormat->setCurrentIndex((int)format);

    // paper orientation:
    if (landscape) {
        rbLandscape->setChecked(true);
    } else {
        rbPortrait->setChecked(true);
    }
	if(format==RS2::Custom){
		RS_Vector s=graphic->getPaperSize();
		lePaperWidth->setText(QString("%1").setNum(s.x,'g',5));
		lePaperHeight->setText(QString("%1").setNum(s.y,'g',5));
		lePaperWidth->setEnabled(true);
		lePaperHeight->setEnabled(true);
	}else{
		lePaperWidth->setEnabled(false);
		lePaperHeight->setEnabled(false);
	}

    // Grid:
    cbGridOn->setChecked(graphic->isGridOn());
    //    RS_SETTINGS->beginGroup("/Appearance");
    //    cbIsometricGrid->setChecked(static_cast<bool>(RS_SETTINGS->readNumEntry("/IsometricGrid", 0)));
    //    RS_SETTINGS->endGroup();

    //    graphic->setIsometricGrid(cbIsometricGrid->isChecked());
    rbIsometricGrid->setChecked(graphic->isIsometricGrid());
    rbOrthogonalGrid->setChecked(! rbIsometricGrid->isChecked());


    rbIsometricGrid->setDisabled(!cbGridOn->isChecked());
    rbOrthogonalGrid->setDisabled(!cbGridOn->isChecked());
    RS2::CrosshairType chType=graphic->getCrosshairType();
    switch(chType){
    case RS2::LeftCrosshair:
        rbCrosshairLeft->setChecked(true);
        break;
    case RS2::TopCrosshair:
        rbCrosshairTop->setChecked(true);
        break;
        //    case RS2::RightCrosshair:
        //        rbCrosshairRight->setChecked(true);
        //        break;
    default:
        rbCrosshairRight->setChecked(true);
        break;
    }
    if(rbOrthogonalGrid->isChecked() || ! cbGridOn->isChecked() ){
        rbCrosshairLeft->setDisabled(true);
        rbCrosshairTop->setDisabled(true);
        rbCrosshairRight->setDisabled(true);
    }else{
        rbCrosshairLeft->setDisabled(false);
        rbCrosshairTop->setDisabled(false);
        rbCrosshairRight->setDisabled(false);
    }

	*spacing = graphic->getVariableVector("$GRIDUNIT",
												   {0.0,0.0});
	cbXSpacing->setEditText( QString("%1").arg(spacing->x));
	cbYSpacing->setEditText( QString("%1").arg(spacing->y));

    if (cbXSpacing->currentText()=="0") {
        cbXSpacing->setEditText(tr("auto"));
    }
    if (cbYSpacing->currentText()=="0") {
        cbYSpacing->setEditText(tr("auto"));
    }
    cbXSpacing->setEnabled(cbGridOn->isChecked() && rbOrthogonalGrid->isChecked());
    cbYSpacing->setEnabled(cbGridOn->isChecked());

    // dimension text height:
	RS2::Unit unit = static_cast<RS2::Unit>(cbUnit->currentIndex());

    // dimension general factor:
    double dimfactor = graphic->getVariableDouble("$DIMLFAC", 1.0);
    cbDimFactor->setEditText(QString("%1").arg(dimfactor));

    // dimension general scale:
    double dimscale = graphic->getVariableDouble("$DIMSCALE", 1.0);
    cbDimScale->setEditText(QString("%1").arg(dimscale));

    double dimtxt = graphic->getVariableDouble("$DIMTXT",
                                               RS_Units::convert(2.5, RS2::Millimeter, unit));
    //RLZ    cbDimTextHeight->setCurrentText(QString("%1").arg(dimtxt));
    cbDimTextHeight->setEditText(QString("%1").arg(dimtxt));

    // dimension extension line extension:
    double dimexe = graphic->getVariableDouble("$DIMEXE",
                                               RS_Units::convert(1.25, RS2::Millimeter, unit));
    //RLZ    cbDimExe->setCurrentText(QString("%1").arg(dimexe));
    cbDimExe->setEditText(QString("%1").arg(dimexe));

    // dimension extension line offset:
    double dimexo = graphic->getVariableDouble("$DIMEXO",
                                               RS_Units::convert(0.625, RS2::Millimeter, unit));
    //RLZ    cbDimExo->setCurrentText(QString("%1").arg(dimexo));
    cbDimExo->setEditText(QString("%1").arg(dimexo));

    // dimension line gap:
    double dimgap = graphic->getVariableDouble("$DIMGAP",
                                               RS_Units::convert(0.625, RS2::Millimeter, unit));
    //RLZ    cbDimGap->setCurrentText(QString("%1").arg(dimgap));
    cbDimGap->setEditText(QString("%1").arg(dimgap));

    // dimension arrow size:
    double dimasz = graphic->getVariableDouble("$DIMASZ",
                                               RS_Units::convert(2.5, RS2::Millimeter, unit));
    //RLZ    cbDimAsz->setCurrentText(QString("%1").arg(dimasz));
    cbDimAsz->setEditText(QString("%1").arg(dimasz));
    // dimension tick size:
    double dimtsz = graphic->getVariableDouble("$DIMTSZ", 0.);
    cbDimTsz->setEditText(QString("%1").arg(dimtsz));
    // dimension alignment:
    int dimtih = graphic->getVariableInt("$DIMTIH", 0);
    cbDimTih->setCurrentIndex(dimtih);
//RLZ todo add more options for dimensions
    cbDimClrT->init(true, false);
    cbDimClrE->init(true, false);
    cbDimClrD->init(true, false);
    cbDimLwD->init(true, false);
    cbDimLwE->init(true, false);
    // fixed extension length:
    double dimfxl = graphic->getVariableDouble("$DIMFXL",
                                               RS_Units::convert(1.0, RS2::Millimeter, unit));
    cbDimFxL->setValue(dimfxl);
    int dimfxlon = graphic->getVariableInt("$DIMFXLON",0);
    if (dimfxlon > 0){
        cbDimFxL->setEnabled(true);
        cbDimFxLon->setChecked(true);
    } else {
        cbDimFxL->setEnabled(false);
        cbDimFxLon->setChecked(false);
    }
    int dimlwd = graphic->getVariableInt("$DIMLWD",-2); //default ByBlock
    cbDimLwD->setWidth(RS2::intToLineWidth(dimlwd));
    int dimlwe = graphic->getVariableInt("$DIMLWE",-2); //default ByBlock
    cbDimLwE->setWidth(RS2::intToLineWidth(dimlwe));

    // Dimensions / length format:
    int dimlunit = graphic->getVariableInt("$DIMLUNIT", lunits);
    cbDimLUnit->setCurrentIndex(dimlunit-1);

    // Dimensions length precision:
    int dimdec = graphic->getVariableInt("$DIMDEC", luprec);
    updateCBLengthPrecision(cbDimLUnit, cbDimDec);
    cbDimDec->setCurrentIndex(dimdec);
    // Dimensions length zeros:
    int dimzin = graphic->getVariableInt("$DIMZIN", 1);
    cbDimZin->setLinear();
    cbDimZin->setData(dimzin);

    // Dimensions / angle format:
    int dimaunit = graphic->getVariableInt("$DIMAUNIT", aunits);
    cbDimAUnit->setCurrentIndex(dimaunit);

    // Dimensions angle precision:
    int dimadec = graphic->getVariableInt("$DIMADEC", auprec);
    updateCBAnglePrecision(cbDimAUnit, cbDimADec);
    cbDimADec->setCurrentIndex(dimadec);
    // Dimensions angle zeros:
    int dimazin = graphic->getVariableInt("$DIMAZIN", 0);
//    cbDimAZin->setCurrentIndex(dimazin);
    cbDimAZin->setData(dimazin);

    int dimclrd = graphic->getVariableInt("$DIMCLRD", 0);
    int dimclre = graphic->getVariableInt("$DIMCLRE", 0);
    int dimclrt = graphic->getVariableInt("$DIMCLRT", 0);
    cbDimClrD->setColor(RS_FilterDXFRW::numberToColor(dimclrd));
    cbDimClrE->setColor(RS_FilterDXFRW::numberToColor(dimclre));
    cbDimClrT->setColor(RS_FilterDXFRW::numberToColor(dimclrt));

    QString dimtxsty = graphic->getVariableString("$DIMTXSTY", "standard");
    cbDimTxSty->setFont(dimtxsty);
    int dimdsep = graphic->getVariableInt("$DIMDSEP", 0);
    (dimdsep == 44) ? cbDimDSep->setCurrentIndex(1) :  cbDimDSep->setCurrentIndex(0);

    // spline line segments per patch:
    int splinesegs = graphic->getVariableInt("$SPLINESEGS", 8);
    //RLZ    cbSplineSegs->setCurrentText(QString("%1").arg(splinesegs));
    cbSplineSegs->setEditText(QString("%1").arg(splinesegs));

    RS_DEBUG->print("QG_DlgOptionsDrawing::setGraphic: splinesegs is: %d",
                    splinesegs);

    // encoding:
    /*
    QString encoding = graphic->getVariableString("$DWGCODEPAGE",
                                                  "ANSI_1252");
    encoding=RS_System::getEncoding(encoding);
    cbEncoding->setEditText(encoding);
    */

	updatePaperSize();
    updateUnitLabels();
}