Exemple #1
0
// ###### Print image #######################################################
void FractalGeneratorView::print(QPrinter* printer)
{
   int width  = Display->imageWidth();
   int height = Display->imageHeight();
   char title[512];
   snprintf((char*)&title, sizeof(title), "%s  -  c1=%f - %fi; c2=%f - %fi; %d iterations",
            Algorithm->getName(),
            C1.real(), C1.imag(), C2.real(), C2.imag(), *Algorithm->getMaxIterations());

   QFont font("Times", 9);
   font.setBold(true);
   QFontMetrics fontMetrics(font);
   QRect        boundingRect = fontMetrics.boundingRect(title);
   const int textwidth  = boundingRect.width();
   const int textheight = boundingRect.height();

   printer->setDocName(title);
   printer->setCreator("Thomas Dreibholz's Fractal Generator II");

   int pagesx = 1;
   int pagesy = 1;

   QPainter p;
   p.begin(printer);
   const int xstep = width  / pagesx;
   const int ystep = height / pagesy;
   for(int y = 0;y < pagesy;y++) {
     for(int x = 0;x < pagesx;x++) {
        p.setWindow(0, 0, xstep, ystep);
        p.drawImage(0, 0, *(Display->image()), x * xstep, y * ystep, xstep, ystep);

        if((x == pagesx - 1) && (y == pagesy - 1)) {
           p.setWindow(0, 0, (int)(1.1 * textwidth), textheight * 50);
           p.setPen(Qt::black);
           p.setFont(font);
           p.drawText(0, textheight * 48, (int)(1.1 * textwidth), textheight, Qt::AlignHCenter|Qt::AlignVCenter, title);
        }
        else {
           printer->newPage();
        }

        /*
        p.setWindow(0, 0, width, height);
        p.setPen(Qt::red);
        p.drawLine(0, 0, Display->imageWidth() - 1, Display->imageHeight() - 1);
        p.drawLine(0, Display->imageHeight() - 1, Display->imageWidth() - 1, 0);
        p.setPen(Qt::black);
        char str[16];
        snprintf((char*)&str,sizeof(str),"x=%d y=%d\n",x,y);
        p.drawText(0, 0, str);
        p.drawRect(0, 0, Display->imageWidth() - 1, Display->imageHeight() - 1);
        */
     }
   }
   p.end();
}
Exemple #2
0
//***************************************************************************
void Kwave::ScaleWidget::paintEvent(QPaintEvent *)
{
    bool inverse = false;
    int h = height();
    int w = width();
    QPainter p;

    p.begin(this);
    p.save();
    p.setPen(palette().light().color());

    p.drawLine(0, 0, w, 0);
    if (h > w) {
	p.setWindow(-w, 0, w, h);
	p.rotate(-90);
	h = width();
	w = height();

	inverse = true;
    }

    (m_logmode) ? drawLog(p, w, h, inverse) : drawLinear(p, w, h, inverse);

    p.restore();
    p.end();
}
Exemple #3
0
void MapWidget::exportSVGToDisplayCluster()
{
    if(g_dcSocket != NULL && svgTmpFile_.open())
    {
        QSvgGenerator generator;
        generator.setFileName(svgTmpFile_.fileName());
        generator.setResolution(90);
        generator.setSize(QSize(1400, 1200));
        generator.setViewBox(viewRect_);

        QPainter painter;
        painter.begin(&generator);

        // set logical coordinates of the render window
        painter.setWindow(viewRect_.toRect());

        // draw a black background
        painter.setBrush(QBrush(QColor::fromRgbF(0,0,0,1)));
        painter.drawRect(QRect(QPoint(-107,37), QPoint(-93,25)));

        renderAll(&painter, false);

        painter.end();

        put_flog(LOG_DEBUG, "wrote %s", svgTmpFile_.fileName().toStdString().c_str());

        // now, send it to DisplayCluster
        sendSVGToDisplayCluster((svgTmpFile_.fileName()).toStdString(), (QString("ExerciseMap-") + QString::number(index_) + ".svg").toStdString());
    }
}
//-------------------------------------------------------------------------
void QGuidoItemContainer::exportToPdf( QPrinter * printer )
{
	int originalPage = mGuidoItem->firstVisiblePage();
			
	mGuidoItem->setPage(1);
	QRectF firstPageRect = guidoItem()->boundingRect();
	printer->setPaperSize( QSizeF( firstPageRect.width() , firstPageRect.height() ) , QPrinter::Millimeter );

	QPainter painter;
	painter.begin( printer );
	
	painter.setWindow( firstPageRect.toRect() );
	
	int pCount = mGuidoItem->pageCount();
	for ( int page = 1 ; page <= pCount ; page++ )
	{
		QRectF rect = guidoItem()->boundingRect();
		
		QStyleOptionGraphicsItem option;
		option.exposedRect = rect;
		mGuidoItem->paint( &painter , &option , 0 );

		if (page != pCount)
		{
			mGuidoItem->setPage(page+1);
			rect = guidoItem()->boundingRect();
			
			printer->newPage();
		}
	}
	painter.end();

	mGuidoItem->setPage( originalPage );
}
Exemple #5
0
void ClusterView::eraseTheLastMovingLine(QColor polygonColor){
  //The user moved since the last left click, a line has been drawn in the mouseMoveEvent
  if(nbSelectionPoints != selectionPolygon.size()){
    //set existLastMovingLine to true to correctely erase the closed polygon
    existLastMovingLine = true;
    
    //Paint in the buffer to allow the selection to be redrawn after a refresh
    QPainter painter;
    painter.begin(&doublebuffer);
    //set the window (part of the word I want to show)
    QRect r((QRect)window);
    painter.setWindow(r.left(),r.top(),r.width()-1,r.height()-1);//hack because Qt QRect is used differently in this function
    painter.setRasterOp(XorROP);
    painter.setPen(polygonColor);
  
    //Treat the case when we reach the first point of the selection
    if(nbSelectionPoints == 1){
      //Erase the last line drawn (in mouseMoveEvent).
      painter.drawPolyline(selectionPolygon,selectionPolygon.size()-2);
    }
    else{
      //CAUTION, Do not remove this line otherwise strang dots will appear
      painter.drawPoint(selectionPolygon.point(selectionPolygon.size()-2));
      //Erase the last line drawn (in mouseMoveEvent)
      painter.drawPolyline(selectionPolygon,selectionPolygon.size()-2);
    }
    //Resize selectionPolygon to remove the last point
    //(the one set in mouseMoveEvent) from selectionPolygon
    selectionPolygon.resize(selectionPolygon.size()-1);

    nbSelectionPoints = selectionPolygon.size();  

    painter.end();
  }
}
void ColorWheel::paintWheel()
{
	int h, s, v;
	QColor col(ScColorEngine::getDisplayColor(actualColor, currentDoc ));
	col.getHsv(&h, &s, &v);
	int width = this->width();
	int height = this->height();
	QPainter p;
	p.begin(this);
	p.setWindow( 0, 0, width, height);
	p.fillRect(0, 0, width, height, Qt::white);
	p.setPen(Qt::black);
	p.drawRect(0, 0, width, height);
	// Half sizes
	heightH = height / 2;
	widthH = width / 2;
	for (int i = 0; i < 360; ++i)
	{
		QMatrix matrix;
		matrix.translate(widthH, heightH);
		matrix.rotate((float)i);
		p.setWorldMatrix(matrix);
		QColor c;
		c.setHsv(i, 255, 255);
		p.setPen(QPen(c, 7));
		p.setBrush(c);
		p.drawLine(0, 0, 130, 0);
	}
}
Exemple #7
0
void altitudewidget::paintEvent(QPaintEvent*){
    QPainter *painter = new QPainter(this);
    painter->setWindow(-50, -100, 100, 200);
    
    QPen backgroundpen(Qt::black, 1, Qt::SolidLine);
    painter->setPen(backgroundpen);
    QBrush backgroundbrush(Qt::black);
    painter->setBrush(backgroundbrush);
    painter->drawRect(-50, -100, 100, 200);

    QPen pointerpen(Qt::white, 1, Qt::SolidLine);
    painter->setPen(pointerpen);
    QBrush pointerbrush(Qt::white);
    painter->setBrush(pointerbrush);
    QPoint arrow[3] = {QPoint(-35, 0), QPoint(-45, 5), QPoint(-45, -5)};
    painter->drawPolygon(arrow, 3);
    
    painter->translate(0, -20*altitude);
    
    QString value;
    for(int i = 0; i<=100; i++) {
        painter->drawLine(-20, 0, -10, 0);
        painter->drawText(0, -10, 25, 20, Qt::AlignRight, value.setNum(i));
        //painter->drawText(0, 0, value.setNum(i));
        painter->translate(0, 20);
    }
}
Exemple #8
0
QPixmap ClsBaseQStateArrayView::getGradientPixmap(int iImgWidth, int iImgHeight, int _iColorMode ) {
#ifdef DEBUG_CLSBASEQSTATEARRAYVIEW
    cout << "ClsBaseQStateArrayView::getGradientPixmap(int iImgWidth, int iImgHeight)" << endl;
#endif

//    int iColorMode = ClsBaseQStateArrayView::GRAY;
//    int iColorMode = ClsBaseQStateArrayView::BLUE2RED;
//    int iColorMode = ClsBaseQStateArrayView::HSV;

    QPixmap pmGradient;
    QPainter* paintGradient = new QPainter();
    QWMatrix mxRot;
    int iDiag = (int)(sqrt(double(iImgWidth * iImgWidth + iImgHeight * iImgHeight))/2.);

    pmGradient.resize(2 * iDiag, 2 * iDiag);
    paintGradient->begin(&pmGradient);

    paintGradient->setWindow( 0, 0, 2 * iDiag, 2 * iDiag );

    int iNrSices = 50;
    for ( int i=0; i<iNrSices; i++ ) {
	paintGradient->setWorldMatrix( mxRot );
	QColor c;
	if(_iColorMode == ClsBaseQStateArrayView::GRAY){
	    c.setRgb( i* 255 / iNrSices,  i* 255 / iNrSices,  i* 255 / iNrSices );
	}
	else if(_iColorMode == ClsBaseQStateArrayView::BLUE2RED){
	    if(i<iNrSices/2){
		/* BLUE */
		c.setRgb(0, 0,  255 - i * 510/iNrSices);
	    }
	    else {
		/* RED */
		c.setRgb( (i - iNrSices/2) * 255/(iNrSices/2),  0,0);
	    }
	}
	else {
	    c.setHsv( i* 360 / iNrSices, 255, 255 );
	}
	paintGradient->setBrush( c );
	paintGradient->setPen( c );
//zzz	QPointArray a;
	QPolygon a;

	a.setPoints( 4,
		     0, 0,
		     iDiag * 2 / iNrSices, 0,
		     iDiag * 2 / iNrSices, iDiag * 2,
		     0, iDiag * 2 );
	paintGradient->drawPolygon( a );
	mxRot.translate( (double)iDiag * 2.0 / (double)iNrSices, 0.0  );
    }

    paintGradient->end();
    return pmGradient;

}
void CMeter2DGraphView::InitializeRasterRenderer( QPainter& aPainter, QImage& anImage )
{
   anImage.fill( 0x00000000 );
   
   aPainter.begin( &anImage );
   aPainter.setViewport( 0, 0, anImage.width(), anImage.height() );
   aPainter.setWindow( 0, anImage.height(), anImage.width(), -anImage.height() );
   aPainter.setRenderHint( QPainter::HighQualityAntialiasing );
}
Exemple #10
0
//-------------------------------------------------------------------------
void MainWindow::exportRect(const QRectF& exportRectangle , const QString& fileName , const QString& fileType )
{
	QList<QLanguageItem*> selectedItems = selectedLanguageItems();
	unselectAll();

	QPainter painter;
	if ( fileType == PNG_FILE_FILTER )
	{
		int result = QResolutionDialog( exportRectangle , EXPORT_MIN_DETAIL , EXPORT_MAX_DETAIL , EXPORT_DEFAULT_DETAIL , EXPORT_DETAIL_TO_SCALE_FACTOR ).exec();
		if ( result )
		{
			//Create a new QImage, with a size corresponding to the Guido Score page
			QSizeF size( exportRectangle.width() , exportRectangle.height() );
			size.setWidth( result * EXPORT_DETAIL_TO_SCALE_FACTOR * size.width() );
			size.setHeight( result * EXPORT_DETAIL_TO_SCALE_FACTOR * size.height() );
			QImage image( size.width() , size.height() , QImage::Format_ARGB32);
			image.fill( QColor(Qt::white).rgb() );
			
			painter.begin( &image );

			//Paint in the QImage
			paintSceneRect( exportRectangle , &painter );

			painter.end();

			image.save( fileName , "PNG" );
		}
	}
	else if ( ( fileType == PDF_FILE_FILTER ) || ( fileType == PS_FILE_FILTER ) )
	{
		QPrinter printer;
		printer.setFullPage(true);
		printer.setOutputFileName( fileName );
		if ( fileType == PS_FILE_FILTER )
		{
			printer.setOutputFormat( QPrinter::PostScriptFormat );
		}
		else if ( fileType == PDF_FILE_FILTER )
		{
			printer.setOutputFormat( QPrinter::PdfFormat );
		}

		printer.setPaperSize( QSizeF( exportRectangle.width() , exportRectangle.height() ) , QPrinter::Millimeter );
		painter.setWindow( exportRectangle.toRect() );
		
		painter.begin( &printer );

		paintSceneRect( exportRectangle , &painter );
		
		painter.end();
	}

	for ( int i = 0 ; i < selectedItems.size() ; i++ )
		selectedItems[i]->setSelected(true);
}
Exemple #11
0
void SpecWidget::PutSpec(vector<_REAL> vecrData)
{
	int w = image.width();
	if (w == 0)
		return;
	Canvas.fill(QColor::fromRgb(0, 0, 128));
	QPainter painter;
	if(!painter.begin(&Canvas)) // David had problems on Linux without this
		return;
	QPen p;
	p.setColor(Qt::white);
	painter.setPen(p);

	if (vecrData.size() >= 300)
	{
//		qDebug() << __FILE__ << __LINE__ << vecrData.size();
		int i;
		for (i = 0;i < 250;i++)
			specbufarr[i] = (3.0 * specbufarr[i] + vecrData[2*i] + vecrData[2*i+1]) * 0.2;
		for (i = 0;i < 250;i++)
		{

//			painter.drawLine(i,specbufarr[i],this->width(),this->height());
			specarr[i] = specbufarr[i] / 50.0;
//			specarr[i] = (int)(specbufarr[i] * 40.0);
			// specarr[i] = -(specbufarr[i] * 40.0 * specagc);
		}
	}
	//	painter.drawPolyline();
	float psize = 250.0;
//	float vs = 2.0;
	float ssize = psize / 1.8;
//	painter.setWindow( 0, -100, ssize, 500 );
	painter.setWindow( -5, -150, ssize, 250);
	painter.setPen( Qt::yellow  );
	int i = 1;
	while (i < ssize)
	{
//		painter.drawLine(i - 1, specarr[i-1] * vs, i, specarr[i] * vs);
		painter.drawLine(i - 1, -specarr[i-1], i, -specarr[i]);
//		qDebug() << __FILE__ << __LINE__  << specarr[i];
		i++;
	}


//	painter.drawLine(0,0,this->width(),this->height());
//	qDebug() << __FILE__ << __LINE__ << this->width() << this->height();
	painter.end();
	update();

	//	Gdisp->setb(SPEC, specarr, 250);
}
Exemple #12
0
void Draw(){
    QPixmap *pixmap = new QPixmap(pixelx,pixely);
    QPainter *painter = new QPainter(pixmap);
    painter->begin(pixmap);
    painter->setViewport(0,0,pixelx,pixely);
    painter->setWindow(0,0,n+1,n+1);
    painter->setPen(Qt::NoPen);
    painter->setBrush(QBrush(Qt::white,Qt::SolidPattern));
    painter->drawRect(0,0,pixelx,pixely);
    painter->setBrush(Qt::NoBrush);
    painter->setPen(Qt::blue);
    painter->setWindow(0,0,pixelx,pixely);
    painter->setFont(QFont("Times", 10));
    for (int i=1;i<=n*n;i++){
        char ts[5];
        sprintf(ts,"%d",i);
        QString num(ts);
        QRect rect;
        double x,y,l;
        x = (location[i][0]*1.0)*pixelx/(n+1);
        y = (location[i][1]*1.0)*pixely/(n+1);
        l = pixelx*0.5/(n+1);
        rect.setRect(x-l,y-l,l*2,l*2);
        painter->drawText(rect,Qt::AlignCenter,num);
    }
    painter->setWindow(0,0,n+1,n+1);
    painter->setPen(Qt::lightGray);
    for (int i=0;i<=n;i++) painter->drawLine(QPointF(0.5,i+0.5),QPointF(n+0.5,i+0.5));
    for (int i=0;i<=n;i++) painter->drawLine(QPointF(i+0.5,0.5),QPointF(i+0.5,n+0.5));
    painter->setPen(Qt::black);
    for (int i=1;i<n*n;i++){
        painter->drawLine(location[i][0],location[i][1],location[i+1][0],location[i+1][1]);
    }
    painter->end();
    char temp[20];
    sprintf(temp,"../picture/%d.jpg",count);
    pixmap->save(temp,0,100);
}
Exemple #13
0
void ClusterView::print(QPainter& printPainter,QPaintDeviceMetrics& metrics,bool whiteBackground){
 //Draw the double buffer (pixmap) by copying it into the printer device throught the painter.
  QRect viewportOld = QRect(viewport.left(),viewport.top(),viewport.width(),viewport.height());

  viewport = QRect(printPainter.viewport().left(),printPainter.viewport().top(),printPainter.viewport().width(),printPainter.viewport().height());

  QRect r = ((QRect)window);

  //Set the window (part of the world I want to show)
  printPainter.setWindow(r.left(),r.top(),r.width()-1,r.height()-1);//hack because Qt QRect is used differently in this function

  //Fill the background with the background color
  QRect back = QRect(r.left(),r.top(),r.width(),r.height());

  QColor colorLegendTmp = colorLegend;
  QColor background= backgroundColor();
  if(whiteBackground){
   colorLegend = black;
   setPaletteBackgroundColor(white);
  }
  
  printPainter.fillRect(back,backgroundColor());
  printPainter.setClipRect(back,QPainter::CoordPainter);

  //Draw the axes
  drawAxes(printPainter);

  //Paint all the clusters in the shownClusters list (in the double buffer)
  drawClusters(printPainter,view.clusters(),true);

  //reset transformation due to setWindow and setViewport
  printPainter.resetXForm();

  //Draw the time axis information if the time is displayed
  drawTimeInformation(printPainter);

  printPainter.setClipping(false);

  //Restore the colors.
  if(whiteBackground){
   colorLegend = colorLegendTmp;
   setPaletteBackgroundColor(background);
  }
  
  //Restore the previous state
  viewport = QRect(viewportOld.left(),viewportOld.top(),viewportOld.width(),viewportOld.height());
}
void ModelIndexLayer::render(QPainter& painter)
{
    if (mItemModel == NULL)
    {
        qDebug() << "Model == NULL";
        // Nothing to do. return.
        return;
    }

    foreach(QModelIndex index, mCulled)
    {
        QGeoCoordinate coord = mItemModel->data(index, ModelIndexLayer::GeoCoordinateRole).value<QGeoCoordinate>();

        if (!coord.isValid())
            continue;

        // prepare the viewport for the delegate
        QRect vp = markerPosition(coord);

        painter.save();
        painter.setClipRect(vp);
        painter.setWindow(QRect(0, 0, vp.width(), vp.height()));
        painter.setViewport(vp);

        MarkerInfo markerInfo;
        markerInfo.coord      = coord;
        markerInfo.modelIndex = index;
        markerInfo.x          = vp.left();
        markerInfo.y          = vp.top();
        markerInfo.width      = vp.width();
        markerInfo.height     = vp.height();

        if (mSelectionModel != NULL)
            markerInfo.markerState = mSelectionModel->selection().contains(index)
                ? MarkerInfo::MarkerStateSelected : MarkerInfo::MarkerStateNone;

        QVariant v = mItemModel->data(index, ModelIndexLayer::DataRole);
        mDelegate->paint(painter, markerInfo, v);
        painter.restore();
    }     // else skip, this coord is not in view
Exemple #15
0
void ClusterView::resetSelectionPolygon(){

  if(selectionPolygon.size()>0){  
   //Erase the existing polygon
  
   //Select the appropriate color
   QColor color = selectPolygonColor(mode);

      //if the polygon was closed, erase the closing line
   if(polygonClosed){
     QPainter painter;
     painter.begin(&doublebuffer);
     //set the window (part of the word I want to show)
     QRect r((QRect)window);
     painter.setWindow(r.left(),r.top(),r.width()-1,r.height()-1);//hack because Qt QRect is used differently in this function

     painter.setRasterOp(XorROP);
     painter.setPen(color);
    
     //Erase the closing line
     painter.drawLine(selectionPolygon.point(0),selectionPolygon.point(selectionPolygon.size()-1));

     if(existLastMovingLine)painter.drawPoint(selectionPolygon.point(selectionPolygon.size()-1));
     //reset existLastMovingLine
     existLastMovingLine = false;
     
     painter.end();
     
     polygonClosed = false;
   }
   
   while(selectionPolygon.size()>0) eraseTheLastDrawnLine(color);

   //Reset the variables associates with the polygon

   //Resize selectionPolygon to remove all the last selected area, reinitialize nbSelectionPoints accordingly
   selectionPolygon.resize(0);
   nbSelectionPoints = 0;
  }
}
Exemple #16
0
void enginewidget::paintEvent(QPaintEvent*){
    QPainter *painter = new QPainter(this);
    painter->setWindow(-100, -100, 200, 200);
    
    QPen backgroundpen(Qt::black, 1, Qt::SolidLine);
    painter->setPen(backgroundpen);
    QBrush backgroundbrush(Qt::black);
    painter->setBrush(backgroundbrush);
    painter->drawRect(-100, -100, 200, 200);
    
    QPen scalepen(Qt::green, 3, Qt::SolidLine);
    painter->setPen(scalepen);
    painter->drawArc(-75, -75, 150, 150, 45*16, 180*16);
    
    QPen pointerpen(Qt::white, 1, Qt::SolidLine);
    painter->setPen(pointerpen);
    QBrush pointerbrush(Qt::white);
    painter->setBrush(pointerbrush);
    painter->rotate(135);
    painter->rotate(throttle*1.8);
    QPoint arrow[3] = {QPoint(75, 0), QPoint(65, 5), QPoint(65, -5)};
    painter->drawPolygon(arrow, 3);
}
bool MReportViewer::printPosReport()
{
  if (report == 0)
    return false;

  posprinter = new FLPosPrinter();
  posprinter->setPaperWidth((FLPosPrinter::PaperWidth) report->pageSize());
  posprinter->setPrinterName(printerName_);

  QPicture *page;
  QPainter painter;
  bool printRev = false;

  int viewIdx = report->getCurrentIndex();

  int printCopies = numCopies_;

  painter.begin(posprinter);
  QPaintDeviceMetrics pdm(posprinter);
  QSize dim(report->pageDimensions());
  painter.setWindow(0, 0, dim.width(), dim.height());
  painter.setViewport(0, 0, pdm.width(), pdm.height());

  for (int j = 0; j < printCopies; j++) {
    report->setCurrentPage(1);
    page = report->getCurrentPage();
    page->play(&painter);
  }

  painter.end();
  report->setCurrentPage(viewIdx);

  delete posprinter;

  return true;
}
Exemple #18
0
void OGWidget::paintEvent(QPaintEvent *ev)
{
    Q_UNUSED(ev)

    QPainter painter;

    painter.begin(this);

    painter.setRenderHint(QPainter::SmoothPixmapTransform);

    getGame()->Paint(&painter);

    painter.setWindow(0, 0, width(), height());

    if (!uiList().isEmpty())
    {
        for (int i = 0; i < uiList().size(); i++)
        {
            if (uiList().at(i)->isVisible()) uiList().at(i)->Paint(&painter);
        }
    }

    painter.end();
}
Exemple #19
0
void ClusterView::drawContents(QPainter* p){
  if(drawContentsMode == UPDATE || drawContentsMode == REDRAW){
    viewport = contentsRect();
 
    //Resize the double buffer with the width and the height of the widget(QFrame)
    doublebuffer.resize(viewport.width(),viewport.height());
    
    //Create a painter to paint on the double buffer
    QPainter painter;
    painter.begin(&doublebuffer);
      
    //set the window (part of the word I want to show)
    QRect r((QRect)window);
    
    painter.setWindow(r.left(),r.top(),r.width()-1,r.height()-1);//hack because Qt QRect is used differently in this function
    
    if(drawContentsMode == REDRAW){
      //Reset the variables associates with the polygon

      //Resize selectionPolygon to remove all the last selected area, reinitialize nbSelectionPoints accordingly
      selectionPolygon.resize(0);
      nbSelectionPoints = 0;
  
      //Fill the double buffer with the background
      doublebuffer.fill(backgroundColor());

      //Draw the axes
      drawAxes(painter);

      //Paint all the clusters in the shownClusters list (in the double buffer)
      drawClusters(painter,view.clusters());      
    }
    if(drawContentsMode == UPDATE){
           
      //Erase any polygon of selection and reset the associated variables
      resetSelectionPolygon();
      
      //Paint the the clusters to update contain in clusterUpdateList
      if(clusterUpdateList.size()>0)drawClusters(painter,clusterUpdateList);

      //Clear the update list
      clusterUpdateList.clear();
    }

    //reset transformation due to setWindow
    painter.resetXForm() ;

    
    //Draw the time axis information if the time is displayed
    drawTimeInformation(painter);
       
    //Closes the painter on the double buffer
    painter.end();

    //Back to the default
    drawContentsMode = REFRESH; 
  }
  //if drawContentsMode == REFRESH, we reuse the double buffer (pixmap)

  //Draw the double buffer (pixmap) by copying it into the paint device.
  p->drawPixmap(0, 0, doublebuffer);
}
Exemple #20
0
void RCDraw::paintEvent ( QPaintEvent * )
{
	QString s;
	QPainter painter ( this );
	painter.setRenderHint(QPainter::HighQualityAntialiasing);

	if ( qimg != NULL )
	{
		painter.drawImage ( QRectF(0., 0., imageScale*width, imageScale*height), *qimg, QRectF(0, 0, width, height) );
	}

	painter.setWindow (effWin.toRect() );

	if ( DRAW_PERIMETER )
	{
		painter.setPen ( Qt::blue );
		painter.drawRect ( 0,0,width-1,height-1 );
	}
	if ( DRAW_AXIS )
	{
		drawAxis(Qt::blue, 2);
	}

	//Draw lines
	while ( !lineQueue.isEmpty() )
	{
		TLine l = lineQueue.dequeue();
		if (invertedVerticalAxis) l.line = QLineF(l.line.x1()-visibleCenter(0), -l.line.y1()+visibleCenter(1), l.line.x2()-visibleCenter(0), -l.line.y2()+visibleCenter(1));
		else l.line.translate(-visibleCenter(0), -visibleCenter(1));
		painter.setPen ( QPen ( QBrush ( l.color ),l.width ) );
		painter.drawLine ( l.line );
	}

	//Draw gradient
	while ( !gradQueue.isEmpty() )
	{
		TGrad g = gradQueue.dequeue();
		if (invertedVerticalAxis) g.line = QLine(g.line.x1()-visibleCenter(0), -g.line.y1()+visibleCenter(1), g.line.x2()-visibleCenter(0), -g.line.y2()+visibleCenter(1));
		else g.line.translate(-visibleCenter(0), -visibleCenter(1));
		linGrad.setColorAt ( 0, g.color );
		linGrad.setColorAt ( 1, g.color1 );
		painter.setBrush ( linGrad );
		painter.setPen ( QPen ( linGrad, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
		painter.drawLine ( g.line );
	}

	//Draw ellipses
	while ( !ellipseQueue.isEmpty() )
	{
		TEllipse e = ellipseQueue.dequeue();
		if (invertedVerticalAxis) e.center.setY(-(e.center.y()-visibleCenter(1)));
		else e.center = QPointF(e.center.x()-visibleCenter(0), e.center.y()-visibleCenter(1));
		if ( e.fill == true )
			painter.setBrush ( e.color );
		else
			painter.setBrush ( Qt::transparent );
		painter.setPen ( e.color );
		if (fabs(e.ang) > 0.1)
		{
			painter.setPen ( e.color );
			painter.translate( e.center );
			painter.rotate( e.ang );
			painter.drawEllipse ( QPointF(0,0), e.rx, e.ry );
			painter.rotate( -e.ang );
			painter.translate( -e.center );
		}
		else
			painter.drawEllipse( e.center, e.rx, e.ry);
	}

	//Draw squares
	{
		QPen pen = painter.pen();
		int penwidth = pen.width();
		while ( !squareQueue.isEmpty() )
		{
			TRect r = squareQueue.dequeue();
			if (invertedVerticalAxis) r.rect = QRect(r.rect.x()-visibleCenter(0), -r.rect.y()+visibleCenter(1)-r.rect.height(), r.rect.width(), r.rect.height());
			else r.rect.translate(-visibleCenter(0),-visibleCenter(1));
			if ( r.fill == true )
				painter.setBrush ( r.color );
			else
				painter.setBrush ( Qt::transparent );
			pen.setColor(r.color);
			pen.setWidth(r.width);
			painter.setPen(pen);
			if (fabs(r.ang) > 0.01 )
			{
				QPointF center = r.rect.center();
				painter.translate( center );
				painter.rotate( r.ang );
				painter.drawRect ( QRectF( r.rect.topLeft() - center, r.rect.size() ));
				painter.rotate( -r.ang );
				painter.translate( -center );
			}
			else
				painter.drawRect( r.rect );
		}
		pen.setWidth(penwidth);
		painter.setPen(pen);
	}


	while ( !lineOnTopQueue.isEmpty() )
	{
		TLine l = lineOnTopQueue.dequeue();
		l.line.translate(-visibleCenter(0), -visibleCenter(1));
		painter.setPen ( QPen ( QBrush ( l.color ),l.width ) );
		painter.drawLine ( l.line );
	}


	//Draw text
	while ( !textQueue.isEmpty() )
	{
		TText t = textQueue.dequeue();
		painter.setWindow ( effWin.normalized().toRect() );
		QFont ant = painter.font();
		QFont temp ( "Helvetica", t.size );
		painter.setFont ( temp );

		QRectF rect = painter.boundingRect(QRectF(t.pos.x(), t.pos.y(), 1, 1), Qt::AlignLeft, t.text);
		if (not t.centered)
		{
			painter.setPen(t.bgc);
			painter.setBrush(t.bgc);
			painter.drawRect(rect);
			painter.setBrush ( Qt::transparent );
			painter.setPen ( t.color );
			painter.drawText( QRectF(t.pos.x(), t.pos.y(), 0.82*t.text.size()*t.size, 1.2*t.size), Qt::AlignCenter, t.text);
		}
		else
		{
			rect.translate(-rect.width()/2., -rect.height()/2.);
			painter.setPen(t.bgc);
			painter.setBrush(t.bgc);
			painter.drawRect(rect);
			painter.setBrush ( Qt::transparent );
			painter.setPen ( t.color );
			painter.drawText(rect, Qt::AlignLeft, t.text);
		}

		painter.setFont ( ant );
		painter.setWindow ( effWin.toRect() );
	}


}
/** Imprime directamente sobre formato PS */
bool MReportViewer::printReportToPS(const QString &outPsFile)
{
  // Check for a report
  if (report == 0)
    return false;

#if defined(Q_OS_WIN32) || defined(Q_OS_MACX)
  return printGhostReportToPS(outPsFile);
#endif

  // Get the page count
  int cnt = report->pageCount();

  // Check if there is a report or any pages to print
  if (cnt == 0) {
    QMessageBox::critical(this, "Kugar", tr("No hay páginas en el\ninforme para."), QMessageBox::Ok,
                          QMessageBox::NoButton, QMessageBox::NoButton);
    return false;
  }

  // Set the printer dialog
  printer = new QPrinter(QPrinter::HighResolution);
  printer->setPageSize((QPrinter::PageSize) report->pageSize());
  if ((QPrinter::PageSize) report->pageSize() == QPrinter::Custom)
    printer->setCustomPaperSize(report->pageDimensions());
  printer->setOrientation((QPrinter::Orientation) report->pageOrientation());
  printer->setMinMax(1, cnt);
  printer->setFromTo(1, cnt);
  printer->setFullPage(true);
  printer->setColorMode((QPrinter::ColorMode) colorMode_);
  printer->setNumCopies(numCopies_);
  printer->setOutputToFile(true);
  printer->setOutputFileName(outPsFile);

  QPicture *page;
  QPainter painter;
  bool printRev = false;

  // Save the viewer's page index
  int viewIdx = report->getCurrentIndex();

  // Check the order we are printing the pages
  if (printer->pageOrder() == QPrinter::LastPageFirst)
    printRev = true;

  // Get the count of pages and copies to print
  int printFrom = printer->fromPage() - 1;
  int printTo = printer->toPage();
  int printCnt = (printTo - printFrom);
  int printCopies = printer->numCopies();
  int totalSteps = printCnt * printCopies;
  int currentStep = 1;

  // Set copies to 1, QPrinter copies does not appear to work ...
  printer->setNumCopies(numCopies_);
  printer->setResolution(dpi_);

  // Setup the progress dialog
  QProgressDialog progress(tr("Imprimiendo Informe..."), tr("Cancelar"), totalSteps, this, tr("progreso"), true);
  progress.setMinimumDuration(M_PROGRESS_DELAY);
  QObject::connect(&progress, SIGNAL(cancelled()), this, SLOT(slotCancelPrinting()));
  progress.setProgress(0);
  qApp->processEvents();

  // Start the printer
  painter.begin(printer);
  QPaintDeviceMetrics pdm(printer);
  QSize dim(report->pageDimensions());
  painter.setWindow(0, 0, dim.width(), dim.height());
  painter.setViewport(0, 0, pdm.width(), pdm.height());

  // Print each page in the collection
  for (int j = 0; j < printCopies; j++) {
    for (int i = printFrom; i < printTo; i++, currentStep++) {
      if (!printer->aborted()) {
        progress.setProgress(currentStep);
        qApp->processEvents();
        if (printRev)
          report->setCurrentPage((printCnt == 1) ? i : (printCnt - 1) - i);
        else
          report->setCurrentPage(i);

        page = report->getCurrentPage();
        page->play(&painter);
        if ((i - printFrom) < printCnt - 1)
          printer->newPage();
      } else {
        j = printCopies;
        break;
      }
    }
    if (j < printCopies - 1)
      printer->newPage();
  }

  // Cleanup printing
  painter.end();
  report->setCurrentPage(viewIdx);
  delete printer;
  return true;
}
Exemple #22
0
void MainWindow::btnExportClicked()
{
    QList<QChar> charset;

    if (chkLowerAZ->isChecked())
        for (char c = 'a'; c <= 'z'; c++)
            charset.append(c);

    if (chkUpperAZ->isChecked())
        for (char c = 'A'; c <= 'Z'; c++)
            charset.append(c);

    if (chkNumbers->isChecked())
        for (char c = '0'; c <= '9'; c++)
            charset.append(c);

    QString str = ldtCharacters->text();
    for (QString::const_iterator itr(str.begin()); itr != str.end(); itr++)
        if (!charset.contains(*itr))
            charset.append(*itr);

    qSort(charset);

    // Render characters
    QFont font = fontSelector->currentFont();
    font.setPixelSize(font.pointSize());

    QFontMetrics metrics = QFontMetrics(font);
    QTextCodec *codec = QTextCodec::codecForName("utf-8");

    QString glyphs;

    QString fontName = QString("font_%1%2")
            .arg(font.family().toLower())
            .arg(font.pixelSize())
            .replace(' ', '_');

    QString fontstruct = QString(
            "const struct glib_font %1 = {\n"
            "    .charcount = %2,\n"
            "    .size = %3,\n"
            "    .glyphs    = {\n        ")
            .arg(fontName)
            .arg(charset.size())
            .arg(font.pixelSize());

    QListIterator<QChar> itr(charset);
    while (itr.hasNext()) {
        QChar c = itr.next();

        if (c == ' ') {
            // Add space character
            fontstruct += QString("{.utf8 = 0x20, .x = %1, .y = 0, .bitmap = NULL}")
                    .arg(metrics.width(' '));

        } else {
            QRect boundingRect = metrics.boundingRect(c);

            QImage image = QImage(boundingRect.width(), boundingRect.height(),
                    QImage::Format_Mono);

            image.fill(Qt::color1);

            QPainter p;
            p.begin(&image);
            p.setFont(font);
            p.setWindow(metrics.boundingRect(c));
            p.drawText(0, 0, c);
            p.end();

            QString utf8 = codec->fromUnicode(c).toHex();

            glyphs += renderGlyph(utf8, image);
            fontstruct += QString("{.utf8 = 0x%1, .x = %2, .y = %3, .bitmap = &glyph_%1}")
                    .arg(utf8)
                    .arg(boundingRect.x() + 1)
                    .arg(boundingRect.y() - metrics.descent() + 1); // +1 for the base line
        }

        if (itr.hasNext())
            fontstruct += ",\n        ";
    }

    fontstruct += "\n    }\n};\n";

    glyphs = "#include <liblcd/glib.h>\n\n" + glyphs + "\n" + fontstruct;


    QString filename = QFileDialog::getSaveFileName(this,
            tr("Save Font"), fontName + ".c", tr("Source Files (*.c *.cpp)"));

    if (!filename.isEmpty()) {
        if (!(filename.endsWith(".c") || filename.endsWith(".cpp")))
            filename += ".c";

        QFile file(filename);
        if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
            return;

        QTextStream out(&file);
        out << glyphs;
        file.close();
    }
}
void SXBSchView::print(QPrinter*  pPrinter)
{
    m_pDoc->resetSelect();
    updateViewBuffer(true);
    QPainter paint;
    if(paint.begin(pPrinter ) ) {
        int dpi;
#ifdef Q_WS_MACX
        int dpix,dpiy;;
        dpix = pPrinter->logicalDpiX();
        dpiy = pPrinter->logicalDpiY();
        dpi=((dpix < dpiy) ? dpix : dpiy);
#else
        dpi = pPrinter->resolution();
#endif

        paint.setRenderHint(QPainter::Antialiasing, true);


        //    	QRect rcPaper = pPrinter->paperRect();
        //    printf("paperRect %d,%d,%d,%d\n",rcPaper.left(),rcPaper.top(),rcPaper.width(),rcPaper.height());
        QRect rcVp = paint.viewport();
        QRect rcPg = pPrinter->pageRect();
        //    printf("pageRect %d,%d,%d,%d\n",rcPg.left(),rcPg.top(),rcPg.width(),rcPg.height());
        //    	int orientation = pPrinter->orientation();
        //    printf("orientation %d\n",orientation);

        int vpWidth, vpHeight;
        int pgLeft, pgTop, pgWidth, pgHeight;

        vpWidth    =rcVp.width();
        vpHeight = rcVp.height();

        pgLeft    =rcPg.left();
        pgTop    =rcPg.top();
        pgWidth    =rcPg.width();
        pgHeight = rcPg.height();


        //印刷時に印刷の向きを変えてもpageRect()の返す値が変わらないQtのバグ(?)の対策
        if(    	(vpWidth > vpHeight && pgWidth < pgHeight)
                ||    (vpWidth < vpHeight && pgWidth > pgHeight)    ) {
            int swapn;
            swapn = pgLeft;
            pgLeft = pgTop;
            pgTop = swapn;

            swapn = pgWidth;
            pgWidth = pgHeight;
            pgHeight = swapn;
        }

        QSettings *settings = g_cfg.getSettings();

        int leftMargin = 15;
        int topMargin = 15;
        int rightMargin = 15;
        int bottomMargin = 15;

        settings->beginGroup("PrintOption");
        bool color = settings->value("Color",true).toBool();
        settings->endGroup();


        settings->beginGroup("PrintMargin");
        topMargin = settings->value("Top",15).toInt();
        bottomMargin = settings->value("Bottom",15).toInt();
        leftMargin = settings->value("Left",15).toInt();
        rightMargin = settings->value("Right",15).toInt();
        settings->endGroup();

        if      (topMargin    < 0)   topMargin = 0;
        else if (topMargin    > 50)  topMargin = 50;
        if      (bottomMargin < 0)   bottomMargin = 0;
        else if (bottomMargin > 50)  bottomMargin = 50;
        if      (leftMargin   < 0)   leftMargin = 0;
        else if (leftMargin   > 50)  leftMargin = 50;
        if      (rightMargin  < 0)   rightMargin = 0;
        else if (rightMargin  > 50)  rightMargin = 50;

        topMargin = dpi * 10 * topMargin / 254;
        bottomMargin = dpi * 10 * bottomMargin / 254;
        leftMargin = dpi * 10 * leftMargin / 254;
        rightMargin = dpi * 10 * rightMargin / 254;




        //    printf("SXBSchView::print() dpi:%d\n",dpi);

        paint.save();

        paint.setViewTransformEnabled (true);
        paint.resetMatrix();

        SSize size = m_pDoc->SheetSize();
        int w = size.w();
        int h = size.h();

        int dw = w*10;
        int dh = h*10;
        //    p->setWindow( 0,0, dw, dh );
        //    QRect rc = paint.viewport();

        int rightWidth = vpWidth-(pgLeft+pgWidth);
        if(rightWidth < 0) rightWidth = 0;
        int bottomWidth = vpHeight-(pgTop+pgHeight);
        if(bottomWidth < 0) bottomWidth = 0;

        leftMargin -= pgLeft;
        if(leftMargin < 0)leftMargin = 0;

        topMargin -= pgTop;
        if(topMargin < 0) topMargin = 0;

        rightMargin -= rightWidth;
        if(rightMargin < 0) rightMargin = 0;

        bottomMargin -= bottomWidth;
        if(bottomMargin < 0) bottomMargin = 0;

        int vw = pgWidth-(leftMargin+rightMargin);
        int vh = pgHeight-(topMargin+bottomMargin);


        double sheetRatio=(double)w / (double)h;
        double viewRatio=(double)vw / (double)vh;

        int newW;
        int newH;

        if(sheetRatio > viewRatio) {
            newW = vw;
            newH = (int)(vw / sheetRatio);
        } else {
            newH = vh;
            newW = (int)(vh *  sheetRatio);
        }
        //    printf("newW,H=%d,%d\n",newW,newH);
        //     p->setViewport(     rc.left() + (vw-newW)/2,
        //    	    	    rc.top() + (vh-newH)/2,
        //    	    	    newW, newH );
        //    QRect rcvp = p->viewport();
        //    printf("x,y,w,h  %d,%d,%d,%d\n",rcvp.x(),rcvp.y(),rcvp.width(),rcvp.height());

        paint.setViewport( leftMargin+ (vw-newW)/2,
                           topMargin + (vh-newH)/2,
                           newW, newH );
        paint.setWindow( 0,0, dw, dh );


        //    rcvp = p->viewport();
        //    printf("x,y,w,h  %d,%d,%d,%d\n",rcvp.x(),rcvp.y(),rcvp.width(),rcvp.height());


        QRect rcClip = QRect(0,0,dw,dh);
        SRect srcClip =SRect(0,0,w,h);

        paint.setBackground(Qt::white);
        paint.eraseRect(0,0,dw,dh);
        g_drawFrame(&paint,size,rcClip,Qt::black,1,10);
        drawMainXBSchObj(&paint,(color ? DRAW_ON : DRAW_MONO)|DRAW_FOR_PRINT,&srcClip,false,1,10);
        paint.restore();

        paint.end();
    }
}
Exemple #24
0
void ClusterView::mousePressEvent(QMouseEvent* e){ 
  //Defining a time window t oupdate the Traceview
  if(mode == SELECT_TIME){
   QPoint current = viewportToWorld(e->x(),e->y());
   if(dimensionX == timeDimension){
     dataType time = static_cast<dataType>(current.x() * samplingInterval / static_cast<double>(1000));
     emit moveToTime(time);
   }
   else if(dimensionY == timeDimension){
    dataType time = -static_cast<dataType>(current.y() * samplingInterval / static_cast<double>(1000));
    emit moveToTime(time);
   }
  }
   
  //The parent implementation takes care of the mode ZOOM
  //(rubber band and calculation of the firstClick)
  ViewWidget::mousePressEvent(e);

  //If there is a polygon to draw (one of the selection modes) 
  if(mode == DELETE_NOISE || mode == DELETE_ARTEFACT || mode == NEW_CLUSTER || mode == NEW_CLUSTERS){  
    //Select the appropriate color
    QColor color = selectPolygonColor(mode);

    //Erase the last line drawn
    if(e->button() == QMouseEvent::RightButton){
      if(selectionPolygon.size() == 0) return;

      //Erase the last drawn line by drawing into the buffer
      eraseTheLastDrawnLine(color);

      //Draw the new doublebuffer onto the widget
      QPainter p(this);
      p.drawPixmap(0, 0, doublebuffer);
    }

    //Close the polygon of selection and trigger the right action depending on the mode
    if(e->button() == QMouseEvent::MidButton && selectionPolygon.size()>0){      
      QRegion selectionArea;

      //Paint into the buffer to allow the selection to be redrawn after a refresh
      QPainter painter;
      painter.begin(&doublebuffer);
      //set the window (part of the word I want to show)
      QRect r((QRect)window);
      painter.setWindow(r.left(),r.top(),r.width()-1,r.height()-1);//hack because Qt QRect is used differently in this function
      painter.setPen(color);

      //If, once the last moving line erase, the polygon exists and has at least 3 points, draw it
      if(selectionPolygon.size()>2){
        //erase the last line drawn if the user moved since the last click
        eraseTheLastMovingLine(color);

        //Draw the closing line of the polygon
        painter.setRasterOp(XorROP);
        painter.drawLine(selectionPolygon.point(0),selectionPolygon.point(selectionPolygon.size()-1));

        polygonClosed = true;

        //Send an event to inform that the data have to be recompute accordingly to the selection polygon.
        //This asynchronous event will allow the widget to close the polygon
        //before asking the document to compute the data.
        ComputeEvent* event = getComputeEvent(selectionPolygon.copy());
        QApplication::postEvent(this,event);
       
      }
      //reset the polygon
      else resetSelectionPolygon();
       
      painter.end();
            
      //Draw the new doublebuffer onto the widget (show the closed polygon)
      QPainter p(this);
      p.drawPixmap(0, 0, doublebuffer);

      statusBar->clear();
    }
   
    if (e->button() == QMouseEvent::LeftButton){       
      QPoint selectedPoint = viewportToWorld(e->x(),e->y());
            
      if(nbSelectionPoints == 0) selectionPolygon.putPoints(0, 1, selectedPoint.x(),selectedPoint.y());
      //If the array is not empty, the last point has been put into the array in mouseMoveEvent
      nbSelectionPoints = selectionPolygon.size();
    }
  }      
}
void CorrelationView::print(QPainter& printPainter,QPaintDeviceMetrics& metrics,bool whiteBackground){
  printState = true;
  
 //Draw the double buffer (pixmap) by copying it into the printer device throught the painter.
  QRect viewportOld = QRect(viewport.left(),viewport.top(),viewport.width(),viewport.height());

 //If the left margin is not visible (the user zoomed without taking it in his selection), the viewport and the printer
  //have the same size.
  QRect r((QRect)window);
  if(r.left() != 0) viewport = QRect(printPainter.viewport().left(),printPainter.viewport().top(),printPainter.viewport().width(),printPainter.viewport().height()-10);
  else viewport = QRect(printPainter.viewport().left() + XMARGIN,printPainter.viewport().top(),printPainter.viewport().width() - XMARGIN,printPainter.viewport().height()-10);
  
  //Set the window (part of the world I want to show)
  printPainter.setWindow(r.left(),r.top(),r.width()-1,r.height()-1);//hack because Qt QRect is used differently in this function
  
  //Set the viewport (part of the device I want to write on).
  //By default, the viewport is the same as the device's rectangle (contentsRec), taking a smaller
  //one will ensure that the legends (cluster ids) will not ovelap a correlogram.
  printPainter.setViewport(viewport);

  //Fill the background with the background color and ensure we draw the same portion of the world than on the screen
  QRect back = QRect(r.left(),r.top(),r.width(),r.height());
  float heightRatio = (static_cast<float>(back.height())/static_cast<float>(metrics.height()));
  back.setBottom(r.top() + r.height() - 1 + static_cast<long>(10 * heightRatio));
  float widthRatio = (static_cast<float>(back.width())/static_cast<float>(metrics.width()));
  if(r.left() == 0) back.setLeft(r.left() - static_cast<long>(XMARGIN * widthRatio));

  printRegion = QRegion(back);

  QColor colorLegendTmp = colorLegend;
  QColor background= backgroundColor();
  if(whiteBackground){
   colorLegend = black;
   setPaletteBackgroundColor(white);
  }
  
  printPainter.fillRect(back,backgroundColor());
  printPainter.setClipRegion(printRegion,QPainter::CoordPainter);

  //Paint all the correlograms in the pairs list (in the double buffer)
  drawCorrelograms(printPainter,pairs);

  //reset transformation due to setWindow and setViewport
  printPainter.resetXForm();

  //Draw the cluster Ids along the correlograms.
  drawClusterIds(printPainter);

  printPainter.setClipping(false);

  //Restore the colors.
  if(whiteBackground){
   colorLegend = colorLegendTmp;
   setPaletteBackgroundColor(background);
  }
  
  //Restore the previous state
  viewport = QRect(viewportOld.left(),viewportOld.top(),viewportOld.width(),viewportOld.height());

  printState = false;
}
/** Prints the rendered report to the selected printer - displays Qt print dialog */
bool MReportViewer::printReport()
{
  // Check for a report
  if (report == 0)
    return false;

  report->setPrintToPos(printToPos_);

  if (report->printToPos())
    return printPosReport();

#if defined(Q_OS_WIN32)
  bool gsOk = false;
  QProcess *procTemp = new QProcess();
  procTemp->addArgument(aqApp->gsExecutable());
  procTemp->addArgument("--version");
  gsOk = procTemp->start();
  delete procTemp;
  if (gsOk) {
    if (printGhostReport())
      return true;
  }

  QMessageBox *m = new QMessageBox(tr("Sugerencia"),
                                   tr("Si instala Ghostscript (http://www.ghostscript.com) y añade\n"
                                      "el directorio de instalación a la ruta de búsqueda de programas\n"
                                      "del sistema (PATH), Eneboo podrá utilizarlo para optimizar\n"
                                      "sustancialmente la calidad de impresión y para poder generar códigos\nde barras.\n\n"),
                                   QMessageBox::Information, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton, this, 0, false);
  m->show();
#endif

  // Get the page count
  int cnt = report->pageCount();

  // Check if there is a report or any pages to print
  if (cnt == 0) {
    QMessageBox::critical(this, "Kugar", tr("No hay páginas en el\ninforme para."), QMessageBox::Ok,
                          QMessageBox::NoButton, QMessageBox::NoButton);
    return false;
  }

  // Set the printer dialog
  printer = new QPrinter(QPrinter::HighResolution);
  printer->setPageSize((QPrinter::PageSize) report->pageSize());
  if ((QPrinter::PageSize) report->pageSize() == QPrinter::Custom)
    printer->setCustomPaperSize(report->pageDimensions());
  printer->setOrientation((QPrinter::Orientation) report->pageOrientation());
  printer->setMinMax(1, cnt);
  printer->setFromTo(1, cnt);
  printer->setFullPage(true);
  printer->setColorMode((QPrinter::ColorMode) colorMode_);
  printer->setNumCopies(numCopies_);
  printer->setResolution(dpi_);
  if (!printerName_.isEmpty())
    printer->setPrinterName(printerName_);
  QString printProg(aqApp->printProgram());
  if (!printProg.isEmpty())
    printer->setPrintProgram(aqApp->printProgram());

  bool printNow = true;
  if (!printerName_.isNull())
    printNow = true;
  else
    printNow = printer->setup(qApp->focusWidget());

  if (printNow) {
    QPicture *page;
    QPainter painter;
    bool printRev = false;

    // Save the viewer's page index
    int viewIdx = report->getCurrentIndex();

    // Check the order we are printing the pages
    if (printer->pageOrder() == QPrinter::LastPageFirst)
      printRev = true;

    // Get the count of pages and copies to print
    int printFrom = printer->fromPage() - 1;
    int printTo = printer->toPage();
    int printCnt = (printTo - printFrom);
    int printCopies = printer->numCopies();
    int totalSteps = printCnt * printCopies;
    int currentStep = 1;

    // Set copies to 1, QPrinter copies does not appear to work ...
    printer->setNumCopies(1);

    // Setup the progress dialog
    QProgressDialog progress(tr("Imprimiendo Informe..."), tr("Cancelar"), totalSteps, this, tr("progreso"), true);
    progress.setMinimumDuration(M_PROGRESS_DELAY);
    QObject::connect(&progress, SIGNAL(cancelled()), this, SLOT(slotCancelPrinting()));
    progress.setProgress(0);
    qApp->processEvents();

    // Start the printer
    painter.begin(printer);
    QPaintDeviceMetrics pdm(printer);
    QSize dim(report->pageDimensions());
    painter.setWindow(0, 0, dim.width(), dim.height());
    painter.setViewport(0, 0, pdm.width(), pdm.height());

    // Print each copy
    for (int j = 0; j < printCopies; j++) {
      // Print each page in the collection
      for (int i = printFrom; i < printTo; i++, currentStep++) {
        if (!printer->aborted()) {
          progress.setProgress(currentStep);
          qApp->processEvents();
          if (printRev)
            report->setCurrentPage((printCnt == 1) ? i : (printCnt - 1) - i);
          else
            report->setCurrentPage(i);

          page = report->getCurrentPage();
          page->play(&painter);
          if ((i - printFrom) < printCnt - 1)
            printer->newPage();
        } else {
          j = printCopies;
          break;
        }
      }
      if (j < printCopies - 1)
        printer->newPage();
    }

    // Cleanup printing
    painter.end();
    report->setCurrentPage(viewIdx);
    delete printer;
    return true;
  }
  delete printer;
  return false;
}
Exemple #27
0
void ClusterView::mouseMoveEvent(QMouseEvent* e){
  //Write the current coordinates in the statusbar.
  QPoint current = viewportToWorld(e->x(),e->y());

  if(dimensionX == timeDimension){
   int timeInS = static_cast<int>(current.x() * samplingInterval / static_cast<double>(1000000));
   statusBar->changeItem("Coordinates: (" + QString("%1").arg(timeInS) + ", " + QString("%1").arg(-current.y()) + ")",1);   
  }
  else if(dimensionY == timeDimension){
   int timeInS = static_cast<int>(current.y() * samplingInterval / static_cast<double>(1000000));
   statusBar->changeItem("Coordinates: (" + QString("%1").arg(current.x()) + ", " + QString("%1").arg(-timeInS) + ")",1);     
  }
  else  statusBar->changeItem("Coordinates: (" + QString("%1").arg(current.x()) + ", " + QString("%1").arg(-current.y()) + ")",1);


                          
  //The parent implementation takes care of the rubber band
  ViewWidget::mouseMoveEvent(e);

  //If the user is closing the polygon do not take mousemove event into account
  if(!polygonClosed){
    //In one of the selection modes we draw the tracking line
    if(mode == DELETE_NOISE || mode == DELETE_ARTEFACT || mode == NEW_CLUSTER || mode == NEW_CLUSTERS){
      
     //Select the appropriate color
     QColor color = selectPolygonColor(mode);

     //If there is no selection point, do not draw a tracking line
     if(selectionPolygon.size() == 0) return;

     //Paint in the buffer to allow the selection to be redrawn after a refresh
     QPainter painter;
     painter.begin(&doublebuffer);
     //set the window (part of the word I want to show)
     QRect r((QRect)window);
     painter.setWindow(r.left(),r.top(),r.width()-1,r.height()-1);//hack because Qt QRect is used differently in this function
     painter.setRasterOp(XorROP);
     painter.setPen(color);

     //First mouseMoveEvent after the last mousePressEvent
     if(nbSelectionPoints == selectionPolygon.size()){
       //Add the current point to the array
       selectionPolygon.putPoints(selectionPolygon.size(), 1, current.x(),current.y());
       painter.drawPolyline(selectionPolygon,selectionPolygon.size()-2);
     }
     else{
       //Erase the previous drawn line
       painter.drawPolyline(selectionPolygon,selectionPolygon.size()-2);
       //Replace the last point by the current one
       selectionPolygon.setPoint(selectionPolygon.size()-1,current);
       //Draw the new line
       painter.drawPolyline(selectionPolygon,selectionPolygon.size()-2);
     }
     painter.end();

     //Draw the new doublebuffer onto the widget
     QPainter p(this);
     p.drawPixmap(0, 0, doublebuffer);
    }
  }
}
bool MReportViewer::printGhostReportToPS(const QString &outPsFile)
{
  if (report == 0)
    return false;

  int cnt = report->pageCount();

  if (cnt == 0)
    return false;

  psprinter = new PSPrinter(PSPrinter::HighResolution);
  psprinter->setPageSize((PSPrinter::PageSize) report->pageSize());
  if ((PSPrinter::PageSize) report->pageSize() == PSPrinter::Custom)
    psprinter->setCustomPaperSize(report->pageDimensions());
  psprinter->setOrientation((PSPrinter::Orientation) report->pageOrientation());
  psprinter->setMinMax(1, cnt);
  psprinter->setFromTo(1, cnt);
  psprinter->setFullPage(true);
  psprinter->setColorMode((PSPrinter::ColorMode) colorMode_);
  psprinter->setNumCopies(numCopies_);
  psprinter->setResolution(dpi_);

  QPicture *page;
  QPainter painter;
  bool printRev = false;

  int viewIdx = report->getCurrentIndex();

  if (psprinter->pageOrder() == QPrinter::LastPageFirst)
    printRev = true;

  int printFrom = psprinter->fromPage() - 1;
  int printTo = psprinter->toPage();
  int printCnt = (printTo - printFrom);
  int printCopies = psprinter->numCopies();
  int totalSteps = printCnt * printCopies;
  int currentStep = 1;

  psprinter->setNumCopies(1);
  psprinter->setOutputToFile(true);
  psprinter->setOutputFileName(outPsFile);

  QProgressDialog progress(tr("Imprimiendo Informe..."), tr("Cancelar"), totalSteps, this, tr("progreso"), true);
  progress.setMinimumDuration(M_PROGRESS_DELAY);
  QObject::connect(&progress, SIGNAL(cancelled()), this, SLOT(slotCancelPrinting()));
  progress.setProgress(0);
  qApp->processEvents();

  painter.begin(psprinter);
  QPaintDeviceMetrics pdm(psprinter);
  QSize dim(report->pageDimensions());
  painter.setWindow(0, 0, dim.width(), dim.height());
  painter.setViewport(0, 0, pdm.width(), pdm.height());

  for (int j = 0; j < printCopies; j++) {
    for (int i = printFrom; i < printTo; i++, currentStep++) {
      if (!psprinter->aborted()) {
        progress.setProgress(currentStep);
        qApp->processEvents();
        if (printRev)
          report->setCurrentPage((printCnt == 1) ? i : (printCnt - 1) - i);
        else
          report->setCurrentPage(i);
        page = report->getCurrentPage();
        page->play(&painter);
        if ((i - printFrom) < printCnt - 1)
          psprinter->newPage();
      } else {
        j = printCopies;
        break;
      }
    }
    if (j < printCopies - 1)
      psprinter->newPage();
  }

  painter.end();
  report->setCurrentPage(viewIdx);

  delete psprinter;
  return true;
}
Exemple #29
0
QImage createImage(int width, int height)
{
    QImage image(width, height, QImage::Format_RGB16);
    QPainter painter;
    QPen pen;
    pen.setStyle(Qt::NoPen);
    QBrush brush(Qt::blue);

    painter.begin(&image);
    painter.fillRect(image.rect(), brush);
    brush.setColor(Qt::white);
    painter.setPen(pen);
    painter.setBrush(brush);

    static const QPointF points1[3] = {
        QPointF(4, 4),
        QPointF(7, 4),
        QPointF(5.5, 1)
    };

    static const QPointF points2[3] = {
        QPointF(1, 4),
        QPointF(7, 4),
        QPointF(10, 10)
    };

    static const QPointF points3[3] = {
        QPointF(4, 4),
        QPointF(10, 4),
        QPointF(1, 10)
    };

    painter.setWindow(0, 0, 10, 10);

    int x = 0;
    int y = 0;
    int starWidth = image.width()/3;
    int starHeight = image.height()/3; 

    QRect rect(x, y, starWidth, starHeight);

    for (int i = 0; i < 9; ++i) {

        painter.setViewport(rect);
        painter.drawPolygon(points1, 3);
        painter.drawPolygon(points2, 3);
        painter.drawPolygon(points3, 3);

        if (i % 3 == 2) {
            y = y + starHeight;
            rect.moveTop(y);

            x = 0;
            rect.moveLeft(x);

        } else {
            x = x + starWidth;
            rect.moveLeft(x);
        }
    }

    painter.end();
    return image;
}
void CorrelationView::drawContents(QPainter *p){ 
 if((drawContentsMode == UPDATE || drawContentsMode == REDRAW) && dataReady){
 
  QRect contentsRec = contentsRect();
  //Set the window (part of the world I want to show)
  QRect r((QRect)window);

  //If the border is not visible (the user zoomed without taking it in his selection), the viewport and the contentsRec
  //have the same size.
  if(r.left() != 0) viewport = QRect(contentsRec.left(),contentsRec.top(),contentsRec.width(),contentsRec.height() -10);
  else viewport = QRect(contentsRec.left() + XMARGIN,contentsRec.top(),contentsRec.width() - XMARGIN,contentsRec.height() -10);

  //Resize the double buffer with the width and the height of the widget(QFrame)
  doublebuffer.resize(contentsRec.width(),contentsRec.height());
   
  //Create a painter to paint on the double buffer
  QPainter painter;
  painter.begin(&doublebuffer);

  painter.setWindow(r.left(),r.top(),r.width()-1,r.height()-1);//hack because Qt QRect is used differently in this function

  //Set the viewport (part of the device I want to write on).
  //By default, the viewport is the same as the device's rectangle (contentsRec), taking a smaller
  //one will ensure that the legends (cluster ids) will not ovelap a correlogram.
  painter.setViewport(viewport);


  if(drawContentsMode == REDRAW){
   //Fill the double buffer with the background
   doublebuffer.fill(backgroundColor());

   //Paint all the correlograms in the pairs list (in the double buffer)
   drawCorrelograms(painter,pairs);
  }
  //The update mode applies only when the color of a cluster has changed.
  if(drawContentsMode == UPDATE){    
   //Paint the correlograms contained in clusterUpdateList
    drawCorrelograms(painter,pairUpdateList);

    //Reset the pairUpdateList list for the next call.
    pairUpdateList.clear();
  }
  
  //reset transformation due to setWindow and setViewport
  painter.resetXForm() ;
  
  //Draw the cluster Ids along the correlograms.
  drawClusterIds(painter);

  //Closes the painter on the double buffer
  painter.end();

  //Back to the default
  drawContentsMode = REFRESH;
 }
 //if drawContentsMode == REFRESH, we reuse the double buffer (pixmap)
    
 //Draw the double buffer (pixmap) by copying it into the widget device.
 p->drawPixmap(0, 0, doublebuffer);
 setCursor(zoomCursor);
}