-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11e84ab
commit 9d02ba0
Showing
13 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include "pngqtpaint.h" | ||
#include "qcolor.h" | ||
#include "qnamespace.h" | ||
#include "qpixmap.h" | ||
|
||
#include <QFile> | ||
|
||
PngQtPaint::PngQtPaint() : QtPainterDrawer() { } | ||
|
||
// void PngQtPaint::drawText(QPointF position, QString text, double textSize, | ||
// TextHeightAnchor textHeightAnchor, TextWidthAnchor textWidthAnchor, | ||
// double lineWidth, QString font, QString name, bool isEditable) | ||
// { | ||
// if (isEditable && !this->showEditable()) { | ||
// return; | ||
// } | ||
|
||
// QFont qFont(font); | ||
// QFont qFontA(font); | ||
// qFont.setPointSizeF(((textSize * std::sqrt(2)) / m_resolutionPMM) | ||
// * 2.8346456692913); // 18897.6378 | ||
// qFontA.setPointSizeF(100); | ||
// double posX = position.x(); | ||
// double posY = position.y(); | ||
// QFontMetrics fm(qFontA); | ||
|
||
// if (textWidthAnchor == TextWidthAnchor::Left) { | ||
// } else if (textWidthAnchor == TextWidthAnchor::Center) { | ||
// posX -= (textSize * (fm.size(Qt::TextDontPrint, text).width() / double(100))) / 2; | ||
// } else if (textWidthAnchor == TextWidthAnchor::Right) { | ||
// posX -= (textSize * (fm.size(Qt::TextDontPrint, text).width() / double(100))); | ||
// } | ||
|
||
// if (textHeightAnchor == TextHeightAnchor::Top) { | ||
// posY += textSize; | ||
// } else if (textHeightAnchor == TextHeightAnchor::Middle) { | ||
// posY += (textSize / 2); | ||
// } else if (textHeightAnchor == TextHeightAnchor::Bottom) { | ||
// } | ||
|
||
// QPen pen(Qt::black); | ||
// if (editableBlue() && isEditable) { | ||
// pen = QPen(Qt::blue); | ||
// } | ||
|
||
// pen.setStyle(Qt::SolidLine); | ||
// pen.setWidthF(lineWidth); | ||
// painter()->setPen(pen); | ||
// painter()->setBrush(Qt::NoBrush); | ||
|
||
// painter()->setFont(qFont); | ||
// painter()->drawText(QPointF(posX, posY), text); | ||
// } | ||
|
||
bool PngQtPaint::start() | ||
{ | ||
m_image = std::shared_ptr<QImage>(new QImage((int)(this->width() * m_resolutionPMM), | ||
(int)(this->height() * m_resolutionPMM), | ||
QImage::Format_ARGB32)); | ||
this->setPainter(std::shared_ptr<QPainter>(new QPainter(m_image.get()))); | ||
this->painter()->setTransform(QTransform().scale(m_resolutionPMM, m_resolutionPMM)); | ||
return true; | ||
} | ||
|
||
bool PngQtPaint::end() | ||
{ | ||
// this->painter()->drawPixmap(10, 130, 50, 50, pixmap); | ||
this->painter()->end(); | ||
m_image->save(this->fileName()); | ||
return true; | ||
} | ||
|
||
int PngQtPaint::resolutionDPI() const | ||
{ | ||
return m_resolutionDPI; | ||
} | ||
|
||
void PngQtPaint::setResolutionDPI(int newResolutionDPI) | ||
{ | ||
m_resolutionDPI = newResolutionDPI; | ||
m_resolutionPMM = m_resolutionDPI * (1 / 25.4); | ||
} | ||
|
||
double PngQtPaint::resolutionPMM() const | ||
{ | ||
return m_resolutionPMM; | ||
} | ||
|
||
void PngQtPaint::setResolutionPMM(double newResolutionPMM) | ||
{ | ||
m_resolutionPMM = newResolutionPMM; | ||
m_resolutionDPI = int(m_resolutionPMM * 25.4); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#ifndef PNGQTPAINT_H | ||
#define PNGQTPAINT_H | ||
|
||
#include <QPainter> | ||
#include <QSvgRenderer> | ||
#include <QPdfWriter> | ||
|
||
#include "UniversalDraw/universaldraw.h" | ||
#include "UniversalDraw/QtPaint/qtpainterdrawer.h" | ||
|
||
/// | ||
/// \brief The PngQtPaint class is used to draw a PDF with the Qt Painter | ||
/// | ||
class PngQtPaint : public QtPainterDrawer | ||
{ | ||
public: | ||
/// | ||
/// \brief PngQtPaint is a class that uses the QPainter class to draw | ||
/// | ||
explicit PngQtPaint(); | ||
|
||
/// | ||
/// \brief drawText draws Text on the given position | ||
/// \param position is the Position of the Text(Text Anchor) in mm | ||
/// \param text is the text that needs to be drawn | ||
/// \param textSize is the height/size of the text in mm | ||
/// \param textHeightAnchor is the position of the text anchor in the height | ||
/// \param textWidthAnchor is the position of the text anchor in the width | ||
/// \param lineWidth is the width of the text line in mm | ||
/// \param font is the name of the font | ||
/// \param isEditable defines if the text field is editable(true) or not(false), this does | ||
/// nothing with base | ||
/// \param name is the name that the text field is given, often used for | ||
/// variable/editable text | ||
/// | ||
// virtual void drawText(QPointF position, QString text, double textSize, | ||
// TextHeightAnchor textHeightAnchor, TextWidthAnchor textWidthAnchor, | ||
// double lineWidth, QString font = QString::fromLatin1("osifont"), | ||
// QString name = QString::fromLatin1(""), bool isEditable = false) | ||
// override; | ||
|
||
/// | ||
/// \brief start initialises the file and make everything ready to be drawn in to | ||
/// \return true if successful | ||
/// | ||
virtual bool start() override; | ||
|
||
/// | ||
/// \brief end finishes and closes the file | ||
/// \return true if successful | ||
/// | ||
virtual bool end() override; | ||
|
||
/// | ||
/// \brief resolutionDPI is the general resolution the PDF is generated with in DPI | ||
/// \return | ||
/// | ||
int resolutionDPI() const; | ||
/// | ||
/// \brief setResolutionDPI sets the general resolution the PDF is generated with in DPI | ||
/// \param newResolutionDPI | ||
/// | ||
void setResolutionDPI(int newResolutionDPI); | ||
|
||
/// | ||
/// \brief resolutionPMM is the general resolution the PDF is generated with in Px Per mm | ||
/// \return | ||
/// | ||
double resolutionPMM() const; | ||
/// | ||
/// \brief setResolutionPMM sets the general resolution the PDF is generated with in Px Per mm | ||
/// \param newResolutionPMM | ||
/// | ||
void setResolutionPMM(double newResolutionPMM); | ||
|
||
private: | ||
/// | ||
std::shared_ptr<QImage> m_image; | ||
|
||
/// | ||
/// \brief m_resolutionDPI the used resolution of the drawing coordinates | ||
/// | ||
int m_resolutionDPI = 1200; | ||
/// | ||
/// \brief m_resolutionPMM the used resolution of the drawing coordinates in Px per mm | ||
/// | ||
double m_resolutionPMM = m_resolutionDPI * (1 / 25.4); | ||
}; | ||
|
||
#endif // PNGQTPAINT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters