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; }
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()); } }