コード例 #1
0
void GeoMapWidget::paintEvent( QPaintEvent* )
{
  uint w = width();
  uint h = height();

  QPixmap pm( w, h );
  QPainter p;
  p.begin( &pm );
  p.initFrom( this );

  p.setPen( QColor( 255, 0, 0 ) );
  p.setBrush( QColor( 255, 0, 0 ) );

  QPixmap world( KStandardDirs::locate( "data", "kaddressbook/pics/world.jpg" ) );
  p.drawPixmap( 0, 0, world );

  double latMid = h / 2;
  double longMid = w / 2;

  double latOffset = ( mLatitude * latMid ) / 90;
  double longOffset = ( mLongitude * longMid ) / 180;

  int x = (int)(longMid + longOffset);
  int y = (int)(latMid - latOffset);
  p.drawEllipse( x, y, 4, 4 );

  p.end();
  QPainter thisPainter(this);
  thisPainter.drawPixmap( 0, 0, pm );
}
コード例 #2
0
   void ParallelCoordinates::paintEvent( QPaintEvent* evtPaint )
   {
      // ------------------------------------------------------------------------
      // ------------------------------------------------------------------------
      QPainter thisPainter(this);

      int w = thisPainter.viewport().width();
      int h = thisPainter.viewport().height();
      if( (abs(m_nHeight-h) > 0 || abs(m_nWidth-w) > 0) && m_data.size() > 0 )
      {
         m_nHeight = h;
         m_nWidth  = w;

         delete m_chart;
         m_chart = new QPixmap(w, h);

         QPainter painter(m_chart);

         // Draw the background.
         QPoint background[4] = { QPoint(0,0), QPoint(0,h), QPoint(w,h), QPoint(w,0) };
         QBrush brush(QColor(20,128,230));
         QBrush oldBrush = painter.brush();
         painter.setBrush(brush);
         painter.drawPolygon( background, 4 );
         painter.setBrush(oldBrush);
         painter.setPen(Qt::green);

         Data::FlightDatabase::iterator i;
         int nFlights = m_data.size();
         int nFlightNum = -1;
         int nLineLength  = h/(nFlights);
         for( i = m_data.begin() ; i != m_data.end(); ++i )
         {
            painter.setPen(Qt::green);
            ++nFlightNum;

            int nAttr = i.value()._metadata.size();
            if( nAttr > 1 )
            {
#              ifdef NDEBUG
               // This makes the drawing VERY slow!!!
               //painter.setRenderHint(QPainter::Antialiasing);
#              endif

               this->setStyleSheet("QWidget { background-color: blue; }");

               QPoint *points = new QPoint[nAttr];

               // Calculate the chart parameters.
               int nLineSpacing = w/(nAttr-1);
               int xoffset = 0;
               int yoffset = nLineLength*(nFlightNum+1);
               int xIncrements = 0;
               int yIncrements = 0;
               bool success = false;
               for( int g =  0; g < i.value()._params.size(); g+=10 )
               {
                  int pt = 0;
                  int x = xoffset;
                  int y = 0;

                  for( int j = 0; j < i.value()._params[g]._dataVector.size(); ++j )
                  {
                     const qreal& data = i.value()._params[g]._dataVector[j].toDouble(&success);

                     y = data * nLineLength;
                     points[pt].setX(x);
                     points[pt].setY(yoffset-y);
                     pt++;
                     x += nLineSpacing;
                  }

                  painter.drawPolyline(points, nAttr);
               }

               // Draw the actual parallel coordinates last so they are visible on top.
               painter.setPen(Qt::black);
               for( int m = 0; m < nAttr; ++m )
               {
                  int x = xoffset+(nLineSpacing*m);
                  painter.drawLine( x, yoffset, x, yoffset-nLineLength);
               }
               painter.drawLine
                  ( xoffset, yoffset
                  , xoffset+(nLineSpacing*nAttr), yoffset);
               painter.drawLine
                  ( xoffset, yoffset+nLineLength
                  , xoffset+(nLineSpacing*nAttr), yoffset+nLineLength);

               delete points;
            }
         }
      }

      if( m_chart )
      {
         // Draw the pixmap to the widget.
         thisPainter.drawPixmap(m_chart->rect(), *m_chart);
      }
      //      else
      //      {
      //         // QStaticText isn't available until 4.7
      //#        if QT_VERSION >= 0x040700
      //            // Draw some reminder text for now on how to get the chart to work.
      //            QStaticText message;
      //
      //            message.setText(
      //               "Parallel coordinates requires loading data and selecting at least two attributes.\n"
      //               "Make sure data is loaded, select two attributes and then re-launch the chart.");
      //
      //            painter.drawStaticText( 0, 0, message );
      //#        endif
      //      }
   }