コード例 #1
0
ファイル: REcmaRuler.cpp プロジェクト: Alpha-Kand/qcad
         QScriptValue
        REcmaRuler::setOrientation
        (QScriptContext* context, QScriptEngine* engine) 
        
        {
            //REcmaHelper::functionStart("REcmaRuler::setOrientation", context, engine);
            //qDebug() << "ECMAScript WRAPPER: REcmaRuler::setOrientation";
            //QCoreApplication::processEvents();

            QScriptValue result = engine->undefinedValue();
            
                    // public function: can be called from ECMA wrapper of ECMA shell:
                    RRuler* self = 
                        getSelf("setOrientation", context);
                  

                //Q_ASSERT(self!=NULL);
                if (self==NULL) {
                    return REcmaHelper::throwError("self is NULL", context);
                }
                
    
    if( context->argumentCount() ==
    1 && (
            context->argument(0).isNumber()
        ) /* type: Qt::Orientation */
    
    ){
    // prepare arguments:
    
                    // argument isStandardType
                    Qt::Orientation
                    a0 =
                    (Qt::Orientation)
                    (int)
                    context->argument( 0 ).
                    toNumber();
                
    // end of arguments

    // call C++ function:
    // return type 'void'
    
               self->setOrientation(a0);
    } else


        
            {
               return REcmaHelper::throwError("Wrong number/types of arguments for RRuler.setOrientation().",
                   context);
            }
            //REcmaHelper::functionEnd("REcmaRuler::setOrientation", context, engine);
            return result;
        }
コード例 #2
0
ファイル: REcmaRuler.cpp プロジェクト: Alpha-Kand/qcad
         QScriptValue
        REcmaRuler::getFont
        (QScriptContext* context, QScriptEngine* engine) 
        
        {
            //REcmaHelper::functionStart("REcmaRuler::getFont", context, engine);
            //qDebug() << "ECMAScript WRAPPER: REcmaRuler::getFont";
            //QCoreApplication::processEvents();

            QScriptValue result = engine->undefinedValue();
            
                    // public function: can be called from ECMA wrapper of ECMA shell:
                    RRuler* self = 
                        getSelf("getFont", context);
                  

                //Q_ASSERT(self!=NULL);
                if (self==NULL) {
                    return REcmaHelper::throwError("self is NULL", context);
                }
                
    
    if( context->argumentCount() ==
    0
    ){
    // prepare arguments:
    
    // end of arguments

    // call C++ function:
    // return type 'QFont'
    QFont cppResult =
        
               self->getFont();
        // return type: QFont
                // not standard type nor reference
                result = qScriptValueFromValue(engine, cppResult);
            
    } else


        
            {
               return REcmaHelper::throwError("Wrong number/types of arguments for RRuler.getFont().",
                   context);
            }
            //REcmaHelper::functionEnd("REcmaRuler::getFont", context, engine);
            return result;
        }
コード例 #3
0
ファイル: ROrthoGrid.cpp プロジェクト: Jackieee/qcad
void ROrthoGrid::paintRuler(RRuler& ruler, qreal devicePixelRatio) {
    RDocument* doc = view.getDocument();
    if (doc == NULL) {
        return;
    }

    RS::Unit unit = doc->getUnit();
    RS::LinearFormat linearFormat = doc->getLinearFormat();

    // use grid spacing if available or auto grid spacing:
    RVector localSpacing = spacing;
    if (!localSpacing.isValid() ||
        (autoSpacing.isValid() && autoSpacing.getMagnitude2d() < localSpacing.getMagnitude2d())) {
        localSpacing = autoSpacing;
    }

    // use meta grid spacing if available or auto meta grid spacing:
    RVector localMetaSpacing = metaSpacing;
    if (!localMetaSpacing.isValid() ||
        (autoMetaSpacing.isValid() && autoMetaSpacing.getMagnitude2d() < localMetaSpacing.getMagnitude2d())) {
        //localMetaSpacing = autoMetaSpacing;
    }

    //if (!localMetaSpacing.isValid()) {
    //    qDebug() << "no local meta spacing";
    //    return;
    //}

    if (localSpacing.getMagnitude()<1.0e-6 || localMetaSpacing.getMagnitude()<1.0e-6)  {
        //qDebug() << "local (meta) spacing too small";
        return;
    }

    RVector min = gridBox.getCorner1();
    RVector max = gridBox.getCorner2();
    bool isHorizontal = ruler.getOrientation() == Qt::Horizontal;

    double tickSpacing;
    //if (!RUnit::isMetric(doc->getUnit())) {
    if (isFractionalFormat(linearFormat) && !RUnit::isMetric(unit)) {
        if (isHorizontal) {
            tickSpacing = localSpacing.x;
        } else {
            tickSpacing = localSpacing.y;
        }
    } else {
        if (isHorizontal) {
            tickSpacing = localMetaSpacing.x;
        } else {
            tickSpacing = localMetaSpacing.y;
        }
        if (view.mapDistanceToView(tickSpacing) >= 80) {
            tickSpacing /= 10;
        } else if (view.mapDistanceToView(tickSpacing) >= 30) {
            tickSpacing /= 5;
        } else if (view.mapDistanceToView(tickSpacing) >= 20) {
            tickSpacing /= 2;
        }
    }

    // ideal tick spacing in pixels:
    int pSpacing = (int) ceil(view.mapDistanceToView(tickSpacing));

    QString l1 = RUnit::getLabel(isHorizontal ? min.x : min.y, *doc, false, true);
    QString l2 = RUnit::getLabel(isHorizontal ? max.x : max.y, *doc, false, true);
    int labelWidth = std::max(
            QFontMetrics(ruler.getFont()).boundingRect(l1).width(),
            QFontMetrics(ruler.getFont()).boundingRect(l2).width()) + 15;

    // smallest displayable distance between labels in steps (ticks):
    int minLabelStep = 1;
    if (pSpacing>0) {
        minLabelStep = labelWidth / pSpacing + 1;
    }

    int labelStep = minLabelStep;
    //if (!RUnit::isMetric(doc->getUnit())) {
    if (isFractionalFormat(linearFormat) && !RUnit::isMetric(unit)) {
        // non metric
        double f = 1.0/128;
        do {
            if (localMetaSpacing.isValid()) {
                if (isHorizontal) {
                    labelStep = RMath::mround(localMetaSpacing.x / localSpacing.x) * f;
                } else {
                    labelStep = RMath::mround(localMetaSpacing.y / localSpacing.y) * f;
                }
            }
            else {
                labelStep = (int)f;
            }
            f = f * 2;
            if (f>65536) {
                labelStep = -1;
            }
        } while (labelStep < minLabelStep && labelStep>=0);
    } else {
        // metric
        if (labelStep >= 3 && labelStep <= 4) {
            labelStep = 5;
        } else if (labelStep >= 6 && labelStep <= 9) {
            labelStep = 10;
        } else if (labelStep >= 11 && labelStep <= 19) {
            labelStep = 20;
        } else if (labelStep >= 21 && labelStep <= 99) {
            labelStep = 100;
        }
    }

    if (labelStep<0) {
        return;
    }

    if (labelStep<1) {
        labelStep = 1;
    }

    double minPos;
    double maxPos;
    if (isHorizontal) {
        minPos = (floor(view.mapFromView(RVector(0, 0)).x
                / (labelStep * tickSpacing))-1) * (labelStep * tickSpacing);
        maxPos = (ceil(view.mapFromView(RVector(view.getWidth(), 0)).x
                / (labelStep * tickSpacing))+1) * (labelStep * tickSpacing);
    } else {
        minPos = (floor(view.mapFromView(RVector(0, view.getHeight())).y
                / (labelStep * tickSpacing))-1) * (labelStep * tickSpacing);
        maxPos = (ceil(view.mapFromView(RVector(0, 0)).y
                / (labelStep * tickSpacing))+1) * (labelStep * tickSpacing);
    }

    if ((maxPos - minPos) / tickSpacing > 1e3) {
        return;
    }

    int c;
    double p;
    for (c = 0, p = minPos; p < maxPos; p += tickSpacing, ++c) {
        bool hasLabel = c % labelStep == 0;
        double v;
        if (isHorizontal) {
            v = view.mapToView(RVector(p, 0)).x;
        } else {
            v = view.mapToView(RVector(0, p)).y;
        }
        ruler.paintTick(v*devicePixelRatio, hasLabel, hasLabel ? RUnit::getLabel(p, *doc, false, true, true) : QString());
    }
}
コード例 #4
0
ファイル: REcmaRuler.cpp プロジェクト: Alpha-Kand/qcad
         QScriptValue
        REcmaRuler::paintTick
        (QScriptContext* context, QScriptEngine* engine) 
        
        {
            //REcmaHelper::functionStart("REcmaRuler::paintTick", context, engine);
            //qDebug() << "ECMAScript WRAPPER: REcmaRuler::paintTick";
            //QCoreApplication::processEvents();

            QScriptValue result = engine->undefinedValue();
            
                    // public function: can be called from ECMA wrapper of ECMA shell:
                    RRuler* self = 
                        getSelf("paintTick", context);
                  

                //Q_ASSERT(self!=NULL);
                if (self==NULL) {
                    return REcmaHelper::throwError("self is NULL", context);
                }
                
    
    if( context->argumentCount() ==
    3 && (
            context->argument(0).isNumber()
        ) /* type: int */
     && (
            context->argument(1).isBool()
        ) /* type: bool */
     && (
            context->argument(2).isString()
        ) /* type: QString */
    
    ){
    // prepare arguments:
    
                    // argument isStandardType
                    int
                    a0 =
                    (int)
                    
                    context->argument( 0 ).
                    toNumber();
                
                    // argument isStandardType
                    bool
                    a1 =
                    (bool)
                    
                    context->argument( 1 ).
                    toBool();
                
                    // argument isStandardType
                    QString
                    a2 =
                    (QString)
                    
                    context->argument( 2 ).
                    toString();
                
    // end of arguments

    // call C++ function:
    // return type 'void'
    
               self->paintTick(a0
        ,
    a1
        ,
    a2);
    } else


        
            {
               return REcmaHelper::throwError("Wrong number/types of arguments for RRuler.paintTick().",
                   context);
            }
            //REcmaHelper::functionEnd("REcmaRuler::paintTick", context, engine);
            return result;
        }
コード例 #5
0
ファイル: REcmaRuler.cpp プロジェクト: Alpha-Kand/qcad
    // public methods:
     QScriptValue
        REcmaRuler::setGraphicsView
        (QScriptContext* context, QScriptEngine* engine) 
        
        {
            //REcmaHelper::functionStart("REcmaRuler::setGraphicsView", context, engine);
            //qDebug() << "ECMAScript WRAPPER: REcmaRuler::setGraphicsView";
            //QCoreApplication::processEvents();

            QScriptValue result = engine->undefinedValue();
            
                    // public function: can be called from ECMA wrapper of ECMA shell:
                    RRuler* self = 
                        getSelf("setGraphicsView", context);
                  

                //Q_ASSERT(self!=NULL);
                if (self==NULL) {
                    return REcmaHelper::throwError("self is NULL", context);
                }
                
    
    if( context->argumentCount() ==
    1 && (
            context->argument(0).isVariant() || 
            context->argument(0).isQObject() || 
            context->argument(0).isNull()
        ) /* type: RGraphicsView * */
    
    ){
    // prepare arguments:
    
                    // argument is pointer
                    RGraphicsView * a0 = NULL;

                    a0 = 
                        REcmaHelper::scriptValueTo<RGraphicsView >(
                            context->argument(0)
                        );
                    
                    if (a0==NULL && 
                        !context->argument(0).isNull()) {
                        return REcmaHelper::throwError("RRuler: Argument 0 is not of type RGraphicsView *RGraphicsView *.", context);                    
                    }
                
    // end of arguments

    // call C++ function:
    // return type 'void'
    
               self->setGraphicsView(a0);
    } else


        
            {
               return REcmaHelper::throwError("Wrong number/types of arguments for RRuler.setGraphicsView().",
                   context);
            }
            //REcmaHelper::functionEnd("REcmaRuler::setGraphicsView", context, engine);
            return result;
        }