2009-11-18 01:36:04 +03:00
/*
Zint Barcode Generator - the open source barcode generator
2024-01-06 01:55:57 +03:00
Copyright ( C ) 2009 - 2024 Robin Stuart < rstuart114 @ gmail . com >
2009-11-18 01:36:04 +03: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 .
*/
RMQR: update to ISO/IEC 23941:2022 - R13x77 numeric cclens change 8 -> 7
QRCODE: use stricter interpretation of ZINT_FULL_MULTIBYTE, excluding
certain trailing bytes
libzint: fix some confusing error messages introduced by segment stuff
general: new escape chars \U, \d and \o
backend_qt: fudge rendering of border rectangles due to scaling/translation
rounding errors TODO: better fudge
GUI: foreground/background colours -> text boxes and icon buttons, add swap
button, independently movable picker (NULL parent), preview colour changes,
preview Data Window changes, add clear data (del) buttons, add zap button
and Factory Reset menu option, various other fixes
libzint: remove STATIC_UNLESS_ZINT_TEST, use wrappers
CMake: add find package QtSvg, remove QtXml
manual: split symbology and general specs and sort, move DAFT to 4-state,
UPC/EAN -> EAN/UPC, DataBar -> GS1 DataBar always, expand MAILMARK info,
various other fiddlings
man page: options or -> |, expand MSI Plessey check digit options
README.linux: add packages info
license: add SPDX-License-Identifier to touched files
2022-06-09 23:52:02 +03:00
/* SPDX-License-Identifier: GPL-3.0-or-later */
2009-11-18 01:36:04 +03:00
2020-10-27 18:21:50 +03:00
//#include <QDebug>
2009-11-18 01:36:04 +03:00
# include <QFile>
# include <QFileDialog>
# include <QMessageBox>
2017-07-27 12:21:46 +03:00
# include <QSettings>
2024-01-06 01:55:57 +03:00
# include <QUiLoader>
2009-11-18 01:36:04 +03:00
# include "sequencewindow.h"
# include "exportwindow.h"
2021-11-23 22:12:48 +03:00
// Shorthand
2024-01-06 01:55:57 +03:00
# define QSL QStringLiteral
# define QSEmpty QLatin1String("")
2021-11-23 22:12:48 +03:00
SequenceWindow : : SequenceWindow ( BarcodeItem * bc ) : m_bc ( bc )
2009-11-18 01:36:04 +03:00
{
2020-10-27 18:21:50 +03:00
setupUi ( this ) ;
2020-10-27 18:11:33 +03:00
QSettings settings ;
2021-01-11 21:11:41 +03:00
# if QT_VERSION < 0x60000
2020-10-27 18:11:33 +03:00
settings . setIniCodec ( " UTF-8 " ) ;
2021-01-11 21:11:41 +03:00
# endif
2021-11-23 22:12:48 +03: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 ( ) ) ;
2024-01-06 01:55:57 +03:00
txtSeqPreview - > setPlainText ( settings . value ( QSL ( " studio/sequence/preview " ) , QSEmpty ) . toString ( ) ) ;
2021-11-23 22:12:48 +03:00
QIcon closeIcon ( QIcon : : fromTheme ( QSL ( " window-close " ) , QIcon ( QSL ( " :res/x.svg " ) ) ) ) ;
RMQR: update to ISO/IEC 23941:2022 - R13x77 numeric cclens change 8 -> 7
QRCODE: use stricter interpretation of ZINT_FULL_MULTIBYTE, excluding
certain trailing bytes
libzint: fix some confusing error messages introduced by segment stuff
general: new escape chars \U, \d and \o
backend_qt: fudge rendering of border rectangles due to scaling/translation
rounding errors TODO: better fudge
GUI: foreground/background colours -> text boxes and icon buttons, add swap
button, independently movable picker (NULL parent), preview colour changes,
preview Data Window changes, add clear data (del) buttons, add zap button
and Factory Reset menu option, various other fixes
libzint: remove STATIC_UNLESS_ZINT_TEST, use wrappers
CMake: add find package QtSvg, remove QtXml
manual: split symbology and general specs and sort, move DAFT to 4-state,
UPC/EAN -> EAN/UPC, DataBar -> GS1 DataBar always, expand MAILMARK info,
various other fiddlings
man page: options or -> |, expand MSI Plessey check digit options
README.linux: add packages info
license: add SPDX-License-Identifier to touched files
2022-06-09 23:52:02 +03:00
QIcon clearIcon ( QSL ( " :res/delete.svg " ) ) ;
2021-11-23 22:12:48 +03:00
btnSeqClose - > setIcon ( closeIcon ) ;
btnSeqClear - > setIcon ( clearIcon ) ;
2022-06-16 18:47:34 +03:00
check_generate ( ) ;
2021-11-23 22:12:48 +03:00
2024-01-06 01:55:57 +03:00
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 ( btnSeqFromFile , SIGNAL ( clicked ( bool ) ) , SLOT ( from_file ( ) ) ) ;
connect ( btnSeqExport , SIGNAL ( clicked ( bool ) ) , SLOT ( generate_sequence ( ) ) ) ;
2009-11-18 01:36:04 +03:00
}
SequenceWindow : : ~ SequenceWindow ( )
{
2017-07-27 12:21:46 +03:00
QSettings settings ;
2021-01-11 21:11:41 +03:00
# if QT_VERSION < 0x60000
2020-10-27 18:11:33 +03:00
settings . setIniCodec ( " UTF-8 " ) ;
2021-01-11 21:11:41 +03:00
# endif
2021-11-23 22:12:48 +03:00
settings . setValue ( QSL ( " studio/sequence/window_geometry " ) , saveGeometry ( ) ) ;
2017-10-23 22:37:52 +03:00
2021-11-23 22:12:48 +03: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 ( ) ) ;
RMQR: update to ISO/IEC 23941:2022 - R13x77 numeric cclens change 8 -> 7
QRCODE: use stricter interpretation of ZINT_FULL_MULTIBYTE, excluding
certain trailing bytes
libzint: fix some confusing error messages introduced by segment stuff
general: new escape chars \U, \d and \o
backend_qt: fudge rendering of border rectangles due to scaling/translation
rounding errors TODO: better fudge
GUI: foreground/background colours -> text boxes and icon buttons, add swap
button, independently movable picker (NULL parent), preview colour changes,
preview Data Window changes, add clear data (del) buttons, add zap button
and Factory Reset menu option, various other fixes
libzint: remove STATIC_UNLESS_ZINT_TEST, use wrappers
CMake: add find package QtSvg, remove QtXml
manual: split symbology and general specs and sort, move DAFT to 4-state,
UPC/EAN -> EAN/UPC, DataBar -> GS1 DataBar always, expand MAILMARK info,
various other fiddlings
man page: options or -> |, expand MSI Plessey check digit options
README.linux: add packages info
license: add SPDX-License-Identifier to touched files
2022-06-09 23:52:02 +03:00
settings . setValue ( QSL ( " studio/sequence/preview " ) , txtSeqPreview - > toPlainText ( ) ) ;
2009-11-18 01:36:04 +03:00
}
2021-11-23 22:12:48 +03:00
void SequenceWindow : : clear_preview ( )
2009-11-18 01:36:04 +03:00
{
2021-11-23 22:12:48 +03:00
txtSeqPreview - > clear ( ) ;
2009-11-18 01:36:04 +03:00
}
2021-11-23 22:12:48 +03:00
QString SequenceWindow : : apply_format ( const QString & raw_number )
2009-11-18 01:36:04 +03:00
{
2020-10-27 18:21:50 +03:00
QString adjusted , reversed ;
QString format ;
int format_len , input_len , i , inpos ;
QChar format_qchar ;
2017-10-23 22:37:52 +03:00
2021-11-23 22:12:48 +03:00
format = linSeqFormat - > text ( ) ;
2020-10-27 18:21:50 +03:00
input_len = raw_number . length ( ) ;
format_len = format . length ( ) ;
2017-10-23 22:37:52 +03:00
2020-10-27 18:21:50 +03:00
inpos = input_len ;
2017-10-23 22:37:52 +03:00
2021-11-23 22:12:48 +03:00
for ( i = format_len ; i > 0 ; i - - ) {
2020-10-27 18:21:50 +03:00
format_qchar = format [ i - 1 ] ;
2017-09-10 18:03:09 +03:00
char format_char = format_qchar . toLatin1 ( ) ;
2021-11-23 22:12:48 +03:00
switch ( format_char ) {
2020-10-27 18:21:50 +03: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 ;
}
}
2022-07-04 23:55:06 +03:00
for ( i = format_len ; i > 0 ; i - - ) {
2020-10-27 18:21:50 +03:00
reversed + = adjusted [ i - 1 ] ;
}
return reversed ;
2009-11-18 01:36:04 +03:00
}
void SequenceWindow : : create_sequence ( )
{
2021-11-23 22:12:48 +03:00
QStringList outputtext ;
2020-10-27 18:21:50 +03:00
int start , stop , step , i ;
2021-11-23 22:12:48 +03:00
start = spnSeqStartVal - > value ( ) ;
stop = spnSeqEndVal - > value ( ) ;
step = spnSeqIncVal - > value ( ) ;
2020-10-27 18:21:50 +03:00
2021-11-23 22:12:48 +03: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-27 18:21:50 +03:00
return ;
}
2021-11-23 22:12:48 +03:00
for ( i = start ; i < = stop ; i + = step ) {
outputtext < < apply_format ( QString : : number ( i , 10 ) ) ;
2020-10-27 18:21:50 +03:00
}
2021-11-23 22:12:48 +03:00
txtSeqPreview - > setPlainText ( outputtext . join ( ' \n ' ) ) ;
2009-11-18 01:36:04 +03:00
}
void SequenceWindow : : check_generate ( )
{
2020-10-27 18:21:50 +03:00
QString preview_copy ;
2021-11-23 22:12:48 +03:00
preview_copy = txtSeqPreview - > toPlainText ( ) ;
if ( preview_copy . isEmpty ( ) ) {
btnSeqExport - > setEnabled ( false ) ;
RMQR: update to ISO/IEC 23941:2022 - R13x77 numeric cclens change 8 -> 7
QRCODE: use stricter interpretation of ZINT_FULL_MULTIBYTE, excluding
certain trailing bytes
libzint: fix some confusing error messages introduced by segment stuff
general: new escape chars \U, \d and \o
backend_qt: fudge rendering of border rectangles due to scaling/translation
rounding errors TODO: better fudge
GUI: foreground/background colours -> text boxes and icon buttons, add swap
button, independently movable picker (NULL parent), preview colour changes,
preview Data Window changes, add clear data (del) buttons, add zap button
and Factory Reset menu option, various other fixes
libzint: remove STATIC_UNLESS_ZINT_TEST, use wrappers
CMake: add find package QtSvg, remove QtXml
manual: split symbology and general specs and sort, move DAFT to 4-state,
UPC/EAN -> EAN/UPC, DataBar -> GS1 DataBar always, expand MAILMARK info,
various other fiddlings
man page: options or -> |, expand MSI Plessey check digit options
README.linux: add packages info
license: add SPDX-License-Identifier to touched files
2022-06-09 23:52:02 +03:00
btnSeqClear - > setEnabled ( false ) ;
2020-10-27 18:21:50 +03:00
} else {
2021-11-23 22:12:48 +03:00
btnSeqExport - > setEnabled ( true ) ;
RMQR: update to ISO/IEC 23941:2022 - R13x77 numeric cclens change 8 -> 7
QRCODE: use stricter interpretation of ZINT_FULL_MULTIBYTE, excluding
certain trailing bytes
libzint: fix some confusing error messages introduced by segment stuff
general: new escape chars \U, \d and \o
backend_qt: fudge rendering of border rectangles due to scaling/translation
rounding errors TODO: better fudge
GUI: foreground/background colours -> text boxes and icon buttons, add swap
button, independently movable picker (NULL parent), preview colour changes,
preview Data Window changes, add clear data (del) buttons, add zap button
and Factory Reset menu option, various other fixes
libzint: remove STATIC_UNLESS_ZINT_TEST, use wrappers
CMake: add find package QtSvg, remove QtXml
manual: split symbology and general specs and sort, move DAFT to 4-state,
UPC/EAN -> EAN/UPC, DataBar -> GS1 DataBar always, expand MAILMARK info,
various other fiddlings
man page: options or -> |, expand MSI Plessey check digit options
README.linux: add packages info
license: add SPDX-License-Identifier to touched files
2022-06-09 23:52:02 +03:00
btnSeqClear - > setEnabled ( true ) ;
2020-10-27 18:21:50 +03:00
}
2009-11-18 01:36:04 +03:00
}
2021-11-25 23:24:02 +03:00
void SequenceWindow : : from_file ( )
2009-11-18 01:36:04 +03:00
{
2017-07-27 12:21:46 +03:00
QSettings settings ;
2021-01-11 21:11:41 +03:00
# if QT_VERSION < 0x60000
2020-10-27 18:11:33 +03:00
settings . setIniCodec ( " UTF-8 " ) ;
2021-01-11 21:11:41 +03:00
# endif
2017-07-27 12:21:46 +03:00
QFileDialog import_dialog ;
QString filename ;
QFile file ;
QByteArray outstream ;
2017-10-23 22:37:52 +03:00
2021-11-23 22:12:48 +03: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-28 23:42:44 +03:00
QDir : : toNativeSeparators ( QDir : : homePath ( ) ) ) . toString ( ) ) ;
2017-10-23 22:37:52 +03:00
2017-07-27 12:21:46 +03:00
if ( import_dialog . exec ( ) ) {
filename = import_dialog . selectedFiles ( ) . at ( 0 ) ;
} else {
return ;
}
2017-10-23 22:37:52 +03:00
2017-07-27 12:21:46 +03:00
file . setFileName ( filename ) ;
2021-11-23 22:12:48 +03:00
if ( ! file . open ( QIODevice : : ReadOnly | QIODevice : : Text ) ) {
2017-07-27 12:21:46 +03:00
QMessageBox : : critical ( this , tr ( " Open Error " ) , tr ( " Could not open selected file. " ) ) ;
return ;
}
outstream = file . readAll ( ) ;
2021-11-23 22:12:48 +03:00
txtSeqPreview - > setPlainText ( QString ( outstream ) ) ;
2017-07-27 12:21:46 +03:00
file . close ( ) ;
2017-10-23 22:37:52 +03:00
2021-11-23 22:12:48 +03:00
settings . setValue ( QSL ( " studio/default_dir " ) , filename . mid ( 0 , filename . lastIndexOf ( QDir : : separator ( ) ) ) ) ;
2009-11-18 01:36:04 +03:00
}
void SequenceWindow : : generate_sequence ( )
{
2021-11-23 22:12:48 +03:00
ExportWindow dlg ( m_bc , txtSeqPreview - > toPlainText ( ) ) ;
2020-10-27 18:21:50 +03:00
dlg . exec ( ) ;
2009-11-18 01:36:04 +03:00
}
RMQR: update to ISO/IEC 23941:2022 - R13x77 numeric cclens change 8 -> 7
QRCODE: use stricter interpretation of ZINT_FULL_MULTIBYTE, excluding
certain trailing bytes
libzint: fix some confusing error messages introduced by segment stuff
general: new escape chars \U, \d and \o
backend_qt: fudge rendering of border rectangles due to scaling/translation
rounding errors TODO: better fudge
GUI: foreground/background colours -> text boxes and icon buttons, add swap
button, independently movable picker (NULL parent), preview colour changes,
preview Data Window changes, add clear data (del) buttons, add zap button
and Factory Reset menu option, various other fixes
libzint: remove STATIC_UNLESS_ZINT_TEST, use wrappers
CMake: add find package QtSvg, remove QtXml
manual: split symbology and general specs and sort, move DAFT to 4-state,
UPC/EAN -> EAN/UPC, DataBar -> GS1 DataBar always, expand MAILMARK info,
various other fiddlings
man page: options or -> |, expand MSI Plessey check digit options
README.linux: add packages info
license: add SPDX-License-Identifier to touched files
2022-06-09 23:52:02 +03:00
/* vim: set ts=4 sw=4 et : */