From f215d9cc84db8c5b0d9a858851a437ce376a233d Mon Sep 17 00:00:00 2001 From: hooper114 Date: Sat, 19 Sep 2009 08:13:35 +0000 Subject: [PATCH] Complete sequence dialog and add export dialog. --- frontend_qt4/CMakeLists.txt | 6 +- frontend_qt4/datawindow.cpp | 19 ++++ frontend_qt4/datawindow.h | 19 ++++ frontend_qt4/exportwindow.cpp | 33 +++++++ frontend_qt4/exportwindow.h | 35 +++++++ frontend_qt4/extSequence.ui | 27 +++--- frontend_qt4/sequencewindow.cpp | 162 +++++++++++++++++++++++++++++++- frontend_qt4/sequencewindow.h | 26 +++++ 8 files changed, 310 insertions(+), 17 deletions(-) create mode 100644 frontend_qt4/exportwindow.cpp create mode 100644 frontend_qt4/exportwindow.h diff --git a/frontend_qt4/CMakeLists.txt b/frontend_qt4/CMakeLists.txt index 3f8bd752..335831fb 100644 --- a/frontend_qt4/CMakeLists.txt +++ b/frontend_qt4/CMakeLists.txt @@ -4,10 +4,10 @@ project(zint-qt) include_directories(BEFORE "${CMAKE_SOURCE_DIR}/backend" "${CMAKE_SOURCE_DIR}/backend_qt4") -set(zint-qt_SRCS barcodeitem.cpp main.cpp mainwindow.cpp datawindow.cpp sequencewindow.cpp) -QT4_WRAP_CPP(zint-qt_SRCS mainwindow.h datawindow.h sequencewindow.h) +set(zint-qt_SRCS barcodeitem.cpp main.cpp mainwindow.cpp datawindow.cpp sequencewindow.cpp exportwindow.cpp) +QT4_WRAP_CPP(zint-qt_SRCS mainwindow.h datawindow.h sequencewindow.h exportwindow.h) -QT4_WRAP_UI(zint-qt_SRCS mainWindow.ui extData.ui extSequence.ui) +QT4_WRAP_UI(zint-qt_SRCS mainWindow.ui extData.ui extSequence.ui extExport.ui) # grpAztec.ui grpC39.ui grpDM.ui grpMSICheck.ui # grpC128.ui grpChannel.ui grpMicroPDF.ui grpPDF417.ui # grpC16k.ui grpCodablock.ui grpMQR.ui grpQR.ui diff --git a/frontend_qt4/datawindow.cpp b/frontend_qt4/datawindow.cpp index 58b23465..dc568a5e 100644 --- a/frontend_qt4/datawindow.cpp +++ b/frontend_qt4/datawindow.cpp @@ -1,3 +1,22 @@ +/* + Zint Barcode Generator - the open source barcode generator + Copyright (C) 2009 Robin Stuart + + 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. +*/ + #include #include #include diff --git a/frontend_qt4/datawindow.h b/frontend_qt4/datawindow.h index 2af2bce4..8a6d7ecc 100644 --- a/frontend_qt4/datawindow.h +++ b/frontend_qt4/datawindow.h @@ -1,3 +1,22 @@ +/* + Zint Barcode Generator - the open source barcode generator + Copyright (C) 2009 Robin Stuart + + 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. +*/ + #ifndef DATAWINDOW_H #define DATAWINDOW_H diff --git a/frontend_qt4/exportwindow.cpp b/frontend_qt4/exportwindow.cpp new file mode 100644 index 00000000..6ba29135 --- /dev/null +++ b/frontend_qt4/exportwindow.cpp @@ -0,0 +1,33 @@ +/* + Zint Barcode Generator - the open source barcode generator + Copyright (C) 2009 Robin Stuart + + 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. +*/ + +#include +#include + +#include "exportwindow.h" + +ExportWindow::ExportWindow() +{ + setupUi(this); +} + +ExportWindow::~ExportWindow() +{ + +} diff --git a/frontend_qt4/exportwindow.h b/frontend_qt4/exportwindow.h new file mode 100644 index 00000000..1536f575 --- /dev/null +++ b/frontend_qt4/exportwindow.h @@ -0,0 +1,35 @@ +/* + Zint Barcode Generator - the open source barcode generator + Copyright (C) 2009 Robin Stuart + + 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. +*/ + +#ifndef EXPORTWINDOW_H +#define EXPORTWINDOW_H + +#include "ui_extExport.h" + +class ExportWindow : public QDialog, private Ui::ExportDialog +{ + Q_OBJECT + +public: + ExportWindow(); + ~ExportWindow(); + +}; + +#endif \ No newline at end of file diff --git a/frontend_qt4/extSequence.ui b/frontend_qt4/extSequence.ui index 092be416..2d353a71 100644 --- a/frontend_qt4/extSequence.ui +++ b/frontend_qt4/extSequence.ui @@ -69,18 +69,8 @@ 1 - - - - - 139 - 80 - 111 - 20 - - - - 1 + + true @@ -213,6 +203,19 @@ Generate Bar Codes: + + + + 140 + 80 + 113 + 22 + + + + 1 + + diff --git a/frontend_qt4/sequencewindow.cpp b/frontend_qt4/sequencewindow.cpp index be4e8b2c..ff79de7c 100644 --- a/frontend_qt4/sequencewindow.cpp +++ b/frontend_qt4/sequencewindow.cpp @@ -1,16 +1,44 @@ +/* + Zint Barcode Generator - the open source barcode generator + Copyright (C) 2009 Robin Stuart + + 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. +*/ + #include #include #include +#include #include "sequencewindow.h" -#include +#include "exportwindow.h" SequenceWindow::SequenceWindow() { setupUi(this); - + QValidator *intvalid = new QIntValidator(this); + + 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())); } SequenceWindow::~SequenceWindow() @@ -26,3 +54,133 @@ void SequenceWindow::reset_preview() { txtPreview->clear(); } + +QString SequenceWindow::apply_format(QString raw_number) +{ + QString adjusted, reversed; + QString format; + int format_len, input_len, i, inpos; + char format_char; + QChar format_qchar; + + format = linFormat->text(); + input_len = raw_number.length(); + format_len = format.length(); + + inpos = input_len; + + for(i = format_len; i > 0; i--) { + format_qchar = format[i - 1]; + format_char = format_qchar.toAscii(); + 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; +} + +void SequenceWindow::create_sequence() +{ + 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)) { + return; + } + + for(i = start; i <= stop; i += step) { + part = apply_format(QString::number(i, 10)); + part += '\n'; + outputtext += part; + } + + txtPreview->setPlainText(outputtext); +} + +void SequenceWindow::check_generate() +{ + QString preview_copy; + + preview_copy = txtPreview->toPlainText(); + if(preview_copy.isEmpty()) { + btnExport->setEnabled(false); + } else { + btnExport->setEnabled(true); + } +} + +void SequenceWindow::import() +{ + QString fileName; + QFileDialog fdialog; + QFile file; + char *streamdata; + int streamlen; + QString utfstream; + + fdialog.setFileMode(QFileDialog::ExistingFile); + + if(fdialog.exec()) { + fileName = fdialog.selectedFiles().at(0); + } else { + return; + } + + file.setFileName(fileName); + if(!file.open(QIODevice::ReadOnly)) { + return; + } + + QDataStream input(&file); + streamlen = input.readRawData(streamdata, 7095); + utfstream = streamdata; /* FIXME: Does not take account of encoding scheme of input data */ + txtPreview->setPlainText(utfstream); + file.close(); +} + +void SequenceWindow::generate_sequence() +{ + int returnval; + + ExportWindow dlg; + returnval = dlg.exec(); +} \ No newline at end of file diff --git a/frontend_qt4/sequencewindow.h b/frontend_qt4/sequencewindow.h index eb5f8a20..54d591ab 100644 --- a/frontend_qt4/sequencewindow.h +++ b/frontend_qt4/sequencewindow.h @@ -1,3 +1,22 @@ +/* + Zint Barcode Generator - the open source barcode generator + Copyright (C) 2009 Robin Stuart + + 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. +*/ + #ifndef SEQUENCEWINDOW_H #define SEQUENCEWINDOW_H @@ -11,9 +30,16 @@ public: SequenceWindow(); ~SequenceWindow(); +private: + QString apply_format(QString raw_number); + private slots: void quit_now(); void reset_preview(); + void create_sequence(); + void check_generate(); + void import(); + void generate_sequence(); }; #endif \ No newline at end of file