void DlgSettingsSegments::updatePreview()
{
  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsSegments::updatePreview"
                              << " loading=" << (m_loading ? "true" : "false");

  const QString ARBITRARY_IDENTIFIER ("");
  const QColor COLOR (Qt::blue);
  const int RADIUS = 5;

  if (!m_loading) {

    SegmentFactory segmentFactory (*m_scenePreview,
                                   mainWindow().isGnuplot());

    clearPoints();
    segmentFactory.clearSegments (m_segments);

    // Create new segments
    segmentFactory.makeSegments (createPreviewImage(),
                                 *m_modelSegmentsAfter,
                                 m_segments);

    // Make the segment visible
    QList<Segment*>::iterator itrS;
    for (itrS = m_segments.begin(); itrS != m_segments.end(); itrS++) {
      Segment *segment = *itrS;
      segment->slotHover (true);
    }

    // Create some points
    PointStyle pointStyle (POINT_SHAPE_CROSS,
                           RADIUS,
                           BRUSH_WIDTH,
                           COLOR_PALETTE_BLUE);
    QPolygonF polygon = pointStyle.polygon();
    QList<QPoint> points = segmentFactory.fillPoints (*m_modelSegmentsAfter,
                                                      m_segments);
    QList<QPoint>::iterator itrP;
    for (itrP = points.begin(); itrP != points.end(); itrP++) {
      QPoint pos = *itrP;
      GraphicsPoint *graphicsPoint = new GraphicsPoint (*m_scenePreview,
                                                        ARBITRARY_IDENTIFIER,
                                                        pos,
                                                        COLOR,
                                                        polygon,
                                                        BRUSH_WIDTH);
      m_points.push_back (graphicsPoint);
    }
  }
}
示例#2
0
QPixmap ViewPointStyle::pixmap (const PointStyle &pointStyle) const
{
  LOG4CPP_INFO_S ((*mainCat)) << "ViewPointStyle::pixmap";

  // Polygon that is sized for the main drawing window.
  QPolygonF polygonUnscaled = pointStyle.polygon();

  // Resize polygon to fit icon, by builiding a new scaled polygon from the unscaled polygon
  double xMinGot = polygonUnscaled.boundingRect().left();
  double xMaxGot = polygonUnscaled.boundingRect().right();
  double yMinGot = polygonUnscaled.boundingRect().top();
  double yMaxGot = polygonUnscaled.boundingRect().bottom();

  QPolygonF polygonScaled;
  for (int i = 0; i < polygonUnscaled.length(); i++) {
    QPointF pOld = polygonUnscaled.at(i);
    polygonScaled.append (QPointF ((width () - 1) * (pOld.x() - xMinGot) / (xMaxGot - xMinGot),
                                   (height () - 1) * (pOld.y() - yMinGot) / (yMaxGot - yMinGot)));
  }

  // Color
  QColor color = ColorPaletteToQColor(pointStyle.paletteColor());

  // Image for drawing
  QImage img (width (),
              height (),
              QImage::Format_RGB32);
  QPainter painter (&img);
  painter.fillRect (0,
                    0,
                    width (),
                    height (),
                    QBrush (COLOR_FOR_BRUSH));
  painter.setPen (QPen (color));
  painter.drawPolygon (polygonScaled);

  // Create pixmap from image
  QPixmap pixmap = QPixmap::fromImage (img);

  return pixmap;
}