#include <QIcon>
#include <QApplication>
#include <QContextMenuEvent>
+#include <QPrintDialog>
+#include <QPrinter>
+#include <QPainter>
+
/*!\class SUIT_ViewWindow
* Class provide view window.
void SUIT_ViewWindow::setVisualParameters( const QString& /*parameters*/ )
{
}
+
+/*!
+ Prints given image
+ \param theImage - the image to print
+*/
+void SUIT_ViewWindow::printImage( const QImage& theImage, QWidget* theWidget )
+{
+ if ( theImage.isNull() )
+ return;
+
+ // stored settings for further starts
+ static QString aPrinterName;
+ static int anOrientation = -1;
+
+ QPrinter aPrinter;
+
+ // restore settinds from previous launching
+
+ // printer name
+ if ( !aPrinterName.isEmpty() )
+ aPrinter.setPrinterName( aPrinterName );
+ else
+ {
+ // Nothing to do for the first printing. aPrinter contains default printer name by default
+ }
+
+ if ( anOrientation >= 0 )
+ aPrinter.setOrientation( (QPrinter::Orientation)anOrientation );
+ else
+ aPrinter.setOrientation( QPrinter::Landscape );
+
+
+ QPrintDialog printDlg( &aPrinter, theWidget );
+ printDlg.setPrintRange( QAbstractPrintDialog::AllPages );
+ if ( printDlg.exec() != QDialog::Accepted )
+ return;
+
+ // store printer settings for further starts
+ aPrinterName = aPrinter.printerName();
+ anOrientation = aPrinter.orientation();
+
+ int W, H;
+ QPainter aPainter;
+
+ // work arround for printing on real printer
+ if ( aPrinter.outputFileName().isEmpty() && aPrinter.orientation() == QPrinter::Landscape )
+ {
+ aPrinter.setFullPage( true );
+ // set paper orientation and rotate painter
+ aPrinter.setOrientation( QPrinter::Portrait );
+
+ W = aPrinter.height();
+ H = aPrinter.width();
+
+ int wBorder = aPrinter.paperRect().height() - W;
+ int hBorder = aPrinter.paperRect().width() - H;
+
+ aPainter.begin( &aPrinter );
+ aPainter.translate( QPoint( H + hBorder, wBorder ) );
+ aPainter.rotate( 90 );
+ }
+ else
+ {
+ aPrinter.setFullPage( false );
+ aPainter.begin( &aPrinter );
+ W = aPrinter.width();
+ H = aPrinter.height();
+ }
+
+ QImage anImage = theImage;
+ if ( anImage.width() > W || anImage.height() > H )
+ anImage = anImage.scaled( W, H, Qt::KeepAspectRatio, Qt::SmoothTransformation );
+
+ // place image in the center of page
+ int offsetW = ( W - anImage.width() ) / 2;
+ int offsetH = ( H - anImage.height() ) / 2;
+
+ aPainter.drawImage( offsetW, offsetH, anImage );
+
+ aPainter.end();
+}
virtual QImage dumpView();
bool dumpViewToFormat( const QString& fileName, const QString& format );
+ virtual void printImage( const QImage&, QWidget* );
bool onAccelAction( int );
void SVTK_MainWindow::onPrintView()
{
QImage img = dumpView();
- if ( img.isNull() )
- return;
-
- // stored settings for further starts
- static QString aPrinterName;
- static int anOrientation = -1;
-
- QPrinter aPrinter;
-
- // restore settinds from previous launching
-
- // printer name
- if ( !aPrinterName.isEmpty() )
- aPrinter.setPrinterName( aPrinterName );
- else
- {
- // Nothing to do for the first printing. aPrinter contains default printer name by default
- }
-
- if ( anOrientation >= 0 )
- aPrinter.setOrientation( (QPrinter::Orientation)anOrientation );
- else
- aPrinter.setOrientation( QPrinter::Landscape );
-
-
- QPrintDialog printDlg( &aPrinter, this );
- printDlg.setPrintRange( QAbstractPrintDialog::AllPages );
- if ( printDlg.exec() != QDialog::Accepted )
- return;
-
- // store printer settings for further starts
- aPrinterName = aPrinter.printerName();
- anOrientation = aPrinter.orientation();
-
- int W, H;
- QPainter aPainter;
-
- // work arround for printing on real printer
- if ( aPrinter.outputFileName().isEmpty() && aPrinter.orientation() == QPrinter::Landscape )
- {
- aPrinter.setFullPage( true );
- // set paper orientation and rotate painter
- aPrinter.setOrientation( QPrinter::Portrait );
-
- W = aPrinter.height();
- H = aPrinter.width();
-
- int wBorder = aPrinter.paperRect().height() - W;
- int hBorder = aPrinter.paperRect().width() - H;
-
- aPainter.begin( &aPrinter );
- aPainter.translate( QPoint( H + hBorder, wBorder ) );
- aPainter.rotate( 90 );
- }
- else
- {
- aPrinter.setFullPage( false );
- aPainter.begin( &aPrinter );
- W = aPrinter.width();
- H = aPrinter.height();
- }
-
- if ( img.width() > W || img.height() > H )
- img = img.scaled( W, H, Qt::KeepAspectRatio, Qt::SmoothTransformation );
-
- // place image in the center of page
- int offsetW = ( W - img.width() ) / 2;
- int offsetH = ( H - img.height() ) / 2;
-
- aPainter.drawImage( offsetW, offsetH, img );
-
- aPainter.end();
+ if ( myViewWindow )
+ myViewWindow->printImage( img, this );
}
QImage TableViewer_ViewWindow::dumpView()
{
- return QPixmap::grabWindow( table()->winId() ).toImage();
+ return QPixmap::grabWidget( table() ).toImage();
+ //return QPixmap::grabWindow( table()->winId() ).toImage();
}
void TableViewer_ViewWindow::createActions()
case PasteId:
pasteData();
break;
+ case PrintId:
+ printData();
+ break;
default:
break;
}
bool aCanPaste = true;
int aLeftCol = myTable->columnCount(), aTopRow = myTable->rowCount();
QModelIndexList::const_iterator anIt = anItems.begin(), aLast = anItems.end();
- QTableWidgetItem* anItem;
int aCol, aRow;
for ( ; anIt != aLast; ++anIt ) {
aRow = (*anIt).row();
return aCanPaste;
}
+void TableViewer_ViewWindow::printData()
+{
+ QImage img = dumpView();
+ printImage( img, this );
+}
+
void TableViewer_ViewWindow::exportTableData( Handle(HTMLService_HTMLTable)& table,
const ContentType type,
const int rowOffset, const int colOffset )
void pasteData();
bool canPasteData();
+ void printData();
+
protected:
typedef enum { VerticalHeader, HorizontalHeader, Cells } ContentType;
typedef enum { DumpId, CopyId, PasteId, PrintId, ExportId, Custom } ActionId;