2009-11-22 18:38:15 +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-22 18:38:15 +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-22 18:38:15 +03:00
2020-10-27 18:21:50 +03:00
//#include <QDebug>
2009-11-22 18:38:15 +03:00
# include <QFileDialog>
# include <QMessageBox>
2021-11-25 23:24:02 +03:00
# include <QRegularExpression>
2024-01-06 01:55:57 +03:00
# include <QSettings>
# include <QStringList>
# include <QUiLoader>
2009-11-22 18:38:15 +03:00
# include "datawindow.h"
2021-11-23 22:12:48 +03:00
// Shorthand
# define QSL QStringLiteral
2021-11-25 23:24:02 +03:00
static const int tempMessageTimeout = 2000 ;
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
DataWindow : : DataWindow ( const QString & input , bool isEscaped , int seg_no ) : Valid ( false ) , Escaped ( false ) ,
m_isEscaped ( isEscaped ) , m_seg_no ( seg_no )
2009-11-22 18:38:15 +03:00
{
2020-10-27 18:21:50 +03:00
setupUi ( this ) ;
2021-11-23 22:12:48 +03:00
QSettings settings ;
# if QT_VERSION < 0x60000
settings . setIniCodec ( " UTF-8 " ) ;
# endif
2009-11-22 18:38:15 +03:00
2021-11-23 22:12:48 +03:00
QByteArray geometry = settings . value ( QSL ( " studio/data/window_geometry " ) ) . toByteArray ( ) ;
restoreGeometry ( geometry ) ;
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
QIcon okIcon ( QIcon ( QSL ( " :res/check.svg " ) ) ) ;
btnCancel - > setIcon ( closeIcon ) ;
btnDataClear - > setIcon ( clearIcon ) ;
btnOK - > setIcon ( okIcon ) ;
2009-11-22 18:38:15 +03:00
2021-11-25 23:24:02 +03:00
if ( isEscaped & & input . contains ( QSL ( " \\ n " ) ) ) {
// Substitute escaped Line Feeds with actual Line Feeds
QString out ;
out . reserve ( input . length ( ) ) ;
int lastPosn = 0 ;
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
QRegularExpression escRE ( QSL ( " \\ \\ (?:[0EabtnvfreGR \\ \\ ]|d[0-9]{3}|o[0-7]{3}|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4} "
" |U[0-9A-Fa-f]{6}) " ) ) ;
2021-11-25 23:24:02 +03:00
QRegularExpressionMatchIterator matchI = escRE . globalMatch ( input ) ;
while ( matchI . hasNext ( ) ) {
QRegularExpressionMatch match = matchI . next ( ) ;
if ( match . captured ( 0 ) = = QSL ( " \\ n " ) ) {
out + = input . mid ( lastPosn , match . capturedStart ( 0 ) - lastPosn ) + ' \n ' ;
lastPosn = match . capturedEnd ( 0 ) ;
}
}
2024-01-25 03:10:34 +03:00
out + = input . mid ( lastPosn ) ;
2021-11-25 23:24:02 +03:00
txtDataInput - > setPlainText ( out ) ;
statusBarData - > showMessage ( tr ( " Converted LFs " ) , tempMessageTimeout ) ;
} else {
txtDataInput - > setPlainText ( input ) ;
}
2020-10-27 18:21:50 +03:00
txtDataInput - > moveCursor ( QTextCursor : : End , QTextCursor : : MoveAnchor ) ;
2017-10-23 22:37:52 +03:00
2024-01-06 01:55:57 +03:00
connect ( btnCancel , SIGNAL ( clicked ( bool ) ) , SLOT ( close ( ) ) ) ;
connect ( btnDataClear , SIGNAL ( clicked ( bool ) ) , SLOT ( clear_data ( ) ) ) ;
connect ( btnOK , SIGNAL ( clicked ( bool ) ) , SLOT ( okay ( ) ) ) ;
connect ( btnFromFile , SIGNAL ( clicked ( bool ) ) , SLOT ( from_file ( ) ) ) ;
connect ( txtDataInput , SIGNAL ( textChanged ( ) ) , this , SLOT ( text_changed ( ) ) ) ;
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
btnDataClear - > setEnabled ( ! txtDataInput - > toPlainText ( ) . isEmpty ( ) ) ;
2009-11-22 18:38:15 +03:00
}
DataWindow : : ~ DataWindow ( )
{
2021-11-23 22:12:48 +03:00
QSettings settings ;
# if QT_VERSION < 0x60000
settings . setIniCodec ( " UTF-8 " ) ;
# endif
settings . setValue ( QSL ( " studio/data/window_geometry " ) , saveGeometry ( ) ) ;
2009-11-22 18:38:15 +03:00
}
void DataWindow : : clear_data ( )
{
2020-10-27 18:21:50 +03:00
txtDataInput - > clear ( ) ;
2009-11-22 18:38:15 +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
void DataWindow : : text_changed ( )
{
bool escaped = m_isEscaped ;
const QString & text = escapedData ( escaped ) ;
btnDataClear - > setEnabled ( ! text . isEmpty ( ) ) ;
emit dataChanged ( text , escaped , m_seg_no ) ;
}
2009-11-22 18:38:15 +03:00
void DataWindow : : okay ( )
{
2021-11-23 22:12:48 +03:00
Valid = 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
DataOutput = escapedData ( Escaped ) ;
close ( ) ;
}
QString DataWindow : : escapedData ( bool & escaped )
{
QString text = txtDataInput - > toPlainText ( ) ;
if ( text . contains ( ' \n ' ) ) {
2021-11-25 23:24:02 +03:00
// Escape Line Feeds
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
text . replace ( ' \n ' , QSL ( " \\ n " ) ) ;
escaped = true ;
2021-11-25 23:24:02 +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
return text ;
2009-11-22 18:38:15 +03:00
}
void DataWindow : : from_file ( )
{
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 open_dialog ;
QString filename ;
QFile file ;
QByteArray outstream ;
2021-11-25 23:24:02 +03:00
open_dialog . setWindowTitle ( " Import File " ) ;
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
open_dialog . setDirectory ( settings . value ( " studio/default_dir " ,
QDir : : toNativeSeparators ( QDir : : homePath ( ) ) ) . toString ( ) ) ;
2017-10-23 22:37:52 +03:00
2017-07-27 12:21:46 +03:00
if ( open_dialog . exec ( ) ) {
filename = open_dialog . selectedFiles ( ) . at ( 0 ) ;
} else {
return ;
}
file . setFileName ( filename ) ;
2021-11-23 22:12:48 +03:00
if ( ! file . open ( QIODevice : : ReadOnly ) ) {
2017-07-27 12:21:46 +03:00
QMessageBox : : critical ( this , tr ( " Open Error " ) , tr ( " Could not open selected file. " ) ) ;
return ;
}
2017-10-23 22:37:52 +03:00
2017-07-27 12:21:46 +03:00
outstream = file . readAll ( ) ;
2017-10-22 12:55:50 +03:00
/* Allow some non-printing (control) characters to be read from file
by converting them to escape sequences */
2021-11-25 23:24:02 +03:00
QString escape_string ( outstream ) ; // Converts to UTF-8 (NOTE: QString can't handle embedded NULs)
QRegularExpression escRE ( QSL ( " [ \\ x04 \\ x07 \\ x08 \\ x09 \\ x0B \\ x0C \\ x0D \\ x1B \\ x1D \\ x1E \\ x5C] " ) ) ;
if ( escape_string . contains ( escRE ) ) {
escape_string . replace ( ( QChar ) ' \\ ' , QSL ( " \\ \\ " ) ) ;
escape_string . replace ( ( QChar ) 0x04 , QSL ( " \\ E " ) ) ; /* End of Transmission */
escape_string . replace ( ( QChar ) ' \a ' , QSL ( " \\ a " ) ) ; /* Bell (0x07) */
escape_string . replace ( ( QChar ) ' \b ' , QSL ( " \\ b " ) ) ; /* Backspace (0x08) */
escape_string . replace ( ( QChar ) ' \t ' , QSL ( " \\ t " ) ) ; /* Horizontal tab (0x09) */
// Leaving Line Feed (0x0A)
escape_string . replace ( ( QChar ) ' \v ' , QSL ( " \\ v " ) ) ; /* Vertical tab (0x0B) */
escape_string . replace ( ( QChar ) ' \f ' , QSL ( " \\ f " ) ) ; /* Form feed (0x0C) */
escape_string . replace ( ( QChar ) ' \r ' , QSL ( " \\ r " ) ) ; /* Carriage return (0x0D) */
escape_string . replace ( ( QChar ) 0x1b , QSL ( " \\ e " ) ) ; /* Escape */
escape_string . replace ( ( QChar ) 0x1d , QSL ( " \\ G " ) ) ; /* Group Separator */
escape_string . replace ( ( QChar ) 0x1e , QSL ( " \\ R " ) ) ; /* Record Separator */
Escaped = true ;
statusBarData - > showMessage ( tr ( " Escaped data " ) , tempMessageTimeout ) ;
}
txtDataInput - > setPlainText ( escape_string ) ;
2017-07-27 12:21:46 +03:00
file . close ( ) ;
2017-10-23 22:37:52 +03:00
2017-07-27 12:21:46 +03:00
settings . setValue ( " studio/default_dir " , filename . mid ( 0 , filename . lastIndexOf ( QDir : : separator ( ) ) ) ) ;
2017-10-23 22:37:52 +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 : */