Changeset 588 for trunk/geant4/visualization/OpenGL/src
- Timestamp:
- Sep 28, 2007, 5:16:30 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc
r587 r588 56 56 #include <QMessageBox> 57 57 #include <QFileDialog.h> 58 #include <QPrinter.h> 59 #include <QPainter.h> 58 60 59 61 ////////////////////////////////////////////////////////////////////////////// … … 664 666 // } 665 667 } 666 filters += "eps"; 668 filters += "eps;;"; 669 filters += "ps;;"; 670 filters += "pdf"; 667 671 QString* selectedFilter = new QString(); 668 672 QString nomFich = QFileDialog::getSaveFileName ( GLWindow, … … 701 705 } else if (nomFich.endsWith(".eps")) { 702 706 generateEPS(nomFich,exportDialog->getNbColor(),image); 707 } else if (nomFich.endsWith(".ps") ||nomFich.endsWith(".pdf")) { 708 generatePS_PDF(nomFich,exportDialog->getNbColor(),image); 703 709 } else if (nomFich.endsWith(".tif") || 704 710 nomFich.endsWith(".tiff") || … … 722 728 /* 723 729 // http://www.google.com/codesearch?hl=en&q=+jpg+Qt+quality+QDialog+show:FZkUoth8oiw:TONpW2mR-_c:tyTfrKMO-xI&sa=N&cd=2&ct=rc&cs_p=http://soft.proindependent.com/src/qtiplot-0.8.9.zip&cs_f=qtiplot-0.8.9/qtiplot/src/application.cpp#a0 724 void ApplicationWindow::exportLayer()725 {726 QWidget *w=ws->activeWindow();727 if (!w || !w->isA("MultiLayer"))728 return;729 730 Graph* g = ((MultiLayer*)w)->activeGraph();731 if (!g)732 return;733 734 ImageExportDialog *ied = new ImageExportDialog(this, 0);735 ied->setDir(workingDir);736 if ( ied->exec() == QDialog::Accepted )737 {738 workingDir = ied->dirPath();739 QString fname = ied->selectedFile();740 QString selectedFilter = ied->selectedFilter();741 742 QFileInfo fi(fname);743 QString baseName = fi.fileName();744 745 if (baseName.contains(".")==0)746 fname.append(selectedFilter.remove("*"));747 748 if ( QFile::exists(fname) &&749 QMessageBox::question(0, tr("QtiPlot - Overwrite File?"),750 tr("A file called: <p><b>%1</b><p>already exists. "751 "Do you want to overwrite it?")752 .arg(fname),753 tr("&Yes"), tr("&No"),754 QString::null, 0, 1 ) )755 return ;756 else757 {758 QFile f(fname);759 if ( !f.open( IO_WriteOnly ) )760 {761 QMessageBox::critical(0, tr("QtiPlot - Export Error"),762 tr("Could not write to file: <br><h4> %1 </h4><p>Please verify that you have the right to write to this location!").arg(fname));763 return;764 }765 766 if (selectedFilter.contains(".eps"))767 {768 if (ied->showExportOptions())769 {770 epsExportDialog *ed= new epsExportDialog (fname, this, "exportDialog", TRUE, WStyle_Tool|WDestructiveClose);771 connect (ed, SIGNAL(exportToEPS(const QString&, int, QPrinter::Orientation, QPrinter::PageSize, QPrinter::ColorMode)),772 g, SLOT(exportToEPS(const QString&, int, QPrinter::Orientation, QPrinter::PageSize, QPrinter::ColorMode)));773 774 ed->showNormal();775 ed->setActiveWindow();776 }777 else778 g->exportToEPS(fname);779 780 if (((MultiLayer*)w)->hasOverlapingLayers())781 ((MultiLayer*)w)->updateTransparency();782 return;783 }784 else if (selectedFilter.contains(".svg"))785 {786 g->exportToSVG(fname);787 return;788 }789 // else if (selectedFilter.contains(".wmf"))790 // {791 // g->exportToWmf(fname);792 // return;793 }794 QStringList list=QImage::outputFormatList ();795 for (int i=0; i<(int)list.count(); i++)796 {797 if (selectedFilter.contains("."+(list[i]).lower()))798 {799 if (ied->showExportOptions())800 {801 imageExportDialog* ed= new imageExportDialog(false, this,"exportDialog",TRUE,WStyle_Tool|WDestructiveClose);802 connect (ed, SIGNAL(options(const QString&, const QString&, int, bool)),803 g, SLOT(exportImage(const QString&, const QString&, int, bool)));804 805 ed->setExportPath(fname, list[i]);806 ed->enableTransparency();807 ed->showNormal();808 ed->setActiveWindow();809 }810 else811 g->exportImage(fname, list[i], 100, true);812 813 if (((MultiLayer*)w)->hasOverlapingLayers())814 ((MultiLayer*)w)->updateTransparency();815 return;816 }817 }818 }819 }820 }821 730 822 731 void Graph::exportToSVG(const QString& fname) … … 952 861 @param aImage : Image to print 953 862 */ 954 intG4OpenGLQtViewer::generateEPS (863 bool G4OpenGLQtViewer::generateEPS ( 955 864 QString aFilename 956 865 ,int aInColor … … 965 874 966 875 const uchar * pixels = aImage.bits (); 967 // pixels = grabPixels (inColour, width, height);968 876 969 877 if (pixels == NULL) 970 return 1;878 return false; 971 879 972 880 fp = fopen (aFilename.toStdString().c_str(), "w"); 973 881 if (fp == NULL) { 974 return 2;882 return false; 975 883 } 976 884 … … 1006 914 fprintf (fp, "{currentfile picstr readhexstring pop}\n"); 1007 915 fprintf (fp, "false %d\n", aInColor); 1008 // fprintf (fp, "%%BeginData: %d ASCII Bytes\n",size);1009 916 fprintf (fp, "colorimage\n"); 1010 917 1011 printf("boucle jusque :%d/%d par ligne:%d \n",aImage.width()*aImage.height()*aInColor,aImage.numBytes(),aImage.bytesPerLine ()); 1012 1013 QRgb color; 1014 if (aInColor == 3) { // for RGB images 1015 for (int j=aImage.height()-1;j>=0;j--){ 1016 for (int i=0;i<aImage.width();i++){ 1017 color = aImage.pixel (i,j); 1018 fprintf (fp, " %02hx %02hx %02hx",qBlue(color),qGreen(color),qRed(color)); 918 919 int width = aImage.width(); 920 int height = aImage.height(); 921 int depth = aImage.depth(); 922 int size = width*height; 923 924 if (depth == 1) 925 size = (width+7)/8*height; 926 else if (aInColor == 1) 927 size = size*3; 928 929 int i = 0; 930 if (depth == 1) { 931 // To be implemented 932 // QImage::Endian bitOrder = aImage.bitOrder(); 933 /* for(int y=0; y < height; y++) { 934 const uchar * s = aImage.scanLine(y); 935 for(int x=0; x < width; x++) { 936 // need to copy bit for bit... 937 bool b = (bitOrder == QImage::LittleEndian) ? 938 (*(s + (x >> 3)) >> (x & 7)) & 1 : 939 (*(s + (x >> 3)) << (x & 7)) & 0x80 ; 940 if (b) 941 pixel[i >> 3] ^= (0x80 >> (i & 7)); 942 i++; 1019 943 } 1020 fprintf (fp, "\n"); 1021 } 1022 } else if (aInColor == 4) { 1023 // for RGB images 1024 for (int j=aImage.height()-1;j>=0;j--){ 1025 for (int i=0;i<aImage.width();i++){ 1026 color = aImage.pixel (i,j); 1027 fprintf (fp, " %02hx %02hx %02hx %02hx",qAlpha(color), qRed(color),qGreen(color),qBlue(color)); 944 // we need to align to 8 bit here 945 i = (i+7) & 0xffffff8; 946 } 947 */ 948 } else if (depth == 8) { 949 printf("has 8 bit\n"); 950 for(int y=height-1; y >=0 ; y--) { 951 const uchar * s = aImage.scanLine(y); 952 for(int x=0; x <width; x++) { 953 QRgb rgb = aImage.color(s[x]); 954 if (aInColor == 1) { 955 fprintf (fp, " %02hx ",(unsigned char)qGray(rgb)); 956 i++; 957 } else { 958 fprintf (fp, " %02hx %02hx %02hx", 959 (unsigned char) qRed(rgb), 960 (unsigned char) qGreen(rgb), 961 (unsigned char) qBlue(rgb)); 962 i += 3; 963 } 1028 964 } 1029 965 fprintf (fp, "\n"); 1030 966 } 1031 } 1032 else if (aInColor == 1) { // for grayscale 1033 } 1034 967 } else { 968 bool alpha = aImage.hasAlphaChannel(); 969 printf("has else %d alpha %d\n",depth,alpha); 970 for(int y=height-1; y >=0 ; y--) { 971 QRgb * s = (QRgb*)(aImage.scanLine(y)); 972 for(int x=0; x <width; x++) { 973 QRgb rgb = (*s++); 974 if (alpha && qAlpha(rgb) < 0x40) // 25% alpha, convert to white - 975 rgb = qRgb(0xff, 0xff, 0xff); 976 if (aInColor == 1) { 977 fprintf (fp, " %02hx ",(unsigned char)qGray(rgb)); 978 i++; 979 } else { 980 fprintf (fp, " %02hx %02hx %02hx", 981 (unsigned char) qRed(rgb), 982 (unsigned char) qGreen(rgb), 983 (unsigned char) qBlue(rgb)); 984 i += 3; 985 } 986 } 987 fprintf (fp, "\n"); 988 } 989 } 990 1035 991 fprintf (fp, "grestore\n"); 1036 992 fprintf (fp, "showpage\n"); 1037 // delete pixels;1038 993 fclose (fp); 1039 return 0; 1040 } 994 995 return true; 996 } 997 /** 998 Generate Postscript or PDF form image 999 @param aFilename : name of file 1000 @param aInColor : numbers of colors : 1->BW 2->RGB 1001 @param aImage : Image to print 1002 */ 1003 bool G4OpenGLQtViewer::generatePS_PDF ( 1004 QString aFilename 1005 ,int aInColor 1006 ,QImage aImage 1007 ) 1008 { 1009 QPrinter printer; 1010 // printer.setPageSize(pageSize); 1011 if (aInColor == 1) { 1012 printer.setColorMode(QPrinter::GrayScale); 1013 } else { 1014 printer.setColorMode(QPrinter::Color); 1015 } 1016 1017 if (aFilename.endsWith(".ps")) { 1018 printer.setOutputFormat(QPrinter::PostScriptFormat); 1019 } else { 1020 printer.setOutputFormat(QPrinter::PdfFormat); 1021 } 1022 printer.setOutputFileName(aFilename); 1023 // printer.setFullPage ( true); 1024 QPainter paint(&printer); 1025 paint.drawImage (0,0,aImage ); 1026 paint.end(); 1027 return true; 1028 } 1029 1041 1030 #endif 1031 1032 /* 1033 1034 void MultiLayer::exportToSVG(const QString& fname) 1035 { 1036 QPicture picture; 1037 QPainter p(&picture); 1038 for (int i=0;i<(int)graphsList->count();i++) 1039 { 1040 Graph *gr=(Graph *)graphsList->at(i); 1041 Plot *myPlot= (Plot *)gr->plotWidget(); 1042 1043 QPoint pos=gr->pos(); 1044 1045 int width=int(myPlot->frameGeometry().width()); 1046 int height=int(myPlot->frameGeometry().height()); 1047 1048 myPlot->print(&p, QRect(pos,QSize(width,height))); 1049 } 1050 1051 p.end(); 1052 picture.save(fname, "svg"); 1053 } 1054 */
Note: See TracChangeset
for help on using the changeset viewer.