/*!
    \class HsAnchorPointInBottomRight
    \brief Diagonal widget positioning algorithm.
    
    Sets widget's lower right corner to follow content area's diagonal.
    Widgets are positioned to certain offset to each other.
*/
HsWidgetPositioningOnWidgetAdd::Result HsAnchorPointInBottomRight::convert(
    const QRectF &contentArea,
    const QList<QRectF> &existingRects,
    const QList<QRectF> &newRects,
    const QPointF &startPoint)
{
    Q_UNUSED(existingRects);

    HsWidgetPositioningOnWidgetAdd::Result result;
    QList<QRectF> toGeometries;

    //Offset for widgets' bottom right position to each other
    qreal k = contentArea.height()/contentArea.width(); //slope of the diagonal
    qreal offset_x = offset/(sqrt(k + 1));
    qreal offset_y = k*offset_x;
    QPointF offsetPoint(offset_x, offset_y);
    
    QPointF anchorPoint;
   
    if(startPoint.isNull()){

        QLineF diagonal(contentArea.topLeft(), contentArea.bottomRight());
        QLineF widgetRightSide(contentArea.center().x()+ newRects.at(0).width()/2,
                           contentArea.top(),
                           contentArea.center().x()+ newRects.at(0).width()/2,
                           contentArea.bottom());

        // right side line intersection with diagonal will be bottom right position
        // for the first rect
        if(QLineF::BoundedIntersection != 
            diagonal.intersect(widgetRightSide, &anchorPoint)) {
            result.calculatedRects = newRects;
            return result; //Return original since undefined error.
                            //In this case widget's must be wider than the content area.
        }
    } else {
        anchorPoint = startPoint - offsetPoint;
    }

    QRectF widgetRect;
    for(int i=0;i<newRects.count();++i) {
        widgetRect = newRects.at(i);
        widgetRect.moveBottomRight(anchorPoint);
        //if widget rect doesn't fit, try to move it
        if(!contentArea.contains(widgetRect)) {
            /*! precondition is that
             widget's max height < content area height
             widget's max widht < content area width
            */
            widgetRect.moveBottomRight(contentArea.bottomRight());
            // anchorPoin is always previous bottom right
            anchorPoint = widgetRect.bottomRight();
        }
        toGeometries << widgetRect;
        anchorPoint -= offsetPoint;
        
    }
    result.calculatedRects = toGeometries;
    return result;
}
bool ContentLoader::load( const QString& filename,
                          const QPointF& windowCenterPosition,
                          const QSizeF& windowSize )
{
    put_flog( LOG_INFO, "opening: '%s'", filename.toLocal8Bit().constData( ));

    ContentPtr content = ContentFactory::getContent( filename );
    if( !content )
    {
        put_flog( LOG_WARN, "ignoring unsupported file: '%s'",
                  filename.toLocal8Bit().constData( ));
        return false;
    }

    ContentWindowPtr contentWindow( new ContentWindow( content ));
    ContentWindowController controller( *contentWindow, *displayGroup_ );

    if( windowSize.isValid( ))
        controller.resize( windowSize );
    else
        controller.adjustSize( SIZE_LARGE );

    if( windowCenterPosition.isNull( ))
        controller.moveCenterTo( displayGroup_->getCoordinates().center( ));
    else
        controller.moveCenterTo( windowCenterPosition );

    displayGroup_->addContentWindow( contentWindow );

    return true;
}
Example #3
0
    //--------------------------------------------------------------------------------------------------
    /// 
    //--------------------------------------------------------------------------------------------------
    virtual QwtText trackerText(const QPoint& pos) const override
    {
        QwtText txt;

        const RiuSummaryQwtPlot* sumPlot = dynamic_cast<const RiuSummaryQwtPlot*>(this->plot());
        if (sumPlot)
        {
            int closestYAxis = QwtPlot::yLeft;
            QString timeString;
            QString valueString;
            QPointF closestPoint = sumPlot->closestCurvePoint(pos, &valueString, &timeString, &closestYAxis);
            if (!closestPoint.isNull())
            {
                QString str = valueString;

                if (!timeString.isEmpty())
                {
                    str += QString(" (%1)").arg(timeString);
                }

                txt.setText(str);
            }

            RiuSummaryQwtPlot* nonConstPlot = const_cast<RiuSummaryQwtPlot*>(sumPlot);
            nonConstPlot->updateClosestCurvePointMarker(closestPoint, closestYAxis);
        }

        return txt;
    }
void NetworkEditorView::wheelEvent(QWheelEvent* e) {
    QPointF numPixels = e->pixelDelta() / 5.0;
    QPointF numDegrees = e->angleDelta() / 8.0 / 15;

    if (e->modifiers() == Qt::ControlModifier) {
        if (!numPixels.isNull()) {
            zoom(qPow(1.05,  numPixels.y()));

        } else if (!numDegrees.isNull()) {
            zoom(qPow(1.05,  numDegrees.y()));
        }
    } else {
        QGraphicsView::wheelEvent(e);
    }
    e->accept();
}
Example #5
0
void MapWindow::mouseMoveEvent(QMouseEvent *ev)
{
#if QT_VERSION < 0x050000
    QPointF delta = ev->posF() - m_lastPos;
#else
    QPointF delta = ev->localPos() - m_lastPos;
#endif

    if (!delta.isNull()) {
        if (ev->buttons() == Qt::LeftButton && ev->modifiers() & Qt::ShiftModifier) {
            m_map->setPitch(m_map->pitch() - delta.y());
        } else if (ev->buttons() == Qt::LeftButton) {
            m_map->moveBy(delta);
        } else if (ev->buttons() == Qt::RightButton) {
#if QT_VERSION < 0x050000
            m_map->rotateBy(m_lastPos, ev->posF());
#else
            m_map->rotateBy(m_lastPos, ev->localPos());
#endif
        }
    }

#if QT_VERSION < 0x050000
    m_lastPos = ev->posF();
#else
    m_lastPos = ev->localPos();
#endif
    ev->accept();
}
bool PunchFilter::setOption(int option, const QVariant &value)
{
    bool bOK = true;
    switch (option) {
        case QtImageFilter::Radius:
        {
            double radius = value.toDouble(&bOK);
            if (bOK) m_Radius = radius;
        }
        break;

        case QtImageFilter::Center:
        {
            QPointF center = value.toPointF();
            if (center.isNull()) {
                bOK = false;
            } else {
                m_Center = center;
            }
        }
        break;

        case QtImageFilter::Force:
        {
            double force = value.toDouble(&bOK);
            if (bOK) m_Force = force;
        }
        break;

        default:
            bOK = false;
        break;
    }
    return bOK;
}
Example #7
0
void QtBasicGraph::addPoint(const QPointF &value)
{
    QPointF oldval;

    if (!m_values.isEmpty())
        oldval = m_values.last();

    if (!oldval.isNull() && value.x() < oldval.x()) {
        qWarning("QtBasicGraph::addPoint(): the new point's x value is less than the last point's x value.");
        return; 
    }

    m_values << value;

    if (!oldval.isNull()) {
        qreal deltaf = width() * ((value.x() - oldval.x()) / m_xrange);
        int delta = (int) deltaf;
        m_scroll_error += (deltaf - qreal(delta));

        if (m_scroll_error > qreal(1.0)) {
            m_scroll_error--;
            delta++;
        }

        if (delta < width()) {
            scroll(-delta, 0);
            update(width() - delta - 3, 0, delta + 3, height());
        } else {
            m_scroll_error = 0;
            update();
        }

        // purge old data
        qreal left = value.x() - m_xrange;

        int i;
        for (i = 0; i < m_values.size(); ++i) {
            if (m_values[i].x() > left)
                break;
        }
        i--;
        
        if (i > 0 && i < (m_values.size() - 1))
            m_values.erase(m_values.begin(), m_values.begin() + i);
  
  }
}
Example #8
0
void TscoreClef::untouched(const QPointF& scenePos) {
    if (!scenePos.isNull() && m_tapTimer.hasExpired(300)) {
        QGraphicsSceneMouseEvent me(QEvent::MouseButtonPress);
        me.setPos(mapFromScene(scenePos));
        me.setButton(Qt::LeftButton);
        mousePressEvent(&me);
    }
}
Example #9
0
void SymbolDataEditor::setSymbolData(const QPointF _inPoint, const QPointF _outPoint, const QRectF _limits)
{
    if (scene->items().isEmpty())
        return;

    QRectF symbolRect = scene->items(Qt::AscendingOrder).at(Item::SymbolItem)->boundingRect();
    symbolRect.moveTopLeft(scene->items(Qt::AscendingOrder).at(Item::SymbolItem)->pos());
    symbolRect.adjust(symbolRect.width() / 4, symbolRect.height() / 4,
                      -symbolRect.width() / 4, -symbolRect.height() / 4);

    //try to set data automatically if they're not set
    if (_inPoint.isNull())
    {
        if (setupPoints)
            inPoint = getBeginPoint();
        else
        {
            inPoint = symbolRect.topLeft();
            inPoint.ry() += symbolRect.height() / 2;
        }
    }
    else
        inPoint = fromStored(_inPoint);

    if (_outPoint.isNull())
    {
        if (setupPoints)
            outPoint = getEndPoint();
        else
        {
            outPoint = symbolRect.topRight();
            outPoint.ry() += symbolRect.height() / 2;
        }
    }
    else
        outPoint = fromStored(_outPoint);

    if (_limits.isNull())
        limits = symbolRect;
    else
        limits = QRectF(fromStored(_limits.topLeft()),
                        fromStored(_limits.bottomRight()));

    correctLimits();
    addDataItems();
}
Example #10
0
void
ZoomWidget::moveViewWorldCs( const QPointF & d )
{
    if ( d.isNull() )
        return;
    wm_.translate( d.x(), -d.y() );
    emit matrixChanged( wm_ );
}
void KisPrescaledProjection::viewportMoved(const QPointF &offset)
{
    // FIXME: \|/
    if (m_d->prescaledQImage.isNull()) return;
    if (offset.isNull()) return;

    QPoint alignedOffset = offset.toPoint();

    if(offset != alignedOffset) {
        /**
         * We can't optimize anything when offset is float :(
         * Just prescale entire image.
         */
        dbgRender << "prescaling the entire image because the offset is float";
        preScale();
        return;
    }

    QImage newImage = QImage(m_d->viewportSize, QImage::Format_ARGB32);
    newImage.fill(0);

    /**
     * TODO: viewport rects should be cropped by the borders of
     * the image, because it may be requested to read/write
     * outside QImage and copyQImage will not chatch it
     */
    QRect newViewportRect = QRect(QPoint(0,0), m_d->viewportSize);
    QRect oldViewportRect = newViewportRect.translated(alignedOffset);

    QRegion updateRegion = newViewportRect;
    QRect savedArea = newViewportRect & oldViewportRect;

    if(!savedArea.isEmpty()) {
        copyQImage(alignedOffset.x(), alignedOffset.y(), &newImage, m_d->prescaledQImage);
        updateRegion -= savedArea;
    }

    QPainter gc(&newImage);
    QVector<QRect> rects = updateRegion.rects();

    foreach(const QRect &rect, rects) {

        QRect imageRect =
            m_d->coordinatesConverter->viewportToImage(rect).toAlignedRect();
        QVector<QRect> patches =
            KritaUtils::splitRectIntoPatches(imageRect, m_d->updatePatchSize);

        foreach(const QRect& rc, patches) {
            QRect viewportPatch =
                m_d->coordinatesConverter->imageToViewport(rc).toAlignedRect();

            KisPPUpdateInfoSP info = getInitialUpdateInformation(QRect());
            fillInUpdateInformation(viewportPatch, info);
            drawUsingBackend(gc, info);
        }
Example #12
0
void NavigationView::plotLineForSelected() {
    if (scene()->selectedItems().count()<2)
        return;

    QLineF vectorLine(scene()->selectedItems().at(0)->pos(), scene()->selectedItems().at(1)->pos());

    QLineF sides[4] = {
        QLineF(0, 0, 0, scene()->height()),
        QLineF(scene()->width(), 0, scene()->width(), scene()->height()),
        QLineF(0, 0, scene()->width(), 0),
        QLineF(0, scene()->height(), scene()->width(), scene()->height())
    };

    QPointF yStart;
    QPointF xStart;
    int i=0;

    while(yStart.isNull()) {
        if (vectorLine.intersect(sides[i++], &yStart)!=QLineF::BoundedIntersection) {
            qDebug("could not intersect y");
        }
        i++;
    }

    i=1;

    while(xStart.isNull()) {
        if (vectorLine.intersect(sides[i++], &xStart)!=QLineF::BoundedIntersection) {
            qDebug("could not intersect x");
        }
    }

    //IntersectionLineItem lineItem(QLineF(yStart, xStart);

    QPen linePen(Qt::black);
    linePen.setWidth(3);
    QGraphicsLineItem * line = scene()->addLine(QLineF(yStart, xStart));
    line->setPen(linePen);
    line->setFlag(QGraphicsItem::ItemIsSelectable, true);

    emit newLineAdded(mapSceneToGeo(scene()->selectedItems().at(0)->pos()), mapSceneToGeo(scene()->selectedItems().at(1)->pos()));
}
Example #13
0
 void updateCurrentTime(int ms) {
     QPointF point = m_cache.at(ms);
     if (! point.isNull()) {
         ++ m_hits;
     } else {
         point = m_path.pointAtPercent(qreal(ms) / m_duration);
         m_cache[ms] = point;
         ++ m_misses;
     }
     if (m_target) m_target->setPos(point);
 }
Example #14
0
void QKineticScrollerPrivate::timerEventWhileScrolling()
{
    qreal deltaTime = qreal(scrollRelativeTimer.restart()) / 1000;
    qreal time = qreal(scrollAbsoluteTimer.elapsed()) / 1000;

    // calculate the velocity for the passed interval deltatime.
    // using the midpoint of the interval gives a better precision than using just time.
    QPointF newVelocity = calculateVelocity(time - deltaTime / 2);
    QPointF deltaPos = newVelocity * deltaTime * pixelPerMeter;

    // -- move (convert from [m/s] to [pix/frame]
    if (!deltaPos.isNull())
        setContentPositionHelper(deltaPos);

    qKSDebug() << "QKS::timerEventWhileScrolling() -- DeltaPos:" << deltaPos << "- NewVel:" <<  newVelocity  << "- Time:" <<  time;

    if (newVelocity.isNull() ||
            (releaseVelocity.isNull() && !scrollToX && !scrollToY && !overshootX && !overshootY))
    // if (newVelocity.isNull())
        setState(QKineticScroller::StateInactive);
}
Example #15
0
void QPolygonF::translate(const QPointF &offset)
{
    if (offset.isNull())
        return;

    QPointF *p = data();
    int i = size();
    while (i--) {
        *p += offset;
        ++p;
    }
}
    void applyBrushOrigin(const QPointF &origin)
    {
        if (brush.brush && !origin.isNull()) {
            D2D1_MATRIX_3X2_F transform;
            brush.brush->GetTransform(&transform);

            brush.brush->SetTransform(*(D2D1::Matrix3x2F::ReinterpretBaseType(&transform))
                                      * D2D1::Matrix3x2F::Translation(origin.x(), origin.y()));
        }

        currentBrushOrigin = origin;
    }
Example #17
0
QmlItemNode QmlItemNode::createQmlItemNode(AbstractView *view, const ItemLibraryEntry &itemLibraryEntry, const QPointF &position, NodeAbstractProperty parentproperty)
{
    QmlItemNode newQmlItemNode;

    try {
        RewriterTransaction transaction = view->beginRewriterTransaction(QByteArrayLiteral("QmlItemNode::createQmlItemNode"));

        NodeMetaInfo metaInfo = view->model()->metaInfo(itemLibraryEntry.typeName());

        int minorVersion = metaInfo.minorVersion();
        int majorVersion = metaInfo.majorVersion();

        typedef QPair<PropertyName, QString> PropertyBindingEntry;
        QList<PropertyBindingEntry> propertyBindingList;
        if (itemLibraryEntry.qmlSource().isEmpty()) {
            QList<QPair<PropertyName, QVariant> > propertyPairList;
            if (!position.isNull()) {
                propertyPairList.append(qMakePair(PropertyName("x"), QVariant(qRound(position.x()))));
                propertyPairList.append(qMakePair(PropertyName("y"), QVariant(qRound(position.y()))));
            }

            foreach (const PropertyContainer &property, itemLibraryEntry.properties()) {
                if (property.type() == QStringLiteral("binding")) {
                    propertyBindingList.append(PropertyBindingEntry(property.name(), property.value().toString()));
                } else {
                    propertyPairList.append(qMakePair(property.name(), property.value()));
                }
            }

            newQmlItemNode = QmlItemNode(view->createModelNode(itemLibraryEntry.typeName(), majorVersion, minorVersion, propertyPairList));
        } else {
            newQmlItemNode = createQmlItemNodeFromSource(view, itemLibraryEntry.qmlSource(), position);
        }

        if (parentproperty.isValid())
            parentproperty.reparentHere(newQmlItemNode);

        if (!newQmlItemNode.isValid())
            return newQmlItemNode;

        newQmlItemNode.setId(view->generateNewId(itemLibraryEntry.name()));

        if (!view->currentState().isBaseState()) {
            newQmlItemNode.modelNode().variantProperty("opacity").setValue(0);
            newQmlItemNode.setVariantProperty("opacity", 1);
        }

        foreach (const PropertyBindingEntry &propertyBindingEntry, propertyBindingList)
            newQmlItemNode.modelNode().bindingProperty(propertyBindingEntry.first).setExpression(propertyBindingEntry.second);

        Q_ASSERT(newQmlItemNode.isValid());
    }
void XFormView::updateCtrlPoints(const QPolygonF &points)
{
    QPointF trans = points.at(0) - ctrlPoints.at(0);

    if (qAbs(points.at(0).x() - points.at(1).x()) < 10
        && qAbs(points.at(0).y() - points.at(1).y()) < 10)
        pts->setPoints(ctrlPoints);
    if (!trans.isNull()) {
        ctrlPoints[0] = points.at(0);
        ctrlPoints[1] += trans;
        pts->setPoints(ctrlPoints);
    }
    ctrlPoints = points;

    QLineF line(ctrlPoints.at(0), ctrlPoints.at(1));
    m_rotation = line.angle(QLineF(0, 0, 1, 0));
    if (line.dy() < 0)
        m_rotation = 360 - m_rotation;

    if (trans.isNull())
        emit rotationChanged(int(m_rotation*10));
}
Example #19
0
void
ZoomWidget::moveView( const QPointF & d )
{
    if ( d.isNull() )
        return;

    QMatrix m;

    m = wm_.inverted();
    m.translate( -d.x(), -d.y() );
    wm_ = m.inverted();
    emit matrixChanged( wm_ );
}
Example #20
0
myTextItem::myTextItem(const QString &tag, const QString &text,
                       const QPointF &ps,  const QFont &fnt,
                       const QColor &col,  bool v_mode)
                           : m_tag  ( QString("[XXX]") )
                           , m_text ( QString() )
                           , m_mode (false)

{
    v_mode = m_mode;

    if (text.isEmpty()){
        this->setEText(tag);
    }else{
        this->setEText(text);
    }

    if (v_mode){
        this->setPlainText(tag);
    }else{
        this->setPlainText(text);
    }

    if (ps.isNull()){
        this->setPos( QPointF(100.0,100.0) );
    }else{
        this->setPos(ps);
    }

    this->setFont(fnt);

    //    if (fnt){
    //        this->setFont(fnt);
    //    }else{
    //        this->setFont( QFont("Times", 14, QFont::Bold) ) ;
    //    }
    if( col.isValid() ){
        this->setDefaultTextColor( col );
    }else{
        this->setDefaultTextColor(  Qt::black );
    }




    this->setETag(tag);
    this->setZValue(100);
    this->setFlag(QGraphicsItem::ItemIsMovable, true);
    this->setFlag(QGraphicsItem::ItemIsSelectable, true);
    this->setFlag(QGraphicsItem::ItemIsFocusable, true);
    this->setData(ObjectName, "tElem");
}
Example #21
0
void CChartTable::dragScrPosition( const QPointF& _rqPointFScrPositionOffset )
{
  if( bIgnoreUpdate || QTabWidget::currentIndex() < 0 || _rqPointFScrPositionOffset.isNull() ) return;
  CChart* __poChart = (CChart*)QTabWidget::currentWidget();
  /*
   * NOTE: We do not move the chart by calling this->setGeoPosition directly because it leads
   *       to extra offset artefacts due to the pixel<->geographical position back and forth conversion.
   *       Instead, we move the chart directly by modifying the pixel positon and
   *       update the reference geographical position accordingly.
   */
  __poChart->move( _rqPointFScrPositionOffset );
  // __poChart->update();
  if( __poChart->isPositionLocked() ) setGeoPosition( __poChart->getGeoPosition(), true );
}
Example #22
0
bool QBezier::deletePoint(const QPointF& c)
{
    if (c.isNull() || knowPoints.isEmpty() )
    {
        return false;
    }
    QList<QPointF>::iterator itor;
    for(itor = knowPoints.begin();itor != knowPoints.end();itor++)
    {
        if(*itor == c)
            break;
    }
    knowPoints.erase(itor);
    return true;
}
Example #23
0
QVariant ImageMarker::itemChange(GraphicsItemChange change, const QVariant &value)
{
    if (change == ItemPositionChange && scene()) {
        QPointF newPos = getLimitPos(value.toPointF());

        if (! newPos.isNull()) {
            return newPos;
        }
    }
    else if (change == ItemPositionHasChanged && scene()) {
        m_view->updateCircles();
    }

    return QGraphicsItem::itemChange(change, value);
}
Example #24
0
void QLagrage::addPoint(const QPointF& p)
{
    if( p.isNull())
        return;
    QList<QPointF>::iterator itor;
    for( itor = knowPoints.begin();itor != knowPoints.end();itor++)
    {
        if(*itor == p || qAbs(p.x() - (*itor).x()) < deta)
            return;
        if( (*itor).x() > p.x())
            break;
    }
    knowPoints.insert(itor,p);
    updateCurve();
}
void ObjectSelectionTool::keyPressed(QKeyEvent *event)
{
    if (mAction != NoAction) {
        event->ignore();
        return;
    }

    QPointF moveBy;

    switch (event->key()) {
    case Qt::Key_Up:    moveBy = QPointF(0, -1); break;
    case Qt::Key_Down:  moveBy = QPointF(0, 1); break;
    case Qt::Key_Left:  moveBy = QPointF(-1, 0); break;
    case Qt::Key_Right: moveBy = QPointF(1, 0); break;
    default:
        AbstractObjectTool::keyPressed(event);
        return;
    }

    const QSet<MapObjectItem*> &items = mapScene()->selectedObjectItems();
    const Qt::KeyboardModifiers modifiers = event->modifiers();

    if (moveBy.isNull() || items.isEmpty() || (modifiers & Qt::ControlModifier)) {
        event->ignore();
        return;
    }

    const bool moveFast = modifiers & Qt::ShiftModifier;
    const bool snapToFineGrid = Preferences::instance()->snapToFineGrid();

    if (moveFast) {
        // TODO: This only makes sense for orthogonal maps
        moveBy.rx() *= mapDocument()->map()->tileWidth();
        moveBy.ry() *= mapDocument()->map()->tileHeight();
        if (snapToFineGrid)
            moveBy /= Preferences::instance()->gridFine();
    }

    QUndoStack *undoStack = mapDocument()->undoStack();
    undoStack->beginMacro(tr("Move %n Object(s)", "", items.size()));
    int i = 0;
    foreach (MapObjectItem *objectItem, items) {
        MapObject *object = objectItem->mapObject();
        const QPointF oldPos = object->position();
        const QPointF newPos = oldPos + moveBy;
        undoStack->push(new MoveMapObject(mapDocument(), object, newPos, oldPos));
        ++i;
    }
Example #26
0
void MapToVariantConverter::addLayerAttributes(QVariantMap &layerVariant,
                                               const Layer &layer) const
{
    layerVariant[QLatin1String("name")] = layer.name();
    layerVariant[QLatin1String("x")] = layer.x();
    layerVariant[QLatin1String("y")] = layer.y();
    layerVariant[QLatin1String("visible")] = layer.isVisible();
    layerVariant[QLatin1String("opacity")] = layer.opacity();

    const QPointF offset = layer.offset();
    if (!offset.isNull()) {
        layerVariant[QLatin1String("offsetx")] = offset.x();
        layerVariant[QLatin1String("offsety")] = offset.y();
    }

    addProperties(layerVariant, layer.properties());
}
Example #27
0
//没有必要按照X的升序排列
void QBezier::addPoint(const QPointF& c)
{
    if (c.isNull())
	return;
    if ( knowPoints.isEmpty() )
    {
        knowPoints.append(c);
	updateCurve();
	return;
    }
    if(-1 != knowPoints.indexOf(c))
    {
        return;
    }
    knowPoints.append(c);
    updateCurve();
}
Example #28
0
void GpxLayer::zoom(int level)
{
    if (m_track.count() > 1) {
        int scale = 1 << level;
        m_trackOnScreen.clear();
        m_trackOffset = map()->raw2screen(m_track.first().x(), m_track.first().y(), scale);
        m_trackOnScreen << QPoint(0, 0);
        for (int i = 1; i < m_track.count(); ++i) {
            QPointF p = m_track.at(i);
            if (!p.isNull()) {
                m_trackOnScreen << map()->raw2screen(p.x(), p.y(), scale) - m_trackOffset;
            } else {
                m_trackOnScreen << QPoint();
            }
        }
    }
}
Example #29
0
bool QKineticScrollerPrivate::moveWhilePressed(QKineticScroller::Input, const QPointF &position, qint64 timestamp)
{
    Q_Q(QKineticScroller);

    QPointF deltaPixel = position - pressPosition;

    bool moveStarted = ((deltaPixel.manhattanLength() / pixelPerMeter) > dragStartDistance);

    if (moveStarted) {
        qreal deltaXtoY = qAbs(pressPosition.x() - position.x()) - qAbs(pressPosition.y() - position.y());
        deltaXtoY /= pixelPerMeter;

        QPointF maxPos = q->maximumContentPosition();
        bool canScrollX = (maxPos.x() > 0);
        bool canScrollY = (maxPos.y() > 0);

        if (hOvershootPolicy == QKineticScroller::OvershootAlwaysOn)
            canScrollX = true;
        if (vOvershootPolicy == QKineticScroller::OvershootAlwaysOn)
            canScrollY = true;

        if (deltaXtoY < 0) {
            if (!canScrollY && (!canScrollX || (-deltaXtoY >= dragStartDirectionErrorMargin)))
                moveStarted = false;
        } else {
            if (!canScrollX && (!canScrollY || (deltaXtoY >= dragStartDirectionErrorMargin)))
                moveStarted = false;
        }
    }

    if (moveStarted) {
        if (cancelPress)
            q->cancelPress(pressPosition);
        setState(QKineticScroller::StateDragging);

        // subtract the dragStartDistance
        deltaPixel = deltaPixel - deltaPixel * (dragStartDistance / deltaPixel.manhattanLength());

        if (!deltaPixel.isNull()) {
            // handleDrag updates lastPosition, lastTimestamp and velocity
            handleDrag(pressPosition + deltaPixel, timestamp);
        }
    }
    return moveStarted;
}
static PyObject *meth_QPointF_isNull(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        QPointF *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QPointF, &sipCpp))
        {
            bool sipRes;

            Py_BEGIN_ALLOW_THREADS
            sipRes = sipCpp->isNull();
            Py_END_ALLOW_THREADS

            return PyBool_FromLong(sipRes);
        }
    }