2009-11-18 11:36:04 +13:00
|
|
|
/*
|
|
|
|
Zint Barcode Generator - the open source barcode generator
|
2021-01-12 07:11:41 +13:00
|
|
|
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com>
|
2009-11-18 11:36:04 +13:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2020-10-28 04:21:50 +13:00
|
|
|
/* vim: set ts=4 sw=4 et : */
|
2009-11-18 11:36:04 +13:00
|
|
|
|
2020-10-28 04:21:50 +13:00
|
|
|
//#include <QDebug>
|
2009-11-18 11:36:04 +13:00
|
|
|
#include <QFile>
|
|
|
|
#include <QUiLoader>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
2017-07-27 21:21:46 +12:00
|
|
|
#include <QSettings>
|
2009-11-18 11:36:04 +13:00
|
|
|
|
|
|
|
#include "sequencewindow.h"
|
|
|
|
#include "exportwindow.h"
|
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
// Shorthand
|
|
|
|
#define QSL QStringLiteral
|
|
|
|
|
|
|
|
SequenceWindow::SequenceWindow(BarcodeItem *bc) : m_bc(bc)
|
2009-11-18 11:36:04 +13:00
|
|
|
{
|
2020-10-28 04:21:50 +13:00
|
|
|
setupUi(this);
|
2020-10-28 04:11:33 +13:00
|
|
|
QSettings settings;
|
2021-01-12 07:11:41 +13:00
|
|
|
#if QT_VERSION < 0x60000
|
2020-10-28 04:11:33 +13:00
|
|
|
settings.setIniCodec("UTF-8");
|
2021-01-12 07:11:41 +13:00
|
|
|
#endif
|
2021-11-24 08:12:48 +13:00
|
|
|
|
|
|
|
QByteArray geometry = settings.value(QSL("studio/sequence/window_geometry")).toByteArray();
|
|
|
|
restoreGeometry(geometry);
|
|
|
|
|
|
|
|
spnSeqStartVal->setValue(settings.value(QSL("studio/sequence/start_value"), 1).toInt());
|
|
|
|
spnSeqEndVal->setValue(settings.value(QSL("studio/sequence/end_value"), 10).toInt());
|
|
|
|
spnSeqIncVal->setValue(settings.value(QSL("studio/sequence/increment"), 1).toInt());
|
|
|
|
linSeqFormat->setText(settings.value(QSL("studio/sequence/format"), QSL("$$$$$$")).toString());
|
|
|
|
|
|
|
|
QIcon closeIcon(QIcon::fromTheme(QSL("window-close"), QIcon(QSL(":res/x.svg"))));
|
|
|
|
QIcon clearIcon(QIcon::fromTheme(QSL("edit-clear"), QIcon(QSL(":res/delete.svg"))));
|
|
|
|
btnSeqClose->setIcon(closeIcon);
|
|
|
|
btnSeqClear->setIcon(clearIcon);
|
|
|
|
|
|
|
|
connect(btnSeqClose, SIGNAL( clicked( bool )), SLOT(close()));
|
|
|
|
connect(btnSeqClear, SIGNAL( clicked( bool )), SLOT(clear_preview()));
|
|
|
|
connect(btnSeqCreate, SIGNAL( clicked( bool )), SLOT(create_sequence()));
|
|
|
|
connect(txtSeqPreview, SIGNAL( textChanged()), SLOT(check_generate()));
|
|
|
|
connect(btnSeqImport, SIGNAL( clicked( bool )), SLOT(import()));
|
|
|
|
connect(btnSeqExport, SIGNAL( clicked( bool )), SLOT(generate_sequence()));
|
2009-11-18 11:36:04 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
SequenceWindow::~SequenceWindow()
|
|
|
|
{
|
2017-07-27 21:21:46 +12:00
|
|
|
QSettings settings;
|
2021-01-12 07:11:41 +13:00
|
|
|
#if QT_VERSION < 0x60000
|
2020-10-28 04:11:33 +13:00
|
|
|
settings.setIniCodec("UTF-8");
|
2021-01-12 07:11:41 +13:00
|
|
|
#endif
|
2021-11-24 08:12:48 +13:00
|
|
|
settings.setValue(QSL("studio/sequence/window_geometry"), saveGeometry());
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
settings.setValue(QSL("studio/sequence/start_value"), spnSeqStartVal->value());
|
|
|
|
settings.setValue(QSL("studio/sequence/end_value"), spnSeqEndVal->value());
|
|
|
|
settings.setValue(QSL("studio/sequence/increment"), spnSeqIncVal->value());
|
|
|
|
settings.setValue(QSL("studio/sequence/format"), linSeqFormat->text());
|
2009-11-18 11:36:04 +13:00
|
|
|
}
|
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
void SequenceWindow::clear_preview()
|
2009-11-18 11:36:04 +13:00
|
|
|
{
|
2021-11-24 08:12:48 +13:00
|
|
|
txtSeqPreview->clear();
|
2009-11-18 11:36:04 +13:00
|
|
|
}
|
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
QString SequenceWindow::apply_format(const QString& raw_number)
|
2009-11-18 11:36:04 +13:00
|
|
|
{
|
2020-10-28 04:21:50 +13:00
|
|
|
QString adjusted, reversed;
|
|
|
|
QString format;
|
|
|
|
int format_len, input_len, i, inpos;
|
|
|
|
QChar format_qchar;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
format = linSeqFormat->text();
|
2020-10-28 04:21:50 +13:00
|
|
|
input_len = raw_number.length();
|
|
|
|
format_len = format.length();
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2020-10-28 04:21:50 +13:00
|
|
|
inpos = input_len;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
for (i = format_len; i > 0; i--) {
|
2020-10-28 04:21:50 +13:00
|
|
|
format_qchar = format[i - 1];
|
2017-09-11 03:03:09 +12:00
|
|
|
char format_char = format_qchar.toLatin1();
|
2021-11-24 08:12:48 +13:00
|
|
|
switch (format_char) {
|
2020-10-28 04:21:50 +13:00
|
|
|
case '#':
|
|
|
|
if (inpos > 0) {
|
|
|
|
adjusted += raw_number[inpos - 1];
|
|
|
|
inpos--;
|
|
|
|
} else {
|
|
|
|
adjusted += ' ';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '$':
|
|
|
|
if (inpos > 0) {
|
|
|
|
adjusted += raw_number[inpos - 1];
|
|
|
|
inpos--;
|
|
|
|
} else {
|
|
|
|
adjusted += '0';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '*':
|
|
|
|
if (inpos > 0) {
|
|
|
|
adjusted += raw_number[inpos - 1];
|
|
|
|
inpos--;
|
|
|
|
} else {
|
|
|
|
adjusted += '*';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
adjusted += format_char;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = format_len; i > 0; i--) {
|
|
|
|
reversed += adjusted[i - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
return reversed;
|
2009-11-18 11:36:04 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
void SequenceWindow::create_sequence()
|
|
|
|
{
|
2021-11-24 08:12:48 +13:00
|
|
|
QStringList outputtext;
|
2020-10-28 04:21:50 +13:00
|
|
|
int start, stop, step, i;
|
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
start = spnSeqStartVal->value();
|
|
|
|
stop = spnSeqEndVal->value();
|
|
|
|
step = spnSeqIncVal->value();
|
2020-10-28 04:21:50 +13:00
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
if (stop < start) {
|
|
|
|
QMessageBox::critical(this, tr("Sequence Error"),
|
|
|
|
tr("End Value must be greater than or equal to Start Value."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((stop - start) / step > 10000) {
|
|
|
|
QMessageBox::critical(this, tr("Sequence Error"), tr("The maximum sequence allowed is 10,000 items."));
|
2020-10-28 04:21:50 +13:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
for (i = start; i <= stop; i += step) {
|
|
|
|
outputtext << apply_format(QString::number(i, 10));
|
2020-10-28 04:21:50 +13:00
|
|
|
}
|
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
txtSeqPreview->setPlainText(outputtext.join('\n'));
|
2009-11-18 11:36:04 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
void SequenceWindow::check_generate()
|
|
|
|
{
|
2020-10-28 04:21:50 +13:00
|
|
|
QString preview_copy;
|
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
preview_copy = txtSeqPreview->toPlainText();
|
|
|
|
if (preview_copy.isEmpty()) {
|
|
|
|
btnSeqExport->setEnabled(false);
|
|
|
|
lblSeqExport->setEnabled(false);
|
2020-10-28 04:21:50 +13:00
|
|
|
} else {
|
2021-11-24 08:12:48 +13:00
|
|
|
btnSeqExport->setEnabled(true);
|
|
|
|
lblSeqExport->setEnabled(true);
|
2020-10-28 04:21:50 +13:00
|
|
|
}
|
2009-11-18 11:36:04 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
void SequenceWindow::import()
|
|
|
|
{
|
2017-07-27 21:21:46 +12:00
|
|
|
QSettings settings;
|
2021-01-12 07:11:41 +13:00
|
|
|
#if QT_VERSION < 0x60000
|
2020-10-28 04:11:33 +13:00
|
|
|
settings.setIniCodec("UTF-8");
|
2021-01-12 07:11:41 +13:00
|
|
|
#endif
|
2017-07-27 21:21:46 +12:00
|
|
|
QFileDialog import_dialog;
|
|
|
|
QString filename;
|
|
|
|
QFile file;
|
|
|
|
QByteArray outstream;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
import_dialog.setWindowTitle(tr("Import File"));
|
|
|
|
import_dialog.setDirectory(settings.value(QSL("studio/default_dir"),
|
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-29 09:42:44 +13:00
|
|
|
QDir::toNativeSeparators(QDir::homePath())).toString());
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2017-07-27 21:21:46 +12:00
|
|
|
if (import_dialog.exec()) {
|
|
|
|
filename = import_dialog.selectedFiles().at(0);
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2017-07-27 21:21:46 +12:00
|
|
|
file.setFileName(filename);
|
2021-11-24 08:12:48 +13:00
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
2017-07-27 21:21:46 +12:00
|
|
|
QMessageBox::critical(this, tr("Open Error"), tr("Could not open selected file."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
outstream = file.readAll();
|
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
txtSeqPreview->setPlainText(QString(outstream));
|
2017-07-27 21:21:46 +12:00
|
|
|
file.close();
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
settings.setValue(QSL("studio/default_dir"), filename.mid(0, filename.lastIndexOf(QDir::separator())));
|
2009-11-18 11:36:04 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
void SequenceWindow::generate_sequence()
|
|
|
|
{
|
2021-11-24 08:12:48 +13:00
|
|
|
ExportWindow dlg(m_bc, txtSeqPreview->toPlainText());
|
2020-10-28 04:21:50 +13:00
|
|
|
dlg.exec();
|
2009-11-18 11:36:04 +13:00
|
|
|
}
|