This forum has been archived. All content is frozen. Please use KDE Discuss instead.

GeoPainter draw rotated Pixmaps display black rectangles

Tags: None
(comma "," separated)
michaelsc
Registered Member
Posts
2
Karma
0
Hello everyone,

new to Marble and even Qt I try to extend GeoPainter to draw pixmaps rotated around and placed at an anchor point.

The function works flawless with a pure QtWidget, but added to GeoPainter just 2 or 3 pixmaps are drawn for the rest I get black rectangles. To test I arranged 10 objects in a circle, I can pan the map around to move objects out of the viewport but never get more than 3 painted correctly.

Here is the code:
Code: Select all
void GeoPainter::drawPixmap ( const GeoDataCoordinates & centerPosition,
                              const QPixmap & pixmap,
                              QPointF anchorRelative,
                              qreal angle,
                              qreal scalePixel,
                              qreal scaleMeter/*=0.0*/ )
{
    int pointRepeatNum;
    qreal x, y;
    bool globeHidesPoint;

    bool visible = d->m_viewport->screenCoordinates( centerPosition, x, y, globeHidesPoint );

    if ( visible ) {
       QPoint screenPos(x, y);

       if( 0.0 < scaleMeter ) {
          qreal scaleFromMeter(0);
          //TODO, calculate meter to pixel
          if( scalePixel < scaleFromMeter ) scalePixel = scaleFromMeter;
       }
       qreal ratio = scalePixel / pixmap.height();
       QPointF scaledSize(pixmap.width() * ratio, scalePixel);
       QPointF pntCenter(scaledSize / 2);
       QPointF pntAnchor(anchorRelative.rx() * scaledSize.x(), anchorRelative.ry() * scaledSize.y());

       qreal dist = QLineF(pntAnchor, pntCenter).length();
       qreal a = qAtan2(pntAnchor.y() - pntCenter.y(), pntAnchor.x() - pntCenter.x());

       QPointF rotAnchor(qCos(angle + a) * dist, qSin(angle + a) * dist);
       rotAnchor += pntCenter;

        QPixmap rotImage = pixmap.transformed(QTransform()
                                  .scale(ratio, ratio)
                                  .translate(-screenPos.x(), -screenPos.y())
                                  .rotateRadians(angle)
                                  .translate(screenPos.x(), screenPos.y())
                                 );

       QPointF rotCenter = QPointF(rotImage.width() / 2, rotImage.height() / 2);
       QPointF offset(rotCenter - pntCenter);

       QPointF origin(screenPos - (rotAnchor + offset));
        QPainter::drawPixmap(origin, rotImage);
    }
}


When I comment out .rotateRadians(angle) all objects get painted.

Anyone knows what the problem is and how to fix it?

Best regards
Michael
michaelsc
Registered Member
Posts
2
Karma
0
Found the issue, coding above is correct. The problem was some time ago I derived MarbleWidget from QOpenGLWidget. Everything seemed to work. Now after I switched back to QWidget all rotated pixmaps get drawn. I need to check the OpenGL initialization.

Thanks for your time!

Regards
Michael


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]