void NonPdfCropping::createWidgets(QGraphicsScene &scene)
{
  const double MARGIN_PERCENT = 5.0;
  const int ZERO_WIDTH_IS_ALWAYS_VISIBLE = 0;

  int marginHor = scene.width()  * MARGIN_PERCENT / 100.0;
  int marginVer = scene.height() * MARGIN_PERCENT / 100.0;

  QRect box (scene.sceneRect().left() + marginHor,
             scene.sceneRect().top()  + marginVer,
             scene.sceneRect().width() - 2 * marginHor,
             scene.sceneRect().height() - 2 * marginVer);

  m_handleTL = new NonPdfFrameHandle (scene, m_view, box.topLeft()    , NON_PDF_CROPPING_LEFT   | NON_PDF_CROPPING_TOP    , *this, Z_HANDLE);
  m_handleTR = new NonPdfFrameHandle (scene, m_view, box.topRight()   , NON_PDF_CROPPING_RIGHT  | NON_PDF_CROPPING_TOP    , *this, Z_HANDLE);
  m_handleBR = new NonPdfFrameHandle (scene, m_view, box.bottomRight(), NON_PDF_CROPPING_RIGHT  | NON_PDF_CROPPING_BOTTOM , *this, Z_HANDLE);
  m_handleBL = new NonPdfFrameHandle (scene, m_view, box.bottomLeft() , NON_PDF_CROPPING_LEFT   | NON_PDF_CROPPING_BOTTOM , *this, Z_HANDLE);

  m_box = new QGraphicsRectItem;
  m_box->setZValue (Z_BOX);
  m_box->setPen (QPen (QBrush (Qt::gray), ZERO_WIDTH_IS_ALWAYS_VISIBLE));
  scene.addItem (m_box);

  updateBox ();
}
QGraphicsScene * ClusteredArranger::arrange(SegmentList const & segments) const {
   QGraphicsScene * arrangement = new QGraphicsScene();

   QTime time;
   time.start();

   // determine background
   Segment * background = determineBackground(segments);
   SegmentList segmentsWOBack = removeBackground(segments, background);
   arrangement->setBackgroundBrush(QBrush(QColor(background->color().toQRgb())));
   segmentsWOBack.calculateFeatureVariances();

   // initialize layout
   //initializeLayout(segmentsWOBack, segmentsWOBack.featX(), segmentsWOBack.featY());
   initializeLayout(segmentsWOBack, xAxisBox->currentIndex(), yAxisBox->currentIndex());

   // find clusters
   time.restart();
   QList<SegmentList> clusters = meanShift(segmentsWOBack);
   qDebug("Segments clustered in %f seconds", time.restart()/1000.0);
   qDebug("  %d clusters found", clusters.size());

   // refine clusters
   //int counter = 0;
   foreach (SegmentList cluster, clusters) {
      if (clusterBox->currentIndex() == 0) {
         refineLayoutCircles(cluster);
      }
      else if (clusterBox->currentIndex() == 1) {
         refineLayoutPiles(cluster);
      }

      // debug output
      /*QGraphicsScene scene;
      scene.setBackgroundBrush(QBrush(QColor(255, 255, 255)));
      foreach(Segment * const segment, cluster) {
         scene.addItem(segment->toQGraphicsItem());
         // without the following line QPainter tends to crash
         scene.width();
      }
      ++counter;
      saveScene(&scene, QString("Test%1.png").arg(counter, 2));*/
   }

   // refine layout
   if (clusterBox->currentIndex() == 0) {
      refineLayoutByPlace(clusters);
   }
   else if (clusterBox->currentIndex() == 1) {
      refineLayoutBySize(clusters);
   }

   // convert the segments to QGraphicsItems and add to QGraphicsScene
   foreach(Segment const * const segment, segmentsWOBack) {
      arrangement->addItem(segment->toQGraphicsItem());
      // without the following line QPainter tends to crash
      arrangement->width();
   }
Exemple #3
0
QRectF SegmentList::rect() const {
   QGraphicsScene scene;
   foreach(Segment const * const segment, *this) {
      scene.addItem(segment->toQGraphicsItem());
      // without the following line QPainter tends to crash
      scene.width();
   }
   return scene.sceneRect();
}
Exemple #4
0
/*!
* Computes the bounding rect of the grid.
*/
QRectF GridItem::boundingRect() const
{
    QGraphicsScene *grscene = scene();
    if (grscene) {
        qreal w = grscene->width();
        qreal h = grscene->height();

        return QRectF((-w - m_penWidth)/2, (-h - m_penWidth)/2, w + m_penWidth, h + m_penWidth);
    }

    return QRectF();
}
void MainWindow::on_actionExport_to_PNG_triggered()
{
    QString fileFilters = tr("Png files (*.png)");

    QString fileName = QFileDialog::getSaveFileName(this,tr("Export to PNG"),
        qApp->applicationDirPath() + QDir::separator()
                + "traces" + QDir::separator(), fileFilters);
    if (fileName.isEmpty()) return;

    if (!fileName.contains(".png")) fileName += ".png";

    /*if (model->size() <= BigGraph){
        if (gvLayout(model->getGVC(), model->getGraph(), currentLayout.toUtf8().data()) == 0)
        {
              gvRenderFilename(model->getGVC(), model->getGraph(),
                         "png", fileName.toUtf8().data() );

              gvFreeLayout(model->getGVC(), model->getGraph());
              return;
         }
    }*/

    QGraphicsScene *scene = qGraph->getScene();
    int width = scene->width(),
        height = scene->height();

    QImage image(width, height, QImage::Format_RGB16);
    if ( !image.isNull()){
        exportToPNG(&image, scene, fileName );
        return;
    }

    QImage imageMono(width, height, QImage::Format_Mono);
    if (!imageMono.isNull()){
        exportToPNG(&imageMono, scene, fileName);
        return;
    }

    QMessageBox::warning(this, tr("Error"), tr("Can't export file to PNG"));
}
VisibleAreaMode::VisibleAreaMode(QGraphicsScene& scene, Toolbar& toolbar)
    : AbstractMode(scene),
      toolbar_(toolbar),
      initialized_(false),
      rectTop(new QGraphicsRectItem),
      rectBottom(new QGraphicsRectItem),
      rectLeft(new QGraphicsRectItem),
      rectRight(new QGraphicsRectItem),
      lineTop(new QGraphicsLineItem),
      lineBottom(new QGraphicsLineItem),
      lineLeft(new QGraphicsLineItem),
      lineRight(new QGraphicsLineItem) {

    QPen pen(Qt::NoPen);
    QBrush brush(Qt::black);

    rectTop->setOpacity(.65);
    rectBottom->setOpacity(.65);
    rectLeft->setOpacity(.65);
    rectRight->setOpacity(.65);

    rectTop->setPen(pen);
    rectBottom->setPen(pen);
    rectLeft->setPen(pen);
    rectRight->setPen(pen);

    rectTop->setBrush(brush);
    rectBottom->setBrush(brush);
    rectLeft->setBrush(brush);
    rectRight->setBrush(brush);

    rectTop->setZValue(1);
    rectBottom->setZValue(1);
    rectLeft->setZValue(1);
    rectRight->setZValue(1);

    // First rectangle fullscreen
    rectTop->setRect(0, 0, scene.width(), scene.height());

    scene.addItem(rectTop);
    scene.addItem(rectBottom);
    scene.addItem(rectLeft);
    scene.addItem(rectRight);

    QPen linePen;
    linePen.setWidthF(.2);
    linePen.setColor(QColor(230, 230, 230));

    lineTop->setPen(linePen);
    lineBottom->setPen(linePen);
    lineLeft->setPen(linePen);
    lineRight->setPen(linePen);

    lineTop->setZValue(1);
    lineBottom->setZValue(1);
    lineLeft->setZValue(1);
    lineRight->setZValue(1);

    scene.addItem(lineTop);
    scene.addItem(lineBottom);
    scene.addItem(lineLeft);
    scene.addItem(lineRight);
}
const QImage loadThumb(const QString& fileName)
{
    QFile file(fileName);
    if(!file.open(QFile::ReadOnly | QFile::Text))
    {
        //Error opening file
        return QImage();
    }

    //Read
    EmbPattern* p = embPattern_create();
    if(!p) { return QImage(); }
    int readSuccessful = 0;
    QString readError;
    EmbReaderWriter* reader = embReaderWriter_getByFileName(qPrintable(fileName));
    if(!reader)
    {
        readSuccessful = 0;
    }
    else
    {
        readSuccessful = reader->reader(p, qPrintable(fileName));
    }
    free(reader);

    if(readSuccessful)
    {
        QGraphicsScene gscene;
        QPainterPath path;

        if(p->stitchList)
        {
            int previousColor = p->stitchList->stitch.color;

            EmbStitchList* curStitchItem = p->stitchList;
            while(curStitchItem)
            {
                EmbStitch tempStitch = curStitchItem->stitch;
                curStitchItem = curStitchItem->next;
                if((tempStitch.flags & STOP) || (tempStitch.flags & END))
                {
                    if(!path.isEmpty())
                    {
                        EmbColor thisColor = embThread_getAt(p->threadList, previousColor).color;
                        QPen loadPen(qRgb(thisColor.r, thisColor.g, thisColor.b));
                        loadPen.setWidthF(0.35);
                        loadPen.setCapStyle(Qt::RoundCap);
                        loadPen.setJoinStyle(Qt::RoundJoin);
                        gscene.addPath(path, loadPen);
                        previousColor = tempStitch.color;
                        path = QPainterPath();
                    }
                    path.moveTo(tempStitch.xx, -tempStitch.yy);
                }
                else if((tempStitch.flags & JUMP) || (tempStitch.flags & TRIM))
                {
                    path.moveTo(tempStitch.xx, -tempStitch.yy);
                }
                else
                {
                    path.lineTo(tempStitch.xx, -tempStitch.yy);
                }
            }
        }

        QImage sceneImg(gscene.width(), gscene.height(), QImage::Format_ARGB32);
        sceneImg.fill(QColor(0,0,0,0));

        QPainter painter(&sceneImg);
        gscene.render(&painter);
        return sceneImg;
    }
    embPattern_free(p);

    return QImage();
}