Пример #1
0
    void MapControl::wheelEvent(QWheelEvent *evnt)
    {
        if(mouse_wheel_events &&
            evnt->orientation() == Qt::Vertical)
        {
            if(evnt->delta() > 0)
            {
                if( currentZoom() == layermanager->maxZoom() )
                {
                    return;
                }

                setView(clickToWorldCoordinate(evnt->pos())); //zoom in under mouse cursor
                zoomIn();
            }
            else
            {
                if( currentZoom() == layermanager->minZoom() )
                {
                    return;
                }
                zoomOut();
            }
            evnt->accept();
        }
        else
        {
            evnt->ignore();
        }
    }
Пример #2
0
/**
 * Zoom the view in and out.
 */
void UMLView::wheelEvent(QWheelEvent* event)
{
    // get the position of the mouse before scaling, in scene coords
    QPointF pointBeforeScale(mapToScene(event->pos()));

    // get the original screen centerpoint
    QPointF screenCenter = center();

    // scale the view ie. do the zoom
    double scaleFactor = 1.15;
    if (event->delta() > 0) {
        // zoom in
        if (currentZoom() < 500) {
            scale(scaleFactor, scaleFactor);
        }
    } else {
        // zooming out
        if (currentZoom() > 10) {
            scale(1.0 / scaleFactor, 1.0 / scaleFactor);
        }
    }

    // get the position after scaling, in scene coords
    QPointF pointAfterScale(mapToScene(event->pos()));

    // get the offset of how the screen moved
    QPointF offset = pointBeforeScale - pointAfterScale;

    // adjust to the new center for correct zooming
    QPointF newCenter = screenCenter + offset;
    setCenter(newCenter);

    DEBUG(DBG_SRC) << "currentZoom=" << currentZoom();
    UMLApp::app()->slotZoomSliderMoved(currentZoom());
}
Пример #3
0
    void QmlMapControl::zoomOut(QPoint middle)
    {
        if( currentZoom() == 0 )
        {
            return;
        }

        layermanager->zoomOut(middle);
        updateView();
        emit viewChanged(currentCoordinate(), currentZoom());
    }
Пример #4
0
    void QmlMapControl::setZoom(int zoomlevel)
    {
        if ( currentZoom() == zoomlevel ||
             zoomlevel < 0 ||
             zoomlevel > 17 )
        {
            return;
        }

        layermanager->setZoom(zoomlevel);
        updateView();
        emit viewChanged(currentCoordinate(), currentZoom());
        refresh();
    }
Пример #5
0
    void MapControl::resize(const QSize newSize)
    {
        this->size = newSize;
        screen_middle = QPoint(newSize.width()/2, newSize.height()/2);

        this->setMaximumSize(newSize.width()+1, newSize.height()+1);
        layermanager->resize(newSize);      

        emit viewChanged(currentCoordinate(), currentZoom());
    }
Пример #6
0
    void QmlMapControl::wheelEvent(QWheelEvent *evnt)
    {
        if(mouse_wheel_events &&
            evnt->orientation() == Qt::Vertical)
        {
            if(evnt->delta() > 0)
            {
                if( currentZoom() == 17 )
                {
                    return;
                }

                QPoint pnt = evnt->pos();
                QPoint newPoint( width()-pnt.x(), height()-pnt.y() );

                setView(clickToWorldCoordinate(pnt));
                zoomIn(pnt);
                setView(clickToWorldCoordinate(newPoint));
            }
            else
            {
                if( currentZoom() == 0 )
                {
                    return;
                }
                QPoint pnt = evnt->pos();
                QPoint newPoint( width()-pnt.x(), height()-pnt.y() );

                setView(clickToWorldCoordinate(pnt));
                zoomOut(pnt);
                setView(clickToWorldCoordinate(newPoint));
            }
            evnt->accept();
        }
        else
        {
            evnt->ignore();
        }
    }
Пример #7
0
/**
 * Sets the zoom of the diagram.
 */
void UMLView::setZoom(int zoom)
{
    if (zoom < 10) {
        zoom = 10;
    } else if (zoom > 500) {
        zoom = 500;
    }

    QMatrix wm;
    wm.scale(zoom / 100.0, zoom / 100.0);
    setMatrix(wm);

    m_nZoom = currentZoom();
    umlScene()->resizeSceneToItems();
}
Пример #8
0
    void QmlMapControl::mouseMoveEvent(QMouseEvent* evnt)
    {
        // emit(mouseEvent(evnt));

        /*
        // rotating
           QMouseEvent* me = new QMouseEvent(evnt->type(), qm.map(QPoint(evnt->x(),evnt->y())), evnt->button(), evnt->buttons(), evnt->modifiers());
           evnt = me;
        */
        if (mousepressed && mymousemode == Panning)
        {
            QPoint offset = pre_click_px - QPoint(evnt->x(), evnt->y());
            layermanager->scrollView(offset);
            pre_click_px = QPoint(evnt->x(), evnt->y());
        }
        else if (mousepressed && mymousemode == Dragging)
        {
            current_mouse_pos = QPoint(evnt->x(), evnt->y());
        }

        evnt->accept();
        update();
        emit viewChanged(currentCoordinate(), currentZoom());
    }
Пример #9
0
    void MapControl::paintEvent(QPaintEvent* evnt)
    {
        QWidget::paintEvent(evnt);
        QPainter painter(this);
        double line;


        // painter.translate(150,190);
        // painter.scale(0.5,0.5);

        // painter.setClipRect(0,0, size.width(), size.height());

        // painter.setViewport(10000000000,0,size.width(),size.height());

        /*
        // rotating
            rotation = 45;
            painter.translate(256,256);
            painter.rotate(rotation);
            painter.translate(-256,-256);
        */

        layermanager->drawImage(&painter);
        layermanager->drawGeoms(&painter);

        // added by wolf
        // draw scale
        if (scaleVisible)
        {
            if (currentZoom() >= 0 && distanceList.size() > currentZoom())
            {
                line = distanceList.at( currentZoom() ) / pow(2.0, 18-currentZoom() ) / 0.597164;

                // draw the scale
                painter.setPen(mapPen);
                QPoint p1(10,size.height()-20);
                QPoint p2((int)line,size.height()-20);
                painter.drawLine(p1,p2);

                painter.drawLine(10,size.height()-15, 10,size.height()-25);
                painter.drawLine((int)line,size.height()-15, (int)line,size.height()-25);

                QString distance;
                if (distanceList.at(currentZoom()) >= 1000)
                {
                    distance = QVariant( distanceList.at(currentZoom())/1000 )  .toString()+ " km";
                }
                else
                {
                    distance = QVariant( distanceList.at(currentZoom()) ).toString() + " m";
                }

                painter.drawText(QPoint((int)line+10,size.height()-15), distance);
            }
        }

        painter.drawLine(screen_middle.x(), screen_middle.y()-10,
                         screen_middle.x(), screen_middle.y()+10); // |
        painter.drawLine(screen_middle.x()-10, screen_middle.y(),
                         screen_middle.x()+10, screen_middle.y()); // -

        // int cross_x = int(layermanager->getMapmiddle_px().x())%256;
        // int cross_y = int(layermanager->getMapmiddle_px().y())%256;
        // painter.drawLine(screen_middle.x()-cross_x+cross_x, screen_middle.y()-cross_y+0,
        //   screen_middle.x()-cross_x+cross_x, screen_middle.y()-cross_y+256); // |
        // painter.drawLine(screen_middle.x()-cross_x+0, screen_middle.y()-cross_y+cross_y,
        //   screen_middle.x()-cross_x+256, screen_middle.y()-cross_y+cross_y); // -

        painter.drawRect(0,0, size.width(), size.height());
        /*
        // rotating
          painter.setMatrix(painter.matrix().inverted());
        //qt = painter.transform();
           qm = painter.combinedMatrix();
        */
        if (mousepressed && mymousemode == Dragging)
        {
            QRect rect = QRect(pre_click_px, current_mouse_pos);
            painter.drawRect(rect);
        }


        // Draw the Lat and Lon if needed

        // FIXME Mariano
        if (cursorPosVisible && currentZoom() < 19)
        {
          line = distanceList.at( currentZoom() ) / pow(2.0, 18-currentZoom() ) / 0.597164;

          QString str;
          str = QString(tr(" Lat: %1")).arg(currentWorldCoordinate.y());
          painter.drawText(QPoint((int)line+70,size.height()-15), str);

          str = QString(tr(" Lon: %1")).arg(currentWorldCoordinate.x());
          painter.drawText(QPoint((int)line+160,size.height()-15), str);
        }

        emit viewChanged(currentCoordinate(), currentZoom());
    }
Пример #10
0
 void MapControl::setViewAndZoomIn(const QList<QPointF> coordinates) const
 {
     layermanager->setViewAndZoomIn(coordinates);
     emit viewChanged(currentCoordinate(), currentZoom());
 }
Пример #11
0
 void MapControl::setView(const QPointF& coordinate) const
 {
     layermanager->setView(coordinate);
     emit viewChanged(currentCoordinate(), currentZoom());
 }
Пример #12
0
 void MapControl::updateView() const
 {
     layermanager->setView( currentCoordinate() );
     emit viewChanged(currentCoordinate(), currentZoom());
 }
Пример #13
0
 void MapControl::setZoom(int zoomlevel)
 {
     layermanager->setZoom(zoomlevel);
     updateView();
     emit viewChanged(currentCoordinate(), currentZoom());
 }
Пример #14
0
 void MapControl::zoomOut()
 {
     layermanager->zoomOut();
     updateView();
     emit viewChanged(currentCoordinate(), currentZoom());
 }
Пример #15
0
    void MapControl::paintEvent(QPaintEvent* evnt)
    {
        Q_UNUSED(evnt);

        static QPixmap *doubleBuffer( new QPixmap(width(), height()) );

        //check for resize change
        if ( doubleBuffer->width() != width() || doubleBuffer->height() != height() )
        {
            delete doubleBuffer;
            doubleBuffer = new QPixmap(width(), height());
        }

        QPainter dbPainter;
        dbPainter.begin(doubleBuffer);

        layermanager->drawImage(&dbPainter);
        layermanager->drawGeoms(&dbPainter);

        // draw scale
        if (scaleVisible)
        {
            static QList<double> distanceList;
            if (distanceList.isEmpty())
            {
                distanceList<<5000000<<2000000<<1000000<<1000000<<1000000<<100000<<100000<<50000<<50000<<10000<<10000<<10000<<1000<<1000<<500<<200<<100<<50<<25;
            }

            if (currentZoom() >= layermanager->minZoom() && distanceList.size() > currentZoom())
            {
                double line;
                line = distanceList.at( currentZoom() ) / pow(2.0, 18-currentZoom() ) / 0.597164;

                // draw the scale
                dbPainter.setPen(Qt::black);
                QPoint p1(10,size.height()-20);
                QPoint p2((int)line,size.height()-20);
                dbPainter.drawLine(p1,p2);

                dbPainter.drawLine(10,size.height()-15, 10,size.height()-25);
                dbPainter.drawLine((int)line,size.height()-15, (int)line,size.height()-25);

                QString distance;
                if (distanceList.at(currentZoom()) >= 1000)
                {
                    distance = QVariant( distanceList.at(currentZoom())/1000 )  .toString()+ " km";
                }
                else
                {
                    distance = QVariant( distanceList.at(currentZoom()) ).toString() + " m";
                }

                dbPainter.drawText(QPoint((int)line+10,size.height()-15), distance);
            }
        }

        if (crosshairsVisible)
        {
            dbPainter.drawLine(screen_middle.x(), screen_middle.y()-10,
                             screen_middle.x(), screen_middle.y()+10); // |
            dbPainter.drawLine(screen_middle.x()-10, screen_middle.y(),
                             screen_middle.x()+10, screen_middle.y()); // -
        }

        dbPainter.drawRect(0,0, size.width(), size.height());

        if (mousepressed && mymousemode == Dragging)
        {
            QRect rect = QRect(pre_click_px, current_mouse_pos);
            dbPainter.drawRect(rect);
        }
        dbPainter.end();
        QPainter painter;
        painter.begin( this );
        painter.drawPixmap( rect(), *doubleBuffer, doubleBuffer->rect() );
        painter.end();
    }
Пример #16
0
    void QmlMapControl::paint(QPainter* painter)
    {
        // painter->translate(150,190);
        // painter->scale(0.5,0.5);

        // painter->setClipRect(0,0, size.width(), size.height());

        // painter->setViewport(10000000000,0,size.width(),size.height());

        /*
        // rotating
            rotation = 45;
            painter->translate(256,256);
            painter->rotate(rotation);
            painter->translate(-256,-256);
        */

        layermanager->drawImage(painter);
        layermanager->drawGeoms(painter);

        // added by wolf
        // draw scale
        if (scaleVisible)
        {
            QList<double> distanceList;
            distanceList<<5000000<<2000000<<1000000<<1000000<<1000000<<100000<<100000<<50000<<50000<<10000<<10000<<10000<<1000<<1000<<500<<200<<100<<50<<25;
            if (currentZoom() >= 0 && distanceList.size() > currentZoom())
            {
                double line;
                line = distanceList.at( currentZoom() ) / pow(2.0, 18-currentZoom() ) / 0.597164;

                // draw the scale
                painter->setPen(Qt::black);
                QPoint p1(10,size.height()-20);
                QPoint p2((int)line,size.height()-20);
                painter->drawLine(p1,p2);

                painter->drawLine(10,size.height()-15, 10,size.height()-25);
                painter->drawLine((int)line,size.height()-15, (int)line,size.height()-25);

                QString distance;
                if (distanceList.at(currentZoom()) >= 1000)
                {
                    distance = QVariant( distanceList.at(currentZoom())/1000 )  .toString()+ " km";
                }
                else
                {
                    distance = QVariant( distanceList.at(currentZoom()) ).toString() + " m";
                }

                painter->drawText(QPoint((int)line+10,size.height()-15), distance);
            }
        }

        if (crosshairsVisible)
        {
            painter->drawLine(screen_middle.x(), screen_middle.y()-10,
                             screen_middle.x(), screen_middle.y()+10); // |
            painter->drawLine(screen_middle.x()-10, screen_middle.y(),
                             screen_middle.x()+10, screen_middle.y()); // -
        }

        // int cross_x = int(layermanager->getMapmiddle_px().x())%256;
        // int cross_y = int(layermanager->getMapmiddle_px().y())%256;
        // painter->drawLine(screen_middle.x()-cross_x+cross_x, screen_middle.y()-cross_y+0,
        //   screen_middle.x()-cross_x+cross_x, screen_middle.y()-cross_y+256); // |
        // painter->drawLine(screen_middle.x()-cross_x+0, screen_middle.y()-cross_y+cross_y,
        //   screen_middle.x()-cross_x+256, screen_middle.y()-cross_y+cross_y); // -

        painter->drawRect(0,0, size.width(), size.height());
        /*
        // rotating
          painter->setMatrix(painter->matrix().inverted());
        //qt = painter->transform();
           qm = painter->combinedMatrix();
        */

        if (mousepressed && mymousemode == Dragging)
        {
            QRect rect = QRect(pre_click_px, current_mouse_pos);
            painter->drawRect(rect);
        }
        //emit viewChanged(currentCoordinate(), currentZoom());
    }