00001 // @(#)root/qt:$Name: $:$Id: QtPrintDialog.C,v 1.4 2008/09/28 02:22:23 fine Exp $ 00002 // Author: Valeri Fine 23/03/2006 00003 #ifndef __CINT__ 00004 # include <QPrintDialog> 00005 # include <QPrinter> 00006 # include <QPainter> 00007 # include <QPixmap> 00008 # include <TCanvas.h> 00009 # include <TGQt.h> 00010 #endif 00011 void QtPrintDialog(TVirtualPad *pad = 0) { 00012 // 00013 // This is a small ROOT macro to use Qt 3.3 class: begin_html <a href="http://doc.trolltech.com/3.3/qprinter.html">QPrinter</a> end_html 00014 // to setup the printer via Qt "setup printer dialog" 00015 // See: begin_html <a href="http://doc.trolltech.com/3.3/qprinter.html#setup">Printer setup dialog box</a> end_html 00016 // and print out the ROOT TCanvas object either via the "can" pointer provided or the current one. 00017 // 00018 // To use, invoke ACLiC from the ROOT prompt: 00019 // root [] .x QtPrintDialog.C++ 00020 // 00021 // To use it with no ACLiC, omit the trailing "++" 00022 // root [] .x QtPrintDialog.C 00023 // 00024 // 00025 // The full list of the Qt classes available from Cint is defined by 00026 // begin_html <a href="http://root.bnl.gov/QtRoot/htmldoc/src/qtclasses.h.html">by $ROOTSYS/cint/lib/qtclasses.h</a> end_html 00027 // 00028 // All Qt classes can be used from ACLiC though. 00029 00030 #ifdef __CINT__ 00031 // Load the qt cint dictionary. 00032 // One is recommended to do that at once somewhere. 00033 // For example from his/her custom rootlogon.C script 00034 gSystem->Load("$ROOTSYS/cint/cint/include/qtcint"); 00035 #endif 00036 TVirtualPad *pd = pad; 00037 if (!pd) pd = TPad::Pad(); // ->GetCanvas(); 00038 if (pd) { 00039 QPrinter p; 00040 // Open the Qt "Setup Printer" dialog to configure the "QPrinter p" object 00041 QPrintDialog printDialog(&p); 00042 if (printDialog.exec() == QDialog::Accepted) { 00043 Int_t id = pd->GetPixmapID(); 00044 QPixmap *pix = (QPixmap *)(TGQt::iwid(id)); 00045 QPainter pnt(&p); 00046 pnt.drawPixmap(0,0,*pix); 00047 } 00048 } else { 00049 printf(" No TCanvas has been selected yet! \n"); 00050 } 00051 } 00052