Make GUI scalable

This commit is contained in:
Robin Stuart 2016-12-14 23:33:17 +00:00
parent 0f9a326398
commit 28ea2f1c69
7 changed files with 77 additions and 74 deletions

View file

@ -42,6 +42,8 @@ namespace Zint {
m_option_3 = 0;
m_hidetext = 0;
m_dot_size = 4.0 / 5.0;
target_size_horiz = 0;
target_size_vert = 0;
}
QZint::~QZint() {
@ -115,6 +117,11 @@ namespace Zint {
void QZint::setText(const QString & text) {
m_text = text;
}
void QZint::setTargetSize(int width, int height) {
target_size_horiz = width;
target_size_vert = height;
}
QString QZint::primaryMessage() {
return m_primaryMessage;
@ -294,16 +301,20 @@ namespace Zint {
}
void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode mode) {
encode();
bool textdone;
int comp_offset = 0, xoffset = m_whitespace, j, main_width = 0, addon_text_height = 0;
int comp_offset = 0;
int xoffset = m_whitespace;
int j, main_width = 0, addon_text_height = 0;
int yoffset = 0;
encode();
QString caption = QString::fromUtf8((const char *) m_zintSymbol->text, -1);
QFont fontSmall(fontstyle);
fontSmall.setPixelSize(fontPixelSizeSmall);
QFont fontLarge(fontstyle);
fontLarge.setPixelSize(fontPixelSizeLarge);
if (m_lastError.length()) {
painter.setFont(fontLarge);
painter.drawText(paintRect, Qt::AlignCenter, m_lastError);
@ -312,6 +323,7 @@ namespace Zint {
painter.save();
painter.setClipRect(paintRect, Qt::IntersectClip);
qreal xtr = paintRect.x();
qreal ytr = paintRect.y();
@ -334,8 +346,8 @@ namespace Zint {
qreal gwidth = m_zintSymbol->width;
qreal gheight = m_zintSymbol->height;
if (m_zintSymbol->symbology == BARCODE_MAXICODE) {
// gheight *= (maxi_width);
// gwidth *= (maxi_width + 1);
gheight *= (maxi_width);
gwidth *= (maxi_width + 1);
gwidth *= 2.0;
gheight *= 2.0;
}
@ -358,27 +370,14 @@ namespace Zint {
textoffset = 0;
}
gwidth += m_zintSymbol->whitespace_width * 2;
// switch (mode) {
// case IgnoreAspectRatio:
// xsf = (qreal) paintRect.width() / gwidth;
// ysf = (qreal) paintRect.height() / gheight;
// break;
//
// case KeepAspectRatio:
if (paintRect.width() / gwidth < paintRect.height() / gheight) {
ysf = xsf = (qreal) paintRect.width() / gwidth;
ytr += (qreal) (paintRect.height() - gheight * ysf) / 2;
} else {
ysf = xsf = (qreal) paintRect.height() / gheight;
xtr += (qreal) (paintRect.width() - gwidth * xsf) / 2;
}
// break;
// case CenterBarCode:
// xtr += ((qreal) paintRect.width() - gwidth * xsf) / 2;
// ytr += ((qreal) paintRect.height() - gheight * ysf) / 2;
// break;
// }
if (paintRect.width() / gwidth < paintRect.height() / gheight) {
ysf = xsf = (qreal) paintRect.width() / gwidth;
ytr += (qreal) (paintRect.height() - gheight * ysf) / 2;
} else {
ysf = xsf = (qreal) paintRect.height() / gheight;
xtr += (qreal) (paintRect.width() - gwidth * xsf) / 2;
}
painter.setBackground(QBrush(m_bgColor));
painter.fillRect(paintRect, QBrush(m_bgColor));
@ -386,11 +385,11 @@ namespace Zint {
painter.scale(xsf, ysf);
QPen p;
p.setColor(m_fgColor);
p.setWidth(m_borderWidth);
painter.setPen(p);
QPainterPath pt;
if (m_zintSymbol->symbology != BARCODE_MAXICODE) {
/* Draw boundary bars or boxes around the symbol */
switch (m_border) {