mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
104 lines
3.8 KiB
C++
104 lines
3.8 KiB
C++
|
/*
|
||
|
Zint Barcode Generator - the open source barcode generator
|
||
|
Copyright (C) 2021 Robin Stuart <rstuart114@gmail.com>
|
||
|
|
||
|
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.
|
||
|
*/
|
||
|
/* vim: set ts=4 sw=4 et : */
|
||
|
|
||
|
//#include <QDebug>
|
||
|
#include <QSettings>
|
||
|
#include <QClipboard>
|
||
|
#include <QMimeData>
|
||
|
|
||
|
#include "cliwindow.h"
|
||
|
#include "barcodeitem.h"
|
||
|
#include "mainwindow.h"
|
||
|
|
||
|
// Shorthand
|
||
|
#define QSL QStringLiteral
|
||
|
|
||
|
static const int tempMessageTimeout = 2000;
|
||
|
|
||
|
CLIWindow::CLIWindow(BarcodeItem *bc, const bool autoHeight, const double heightPerRow)
|
||
|
: m_bc(bc), m_autoHeight(autoHeight), m_heightPerRow(heightPerRow)
|
||
|
{
|
||
|
setupUi(this);
|
||
|
QSettings settings;
|
||
|
#if QT_VERSION < 0x60000
|
||
|
settings.setIniCodec("UTF-8");
|
||
|
#endif
|
||
|
|
||
|
QByteArray geometry = settings.value(QSL("studio/cli/window_geometry")).toByteArray();
|
||
|
restoreGeometry(geometry);
|
||
|
|
||
|
#if _WIN32
|
||
|
const int index = settings.value(QSL("studio/cli/rad_unix_win"), 1).toInt();
|
||
|
#else
|
||
|
const int index = settings.value(QSL("studio/cli/rad_unix_win"), 0).toInt();
|
||
|
#endif
|
||
|
if (index == 1) {
|
||
|
radCLIWin->setChecked(true);
|
||
|
} else {
|
||
|
radCLIUnix->setChecked(true);
|
||
|
}
|
||
|
chkCLILongOpts->setChecked(settings.value(QSL("studio/cli/chk_long_opts"), 0).toInt() ? true : false);
|
||
|
chkCLIBarcodeName->setChecked(settings.value(QSL("studio/cli/chk_barcode_name"), 0).toInt() ? true : false);
|
||
|
|
||
|
QIcon copyIcon(QIcon::fromTheme(QSL("edit-copy"), QIcon(QSL(":res/copy.svg"))));
|
||
|
QIcon closeIcon(QIcon::fromTheme(QSL("window-close"), QIcon(QSL(":res/x.svg"))));
|
||
|
btnCLICopy->setIcon(copyIcon);
|
||
|
btnCLIClose->setIcon(closeIcon);
|
||
|
|
||
|
connect(btnCLIClose, SIGNAL( clicked( bool )), SLOT(close()));
|
||
|
connect(btnCLICopy, SIGNAL( clicked( bool )), SLOT(copy_to_clipboard()));
|
||
|
connect(radCLIUnix, SIGNAL(toggled( bool )), SLOT(generate_cli()));
|
||
|
connect(radCLIWin, SIGNAL(toggled( bool )), SLOT(generate_cli()));
|
||
|
connect(chkCLILongOpts, SIGNAL(toggled( bool )), SLOT(generate_cli()));
|
||
|
connect(chkCLIBarcodeName, SIGNAL(toggled( bool )), SLOT(generate_cli()));
|
||
|
|
||
|
generate_cli();
|
||
|
}
|
||
|
|
||
|
CLIWindow::~CLIWindow()
|
||
|
{
|
||
|
QSettings settings;
|
||
|
#if QT_VERSION < 0x60000
|
||
|
settings.setIniCodec("UTF-8");
|
||
|
#endif
|
||
|
settings.setValue(QSL("studio/cli/window_geometry"), saveGeometry());
|
||
|
settings.setValue(QSL("studio/cli/rad_unix_win"), radCLIWin->isChecked() ? 1 : 0);
|
||
|
settings.setValue(QSL("studio/cli/chk_long_opts"), chkCLILongOpts->isChecked() ? 1 : 0);
|
||
|
settings.setValue(QSL("studio/cli/chk_barcode_name"), chkCLIBarcodeName->isChecked() ? 1 : 0);
|
||
|
}
|
||
|
|
||
|
void CLIWindow::copy_to_clipboard()
|
||
|
{
|
||
|
QClipboard *clipboard = QGuiApplication::clipboard();
|
||
|
QMimeData *mdata = new QMimeData;
|
||
|
mdata->setData("text/plain", txtCLICmd->toPlainText().toUtf8());
|
||
|
clipboard->setMimeData(mdata, QClipboard::Clipboard);
|
||
|
statusBarCLI->showMessage(tr("Copied to clipboard"), tempMessageTimeout);
|
||
|
}
|
||
|
|
||
|
void CLIWindow::generate_cli()
|
||
|
{
|
||
|
QString cmd = m_bc->bc.getAsCLI(radCLIWin->isChecked(), chkCLILongOpts->isChecked(),
|
||
|
chkCLIBarcodeName->isChecked(), m_autoHeight, m_heightPerRow);
|
||
|
|
||
|
txtCLICmd->setPlainText(cmd);
|
||
|
statusBarCLI->clearMessage();
|
||
|
}
|