//-----------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------
void HistogramItem::mousePressEvent (QMouseEvent *event) {
    event->accept();
    if (event->button() == Qt::RightButton) {
//        int w = this->width();
//        int h = this->height();
        int w = 512;
        int h = 512;
        QPixmap pixmap(w, h);
        pixmap.fill(Qt::white); // Qt::transparent ?

        QwtPlotPrintFilter filter;
        int options = QwtPlotPrintFilter::PrintAll;
        options &= ~QwtPlotPrintFilter::PrintBackground;
        options |= QwtPlotPrintFilter::PrintFrameWithScales;
        filter.setOptions(options);

//        this->print(pixmap, filter);

//		QString fileName = getImageFile();
        QString fileName = QFileDialog::getSaveFileName(0,"Select image file", ".",
            "Image files (*.png *.jpg *.tif *.bmp)");
        if (fileName.isEmpty()) {
            return;
        }
        pixmap.save(fileName,0,-1);
    }
}
示例#2
0
//-----------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------
void Plot::mousePressEvent (QMouseEvent *event) {
	event->accept();
	if (event->button() == Qt::RightButton) {
		int w = this->width();
		int h = this->height();
		QPixmap pixmap(w, h);
        pixmap.fill(Qt::white);

		QwtPlotPrintFilter filter;
		int options = QwtPlotPrintFilter::PrintAll;
		options &= ~QwtPlotPrintFilter::PrintBackground;
		options |= QwtPlotPrintFilter::PrintFrameWithScales;
		filter.setOptions(options);

		this->print(pixmap, filter);

		QString fileName = getImageFile();
		if (fileName.isEmpty()) {
			return;
		}
		pixmap.save(fileName,0,-1);

        // Testing conversion to QImage, for qvideooutput
        QImage image = pixmap.toImage();
	}
}
QPixmap MultiLayer::canvasPixmap()
{
QSize size=canvas->size();
QPixmap pic(size.width(), size.height(), -1, QPixmap::BestOptim);
pic.fill (Qt::white);
	
QPainter paint;
paint.begin(&pic);

QwtPlotPrintFilter filter;
filter.setOptions(QwtPlotPrintFilter::PrintAll | QwtPlotPrintFilter::PrintTitle |
				   QwtPlotPrintFilter::PrintCanvasBackground);
	
for (int i=0;i<(int)graphsList->count();i++)
		{
		Graph *gr=(Graph *)graphsList->at(i);
		Plot *myPlot= gr->plotWidget();

		int lw = myPlot->lineWidth();
		QRect rect = QRect(gr->x() + lw, gr->y() + lw, myPlot->width() - 2*lw, 
						  myPlot->height() - 2*lw);

		if (myPlot->paletteBackgroundColor() != QColor(white))
			paint.fillRect(rect, myPlot->paletteBackgroundColor());

		myPlot->print(&paint, rect, filter);

		if (lw > 0)
			myPlot->printFrame(&paint, rect);
		}		
paint.end();
return pic;
}
示例#4
0
void ProRataGraphPane::print()
{
	if ( !(qtwGraphTab->currentWidget()) )
	{
		return ;
	}

/*
	QString qsSaveFileName = QFileDialog::getSaveFileName(
                    this,
                    "ProRata - Choose a file name to save",
                    ".",
                    "Images (*.png *.jpg)");

	if (qsSaveFileName.isEmpty())
	{
		return;
	}
	*/

	ProRataGraph *clickedGraph = (ProRataGraph *)qtwGraphTab->currentWidget();

	QPrinter printer;
    //printer.setOutputToFile(true);
    //printer.setOutputFileName(qsSaveFileName);
    printer.setDocName(QString("ProRata_Graph"));

    printer.setCreator("ProRata Graph");
    printer.setOrientation(QPrinter::Landscape);

	QPrintDialog dialog(&printer);
    if ( dialog.exec() )
    {
		QwtPlotPrintFilter filter;
		if ( printer.colorMode() == QPrinter::GrayScale )
        {
            filter.setOptions(QwtPlotPrintFilter::PrintAll 
                & ~QwtPlotPrintFilter::PrintCanvasBackground);
        }
		clickedGraph->print( printer, filter );
	}
	
	

/*
	//QPixmap *qpPic = new QPixmap( qsSaveFileName );
	//QPainter * qpntrPainter = new QPainter( qpPic );
	QPixmap qpPic( qsSaveFileName );
	qpPic.save( qsSaveFileName );
	//QPainter * qpntrPainter = new QPainter( qpPic );

	//clickedGraph->print( qpntrPainter, clickedGraph->frameGeometry() );
	clickedGraph->print( qpPic );
*/
	//QMessageBox::information( this, "Printing done.", QString( "Saved \"") + qsSaveFileName + QString( "\"" ) );

}
void Data_analysis_gui::save_as_image( const QString& filename, 
                                       const QString& format,
                                       bool show_stats, bool show_grid ) {
  // get a file name and the name of the filter to use to save the image.
  // 3 filters are available: PNG, BMP, and Postscript. Postscript is not
  // available on Windows (Qt limitation).


  // Create a blank image of the correct dimensions
  int extra_width = 15;
  int min_height = 0;
  if( show_stats ) {
    extra_width = 200;
    min_height = 250;
  }
  QSize total_size( plot_->size().width() + extra_width, 
                    std::max( min_height, plot_->size().height()+10 ) );
  QPixmap pix( total_size );
  pix.fill();
  QPainter painter( &pix );
  

  // draw the content of the plot

  QwtPlotPrintFilter filter;
  if( show_grid )
    filter.setOptions( QwtPlotPrintFilter::PrintTitle | QwtPlotPrintFilter::PrintGrid );
  else
    filter.setOptions( QwtPlotPrintFilter::PrintTitle );

  QRect rect = plot_->rect();
  rect.setY( rect.y() + 10 );
  plot_->print( &painter, rect, filter );


  // Add the summary statistics to the image if requested

  if( show_stats ) {
    QFont font = plot_->axisFont( QwtPlot::xBottom );
    painter.setFont( font );
    int text_y_start = std::max( 40, total_size.height()/2 - 100 );
    painter.translate( plot_->size().width()+15 , text_y_start );
    paint_stats( painter );
  }


  // Finally, save the pixmap in the required format

  if( format == "Postscript" || format == "PS" ) {
    /*
#if defined(WIN32) || defined(_WIN32)
    if (show_stats)
		build_stats();
    SimplePs ps(filename,plot_, _stats,show_stats);
	if (!ps.isopen()){
		QMessageBox::warning(this,"Unable to save file",
		"Failed to save ps file",QMessageBox::Ok,
		Qt::NoButton);
		return;
	}
	savePostScript(ps);

#else
    */
    QPrinter printer;
    
    printer.setOutputFormat(QPrinter::PostScriptFormat);
    printer.setOutputFileName( filename );
    printer.setPageSize( QPrinter::A6 );
    printer.setFullPage( true );
    printer.setOrientation( QPrinter::Landscape );
    plot_->print(printer, filter);

    QPainter P(&printer);
    //P.begin(&printer);
    //paint_stats(P);
    P.drawPixmap(QPoint(0,0),pix);

    //#endif
  }
  else {
    QByteArray tmp = format.toLatin1();
    pix.save( filename, tmp.constData() );
  }

}