]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
DIAGRAM issue 0000364: Feedback 18: A print option should be available for 2D plot...
authorouv <ouv@opencascade.com>
Fri, 1 Jul 2011 09:47:15 +0000 (09:47 +0000)
committerouv <ouv@opencascade.com>
Fri, 1 Jul 2011 09:47:15 +0000 (09:47 +0000)
src/Plot2d/Plot2d_ViewFrame.cxx
src/Plot2d/Plot2d_ViewFrame.h
src/Plot2d/Plot2d_ViewWindow.cxx
src/Plot2d/Plot2d_ViewWindow.h
src/Plot2d/resources/Plot2d_images.ts
src/Plot2d/resources/Plot2d_msg_en.ts
src/Plot2d/resources/plot2d_print.png [new file with mode: 0755]

index 70d52624e1ce9d6401b3b085a938862509178752..85ffb2ca07f0c63647911a330dd2181b49cc0936 100755 (executable)
@@ -45,6 +45,7 @@
 #include <QMouseEvent>
 #include <QContextMenuEvent>
 #include <QPrinter>
+#include <QPrintDialog>
 #include <QPalette>
 
 #include <qwt_math.h>
@@ -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;
 
index 3f53a46bd00380c412c3d1601d25137f7c08df07..9678b57c87b3a26e2c8d0d8be4f933189ceb31db 100755 (executable)
@@ -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 );
index 1a29b99cbf5c95c8c999284524e819b290529465..fa4906c7a862052e8b82ce769b6857e2599cea24 100755 (executable)
@@ -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
index 3de5066f9508a3bfe07809eee3ab6b28eb2c0375..b0a1f08351bf2ceda21e949338c60d262f0a1e3e 100755 (executable)
@@ -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();
index 58cf8b95279e4d0a3c5f7224bff3f3199144ee1a..23101633b216ed4af1e7ced16d254aa575af960a 100644 (file)
         <source>ICON_PLOT2D_DUMP</source>
         <translation>plot2d_camera_dump.png</translation>
     </message>
+    <message>
+        <source>ICON_PLOT2D_PRINT</source>
+        <translation>plot2d_print.png</translation>
+    </message>
     <message>
         <source>ICON_PLOT2D_ZOOM</source>
         <translation>plot2d_zoom.png</translation>
index dd862f3d8950c9e0236c582a1d27b52e50e6c3d1..d9dcdd39510d341cee3df8d655817a89afb36998 100644 (file)
         <source>MNU_DUMP_VIEW</source>
         <translation>Dump view...</translation>
     </message>
+    <message>
+        <source>MNU_PRINT_VIEW</source>
+        <translation>Print view...</translation>
+    </message>
     <message>
         <source>PLOT2D_SCALE_MODE_HOR</source>
         <translation>Horizontal axis:</translation>
@@ -319,6 +323,10 @@ Logarithmic scale for ordinate axis is not allowed.</translation>
         <source>DSC_DUMP_VIEW</source>
         <translation>Saves the active view in the image file</translation>
     </message>
+    <message>
+        <source>DSC_PRINT_VIEW</source>
+        <translation>Print the active view</translation>
+    </message>
     <message>
         <source>WARNING</source>
         <translation>Warning</translation>
diff --git a/src/Plot2d/resources/plot2d_print.png b/src/Plot2d/resources/plot2d_print.png
new file mode 100755 (executable)
index 0000000..ad05748
Binary files /dev/null and b/src/Plot2d/resources/plot2d_print.png differ