mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Make GUI scalable
This commit is contained in:
parent
0f9a326398
commit
28ea2f1c69
@ -42,6 +42,8 @@ namespace Zint {
|
|||||||
m_option_3 = 0;
|
m_option_3 = 0;
|
||||||
m_hidetext = 0;
|
m_hidetext = 0;
|
||||||
m_dot_size = 4.0 / 5.0;
|
m_dot_size = 4.0 / 5.0;
|
||||||
|
target_size_horiz = 0;
|
||||||
|
target_size_vert = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QZint::~QZint() {
|
QZint::~QZint() {
|
||||||
@ -115,6 +117,11 @@ namespace Zint {
|
|||||||
void QZint::setText(const QString & text) {
|
void QZint::setText(const QString & text) {
|
||||||
m_text = text;
|
m_text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QZint::setTargetSize(int width, int height) {
|
||||||
|
target_size_horiz = width;
|
||||||
|
target_size_vert = height;
|
||||||
|
}
|
||||||
|
|
||||||
QString QZint::primaryMessage() {
|
QString QZint::primaryMessage() {
|
||||||
return m_primaryMessage;
|
return m_primaryMessage;
|
||||||
@ -294,16 +301,20 @@ namespace Zint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode mode) {
|
void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode mode) {
|
||||||
encode();
|
|
||||||
bool textdone;
|
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;
|
int yoffset = 0;
|
||||||
|
|
||||||
|
encode();
|
||||||
|
|
||||||
QString caption = QString::fromUtf8((const char *) m_zintSymbol->text, -1);
|
QString caption = QString::fromUtf8((const char *) m_zintSymbol->text, -1);
|
||||||
QFont fontSmall(fontstyle);
|
QFont fontSmall(fontstyle);
|
||||||
fontSmall.setPixelSize(fontPixelSizeSmall);
|
fontSmall.setPixelSize(fontPixelSizeSmall);
|
||||||
QFont fontLarge(fontstyle);
|
QFont fontLarge(fontstyle);
|
||||||
fontLarge.setPixelSize(fontPixelSizeLarge);
|
fontLarge.setPixelSize(fontPixelSizeLarge);
|
||||||
|
|
||||||
if (m_lastError.length()) {
|
if (m_lastError.length()) {
|
||||||
painter.setFont(fontLarge);
|
painter.setFont(fontLarge);
|
||||||
painter.drawText(paintRect, Qt::AlignCenter, m_lastError);
|
painter.drawText(paintRect, Qt::AlignCenter, m_lastError);
|
||||||
@ -312,6 +323,7 @@ namespace Zint {
|
|||||||
|
|
||||||
painter.save();
|
painter.save();
|
||||||
painter.setClipRect(paintRect, Qt::IntersectClip);
|
painter.setClipRect(paintRect, Qt::IntersectClip);
|
||||||
|
|
||||||
qreal xtr = paintRect.x();
|
qreal xtr = paintRect.x();
|
||||||
qreal ytr = paintRect.y();
|
qreal ytr = paintRect.y();
|
||||||
|
|
||||||
@ -334,8 +346,8 @@ namespace Zint {
|
|||||||
qreal gwidth = m_zintSymbol->width;
|
qreal gwidth = m_zintSymbol->width;
|
||||||
qreal gheight = m_zintSymbol->height;
|
qreal gheight = m_zintSymbol->height;
|
||||||
if (m_zintSymbol->symbology == BARCODE_MAXICODE) {
|
if (m_zintSymbol->symbology == BARCODE_MAXICODE) {
|
||||||
// gheight *= (maxi_width);
|
gheight *= (maxi_width);
|
||||||
// gwidth *= (maxi_width + 1);
|
gwidth *= (maxi_width + 1);
|
||||||
gwidth *= 2.0;
|
gwidth *= 2.0;
|
||||||
gheight *= 2.0;
|
gheight *= 2.0;
|
||||||
}
|
}
|
||||||
@ -358,27 +370,14 @@ namespace Zint {
|
|||||||
textoffset = 0;
|
textoffset = 0;
|
||||||
}
|
}
|
||||||
gwidth += m_zintSymbol->whitespace_width * 2;
|
gwidth += m_zintSymbol->whitespace_width * 2;
|
||||||
// switch (mode) {
|
|
||||||
// case IgnoreAspectRatio:
|
if (paintRect.width() / gwidth < paintRect.height() / gheight) {
|
||||||
// xsf = (qreal) paintRect.width() / gwidth;
|
ysf = xsf = (qreal) paintRect.width() / gwidth;
|
||||||
// ysf = (qreal) paintRect.height() / gheight;
|
ytr += (qreal) (paintRect.height() - gheight * ysf) / 2;
|
||||||
// break;
|
} else {
|
||||||
//
|
ysf = xsf = (qreal) paintRect.height() / gheight;
|
||||||
// case KeepAspectRatio:
|
xtr += (qreal) (paintRect.width() - gwidth * xsf) / 2;
|
||||||
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;
|
|
||||||
// }
|
|
||||||
|
|
||||||
painter.setBackground(QBrush(m_bgColor));
|
painter.setBackground(QBrush(m_bgColor));
|
||||||
painter.fillRect(paintRect, QBrush(m_bgColor));
|
painter.fillRect(paintRect, QBrush(m_bgColor));
|
||||||
@ -386,11 +385,11 @@ namespace Zint {
|
|||||||
painter.scale(xsf, ysf);
|
painter.scale(xsf, ysf);
|
||||||
|
|
||||||
QPen p;
|
QPen p;
|
||||||
|
|
||||||
p.setColor(m_fgColor);
|
p.setColor(m_fgColor);
|
||||||
p.setWidth(m_borderWidth);
|
p.setWidth(m_borderWidth);
|
||||||
painter.setPen(p);
|
painter.setPen(p);
|
||||||
|
|
||||||
QPainterPath pt;
|
|
||||||
if (m_zintSymbol->symbology != BARCODE_MAXICODE) {
|
if (m_zintSymbol->symbology != BARCODE_MAXICODE) {
|
||||||
/* Draw boundary bars or boxes around the symbol */
|
/* Draw boundary bars or boxes around the symbol */
|
||||||
switch (m_border) {
|
switch (m_border) {
|
||||||
|
@ -93,6 +93,8 @@ public:
|
|||||||
bool save_to_file(QString filename);
|
bool save_to_file(QString filename);
|
||||||
|
|
||||||
void setHideText(bool hide);
|
void setHideText(bool hide);
|
||||||
|
|
||||||
|
void setTargetSize(int width, int height);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void encode();
|
void encode();
|
||||||
@ -119,6 +121,8 @@ private:
|
|||||||
int m_option_3;
|
int m_option_3;
|
||||||
bool m_hidetext;
|
bool m_hidetext;
|
||||||
float m_dot_size;
|
float m_dot_size;
|
||||||
|
int target_size_horiz;
|
||||||
|
int target_size_vert;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,15 +20,19 @@
|
|||||||
BarcodeItem::BarcodeItem()
|
BarcodeItem::BarcodeItem()
|
||||||
: QGraphicsItem()
|
: QGraphicsItem()
|
||||||
{
|
{
|
||||||
w=550;
|
w=693;
|
||||||
h=230;
|
h=378; // Default widget size when created
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BarcodeItem::~BarcodeItem()
|
BarcodeItem::~BarcodeItem()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BarcodeItem::setSize(int width, int height) {
|
||||||
|
w = width;
|
||||||
|
h = height;
|
||||||
|
}
|
||||||
|
|
||||||
QRectF BarcodeItem::boundingRect() const
|
QRectF BarcodeItem::boundingRect() const
|
||||||
{
|
{
|
||||||
return QRectF(0, 0, w, h);
|
return QRectF(0, 0, w, h);
|
||||||
|
@ -29,12 +29,15 @@ class BarcodeItem : public QGraphicsItem
|
|||||||
public:
|
public:
|
||||||
BarcodeItem();
|
BarcodeItem();
|
||||||
~BarcodeItem();
|
~BarcodeItem();
|
||||||
|
void setSize(int width, int height);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);
|
void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int w, h;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
mutable Zint::QZint bc;
|
mutable Zint::QZint bc;
|
||||||
int w,h;
|
|
||||||
Zint::QZint::AspectRatioMode ar;
|
Zint::QZint::AspectRatioMode ar;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,22 +5,24 @@
|
|||||||
<property name="windowModality">
|
<property name="windowModality">
|
||||||
<enum>Qt::NonModal</enum>
|
<enum>Qt::NonModal</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>701</width>
|
||||||
|
<height>724</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>590</width>
|
<width>420</width>
|
||||||
<height>600</height>
|
<height>500</height>
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>590</width>
|
|
||||||
<height>600</height>
|
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -41,32 +43,7 @@
|
|||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGraphicsView" name="view">
|
<widget class="QGraphicsView" name="view"/>
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>0</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>1000</width>
|
|
||||||
<height>1000</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Resulting barcode shown here</string>
|
|
||||||
</property>
|
|
||||||
<property name="autoFillBackground">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
@ -331,8 +308,8 @@ Remember to place [square brackets] around AI data</string>
|
|||||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||||
p, li { white-space: pre-wrap; }
|
p, li { white-space: pre-wrap; }
|
||||||
</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
|
</style></head><body style=" font-family:'Noto Sans [monotype]'; font-size:9pt; font-weight:400; font-style:normal;">
|
||||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Your Data Here!</p></body></html></string>
|
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif';">Your Data Here!</span></p></body></html></string>
|
||||||
</property>
|
</property>
|
||||||
<property name="acceptRichText">
|
<property name="acceptRichText">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
|
@ -103,8 +103,10 @@ MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags fl)
|
|||||||
/* createActions();
|
/* createActions();
|
||||||
createMenus(); */
|
createMenus(); */
|
||||||
|
|
||||||
|
scene = new QGraphicsScene(this);
|
||||||
|
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
view->setScene(new QGraphicsScene);
|
view->setScene(scene);
|
||||||
|
|
||||||
m_fgcolor=qRgb(0,0,0);
|
m_fgcolor=qRgb(0,0,0);
|
||||||
m_bgcolor=qRgb(0xff,0xff,0xff);
|
m_bgcolor=qRgb(0xff,0xff,0xff);
|
||||||
@ -114,8 +116,8 @@ MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags fl)
|
|||||||
}
|
}
|
||||||
bstyle->setCurrentIndex(10);
|
bstyle->setCurrentIndex(10);
|
||||||
change_options();
|
change_options();
|
||||||
|
scene->addItem(&m_bc);
|
||||||
update_preview();
|
update_preview();
|
||||||
view->scene()->addItem(&m_bc);
|
|
||||||
connect(bstyle, SIGNAL(currentIndexChanged( int )), SLOT(change_options()));
|
connect(bstyle, SIGNAL(currentIndexChanged( int )), SLOT(change_options()));
|
||||||
connect(bstyle, SIGNAL(currentIndexChanged( int )), SLOT(update_preview()));
|
connect(bstyle, SIGNAL(currentIndexChanged( int )), SLOT(update_preview()));
|
||||||
connect(heightb, SIGNAL(valueChanged( int )), SLOT(update_preview()));
|
connect(heightb, SIGNAL(valueChanged( int )), SLOT(update_preview()));
|
||||||
@ -141,6 +143,12 @@ MainWindow::~MainWindow()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::resizeEvent(QResizeEvent* event)
|
||||||
|
{
|
||||||
|
QWidget::resizeEvent(event);
|
||||||
|
update_preview();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::reset_view()
|
void MainWindow::reset_view()
|
||||||
{
|
{
|
||||||
m_fgcolor=qRgb(0,0,0);
|
m_fgcolor=qRgb(0,0,0);
|
||||||
@ -588,8 +596,10 @@ void MainWindow::maxi_primary()
|
|||||||
|
|
||||||
void MainWindow::update_preview()
|
void MainWindow::update_preview()
|
||||||
{
|
{
|
||||||
QString error;
|
int width = view->geometry().width();
|
||||||
m_bc.ar=(Zint::QZint::AspectRatioMode)1;
|
int height = view->geometry().height();
|
||||||
|
|
||||||
|
//m_bc.ar=(Zint::QZint::AspectRatioMode)1;
|
||||||
if(chkComposite->isChecked() == true) {
|
if(chkComposite->isChecked() == true) {
|
||||||
m_bc.bc.setPrimaryMessage(txtData->text());
|
m_bc.bc.setPrimaryMessage(txtData->text());
|
||||||
m_bc.bc.setText(txtComposite->toPlainText());
|
m_bc.bc.setText(txtComposite->toPlainText());
|
||||||
@ -885,7 +895,8 @@ void MainWindow::update_preview()
|
|||||||
m_bc.bc.setWhitespace(spnWhitespace->value());
|
m_bc.bc.setWhitespace(spnWhitespace->value());
|
||||||
m_bc.bc.setFgColor(m_fgcolor);
|
m_bc.bc.setFgColor(m_fgcolor);
|
||||||
m_bc.bc.setBgColor(m_bgcolor);
|
m_bc.bc.setBgColor(m_bgcolor);
|
||||||
|
m_bc.setSize(width - 10, height - 10);
|
||||||
m_bc.update();
|
m_bc.update();
|
||||||
view->scene()->update();
|
scene->setSceneRect(0, 0, width - 10, height - 10);
|
||||||
|
scene->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
|
||||||
#include "ui_mainWindow.h"
|
#include "ui_mainWindow.h"
|
||||||
#include "barcodeitem.h"
|
#include "barcodeitem.h"
|
||||||
@ -119,6 +120,9 @@ public slots:
|
|||||||
void maxi_primary();
|
void maxi_primary();
|
||||||
void change_print_scale();
|
void change_print_scale();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void resizeEvent(QResizeEvent *event);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
bool save();
|
bool save();
|
||||||
void about();
|
void about();
|
||||||
@ -134,6 +138,7 @@ private:
|
|||||||
QColor m_fgcolor,m_bgcolor;
|
QColor m_fgcolor,m_bgcolor;
|
||||||
BarcodeItem m_bc;
|
BarcodeItem m_bc;
|
||||||
QWidget *m_optionWidget;
|
QWidget *m_optionWidget;
|
||||||
|
QGraphicsScene *scene;
|
||||||
/* QMenu *fileMenu;
|
/* QMenu *fileMenu;
|
||||||
QMenu *helpMenu;
|
QMenu *helpMenu;
|
||||||
QAction *saveAct;
|
QAction *saveAct;
|
||||||
|
Loading…
Reference in New Issue
Block a user