2009-11-18 11:36:04 +13:00
|
|
|
/*
|
|
|
|
Zint Barcode Generator - the open source barcode generator
|
2020-10-28 04:21:50 +13:00
|
|
|
Copyright (C) 2009 - 2020 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"
|
|
|
|
|
|
|
|
SequenceWindow::SequenceWindow()
|
|
|
|
{
|
2020-10-28 04:21:50 +13:00
|
|
|
setupUi(this);
|
2020-10-28 04:11:33 +13:00
|
|
|
QSettings settings;
|
|
|
|
settings.setIniCodec("UTF-8");
|
2020-10-28 04:21:50 +13:00
|
|
|
QValidator *intvalid = new QIntValidator(this);
|
|
|
|
|
|
|
|
linStartVal->setText(settings.value("studio/sequence/start_value", "1").toString());
|
|
|
|
linEndVal->setText(settings.value("studio/sequence/end_value", "10").toString());
|
|
|
|
linIncVal->setText(settings.value("studio/sequence/increment", "1").toString());
|
|
|
|
linFormat->setText(settings.value("studio/sequence/format", "$$$$$$").toString());
|
|
|
|
|
|
|
|
linStartVal->setValidator(intvalid);
|
|
|
|
linEndVal->setValidator(intvalid);
|
|
|
|
linIncVal->setValidator(intvalid);
|
|
|
|
connect(btnClose, SIGNAL( clicked( bool )), SLOT(quit_now()));
|
|
|
|
connect(btnReset, SIGNAL( clicked( bool )), SLOT(reset_preview()));
|
|
|
|
connect(btnCreate, SIGNAL( clicked( bool )), SLOT(create_sequence()));
|
|
|
|
connect(txtPreview, SIGNAL( textChanged()), SLOT(check_generate()));
|
|
|
|
connect(btnImport, SIGNAL( clicked( bool )), SLOT(import()));
|
|
|
|
connect(btnExport, 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;
|
2020-10-28 04:11:33 +13:00
|
|
|
settings.setIniCodec("UTF-8");
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2017-07-27 21:21:46 +12:00
|
|
|
settings.setValue("studio/sequence/start_value", linStartVal->text());
|
|
|
|
settings.setValue("studio/sequence/end_value", linEndVal->text());
|
|
|
|
settings.setValue("studio/sequence/increment", linIncVal->text());
|
|
|
|
settings.setValue("studio/sequence/format", linFormat->text());
|
2009-11-18 11:36:04 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
void SequenceWindow::quit_now()
|
|
|
|
{
|
2020-10-28 04:21:50 +13:00
|
|
|
close();
|
2009-11-18 11:36:04 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
void SequenceWindow::reset_preview()
|
|
|
|
{
|
2020-10-28 04:21:50 +13:00
|
|
|
txtPreview->clear();
|
2009-11-18 11:36:04 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
QString SequenceWindow::apply_format(QString raw_number)
|
|
|
|
{
|
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
|
|
|
|
2020-10-28 04:21:50 +13:00
|
|
|
format = linFormat->text();
|
|
|
|
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
|
|
|
|
2020-10-28 04:21:50 +13:00
|
|
|
for(i = format_len; i > 0; i--) {
|
|
|
|
format_qchar = format[i - 1];
|
2017-09-11 03:03:09 +12:00
|
|
|
char format_char = format_qchar.toLatin1();
|
2020-10-28 04:21:50 +13:00
|
|
|
switch(format_char) {
|
|
|
|
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()
|
|
|
|
{
|
2020-10-28 04:21:50 +13:00
|
|
|
QString startval, endval, incval, part, outputtext;
|
|
|
|
int start, stop, step, i;
|
|
|
|
bool ok;
|
|
|
|
|
|
|
|
startval = linStartVal->text();
|
|
|
|
endval = linEndVal->text();
|
|
|
|
incval = linIncVal->text();
|
|
|
|
start = startval.toInt(&ok, 10);
|
|
|
|
stop = endval.toInt(&ok, 10);
|
|
|
|
step = incval.toInt(&ok, 10);
|
|
|
|
|
|
|
|
if((stop <= start) || (step <= 0)) {
|
|
|
|
QMessageBox::critical(this, tr("Sequence Error"), tr("One or more of the input values is incorrect."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = start; i <= stop; i += step) {
|
|
|
|
part = apply_format(QString::number(i, 10));
|
|
|
|
part += '\n';
|
|
|
|
outputtext += part;
|
|
|
|
}
|
|
|
|
|
|
|
|
txtPreview->setPlainText(outputtext);
|
2009-11-18 11:36:04 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
void SequenceWindow::check_generate()
|
|
|
|
{
|
2020-10-28 04:21:50 +13:00
|
|
|
QString preview_copy;
|
|
|
|
|
|
|
|
preview_copy = txtPreview->toPlainText();
|
|
|
|
if(preview_copy.isEmpty()) {
|
|
|
|
btnExport->setEnabled(false);
|
|
|
|
lblExport->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
btnExport->setEnabled(true);
|
|
|
|
lblExport->setEnabled(true);
|
|
|
|
}
|
2009-11-18 11:36:04 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
void SequenceWindow::import()
|
|
|
|
{
|
2017-07-27 21:21:46 +12:00
|
|
|
QSettings settings;
|
2020-10-28 04:11:33 +13:00
|
|
|
settings.setIniCodec("UTF-8");
|
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
|
|
|
|
2017-07-27 21:21:46 +12:00
|
|
|
import_dialog.setWindowTitle("Import File");
|
|
|
|
import_dialog.setDirectory(settings.value("studio/default_dir", 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);
|
|
|
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
QMessageBox::critical(this, tr("Open Error"), tr("Could not open selected file."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
outstream = file.readAll();
|
|
|
|
|
|
|
|
txtPreview->setPlainText(QString(outstream));
|
|
|
|
file.close();
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2017-07-27 21:21:46 +12:00
|
|
|
settings.setValue("studio/default_dir", filename.mid(0, filename.lastIndexOf(QDir::separator())));
|
2009-11-18 11:36:04 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
void SequenceWindow::generate_sequence()
|
|
|
|
{
|
2020-10-28 04:21:50 +13:00
|
|
|
ExportWindow dlg;
|
|
|
|
dlg.barcode = barcode;
|
|
|
|
dlg.output_data = txtPreview->toPlainText();
|
|
|
|
dlg.exec();
|
2009-11-18 11:36:04 +13:00
|
|
|
}
|