Beispiel #1
0
int main( int argc, char **argv )
{
    QApplication a( argc, argv );		// QApplication required!

    const char *fileName = "car.pic";			// default picture file name

    if ( argc == 2 )				// use argument as file name
	fileName = argv[1];

    if ( !QFile::exists(fileName) ) {
	QPicture pict;				// our picture
	QPainter paint;				// our painter

	paint.begin( &pict );			// begin painting onto picture
	paintCar( &paint );				// paint!
	paint.end();				// painting done

	pict.save( fileName );			// save picture
	QMessageBox::information(0, "Qt picture example", "Saved.  Run me again!");
	return 0;
    } else {
	PictureDisplay test( fileName );		// create picture display
	a.setMainWidget( &test);			// set main widget
	test.setCaption("Qt Example - Picture");
	test.show();				// show it

	return a.exec();				// start event loop
    }
}
bool QGraph::toImage(QString path){
	if(!path.isEmpty() && path.endsWith(".svg")) {
		QPicture pic;
		QPainter  p;
		
		pintafunc(&pic);
		pic.save(path, "svg");
	} else if(!path.isEmpty() && path.endsWith(".png")) {
		front.save(path, "PNG");
	} else
		return false;
	
	return true;
}
Beispiel #3
0
void FLReportViewer::saveSVGStyle()
{
  if (report) {
    QString fileName = QFileDialog::getSaveFileName("", tr("Fichero SVG (*.svg)"), this, tr("Guardar en SVG"),
                                                    tr("Guardar en SVG"));
    if (fileName.isEmpty())
      return;

    if (!fileName.upper().contains(".SVG"))
      fileName += ".svg";
    if (QFile::exists(fileName)
        && QMessageBox::question(this, tr("Sobreescribir %1").arg(fileName),
                                 tr("Ya existe un fichero llamado %1. ¿ Desea sobreescribirlo ?").arg(fileName),
                                 tr("&Sí"), tr("&No"), QString::null, 0, 1))
      return;

    FLStylePainter::setSVGMode(true);
    updateReport();
    FLStylePainter::setSVGMode(false);

    QStringList fileNames;
    QString fname;
    QPicture *page;
    QSize psize;
    for (int i = 0; i < report->pageCount(); ++i) {
      fname = fileName + QString::number(i);
      fileNames.append(fname);
      page = report->getPageAt(i);
      psize = report->pageDimensions();
      page->setBoundingRect(QRect(QPoint(0, 0), psize));
      page->save(fname, "svg");
    }

    FLStylePainter::normalizeSVGFile(fileName, fileNames);

    updateReport();
  }
}
Beispiel #4
0
void MainWindow::on_divideButton_clicked()
{
    cubeRow = ui->cubeRow->value();
    cubeCol = ui->cubeCol->value();
    if(cubeRow*cubeCol >= 4 && !filename.isEmpty() && image_origin.rows >= cubeRow*3 && image_origin.cols >= cubeCol*3)
    {
        //I. divide image
        //1.prepare
        //int largeSquare = (int)floor(sqrt(cubeNum));//get the largest square that can be made
        //qDebug() << "largeSquare:" <<largeSquare;
        float picRatio = (float)image_origin.rows / (float)image_origin.cols;//row行数col列数
        //qDebug() << "picRatio:" <<picRatio;
        float cubeRatio = (float)cubeRow / (float)cubeCol;
        int scale, fixedCol, fixedRow;
        if(picRatio >= cubeRatio)//row long
        {
            scale = image_origin.cols/(cubeCol*3);//img size devide cube's totol col
            fixedRow = scale*cubeRow*3;//set the size corresponding cube's
            fixedCol = scale*cubeCol*3;
        }
        else//col long
        {
            scale = image_origin.rows/(cubeRow*3);
            fixedRow = scale*cubeRow*3;
            fixedCol = scale*cubeCol*3;
        }
        int removeRows = image_origin.rows - fixedRow;
        int removeCols = image_origin.cols - fixedCol;

        //qDebug()<<"scale:"<<scale<<" row:"<<fixedRow<<" col:"<<fixedCol<<" Original resolution:"<<image_origin.rows<<image_origin.cols<<" remove:"<<removeRows<<removeCols;

        int removeRows_top,removeRows_down,removeCols_left,removeCols_right;
        if(removeRows%2 != 0)//the remove num of rows is not even number
        {
            //up need remove one more than down
            removeRows_top = removeRows/2 + 1;
            removeRows_down = removeRows/2;
        }
        else
            removeRows_top = removeRows_down = removeRows/2;
        if(removeCols%2 != 0)//the remove num of cols is not even number
        {
            //left need remove one more than right
            removeCols_left = removeCols/2 + 1;
            removeCols_right = removeCols/2;
        }
        else
            removeCols_left = removeCols_right = removeCols/2;

        //qDebug()<<"removeRow_fixed:"<<removeRows_top<<removeRows_down<<"removeCol_fixed:"<<removeCols_left<<removeCols_right;
        cv::Mat fixedImage = image_origin(Rect(removeCols_left,removeRows_top,fixedCol,fixedRow));//改好大小的图片

        //resize the image
        cv::Size dsize = cv::Size(cubeCol*3,cubeRow*3);//Image resolution of the match cube ratio
        //cv::Mat image_resize = fixedImage;

        cv::resize(fixedImage, image_resize, dsize);
        image_resize = changeRubixColor(image_resize);
        cv::cvtColor(image_resize, image_resize, CV_BGR2RGB);
        //image_resize---->this is what we want!!!!
        QImage QimgResize = QImage((const unsigned char*)(image_resize.data),image_resize.cols,image_resize.rows, image_resize.cols*image_resize.channels(),  QImage::Format_RGB888);
        //qDebug() << "QimgResizeRect:" << QimgResize.rect();
        ui->picLabel->clear();
        imgScaled = QimgResize.scaled(ui->picLabel->size(),Qt::KeepAspectRatio);
        //qDebug() << "imgScaledRect:" << imgScaled.rect();
        ui->picLabel->setPixmap(QPixmap::fromImage(imgScaled));//image insert into label

        /*--------------------------drawing grids----------------------------*/
        QPicture picture;
        QPainter painter;
        QPen pen_thick,pen_thin;
        pen_thick.setWidth(3);
        pen_thick.setColor(Qt::gray);
        pen_thin.setWidth(1);
        pen_thin.setColor(Qt::gray);
        painter.begin(&picture);
        picture.setBoundingRect(imgScaled.rect()); //set the boundary of painting

        //draw col line
        painter.setPen(pen_thin);
        for(int i = 0; i <= cubeCol*3; i++)
            painter.drawLine(QLineF((float)imgScaled.rect().width()/cubeCol/3.0*i, 0, (float)imgScaled.rect().width()/cubeCol/3.0*i, imgScaled.rect().height()));
        painter.setPen(pen_thick);
        for(int i = 0; i <= cubeCol; i++)
            painter.drawLine(QLineF((float)imgScaled.rect().width()/cubeCol*i, 0, (float)imgScaled.rect().width()/cubeCol*i, imgScaled.rect().height()));
        //draw row line
        painter.setPen(pen_thin);
        for(int i = 0; i <= cubeRow*3; i++)
            painter.drawLine(QLineF(0, (float)imgScaled.rect().height()/cubeRow/3.0*i, imgScaled.rect().width(), (float)imgScaled.rect().height()/cubeRow/3.0*i));
        painter.setPen(pen_thick);
        for(int i = 0; i <= cubeRow; i++)
            painter.drawLine(QLineF(0, (float)imgScaled.rect().height()/cubeRow*i, imgScaled.rect().width(), (float)imgScaled.rect().height()/cubeRow*i));

        painter.end();
        picture.save("draw_record.pic");
        ui->picLabelUp->setPicture(picture);
    }
    else if(cubeRow*cubeCol < 4)
    {
        int ret = QMessageBox::warning(this, "Warning", "The number of cubes is at least four!", QMessageBox::Abort);
        if (ret == QMessageBox::Abort)
            qDebug() << "WARNING!!";
    }
    else if(filename.isEmpty())
    {
        int ret = QMessageBox::warning(this, "Warning", "You need choose an image file!", QMessageBox::Abort);
        if (ret == QMessageBox::Abort)
            qDebug() << "WARNING!!";
    }
    else if(image_origin.rows < cubeRow*3 || image_origin.cols < cubeCol*3)
    {
        int ret = QMessageBox::warning(this, "Warning", "Too many cubes!", QMessageBox::Abort);
        if (ret == QMessageBox::Abort)
            qDebug() << "WARNING!!";
    }
}
Beispiel #5
0
void MainWindow::on_chooseCube_editingFinished()
{
    ui->divideButton->clicked();
    ui->picLabelRoi->clear();
    int num_cube = ui->chooseCube->value();
    if(num_cube > 0 && num_cube <= cubeRow * cubeCol)
    {
        //find cube in pic
        int num_row = (num_cube - 1) / cubeCol;//start at 0
        int num_col = (num_cube - 1) % cubeCol; // start at 0
        //qDebug() << "row,col:" << num_row << num_col;
        chooseCubeColor = image_resize(cv::Rect(num_col*3,num_row*3,3,3));//cube what we choose

//        //painting roi
//        float multiple = (float)imgScaled.width() / (float)image_resize.size().width;
//        QPicture picture0;
//        QPainter painter0;
//        QPen pen_roi;
//        pen_roi.setColor(Qt::red);
//        pen_roi.setWidth(2);
//        painter0.begin(&picture0);
//        painter0.setPen(pen_roi);
//        //painting red Roi
//        painter0.drawRect(QRectF(num_col*3*multiple,num_row*3*multiple,3*multiple,3*multiple));
//        //qDebug() << QRectF(num_col*3*multiple,num_row*3*multiple,3*multiple,3*multiple);
//        painter0.end();
//        picture0.save("draw_roi.pic");
//        ui->picLabelRoi->setPicture(picture0);


        //painting cube
        QPicture picture;
        QPainter painter;
        QPen pen_cube;
        pen_cube.setColor(Qt::black);
        pen_cube.setWidth(2);
        painter.begin(&picture);
        painter.setPen(pen_cube);
        QBrush brush(Qt::SolidPattern);

        //painting choose cube
        int block_size = 40;
        for(int i = 0; i < 9; i++)
        {
            //qDebug() << "RGB:" << chooseCubeColor.at<Vec3b>(i/3,i%3).val[0]<<chooseCubeColor.at<Vec3b>(i/3,i%3).val[1]<<chooseCubeColor.at<Vec3b>(i/3,i%3).val[2];
            brush.setColor(QColor(chooseCubeColor.at<Vec3b>(i/3,i%3).val[0],chooseCubeColor.at<Vec3b>(i/3,i%3).val[1],chooseCubeColor.at<Vec3b>(i/3,i%3).val[2]));//RGB 3 channels
            painter.setBrush(brush);
            painter.drawRoundRect(QRect(block_size*i%(block_size*3),block_size*(i/3),block_size,block_size));
        }
        painter.end();
        picture.save("draw_cube.pic");
        ui->showCubeChoose->setPicture(picture);

        //store colors of cube
        for(int i = 0; i < 9; i++)
        {
            QColor qcolor = QColor(chooseCubeColor.at<Vec3b>(i/3,i%3).val[0],chooseCubeColor.at<Vec3b>(i/3,i%3).val[1],chooseCubeColor.at<Vec3b>(i/3,i%3).val[2]);//RGB 3 channels
            int color_num;
            if(qcolor == colorTable_cube[0])
                color_num = 0;
            else if(qcolor == colorTable_cube[1])
                color_num = 1;
            else if(qcolor == colorTable_cube[2])
                color_num = 2;
            else if(qcolor == colorTable_cube[3])
                color_num = 3;
            else if(qcolor == colorTable_cube[4])
                color_num = 4;
            else if(qcolor == colorTable_cube[5])
                color_num = 5;
            else
                color_num = -1;
            col[i] = RubikColor(color_num);
            //qDebug() << "color:" << color_num;
        }
        dlg.setRubikColor(col);
    }
    else
    {
        int ret = QMessageBox::warning(this, "Warning", "Please choose the cube you want to make!", QMessageBox::Abort);
        if (ret == QMessageBox::Abort)
            qDebug() << "WARNING!!";
    }

}
Beispiel #6
0
int main()
{
    QWidget myWidget;
    {
        // RECORD
//! [0]
        QPicture picture;
        QPainter painter;
        painter.begin(&picture);           // paint in picture
        painter.drawEllipse(10,20, 80,70); // draw an ellipse
        painter.end();                     // painting done
        picture.save("drawing.pic");       // save picture
//! [0]
    }

    {
        // REPLAY
//! [1]
        QPicture picture;
        picture.load("drawing.pic");           // load picture
        QPainter painter;
        painter.begin(&myImage);               // paint in myImage
        painter.drawPicture(0, 0, picture);    // draw the picture at (0,0)
        painter.end();                         // painting done
//! [1]
    }

    QPicture myPicture;
    {
        // FORMATS
//! [2]
        QStringList list = QPicture::inputFormatList();
        foreach (QString string, list)
            myProcessing(string);
//! [2]
    }

    {
        // OUTPUT
//! [3]
        QStringList list = QPicture::outputFormatList();
        foreach (QString string, list)
            myProcessing(string);
//! [3]
    }

    {
        // PIC READ
//! [4]
        QPictureIO iio;
        QPixmap  pixmap;
        iio.setFileName("vegeburger.pic");
        if (iio.read()) {        // OK
            QPicture picture = iio.picture();
            QPainter painter(&pixmap);
            painter.drawPicture(0, 0, picture);
        }
//! [4]
    }

    {
        QPixmap pixmap;
        // PIC WRITE
//! [5]
        QPictureIO iio;
        QPicture   picture;
        QPainter painter(&picture);
        painter.drawPixmap(0, 0, pixmap);
        iio.setPicture(picture);
        iio.setFileName("vegeburger.pic");
        iio.setFormat("PIC");
        if (iio.write())
            return true; // returned true if written successfully
//! [5]
    }

}
void SvgCanvas::actionExport_to_callback()
{
	QDialog dialog;
	ExportToDialog export_to_dialog;
	export_to_dialog.setupUi(&dialog);
	QListWidget *list = export_to_dialog.formats_listWidget;
	QListWidgetItem *item;
	//Pixmaps formats
	QList<QByteArray> formats=QImageWriter::supportedImageFormats();
	for(int i=0;i<formats.size();i++)
	{
		QString text(formats[i]);
		item=new QListWidgetItem(text,list);
		item->setData(1,QVariant(PIXMAP));
	}
	//Vector formats
	formats= QPicture::outputFormats();
	for(int i=0;i<formats.size();i++)
	{
		QString text(formats[i]);
		item=new QListWidgetItem(text,list);
		item->setData(1,QVariant(PICTURE));
	}
	
	item=new QListWidgetItem("ps",list);
	item->setData(1,QVariant(PRINTER));
	
	item=new QListWidgetItem("pdf",list);
	item->setData(1,QVariant(PDF));
	
	item=new QListWidgetItem("svg",list);
	item->setData(1,QVariant(SVG));
	
	int ok=dialog.exec();
	if(ok==QDialog::Rejected) return;
	
	item =list->currentItem();
	int format=item->data(1).toInt();
	
	QPainter plot;
	switch(format)
	{
		case PIXMAP:
		{
			bool ok;
			int h, w = QInputDialog::getInteger(this, tr("Width"), tr("Width:"), 300, 0, 2147483647, 1, &ok);
			if(!ok) return;
			h=QInputDialog::getInteger(this, tr("Height"), tr("Height:"), 200, 0, 2147483647, 1, &ok);
			if(!ok) return;
			QString s = QFileDialog::getSaveFileName(this, "Choose a filename to save");
			if(s.isEmpty()) return;
			QImage image(w,h,QImage::Format_RGB32);
			plot.begin(&image);
			svg_plot->renderer()->render(&plot);
			plot.end();
			image.save(s,item->data(0).toString().toLocal8Bit().data());
		}
		break;
		case PICTURE:
		{
			bool ok;
			int h, w = QInputDialog::getInteger(this, tr("Width"), tr("Width:"), 300, 0, 2147483647, 1, &ok);
			if(!ok) return;
			h=QInputDialog::getInteger(this, tr("Height"), tr("Height:"), 200, 0, 2147483647, 1, &ok);
			if(!ok) return;
			QString s = QFileDialog::getSaveFileName(this, "Choose a filename to save");
			if(s.isEmpty()) return;
			QPicture image;
			const QRect r(0,0,w,h);
			image.setBoundingRect(r);
			plot.begin(&image);
			svg_plot->renderer()->render(&plot);
			plot.end();
			image.save(s,item->data(0).toString().toLocal8Bit().data());
		}
		break;
		case PRINTER:
		{
			QPrinter p;
			QPrintDialog printDialog(&p, this);
			if (printDialog.exec() != QDialog::Accepted) return;
			plot.begin(&p);
			svg_plot->renderer()->render(&plot);
			plot.end();
		}
		break;
		case PDF:
		{
			QPrinter p;
			QPrintDialog printDialog(&p, this);
			p.setOutputFormat(QPrinter::PdfFormat);
			if (printDialog.exec() != QDialog::Accepted) return;
			
			plot.begin(&p);
			svg_plot->renderer()->render(&plot);
			plot.end();
		}
		break;
		case SVG:
		{
			QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "", tr("*.svg"));
			QSvgGenerator p;
			p.setFileName(fileName);
			plot.begin(&p);
			svg_plot->renderer()->render(&plot);
			plot.end();
		}
	}
}
Beispiel #8
0
void Export::slotAccept()
{
    switch ( group -> selectedId() )
    {
        case 0:
	{
            QString fn = QFileDialog::getSaveFileName( "projects/output/", "PNG sequence ( *.png )", this );
            if ( !fn.isEmpty() )
	    {
        	if ( k_toon -> scenes() -> exportAnimation( fn, "PNG" ) > 0 )
        	    k_toon -> statusBar() -> message( tr( "Animation Exported Successfully" ), 2000 );
        	else
        	    k_toon -> statusBar() -> message( tr( "Could not Export Animation" ), 2000 );
	    }
	    break;
	}
        case 1:
	{
            QString fn = QFileDialog::getSaveFileName( "projects/output/", "Single PNG ( *.png )", this );
            if ( !fn.isEmpty() )
	    {
		QPixmap exp;
		fn = fn + ".png";
		exp.convertFromImage( k_toon -> renderCameraPreview() -> grabFrameBuffer() );
		if ( !exp.save( fn, "PNG" ) )
		     k_toon -> statusBar() -> message( tr( "Could not save the file: %1" ).arg( fn ), 2000 );
	    }
	    break;
	}
        case 2:
	{
            QString fn = QFileDialog::getSaveFileName( "projects/output/", "Macromedia Flash ( *.swf )", this );
            if ( !fn.isEmpty() )
	    {
	        int number_of_images = k_toon -> scenes() -> exportAnimation( fn, "JPEG" );
        	if ( number_of_images > 0 )
		{
		    int frame_rate = k_toon -> currentStatus() -> currentFrameRate();

		    SWFMovie *movie = doMovie( 360, 280 );
  		    movie -> setRate( ( float )frame_rate );
  		    QStringList images;

		    for ( int i = 1; i < number_of_images; i++ )
  		    {
     			QString iterator = QString::number( i );
     			iterator = iterator.rightJustify( 3, '0' );
     			images << QString( fn + iterator + ".jpg" );
  		    }

  		    SWFDisplayItem *frame = doAnimation( movie, images );
		    frame -> addColor( 255, 0, 0 );

  		    if ( movie -> save( ( char * )( fn + ".swf" ).latin1() ) < 0 )
        	        k_toon -> statusBar() -> message( tr( "Could not Export Animation" ), 2000 );
		    else
		        k_toon -> statusBar() -> message( tr( "Animation Exported Successfully" ), 2000 );

		    for ( int i = 1; i < number_of_images; i++ )
  		    {
     			QString iterator = QString::number( i );
     			iterator = iterator.rightJustify( 3, '0' );
     			QFile::remove( fn + iterator + ".jpg" );
  		    }
		}
        	else
        	    k_toon -> statusBar() -> message( tr( "Could not Export Animation" ), 2000 );
	    }
	    break;
	}
	case 3:
	{
            QString fn = QFileDialog::getSaveFileName( "projects/output/", "Scalable Vector Graphics ( *.svg )", this );
            if ( !fn.isEmpty() )
	    {
		QPixmap exp;
		fn = fn + ".svg";
		exp.convertFromImage( k_toon -> renderCameraPreview() -> grabFrameBuffer() );

		QPainter painter;
		QPicture picture;

		painter.begin( &picture );
		painter.drawPixmap( 0, 0, exp );
		painter.end();

		if ( picture.save( fn, "svg" ) )
		    k_toon -> statusBar() -> message( tr( "SVG Exported Successfully" ), 2000 );
		else
		    k_toon -> statusBar() -> message( tr( "Could not Export SVG" ), 2000 );
	    }
	    break;
	}
	default: break;
    }

    close( true );
}
Beispiel #9
0
void Clamp::print() {
#if 1
	QPrinter printer;
#else
	QPrinter printer(QPrinter::HighResolution);
#if QT_VERSION < 0x040000
	printer.setOutputToFile(true);
	printer.setOutputFileName("/tmp/FI.ps");
	printer.setColorMode(QPrinter::Color);
#else
	printer.setOutputFileName("/tmp/FI.pdf");
#endif
#endif

	QString docName = splot->title().text();
	if (!docName.isEmpty()) {
		docName.replace(QRegExp(QString::fromLatin1("\n")), tr(" -- "));
		printer.setDocName(docName);
	}

	printer.setCreator("RTXI");
	printer.setOrientation(QPrinter::Landscape);

#if QT_VERSION >= 0x040000
	QPrintDialog dialog(&printer);
	if ( dialog.exec() ) {
#else
		if (printer.setup())	{
#endif 
/*
		RTXIPrintFilter filter;
		if (printer.colorMode() == QPrinter::GrayScale) {
		 int options = QwtPlotPrintFilter::PrintAll;
		 filter.setOptions(options);
		 filter.color(QColor(29, 100, 141),
			  QwtPlotPrintFilter::CanvasBackground);
		 filter.color(Qt::white, QwtPlotPrintFilter::CurveSymbol);
		}
*/
//	splot->print(printer, filter);
	QwtPlotRenderer *renderer = new QwtPlotRenderer;
	renderer->renderTo(splot, printer);
	}
}

void Clamp::exportSVG() {
	QString fileName = "FI.svg";

std::cout<<"flag 0"<<std::endl;

#if QT_VERSION < 0x040000
std::cout<<"flag 1"<<std::endl;

#ifndef QT_NO_FILEDIALOG
std::cout<<"flag 2"<<std::endl;
	fileName = QFileDialog::getSaveFileName("FI.svg", "SVG Documents (*.svg)",	this);
#endif
std::cout<<"flag 3"<<std::endl;
	if (!fileName.isEmpty()) {
		// enable workaround for Qt3 misalignments
		QwtPainter::setSVGMode(true);
		QPicture picture;
		QPainter p(&picture);
//		splot->print(&p, QRect(0, 0, 800, 600));
		QwtPlotRenderer *renderer = new QwtPlotRenderer;
		renderer->renderTo(splot, p, QRect(0, 0, 800, 600));
		p.end();
		picture.save(fileName, "svg");
	}

#elif QT_VERSION >= 0x040300
std::cout<<"flag 4"<<std::endl;
#ifdef QT_SVG_LIB
std::cout<<"flag 5"<<std::endl;
#ifndef QT_NO_FILEDIALOG
std::cout<<"flag 6"<<std::endl;
		fileName = QFileDialog::getSaveFileName(this, "Export File Name", 
		                                        QString(), "SVG Documents (*.svg)");
#endif
std::cout<<"flag 7"<<std::endl;
	if ( !fileName.isEmpty() ) {
		QSvgGenerator generator;
		generator.setFileName(fileName);
		generator.setSize(QSize(800, 600));
//		splot->print(generator);
	}
#endif
#endif
}