comparison mupdf-source/thirdparty/zint/frontend_qt/cliwindow.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) 2021-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 <QClipboard>
23 #include <QMimeData>
24 #include <QSettings>
25
26 #include "cliwindow.h"
27
28 // Shorthand
29 #define QSL QStringLiteral
30 #define QSEmpty QLatin1String("")
31
32 static const int tempMessageTimeout = 2000;
33
34 CLIWindow::CLIWindow(BarcodeItem *bc, const bool autoHeight, const double heightPerRow,
35 const struct Zint::QZintXdimDpVars* xdimdpVars)
36 : m_bc(bc), m_autoHeight(autoHeight), m_heightPerRow(heightPerRow), m_xdimdpVars(xdimdpVars)
37 {
38 setupUi(this);
39 QSettings settings;
40 #if QT_VERSION < 0x60000
41 settings.setIniCodec("UTF-8");
42 #endif
43
44 QByteArray geometry = settings.value(QSL("studio/cli/window_geometry")).toByteArray();
45 restoreGeometry(geometry);
46
47 #ifdef _WIN32
48 const int index = settings.value(QSL("studio/cli/rad_unix_win"), 1).toInt();
49 #else
50 const int index = settings.value(QSL("studio/cli/rad_unix_win"), 0).toInt();
51 #endif
52 if (index == 1) {
53 radCLIWin->setChecked(true);
54 chkCLINoEXE->setEnabled(true);
55 } else {
56 radCLIUnix->setChecked(true);
57 chkCLINoEXE->setEnabled(false);
58 }
59 chkCLILongOpts->setChecked(settings.value(QSL("studio/cli/chk_long_opts"), 0).toInt() ? true : false);
60 chkCLIBarcodeName->setChecked(settings.value(QSL("studio/cli/chk_barcode_name"), 0).toInt() ? true : false);
61 chkCLINoEXE->setChecked(settings.value(QSL("studio/cli/chk_no_exe"), 0).toInt() ? true : false);
62
63 QIcon copyIcon(QIcon::fromTheme(QSL("edit-copy"), QIcon(QSL(":res/copy.svg"))));
64 QIcon closeIcon(QIcon::fromTheme(QSL("window-close"), QIcon(QSL(":res/x.svg"))));
65 btnCLICopy->setIcon(copyIcon);
66 btnCLIClose->setIcon(closeIcon);
67
68 connect(btnCLIClose, SIGNAL(clicked(bool)), SLOT(close()));
69 connect(btnCLICopy, SIGNAL(clicked(bool)), SLOT(copy_to_clipboard()));
70 connect(radCLIUnix, SIGNAL(toggled(bool)), SLOT(generate_cli()));
71 connect(radCLIWin, SIGNAL(toggled(bool)), SLOT(generate_cli()));
72 connect(chkCLILongOpts, SIGNAL(toggled(bool)), SLOT(generate_cli()));
73 connect(chkCLIBarcodeName, SIGNAL(toggled(bool)), SLOT(generate_cli()));
74 connect(chkCLINoEXE, SIGNAL(toggled(bool)), SLOT(generate_cli()));
75
76 generate_cli();
77 }
78
79 CLIWindow::~CLIWindow()
80 {
81 QSettings settings;
82 #if QT_VERSION < 0x60000
83 settings.setIniCodec("UTF-8");
84 #endif
85 settings.setValue(QSL("studio/cli/window_geometry"), saveGeometry());
86 settings.setValue(QSL("studio/cli/rad_unix_win"), radCLIWin->isChecked() ? 1 : 0);
87 settings.setValue(QSL("studio/cli/chk_long_opts"), chkCLILongOpts->isChecked() ? 1 : 0);
88 settings.setValue(QSL("studio/cli/chk_barcode_name"), chkCLIBarcodeName->isChecked() ? 1 : 0);
89 settings.setValue(QSL("studio/cli/chk_no_exe"), chkCLINoEXE->isChecked() ? 1 : 0);
90 }
91
92 void CLIWindow::copy_to_clipboard()
93 {
94 QClipboard *clipboard = QGuiApplication::clipboard();
95 QMimeData *mdata = new QMimeData;
96 mdata->setData("text/plain", txtCLICmd->toPlainText().toUtf8());
97 clipboard->setMimeData(mdata, QClipboard::Clipboard);
98 statusBarCLI->showMessage(tr("Copied to clipboard"), tempMessageTimeout);
99 }
100
101 void CLIWindow::generate_cli()
102 {
103 bool noEXE = false;
104 if (radCLIWin->isChecked()) {
105 noEXE = chkCLINoEXE->isChecked();
106 chkCLINoEXE->setEnabled(true);
107 } else {
108 chkCLINoEXE->setEnabled(false);
109 }
110 QString cmd = m_bc->bc.getAsCLI(radCLIWin->isChecked(), chkCLILongOpts->isChecked(),
111 chkCLIBarcodeName->isChecked(), noEXE, m_autoHeight, m_heightPerRow, QSEmpty /*outfile*/,
112 m_xdimdpVars);
113
114 txtCLICmd->setPlainText(cmd);
115 statusBarCLI->clearMessage();
116 }
117
118 /* vim: set ts=4 sw=4 et : */