[Kst] branches/work/kst/portto4/kst

Barth Netterfield netterfield at astro.utoronto.ca
Thu Feb 4 04:04:57 CET 2010


SVN commit 1084951 by netterfield:

BUG: 216746

Add command line options for orientation and paper size.
Make orientation, paper size, and margins sticky.

Also, unrelated, make 'p' be an accelerator for pause.



 M  +5 -1      devel-docs/Kst2Specs/Wishlist  
 M  +24 -1     src/libkstapp/commandlineparser.cpp  
 M  +2 -1      src/libkstapp/commandlineparser.h  
 M  +38 -8     src/libkstapp/mainwindow.cpp  
 M  +3 -1      src/libkstapp/mainwindow.h  


--- branches/work/kst/portto4/kst/devel-docs/Kst2Specs/Wishlist #1084950:1084951
@@ -100,4 +100,8 @@
 
 5. When displaying an axis as time and offset mode is on, the offset
 steps should be natural for the type of units.  100 seconds is not
-natural (120 would be, or better, 2 minutes; see the bug above).  
\ No newline at end of file
+natural (120 would be, or better, 2 minutes; see the bug above).  
+
+-------------------
+
+in <ctrl> or <shift> zoom modes the line cursor should appear in all tied plots.
--- branches/work/kst/portto4/kst/src/libkstapp/commandlineparser.cpp #1084950:1084951
@@ -26,6 +26,7 @@
 #include "palette.h"
 #include "kst_i18n.h"
 #include "updatemanager.h"
+#include "dialogdefaults.h"
 
 namespace Kst {
 
@@ -50,7 +51,10 @@
 "OPTIONS are read and interpreted in order. Except for data object options, all are applied to all future data objects, unless later overridden.\n"
 "Output Options:\n"
 "      --print <filename>       Print to file and exit.\n"
-"      --landscape              Pring in landscape mode (default is portrait).\n"
+"      --landscape              Print in landscape mode.\n"
+"      --portrait               Print in portrait mode.\n"
+"      --Letter                 Print to Letter sized paper.\n"
+"      --A4                     Print to A4 sized paper.\n"
 "      --png <filename>         Render to a png image, and exit.\n"
 "File Options:\n"
 "      -f <startframe>          default: 'end' counts from end.\n"
@@ -346,6 +350,14 @@
   bool new_fileList=true;
   bool dataPlotted = false;
 
+  // set paper settings to match defaults.
+  _paperSize = QPrinter::PaperSize(_dialogDefaults->value("print/paperSize", QPrinter::Letter).toInt());
+  if (_dialogDefaults->value("print/landscape",true).toBool()) {
+    _landscape = true;
+  } else {
+    _landscape = false;
+  }
+
   while (*ok) {
     if (_arguments.count()<1) break;
 
@@ -553,6 +565,12 @@
       *ok = _setStringArg(_printFile, i18n("Usage: --print <filename>\n"));
     } else if (arg == "--landscape") {
       _landscape = true;
+    } else if (arg == "--portrait") {
+      _landscape = false;
+    } else if (arg == "--A4") {
+      _paperSize = QPrinter::A4;
+    } else if (arg == "--letter") {
+      _paperSize = QPrinter::Letter;
     } else { // arg is not an option... must be a file
       if (new_fileList) { // if the file list has been used, clear it.
         _fileNames.clear();
@@ -561,6 +579,11 @@
       _fileNames.append(arg);
     }
   }
+
+  // set defaults to match what has been set.
+  _dialogDefaults->setValue("print/landscape", _landscape);
+  _dialogDefaults->setValue("print/paperSize", int(_paperSize));
+
   if (_plotItem) {
     _plotItem->parentView()->resetPlotFontSizes();
   }
--- branches/work/kst/portto4/kst/src/libkstapp/commandlineparser.h #1084950:1084951
@@ -30,7 +30,7 @@
   QString kstFileName();
   QString pngFile() const {return _pngFile;}
   QString printFile() const {return _printFile;}
-  bool landscape() const {return _landscape;}
+  //bool landscape() const {return _landscape;}
 private:
   bool _doAve;
   bool _doSkip;
@@ -50,6 +50,7 @@
   QString _pngFile;
   QString _printFile;
   bool _landscape;
+  QPrinter::PaperSize _paperSize;
 
   QStringList _fileNames;
   QStringList _arguments;
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #1084950:1084951
@@ -49,6 +49,7 @@
 #include "aboutdialog.h"
 #include "datavector.h"
 #include "commandlineparser.h"
+#include "dialogdefaults.h"
 
 #include "dialoglauncher.h"
 
@@ -254,7 +255,7 @@
     ok = false;
   }
   if (!P.printFile().isEmpty()) {
-    printFromCommandLine(P.printFile(), P.landscape());
+    printFromCommandLine(P.printFile());
     ok = false;
   }
   if (!P.kstFileName().isEmpty()) {
@@ -378,34 +379,62 @@
   }
 }
 
-void MainWindow::printFromCommandLine(const QString &printFileName, bool landscape) {
+void MainWindow::printFromCommandLine(const QString &printFileName) {
   QPrinter printer(QPrinter::ScreenResolution);
   printer.setOutputFileName(printFileName);
-  if (landscape) {
-    printer.setOrientation(QPrinter::Landscape);
-  } else {
-    printer.setOrientation(QPrinter::Portrait);
-  }
+  setPrinterDefaults(&printer);
 
   printer.setPrintRange(QPrinter::AllPages);
   printToPrinter(&printer);
 }
 
+void MainWindow::setPrinterDefaults(QPrinter *printer) {
+  if (_dialogDefaults->value("print/landscape",true).toBool()) {
+    printer->setOrientation(QPrinter::Landscape);
+  } else {
+    printer->setOrientation(QPrinter::Portrait);
+  }
+
+  printer->setPaperSize(QPrinter::PaperSize(_dialogDefaults->value("print/paperSize", QPrinter::Letter).toInt()));
+
+  QPointF topLeft =_dialogDefaults->value("print/topLeftMargin", QPointF(15.0,15.0)).toPointF();
+  QPointF bottomRight =_dialogDefaults->value("print/bottomRightMargin", QPointF(15.0,15.0)).toPointF();
+
+  printer->setPageMargins(topLeft.x(), topLeft.y(), bottomRight.x(), bottomRight.y(), QPrinter::Millimeter);
+  // Apparent Qt bug: setting the page margins here doesn't set the correspoding values in the print
+  // dialog->printer-options sub-dialog under linux.  If you don't open the printer-options sub-dialog,
+  // the values here are honored.
+}
+
+void MainWindow::savePrinterDefaults(QPrinter *printer) {
+  _dialogDefaults->setValue("print/landscape", printer->orientation() == QPrinter::Landscape);
+  _dialogDefaults->setValue("print/paperSize", int(printer->paperSize()));
+
+  double left, top, right, bottom;
+  printer->getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);
+  _dialogDefaults->setValue("print/topLeftMargin", QPointF(left, top));
+  _dialogDefaults->setValue("print/bottomRightMargin", QPointF(right, bottom));
+
+}
+
 void MainWindow::print() {
   // line widths in pixels make sense when using ScreenResolution
   // FIXME: come up with a better definition of line width!
   QPrinter printer(QPrinter::ScreenResolution);
   //QPrinter printer(QPrinter::HighResolution);
 
+  setPrinterDefaults(&printer);
+
   QPrintDialog pd(&printer, this);
   pd.setOption(QPrintDialog::PrintToFile);
   pd.setOption(QPrintDialog::PrintPageRange, true);
+  pd.setOption(QAbstractPrintDialog::PrintShowPageSize,true);
 
   if (pd.exec() == QDialog::Accepted) {
-
     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
     printToPrinter(&printer);
     QApplication::restoreOverrideCursor();
+    savePrinterDefaults(&printer);
   }
 }
 
@@ -816,6 +845,7 @@
   _pauseAct->setStatusTip(tr("Toggle pause updates of data sources"));
   _pauseAct->setIcon(QPixmap(":kst_pause.png"));
   _pauseAct->setCheckable(true);
+  _pauseAct->setShortcut(QString("p"));
   connect(_pauseAct, SIGNAL(toggled(bool)), this, SLOT(pause(bool)));
 
   _backAct = new QAction(tr("Back One Screen..."), this);
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.h #1084950:1084951
@@ -82,8 +82,10 @@
     void newDoc();
     void openFile(const QString &file);
     void print();
+    void setPrinterDefaults(QPrinter *printer);
+    void savePrinterDefaults(QPrinter *printer);
     void printToPrinter(QPrinter *printer);
-    void printFromCommandLine(const QString &printFileName, bool landscape);
+    void printFromCommandLine(const QString &printFileName);
     void exportGraphicsFile(const QString &filename, const QString &format, int w, int h, int display);
 
     void clearDrawingMarker();


More information about the Kst mailing list