From: ouv Date: Fri, 1 Jul 2011 09:47:15 +0000 (+0000) Subject: DIAGRAM issue 0000364: Feedback 18: A print option should be available for 2D plot... X-Git-Tag: DIAGRAM_1_0~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=80fec8a86049357395945bca6d1751e93077b4ed;p=modules%2Fgui.git DIAGRAM issue 0000364: Feedback 18: A print option should be available for 2D plot direct printing --- 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 000000000..ad057487a Binary files /dev/null and b/src/Plot2d/resources/plot2d_print.png differ