From 80fec8a86049357395945bca6d1751e93077b4ed Mon Sep 17 00:00:00 2001 From: ouv Date: Fri, 1 Jul 2011 09:47:15 +0000 Subject: [PATCH] DIAGRAM issue 0000364: Feedback 18: A print option should be available for 2D plot direct printing --- src/Plot2d/Plot2d_ViewFrame.cxx | 24 ++++++++++++++++++++++++ src/Plot2d/Plot2d_ViewFrame.h | 5 +++-- src/Plot2d/Plot2d_ViewWindow.cxx | 22 +++++++++++++++++++++- src/Plot2d/Plot2d_ViewWindow.h | 3 ++- src/Plot2d/resources/Plot2d_images.ts | 4 ++++ src/Plot2d/resources/Plot2d_msg_en.ts | 8 ++++++++ src/Plot2d/resources/plot2d_print.png | Bin 0 -> 1116 bytes 7 files changed, 62 insertions(+), 4 deletions(-) create mode 100755 src/Plot2d/resources/plot2d_print.png diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index 70d52624e..85ffb2ca0 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -2294,6 +2295,29 @@ void Plot2d_ViewFrame::updateTitles() */ bool Plot2d_ViewFrame::print( const QString& file, const QString& format ) const { + // if the method is called with default (empty) arguments, + // send contents of the plot directly to printer + if( file.isEmpty() && format.isEmpty() ) + { + SUIT_Application* anApp = SUIT_Session::session()->activeApplication(); + + QPrinter aPrinter( QPrinter::HighResolution ); + aPrinter.setPageSize( QPrinter::A4 ); + + if( anApp ) + aPrinter.setPrinterName( anApp->getLastUsedPrinter() ); + + QPrintDialog aDlg( &aPrinter ); + int aStatus = aDlg.exec(); + if( aStatus ) + myPlot->print( aPrinter ); + + if( anApp ) + anApp->setLastUsedPrinter( aPrinter.printerName() ); + + return aStatus; + } + #ifdef WIN32 return false; diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index 3f53a46bd..9678b57c8 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -41,7 +41,7 @@ class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget { Q_OBJECT - enum { NoOpId, FitAreaId, ZoomId, PanId, GlPanId, DumpId, + enum { NoOpId, FitAreaId, ZoomId, PanId, GlPanId, DumpId, PrintId, ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId, LegendId, CurvePointsId, CurveLinesId, CurveSplinesId }; public: @@ -129,7 +129,8 @@ public: bool isXLogEnabled() const; bool isYLogEnabled() const; - virtual bool print( const QString& file, const QString& format ) const; + virtual bool print( const QString& file = QString::null, + const QString& format = QString::null ) const; QString getVisualParameters(); void setVisualParameters( const QString& parameters ); diff --git a/src/Plot2d/Plot2d_ViewWindow.cxx b/src/Plot2d/Plot2d_ViewWindow.cxx index 1a29b99cb..fa4906c7a 100755 --- a/src/Plot2d/Plot2d_ViewWindow.cxx +++ b/src/Plot2d/Plot2d_ViewWindow.cxx @@ -183,7 +183,9 @@ void Plot2d_ViewWindow::createActions() QtxAction* aAction; SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - // 1. Dump View + // 1. Dump and Print + + // 1.1. Dump View aAction = new QtxAction( tr( "MNU_DUMP_VIEW" ), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_DUMP" ) ), tr( "MNU_DUMP_VIEW" ), @@ -192,6 +194,15 @@ void Plot2d_ViewWindow::createActions() connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onDumpView() ) ); mgr->registerAction( aAction, DumpId ); + // 1.2. Print View + aAction = new QtxAction( tr( "MNU_PRINT_VIEW" ), + aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_PRINT" ) ), + tr( "MNU_PRINT_VIEW" ), + 0, this); + aAction->setStatusTip( tr( "DSC_PRINT_VIEW" ) ); + connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onPrintView() ) ); + mgr->registerAction( aAction, PrintId ); + // 2. Scaling operations // 2.1. Fit All @@ -395,6 +406,7 @@ void Plot2d_ViewWindow::createToolBar() QtxActionToolMgr* mgr = toolMgr(); myToolBar = mgr->createToolBar( tr( "LBL_TOOLBAR_LABEL" ) ); mgr->append( DumpId, myToolBar ); + mgr->append( PrintId, myToolBar ); mgr->append( ScaleOpId, myToolBar ); mgr->append( MoveOpId, myToolBar ); mgr->append( toolMgr()->separator(), myToolBar ); @@ -588,6 +600,14 @@ void Plot2d_ViewWindow::onDumpView() SUIT_ViewWindow::onDumpView(); } +/*! + \brief Called when the "Print view" action is activated. +*/ +void Plot2d_ViewWindow::onPrintView() +{ + myViewFrame->print(); +} + /*! \brief Dump the contents of the view window to the image. \return image, containing all scene rendered in the window diff --git a/src/Plot2d/Plot2d_ViewWindow.h b/src/Plot2d/Plot2d_ViewWindow.h index 3de5066f9..b0a1f0835 100755 --- a/src/Plot2d/Plot2d_ViewWindow.h +++ b/src/Plot2d/Plot2d_ViewWindow.h @@ -44,7 +44,7 @@ class PLOT2D_EXPORT Plot2d_ViewWindow : public SUIT_ViewWindow Q_OBJECT public: - enum { DumpId, + enum { DumpId, PrintId, ScaleOpId, FitAllId, FitRectId, ZoomId, MoveOpId, PanId, GlobalPanId, PModeXLinearId, PModeXLogarithmicId, @@ -91,6 +91,7 @@ public slots: void onCurves(); void onDumpView(); + void onPrintView(); protected: virtual QImage dumpView(); diff --git a/src/Plot2d/resources/Plot2d_images.ts b/src/Plot2d/resources/Plot2d_images.ts index 58cf8b952..23101633b 100644 --- a/src/Plot2d/resources/Plot2d_images.ts +++ b/src/Plot2d/resources/Plot2d_images.ts @@ -21,6 +21,10 @@ ICON_PLOT2D_DUMP plot2d_camera_dump.png + + ICON_PLOT2D_PRINT + plot2d_print.png + ICON_PLOT2D_ZOOM plot2d_zoom.png diff --git a/src/Plot2d/resources/Plot2d_msg_en.ts b/src/Plot2d/resources/Plot2d_msg_en.ts index dd862f3d8..d9dcdd395 100644 --- a/src/Plot2d/resources/Plot2d_msg_en.ts +++ b/src/Plot2d/resources/Plot2d_msg_en.ts @@ -21,6 +21,10 @@ MNU_DUMP_VIEW Dump view... + + MNU_PRINT_VIEW + Print view... + PLOT2D_SCALE_MODE_HOR Horizontal axis: @@ -319,6 +323,10 @@ Logarithmic scale for ordinate axis is not allowed. DSC_DUMP_VIEW Saves the active view in the image file + + DSC_PRINT_VIEW + Print the active view + WARNING Warning diff --git a/src/Plot2d/resources/plot2d_print.png b/src/Plot2d/resources/plot2d_print.png new file mode 100755 index 0000000000000000000000000000000000000000..ad057487adbe10043a90503afa0883614fb50dd6 GIT binary patch literal 1116 zcmV-i1f%OV8FWQhbW?9;ba!ELWdL_~cP?peYja~^aAhuUa%Y?FJQ@H11L;Xb zK~#9!g;ZNeTWJtJ>cb)!>9VV>i7)%I&_`Jp1feOi`r-`|SXh(=Wf3nM6|vTPyxL1;GeQ9!f!pm6d9B<0aKZqiM2@H74d_+jS*POg!hGorxl8ReH$B|DTy}Cf}Kv z|L0m-TDWi&6%|E&Zo3UPaj%h5Q&aD@wzf_W4-Y>Z92|T)G&J-q9AqOOafo|s!ltIC zh|7fEIUEiizVJAmPM)~ou{SDAPEP(-tJS)L!QlDX*;xRe^Kkh6{s8$lHgs;{-m0*< zxjCw{voj(;KmX^gErSn(c!a+0(Mc>eq^ zX0f~pTCE4*a5%x`@_^fYjCFH^&1Q$UZx4enUMw@>c6WEjV|)VQE+Uevs;c^>v9ZzD z+uO^Jj*gxy6u%29)t|7wzR6H2Ga60s`t?6xHopOr$pQw$F4OCcOs#$jm6esk^z`)k zz`#HNlk@fU_4l~q;^JS+%gcqnzCJ)FD=RC52M?r>lam9PnOTsPm3@WmY+AD*H#Zlg zQYlnaRKU#448w8aXQ zL)^=UM=^l8BwTxYd%@b;8ap~V!os^*M@I*wq@+MbMh2v(r$cFJDPWyLpgq~hM;zk1 zTrP%jyiTVB9B?t$-``)jva$kty&g6K)!CkXdhtyXN30p{oD`NhRW zKyeZd2eZ&A+FhMW=l&;L2QtKvn=Ks z8XA7Xae>*{Sy)|NMcHle@L?KkY#89>%T>_n^su$HgC#Mdl5NmxH}Es}AT8}DKrx{h zjYb1%wVG-up*a*uB$E5l(a}F9B_$Q%vwZiLp||57@YQnTd&sa