Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zint/frontend_qt/sequencewindow.cpp @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /* | |
| 2 Zint Barcode Generator - the open source barcode generator | |
| 3 Copyright (C) 2009-2024 Robin Stuart <rstuart114@gmail.com> | |
| 4 | |
| 5 This program is free software; you can redistribute it and/or modify | |
| 6 it under the terms of the GNU General Public License as published by | |
| 7 the Free Software Foundation; either version 3 of the License, or | |
| 8 (at your option) any later version. | |
| 9 | |
| 10 This program is distributed in the hope that it will be useful, | |
| 11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 GNU General Public License for more details. | |
| 14 | |
| 15 You should have received a copy of the GNU General Public License along | |
| 16 with this program; if not, write to the Free Software Foundation, Inc., | |
| 17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 18 */ | |
| 19 /* SPDX-License-Identifier: GPL-3.0-or-later */ | |
| 20 | |
| 21 //#include <QDebug> | |
| 22 #include <QFile> | |
| 23 #include <QFileDialog> | |
| 24 #include <QMessageBox> | |
| 25 #include <QSettings> | |
| 26 #include <QUiLoader> | |
| 27 | |
| 28 #include "sequencewindow.h" | |
| 29 #include "exportwindow.h" | |
| 30 | |
| 31 // Shorthand | |
| 32 #define QSL QStringLiteral | |
| 33 #define QSEmpty QLatin1String("") | |
| 34 | |
| 35 SequenceWindow::SequenceWindow(BarcodeItem *bc) : m_bc(bc) | |
| 36 { | |
| 37 setupUi(this); | |
| 38 QSettings settings; | |
| 39 #if QT_VERSION < 0x60000 | |
| 40 settings.setIniCodec("UTF-8"); | |
| 41 #endif | |
| 42 | |
| 43 QByteArray geometry = settings.value(QSL("studio/sequence/window_geometry")).toByteArray(); | |
| 44 restoreGeometry(geometry); | |
| 45 | |
| 46 spnSeqStartVal->setValue(settings.value(QSL("studio/sequence/start_value"), 1).toInt()); | |
| 47 spnSeqEndVal->setValue(settings.value(QSL("studio/sequence/end_value"), 10).toInt()); | |
| 48 spnSeqIncVal->setValue(settings.value(QSL("studio/sequence/increment"), 1).toInt()); | |
| 49 linSeqFormat->setText(settings.value(QSL("studio/sequence/format"), QSL("$$$$$$")).toString()); | |
| 50 txtSeqPreview->setPlainText(settings.value(QSL("studio/sequence/preview"), QSEmpty).toString()); | |
| 51 | |
| 52 QIcon closeIcon(QIcon::fromTheme(QSL("window-close"), QIcon(QSL(":res/x.svg")))); | |
| 53 QIcon clearIcon(QSL(":res/delete.svg")); | |
| 54 btnSeqClose->setIcon(closeIcon); | |
| 55 btnSeqClear->setIcon(clearIcon); | |
| 56 check_generate(); | |
| 57 | |
| 58 connect(btnSeqClose, SIGNAL(clicked(bool)), SLOT(close())); | |
| 59 connect(btnSeqClear, SIGNAL(clicked(bool)), SLOT(clear_preview())); | |
| 60 connect(btnSeqCreate, SIGNAL(clicked(bool)), SLOT(create_sequence())); | |
| 61 connect(txtSeqPreview, SIGNAL(textChanged()), SLOT(check_generate())); | |
| 62 connect(btnSeqFromFile, SIGNAL(clicked(bool)), SLOT(from_file())); | |
| 63 connect(btnSeqExport, SIGNAL(clicked(bool)), SLOT(generate_sequence())); | |
| 64 } | |
| 65 | |
| 66 SequenceWindow::~SequenceWindow() | |
| 67 { | |
| 68 QSettings settings; | |
| 69 #if QT_VERSION < 0x60000 | |
| 70 settings.setIniCodec("UTF-8"); | |
| 71 #endif | |
| 72 settings.setValue(QSL("studio/sequence/window_geometry"), saveGeometry()); | |
| 73 | |
| 74 settings.setValue(QSL("studio/sequence/start_value"), spnSeqStartVal->value()); | |
| 75 settings.setValue(QSL("studio/sequence/end_value"), spnSeqEndVal->value()); | |
| 76 settings.setValue(QSL("studio/sequence/increment"), spnSeqIncVal->value()); | |
| 77 settings.setValue(QSL("studio/sequence/format"), linSeqFormat->text()); | |
| 78 settings.setValue(QSL("studio/sequence/preview"), txtSeqPreview->toPlainText()); | |
| 79 } | |
| 80 | |
| 81 void SequenceWindow::clear_preview() | |
| 82 { | |
| 83 txtSeqPreview->clear(); | |
| 84 } | |
| 85 | |
| 86 QString SequenceWindow::apply_format(const QString& raw_number) | |
| 87 { | |
| 88 QString adjusted, reversed; | |
| 89 QString format; | |
| 90 int format_len, input_len, i, inpos; | |
| 91 QChar format_qchar; | |
| 92 | |
| 93 format = linSeqFormat->text(); | |
| 94 input_len = raw_number.length(); | |
| 95 format_len = format.length(); | |
| 96 | |
| 97 inpos = input_len; | |
| 98 | |
| 99 for (i = format_len; i > 0; i--) { | |
| 100 format_qchar = format[i - 1]; | |
| 101 char format_char = format_qchar.toLatin1(); | |
| 102 switch (format_char) { | |
| 103 case '#': | |
| 104 if (inpos > 0) { | |
| 105 adjusted += raw_number[inpos - 1]; | |
| 106 inpos--; | |
| 107 } else { | |
| 108 adjusted += ' '; | |
| 109 } | |
| 110 break; | |
| 111 case '$': | |
| 112 if (inpos > 0) { | |
| 113 adjusted += raw_number[inpos - 1]; | |
| 114 inpos--; | |
| 115 } else { | |
| 116 adjusted += '0'; | |
| 117 } | |
| 118 break; | |
| 119 case '*': | |
| 120 if (inpos > 0) { | |
| 121 adjusted += raw_number[inpos - 1]; | |
| 122 inpos--; | |
| 123 } else { | |
| 124 adjusted += '*'; | |
| 125 } | |
| 126 break; | |
| 127 default: | |
| 128 adjusted += format_char; | |
| 129 break; | |
| 130 } | |
| 131 } | |
| 132 | |
| 133 for (i = format_len; i > 0; i--) { | |
| 134 reversed += adjusted[i - 1]; | |
| 135 } | |
| 136 | |
| 137 return reversed; | |
| 138 } | |
| 139 | |
| 140 void SequenceWindow::create_sequence() | |
| 141 { | |
| 142 QStringList outputtext; | |
| 143 int start, stop, step, i; | |
| 144 | |
| 145 start = spnSeqStartVal->value(); | |
| 146 stop = spnSeqEndVal->value(); | |
| 147 step = spnSeqIncVal->value(); | |
| 148 | |
| 149 if (stop < start) { | |
| 150 QMessageBox::critical(this, tr("Sequence Error"), | |
| 151 tr("End Value must be greater than or equal to Start Value.")); | |
| 152 return; | |
| 153 } | |
| 154 if ((stop - start) / step > 10000) { | |
| 155 QMessageBox::critical(this, tr("Sequence Error"), tr("The maximum sequence allowed is 10,000 items.")); | |
| 156 return; | |
| 157 } | |
| 158 | |
| 159 for (i = start; i <= stop; i += step) { | |
| 160 outputtext << apply_format(QString::number(i, 10)); | |
| 161 } | |
| 162 | |
| 163 txtSeqPreview->setPlainText(outputtext.join('\n')); | |
| 164 } | |
| 165 | |
| 166 void SequenceWindow::check_generate() | |
| 167 { | |
| 168 QString preview_copy; | |
| 169 | |
| 170 preview_copy = txtSeqPreview->toPlainText(); | |
| 171 if (preview_copy.isEmpty()) { | |
| 172 btnSeqExport->setEnabled(false); | |
| 173 btnSeqClear->setEnabled(false); | |
| 174 } else { | |
| 175 btnSeqExport->setEnabled(true); | |
| 176 btnSeqClear->setEnabled(true); | |
| 177 } | |
| 178 } | |
| 179 | |
| 180 void SequenceWindow::from_file() | |
| 181 { | |
| 182 QSettings settings; | |
| 183 #if QT_VERSION < 0x60000 | |
| 184 settings.setIniCodec("UTF-8"); | |
| 185 #endif | |
| 186 QFileDialog import_dialog; | |
| 187 QString filename; | |
| 188 QFile file; | |
| 189 QByteArray outstream; | |
| 190 | |
| 191 import_dialog.setWindowTitle(tr("Import File")); | |
| 192 import_dialog.setDirectory(settings.value(QSL("studio/default_dir"), | |
| 193 QDir::toNativeSeparators(QDir::homePath())).toString()); | |
| 194 | |
| 195 if (import_dialog.exec()) { | |
| 196 filename = import_dialog.selectedFiles().at(0); | |
| 197 } else { | |
| 198 return; | |
| 199 } | |
| 200 | |
| 201 file.setFileName(filename); | |
| 202 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { | |
| 203 QMessageBox::critical(this, tr("Open Error"), tr("Could not open selected file.")); | |
| 204 return; | |
| 205 } | |
| 206 | |
| 207 outstream = file.readAll(); | |
| 208 | |
| 209 txtSeqPreview->setPlainText(QString(outstream)); | |
| 210 file.close(); | |
| 211 | |
| 212 settings.setValue(QSL("studio/default_dir"), filename.mid(0, filename.lastIndexOf(QDir::separator()))); | |
| 213 } | |
| 214 | |
| 215 void SequenceWindow::generate_sequence() | |
| 216 { | |
| 217 ExportWindow dlg(m_bc, txtSeqPreview->toPlainText()); | |
| 218 dlg.exec(); | |
| 219 } | |
| 220 | |
| 221 /* vim: set ts=4 sw=4 et : */ |
