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.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)
, ("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.
, ("viewer.printer.paper", TypeEnumerate ,0
, { 'values':( ("A4" , 0)
@ -54,14 +61,16 @@ parametersTable = \
layoutTable = \
( (TypeTab , 'Misc.', 'misc')
, (TypeTitle , 'Miscellaneous')
, (TypeOption, 'misc.catchCore' , 'Catch Core Dumps' , 1)
, (TypeOption, 'misc.verboseLevel1' , 'Verbose' , 0)
, (TypeOption, 'misc.verboseLevel2' , 'Very Verbose' , 0)
, (TypeOption, 'misc.info' , 'Show Info' , 0)
, (TypeOption, 'misc.logMode' , 'Output is a TTY' , 0)
, (TypeOption, 'misc.minTraceLevel' , 'Min. Trace Level' , 1)
, (TypeOption, 'misc.maxTraceLevel' , 'Max. Trace Level' , 1)
, (TypeOption, 'misc.catchCore' , 'Catch Core Dumps' , 1)
, (TypeOption, 'misc.verboseLevel1' , 'Verbose' , 0)
, (TypeOption, 'misc.verboseLevel2' , 'Very Verbose' , 0)
, (TypeOption, 'misc.info' , 'Show Info' , 0)
, (TypeOption, 'misc.logMode' , 'Output is a TTY' , 0)
, (TypeOption, 'misc.minTraceLevel' , 'Min. Trace Level' , 1)
, (TypeOption, 'misc.maxTraceLevel' , 'Max. Trace Level' , 1)
, (TypeTitle , 'Print/Snapshot Parameters')
, (TypeOption, 'viewer.printer.mode' , 'Printer/Snapshot Mode', 1)
, (TypeOption, 'viewer.printer.paper', 'Paper Size' , 0)
, (TypeOption, 'viewer.printer.mode' , 'Printer/Snapshot Mode', 1)
, (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 {
CellPrinter::CellPrinter ( QWidget* parent ) : QMainWindow (parent)
, _screenCellWidget(NULL)
, _cellWidget (NULL)
, _palette (NULL)
, _printer (NULL)
, _mode (Cfg::getParamEnumerate("viewer.printer.mode",1)->asInt())
, _paperWidth (0)
, _paperHeight (0)
, _frameMargin (50)
, _cartoucheWidth (1000)
, _cartoucheHeight (90) // 40*2
, _titleHeight (60) // 30*2
, _xpaper (0)
, _ypaper (0)
, _drawingWidth (0)
, _drawingHeight (0)
, _fitOnAbutmentBox(false)
CellPrinter::CellPrinter ( QWidget* parent )
: QMainWindow (parent)
, _screenCellWidget(NULL)
, _cellWidget (NULL)
, _palette (NULL)
, _printer (NULL)
, _dpi (Cfg::getParamInt ("viewer.printer.DPI" ,150)->asInt())
, _mode (Cfg::getParamEnumerate("viewer.printer.mode", 1)->asInt())
, _paperWidth (0)
, _paperHeight (0)
, _frameMargin (_scalePixels( 50)) // Dimensions are in pixels,
, _cartoucheWidth (_scalePixels(1000)) // computed for a reference DPI of 150.
, _cartoucheHeight (_scalePixels( 90))
, _titleHeight (_scalePixels( 60))
, _xpaper (0)
, _ypaper (0)
, _drawingWidth (0)
, _drawingHeight (0)
, _fitOnAbutmentBox(false)
{
setObjectName("viewer.printer");
setAttribute (Qt::WA_DontShowOnScreen);
@ -162,18 +164,14 @@ namespace Hurricane {
void CellPrinter::pageDecorate ( QPainter& painter )
{
_cartoucheWidth = _scalePixels( _cartoucheWidth , 600 );
_cartoucheHeight = _scalePixels( _cartoucheHeight, 600 );
_titleHeight = _scalePixels( _titleHeight , 600 );
int right = 0;
int bottom = 0;
int userFieldWidth = _scalePixels( 150 * _mode, 600 );
int dateFieldWidth = _scalePixels( 180 * _mode, 600 );
int unitFieldWidth = _scalePixels( 150 * _mode, 600 );
int areaFieldWidth = cartoucheWidth() - userFieldWidth - dateFieldWidth - unitFieldWidth;
int thinWidth = _scalePixels( 1, 600 );
int thickWidth = _scalePixels( 2, 600 );
int thinWidth = _scalePixels( 1 );
int thickWidth = _scalePixels( 2 );
int right = 0;
int bottom = 0;
int userFieldWidth = _scalePixels( 150 * _mode );
int dateFieldWidth = _scalePixels( 180 * _mode );
int unitFieldWidth = _scalePixels( 150 * _mode );
int areaFieldWidth = cartoucheWidth() - userFieldWidth - dateFieldWidth - unitFieldWidth;
QFont font ( "Bitstream Vera Sans", 18 );
font.setWeight ( QFont::Bold );
@ -290,19 +288,17 @@ namespace Hurricane {
void CellPrinter::toPdf ( QPrinter* printer, bool imageOnly )
{
int screenResolution = resolution();
//int screenResolution = resolution();
if (printer == NULL) return;
if (_cellWidget->getCell() == NULL) return;
_printer = printer;
_printer->setResolution ( 600 );
_printer->setResolution ( _dpi );
_printer->setPageMargins( 0.0, 0.0, 0.0, 0.0, QPrinter::DevicePixel );
_paperWidth = _printer->width ();
_paperHeight = _printer->height ();
//_drawingWidth = _paperWidth /4 - (frameMargin()<<1);
//_drawingHeight = _paperHeight/4 - (frameMargin()<<1);
_drawingWidth = _paperWidth - (frameMargin()<<1);
_drawingHeight = _paperHeight - (frameMargin()<<1);
_xpaper = (imageOnly) ? 0 : frameMargin();
@ -358,8 +354,8 @@ namespace Hurricane {
}
int CellPrinter::_scalePixels ( int pixels, int dpi )
{ return (int)( (float)dpi/150.0 * (float)pixels ); }
int CellPrinter::_scalePixels ( int pixels )
{ return (int)( (float)_dpi/150.0 * (float)pixels ); }
string CellPrinter::_getString () const

View File

@ -813,8 +813,9 @@ namespace Hurricane {
}
QPrinter printer ( QPrinter::ScreenResolution );
printer.setPaperSize ( (QPrinter::PaperSize)Cfg::getParamEnumerate("viewer.printer.paper",0)->asInt() );
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 );
if ( dialog.exec() == QDialog::Accepted )
@ -824,7 +825,7 @@ namespace Hurricane {
void CellViewer::print ( QPrinter* printer )
{
CellPrinter* cellPrinter = new CellPrinter();
CellPrinter* cellPrinter = new CellPrinter();
cellPrinter->setScreenCellWidget( _cellWidget );
cellPrinter->toPdf ( printer, false );

View File

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