In CellPrinter, adds the DPI and the Orientation as config. parameters.

This commit is contained in:
Jean-Paul Chaput 2017-03-15 17:59:00 +01:00
parent 210f307270
commit 880b1817ce
4 changed files with 55 additions and 48 deletions

View File

@ -10,11 +10,18 @@ parametersTable = \
, ('misc.minTraceLevel', TypeInt , 0, {'min':0} ) , ('misc.minTraceLevel', TypeInt , 0, {'min':0} )
, ('misc.maxTraceLevel', TypeInt , 0, {'min':0} ) , ('misc.maxTraceLevel', TypeInt , 0, {'min':0} )
, ("viewer.printer.mode", TypeEnumerate ,1 , ('viewer.printer.DPI' , TypeInt , 150, {'min':100} )
, ("viewer.printer.mode", TypeEnumerate , 1
, { 'values':( ("Cell Mode" , 1) , { 'values':( ("Cell Mode" , 1)
, ("Design Mode", 2) ) } , ("Design Mode", 2) ) }
) )
# Those enumerated values *must* match QPrinter::Orientation.
, ("viewer.printer.orientation", TypeEnumerate , 0
, { 'values':( ("Portrait" , 0)
, ("Landscape" , 1) ) }
)
# Those enumerated values *must* match QPrinter::PaperSize. # Those enumerated values *must* match QPrinter::PaperSize.
, ("viewer.printer.paper", TypeEnumerate ,0 , ("viewer.printer.paper", TypeEnumerate ,0
, { 'values':( ("A4" , 0) , { 'values':( ("A4" , 0)
@ -54,14 +61,16 @@ parametersTable = \
layoutTable = \ layoutTable = \
( (TypeTab , 'Misc.', 'misc') ( (TypeTab , 'Misc.', 'misc')
, (TypeTitle , 'Miscellaneous') , (TypeTitle , 'Miscellaneous')
, (TypeOption, 'misc.catchCore' , 'Catch Core Dumps' , 1) , (TypeOption, 'misc.catchCore' , 'Catch Core Dumps' , 1)
, (TypeOption, 'misc.verboseLevel1' , 'Verbose' , 0) , (TypeOption, 'misc.verboseLevel1' , 'Verbose' , 0)
, (TypeOption, 'misc.verboseLevel2' , 'Very Verbose' , 0) , (TypeOption, 'misc.verboseLevel2' , 'Very Verbose' , 0)
, (TypeOption, 'misc.info' , 'Show Info' , 0) , (TypeOption, 'misc.info' , 'Show Info' , 0)
, (TypeOption, 'misc.logMode' , 'Output is a TTY' , 0) , (TypeOption, 'misc.logMode' , 'Output is a TTY' , 0)
, (TypeOption, 'misc.minTraceLevel' , 'Min. Trace Level' , 1) , (TypeOption, 'misc.minTraceLevel' , 'Min. Trace Level' , 1)
, (TypeOption, 'misc.maxTraceLevel' , 'Max. Trace Level' , 1) , (TypeOption, 'misc.maxTraceLevel' , 'Max. Trace Level' , 1)
, (TypeTitle , 'Print/Snapshot Parameters') , (TypeTitle , 'Print/Snapshot Parameters')
, (TypeOption, 'viewer.printer.mode' , 'Printer/Snapshot Mode', 1) , (TypeOption, 'viewer.printer.mode' , 'Printer/Snapshot Mode', 1)
, (TypeOption, 'viewer.printer.paper', 'Paper Size' , 0) , (TypeOption, 'viewer.printer.paper' , 'Paper Size' , 0)
, (TypeOption, 'viewer.printer.orientation', 'Orientation' , 0)
, (TypeOption, 'viewer.printer.DPI' , 'DPI' , 0)
) )

View File

@ -31,23 +31,25 @@
namespace Hurricane { namespace Hurricane {
CellPrinter::CellPrinter ( QWidget* parent ) : QMainWindow (parent) CellPrinter::CellPrinter ( QWidget* parent )
, _screenCellWidget(NULL) : QMainWindow (parent)
, _cellWidget (NULL) , _screenCellWidget(NULL)
, _palette (NULL) , _cellWidget (NULL)
, _printer (NULL) , _palette (NULL)
, _mode (Cfg::getParamEnumerate("viewer.printer.mode",1)->asInt()) , _printer (NULL)
, _paperWidth (0) , _dpi (Cfg::getParamInt ("viewer.printer.DPI" ,150)->asInt())
, _paperHeight (0) , _mode (Cfg::getParamEnumerate("viewer.printer.mode", 1)->asInt())
, _frameMargin (50) , _paperWidth (0)
, _cartoucheWidth (1000) , _paperHeight (0)
, _cartoucheHeight (90) // 40*2 , _frameMargin (_scalePixels( 50)) // Dimensions are in pixels,
, _titleHeight (60) // 30*2 , _cartoucheWidth (_scalePixels(1000)) // computed for a reference DPI of 150.
, _xpaper (0) , _cartoucheHeight (_scalePixels( 90))
, _ypaper (0) , _titleHeight (_scalePixels( 60))
, _drawingWidth (0) , _xpaper (0)
, _drawingHeight (0) , _ypaper (0)
, _fitOnAbutmentBox(false) , _drawingWidth (0)
, _drawingHeight (0)
, _fitOnAbutmentBox(false)
{ {
setObjectName("viewer.printer"); setObjectName("viewer.printer");
setAttribute (Qt::WA_DontShowOnScreen); setAttribute (Qt::WA_DontShowOnScreen);
@ -162,18 +164,14 @@ namespace Hurricane {
void CellPrinter::pageDecorate ( QPainter& painter ) void CellPrinter::pageDecorate ( QPainter& painter )
{ {
_cartoucheWidth = _scalePixels( _cartoucheWidth , 600 ); int thinWidth = _scalePixels( 1 );
_cartoucheHeight = _scalePixels( _cartoucheHeight, 600 ); int thickWidth = _scalePixels( 2 );
_titleHeight = _scalePixels( _titleHeight , 600 ); int right = 0;
int bottom = 0;
int right = 0; int userFieldWidth = _scalePixels( 150 * _mode );
int bottom = 0; int dateFieldWidth = _scalePixels( 180 * _mode );
int userFieldWidth = _scalePixels( 150 * _mode, 600 ); int unitFieldWidth = _scalePixels( 150 * _mode );
int dateFieldWidth = _scalePixels( 180 * _mode, 600 ); int areaFieldWidth = cartoucheWidth() - userFieldWidth - dateFieldWidth - unitFieldWidth;
int unitFieldWidth = _scalePixels( 150 * _mode, 600 );
int areaFieldWidth = cartoucheWidth() - userFieldWidth - dateFieldWidth - unitFieldWidth;
int thinWidth = _scalePixels( 1, 600 );
int thickWidth = _scalePixels( 2, 600 );
QFont font ( "Bitstream Vera Sans", 18 ); QFont font ( "Bitstream Vera Sans", 18 );
font.setWeight ( QFont::Bold ); font.setWeight ( QFont::Bold );
@ -290,19 +288,17 @@ namespace Hurricane {
void CellPrinter::toPdf ( QPrinter* printer, bool imageOnly ) void CellPrinter::toPdf ( QPrinter* printer, bool imageOnly )
{ {
int screenResolution = resolution(); //int screenResolution = resolution();
if (printer == NULL) return; if (printer == NULL) return;
if (_cellWidget->getCell() == NULL) return; if (_cellWidget->getCell() == NULL) return;
_printer = printer; _printer = printer;
_printer->setResolution ( 600 ); _printer->setResolution ( _dpi );
_printer->setPageMargins( 0.0, 0.0, 0.0, 0.0, QPrinter::DevicePixel ); _printer->setPageMargins( 0.0, 0.0, 0.0, 0.0, QPrinter::DevicePixel );
_paperWidth = _printer->width (); _paperWidth = _printer->width ();
_paperHeight = _printer->height (); _paperHeight = _printer->height ();
//_drawingWidth = _paperWidth /4 - (frameMargin()<<1);
//_drawingHeight = _paperHeight/4 - (frameMargin()<<1);
_drawingWidth = _paperWidth - (frameMargin()<<1); _drawingWidth = _paperWidth - (frameMargin()<<1);
_drawingHeight = _paperHeight - (frameMargin()<<1); _drawingHeight = _paperHeight - (frameMargin()<<1);
_xpaper = (imageOnly) ? 0 : frameMargin(); _xpaper = (imageOnly) ? 0 : frameMargin();
@ -358,8 +354,8 @@ namespace Hurricane {
} }
int CellPrinter::_scalePixels ( int pixels, int dpi ) int CellPrinter::_scalePixels ( int pixels )
{ return (int)( (float)dpi/150.0 * (float)pixels ); } { return (int)( (float)_dpi/150.0 * (float)pixels ); }
string CellPrinter::_getString () const string CellPrinter::_getString () const

View File

@ -813,8 +813,9 @@ namespace Hurricane {
} }
QPrinter printer ( QPrinter::ScreenResolution ); QPrinter printer ( QPrinter::ScreenResolution );
printer.setPaperSize ( (QPrinter::PaperSize)Cfg::getParamEnumerate("viewer.printer.paper",0)->asInt() );
printer.setOutputFileName ( "unicorn-snapshot.pdf" ); printer.setOutputFileName ( "unicorn-snapshot.pdf" );
printer.setPaperSize ( (QPrinter::PaperSize )Cfg::getParamEnumerate("viewer.printer.paper" ,0)->asInt() );
printer.setOrientation( (QPrinter::Orientation)Cfg::getParamEnumerate("viewer.printer.orientation",0)->asInt() );
QPrintDialog dialog ( &printer ); QPrintDialog dialog ( &printer );
if ( dialog.exec() == QDialog::Accepted ) if ( dialog.exec() == QDialog::Accepted )
@ -824,7 +825,7 @@ namespace Hurricane {
void CellViewer::print ( QPrinter* printer ) void CellViewer::print ( QPrinter* printer )
{ {
CellPrinter* cellPrinter = new CellPrinter(); CellPrinter* cellPrinter = new CellPrinter();
cellPrinter->setScreenCellWidget( _cellWidget ); cellPrinter->setScreenCellWidget( _cellWidget );
cellPrinter->toPdf ( printer, false ); cellPrinter->toPdf ( printer, false );

View File

@ -71,13 +71,14 @@ namespace Hurricane {
void toPdf ( QPrinter* , bool imageOnly=false ); void toPdf ( QPrinter* , bool imageOnly=false );
virtual std::string _getString () const; virtual std::string _getString () const;
private: private:
int _scalePixels ( int pixels, int dpi ); int _scalePixels ( int pixels );
protected: protected:
CellWidget* _screenCellWidget; CellWidget* _screenCellWidget;
CellWidget* _cellWidget; CellWidget* _cellWidget;
PaletteWidget* _palette; PaletteWidget* _palette;
QPrinter* _printer; QPrinter* _printer;
int _dpi;
int _mode; int _mode;
int _paperWidth; int _paperWidth;
int _paperHeight; int _paperHeight;