Debian Codegraph @

HercPrinter/PrinterInterface.cpp

raw symbols SCIP
1 #include "PrinterInterface.h"
2 #include "Environment.h"
3 #include "HerculesStudio.h"
4
5 #include <QHostAddress>
6 #include <QTcpSocket>
7 #include <QPainter> //TODO move to PagePrinter
8
9 BasicPrinter::BasicPrinter()
10 {
11 }
12
13
14 GenericPagePrinter::GenericPagePrinter(StationeryPtr &stationery, float scaling) :
15 mStationery(stationery), mPen(NULL), mLogo(QPixmap(2200,1200)), mLogoWidth(0), mScaling(scaling)
16 {
17 mDecolation.clear();
18 mHeightInPixels = 4000;
19 mWidthInPixels = 1200;
20 mLeftMargin = 0;
21 mLogicalDpiX = mLogicalDpiY = 1200;
22 }
23
24 void GenericPagePrinter::preparePage(bool eject)
25 {
26 int builtinMargin = 250;
27 const int penWidth = 20;
28 const int alternatingStripes = 20;
29
30 setValues(eject);
31
32 mPen->fillRect(0, 0, mWidthInPixels, mHeightInPixels-mLeftMargin, QColor(0xff, 0xff, 0xff));
33
34 if (eject) mEndJobTrigger.clear();
35 if (!mDecolation.isNull())
36 {
37 for (int i=0; i<mDecolation->mSeperator.mTriggers.count(); i++)
38 {
39 Trigger t = mDecolation->mSeperator.mTriggers[i];
40 mEndJobTrigger.insert(t.line(), t);
41 }
42 }
43
44 hOutDebug(1, "in pixels: " <<mWidthInPixels << " " << mHeightInPixels);
45 hOutDebug(1, "left margin " << mLeftMargin);
46
47 int stripe = (mHeightInPixels-(mMargin+mBottomMargin))/alternatingStripes*mScaling;
48
49 if (mHeightInPixels > 0)
50 {
51 for (int i=mMargin+stripe; i<=mMargin+(alternatingStripes)*stripe; i+=2*stripe)
52 {
53 int barsR = mBarsColor[0];
54 int barsG = mBarsColor[1];
55 int barsB = mBarsColor[2];
56 mPen->fillRect(mLeftMargin, i, mWidthInPixels-2*mLeftMargin, stripe, QColor(barsR, barsG, barsB));
57
58 // if (mStationery->mDecorated)
59 // {
60 // mPen->setPen(QPen(QColor(barsR-0x20, barsG-0x20, barsB-0x20), penWidth));
61 // mPen->drawLine(leftMargin,i,widthInPixels-leftMargin,i);
62 // mPen->drawLine(leftMargin,i+stripe,widthInPixels-leftMargin,i+stripe);
63 // }
64 }
65 }
66
67 if (mStationery->mDecorated)
68 {
69 int barsR = mBarsColor[0];
70 int barsG = mBarsColor[1];
71 int barsB = mBarsColor[2];
72 mPen->setPen(QPen(QColor(barsR, barsG, barsB), penWidth*(mScaling==1.0 ? 1.0 : 0.1)));
73 mPen->drawRect(mLeftMargin, mMargin, mWidthInPixels-2*mLeftMargin, stripe*(alternatingStripes));//heightInPixels-leftMargin);
74 }
75
76 if (mStationery->mTractorFeedHoles)
77 {
78 QString pixmapStr(Environment::getIconsPath().c_str());
79 pixmapStr +="/Hole.png";
80 QPixmap pixmap(pixmapStr);
81 hOutDebug(5, "hole width " << pixmap.width() << " " << pixmap.logicalDpiX() << " " << pixmap.physicalDpiX());
82 float gap = mLogicalDpiY/2;
83 float holeStart = mLogicalDpiY/4 - builtinMargin;
84 if (mScaling < 1)
85 {
86 gap = 40;
87 holeStart = 20;
88 }
89
90 for (int holePos=holeStart; holePos <= mHeightInPixels; holePos += gap) // image is 200 pixels
91 {
92 //TODO: automatic scaling?
93 if (mScaling < 1.0)
94 {
95 mPen->drawPixmap(50*mScaling, holePos, 15, 15, pixmap, 0,0,200,200);
96 }
97 else
98 {
99 mPen->drawPixmap(160, holePos, pixmap);
100 mPen->drawPixmap(mWidthInPixels-160-200, holePos, pixmap);
101 }
102 }
103 }
104 //mPen->drawRect(0,0,mWidthInPixels, mHeightInPixels); //debug
105
106 if (mLogoWidth == 0)
107 {
108 mLogo.fill(QColor(255,255,255,255));
109 QPainter * logoPainter = new QPainter(&mLogo);
110
111 const char * logo{"Printed With Hercules Studio"};
112 logoPainter->setFont(QFont("Verdana", 110));
113 logoPainter->setPen(QColor(mBarsColor[0], mBarsColor[1], mBarsColor[2]));
114 logoPainter->drawText(0, logoPainter->fontMetrics().height() , logo);
115 mLogoWidth = logoPainter->fontMetrics().width(logo);
116 mLogoHeight = logoPainter->fontMetrics().height();
117 logoPainter->end();
118 }
119 mPen->drawPixmap(mWidthInPixels-mLeftMargin-mLogoWidth, mHeightInPixels - mLogoHeight, mLogo);
120 }
121
122