Restructuring directory layout. Move towards "Modern CMake" usage.
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "AboutDialog.h"
|
||||
|
||||
#include "Version.h"
|
||||
#include "model/Version.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
@@ -38,7 +38,7 @@ namespace glabels
|
||||
{
|
||||
setupUi( this );
|
||||
|
||||
QString version = tr("Version") + " " + Version::STRING;
|
||||
QString version = tr("Version") + " " + model::Version::STRING;
|
||||
|
||||
QString description = tr("A program to create labels and business cards.");
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace glabels
|
||||
///
|
||||
void AboutDialog::onWebsiteButtonClicked()
|
||||
{
|
||||
QDesktopServices::openUrl( QUrl(Version::WEBSITE) );
|
||||
QDesktopServices::openUrl( QUrl(model::Version::WEBSITE) );
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
|
||||
@@ -1,528 +0,0 @@
|
||||
/* BarcodeBackends.cpp
|
||||
*
|
||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "BarcodeBackends.h"
|
||||
|
||||
#include "glbarcode/Factory.h"
|
||||
|
||||
#include "BarcodeBackends/GnuBarcode.h"
|
||||
#include "BarcodeBackends/QrEncode.h"
|
||||
#include "BarcodeBackends/Zint.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
//
|
||||
// Static data
|
||||
//
|
||||
QStringList BarcodeBackends::mBackendIdList;
|
||||
QMap<QString,QString> BarcodeBackends::mBackendNameMap;
|
||||
|
||||
QList<BarcodeStyle> BarcodeBackends::mStyleList;
|
||||
|
||||
|
||||
BarcodeBackends::BarcodeBackends()
|
||||
{
|
||||
registerStyle( "code39", "", tr("Code 39"),
|
||||
true, true, true, true, "1234567890", true, 10 );
|
||||
|
||||
registerStyle( "code39ext", "", tr("Code 39 Extended"),
|
||||
true, true, true, true, "1234567890", true, 10 );
|
||||
|
||||
registerStyle( "upc-a", "", tr("UPC-A"),
|
||||
true, false, true, false, "12345678901", false, 11 );
|
||||
|
||||
registerStyle( "ean-13", "", tr("EAN-13"),
|
||||
true, false, true, false, "123456789012", false, 12 );
|
||||
|
||||
registerStyle( "postnet", "", tr("POSTNET (any)"),
|
||||
false, false, true, false, "12345-6789-12", false, 11 );
|
||||
|
||||
registerStyle( "postnet-5", "", tr("POSTNET-5 (ZIP only)"),
|
||||
false, false, true, false, "12345", false, 5 );
|
||||
|
||||
registerStyle( "postnet-9", "", tr("POSTNET-9 (ZIP+4)"),
|
||||
false, false, true, false, "12345-6789", false, 9 );
|
||||
|
||||
registerStyle( "postnet-11", "", tr("POSTNET-11 (DPBC)"),
|
||||
false, false, true, false, "12345-6789-12", false, 11 );
|
||||
|
||||
registerStyle( "cepnet", "", tr("CEPNET"),
|
||||
false, false, true, false, "12345-678", false, 8 );
|
||||
|
||||
registerStyle( "onecode", "", tr("USPS Intelligent Mail"),
|
||||
false, false, true, false, "12345678901234567890", false, 20 );
|
||||
|
||||
registerStyle( "datamatrix", "", tr("IEC16022 (DataMatrix)"),
|
||||
false, false, true, false, "1234567890AB", false, 12 );
|
||||
|
||||
#if HAVE_GNU_BARCODE
|
||||
//
|
||||
// GNU Barcode backend
|
||||
//
|
||||
registerBackend( "gnu-barcode", "GNU Barcode" );
|
||||
|
||||
glbarcode::Factory::registerType( "gnu-barcode::ean", GnuBarcode::Ean::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::ean-8", GnuBarcode::Ean8::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::ean-8+2", GnuBarcode::Ean8_2::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::ean-8+5", GnuBarcode::Ean8_5::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::ean-13", GnuBarcode::Ean13::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::ean-13+2", GnuBarcode::Ean13_2::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::ean-13+5", GnuBarcode::Ean13_5::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::upc", GnuBarcode::Upc::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::upc-a", GnuBarcode::UpcA::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::upc-a+2", GnuBarcode::UpcA_2::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::upc-a+5", GnuBarcode::UpcA_5::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::upc-e", GnuBarcode::UpcE::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::upc-e+2", GnuBarcode::UpcE_2::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::upc-e+5", GnuBarcode::UpcE_5::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::isbn", GnuBarcode::Isbn::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::isbn+5", GnuBarcode::Isbn_5::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::code39", GnuBarcode::Code39::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::code128", GnuBarcode::Code128::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::code128c", GnuBarcode::Code128C::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::code128b", GnuBarcode::Code128B::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::i25", GnuBarcode::I25::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::cbr", GnuBarcode::Cbr::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::msi", GnuBarcode::Msi::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::pls", GnuBarcode::Pls::create );
|
||||
glbarcode::Factory::registerType( "gnu-barcode::code93", GnuBarcode::Code93::create );
|
||||
|
||||
registerStyle( "ean", "gnu-barcode", tr("EAN (any)"),
|
||||
true, true, true, false, "000000000000 00000", false, 17 );
|
||||
registerStyle( "ean-8", "gnu-barcode", tr("EAN-8"),
|
||||
true, true, true, false, "0000000", false, 7 );
|
||||
registerStyle( "ean-8+2", "gnu-barcode", tr("EAN-8+2"),
|
||||
true, true, true, false, "0000000 00", false, 9 );
|
||||
registerStyle( "ean-8+5", "gnu-barcode", tr("EAN-8+5"),
|
||||
true, true, true, false, "0000000 00000", false, 12 );
|
||||
registerStyle( "ean-13", "gnu-barcode", tr("EAN-13"),
|
||||
true, true, true, false, "000000000000", false, 12 );
|
||||
registerStyle( "ean-13+2", "gnu-barcode", tr("EAN-13+2"),
|
||||
true, true, true, false, "000000000000 00", false, 14 );
|
||||
registerStyle( "ean-13+5", "gnu-barcode", tr("EAN-13+5"),
|
||||
true, true, true, false, "000000000000 00000", false, 17 );
|
||||
registerStyle( "upc", "gnu-barcode", tr("UPC (UPC-A or UPC-E)"),
|
||||
true, true, true, false, "00000000000 00000", false, 16 );
|
||||
registerStyle( "upc-a", "gnu-barcode", tr("UPC-A"),
|
||||
true, true, true, false, "00000000000", false, 11 );
|
||||
registerStyle( "upc-a+2", "gnu-barcode", tr("UPC-A +2"),
|
||||
true, true, true, false, "00000000000 00", false, 13 );
|
||||
registerStyle( "upc-a+5", "gnu-barcode", tr("UPC-A +5"),
|
||||
true, true, true, false, "00000000000 00000", false, 16 );
|
||||
registerStyle( "upc-e", "gnu-barcode", tr("UPC-E"),
|
||||
true, true, true, false, "000000", false, 6 );
|
||||
registerStyle( "upc-e+2", "gnu-barcode", tr("UPC-E +2"),
|
||||
true, true, true, false, "000000 00", false, 8 );
|
||||
registerStyle( "upc-e+5", "gnu-barcode", tr("UPC-E +5"),
|
||||
true, true, true, false, "000000 00000", false, 11 );
|
||||
registerStyle( "isbn", "gnu-barcode", tr("ISBN"),
|
||||
true, true, true, true, "0-00000-000-0", false, 10 );
|
||||
registerStyle( "isbn+5", "gnu-barcode", tr("ISBN +5"),
|
||||
true, true, true, true, "0-00000-000-0 00000", false, 15 );
|
||||
registerStyle( "code39", "gnu-barcode", tr("Code 39"),
|
||||
true, true, true, true, "0000000000", true, 10 );
|
||||
registerStyle( "code128", "gnu-barcode", tr("Code 128"),
|
||||
true, true, true, true, "0000000000", true, 10 );
|
||||
registerStyle( "code128c", "gnu-barcode", tr("Code 128C"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
registerStyle( "code128b", "gnu-barcode", tr("Code 128B"),
|
||||
true, true, true, true, "0000000000", true, 10 );
|
||||
registerStyle( "i25", "gnu-barcode", tr("Interleaved 2 of 5"),
|
||||
true, true, true, true, "0000000000", true, 10 );
|
||||
registerStyle( "cbr", "gnu-barcode", tr("Codabar"),
|
||||
true, true, true, true, "0000000000", true, 10 );
|
||||
registerStyle( "msi", "gnu-barcode", tr("MSI"),
|
||||
true, true, true, true, "0000000000", true, 10 );
|
||||
registerStyle( "pls", "gnu-barcode", tr("Plessey"),
|
||||
true, true, true, true, "0000000000", true, 10 );
|
||||
registerStyle( "code93", "gnu-barcode", tr("Code 93"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
#endif // HAVE_GNU_BARCODE
|
||||
|
||||
#if HAVE_QRENCODE
|
||||
//
|
||||
// Libqrencode backend
|
||||
//
|
||||
registerBackend( "qrencode", "QREncode" );
|
||||
|
||||
glbarcode::Factory::registerType( "qrencode::qrcode", QrEncode::QrCode::create );
|
||||
|
||||
registerStyle( "qrcode", "qrencode", tr("IEC18004 (QRCode)"),
|
||||
false, false, true, false, "1234567890AB", false, 12 );
|
||||
#endif // HAVE_QRENCODE
|
||||
|
||||
#if HAVE_ZINT
|
||||
//
|
||||
// Zint barcode backend
|
||||
//
|
||||
registerBackend( "zint", "Zint" );
|
||||
|
||||
glbarcode::Factory::registerType( "zint::ausp", Zint::AusP::create );
|
||||
glbarcode::Factory::registerType( "zint::ausrp", Zint::AusRP::create );
|
||||
glbarcode::Factory::registerType( "zint::ausrt", Zint::AusRT::create );
|
||||
glbarcode::Factory::registerType( "zint::ausrd", Zint::AusRD::create );
|
||||
glbarcode::Factory::registerType( "zint::aztec", Zint::Aztec::create );
|
||||
glbarcode::Factory::registerType( "zint::azrun", Zint::Azrun::create );
|
||||
glbarcode::Factory::registerType( "zint::cbr", Zint::Cbr::create );
|
||||
glbarcode::Factory::registerType( "zint::code1", Zint::Code1::create );
|
||||
glbarcode::Factory::registerType( "zint::code11", Zint::Code11::create );
|
||||
glbarcode::Factory::registerType( "zint::c16k", Zint::C16k::create );
|
||||
glbarcode::Factory::registerType( "zint::c25m", Zint::C25m::create );
|
||||
glbarcode::Factory::registerType( "zint::c25i", Zint::C25i::create );
|
||||
glbarcode::Factory::registerType( "zint::c25dl", Zint::C25dl::create );
|
||||
glbarcode::Factory::registerType( "zint::code32", Zint::Code32::create );
|
||||
glbarcode::Factory::registerType( "zint::code39", Zint::Code39::create );
|
||||
glbarcode::Factory::registerType( "zint::code39e", Zint::Code39e::create );
|
||||
glbarcode::Factory::registerType( "zint::code49", Zint::Code49::create );
|
||||
glbarcode::Factory::registerType( "zint::code93", Zint::Code93::create );
|
||||
glbarcode::Factory::registerType( "zint::code128", Zint::Code128::create );
|
||||
glbarcode::Factory::registerType( "zint::code128b", Zint::Code128b::create );
|
||||
glbarcode::Factory::registerType( "zint::daft", Zint::Daft::create );
|
||||
glbarcode::Factory::registerType( "zint::dmtx", Zint::Dmtx::create );
|
||||
glbarcode::Factory::registerType( "zint::dpl", Zint::Dpl::create );
|
||||
glbarcode::Factory::registerType( "zint::dpi", Zint::Dpi::create );
|
||||
glbarcode::Factory::registerType( "zint::kix", Zint::Kix::create );
|
||||
glbarcode::Factory::registerType( "zint::ean", Zint::Ean::create );
|
||||
glbarcode::Factory::registerType( "zint::gmtx", Zint::Gmtx::create );
|
||||
glbarcode::Factory::registerType( "zint::gs1128", Zint::Gs1128::create );
|
||||
glbarcode::Factory::registerType( "zint::rss14", Zint::Rss14::create );
|
||||
glbarcode::Factory::registerType( "zint::rssltd", Zint::Rssltd::create );
|
||||
glbarcode::Factory::registerType( "zint::rssexp", Zint::Rssexp::create );
|
||||
glbarcode::Factory::registerType( "zint::rsss", Zint::Rsss::create );
|
||||
glbarcode::Factory::registerType( "zint::rssso", Zint::Rssso::create );
|
||||
glbarcode::Factory::registerType( "zint::rssse", Zint::Rssse::create );
|
||||
glbarcode::Factory::registerType( "zint::hibc128", Zint::Hibc128::create );
|
||||
glbarcode::Factory::registerType( "zint::hibc39", Zint::Hibc39::create );
|
||||
glbarcode::Factory::registerType( "zint::hibcdm", Zint::Hibcdm::create );
|
||||
glbarcode::Factory::registerType( "zint::hibcqr", Zint::Hibcqr::create );
|
||||
glbarcode::Factory::registerType( "zint::hibcpdf", Zint::Hibcpdf::create );
|
||||
glbarcode::Factory::registerType( "zint::hibcmpdf", Zint::Hibcmpdf::create );
|
||||
glbarcode::Factory::registerType( "zint::hibcaz", Zint::Hibcaz::create );
|
||||
glbarcode::Factory::registerType( "zint::i25", Zint::I25::create );
|
||||
glbarcode::Factory::registerType( "zint::isbn", Zint::Isbn::create );
|
||||
glbarcode::Factory::registerType( "zint::itf14", Zint::Itf14::create );
|
||||
glbarcode::Factory::registerType( "zint::japan", Zint::Japan::create );
|
||||
glbarcode::Factory::registerType( "zint::korea", Zint::Korea::create );
|
||||
glbarcode::Factory::registerType( "zint::logm", Zint::Logm::create );
|
||||
glbarcode::Factory::registerType( "zint::maxi", Zint::Maxi::create );
|
||||
glbarcode::Factory::registerType( "zint::mpdf", Zint::Mpdf::create );
|
||||
glbarcode::Factory::registerType( "zint::mqr", Zint::Mqr::create );
|
||||
glbarcode::Factory::registerType( "zint::msi", Zint::Msi::create );
|
||||
glbarcode::Factory::registerType( "zint::nve", Zint::Nve::create );
|
||||
glbarcode::Factory::registerType( "zint::pdf", Zint::Pdf::create );
|
||||
glbarcode::Factory::registerType( "zint::pdft", Zint::Pdft::create );
|
||||
glbarcode::Factory::registerType( "zint::plan", Zint::Plan::create );
|
||||
glbarcode::Factory::registerType( "zint::postnet", Zint::Postnet::create );
|
||||
glbarcode::Factory::registerType( "zint::pharma", Zint::Pharma::create );
|
||||
glbarcode::Factory::registerType( "zint::pharma2", Zint::Pharma2::create );
|
||||
glbarcode::Factory::registerType( "zint::pzn", Zint::Pzn::create );
|
||||
glbarcode::Factory::registerType( "zint::qr", Zint::Qr::create );
|
||||
glbarcode::Factory::registerType( "zint::rm4", Zint::Rm4::create );
|
||||
glbarcode::Factory::registerType( "zint::tele", Zint::Tele::create );
|
||||
glbarcode::Factory::registerType( "zint::telex", Zint::Telex::create );
|
||||
glbarcode::Factory::registerType( "zint::upc-a", Zint::UpcA::create );
|
||||
glbarcode::Factory::registerType( "zint::upc-e", Zint::UpcE::create );
|
||||
glbarcode::Factory::registerType( "zint::usps", Zint::Usps::create );
|
||||
glbarcode::Factory::registerType( "zint::pls", Zint::Pls::create );
|
||||
|
||||
registerStyle( "ausp", "zint", tr("Austraila Post Standard"),
|
||||
false, false, true, false, "12345678901234567890123", true, 23 );
|
||||
|
||||
registerStyle( "ausrp", "zint", tr("Australia Post Reply Paid"),
|
||||
false, false, true, false, "12345678", true, 8 );
|
||||
|
||||
registerStyle( "ausrt", "zint", tr("Australia Post Route Code"),
|
||||
false, false, true, false, "12345678", true, 8 );
|
||||
|
||||
registerStyle( "ausrd", "zint", tr("Australia Post Redirect"),
|
||||
false, false, true, false, "12345678", true, 8 );
|
||||
|
||||
registerStyle( "aztec", "zint", tr("Aztec Code"),
|
||||
false, false, true, false, "1234567890", true, 10 );
|
||||
|
||||
registerStyle( "azrun", "zint", tr("Aztec Rune"),
|
||||
false, false, true, false, "255", true, 3 );
|
||||
|
||||
registerStyle( "cbr", "zint", tr("Codabar"),
|
||||
true, true, true, false, "ABCDABCDAB", true, 10 );
|
||||
|
||||
registerStyle( "code1", "zint", tr("Code One"),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "code11", "zint", tr("Code 11"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "c16k", "zint", tr("Code 16K"),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "c25m", "zint", tr("Code 2 of 5 Matrix"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "c25i", "zint", tr("Code 2 of 5 IATA"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "c25dl", "zint", tr("Code 2 of 5 Data Logic"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "code32", "zint", tr("Code 32 (Italian Pharmacode)"),
|
||||
true, true, true, false, "12345678", true, 8 );
|
||||
|
||||
registerStyle( "code39", "zint", tr("Code 39"),
|
||||
true, true, false, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "code39e", "zint", tr("Code 39 Extended"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "code49", "zint", tr("Code 49"),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "code93", "zint", tr("Code 93"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "code128", "zint", tr("Code 128"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "code128b", "zint", tr("Code 128 (Mode C supression)"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "daft", "zint", tr("DAFT Code"),
|
||||
false, false, false, false, "DAFTDAFTDAFTDAFT", true, 16 );
|
||||
|
||||
registerStyle( "dmtx", "zint", tr("Data Matrix"),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "dpl", "zint", tr("Deutsche Post Leitcode"),
|
||||
true, true, true, false, "1234567890123", true, 13 );
|
||||
|
||||
registerStyle( "dpi", "zint", tr("Deutsche Post Identcode"),
|
||||
true, true, true, false, "12345678901", true, 11 );
|
||||
|
||||
registerStyle( "kix", "zint", tr("Dutch Post KIX Code"),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "ean", "zint", tr("EAN"),
|
||||
true, true, true, false, "1234567890123", false, 13 );
|
||||
|
||||
registerStyle( "gmtx", "zint", tr("Grid Matrix"),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "gs1-128", "zint", tr("GS1-128"),
|
||||
true, true, true, false, "[01]12345678901234", false, 18 );
|
||||
|
||||
registerStyle( "rss14", "zint", tr("GS1 DataBar-14"),
|
||||
true, true, true, false, "1234567890123", true, 13 );
|
||||
|
||||
registerStyle( "rssltd", "zint", "GS1 DataBar-14 Limited",
|
||||
true, true, true, false, "1234567890123", true, 13 );
|
||||
|
||||
registerStyle( "rssexp", "zint", "GS1 DataBar Extended",
|
||||
true, true, true, false, "[01]12345678901234", false, 18 );
|
||||
|
||||
registerStyle( "rsss", "zint", tr("GS1 DataBar-14 Stacked"),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "rssso", "zint", tr("GS1 DataBar-14 Stacked Omni."),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "rssse", "zint", tr("GS1 DataBar Extended Stacked"),
|
||||
false, false, true, false, "[01]12345678901234", false, 18 );
|
||||
|
||||
registerStyle( "hibc128", "zint", tr("HIBC Code 128"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "hibc39", "zint", tr("HIBC Code 39"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "hibcdm", "zint", tr("HIBC Data Matrix"),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "hibcqr", "zint", tr("HIBC QR Code"),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "hibcpdf", "zint", tr("HIBC PDF417"),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "hibcmpdf", "zint", tr("HIBC Micro PDF417"),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "hibcaz", "zint", tr("HIBC Aztec Code"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "i25", "zint", tr("Interleaved 2 of 5"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "isbn", "zint", tr("ISBN"),
|
||||
true, true, true, false, "123456789", false, 9 );
|
||||
|
||||
registerStyle( "itf14", "zint", tr("ITF-14"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "japan", "zint", tr("Japanese Postal"),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "korea", "zint", tr("Korean Postal"),
|
||||
true, true, true, false, "123456", false, 6 );
|
||||
|
||||
registerStyle( "logm", "zint", tr("LOGMARS"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "maxi", "zint", tr("Maxicode"),
|
||||
false, false, false, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "mpdf", "zint", tr("Micro PDF417"),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "mqr", "zint", tr("Micro QR Code"),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "msi", "zint", tr("MSI Plessey"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "nve", "zint", tr("NVE-18"),
|
||||
true, true, true, false, "12345678901234567", false, 17 );
|
||||
|
||||
registerStyle( "pdf", "zint", tr("PDF417"),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "pdft", "zint", tr("PDF417 Truncated"),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "plan", "zint", tr("PLANET"),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "postnet", "zint", tr("PostNet"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "pharma", "zint", tr("Pharmacode"),
|
||||
false, false, true, false, "123456", false, 6 );
|
||||
|
||||
registerStyle( "pharma2", "zint", tr("Pharmacode 2-track"),
|
||||
false, false, true, false, "12345678", false, 8 );
|
||||
|
||||
registerStyle( "pzn", "zint", tr("Pharmazentral Nummer (PZN)"),
|
||||
true, true, true, false, "123456", false, 6 );
|
||||
|
||||
registerStyle( "qr", "zint", tr("QR Code"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "rm4", "zint", tr("Royal Mail 4-State"),
|
||||
false, false, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "tele", "zint", tr("Telepen"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "telex", "zint", tr("Telepen Numeric"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
|
||||
registerStyle( "upc-a", "zint", tr("UPC-A"),
|
||||
true, true, true, false, "12345678901", false, 11 );
|
||||
|
||||
registerStyle( "upc-e", "zint", tr("UPC-E"),
|
||||
true, true, true, false, "1234567", false, 7 );
|
||||
|
||||
registerStyle( "usps", "zint", tr("USPS One Code"),
|
||||
false, false, true, false, "12345678901234567890", true, 20 );
|
||||
|
||||
registerStyle( "pls", "zint", tr("UK Plessey"),
|
||||
true, true, true, false, "0000000000", true, 10 );
|
||||
#endif // HAVE_ZINT
|
||||
|
||||
}
|
||||
|
||||
|
||||
void BarcodeBackends::init()
|
||||
{
|
||||
static BarcodeBackends* singletonInstance = nullptr;
|
||||
|
||||
if ( singletonInstance == nullptr )
|
||||
{
|
||||
singletonInstance = new BarcodeBackends();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const QStringList& BarcodeBackends::backendList()
|
||||
{
|
||||
return mBackendIdList;
|
||||
}
|
||||
|
||||
|
||||
QString BarcodeBackends::backendName( const QString& backendId )
|
||||
{
|
||||
return mBackendNameMap[ backendId ];
|
||||
}
|
||||
|
||||
|
||||
const QList<BarcodeStyle>& BarcodeBackends::styleList()
|
||||
{
|
||||
return mStyleList;
|
||||
}
|
||||
|
||||
|
||||
const BarcodeStyle& BarcodeBackends::defaultStyle()
|
||||
{
|
||||
return mStyleList[0];
|
||||
}
|
||||
|
||||
|
||||
const BarcodeStyle& BarcodeBackends::style( const QString& backendId, const QString& StyleId )
|
||||
{
|
||||
foreach ( const BarcodeStyle& bcStyle, mStyleList )
|
||||
{
|
||||
if ( (bcStyle.backendId() == backendId) && (bcStyle.id() == StyleId) )
|
||||
{
|
||||
return bcStyle;
|
||||
}
|
||||
}
|
||||
|
||||
return defaultStyle();
|
||||
}
|
||||
|
||||
|
||||
void BarcodeBackends::registerBackend( const QString& backendId, const QString& backendName )
|
||||
{
|
||||
mBackendIdList.append( backendId );
|
||||
mBackendNameMap[ backendId ] = backendName;
|
||||
}
|
||||
|
||||
|
||||
void BarcodeBackends::registerStyle( const QString& id,
|
||||
const QString& backendId,
|
||||
const QString& name,
|
||||
bool canText,
|
||||
bool textOptional,
|
||||
bool canChecksum,
|
||||
bool checksumOptional,
|
||||
const QString& defaultDigits,
|
||||
bool canFreeForm,
|
||||
int preferedN )
|
||||
{
|
||||
BarcodeStyle style( id, backendId, name,
|
||||
canText, textOptional,
|
||||
canChecksum, checksumOptional,
|
||||
defaultDigits,
|
||||
canFreeForm, preferedN );
|
||||
|
||||
mStyleList.append( style );
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,95 +0,0 @@
|
||||
/* BarcodeBackends.h
|
||||
*
|
||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef BarcodeBackends_h
|
||||
#define BarcodeBackends_h
|
||||
|
||||
|
||||
#include "BarcodeStyle.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Barcode Backends Database
|
||||
///
|
||||
class BarcodeBackends : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
private:
|
||||
BarcodeBackends();
|
||||
|
||||
public:
|
||||
static void init();
|
||||
|
||||
/////////////////////////////////
|
||||
// Public Methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
static const QStringList& backendList();
|
||||
static QString backendName( const QString& backendId );
|
||||
static const QList<BarcodeStyle>& styleList();
|
||||
static const BarcodeStyle& defaultStyle();
|
||||
static const BarcodeStyle& style( const QString& backendId, const QString& StyleId );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Methods
|
||||
/////////////////////////////////
|
||||
private:
|
||||
static void registerBackend( const QString &backendId, const QString &backendName );
|
||||
|
||||
static void registerStyle( const QString& id,
|
||||
const QString& backendId,
|
||||
const QString& name,
|
||||
bool canText,
|
||||
bool textOptional,
|
||||
bool canChecksum,
|
||||
bool checksumOptional,
|
||||
const QString& defaultDigits,
|
||||
bool canFreeForm,
|
||||
int preferedN );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Members
|
||||
/////////////////////////////////
|
||||
static QStringList mBackendIdList;
|
||||
static QMap<QString,QString> mBackendNameMap;
|
||||
|
||||
static QList<BarcodeStyle> mStyleList;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // BarcodeBackends_h
|
||||
@@ -1,32 +0,0 @@
|
||||
#=======================================
|
||||
# Sources
|
||||
#=======================================
|
||||
set (barcode_sources
|
||||
GnuBarcode.cpp
|
||||
QrEncode.cpp
|
||||
Zint.cpp
|
||||
)
|
||||
|
||||
add_library (Barcode STATIC
|
||||
${barcode_sources}
|
||||
)
|
||||
|
||||
|
||||
#=======================================
|
||||
# Where to find stuff
|
||||
#=======================================
|
||||
include_directories (
|
||||
)
|
||||
|
||||
link_directories (
|
||||
)
|
||||
|
||||
|
||||
#=======================================
|
||||
# Subdirectories
|
||||
#=======================================
|
||||
|
||||
|
||||
#=======================================
|
||||
# Install
|
||||
#=======================================
|
||||
@@ -1,906 +0,0 @@
|
||||
/* GnuBarcode.cpp
|
||||
*
|
||||
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if HAVE_GNU_BARCODE
|
||||
|
||||
#include "GnuBarcode.h"
|
||||
|
||||
#include <QtDebug>
|
||||
#include <barcode.h>
|
||||
#include <cctype>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
const double INK_BLEED = 0.1; /* Shrink bars to account for ink bleed. */
|
||||
const double FONT_SCALE = 0.75; /* Shrink font slightly, otherwise too crowded. */
|
||||
}
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace GnuBarcode
|
||||
{
|
||||
|
||||
bool Base::isAscii( const std::string& data ) const
|
||||
{
|
||||
for ( unsigned int i = 0; i < data.size(); i++ )
|
||||
{
|
||||
if ( (data[i] & 0x80) != 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Base::isNumericLengthValid( const std::string& data,
|
||||
unsigned int nMin,
|
||||
unsigned int nMax ) const
|
||||
{
|
||||
unsigned int n = 0;
|
||||
|
||||
for ( unsigned int i = 0; i < data.size(); i++ )
|
||||
{
|
||||
if ( isdigit(data[i]) )
|
||||
{
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
return (n >= nMin) && (n <= nMax);
|
||||
}
|
||||
|
||||
|
||||
bool Base::isNumericLength1Valid( const std::string& data,
|
||||
unsigned int nMin,
|
||||
unsigned int nMax ) const
|
||||
{
|
||||
unsigned int n = 0;
|
||||
|
||||
for ( unsigned int i = 0; !isspace(data[i]) && (i < data.size()); i++ )
|
||||
{
|
||||
if ( isdigit(data[i]) )
|
||||
{
|
||||
n++;
|
||||
}
|
||||
else if ( !isspace(data[i]) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return (n >= nMin) && (n <= nMax);
|
||||
}
|
||||
|
||||
|
||||
bool Base::isNumericLength2Valid( const std::string& data,
|
||||
unsigned int nMin,
|
||||
unsigned int nMax ) const
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int n = 0;
|
||||
|
||||
for ( i = 0; !isspace(data[i]) && (i < data.size()); i++ )
|
||||
{
|
||||
/* Skip over 1st string */
|
||||
}
|
||||
|
||||
for ( i++ /* skip space */ ; i < data.size(); i++ )
|
||||
{
|
||||
if ( isdigit(data[i]) )
|
||||
{
|
||||
n++;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return (n >= nMin) && (n <= nMax);
|
||||
}
|
||||
|
||||
|
||||
void Base::vectorize( const std::string& encodedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h )
|
||||
{
|
||||
/*
|
||||
* First encode using GNU Barcode library.
|
||||
*/
|
||||
Barcode_Item* bci = Barcode_Create( (char*)cookedData.c_str() );
|
||||
|
||||
bci->scalef = 0;
|
||||
bci->width = (int)w;
|
||||
bci->height = (int)h;
|
||||
|
||||
bci->flags = flags;
|
||||
if ( !showText() )
|
||||
{
|
||||
bci->flags |= BARCODE_NO_ASCII;
|
||||
}
|
||||
if ( !checksum() )
|
||||
{
|
||||
bci->flags |= BARCODE_NO_CHECKSUM;
|
||||
}
|
||||
|
||||
Barcode_Encode( bci, flags );
|
||||
|
||||
if ( (bci->partial == nullptr) || (bci->textinfo == nullptr) )
|
||||
{
|
||||
Barcode_Delete( bci );
|
||||
setIsDataValid( false );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Now do the actual vectorization.
|
||||
*
|
||||
* This code is based on the postscript renderer (ps.c) from the GNU barcode library:
|
||||
*
|
||||
* Copyright (C) 1999 Alessaandro Rubini (rubini@gnu.org)
|
||||
* Copyright (C) 1999 Prosa Srl. (prosa@prosa.it)
|
||||
*/
|
||||
if (bci->width > (2*bci->margin))
|
||||
{
|
||||
bci->width -= 2*bci->margin;
|
||||
}
|
||||
if (bci->height > (2*bci->margin))
|
||||
{
|
||||
bci->height -= 2*bci->margin;
|
||||
}
|
||||
|
||||
/* First calculate barlen */
|
||||
int barlen = bci->partial[0] - '0';
|
||||
for ( int i = 1; bci->partial[i] != 0; i++ )
|
||||
{
|
||||
if ( isdigit(bci->partial[i]) )
|
||||
{
|
||||
barlen += bci->partial[i] - '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( (bci->partial[i] != '+') && (bci->partial[i] != '-') )
|
||||
{
|
||||
barlen += bci->partial[i] - 'a' + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* The scale factor depends on bar length */
|
||||
double scalef = 1;
|
||||
if ( bci->scalef == 0 )
|
||||
{
|
||||
if ( bci->width == 0 )
|
||||
{
|
||||
bci->width = barlen; /* default */
|
||||
}
|
||||
scalef = bci->scalef = (double)bci->width / (double)barlen;
|
||||
if ( scalef < 0.5 )
|
||||
{
|
||||
scalef = 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
/* The width defaults to "just enough" */
|
||||
bci->width = (int)( barlen * scalef + 1 );
|
||||
|
||||
/* But it can be too small, in this case enlarge and center the area */
|
||||
if ( bci->width < (int)(barlen * scalef) )
|
||||
{
|
||||
int wid = (int)( barlen * scalef + 1);
|
||||
bci->xoff -= (wid - bci->width)/2 ;
|
||||
bci->width = wid;
|
||||
/* Can't extend too far on the left */
|
||||
if (bci->xoff < 0)
|
||||
{
|
||||
bci->width += -bci->xoff;
|
||||
bci->xoff = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* The height defaults to 80 points (rescaled) */
|
||||
if ( bci->height == 0 )
|
||||
{
|
||||
bci->height = (int)( 80 * scalef );
|
||||
}
|
||||
|
||||
/* If too small (5 + text), reduce the scale factor and center */
|
||||
int i = 5 + 10 * ( ((bci->flags & BARCODE_NO_ASCII)==0) ? 1 : 0 );
|
||||
if ( bci->height < (int)(i * scalef) )
|
||||
{
|
||||
bci->height = (int)( i * scalef );
|
||||
}
|
||||
|
||||
/* Now traverse the code string and create a list of lines */
|
||||
char mode = '-'; /* text below bars */
|
||||
double x = bci->margin + (bci->partial[0] - '0') * scalef;
|
||||
i = 1;
|
||||
for ( int ip = 1; bci->partial[ip] != 0; ip++, i++)
|
||||
{
|
||||
/* special cases: '+' and '-' */
|
||||
if ( bci->partial[ip] == '+' || bci->partial[ip] == '-' )
|
||||
{
|
||||
mode = bci->partial[ip]; /* don't count it */
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
/* j is the width of this bar/space */
|
||||
int j;
|
||||
if ( isdigit(bci->partial[ip]) )
|
||||
{
|
||||
j = bci->partial[ip] - '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
j = bci->partial[ip] - 'a' + 1;
|
||||
}
|
||||
if ( (i % 2) != 0 )
|
||||
{
|
||||
/* bar */
|
||||
double x0 = x;
|
||||
double y0 = bci->margin;
|
||||
double yr = bci->height;
|
||||
if ( (bci->flags & BARCODE_NO_ASCII) == 0 )
|
||||
{
|
||||
/* leave space for text */
|
||||
if (mode == '-')
|
||||
{
|
||||
/* text below bars: 10 or 5 points */
|
||||
yr -= (isdigit(bci->partial[ip]) ? 10 : 5) * scalef;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* '+' */
|
||||
/* above bars: 10 or 0 from bottom,
|
||||
and 10 from top */
|
||||
y0 += 10 * scalef;
|
||||
yr -= (isdigit(bci->partial[ip]) ? 20 : 10) * scalef;
|
||||
}
|
||||
}
|
||||
addBox( x0, y0, (j * scalef) - INK_BLEED, yr );
|
||||
}
|
||||
x += j * scalef;
|
||||
|
||||
}
|
||||
|
||||
/* Now the text */
|
||||
mode = '-'; /* reinstantiate default */
|
||||
if ( (bci->flags & BARCODE_NO_ASCII) == 0 )
|
||||
{
|
||||
int len = strlen( bci->textinfo );
|
||||
for ( int i = 0; i < len; i++ )
|
||||
{
|
||||
if ( bci->textinfo[i] == ' ' )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ( (bci->textinfo[i] == '+') || (bci->textinfo[i] == '-') )
|
||||
{
|
||||
mode = bci->textinfo[i];
|
||||
continue;
|
||||
}
|
||||
double f1, f2;
|
||||
char c;
|
||||
if ( sscanf( &bci->textinfo[i], "%lf:%lf:%c", &f1, &f2, &c) != 3 )
|
||||
{
|
||||
qDebug() << "Impossible data:" << QString(&bci->textinfo[i]);
|
||||
continue;
|
||||
}
|
||||
f2 *= FONT_SCALE;
|
||||
double x0 = f1*scalef + bci->margin + 0.4*f2*scalef;
|
||||
double y0;
|
||||
if (mode == '-')
|
||||
{
|
||||
y0 = bci->margin + bci->height - 8*scalef + 0.75*f2*scalef;
|
||||
}
|
||||
else
|
||||
{
|
||||
y0 = bci->margin + 0.75*f2*scalef;
|
||||
}
|
||||
addText( x0, y0, f2*scalef, QString(c).toStdString() );
|
||||
|
||||
/* skip past the substring we just read. */
|
||||
while ( (bci->textinfo[i] != ' ') && (bci->textinfo[i] != 0) )
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Fill in other info */
|
||||
w = bci->width + 2.0*bci->margin;
|
||||
h = bci->height + 2.0*bci->margin;
|
||||
|
||||
/* Cleanup */
|
||||
Barcode_Delete( bci );
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// EAN Barcode (Any)
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* Ean::create()
|
||||
{
|
||||
return new Ean();
|
||||
}
|
||||
|
||||
|
||||
bool Ean::validate( const std::string& rawData )
|
||||
{
|
||||
return ( isNumericLengthValid( rawData, 7, 8 )
|
||||
|| isNumericLengthValid( rawData, 12, 13 )
|
||||
|| ( isNumericLength1Valid( rawData, 7, 8 ) && isNumericLength2Valid( rawData, 2, 2 ) )
|
||||
|| ( isNumericLength1Valid( rawData, 7, 8 ) && isNumericLength2Valid( rawData, 5, 5 ) )
|
||||
|| ( isNumericLength1Valid( rawData, 12, 13 ) && isNumericLength2Valid( rawData, 2, 2 ) )
|
||||
|| ( isNumericLength1Valid( rawData, 12, 13 ) && isNumericLength2Valid( rawData, 5, 5 ) ) );
|
||||
}
|
||||
|
||||
|
||||
std::string Ean::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_EAN;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// EAN-8 Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* Ean8::create()
|
||||
{
|
||||
return new Ean8();
|
||||
}
|
||||
|
||||
|
||||
bool Ean8::validate( const std::string& rawData )
|
||||
{
|
||||
return isNumericLengthValid( rawData, 7, 8 );
|
||||
}
|
||||
|
||||
|
||||
std::string Ean8::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_EAN;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// EAN-8+2 Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* Ean8_2::create()
|
||||
{
|
||||
return new Ean8_2();
|
||||
}
|
||||
|
||||
|
||||
bool Ean8_2::validate( const std::string& rawData )
|
||||
{
|
||||
return isNumericLength1Valid( rawData, 7, 8 ) && isNumericLength2Valid( rawData, 2, 2 );
|
||||
}
|
||||
|
||||
|
||||
std::string Ean8_2::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_EAN;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// EAN-8+5 Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* Ean8_5::create()
|
||||
{
|
||||
return new Ean8_5();
|
||||
}
|
||||
|
||||
|
||||
bool Ean8_5::validate( const std::string& rawData )
|
||||
{
|
||||
return isNumericLength1Valid( rawData, 7, 8 ) && isNumericLength2Valid( rawData, 5, 5 );
|
||||
}
|
||||
|
||||
|
||||
std::string Ean8_5::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_EAN;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// EAN-13 Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* Ean13::create()
|
||||
{
|
||||
return new Ean13();
|
||||
}
|
||||
|
||||
|
||||
bool Ean13::validate( const std::string& rawData )
|
||||
{
|
||||
return isNumericLengthValid( rawData, 12, 13 );
|
||||
}
|
||||
|
||||
|
||||
std::string Ean13::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_EAN;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// EAN-13+2 Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* Ean13_2::create()
|
||||
{
|
||||
return new Ean13_2();
|
||||
}
|
||||
|
||||
|
||||
bool Ean13_2::validate( const std::string& rawData )
|
||||
{
|
||||
return isNumericLength1Valid( rawData, 12, 13 ) && isNumericLength2Valid( rawData, 2, 2 );
|
||||
}
|
||||
|
||||
|
||||
std::string Ean13_2::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_EAN;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// EAN-13+5 Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* Ean13_5::create()
|
||||
{
|
||||
return new Ean13_5();
|
||||
}
|
||||
|
||||
|
||||
bool Ean13_5::validate( const std::string& rawData )
|
||||
{
|
||||
return isNumericLength1Valid( rawData, 12, 13 ) && isNumericLength2Valid( rawData, 5, 5 );
|
||||
}
|
||||
|
||||
|
||||
std::string Ean13_5::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_EAN;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// UPC Barcode (Any)
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* Upc::create()
|
||||
{
|
||||
return new Upc();
|
||||
}
|
||||
|
||||
|
||||
bool Upc::validate( const std::string& rawData )
|
||||
{
|
||||
return isNumericLengthValid( rawData, 6, 8 )
|
||||
|| isNumericLengthValid( rawData, 11, 12 )
|
||||
|| (isNumericLength1Valid( rawData, 6, 8 ) && isNumericLength2Valid( rawData, 2, 2 ))
|
||||
|| (isNumericLength1Valid( rawData, 6, 8 ) && isNumericLength2Valid( rawData, 5, 5 ))
|
||||
|| (isNumericLength1Valid( rawData, 11, 12 ) && isNumericLength2Valid( rawData, 2, 2 ))
|
||||
|| (isNumericLength1Valid( rawData, 11, 12 ) && isNumericLength2Valid( rawData, 5, 5 ));
|
||||
}
|
||||
|
||||
|
||||
std::string Upc::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_UPC;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// UPC-A Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* UpcA::create()
|
||||
{
|
||||
return new UpcA();
|
||||
}
|
||||
|
||||
|
||||
bool UpcA::validate( const std::string& rawData )
|
||||
{
|
||||
return isNumericLengthValid( rawData, 11, 12 );
|
||||
}
|
||||
|
||||
|
||||
std::string UpcA::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_UPC;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// UPC-A+2 Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* UpcA_2::create()
|
||||
{
|
||||
return new UpcA_2();
|
||||
}
|
||||
|
||||
|
||||
bool UpcA_2::validate( const std::string& rawData )
|
||||
{
|
||||
return isNumericLength1Valid( rawData, 11, 12 ) && isNumericLength2Valid( rawData, 2, 2 );
|
||||
}
|
||||
|
||||
|
||||
std::string UpcA_2::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_UPC;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// UPC-A+5 Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* UpcA_5::create()
|
||||
{
|
||||
return new UpcA_5();
|
||||
}
|
||||
|
||||
|
||||
bool UpcA_5::validate( const std::string& rawData )
|
||||
{
|
||||
return isNumericLength1Valid( rawData, 11, 12 ) && isNumericLength2Valid( rawData, 5, 5 );
|
||||
}
|
||||
|
||||
|
||||
std::string UpcA_5::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_UPC;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// UPC-E Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* UpcE::create()
|
||||
{
|
||||
return new UpcE();
|
||||
}
|
||||
|
||||
|
||||
bool UpcE::validate( const std::string& rawData )
|
||||
{
|
||||
return isNumericLengthValid( rawData, 6, 8 );
|
||||
}
|
||||
|
||||
|
||||
std::string UpcE::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_UPC;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// UPC-E+2 Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* UpcE_2::create()
|
||||
{
|
||||
return new UpcE_2();
|
||||
}
|
||||
|
||||
|
||||
bool UpcE_2::validate( const std::string& rawData )
|
||||
{
|
||||
return isNumericLength1Valid( rawData, 6, 8 ) && isNumericLength2Valid( rawData, 2, 2 );
|
||||
}
|
||||
|
||||
|
||||
std::string UpcE_2::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_UPC;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// UPC-E+5 Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* UpcE_5::create()
|
||||
{
|
||||
return new UpcE_5();
|
||||
}
|
||||
|
||||
|
||||
bool UpcE_5::validate( const std::string& rawData )
|
||||
{
|
||||
return isNumericLength1Valid( rawData, 6, 8 ) && isNumericLength2Valid( rawData, 5, 5 );
|
||||
}
|
||||
|
||||
|
||||
std::string UpcE_5::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_UPC;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// ISBN Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* Isbn::create()
|
||||
{
|
||||
return new Isbn();
|
||||
}
|
||||
|
||||
|
||||
bool Isbn::validate( const std::string& rawData )
|
||||
{
|
||||
return isNumericLengthValid( rawData, 9, 10 );
|
||||
}
|
||||
|
||||
|
||||
std::string Isbn::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_ISBN;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// ISBN+5 Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* Isbn_5::create()
|
||||
{
|
||||
return new Isbn_5();
|
||||
}
|
||||
|
||||
|
||||
bool Isbn_5::validate( const std::string& rawData )
|
||||
{
|
||||
return isNumericLength1Valid( rawData, 9, 10 ) && isNumericLength2Valid( rawData, 5, 5 );
|
||||
}
|
||||
|
||||
|
||||
std::string Isbn_5::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_ISBN;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Code39 Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* Code39::create()
|
||||
{
|
||||
return new Code39();
|
||||
}
|
||||
|
||||
|
||||
bool Code39::validate( const std::string& rawData )
|
||||
{
|
||||
return isAscii( rawData );
|
||||
}
|
||||
|
||||
|
||||
std::string Code39::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_39;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Code128 Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* Code128::create()
|
||||
{
|
||||
return new Code128();
|
||||
}
|
||||
|
||||
|
||||
bool Code128::validate( const std::string& rawData )
|
||||
{
|
||||
return isAscii( rawData );
|
||||
}
|
||||
|
||||
|
||||
std::string Code128::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_128;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Code128C Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* Code128C::create()
|
||||
{
|
||||
return new Code128C();
|
||||
}
|
||||
|
||||
|
||||
bool Code128C::validate( const std::string& rawData )
|
||||
{
|
||||
return isAscii( rawData );
|
||||
}
|
||||
|
||||
|
||||
std::string Code128C::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_128C;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Code128B Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* Code128B::create()
|
||||
{
|
||||
return new Code128B();
|
||||
}
|
||||
|
||||
|
||||
bool Code128B::validate( const std::string& rawData )
|
||||
{
|
||||
return isAscii( rawData );
|
||||
}
|
||||
|
||||
|
||||
std::string Code128B::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_128B;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// I25 Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* I25::create()
|
||||
{
|
||||
return new I25();
|
||||
}
|
||||
|
||||
|
||||
bool I25::validate( const std::string& rawData )
|
||||
{
|
||||
return isAscii( rawData );
|
||||
}
|
||||
|
||||
|
||||
std::string I25::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_I25;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// CBR Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* Cbr::create()
|
||||
{
|
||||
return new Cbr();
|
||||
}
|
||||
|
||||
|
||||
bool Cbr::validate( const std::string& rawData )
|
||||
{
|
||||
return isAscii( rawData );
|
||||
}
|
||||
|
||||
|
||||
std::string Cbr::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_CBR;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// MSI Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* Msi::create()
|
||||
{
|
||||
return new Msi();
|
||||
}
|
||||
|
||||
|
||||
bool Msi::validate( const std::string& rawData )
|
||||
{
|
||||
return isAscii( rawData );
|
||||
}
|
||||
|
||||
|
||||
std::string Msi::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_MSI;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// PLS Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* Pls::create()
|
||||
{
|
||||
return new Pls();
|
||||
}
|
||||
|
||||
|
||||
bool Pls::validate( const std::string& rawData )
|
||||
{
|
||||
return isAscii( rawData );
|
||||
}
|
||||
|
||||
|
||||
std::string Pls::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_PLS;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Code93 Barcode
|
||||
//////////////////////////////////////////////////////
|
||||
glbarcode::Barcode* Code93::create()
|
||||
{
|
||||
return new Code93();
|
||||
}
|
||||
|
||||
|
||||
bool Code93::validate( const std::string& rawData )
|
||||
{
|
||||
return isAscii( rawData );
|
||||
}
|
||||
|
||||
|
||||
std::string Code93::encode( const std::string& cookedData )
|
||||
{
|
||||
flags = BARCODE_93;
|
||||
return ""; // Actual encoding is done in vectorize
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HAVE_GNU_BARCODE
|
||||
@@ -1,421 +0,0 @@
|
||||
/* GnuBarcode.h
|
||||
*
|
||||
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef barcode_GnuBarcode_h
|
||||
#define barcode_GnuBarcode_h
|
||||
|
||||
#if HAVE_GNU_BARCODE
|
||||
|
||||
#include "glbarcode/Barcode1dBase.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace GnuBarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* GnuBarcode::Base base class for all GNU Barcodes
|
||||
*
|
||||
* Implements glbarcode::Barcode1dBase.
|
||||
*/
|
||||
class Base : public glbarcode::Barcode1dBase
|
||||
{
|
||||
protected:
|
||||
int flags;
|
||||
|
||||
bool isAscii( const std::string& data ) const;
|
||||
|
||||
bool isNumericLengthValid( const std::string& data,
|
||||
unsigned int nMin,
|
||||
unsigned int nMax ) const;
|
||||
|
||||
bool isNumericLength1Valid( const std::string& data,
|
||||
unsigned int nMin,
|
||||
unsigned int nMax ) const;
|
||||
|
||||
bool isNumericLength2Valid( const std::string& data,
|
||||
unsigned int nMin,
|
||||
unsigned int nMax ) const;
|
||||
|
||||
void vectorize( const std::string& encodedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* EAN Barcode (Any)
|
||||
*/
|
||||
class Ean : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* EAN-8 Barcode
|
||||
*/
|
||||
class Ean8 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* EAN-8+2 Barcode
|
||||
*/
|
||||
class Ean8_2 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* EAN-8+5 Barcode
|
||||
*/
|
||||
class Ean8_5 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* EAN-13 Barcode
|
||||
*/
|
||||
class Ean13 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* EAN-13+2 Barcode
|
||||
*/
|
||||
class Ean13_2 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* EAN-13+5 Barcode
|
||||
*/
|
||||
class Ean13_5 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* UPC Barcode (Any)
|
||||
*/
|
||||
class Upc : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* UPC-A Barcode
|
||||
*/
|
||||
class UpcA : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* UPC-A+2 Barcode
|
||||
*/
|
||||
class UpcA_2 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* UPC-A+5 Barcode
|
||||
*/
|
||||
class UpcA_5 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* UPC-E Barcode
|
||||
*/
|
||||
class UpcE : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* UPC-E+2 Barcode
|
||||
*/
|
||||
class UpcE_2 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* UPC-E+5 Barcode
|
||||
*/
|
||||
class UpcE_5 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* ISBN Barcode
|
||||
*/
|
||||
class Isbn : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* ISBN+5 Barcode
|
||||
*/
|
||||
class Isbn_5 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Code39 Barcode
|
||||
*/
|
||||
class Code39 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Code128 Barcode
|
||||
*/
|
||||
class Code128 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Code128C Barcode
|
||||
*/
|
||||
class Code128C : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Code128B Barcode
|
||||
*/
|
||||
class Code128B : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* I25 Barcode
|
||||
*/
|
||||
class I25 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* CBR Barcode
|
||||
*/
|
||||
class Cbr : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* MSI Barcode
|
||||
*/
|
||||
class Msi : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* PLS Barcode
|
||||
*/
|
||||
class Pls : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Code93 Barcode
|
||||
*/
|
||||
class Code93 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // HAVE_GNU_BARCODE
|
||||
|
||||
#endif // barcode_GnuBarcode_h
|
||||
@@ -1,89 +0,0 @@
|
||||
/* QrEncode.cpp
|
||||
*
|
||||
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if HAVE_QRENCODE
|
||||
|
||||
#include "QrEncode.h"
|
||||
|
||||
#include <qrencode.h>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace QrEncode
|
||||
{
|
||||
|
||||
/*
|
||||
* Static QrCode barcode creation method
|
||||
*/
|
||||
glbarcode::Barcode* QrCode::create()
|
||||
{
|
||||
return new QrCode();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* QrCode data validation, implements glbarcode::Barcode2dBase::validate()
|
||||
*/
|
||||
bool QrCode::validate( const std::string& rawData )
|
||||
{
|
||||
if ( rawData.size() == 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* QrCode data encoding, implements glbarcode::Barcode2dBase::encode()
|
||||
*/
|
||||
bool QrCode::encode( const std::string& cookedData, glbarcode::Matrix<bool>& encodedData )
|
||||
{
|
||||
QRcode *qrcode = QRcode_encodeString( cookedData.c_str(), 0, QR_ECLEVEL_M, QR_MODE_8, 1 );
|
||||
if ( qrcode == NULL )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int w = qrcode->width;
|
||||
encodedData.resize( w, w );
|
||||
|
||||
|
||||
for ( int iy = 0; iy < w; iy++ )
|
||||
{
|
||||
for ( int ix = 0; ix < w; ix++ )
|
||||
{
|
||||
encodedData[iy][ix] = qrcode->data[ iy*w + ix ] & 0x01;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QRcode_free( qrcode );
|
||||
QRcode_clearCache();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HAVE_QRENCODE
|
||||
@@ -1,57 +0,0 @@
|
||||
/* QrEncode.h
|
||||
*
|
||||
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef barcode_QrEncode_h
|
||||
#define barcode_QrEncode_h
|
||||
|
||||
#if HAVE_QRENCODE
|
||||
|
||||
#include "glbarcode/Barcode2dBase.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace QrEncode
|
||||
{
|
||||
|
||||
/**
|
||||
* QrEncode::QrCode QR Code Barcode
|
||||
*
|
||||
* Implements glbarcode::Barcode2dBase.
|
||||
*/
|
||||
class QrCode : public glbarcode::Barcode2dBase
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
private:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
|
||||
bool encode( const std::string& cookedData,
|
||||
glbarcode::Matrix<bool>& encodedData ) override;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // HAVE_QRENCODE
|
||||
|
||||
#endif // barcode_QrEncode_h
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,932 +0,0 @@
|
||||
/* Zint.h
|
||||
*
|
||||
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef barcode_Zint_h
|
||||
#define barcode_Zint_h
|
||||
|
||||
#if HAVE_ZINT
|
||||
|
||||
#include "glbarcode/Barcode1dBase.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace Zint
|
||||
{
|
||||
|
||||
/**
|
||||
* Zint::Base base class for all Zint barcodes
|
||||
*
|
||||
* Implements glbarcode::Barcode1dBase.
|
||||
*/
|
||||
class Base : public glbarcode::Barcode1dBase
|
||||
{
|
||||
protected:
|
||||
int symbology;
|
||||
|
||||
|
||||
bool validate( const std::string& rawData ) override;
|
||||
|
||||
void vectorize( const std::string& encodedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* AusP Barcode
|
||||
*/
|
||||
class AusP : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* AusRP Barcode
|
||||
*/
|
||||
class AusRP : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* AusRT Barcode
|
||||
*/
|
||||
class AusRT : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* AusRD Barcode
|
||||
*/
|
||||
class AusRD : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Aztec Barcode
|
||||
*/
|
||||
class Aztec : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Azrun Barcode
|
||||
*/
|
||||
class Azrun : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Cbr Barcode
|
||||
*/
|
||||
class Cbr : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Code1 Barcode
|
||||
*/
|
||||
class Code1 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Code11 Barcode
|
||||
*/
|
||||
class Code11 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* C16k Barcode
|
||||
*/
|
||||
class C16k : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* C25m Barcode
|
||||
*/
|
||||
class C25m : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* C25i Barcode
|
||||
*/
|
||||
class C25i : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* C25dl Barcode
|
||||
*/
|
||||
class C25dl : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Code32 Barcode
|
||||
*/
|
||||
class Code32 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Code39 Barcode
|
||||
*/
|
||||
class Code39 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Code39e Barcode
|
||||
*/
|
||||
class Code39e : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Code49 Barcode
|
||||
*/
|
||||
class Code49 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Code93 Barcode
|
||||
*/
|
||||
class Code93 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Code128 Barcode
|
||||
*/
|
||||
class Code128 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Code128b Barcode
|
||||
*/
|
||||
class Code128b : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Daft Barcode
|
||||
*/
|
||||
class Daft : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Dmtx Barcode
|
||||
*/
|
||||
class Dmtx : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Dpl Barcode
|
||||
*/
|
||||
class Dpl : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Dpi Barcode
|
||||
*/
|
||||
class Dpi : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Kix Barcode
|
||||
*/
|
||||
class Kix : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Ean Barcode
|
||||
*/
|
||||
class Ean : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Hibc128 Barcode
|
||||
*/
|
||||
class Hibc128 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Hibc39 Barcode
|
||||
*/
|
||||
class Hibc39 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Hibcdm Barcode
|
||||
*/
|
||||
class Hibcdm : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Hibcqr Barcode
|
||||
*/
|
||||
class Hibcqr : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Hibcpdf Barcode
|
||||
*/
|
||||
class Hibcpdf : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Hibcmpdf Barcode
|
||||
*/
|
||||
class Hibcmpdf : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Hibcaz Barcode
|
||||
*/
|
||||
class Hibcaz : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* I25 Barcode
|
||||
*/
|
||||
class I25 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Isbn Barcode
|
||||
*/
|
||||
class Isbn : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Itf14 Barcode
|
||||
*/
|
||||
class Itf14 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Gmtx Barcode
|
||||
*/
|
||||
class Gmtx : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Gs1128 Barcode
|
||||
*/
|
||||
class Gs1128 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Logm Barcode
|
||||
*/
|
||||
class Logm : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Rss14 Barcode
|
||||
*/
|
||||
class Rss14 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Rssltd Barcode
|
||||
*/
|
||||
class Rssltd : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Rssexp Barcode
|
||||
*/
|
||||
class Rssexp : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Rsss Barcode
|
||||
*/
|
||||
class Rsss : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Rssso Barcode
|
||||
*/
|
||||
class Rssso : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Rssse Barcode
|
||||
*/
|
||||
class Rssse : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Pharma Barcode
|
||||
*/
|
||||
class Pharma : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Pharma2 Barcode
|
||||
*/
|
||||
class Pharma2 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Pzn Barcode
|
||||
*/
|
||||
class Pzn : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Tele Barcode
|
||||
*/
|
||||
class Tele : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Telex Barcode
|
||||
*/
|
||||
class Telex : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Japan Barcode
|
||||
*/
|
||||
class Japan : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Korea Barcode
|
||||
*/
|
||||
class Korea : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Maxi Barcode
|
||||
*/
|
||||
class Maxi : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Mpdf Barcode
|
||||
*/
|
||||
class Mpdf : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Msi Barcode
|
||||
*/
|
||||
class Msi : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Mqr Barcode
|
||||
*/
|
||||
class Mqr : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Nve Barcode
|
||||
*/
|
||||
class Nve : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Plan Barcode
|
||||
*/
|
||||
class Plan : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Postnet Barcode
|
||||
*/
|
||||
class Postnet : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Pdf Barcode
|
||||
*/
|
||||
class Pdf : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Pdft Barcode
|
||||
*/
|
||||
class Pdft : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Qr Barcode
|
||||
*/
|
||||
class Qr : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Rm4 Barcode
|
||||
*/
|
||||
class Rm4 : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* UpcA Barcode
|
||||
*/
|
||||
class UpcA : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* UpcE Barcode
|
||||
*/
|
||||
class UpcE : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Usps Barcode
|
||||
*/
|
||||
class Usps : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Pls Barcode
|
||||
*/
|
||||
class Pls : public Base
|
||||
{
|
||||
public:
|
||||
static Barcode* create();
|
||||
|
||||
protected:
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // HAVE_ZINT
|
||||
|
||||
#endif // barcode_Zint_h
|
||||
+12
-11
@@ -20,9 +20,10 @@
|
||||
|
||||
#include "BarcodeMenu.h"
|
||||
|
||||
#include "BarcodeBackends.h"
|
||||
#include "BarcodeMenuItem.h"
|
||||
|
||||
#include "barcode/Backends.h"
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
@@ -34,29 +35,29 @@ namespace glabels
|
||||
///
|
||||
BarcodeMenu::BarcodeMenu()
|
||||
{
|
||||
foreach ( const BarcodeStyle& bcStyle, BarcodeBackends::styleList() )
|
||||
foreach ( const barcode::Style& bcStyle, barcode::Backends::styleList() )
|
||||
{
|
||||
if ( bcStyle.backendId() == "" )
|
||||
{
|
||||
BarcodeMenuItem* bcMenuItem = new BarcodeMenuItem( bcStyle );
|
||||
connect( bcMenuItem, SIGNAL(activated(const BarcodeStyle&)),
|
||||
this, SLOT(onMenuItemActivated(const BarcodeStyle&)) );
|
||||
connect( bcMenuItem, SIGNAL(activated(const barcode::Style&)),
|
||||
this, SLOT(onMenuItemActivated(const barcode::Style&)) );
|
||||
|
||||
addAction( bcMenuItem );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( const QString& backendId, BarcodeBackends::backendList() )
|
||||
foreach ( const QString& backendId, barcode::Backends::backendList() )
|
||||
{
|
||||
QMenu* subMenu = addMenu( BarcodeBackends::backendName( backendId ) );
|
||||
QMenu* subMenu = addMenu( barcode::Backends::backendName( backendId ) );
|
||||
|
||||
foreach ( const BarcodeStyle& bcStyle, BarcodeBackends::styleList() )
|
||||
foreach ( const barcode::Style& bcStyle, barcode::Backends::styleList() )
|
||||
{
|
||||
if ( bcStyle.backendId() == backendId )
|
||||
{
|
||||
BarcodeMenuItem* bcMenuItem = new BarcodeMenuItem( bcStyle );
|
||||
connect( bcMenuItem, SIGNAL(activated(const BarcodeStyle&)),
|
||||
this, SLOT(onMenuItemActivated(const BarcodeStyle&)) );
|
||||
connect( bcMenuItem, SIGNAL(activated(const barcode::Style&)),
|
||||
this, SLOT(onMenuItemActivated(const barcode::Style&)) );
|
||||
|
||||
subMenu->addAction( bcMenuItem );
|
||||
}
|
||||
@@ -68,7 +69,7 @@ namespace glabels
|
||||
///
|
||||
/// bcStyle getter
|
||||
///
|
||||
BarcodeStyle BarcodeMenu::bcStyle() const
|
||||
barcode::Style BarcodeMenu::bcStyle() const
|
||||
{
|
||||
return mBcStyle;
|
||||
}
|
||||
@@ -77,7 +78,7 @@ namespace glabels
|
||||
///
|
||||
/// onMenuItemActivated slot
|
||||
///
|
||||
void BarcodeMenu::onMenuItemActivated( const BarcodeStyle& bcStyle )
|
||||
void BarcodeMenu::onMenuItemActivated( const barcode::Style& bcStyle )
|
||||
{
|
||||
mBcStyle = bcStyle;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#define BarcodeMenu_h
|
||||
|
||||
|
||||
#include "BarcodeStyle.h"
|
||||
#include "barcode/Style.h"
|
||||
|
||||
#include <QMenu>
|
||||
|
||||
@@ -55,21 +55,21 @@ namespace glabels
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
BarcodeStyle bcStyle() const;
|
||||
barcode::Style bcStyle() const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Slots
|
||||
/////////////////////////////////
|
||||
private slots:
|
||||
void onMenuItemActivated( const BarcodeStyle& bcStyle );
|
||||
void onMenuItemActivated( const barcode::Style& bcStyle );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
BarcodeStyle mBcStyle;
|
||||
barcode::Style mBcStyle;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -20,9 +20,10 @@
|
||||
|
||||
#include "BarcodeMenuButton.h"
|
||||
|
||||
#include "BarcodeBackends.h"
|
||||
#include "BarcodeMenuItem.h"
|
||||
|
||||
#include "barcode/Backends.h"
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
@@ -38,7 +39,7 @@ namespace glabels
|
||||
mMenu = new BarcodeMenu();
|
||||
setMenu( mMenu );
|
||||
|
||||
mBcStyle = BarcodeBackends::defaultStyle();
|
||||
mBcStyle = barcode::Backends::defaultStyle();
|
||||
setText( mBcStyle.name() );
|
||||
|
||||
connect( mMenu, SIGNAL(selectionChanged()), this, SLOT(onMenuSelectionChanged()) );
|
||||
@@ -48,7 +49,7 @@ namespace glabels
|
||||
///
|
||||
/// bcStyle getter
|
||||
///
|
||||
BarcodeStyle BarcodeMenuButton::bcStyle() const
|
||||
barcode::Style BarcodeMenuButton::bcStyle() const
|
||||
{
|
||||
return mBcStyle;
|
||||
}
|
||||
@@ -57,7 +58,7 @@ namespace glabels
|
||||
///
|
||||
/// bcStyle setter
|
||||
///
|
||||
void BarcodeMenuButton::setBcStyle( const BarcodeStyle& bcStyle )
|
||||
void BarcodeMenuButton::setBcStyle( const barcode::Style& bcStyle )
|
||||
{
|
||||
mBcStyle = bcStyle;
|
||||
setText( mBcStyle.name() );
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
|
||||
|
||||
#include "BarcodeMenu.h"
|
||||
#include "BarcodeStyle.h"
|
||||
|
||||
#include "barcode/Style.h"
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
@@ -56,8 +57,8 @@ namespace glabels
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
BarcodeStyle bcStyle() const;
|
||||
void setBcStyle( const BarcodeStyle& bcStyle );
|
||||
barcode::Style bcStyle() const;
|
||||
void setBcStyle( const barcode::Style& bcStyle );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
@@ -72,7 +73,7 @@ namespace glabels
|
||||
/////////////////////////////////
|
||||
private:
|
||||
BarcodeMenu* mMenu;
|
||||
BarcodeStyle mBcStyle;
|
||||
barcode::Style mBcStyle;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace glabels
|
||||
///
|
||||
/// Constructor From Data
|
||||
///
|
||||
BarcodeMenuItem::BarcodeMenuItem( const BarcodeStyle& bcStyle, QObject* parent )
|
||||
BarcodeMenuItem::BarcodeMenuItem( const barcode::Style& bcStyle, QObject* parent )
|
||||
: QAction(parent), mBcStyle(bcStyle)
|
||||
{
|
||||
setText( bcStyle.name() );
|
||||
@@ -41,7 +41,7 @@ namespace glabels
|
||||
///
|
||||
/// bcStyle Property Getter
|
||||
///
|
||||
BarcodeStyle BarcodeMenuItem::bcStyle() const
|
||||
barcode::Style BarcodeMenuItem::bcStyle() const
|
||||
{
|
||||
return mBcStyle;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#define BarcodeMenuItem_h
|
||||
|
||||
|
||||
#include "BarcodeStyle.h"
|
||||
#include "barcode/Style.h"
|
||||
|
||||
#include <QAction>
|
||||
|
||||
@@ -41,21 +41,21 @@ namespace glabels
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
BarcodeMenuItem( const BarcodeStyle& bcStyle, QObject* parent = nullptr );
|
||||
BarcodeMenuItem( const barcode::Style& bcStyle, QObject* parent = nullptr );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Signals
|
||||
/////////////////////////////////
|
||||
signals:
|
||||
void activated( const BarcodeStyle& bcStyle );
|
||||
void activated( const barcode::Style& bcStyle );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
BarcodeStyle bcStyle() const;
|
||||
barcode::Style bcStyle() const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
@@ -69,7 +69,7 @@ namespace glabels
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
BarcodeStyle mBcStyle;
|
||||
barcode::Style mBcStyle;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,204 +0,0 @@
|
||||
/* BarcodeStyle.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "BarcodeStyle.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Default Constructor
|
||||
///
|
||||
BarcodeStyle::BarcodeStyle ()
|
||||
: mId( "" ),
|
||||
mBackendId( "" ),
|
||||
mName( "" ),
|
||||
mCanText( false ),
|
||||
mTextOptional( false ),
|
||||
mCanChecksum( false ),
|
||||
mChecksumOptional( false ),
|
||||
mDefaultDigits( "" ),
|
||||
mCanFreeform( false ),
|
||||
mPreferedN( 0 )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor From Data
|
||||
///
|
||||
BarcodeStyle::BarcodeStyle ( const QString& id,
|
||||
const QString& backendId,
|
||||
const QString& name,
|
||||
bool canText,
|
||||
bool textOptional,
|
||||
bool canChecksum,
|
||||
bool checksumOptional,
|
||||
const QString& defaultDigits,
|
||||
bool canFreeform,
|
||||
int preferedN )
|
||||
: mId( id ),
|
||||
mBackendId( backendId ),
|
||||
mName( name ),
|
||||
mCanText( canText ),
|
||||
mTextOptional( textOptional ),
|
||||
mCanChecksum( canChecksum ),
|
||||
mChecksumOptional( checksumOptional ),
|
||||
mDefaultDigits( defaultDigits ),
|
||||
mCanFreeform( canFreeform ),
|
||||
mPreferedN( preferedN )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// ID Property Getter
|
||||
///
|
||||
const QString& BarcodeStyle::id() const
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Full ID Property Getter
|
||||
///
|
||||
QString BarcodeStyle::fullId() const
|
||||
{
|
||||
if ( mBackendId == "" )
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
else
|
||||
{
|
||||
return mBackendId + "::" + mId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Backend ID Property Getter
|
||||
///
|
||||
const QString& BarcodeStyle::backendId() const
|
||||
{
|
||||
return mBackendId;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Name Property Getter
|
||||
///
|
||||
const QString& BarcodeStyle::name() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Text Property Getter
|
||||
///
|
||||
bool BarcodeStyle::canText() const
|
||||
{
|
||||
return mCanText;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Text Optional Property Getter
|
||||
///
|
||||
bool BarcodeStyle::textOptional() const
|
||||
{
|
||||
return mTextOptional;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Checksum Property Getter
|
||||
///
|
||||
bool BarcodeStyle::canChecksum() const
|
||||
{
|
||||
return mCanChecksum;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Checksum Optional Property Getter
|
||||
///
|
||||
bool BarcodeStyle::checksumOptional() const
|
||||
{
|
||||
return mChecksumOptional;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Default Digits Property Getter
|
||||
///
|
||||
const QString& BarcodeStyle::defaultDigits() const
|
||||
{
|
||||
return mDefaultDigits;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Freeform Property Getter
|
||||
///
|
||||
bool BarcodeStyle::canFreeform() const
|
||||
{
|
||||
return mCanFreeform;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Prefered N Property Getter
|
||||
///
|
||||
int BarcodeStyle::preferedN() const
|
||||
{
|
||||
return mPreferedN;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Generate Example Digits
|
||||
///
|
||||
QString BarcodeStyle::exampleDigits( int n ) const
|
||||
{
|
||||
if ( mCanFreeform )
|
||||
{
|
||||
return QString( qMax( n, 1 ), QChar('0') );
|
||||
}
|
||||
else
|
||||
{
|
||||
return mDefaultDigits;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// "Not equals" operator
|
||||
///
|
||||
bool BarcodeStyle::operator!=( const BarcodeStyle& other ) const
|
||||
{
|
||||
return mId != other.mId;
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,115 +0,0 @@
|
||||
/* BarcodeStyle.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef BarcodeStyle_h
|
||||
#define BarcodeStyle_h
|
||||
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Barcode Style Type
|
||||
///
|
||||
class BarcodeStyle
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
BarcodeStyle ();
|
||||
|
||||
BarcodeStyle ( const QString& id,
|
||||
const QString& backendId,
|
||||
const QString& name,
|
||||
bool canText,
|
||||
bool textOptional,
|
||||
bool canChecksum,
|
||||
bool checksumOptional,
|
||||
const QString& defaultDigits,
|
||||
bool canFreeform,
|
||||
int preferedN );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
const QString& id() const;
|
||||
|
||||
QString fullId() const;
|
||||
|
||||
const QString& backendId() const;
|
||||
|
||||
const QString& name() const;
|
||||
|
||||
bool canText() const;
|
||||
|
||||
bool textOptional() const;
|
||||
|
||||
bool canChecksum() const;
|
||||
|
||||
bool checksumOptional() const;
|
||||
|
||||
const QString& defaultDigits() const;
|
||||
|
||||
bool canFreeform() const;
|
||||
|
||||
int preferedN() const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
QString exampleDigits( int n ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Operators
|
||||
/////////////////////////////////
|
||||
public:
|
||||
bool operator!=( const BarcodeStyle& other ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
QString mId;
|
||||
QString mBackendId;
|
||||
QString mName;
|
||||
bool mCanText;
|
||||
bool mTextOptional;
|
||||
bool mCanChecksum;
|
||||
bool mChecksumOptional;
|
||||
QString mDefaultDigits;
|
||||
bool mCanFreeform;
|
||||
int mPreferedN;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // BarcodeStyle_h
|
||||
+15
-241
@@ -1,138 +1,45 @@
|
||||
#=======================================
|
||||
# Compilation
|
||||
#=======================================
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
add_compile_options (-std=c++11 -g)
|
||||
if (NOT WIN32)
|
||||
add_compile_options (-fPIC)
|
||||
endif ()
|
||||
|
||||
# Uncomment to build with pedantic flags
|
||||
#add_compile_options (-Werror -Wall -Wpedantic)
|
||||
#add_definitions (-DQT_DISABLE_DEPRECATED_BEFORE=0x050400)
|
||||
|
||||
if (${GNUBARCODE_FOUND})
|
||||
add_definitions (-DHAVE_GNU_BARCODE=1)
|
||||
else (${GNUBARCODE_FOUND})
|
||||
set (GNUBARCODE_INCLUDE_DIR "")
|
||||
set (GNUBARCODE_LIBRARIES "")
|
||||
endif (${GNUBARCODE_FOUND})
|
||||
|
||||
if (${LIBQRENCODE_FOUND})
|
||||
add_definitions (-DHAVE_QRENCODE=1)
|
||||
else (${LIBQRENCODE_FOUND})
|
||||
set (LIBQRENCODE_INCLUDE_DIR "")
|
||||
set (LIBQRENCODE_LIBRARIES "")
|
||||
endif (${LIBQRENCODE_FOUND})
|
||||
|
||||
if (${LIBZINT_FOUND})
|
||||
add_definitions (-DHAVE_ZINT=1)
|
||||
else (${LIBZINT_FOUND})
|
||||
set (LIBZINT_INCLUDE_DIR "")
|
||||
set (LIBZINT_LIBRARIES "")
|
||||
endif (${LIBZINT_FOUND})
|
||||
|
||||
|
||||
#=======================================
|
||||
# Auto-generate Version.h
|
||||
#=======================================
|
||||
configure_file (Version.h.in ${CMAKE_CURRENT_BINARY_DIR}/Version.h @ONLY)
|
||||
configure_file (Config.h.in ${CMAKE_CURRENT_BINARY_DIR}/Config.h @ONLY)
|
||||
|
||||
project (glabels LANGUAGES CXX)
|
||||
|
||||
#=======================================
|
||||
# Sources
|
||||
#=======================================
|
||||
|
||||
#
|
||||
# glabels executable
|
||||
#
|
||||
set (glabels_sources
|
||||
glabels_main.cpp
|
||||
main.cpp
|
||||
AboutDialog.cpp
|
||||
BarcodeBackends.cpp
|
||||
BarcodeMenu.cpp
|
||||
BarcodeMenuButton.cpp
|
||||
BarcodeMenuItem.cpp
|
||||
BarcodeStyle.cpp
|
||||
Category.cpp
|
||||
ColorButton.cpp
|
||||
ColorHistory.cpp
|
||||
ColorNode.cpp
|
||||
ColorPaletteDialog.cpp
|
||||
ColorPaletteItem.cpp
|
||||
ColorPaletteButtonItem.cpp
|
||||
ColorSwatch.cpp
|
||||
Cursors.cpp
|
||||
DataCache.cpp
|
||||
Db.cpp
|
||||
Distance.cpp
|
||||
FieldButton.cpp
|
||||
File.cpp
|
||||
FileUtil.cpp
|
||||
Frame.cpp
|
||||
FrameCd.cpp
|
||||
FrameEllipse.cpp
|
||||
FrameRect.cpp
|
||||
FrameRound.cpp
|
||||
Handles.cpp
|
||||
Help.cpp
|
||||
Icons.cpp
|
||||
LabelEditor.cpp
|
||||
LabelModel.cpp
|
||||
LabelModelObject.cpp
|
||||
LabelModelBarcodeObject.cpp
|
||||
LabelModelBoxObject.cpp
|
||||
LabelModelEllipseObject.cpp
|
||||
LabelModelImageObject.cpp
|
||||
LabelModelLineObject.cpp
|
||||
LabelModelShapeObject.cpp
|
||||
LabelModelTextObject.cpp
|
||||
Layout.cpp
|
||||
MainWindow.cpp
|
||||
Markup.cpp
|
||||
MergeView.cpp
|
||||
MiniPreviewPixmap.cpp
|
||||
ObjectEditor.cpp
|
||||
Outline.cpp
|
||||
PageRenderer.cpp
|
||||
Paper.cpp
|
||||
Point.cpp
|
||||
PreferencesDialog.cpp
|
||||
PrintView.cpp
|
||||
PropertiesView.cpp
|
||||
Preview.cpp
|
||||
PreviewOverlayItem.cpp
|
||||
RawText.cpp
|
||||
Region.cpp
|
||||
SelectProductDialog.cpp
|
||||
Settings.cpp
|
||||
SimplePreview.cpp
|
||||
Size.cpp
|
||||
StartupView.cpp
|
||||
StrUtil.cpp
|
||||
SubstitutionField.cpp
|
||||
Template.cpp
|
||||
TemplatePicker.cpp
|
||||
TemplatePickerItem.cpp
|
||||
TextNode.cpp
|
||||
UndoRedoModel.cpp
|
||||
Units.cpp
|
||||
Vendor.cpp
|
||||
XmlCategoryParser.cpp
|
||||
XmlLabelCreator.cpp
|
||||
XmlLabelParser.cpp
|
||||
XmlPaperParser.cpp
|
||||
XmlTemplateCreator.cpp
|
||||
XmlTemplateParser.cpp
|
||||
XmlUtil.cpp
|
||||
XmlVendorParser.cpp
|
||||
)
|
||||
|
||||
set (glabels_qobject_headers
|
||||
AboutDialog.h
|
||||
BarcodeBackends.h
|
||||
BarcodeMenu.h
|
||||
BarcodeMenuButton.h
|
||||
BarcodeMenuItem.h
|
||||
@@ -144,25 +51,14 @@ set (glabels_qobject_headers
|
||||
FieldButton.h
|
||||
File.h
|
||||
LabelEditor.h
|
||||
LabelModel.h
|
||||
LabelModelObject.h
|
||||
LabelModelBarcodeObject.h
|
||||
LabelModelBoxObject.h
|
||||
LabelModelEllipseObject.h
|
||||
LabelModelImageObject.h
|
||||
LabelModelLineObject.h
|
||||
LabelModelShapeObject.h
|
||||
LabelModelTextObject.h
|
||||
MainWindow.h
|
||||
MergeView.h
|
||||
ObjectEditor.h
|
||||
PageRenderer.h
|
||||
PreferencesDialog.h
|
||||
PrintView.h
|
||||
PropertiesView.h
|
||||
Preview.h
|
||||
SelectProductDialog.h
|
||||
Settings.h
|
||||
SimplePreview.h
|
||||
StartupView.h
|
||||
TemplatePicker.h
|
||||
@@ -195,6 +91,9 @@ if (WIN32)
|
||||
set (glabels_win_rc glabels.rc)
|
||||
endif ()
|
||||
|
||||
#=====================================
|
||||
# Target
|
||||
#=====================================
|
||||
add_executable (glabels-qt WIN32
|
||||
${glabels_sources}
|
||||
${glabels_moc_sources}
|
||||
@@ -203,144 +102,19 @@ add_executable (glabels-qt WIN32
|
||||
${glabels_win_rc}
|
||||
)
|
||||
|
||||
target_compile_features (glabels-qt
|
||||
PUBLIC cxx_std_11
|
||||
)
|
||||
|
||||
target_include_directories (glabels-qt
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries (glabels-qt
|
||||
Barcode
|
||||
Merge
|
||||
glbarcode
|
||||
${Qt5Widgets_LIBRARIES}
|
||||
${Qt5PrintSupport_LIBRARIES}
|
||||
${Qt5Xml_LIBRARIES}
|
||||
${Qt5Svg_LIBRARIES}
|
||||
${ZLIB_LIBRARIES}
|
||||
${GNUBARCODE_LIBRARIES}
|
||||
${LIBQRENCODE_LIBRARIES}
|
||||
${LIBZINT_LIBRARIES}
|
||||
Model
|
||||
Qt5::Widgets
|
||||
)
|
||||
|
||||
|
||||
#
|
||||
# glabels-batch executable
|
||||
#
|
||||
set (glabels-batch_sources
|
||||
glabels-batch_main.cpp
|
||||
BarcodeBackends.cpp
|
||||
BarcodeStyle.cpp
|
||||
Category.cpp
|
||||
ColorNode.cpp
|
||||
DataCache.cpp
|
||||
Db.cpp
|
||||
Distance.cpp
|
||||
FileUtil.cpp
|
||||
Frame.cpp
|
||||
FrameCd.cpp
|
||||
FrameEllipse.cpp
|
||||
FrameRect.cpp
|
||||
FrameRound.cpp
|
||||
Handles.cpp
|
||||
LabelModel.cpp
|
||||
LabelModelObject.cpp
|
||||
LabelModelBarcodeObject.cpp
|
||||
LabelModelBoxObject.cpp
|
||||
LabelModelEllipseObject.cpp
|
||||
LabelModelImageObject.cpp
|
||||
LabelModelLineObject.cpp
|
||||
LabelModelShapeObject.cpp
|
||||
LabelModelTextObject.cpp
|
||||
Layout.cpp
|
||||
Markup.cpp
|
||||
Outline.cpp
|
||||
PageRenderer.cpp
|
||||
Paper.cpp
|
||||
Point.cpp
|
||||
RawText.cpp
|
||||
Region.cpp
|
||||
Settings.cpp
|
||||
Size.cpp
|
||||
StrUtil.cpp
|
||||
SubstitutionField.cpp
|
||||
Template.cpp
|
||||
TextNode.cpp
|
||||
Units.cpp
|
||||
Vendor.cpp
|
||||
XmlCategoryParser.cpp
|
||||
XmlLabelCreator.cpp
|
||||
XmlLabelParser.cpp
|
||||
XmlPaperParser.cpp
|
||||
XmlTemplateCreator.cpp
|
||||
XmlTemplateParser.cpp
|
||||
XmlUtil.cpp
|
||||
XmlVendorParser.cpp
|
||||
)
|
||||
|
||||
set (glabels-batch_qobject_headers
|
||||
BarcodeBackends.h
|
||||
LabelModel.h
|
||||
LabelModelObject.h
|
||||
LabelModelBarcodeObject.h
|
||||
LabelModelBoxObject.h
|
||||
LabelModelEllipseObject.h
|
||||
LabelModelImageObject.h
|
||||
LabelModelLineObject.h
|
||||
LabelModelShapeObject.h
|
||||
LabelModelTextObject.h
|
||||
PageRenderer.h
|
||||
Settings.h
|
||||
)
|
||||
|
||||
qt5_wrap_cpp (glabels-batch_moc_sources ${glabels-batch_qobject_headers})
|
||||
|
||||
if (WIN32)
|
||||
# Windows resource file
|
||||
set (glabels-batch_win_rc glabels-batch.rc)
|
||||
endif ()
|
||||
|
||||
add_executable (glabels-batch-qt WIN32
|
||||
${glabels-batch_sources}
|
||||
${glabels-batch_moc_sources}
|
||||
${glabels-batch_win_rc}
|
||||
)
|
||||
|
||||
target_link_libraries (glabels-batch-qt
|
||||
Barcode
|
||||
Merge
|
||||
glbarcode
|
||||
${Qt5PrintSupport_LIBRARIES}
|
||||
${Qt5Xml_LIBRARIES}
|
||||
${Qt5Svg_LIBRARIES}
|
||||
${ZLIB_LIBRARIES}
|
||||
${GNUBARCODE_LIBRARIES}
|
||||
${LIBQRENCODE_LIBRARIES}
|
||||
${LIBZINT_LIBRARIES}
|
||||
)
|
||||
|
||||
|
||||
#=======================================
|
||||
# Where to find stuff
|
||||
#=======================================
|
||||
include_directories (
|
||||
${glabels_SOURCE_DIR}
|
||||
${ZLIB_INCLUDE_DIRS}
|
||||
${Qt5Widgets_INCLUDE_DIRS}
|
||||
${Qt5PrintSupport_INCLUDE_DIRS}
|
||||
${Qt5Xml_INCLUDE_DIRS}
|
||||
${Qt5Svg_INCLUDE_DIRS}
|
||||
${GNUBARCODE_INCLUDE_DIR}
|
||||
${LIBQRENCODE_INCLUDE_DIR}
|
||||
${LIBZINT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
link_directories (
|
||||
)
|
||||
|
||||
|
||||
#=======================================
|
||||
# Subdirectories
|
||||
#=======================================
|
||||
add_subdirectory (BarcodeBackends)
|
||||
add_subdirectory (Merge)
|
||||
add_subdirectory (unit_tests)
|
||||
|
||||
|
||||
#=======================================
|
||||
# Install
|
||||
#=======================================
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/* Category.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Category.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
Category::Category( const QString &id, const QString &name )
|
||||
: mId(id), mName(name)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
QString Category::id() const
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
|
||||
|
||||
QString Category::name() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,50 +0,0 @@
|
||||
/* Category.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_Category_h
|
||||
#define glabels_Category_h
|
||||
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class Category
|
||||
{
|
||||
|
||||
public:
|
||||
Category( const QString& id, const QString& name );
|
||||
|
||||
QString id() const;
|
||||
QString name() const;
|
||||
|
||||
|
||||
private:
|
||||
QString mId;
|
||||
QString mName;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_Category_h
|
||||
@@ -52,7 +52,7 @@ namespace glabels
|
||||
const QColor& color )
|
||||
{
|
||||
mDefaultColor = defaultColor;
|
||||
mColorNode = ColorNode( color );
|
||||
mColorNode = model::ColorNode( color );
|
||||
|
||||
setMinimumSize( QSize( 85, 34 ) );
|
||||
setIconSize( QSize(SWATCH_W, SWATCH_H) );
|
||||
@@ -64,14 +64,14 @@ namespace glabels
|
||||
mDialog = new ColorPaletteDialog( defaultLabel, defaultColor, color );
|
||||
|
||||
connect( this, SIGNAL(toggled(bool)), this, SLOT(onButtonToggled(bool)) );
|
||||
connect( mDialog, SIGNAL(colorChanged(ColorNode,bool)),
|
||||
this, SLOT(onPaletteDialogChanged(ColorNode,bool)) );
|
||||
connect( mDialog, SIGNAL(colorChanged(model::ColorNode,bool)),
|
||||
this, SLOT(onPaletteDialogChanged(model::ColorNode,bool)) );
|
||||
connect( mDialog, SIGNAL(accepted()), this, SLOT(onPaletteDialogAccepted()) );
|
||||
connect( mDialog, SIGNAL(rejected()), this, SLOT(onPaletteDialogRejected()) );
|
||||
}
|
||||
|
||||
|
||||
void ColorButton::setColorNode( ColorNode colorNode )
|
||||
void ColorButton::setColorNode( model::ColorNode colorNode )
|
||||
{
|
||||
mIsDefault = false;
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
ColorNode ColorButton::colorNode()
|
||||
model::ColorNode ColorButton::colorNode()
|
||||
{
|
||||
return mColorNode;
|
||||
}
|
||||
@@ -163,7 +163,7 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
void ColorButton::onPaletteDialogChanged( ColorNode colorNode, bool isDefault )
|
||||
void ColorButton::onPaletteDialogChanged( model::ColorNode colorNode, bool isDefault )
|
||||
{
|
||||
mColorNode = colorNode;
|
||||
mIsDefault = isDefault;
|
||||
|
||||
@@ -22,9 +22,10 @@
|
||||
#define ColorButton_h
|
||||
|
||||
|
||||
#include "ColorNode.h"
|
||||
#include "ColorPaletteDialog.h"
|
||||
|
||||
#include "model/ColorNode.h"
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
|
||||
@@ -58,10 +59,10 @@ namespace glabels
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void init( const QString& defaultLabel, const QColor& defaultColor, const QColor& color );
|
||||
void setColorNode( ColorNode colorNode );
|
||||
void setColorNode( model::ColorNode colorNode );
|
||||
void setColor( QColor color );
|
||||
void setToDefault();
|
||||
ColorNode colorNode();
|
||||
model::ColorNode colorNode();
|
||||
void setKeys( const QList<QString> keyList );
|
||||
void clearKeys();
|
||||
|
||||
@@ -73,7 +74,7 @@ namespace glabels
|
||||
void onButtonToggled( bool checked );
|
||||
void onPaletteDialogAccepted();
|
||||
void onPaletteDialogRejected();
|
||||
void onPaletteDialogChanged( ColorNode colorNode, bool isDefault );
|
||||
void onPaletteDialogChanged( model::ColorNode colorNode, bool isDefault );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
@@ -88,7 +89,7 @@ namespace glabels
|
||||
private:
|
||||
QColor mDefaultColor;
|
||||
bool mIsDefault;
|
||||
ColorNode mColorNode;
|
||||
model::ColorNode mColorNode;
|
||||
|
||||
ColorPaletteDialog* mDialog;
|
||||
};
|
||||
|
||||
@@ -1,202 +0,0 @@
|
||||
/* ColorNode.cpp
|
||||
*
|
||||
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ColorNode.h"
|
||||
|
||||
#include "Merge/Record.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Default Constructor
|
||||
///
|
||||
ColorNode::ColorNode()
|
||||
: mIsField(false), mColor(QColor::fromRgba(0x00000000)), mKey("")
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor From Data
|
||||
///
|
||||
ColorNode::ColorNode( bool isField, const QColor& color, const QString& key )
|
||||
: mIsField(isField), mColor(color), mKey(key)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor From Data
|
||||
///
|
||||
ColorNode::ColorNode( bool isField, uint32_t rgba, const QString& key )
|
||||
: mIsField(isField), mKey(key)
|
||||
{
|
||||
mColor = QColor( (rgba >> 24) & 0xFF,
|
||||
(rgba >> 16) & 0xFF,
|
||||
(rgba >> 8) & 0xFF,
|
||||
(rgba ) & 0xFF );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor From Color
|
||||
///
|
||||
ColorNode::ColorNode( const QColor& color )
|
||||
: mIsField(false), mColor(color), mKey("")
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor From Key
|
||||
///
|
||||
ColorNode::ColorNode( const QString& key )
|
||||
: mIsField(true), mColor(QColor::fromRgba(0x00000000)), mKey(key)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// == Operator
|
||||
///
|
||||
bool ColorNode::operator==( const ColorNode& cn )
|
||||
{
|
||||
return (mIsField == cn.mIsField) &&
|
||||
(mColor == cn.mColor) &&
|
||||
(mKey == cn.mKey);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// != Operator
|
||||
///
|
||||
bool ColorNode::operator!=( const ColorNode& cn )
|
||||
{
|
||||
return (mIsField != cn.mIsField) ||
|
||||
(mColor != cn.mColor) ||
|
||||
(mKey != cn.mKey);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Field Flag Property Getter
|
||||
///
|
||||
bool ColorNode::isField() const
|
||||
{
|
||||
return mIsField;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Field Flag Property Setter
|
||||
///
|
||||
void ColorNode::setField( bool isField )
|
||||
{
|
||||
mIsField = isField;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Color Property Getter
|
||||
///
|
||||
const QColor& ColorNode::color() const
|
||||
{
|
||||
return mColor;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Color Property Setter
|
||||
///
|
||||
void ColorNode::setColor( const QColor& color )
|
||||
{
|
||||
mColor = color;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Key Property Getter
|
||||
///
|
||||
const QString& ColorNode::key() const
|
||||
{
|
||||
return mKey;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Key Property Setter
|
||||
///
|
||||
void ColorNode::setKey( const QString& key )
|
||||
{
|
||||
mKey = key;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get color encoded as an RGBA 32-bit number
|
||||
///
|
||||
uint32_t ColorNode::rgba() const
|
||||
{
|
||||
uint32_t c =
|
||||
mColor.red() << 24 |
|
||||
mColor.green() << 16 |
|
||||
mColor.blue() << 8 |
|
||||
mColor.alpha();
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get color, expand if necessary
|
||||
///
|
||||
QColor ColorNode::color( merge::Record* record ) const
|
||||
{
|
||||
if ( mIsField )
|
||||
{
|
||||
if ( record == nullptr )
|
||||
{
|
||||
return mColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( record->contains( mKey ) )
|
||||
{
|
||||
return QColor( (*record)[ mKey ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
return mColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return mColor;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,112 +0,0 @@
|
||||
/* ColorNode.h
|
||||
*
|
||||
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ColorNode_h
|
||||
#define ColorNode_h
|
||||
|
||||
|
||||
#include "Merge/Record.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QColor>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Color Node Type
|
||||
///
|
||||
struct ColorNode
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
ColorNode();
|
||||
|
||||
ColorNode( bool isField, const QColor& color, const QString& key );
|
||||
|
||||
ColorNode( bool isField, uint32_t rgba, const QString& key );
|
||||
|
||||
ColorNode( const QColor& color );
|
||||
|
||||
ColorNode( const QString& key );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Operators
|
||||
/////////////////////////////////
|
||||
public:
|
||||
bool operator==( const ColorNode& cn );
|
||||
|
||||
bool operator!=( const ColorNode& cn );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Field Flag Property
|
||||
//
|
||||
bool isField() const;
|
||||
void setField( bool isField );
|
||||
|
||||
|
||||
//
|
||||
// Color Property
|
||||
//
|
||||
const QColor& color() const;
|
||||
void setColor( const QColor& color );
|
||||
|
||||
|
||||
//
|
||||
// Key Property
|
||||
//
|
||||
const QString& key() const;
|
||||
void setKey( const QString& key );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Misc. Methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
uint32_t rgba() const;
|
||||
QColor color( merge::Record* record ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
bool mIsField;
|
||||
QColor mColor;
|
||||
QString mKey;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // ColorNode_h
|
||||
@@ -90,7 +90,7 @@ namespace glabels
|
||||
connect( mColorHistory, SIGNAL(changed()), this, SLOT(onColorHistoryChanged()) );
|
||||
|
||||
mDefaultColor = defaultColor;
|
||||
mColorNode = ColorNode( color );
|
||||
mColorNode = model::ColorNode( color );
|
||||
|
||||
setStyleSheet( ".glabels--ColorPaletteDialog {background: white; border: 1px solid black}" );
|
||||
setWindowFlags( Qt::Popup | Qt::FramelessWindowHint );
|
||||
@@ -177,7 +177,7 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
void ColorPaletteDialog::setColorNode( const ColorNode& colorNode )
|
||||
void ColorPaletteDialog::setColorNode( const model::ColorNode& colorNode )
|
||||
{
|
||||
mColorNode = colorNode;
|
||||
}
|
||||
@@ -257,7 +257,7 @@ namespace glabels
|
||||
|
||||
if ( dlg.exec() )
|
||||
{
|
||||
ColorNode newColorNode;
|
||||
model::ColorNode newColorNode;
|
||||
|
||||
newColorNode.setField( false );
|
||||
newColorNode.setColor( dlg.currentColor() );
|
||||
|
||||
@@ -22,11 +22,12 @@
|
||||
#define ColorPaletteDialog_h
|
||||
|
||||
|
||||
#include "ColorNode.h"
|
||||
#include "ColorHistory.h"
|
||||
#include "ColorPaletteItem.h"
|
||||
#include "ColorPaletteButtonItem.h"
|
||||
|
||||
#include "model/ColorNode.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
|
||||
@@ -56,14 +57,14 @@ namespace glabels
|
||||
// Signals
|
||||
/////////////////////////////////
|
||||
signals:
|
||||
void colorChanged( ColorNode colorNode, bool isDefault );
|
||||
void colorChanged( model::ColorNode colorNode, bool isDefault );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Public Methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void setColorNode( const ColorNode& colorNode );
|
||||
void setColorNode( const model::ColorNode& colorNode );
|
||||
void setKeys( const QStringList& keyList );
|
||||
void clearKeys();
|
||||
|
||||
@@ -94,8 +95,8 @@ namespace glabels
|
||||
// Private Members
|
||||
/////////////////////////////////
|
||||
private:
|
||||
QColor mDefaultColor;
|
||||
ColorNode mColorNode;
|
||||
QColor mDefaultColor;
|
||||
model::ColorNode mColorNode;
|
||||
|
||||
static const int PALETTE_COLS = ColorHistory::MAX_COLORS;
|
||||
static const int PALETTE_ROWS = 4;
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/* Config.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_Config_h
|
||||
#define glabels_Config_h
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace Config
|
||||
{
|
||||
const QString PROJECT_SOURCE_DIR = "@glabels_SOURCE_DIR@";
|
||||
const QString PROJECT_BUILD_DIR = "@glabels_BINARY_DIR@";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_Config_h
|
||||
@@ -1,37 +0,0 @@
|
||||
/* Constants.h
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_Constants_h
|
||||
#define glabels_Constants_h
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
const double PTS_PER_PT = 1.0;
|
||||
const double PTS_PER_INCH = 72.0;
|
||||
const double PTS_PER_MM = 2.83464566929;
|
||||
const double PTS_PER_CM = (10.0*PTS_PER_MM);
|
||||
const double PTS_PER_PICA = 12.0;
|
||||
|
||||
const Distance EPSILON( 0.5, Units::PT );
|
||||
}
|
||||
|
||||
#endif // glabels_Constants_h
|
||||
@@ -1,110 +0,0 @@
|
||||
/* DataCache.cpp
|
||||
*
|
||||
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "DataCache.h"
|
||||
|
||||
#include "LabelModelImageObject.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
DataCache::DataCache()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
DataCache::DataCache( const QList<LabelModelObject*>& objects )
|
||||
{
|
||||
foreach( LabelModelObject* object, objects )
|
||||
{
|
||||
if ( LabelModelImageObject* imageObject = dynamic_cast<LabelModelImageObject*>(object) )
|
||||
{
|
||||
TextNode filenameNode = imageObject->filenameNode();
|
||||
if ( !filenameNode.isField() )
|
||||
{
|
||||
if ( const QImage* image = imageObject->image() )
|
||||
{
|
||||
addImage( filenameNode.data(), *image );
|
||||
}
|
||||
else
|
||||
{
|
||||
QByteArray svg = imageObject->svg();
|
||||
if ( !svg.isEmpty() )
|
||||
{
|
||||
addSvg( filenameNode.data(), svg );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool DataCache::hasImage( const QString& name ) const
|
||||
{
|
||||
return mImageMap.contains( name );
|
||||
}
|
||||
|
||||
|
||||
QImage DataCache::getImage( const QString& name ) const
|
||||
{
|
||||
return mImageMap[ name ];
|
||||
}
|
||||
|
||||
|
||||
void DataCache::addImage( const QString& name, const QImage& image )
|
||||
{
|
||||
mImageMap[ name ] = image;
|
||||
}
|
||||
|
||||
|
||||
QList<QString> DataCache::imageNames() const
|
||||
{
|
||||
return mImageMap.keys();
|
||||
}
|
||||
|
||||
|
||||
bool DataCache::hasSvg( const QString& name ) const
|
||||
{
|
||||
return mSvgMap.contains( name );
|
||||
}
|
||||
|
||||
|
||||
QByteArray DataCache::getSvg( const QString& name ) const
|
||||
{
|
||||
return mSvgMap[ name ];
|
||||
}
|
||||
|
||||
|
||||
void DataCache::addSvg( const QString& name, const QByteArray& svg )
|
||||
{
|
||||
mSvgMap[ name ] = svg;
|
||||
}
|
||||
|
||||
|
||||
QList<QString> DataCache::svgNames() const
|
||||
{
|
||||
return mSvgMap.keys();
|
||||
}
|
||||
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,58 +0,0 @@
|
||||
/* DataCache.h
|
||||
*
|
||||
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_DataCache_h
|
||||
#define glabels_DataCache_h
|
||||
|
||||
|
||||
#include "LabelModel.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class DataCache
|
||||
{
|
||||
public:
|
||||
DataCache();
|
||||
|
||||
DataCache( const QList<LabelModelObject*>& objects );
|
||||
|
||||
bool hasImage( const QString& name ) const;
|
||||
QImage getImage( const QString& name ) const;
|
||||
void addImage( const QString& name, const QImage& image );
|
||||
QList<QString> imageNames() const;
|
||||
|
||||
bool hasSvg( const QString& name ) const;
|
||||
QByteArray getSvg( const QString& name ) const;
|
||||
void addSvg( const QString& name, const QByteArray& svg );
|
||||
QList<QString> svgNames() const;
|
||||
|
||||
|
||||
private:
|
||||
QMap<QString,QImage> mImageMap;
|
||||
QMap<QString,QByteArray> mSvgMap;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_DataCache_h
|
||||
-689
@@ -1,689 +0,0 @@
|
||||
/* Db.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Db.h"
|
||||
|
||||
#include "Config.h"
|
||||
#include "StrUtil.h"
|
||||
#include "FileUtil.h"
|
||||
#include "XmlCategoryParser.h"
|
||||
#include "XmlPaperParser.h"
|
||||
#include "XmlTemplateParser.h"
|
||||
#include "XmlVendorParser.h"
|
||||
|
||||
#include <QtDebug>
|
||||
#include <QtGlobal>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const QString empty = "";
|
||||
|
||||
bool partNameLessThan( const Template *a, const Template *b )
|
||||
{
|
||||
return StrUtil::comparePartNames( a->name(), b->name() ) < 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Static data
|
||||
//
|
||||
QList<Paper*> Db::mPapers;
|
||||
QStringList Db::mPaperIds;
|
||||
QStringList Db::mPaperNames;
|
||||
QList<Category*> Db::mCategories;
|
||||
QStringList Db::mCategoryIds;
|
||||
QStringList Db::mCategoryNames;
|
||||
QList<Vendor*> Db::mVendors;
|
||||
QStringList Db::mVendorNames;
|
||||
QList<Template*> Db::mTemplates;
|
||||
QString Db::mPaperNameOther;
|
||||
|
||||
|
||||
Db::Db()
|
||||
{
|
||||
mPaperNameOther = tr("Other");
|
||||
|
||||
readPapers();
|
||||
readCategories();
|
||||
readVendors();
|
||||
readTemplates();
|
||||
}
|
||||
|
||||
|
||||
void Db::init()
|
||||
{
|
||||
instance();
|
||||
}
|
||||
|
||||
|
||||
Db* Db::instance()
|
||||
{
|
||||
static Db* db = new Db();
|
||||
return db;
|
||||
}
|
||||
|
||||
|
||||
const QList<Paper*>& Db::papers()
|
||||
{
|
||||
return mPapers;
|
||||
}
|
||||
|
||||
|
||||
const QStringList& Db::paperIds()
|
||||
{
|
||||
return mPaperIds;
|
||||
}
|
||||
|
||||
|
||||
const QStringList& Db::paperNames()
|
||||
{
|
||||
return mPaperNames;
|
||||
}
|
||||
|
||||
|
||||
const QList<Category*>& Db::categories()
|
||||
{
|
||||
return mCategories;
|
||||
}
|
||||
|
||||
|
||||
const QStringList& Db::categoryIds()
|
||||
{
|
||||
return mCategoryIds;
|
||||
}
|
||||
|
||||
|
||||
const QStringList& Db::categoryNames()
|
||||
{
|
||||
return mCategoryNames;
|
||||
}
|
||||
|
||||
|
||||
const QList<Vendor*>& Db::vendors()
|
||||
{
|
||||
return mVendors;
|
||||
}
|
||||
|
||||
|
||||
const QStringList& Db::vendorNames()
|
||||
{
|
||||
return mVendorNames;
|
||||
}
|
||||
|
||||
|
||||
const QList<Template*>& Db::templates()
|
||||
{
|
||||
return mTemplates;
|
||||
}
|
||||
|
||||
|
||||
void Db::registerPaper( Paper *paper )
|
||||
{
|
||||
if ( !isPaperIdKnown( paper->id() ) )
|
||||
{
|
||||
mPapers << paper;
|
||||
mPaperIds << paper->id();
|
||||
mPaperNames << paper->name();
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Duplicate paper ID: " << paper->id();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const Paper *Db::lookupPaperFromName( const QString& name )
|
||||
{
|
||||
if ( name.isNull() || name.isEmpty() )
|
||||
{
|
||||
qWarning() << "NULL paper name.";
|
||||
return mPapers.first();
|
||||
}
|
||||
|
||||
foreach ( Paper *paper, mPapers )
|
||||
{
|
||||
if ( paper->name() == name )
|
||||
{
|
||||
return paper;
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unknown paper name: " << name;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
const Paper *Db::lookupPaperFromId( const QString& id )
|
||||
{
|
||||
if ( id.isNull() || id.isEmpty() )
|
||||
{
|
||||
qWarning() << "NULL paper ID.";
|
||||
return mPapers.first();
|
||||
}
|
||||
|
||||
foreach ( Paper *paper, mPapers )
|
||||
{
|
||||
if ( paper->id() == id )
|
||||
{
|
||||
return paper;
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unknown paper ID: " << id;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
QString Db::lookupPaperIdFromName( const QString& name )
|
||||
{
|
||||
if ( !name.isNull() && !name.isEmpty() )
|
||||
{
|
||||
const Paper *paper = lookupPaperFromName( name );
|
||||
if ( paper != nullptr )
|
||||
{
|
||||
return paper->id();
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unknown paper name: " << name;
|
||||
return empty;
|
||||
}
|
||||
|
||||
|
||||
QString Db::lookupPaperNameFromId( const QString& id )
|
||||
{
|
||||
if ( !id.isNull() && !id.isEmpty() )
|
||||
{
|
||||
if ( isPaperIdOther( id ) )
|
||||
{
|
||||
return mPaperNameOther;
|
||||
}
|
||||
|
||||
const Paper *paper = lookupPaperFromId( id );
|
||||
if ( paper != nullptr )
|
||||
{
|
||||
return paper->name();
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unknown paper id: " << id;
|
||||
return empty;
|
||||
}
|
||||
|
||||
|
||||
bool Db::isPaperIdKnown( const QString& id )
|
||||
{
|
||||
foreach ( Paper *paper, mPapers )
|
||||
{
|
||||
if ( paper->id() == id )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Db::isPaperIdOther( const QString& id )
|
||||
{
|
||||
return ( id == "Other" );
|
||||
}
|
||||
|
||||
|
||||
void Db::registerCategory( Category *category )
|
||||
{
|
||||
if ( !isCategoryIdKnown( category->id() ) )
|
||||
{
|
||||
mCategories << category;
|
||||
mCategoryIds << category->id();
|
||||
mCategoryNames << category->name();
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Duplicate category ID: " << category->id();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const Category *Db::lookupCategoryFromName( const QString& name )
|
||||
{
|
||||
if ( name.isNull() || name.isEmpty() )
|
||||
{
|
||||
qWarning() << "NULL category name.";
|
||||
return mCategories.first();
|
||||
}
|
||||
|
||||
foreach ( Category *category, mCategories )
|
||||
{
|
||||
if ( category->name() == name )
|
||||
{
|
||||
return category;
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unknown category name: \"%s\"." << name;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
const Category *Db::lookupCategoryFromId( const QString& id )
|
||||
{
|
||||
if ( id.isNull() || id.isEmpty() )
|
||||
{
|
||||
qDebug() << "NULL category ID.";
|
||||
return mCategories.first();
|
||||
}
|
||||
|
||||
foreach ( Category *category, mCategories )
|
||||
{
|
||||
if ( category->id() == id )
|
||||
{
|
||||
return category;
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unknown category ID: " << id;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
QString Db::lookupCategoryIdFromName( const QString& name )
|
||||
{
|
||||
if ( !name.isNull() && !name.isEmpty() )
|
||||
{
|
||||
const Category *category = lookupCategoryFromName( name );
|
||||
if ( category != nullptr )
|
||||
{
|
||||
return category->id();
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unknown category name: " << name;
|
||||
return empty;
|
||||
}
|
||||
|
||||
|
||||
QString Db::lookupCategoryNameFromId( const QString& id )
|
||||
{
|
||||
if ( !id.isNull() && !id.isEmpty() )
|
||||
{
|
||||
const Category *category = lookupCategoryFromId( id );
|
||||
if ( category != nullptr )
|
||||
{
|
||||
return category->name();
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unknown category id: " << id;
|
||||
return empty;
|
||||
}
|
||||
|
||||
|
||||
bool Db::isCategoryIdKnown( const QString& id )
|
||||
{
|
||||
foreach ( Category *category, mCategories )
|
||||
{
|
||||
if ( category->id() == id )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void Db::registerVendor( Vendor *vendor )
|
||||
{
|
||||
if ( !isVendorNameKnown( vendor->name() ) )
|
||||
{
|
||||
mVendors << vendor;
|
||||
mVendorNames << vendor->name();
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Duplicate vendor name: " << vendor->name();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const Vendor *Db::lookupVendorFromName( const QString& name )
|
||||
{
|
||||
if ( name.isNull() || name.isEmpty() )
|
||||
{
|
||||
qWarning() << "NULL vendor name.";
|
||||
return mVendors.first();
|
||||
}
|
||||
|
||||
foreach ( Vendor *vendor, mVendors )
|
||||
{
|
||||
if ( vendor->name() == name )
|
||||
{
|
||||
return vendor;
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unknown vendor name: " << name;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
QString Db::lookupVendorUrlFromName( const QString& name )
|
||||
{
|
||||
if ( !name.isNull() && !name.isEmpty() )
|
||||
{
|
||||
const Vendor *vendor = lookupVendorFromName( name );
|
||||
if ( vendor != nullptr )
|
||||
{
|
||||
return vendor->url();
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unknown vendor name: " << name;
|
||||
return empty;
|
||||
}
|
||||
|
||||
|
||||
bool Db::isVendorNameKnown( const QString& name )
|
||||
{
|
||||
foreach ( Vendor *vendor, mVendors )
|
||||
{
|
||||
if ( vendor->name() == name )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void Db::registerTemplate( Template *tmplate )
|
||||
{
|
||||
if ( !isTemplateKnown( tmplate->brand(), tmplate->part() ) )
|
||||
{
|
||||
mTemplates << tmplate;
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Duplicate template name: " << tmplate->name();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const Template *Db::lookupTemplateFromName( const QString& name )
|
||||
{
|
||||
if ( name.isNull() || name.isEmpty() )
|
||||
{
|
||||
qWarning() << "NULL template name.";
|
||||
return mTemplates.first();
|
||||
}
|
||||
|
||||
foreach ( Template *tmplate, mTemplates )
|
||||
{
|
||||
if ( tmplate->name() == name )
|
||||
{
|
||||
return tmplate;
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unknown template name: " << name;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
const Template *Db::lookupTemplateFromBrandPart( const QString& brand, const QString& part )
|
||||
{
|
||||
if ( brand.isNull() || brand.isEmpty() || part.isNull() || part.isEmpty() )
|
||||
{
|
||||
qWarning() << "NULL template brand and/or part.";
|
||||
return mTemplates.first();
|
||||
}
|
||||
|
||||
foreach ( Template *tmplate, mTemplates )
|
||||
{
|
||||
if ( (tmplate->brand() == brand) && (tmplate->part() == part) )
|
||||
{
|
||||
return tmplate;
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unknown template brand, part: " << brand << ", " << part;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool Db::isTemplateKnown( const QString& brand, const QString& part )
|
||||
{
|
||||
foreach ( Template *tmplate, mTemplates )
|
||||
{
|
||||
if ( (tmplate->brand() == brand) && (tmplate->part() == part) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
QStringList Db::getNameListOfSimilarTemplates( const QString& name )
|
||||
{
|
||||
QStringList list;
|
||||
|
||||
const Template *tmplate1 = lookupTemplateFromName( name );
|
||||
if ( tmplate1 == nullptr )
|
||||
{
|
||||
qWarning() << "Unknown template name: " << name;
|
||||
return list;
|
||||
}
|
||||
|
||||
foreach (const Template *tmplate2, mTemplates )
|
||||
{
|
||||
if ( tmplate1->name() != tmplate2->name() )
|
||||
{
|
||||
if ( tmplate1->isSimilarTo( tmplate2 ) )
|
||||
{
|
||||
list << tmplate2->name();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
void Db::registerUserTemplate( Template *templat )
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
void Db::deleteUserTemplateByName( const QString& name )
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
void Db::deleteUserTemplateByBrandPart( const QString& brand, const QString& part )
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
void Db::printKnownPapers()
|
||||
{
|
||||
qDebug() << "KNOWN PAPERS:";
|
||||
|
||||
foreach ( Paper *paper, mPapers )
|
||||
{
|
||||
qDebug() << "paper "
|
||||
<< "id=" << paper->id() << ", "
|
||||
<< "name=" << paper->name() << ", "
|
||||
<< "width=" << paper->width().pt() << "pts, "
|
||||
<< "height=" << paper->height().pt() << "pts, "
|
||||
<< "pwg_size=" << paper->pwgSize();
|
||||
}
|
||||
|
||||
qDebug();
|
||||
}
|
||||
|
||||
|
||||
void Db::printKnownCategories()
|
||||
{
|
||||
qDebug() << "KNOWN CATEGORIES:";
|
||||
|
||||
foreach ( Category *category, mCategories )
|
||||
{
|
||||
qDebug() << "category "
|
||||
<< "id=" << category->id() << ", "
|
||||
<< "name=" << category->name();
|
||||
}
|
||||
|
||||
qDebug();
|
||||
}
|
||||
|
||||
|
||||
void Db::printKnownVendors()
|
||||
{
|
||||
qDebug() << "KNOWN VENDORS:";
|
||||
|
||||
foreach ( Vendor *vendor, mVendors )
|
||||
{
|
||||
qDebug() << "vendor "
|
||||
<< "name='" << vendor->name() << ", "
|
||||
<< "url='" << vendor->url();
|
||||
}
|
||||
|
||||
qDebug();
|
||||
}
|
||||
|
||||
|
||||
void Db::printKnownTemplates()
|
||||
{
|
||||
qDebug() << "KNOWN TEMPLATES:";
|
||||
|
||||
foreach ( Template *tmplate, mTemplates )
|
||||
{
|
||||
qDebug() << "template "
|
||||
<< "brand=" << tmplate->brand() << ", "
|
||||
<< "part=" << tmplate->part() << ", "
|
||||
<< "description=" << tmplate->description();
|
||||
}
|
||||
|
||||
qDebug();
|
||||
}
|
||||
|
||||
|
||||
void Db::readPapers()
|
||||
{
|
||||
readPapersFromDir( FileUtil::systemTemplatesDir() );
|
||||
}
|
||||
|
||||
|
||||
void Db::readPapersFromDir( const QDir& dir )
|
||||
{
|
||||
XmlPaperParser parser;
|
||||
|
||||
foreach ( QString fileName, dir.entryList( QDir::Files ) )
|
||||
{
|
||||
if ( fileName == "paper-sizes.xml" )
|
||||
{
|
||||
parser.readFile( dir.absoluteFilePath( fileName ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Db::readCategories()
|
||||
{
|
||||
readCategoriesFromDir( FileUtil::systemTemplatesDir() );
|
||||
}
|
||||
|
||||
|
||||
void Db::readCategoriesFromDir( const QDir& dir )
|
||||
{
|
||||
XmlCategoryParser parser;
|
||||
|
||||
foreach ( QString fileName, dir.entryList( QDir::Files ) )
|
||||
{
|
||||
if ( fileName == "categories.xml" )
|
||||
{
|
||||
parser.readFile( dir.absoluteFilePath( fileName ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Db::readVendors()
|
||||
{
|
||||
readVendorsFromDir( FileUtil::systemTemplatesDir() );
|
||||
}
|
||||
|
||||
|
||||
void Db::readVendorsFromDir( const QDir& dir )
|
||||
{
|
||||
XmlVendorParser parser;
|
||||
|
||||
foreach ( QString fileName, dir.entryList( QDir::Files ) )
|
||||
{
|
||||
if ( fileName == "vendors.xml" )
|
||||
{
|
||||
parser.readFile( dir.absoluteFilePath( fileName ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Db::readTemplates()
|
||||
{
|
||||
readTemplatesFromDir( FileUtil::systemTemplatesDir() );
|
||||
|
||||
// TODO: Read user directories
|
||||
|
||||
std::stable_sort( mTemplates.begin(), mTemplates.end(), partNameLessThan );
|
||||
}
|
||||
|
||||
|
||||
void Db::readTemplatesFromDir( const QDir& dir )
|
||||
{
|
||||
QStringList filters;
|
||||
filters << "*-templates.xml" << "*.template";
|
||||
|
||||
XmlTemplateParser parser;
|
||||
|
||||
foreach ( QString fileName, dir.entryList( filters, QDir::Files ) )
|
||||
{
|
||||
parser.readFile( dir.absoluteFilePath( fileName ) );
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
-141
@@ -1,141 +0,0 @@
|
||||
/* Db.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_Db_h
|
||||
#define glabels_Db_h
|
||||
|
||||
|
||||
#include "Category.h"
|
||||
#include "Paper.h"
|
||||
#include "Template.h"
|
||||
#include "Vendor.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class Db
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Db)
|
||||
|
||||
private:
|
||||
Db();
|
||||
|
||||
|
||||
public:
|
||||
static void init();
|
||||
static Db* instance();
|
||||
|
||||
|
||||
static const QList<Paper*>& papers();
|
||||
static const QStringList& paperIds();
|
||||
static const QStringList& paperNames();
|
||||
|
||||
static const QList<Category*>& categories();
|
||||
static const QStringList& categoryIds();
|
||||
static const QStringList& categoryNames();
|
||||
|
||||
static const QList<Vendor*>& vendors();
|
||||
static const QStringList& vendorNames();
|
||||
|
||||
static const QList<Template*>& templates();
|
||||
|
||||
|
||||
static void registerPaper( Paper *paper );
|
||||
static const Paper *lookupPaperFromName( const QString& name );
|
||||
static const Paper *lookupPaperFromId( const QString& id );
|
||||
static QString lookupPaperIdFromName( const QString& name );
|
||||
static QString lookupPaperNameFromId( const QString& id );
|
||||
static bool isPaperIdKnown( const QString& id );
|
||||
static bool isPaperIdOther( const QString& id );
|
||||
|
||||
static void registerCategory( Category *category );
|
||||
static const Category *lookupCategoryFromName( const QString& name );
|
||||
static const Category *lookupCategoryFromId( const QString& id );
|
||||
static QString lookupCategoryIdFromName( const QString& name );
|
||||
static QString lookupCategoryNameFromId( const QString& id );
|
||||
static bool isCategoryIdKnown( const QString& id );
|
||||
|
||||
static void registerVendor( Vendor *vendor );
|
||||
static const Vendor *lookupVendorFromName( const QString& name );
|
||||
static QString lookupVendorUrlFromName( const QString& name );
|
||||
static bool isVendorNameKnown( const QString& id );
|
||||
|
||||
static void registerTemplate( Template *tmplate );
|
||||
static const Template *lookupTemplateFromName( const QString& name );
|
||||
static const Template *lookupTemplateFromBrandPart( const QString& brand,
|
||||
const QString& part );
|
||||
static bool isTemplateKnown( const QString& brand, const QString& part );
|
||||
static QStringList getNameListOfSimilarTemplates( const QString& name );
|
||||
|
||||
static void registerUserTemplate( Template *tmplate );
|
||||
static void deleteUserTemplateByName( const QString& name );
|
||||
static void deleteUserTemplateByBrandPart( const QString& brand,
|
||||
const QString& part );
|
||||
|
||||
static void printKnownPapers();
|
||||
static void printKnownCategories();
|
||||
static void printKnownVendors();
|
||||
static void printKnownTemplates();
|
||||
|
||||
|
||||
private:
|
||||
static QDir systemTemplatesDir();
|
||||
|
||||
static void readPapers();
|
||||
static void readPapersFromDir( const QDir& dir );
|
||||
|
||||
static void readCategories();
|
||||
static void readCategoriesFromDir( const QDir& dir );
|
||||
|
||||
static void readVendors();
|
||||
static void readVendorsFromDir( const QDir& dir );
|
||||
|
||||
static void readTemplates();
|
||||
static void readTemplatesFromDir( const QDir& dir );
|
||||
|
||||
|
||||
private:
|
||||
static QList<Paper*> mPapers;
|
||||
static QStringList mPaperIds;
|
||||
static QStringList mPaperNames;
|
||||
|
||||
static QList<Category*> mCategories;
|
||||
static QStringList mCategoryIds;
|
||||
static QStringList mCategoryNames;
|
||||
|
||||
static QList<Vendor*> mVendors;
|
||||
static QStringList mVendorNames;
|
||||
|
||||
static QList<Template*> mTemplates;
|
||||
|
||||
static QString mPaperNameOther;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_Db_h
|
||||
@@ -1,207 +0,0 @@
|
||||
/* Distance.cpp
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Distance.h"
|
||||
|
||||
#include <QTextStream>
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
Distance::Distance( double d, Units::Enum unitsEnum )
|
||||
{
|
||||
switch (unitsEnum)
|
||||
{
|
||||
case Units::PT:
|
||||
mDPts = d;
|
||||
break;
|
||||
case Units::IN:
|
||||
mDPts = d * PTS_PER_INCH;
|
||||
break;
|
||||
case Units::MM:
|
||||
mDPts = d * PTS_PER_MM;
|
||||
break;
|
||||
case Units::CM:
|
||||
mDPts = d * PTS_PER_CM;
|
||||
break;
|
||||
case Units::PC:
|
||||
mDPts = d * PTS_PER_PICA;
|
||||
break;
|
||||
default:
|
||||
mDPts = d;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Distance::Distance( double d, const Units& units )
|
||||
{
|
||||
switch (units.toEnum())
|
||||
{
|
||||
case Units::PT:
|
||||
mDPts = d;
|
||||
break;
|
||||
case Units::IN:
|
||||
mDPts = d * PTS_PER_INCH;
|
||||
break;
|
||||
case Units::MM:
|
||||
mDPts = d * PTS_PER_MM;
|
||||
break;
|
||||
case Units::CM:
|
||||
mDPts = d * PTS_PER_CM;
|
||||
break;
|
||||
case Units::PC:
|
||||
mDPts = d * PTS_PER_PICA;
|
||||
break;
|
||||
default:
|
||||
mDPts = d;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Distance::Distance( double d, const QString& unitsId )
|
||||
{
|
||||
Units units = Units( unitsId );
|
||||
|
||||
switch (units.toEnum())
|
||||
{
|
||||
case Units::PT:
|
||||
mDPts = d;
|
||||
break;
|
||||
case Units::IN:
|
||||
mDPts = d * PTS_PER_INCH;
|
||||
break;
|
||||
case Units::MM:
|
||||
mDPts = d * PTS_PER_MM;
|
||||
break;
|
||||
case Units::CM:
|
||||
mDPts = d * PTS_PER_CM;
|
||||
break;
|
||||
case Units::PC:
|
||||
mDPts = d * PTS_PER_PICA;
|
||||
break;
|
||||
default:
|
||||
mDPts = d;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Distance Distance::fromString( const QString& string )
|
||||
{
|
||||
QString stringCopy = string;
|
||||
QTextStream valueStream( &stringCopy, QIODevice::ReadOnly );
|
||||
|
||||
double value;
|
||||
QString unitsString;
|
||||
valueStream >> value >> unitsString;
|
||||
|
||||
if ( !unitsString.isEmpty() && !Units::isIdValid( unitsString ) )
|
||||
{
|
||||
qWarning() << "Invalid Units in string: \"" << string << "\"";
|
||||
}
|
||||
|
||||
return Distance( value, unitsString );
|
||||
}
|
||||
|
||||
|
||||
double Distance::inUnits( const Units& units ) const
|
||||
{
|
||||
double d;
|
||||
|
||||
switch (units.toEnum())
|
||||
{
|
||||
case Units::PT:
|
||||
d = pt();
|
||||
break;
|
||||
case Units::IN:
|
||||
d = in();
|
||||
break;
|
||||
case Units::MM:
|
||||
d = mm();
|
||||
break;
|
||||
case Units::CM:
|
||||
d = cm();
|
||||
break;
|
||||
case Units::PC:
|
||||
d = pc();
|
||||
break;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
double Distance::inUnits( Units::Enum unitsEnum ) const
|
||||
{
|
||||
double d;
|
||||
|
||||
switch (unitsEnum)
|
||||
{
|
||||
case Units::PT:
|
||||
d = pt();
|
||||
break;
|
||||
case Units::IN:
|
||||
d = in();
|
||||
break;
|
||||
case Units::MM:
|
||||
d = mm();
|
||||
break;
|
||||
case Units::CM:
|
||||
d = cm();
|
||||
break;
|
||||
case Units::PC:
|
||||
d = pc();
|
||||
break;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
double Distance::inUnits( const QString& unitsId ) const
|
||||
{
|
||||
return inUnits( Units( unitsId ) );
|
||||
}
|
||||
|
||||
|
||||
QString Distance::toString( const Units& units ) const
|
||||
{
|
||||
return QString::number( inUnits(units) ) + units.toIdString();
|
||||
}
|
||||
|
||||
|
||||
QString Distance::toString( Units::Enum unitsEnum ) const
|
||||
{
|
||||
Units units(unitsEnum);
|
||||
return QString::number( inUnits(units) ) + units.toIdString();
|
||||
}
|
||||
|
||||
|
||||
QString Distance::toString( const QString& unitsId ) const
|
||||
{
|
||||
Units units(unitsId);
|
||||
return QString::number( inUnits(units) ) + units.toIdString();
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,103 +0,0 @@
|
||||
/* Distance.h
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_Distance_h
|
||||
#define glabels_Distance_h
|
||||
|
||||
|
||||
#include "Units.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
|
||||
class Distance
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Distance)
|
||||
|
||||
public:
|
||||
Distance();
|
||||
Distance( double d, Units::Enum unitsEnum = Units::PT );
|
||||
Distance( double d, const Units& units );
|
||||
Distance( double d, const QString& unitsId );
|
||||
|
||||
static Distance pt( double dPts );
|
||||
static Distance in( double dInches );
|
||||
static Distance mm( double dMm );
|
||||
static Distance cm( double dCm );
|
||||
static Distance pc( double dPicas );
|
||||
static Distance fromString( const QString& string );
|
||||
|
||||
|
||||
double pt() const;
|
||||
double in() const;
|
||||
double mm() const;
|
||||
double cm() const;
|
||||
double pc() const;
|
||||
double inUnits( const Units& units ) const;
|
||||
double inUnits( Units::Enum unitsEnum ) const;
|
||||
double inUnits( const QString& unitsId ) const;
|
||||
|
||||
|
||||
QString toString( const Units& units ) const;
|
||||
QString toString( Units::Enum unitsEnum ) const;
|
||||
QString toString( const QString& unitsId ) const;
|
||||
|
||||
|
||||
Distance& operator+=( const Distance& d );
|
||||
Distance& operator-=( const Distance& d );
|
||||
Distance operator-();
|
||||
|
||||
friend inline Distance operator+( const Distance& d1, const Distance& d2 );
|
||||
friend inline Distance operator-( const Distance& d1, const Distance& d2 );
|
||||
friend inline Distance operator*( double x, const Distance& d );
|
||||
friend inline Distance operator*( const Distance& d, double x );
|
||||
friend inline double operator/( const Distance& d1, const Distance& d2 );
|
||||
friend inline Distance operator/( const Distance& d, double x );
|
||||
|
||||
friend inline bool operator<( const Distance& d1, const Distance& d2 );
|
||||
friend inline bool operator<=( const Distance& d1, const Distance& d2 );
|
||||
friend inline bool operator>( const Distance& d1, const Distance& d2 );
|
||||
friend inline bool operator>=( const Distance& d1, const Distance& d2 );
|
||||
friend inline bool operator==( const Distance& d1, const Distance& d2 );
|
||||
friend inline bool operator!=( const Distance& d1, const Distance& d2 );
|
||||
|
||||
friend inline Distance fabs( const Distance& d );
|
||||
friend inline Distance min( const Distance& d1, const Distance& d2 );
|
||||
friend inline Distance max( const Distance& d1, const Distance& d2 );
|
||||
friend inline Distance fmod( const Distance& d1, const Distance& d2 );
|
||||
|
||||
|
||||
private:
|
||||
double mDPts;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#include "Distance.inl"
|
||||
|
||||
|
||||
#endif // glabels_Distance_h
|
||||
@@ -1,219 +0,0 @@
|
||||
/* Distance.inl
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "Constants.h"
|
||||
#include <QtMath>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
inline Distance::Distance() : mDPts(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline Distance Distance::pt( double dPts )
|
||||
{
|
||||
Distance d;
|
||||
d.mDPts = dPts;
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
inline Distance Distance::in( double dInches )
|
||||
{
|
||||
Distance d;
|
||||
d.mDPts = dInches * PTS_PER_INCH;
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
inline Distance Distance::mm( double dMm )
|
||||
{
|
||||
Distance d;
|
||||
d.mDPts = dMm * PTS_PER_MM;
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
inline Distance Distance::cm( double dCm )
|
||||
{
|
||||
Distance d;
|
||||
d.mDPts = dCm * PTS_PER_CM;
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
inline Distance Distance::pc( double dPicas )
|
||||
{
|
||||
Distance d;
|
||||
d.mDPts = dPicas * PTS_PER_PICA;
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
inline double Distance::pt() const
|
||||
{
|
||||
return mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline double Distance::in() const
|
||||
{
|
||||
return mDPts / PTS_PER_INCH;
|
||||
}
|
||||
|
||||
|
||||
inline double Distance::mm() const
|
||||
{
|
||||
return mDPts / PTS_PER_MM;
|
||||
}
|
||||
|
||||
|
||||
inline double Distance::cm() const
|
||||
{
|
||||
return mDPts / PTS_PER_CM;
|
||||
}
|
||||
|
||||
|
||||
inline double Distance::pc() const
|
||||
{
|
||||
return mDPts / PTS_PER_PICA;
|
||||
}
|
||||
|
||||
|
||||
inline Distance& Distance::operator+=( const Distance& d )
|
||||
{
|
||||
mDPts += d.mDPts;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Distance& Distance::operator-=( const Distance& d )
|
||||
{
|
||||
mDPts -= d.mDPts;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Distance Distance::operator-()
|
||||
{
|
||||
return Distance::pt( -mDPts );
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator+( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return Distance::pt( d1.mDPts + d2.mDPts );
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator-( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return Distance::pt( d1.mDPts - d2.mDPts );
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator*( double x, const Distance& d )
|
||||
{
|
||||
return Distance::pt( x * d.mDPts );
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator*( const Distance& d, double x )
|
||||
{
|
||||
return Distance::pt( d.mDPts * x );
|
||||
}
|
||||
|
||||
|
||||
inline double operator/( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return d1.mDPts / d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator/( const Distance& d, double x )
|
||||
{
|
||||
return Distance::pt( d.mDPts / x );
|
||||
}
|
||||
|
||||
|
||||
inline bool operator<( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return d1.mDPts < d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator<=( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return d1.mDPts <= d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator>( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return d1.mDPts > d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator>=( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return d1.mDPts >= d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator==( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return d1.mDPts == d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator!=( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return d1.mDPts != d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline Distance fabs( const Distance& d )
|
||||
{
|
||||
return Distance::pt( qFabs( d.mDPts ) );
|
||||
}
|
||||
|
||||
|
||||
inline Distance min( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return (d1.mDPts < d2.mDPts) ? d1 : d2;
|
||||
}
|
||||
|
||||
|
||||
inline Distance max( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return (d1.mDPts > d2.mDPts) ? d1 : d2;
|
||||
}
|
||||
|
||||
|
||||
inline Distance fmod( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return Distance::pt( std::fmod( d1.mDPts, d2.mDPts ) );
|
||||
}
|
||||
|
||||
}
|
||||
+21
-20
@@ -20,12 +20,13 @@
|
||||
|
||||
#include "File.h"
|
||||
|
||||
#include "FileUtil.h"
|
||||
#include "LabelModel.h"
|
||||
#include "MainWindow.h"
|
||||
#include "SelectProductDialog.h"
|
||||
#include "XmlLabelParser.h"
|
||||
#include "XmlLabelCreator.h"
|
||||
|
||||
#include "model/FileUtil.h"
|
||||
#include "model/Model.h"
|
||||
#include "model/XmlLabelParser.h"
|
||||
#include "model/XmlLabelCreator.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
@@ -49,26 +50,26 @@ namespace glabels
|
||||
SelectProductDialog dialog;
|
||||
dialog.exec();
|
||||
|
||||
const Template* tmplate = dialog.tmplate();
|
||||
const model::Template* tmplate = dialog.tmplate();
|
||||
if ( tmplate )
|
||||
{
|
||||
LabelModel* label = new LabelModel();
|
||||
label->setTmplate( tmplate );
|
||||
label->clearModified();
|
||||
model::Model* model = new model::Model();
|
||||
model->setTmplate( tmplate );
|
||||
model->clearModified();
|
||||
|
||||
// Intelligently decide to rotate label by default
|
||||
const Frame* frame = tmplate->frames().first();
|
||||
label->setRotate( frame->h() > frame->w() );
|
||||
const model::Frame* frame = tmplate->frames().first();
|
||||
model->setRotate( frame->h() > frame->w() );
|
||||
|
||||
// Either apply to current window or open a new one
|
||||
if ( window->isEmpty() )
|
||||
{
|
||||
window->setModel( label );
|
||||
window->setModel( model );
|
||||
}
|
||||
else
|
||||
{
|
||||
MainWindow *newWindow = new MainWindow();
|
||||
newWindow->setModel( label );
|
||||
newWindow->setModel( model );
|
||||
newWindow->show();
|
||||
}
|
||||
|
||||
@@ -105,20 +106,20 @@ namespace glabels
|
||||
);
|
||||
if ( !fileName.isEmpty() )
|
||||
{
|
||||
LabelModel *label = XmlLabelParser::readFile( fileName );
|
||||
if ( label )
|
||||
model::Model *model = model::XmlLabelParser::readFile( fileName );
|
||||
if ( model )
|
||||
{
|
||||
label->setFileName( fileName );
|
||||
model->setFileName( fileName );
|
||||
|
||||
// Either apply to current window or open a new one
|
||||
if ( window->isEmpty() )
|
||||
{
|
||||
window->setModel( label );
|
||||
window->setModel( model );
|
||||
}
|
||||
else
|
||||
{
|
||||
MainWindow *newWindow = new MainWindow();
|
||||
newWindow->setModel( label );
|
||||
newWindow->setModel( model );
|
||||
newWindow->show();
|
||||
}
|
||||
|
||||
@@ -152,7 +153,7 @@ namespace glabels
|
||||
return true;
|
||||
}
|
||||
|
||||
XmlLabelCreator::writeFile( window->model(), window->model()->fileName() );
|
||||
model::XmlLabelCreator::writeFile( window->model(), window->model()->fileName() );
|
||||
window->model()->clearModified();
|
||||
|
||||
// Save CWD
|
||||
@@ -187,7 +188,7 @@ namespace glabels
|
||||
QFileDialog::DontConfirmOverwrite );
|
||||
if ( !rawFileName.isEmpty() )
|
||||
{
|
||||
QString fileName = FileUtil::addExtension( rawFileName, ".glabels" );
|
||||
QString fileName = model::FileUtil::addExtension( rawFileName, ".glabels" );
|
||||
|
||||
|
||||
if ( QFileInfo(fileName).exists() )
|
||||
@@ -206,7 +207,7 @@ namespace glabels
|
||||
}
|
||||
}
|
||||
|
||||
XmlLabelCreator::writeFile( window->model(), fileName );
|
||||
model::XmlLabelCreator::writeFile( window->model(), fileName );
|
||||
window->model()->setFileName( fileName );
|
||||
window->model()->clearModified();
|
||||
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
/* FileUtil.cpp
|
||||
*
|
||||
* Copyright (C) 2015 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "FileUtil.h"
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
QString FileUtil::addExtension( const QString& rawFilename, const QString& extension )
|
||||
{
|
||||
if ( rawFilename.endsWith( extension ) )
|
||||
{
|
||||
return rawFilename;
|
||||
}
|
||||
|
||||
return rawFilename + extension;
|
||||
}
|
||||
|
||||
|
||||
QDir FileUtil::systemTemplatesDir()
|
||||
{
|
||||
QDir dir;
|
||||
|
||||
// First, try finding templates directory relative to application path
|
||||
dir.cd( QApplication::applicationDirPath() );
|
||||
if ( (dir.dirName() == "bin") &&
|
||||
dir.cdUp() && dir.cd( "share" ) && dir.cd( "glabels-qt" ) && dir.cd( "templates" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
// Next, try running out of the source directory.
|
||||
if ( dir.cd( Config::PROJECT_SOURCE_DIR ) && dir.cd( "templates" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
qFatal( "Cannot locate system template directory!" );
|
||||
return QDir("/");
|
||||
}
|
||||
|
||||
|
||||
QDir FileUtil::translationsDir()
|
||||
{
|
||||
QDir dir;
|
||||
|
||||
// First, try finding translations directory relative to application path
|
||||
dir.cd( QApplication::applicationDirPath() );
|
||||
if ( (dir.dirName() == "bin") &&
|
||||
dir.cdUp() && dir.cd( "share" ) && dir.cd( "glabels-qt" ) && dir.cd( "translations" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
// Next, try running out of the source directory.
|
||||
if ( dir.cd( Config::PROJECT_BUILD_DIR ) && dir.cd( "translations" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
qFatal( "Cannot locate system template directory!" );
|
||||
return QDir("/");
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,46 +0,0 @@
|
||||
/* FileUtil.h
|
||||
*
|
||||
* Copyright (C) 2015 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef FileUtil_h
|
||||
#define FileUtil_h
|
||||
|
||||
|
||||
#include <QString>
|
||||
#include <QDir>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace FileUtil
|
||||
{
|
||||
|
||||
QString addExtension( const QString& rawFilename, const QString& extension );
|
||||
|
||||
QDir systemTemplatesDir();
|
||||
QDir userTemplatesDir();
|
||||
|
||||
QDir translationsDir();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // FileUtil_h
|
||||
@@ -1,138 +0,0 @@
|
||||
/* Frame.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Frame.h"
|
||||
|
||||
#include "Markup.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
Frame::Frame( const QString& id )
|
||||
: mId(id), mNLabels(0), mLayoutDescription("")
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
Frame::Frame( const Frame& other )
|
||||
{
|
||||
mId = other.mId;
|
||||
mNLabels = 0;
|
||||
|
||||
foreach ( Layout *layout, mLayouts )
|
||||
{
|
||||
addLayout( layout->dup() );
|
||||
}
|
||||
|
||||
foreach ( Markup *markup, mMarkups )
|
||||
{
|
||||
addMarkup( markup->dup() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString Frame::id() const
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
|
||||
|
||||
int Frame::nLabels() const
|
||||
{
|
||||
return mNLabels;
|
||||
}
|
||||
|
||||
|
||||
QString Frame::layoutDescription() const
|
||||
{
|
||||
return mLayoutDescription;
|
||||
}
|
||||
|
||||
|
||||
const QList<Layout*>& Frame::layouts() const
|
||||
{
|
||||
return mLayouts;
|
||||
}
|
||||
|
||||
|
||||
const QList<Markup*>& Frame::markups() const
|
||||
{
|
||||
return mMarkups;
|
||||
}
|
||||
|
||||
|
||||
QVector<Point> Frame::getOrigins() const
|
||||
{
|
||||
QVector<Point> origins( nLabels() );
|
||||
|
||||
int i = 0;
|
||||
foreach ( Layout *layout, mLayouts )
|
||||
{
|
||||
for ( int iy = 0; iy < layout->ny(); iy++ )
|
||||
{
|
||||
for ( int ix = 0; ix < layout->nx(); ix++ )
|
||||
{
|
||||
origins[i++] = Point( ix*layout->dx() + layout->x0(), iy*layout->dy() + layout->y0() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::stable_sort( origins.begin(), origins.end() );
|
||||
|
||||
return origins;
|
||||
}
|
||||
|
||||
|
||||
void Frame::addLayout( Layout *layout )
|
||||
{
|
||||
mLayouts << layout;
|
||||
|
||||
// Update total number of labels
|
||||
mNLabels += layout->nx() * layout->ny();
|
||||
|
||||
// Update layout description
|
||||
if ( mLayouts.size() == 1 )
|
||||
{
|
||||
/*
|
||||
* Translators: %1 = number of labels across a page,
|
||||
* %2 = number of labels down a page,
|
||||
* %3 = total number of labels on a page (sheet).
|
||||
*/
|
||||
mLayoutDescription = QString( tr("%1 x %2 (%3 per sheet)") )
|
||||
.arg(layout->nx()).arg(layout->ny()).arg(mNLabels);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Translators: %1 is the total number of labels on a page (sheet). */
|
||||
mLayoutDescription = QString( tr("%1 per sheet") ).arg(mNLabels);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Frame::addMarkup( Markup *markup )
|
||||
{
|
||||
mMarkups << markup;
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,88 +0,0 @@
|
||||
/* Frame.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_Frame_h
|
||||
#define glabels_Frame_h
|
||||
|
||||
|
||||
#include "Distance.h"
|
||||
#include "Layout.h"
|
||||
#include "Point.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QList>
|
||||
#include <QPainterPath>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
// Forward references
|
||||
class Markup;
|
||||
|
||||
|
||||
class Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Frame)
|
||||
|
||||
protected:
|
||||
Frame( const QString& id = "0" );
|
||||
Frame( const Frame& other );
|
||||
|
||||
public:
|
||||
virtual Frame* dup() const = 0;
|
||||
|
||||
QString id() const;
|
||||
int nLabels() const;
|
||||
QString layoutDescription() const;
|
||||
const QList<Layout*>& layouts() const;
|
||||
const QList<Markup*>& markups() const;
|
||||
|
||||
QVector<Point> getOrigins() const;
|
||||
|
||||
void addLayout( Layout* layout );
|
||||
void addMarkup( Markup* markup );
|
||||
|
||||
virtual Distance w() const = 0;
|
||||
virtual Distance h() const = 0;
|
||||
|
||||
virtual QString sizeDescription( const Units& units ) const = 0;
|
||||
virtual bool isSimilarTo( Frame* other ) const = 0;
|
||||
|
||||
virtual const QPainterPath& path() const = 0;
|
||||
virtual const QPainterPath& clipPath() const = 0;
|
||||
virtual QPainterPath marginPath( const Distance& size ) const = 0;
|
||||
|
||||
|
||||
private:
|
||||
QString mId;
|
||||
int mNLabels;
|
||||
QString mLayoutDescription;
|
||||
|
||||
QList<Layout*> mLayouts;
|
||||
QList<Markup*> mMarkups;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_Frame_h
|
||||
@@ -1,218 +0,0 @@
|
||||
/* FrameCd.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "FrameCd.h"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "StrUtil.h"
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
FrameCd::FrameCd( const Distance& r1,
|
||||
const Distance& r2,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& waste,
|
||||
const QString& id )
|
||||
: Frame(id), mR1(r1), mR2(r2), mW(w), mH(h), mWaste(waste)
|
||||
{
|
||||
Distance wReal = (mW == 0) ? 2*mR1 : mW;
|
||||
Distance hReal = (mH == 0) ? 2*mR1 : mH;
|
||||
|
||||
//
|
||||
// Create path
|
||||
//
|
||||
{
|
||||
/*
|
||||
* Construct outer subpath (may be clipped if it's a business card CD)
|
||||
*/
|
||||
QPainterPath outerPath;
|
||||
outerPath.addEllipse( (wReal/2 - r1).pt(), (hReal/2 - r1).pt(), 2*r1.pt(), 2*r1.pt() );
|
||||
|
||||
QPainterPath clipPath;
|
||||
clipPath.addRect( 0, 0, wReal.pt(), hReal.pt() );
|
||||
|
||||
mPath.addPath( outerPath & clipPath );
|
||||
mPath.closeSubpath();
|
||||
|
||||
/*
|
||||
* Add inner subpath
|
||||
*/
|
||||
mPath.addEllipse( (wReal/2 - r2).pt(), (hReal/2 - r2).pt(), 2*r2.pt(), 2*r2.pt() );
|
||||
}
|
||||
|
||||
//
|
||||
// Create clip path
|
||||
//
|
||||
{
|
||||
Distance r1Clip = mR1 + mWaste;
|
||||
Distance r2Clip = mR2 - mWaste;
|
||||
Distance wClip = (mW == 0) ? 2*r1Clip : mW + 2*mWaste;
|
||||
Distance hClip = (mH == 0) ? 2*r1Clip : mH + 2*mWaste;
|
||||
|
||||
/*
|
||||
* Construct outer subpath (may be clipped if it's a business card CD)
|
||||
*/
|
||||
QPainterPath outerPath;
|
||||
outerPath.addEllipse( (wReal/2 - r1Clip).pt(), (hReal/2 - r1Clip).pt(), 2*r1Clip.pt(), 2*r1Clip.pt() );
|
||||
|
||||
QPainterPath clipPath;
|
||||
clipPath.addRect( -mWaste.pt(), -mWaste.pt(), wClip.pt(), hClip.pt() );
|
||||
|
||||
mClipPath.addPath( outerPath & clipPath );
|
||||
mClipPath.closeSubpath();
|
||||
|
||||
/*
|
||||
* Add inner subpath
|
||||
*/
|
||||
mClipPath.addEllipse( (wReal/2 - r2Clip).pt(), (hReal/2 - r2Clip).pt(), 2*r2Clip.pt(), 2*r2Clip.pt() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FrameCd::FrameCd( const FrameCd& other )
|
||||
: Frame(other),
|
||||
mR1(other.mR1), mR2(other.mR2), mW(other.mW), mH(other.mH), mWaste(other.mWaste),
|
||||
mPath(other.mPath)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
Frame* FrameCd::dup() const
|
||||
{
|
||||
return new FrameCd( *this );
|
||||
}
|
||||
|
||||
|
||||
Distance FrameCd::w() const
|
||||
{
|
||||
return (mW == 0) ? 2*mR1 : mW;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameCd::h() const
|
||||
{
|
||||
return (mH == 0) ? 2*mR1 : mH;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameCd::r1() const
|
||||
{
|
||||
return mR1;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameCd::r2() const
|
||||
{
|
||||
return mR2;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameCd::waste() const
|
||||
{
|
||||
return mWaste;
|
||||
}
|
||||
|
||||
|
||||
QString FrameCd::sizeDescription( const Units& units ) const
|
||||
{
|
||||
if ( units.toEnum() == Units::IN )
|
||||
{
|
||||
QString dStr = StrUtil::formatFraction( 2 * mR1.in() );
|
||||
|
||||
return QString().sprintf( "%s %s %s",
|
||||
qPrintable(dStr),
|
||||
qPrintable(units.toTrName()),
|
||||
qPrintable(tr("diameter")) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString().sprintf( "%.5g %s %s",
|
||||
2 * mR1.inUnits(units),
|
||||
qPrintable(units.toTrName()),
|
||||
qPrintable(tr("diameter")) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool FrameCd::isSimilarTo( Frame* other ) const
|
||||
{
|
||||
if ( FrameCd *otherCd = dynamic_cast<FrameCd*>(other) )
|
||||
{
|
||||
if ( (fabs( mW - otherCd->mW ) <= EPSILON) &&
|
||||
(fabs( mH - otherCd->mH ) <= EPSILON) &&
|
||||
(fabs( mR1 - otherCd->mR1 ) <= EPSILON) &&
|
||||
(fabs( mR2 - otherCd->mR2 ) <= EPSILON) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameCd::path() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameCd::clipPath() const
|
||||
{
|
||||
return mClipPath;
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FrameCd::marginPath( const Distance& size ) const
|
||||
{
|
||||
Distance wReal = (mW == 0) ? 2*mR1 : mW;
|
||||
Distance hReal = (mH == 0) ? 2*mR1 : mH;
|
||||
|
||||
Distance r1 = mR1 - size;
|
||||
Distance r2 = mR2 + size;
|
||||
|
||||
QPainterPath path;
|
||||
|
||||
/*
|
||||
* Construct outer subpath (may be clipped if it's a business card CD)
|
||||
*/
|
||||
QPainterPath outerPath;
|
||||
outerPath.addEllipse( (wReal/2 - r1).pt(), (hReal/2 - r1).pt(), 2*r1.pt(), 2*r1.pt() );
|
||||
|
||||
QPainterPath clipPath;
|
||||
clipPath.addRect( size.pt(), size.pt(), (wReal-2*size).pt(), (hReal-2*size).pt() );
|
||||
|
||||
path.addPath( outerPath & clipPath );
|
||||
path.closeSubpath();
|
||||
|
||||
/*
|
||||
* Add inner subpath
|
||||
*/
|
||||
path.addEllipse( (wReal/2 - r2).pt(), (hReal/2 - r2).pt(), 2*r2.pt(), 2*r2.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,77 +0,0 @@
|
||||
/* FrameCd.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_FrameCd_h
|
||||
#define glabels_FrameCd_h
|
||||
|
||||
|
||||
#include "Frame.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class FrameCd : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FrameCd)
|
||||
|
||||
public:
|
||||
FrameCd( const Distance& r1,
|
||||
const Distance& r2,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& waste,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameCd( const FrameCd &other );
|
||||
|
||||
Frame *dup() const override;
|
||||
|
||||
Distance r1() const;
|
||||
Distance r2() const;
|
||||
Distance waste() const;
|
||||
|
||||
Distance w() const override;
|
||||
Distance h() const override;
|
||||
|
||||
QString sizeDescription( const Units& units ) const override;
|
||||
bool isSimilarTo( Frame* other ) const override;
|
||||
|
||||
const QPainterPath& path() const override;
|
||||
const QPainterPath& clipPath() const override;
|
||||
QPainterPath marginPath( const Distance& size ) const override;
|
||||
|
||||
|
||||
private:
|
||||
Distance mR1;
|
||||
Distance mR2;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
QPainterPath mClipPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_FrameCd_h
|
||||
@@ -1,130 +0,0 @@
|
||||
/* FrameEllipse.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "FrameEllipse.h"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "StrUtil.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
FrameEllipse::FrameEllipse( const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& waste,
|
||||
const QString& id )
|
||||
: Frame(id), mW(w), mH(h), mWaste(waste)
|
||||
{
|
||||
mPath.addEllipse( 0, 0, mW.pt(), mH.pt() );
|
||||
mClipPath.addEllipse( -mWaste.pt(), -mWaste.pt(), (mW+2*mWaste).pt(), (mH+2*mWaste).pt() );
|
||||
}
|
||||
|
||||
FrameEllipse::FrameEllipse( const FrameEllipse& other )
|
||||
: Frame(other), mW(other.mW), mH(other.mH), mWaste(other.mWaste), mPath(other.mPath)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
Frame* FrameEllipse::dup() const
|
||||
{
|
||||
return new FrameEllipse( *this );
|
||||
}
|
||||
|
||||
|
||||
Distance FrameEllipse::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameEllipse::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameEllipse::waste() const
|
||||
{
|
||||
return mWaste;
|
||||
}
|
||||
|
||||
|
||||
QString FrameEllipse::sizeDescription( const Units& units ) const
|
||||
{
|
||||
if ( units.toEnum() == Units::IN )
|
||||
{
|
||||
QString wStr = StrUtil::formatFraction( mW.in() );
|
||||
QString hStr = StrUtil::formatFraction( mH.in() );
|
||||
|
||||
return QString().sprintf( "%s x %s %s",
|
||||
qPrintable(wStr),
|
||||
qPrintable(hStr),
|
||||
qPrintable(units.toTrName()) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString().sprintf( "%.5g x %.5g %s",
|
||||
mW.inUnits(units),
|
||||
mH.inUnits(units),
|
||||
qPrintable(units.toTrName()) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool FrameEllipse::isSimilarTo( Frame* other ) const
|
||||
{
|
||||
if ( FrameEllipse* otherEllipse = dynamic_cast<FrameEllipse*>(other) )
|
||||
{
|
||||
if ( (fabs( mW - otherEllipse->mW ) <= EPSILON) &&
|
||||
(fabs( mH - otherEllipse->mH ) <= EPSILON) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameEllipse::path() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameEllipse::clipPath() const
|
||||
{
|
||||
return mClipPath;
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FrameEllipse::marginPath( const Distance& size ) const
|
||||
{
|
||||
Distance w = mW - 2*size;
|
||||
Distance h = mH - 2*size;
|
||||
|
||||
QPainterPath path;
|
||||
path.addEllipse( size.pt(), size.pt(), w.pt(), h.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,71 +0,0 @@
|
||||
/* FrameEllipse.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_FrameEllipse_h
|
||||
#define glabels_FrameEllipse_h
|
||||
|
||||
|
||||
#include "Frame.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class FrameEllipse : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FrameEllipse)
|
||||
|
||||
public:
|
||||
FrameEllipse( const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& waste,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameEllipse( const FrameEllipse& other );
|
||||
|
||||
Frame* dup() const override;
|
||||
|
||||
Distance waste() const;
|
||||
|
||||
Distance w() const override;
|
||||
Distance h() const override;
|
||||
|
||||
QString sizeDescription( const Units& units ) const override;
|
||||
bool isSimilarTo( Frame* other ) const override;
|
||||
|
||||
const QPainterPath& path() const override;
|
||||
const QPainterPath& clipPath() const override;
|
||||
QPainterPath marginPath( const Distance& size ) const override;
|
||||
|
||||
|
||||
private:
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
QPainterPath mClipPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_FrameEllipse_h
|
||||
@@ -1,152 +0,0 @@
|
||||
/* FrameRect.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "FrameRect.h"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "StrUtil.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
FrameRect::FrameRect( const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& r,
|
||||
const Distance& xWaste,
|
||||
const Distance& yWaste,
|
||||
const QString& id )
|
||||
: Frame(id), mW(w), mH(h), mR(r), mXWaste(xWaste), mYWaste(yWaste)
|
||||
{
|
||||
mPath.addRoundedRect( 0, 0, mW.pt(), mH.pt(), mR.pt(), mR.pt() );
|
||||
|
||||
mClipPath.addRoundedRect( -mXWaste.pt(), -mYWaste.pt(),
|
||||
mW.pt() + 2*mXWaste.pt(), mH.pt() + 2*mYWaste.pt(),
|
||||
mR.pt(), mR.pt() );
|
||||
}
|
||||
|
||||
|
||||
FrameRect::FrameRect( const FrameRect &other )
|
||||
: Frame(other),
|
||||
mW(other.mW), mH(other.mH), mR(other.mR), mXWaste(other.mXWaste),
|
||||
mYWaste(other.mYWaste), mPath(other.mPath)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
Frame* FrameRect::dup() const
|
||||
{
|
||||
return new FrameRect( *this );
|
||||
}
|
||||
|
||||
|
||||
Distance FrameRect::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameRect::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameRect::r() const
|
||||
{
|
||||
return mR;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameRect::xWaste() const
|
||||
{
|
||||
return mXWaste;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameRect::yWaste() const
|
||||
{
|
||||
return mYWaste;
|
||||
}
|
||||
|
||||
|
||||
QString FrameRect::sizeDescription( const Units& units ) const
|
||||
{
|
||||
if ( units.toEnum() == Units::IN )
|
||||
{
|
||||
QString wStr = StrUtil::formatFraction( mW.in() );
|
||||
QString hStr = StrUtil::formatFraction( mH.in() );
|
||||
|
||||
return QString().sprintf( "%s x %s %s",
|
||||
qPrintable(wStr),
|
||||
qPrintable(hStr),
|
||||
qPrintable(units.toTrName()) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString().sprintf( "%.5g x %.5g %s",
|
||||
mW.inUnits(units),
|
||||
mH.inUnits(units),
|
||||
qPrintable(units.toTrName()) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool FrameRect::isSimilarTo( Frame* other ) const
|
||||
{
|
||||
if ( FrameRect *otherRect = dynamic_cast<FrameRect*>(other) )
|
||||
{
|
||||
if ( (fabs( mW - otherRect->mW ) <= EPSILON) &&
|
||||
(fabs( mH - otherRect->mH ) <= EPSILON) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameRect::path() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameRect::clipPath() const
|
||||
{
|
||||
return mClipPath;
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FrameRect::marginPath( const Distance& size ) const
|
||||
{
|
||||
Distance w = mW - 2*size;
|
||||
Distance h = mH - 2*size;
|
||||
Distance r = std::max( mR - size, Distance(0.0) );
|
||||
|
||||
QPainterPath path;
|
||||
path.addRoundedRect( size.pt(), size.pt(), w.pt(), h.pt(), r.pt(), r.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,78 +0,0 @@
|
||||
/* FrameRect.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_FrameRect_h
|
||||
#define glabels_FrameRect_h
|
||||
|
||||
|
||||
#include "Frame.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class FrameRect : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FrameRect)
|
||||
|
||||
public:
|
||||
FrameRect( const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& r,
|
||||
const Distance& xWaste,
|
||||
const Distance& yWaste,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameRect( const FrameRect& other );
|
||||
|
||||
Frame* dup() const override;
|
||||
|
||||
Distance r() const;
|
||||
Distance xWaste() const;
|
||||
Distance yWaste() const;
|
||||
|
||||
Distance w() const override;
|
||||
Distance h() const override;
|
||||
|
||||
QString sizeDescription( const Units& units ) const override;
|
||||
|
||||
bool isSimilarTo( Frame* other ) const override;
|
||||
|
||||
const QPainterPath& path() const override;
|
||||
const QPainterPath& clipPath() const override;
|
||||
QPainterPath marginPath( const Distance& size ) const override;
|
||||
|
||||
|
||||
private:
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mR;
|
||||
Distance mXWaste;
|
||||
Distance mYWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
QPainterPath mClipPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_FrameRect_h
|
||||
@@ -1,134 +0,0 @@
|
||||
/* FrameRound.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "FrameRound.h"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "StrUtil.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
FrameRound::FrameRound( const Distance& r,
|
||||
const Distance& waste,
|
||||
const QString& id )
|
||||
: Frame(id), mR(r), mWaste(waste)
|
||||
{
|
||||
mPath.addEllipse( 0, 0, 2*mR.pt(), 2*mR.pt() );
|
||||
mClipPath.addEllipse( -mWaste.pt(), -mWaste.pt(),
|
||||
2*(mR+mWaste).pt(), 2*(mR+mWaste).pt() );
|
||||
}
|
||||
|
||||
|
||||
FrameRound::FrameRound( const FrameRound& other )
|
||||
: Frame(other), mR(other.mR), mWaste(other.mWaste), mPath(other.mPath)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
Frame* FrameRound::dup() const
|
||||
{
|
||||
return new FrameRound( *this );
|
||||
}
|
||||
|
||||
|
||||
Distance FrameRound::w() const
|
||||
{
|
||||
return 2*mR;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameRound::h() const
|
||||
{
|
||||
return 2*mR;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameRound::r() const
|
||||
{
|
||||
return mR;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameRound::waste() const
|
||||
{
|
||||
return mWaste;
|
||||
}
|
||||
|
||||
|
||||
QString FrameRound::sizeDescription( const Units& units ) const
|
||||
{
|
||||
if ( units.toEnum() == Units::IN )
|
||||
{
|
||||
QString dStr = StrUtil::formatFraction( 2 * mR.in() );
|
||||
|
||||
return QString().sprintf( "%s %s %s",
|
||||
qPrintable(dStr),
|
||||
qPrintable(units.toTrName()),
|
||||
qPrintable(tr("diameter")) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString().sprintf( "%.5g %s %s",
|
||||
2 * mR.inUnits(units),
|
||||
qPrintable(units.toTrName()),
|
||||
qPrintable(tr("diameter")) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool FrameRound::isSimilarTo( Frame* other ) const
|
||||
{
|
||||
if ( FrameRound *otherRound = dynamic_cast<FrameRound*>(other) )
|
||||
{
|
||||
if ( fabs( mR - otherRound->mR ) <= EPSILON )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameRound::path() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameRound::clipPath() const
|
||||
{
|
||||
return mClipPath;
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FrameRound::marginPath( const Distance& size ) const
|
||||
{
|
||||
Distance r = mR - size;
|
||||
|
||||
QPainterPath path;
|
||||
path.addEllipse( size.pt(), size.pt(), 2*r.pt(), 2*r.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,70 +0,0 @@
|
||||
/* FrameRound.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_FrameRound_h
|
||||
#define glabels_FrameRound_h
|
||||
|
||||
|
||||
#include "Frame.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class FrameRound : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FrameRound)
|
||||
|
||||
public:
|
||||
FrameRound( const Distance& r,
|
||||
const Distance& waste,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameRound( const FrameRound &other );
|
||||
|
||||
Frame *dup() const override;
|
||||
|
||||
Distance r() const;
|
||||
Distance waste() const;
|
||||
|
||||
Distance w() const override;
|
||||
Distance h() const override;
|
||||
|
||||
QString sizeDescription( const Units& units ) const override;
|
||||
bool isSimilarTo( Frame* other ) const override;
|
||||
|
||||
const QPainterPath& path() const override;
|
||||
const QPainterPath& clipPath() const override;
|
||||
QPainterPath marginPath( const Distance& size ) const override;
|
||||
|
||||
|
||||
private:
|
||||
Distance mR;
|
||||
Distance mWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
QPainterPath mClipPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_FrameRound_h
|
||||
@@ -1,588 +0,0 @@
|
||||
/* Handles.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Handles.h"
|
||||
|
||||
#include "LabelModelObject.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const double handlePixels = 7;
|
||||
const double handleOutlineWidthPixels = 1;
|
||||
|
||||
const QColor handleFillColor( 0, 192, 0, 96 );
|
||||
const QColor originHandleFillColor( 192, 0, 0, 96 );
|
||||
const QColor handleOutlineColor( 0, 0, 0, 192 );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Handle Constructor
|
||||
///
|
||||
Handle::Handle( LabelModelObject* owner, Location location )
|
||||
: mOwner(owner), mLocation(location)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Handle Destructor
|
||||
///
|
||||
Handle::~Handle()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Handle owner
|
||||
///
|
||||
LabelModelObject* Handle::owner() const
|
||||
{
|
||||
return mOwner;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Handle location
|
||||
///
|
||||
Handle::Location Handle::location() const
|
||||
{
|
||||
return mLocation;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw Handle at x,y
|
||||
///
|
||||
void Handle::drawAt( QPainter* painter,
|
||||
double scale,
|
||||
const Distance& x,
|
||||
const Distance& y,
|
||||
QColor color ) const
|
||||
{
|
||||
painter->save();
|
||||
|
||||
painter->translate( x.pt(), y.pt() );
|
||||
|
||||
double s = 1.0 / scale;
|
||||
|
||||
QPen pen( handleOutlineColor );
|
||||
pen.setCosmetic( true );
|
||||
pen.setWidth( handleOutlineWidthPixels );
|
||||
|
||||
painter->setPen( pen );
|
||||
painter->setBrush( color );
|
||||
|
||||
painter->drawRect( QRectF( -s*handlePixels/2.0, -s*handlePixels/2.0,
|
||||
s*handlePixels, s*handlePixels ) );
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Create Handle path at x,y
|
||||
///
|
||||
QPainterPath Handle::pathAt( double scale,
|
||||
const Distance& x,
|
||||
const Distance& y ) const
|
||||
{
|
||||
QPainterPath path;
|
||||
|
||||
double s = 1/scale;
|
||||
|
||||
path.addRect( -s*handlePixels/2, -s*handlePixels/2, s*handlePixels, s*handlePixels );
|
||||
path.translate( x.pt(), y.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleNorth Constructor
|
||||
///
|
||||
HandleNorth::HandleNorth( LabelModelObject* owner )
|
||||
: Handle( owner, N )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleNorth Destructor
|
||||
///
|
||||
HandleNorth::~HandleNorth()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleNorth Clone
|
||||
///
|
||||
HandleNorth* HandleNorth::clone( LabelModelObject* newOwner ) const
|
||||
{
|
||||
return new HandleNorth( newOwner );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw HandleNorth
|
||||
///
|
||||
void HandleNorth::draw( QPainter* painter, double scale ) const
|
||||
{
|
||||
drawAt( painter, scale, mOwner->w()/2, 0, handleFillColor );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleNorth Path
|
||||
///
|
||||
QPainterPath HandleNorth::path( double scale ) const
|
||||
{
|
||||
return pathAt( scale, mOwner->w()/2, 0 );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleNorthEast Constructor
|
||||
///
|
||||
HandleNorthEast::HandleNorthEast( LabelModelObject* owner )
|
||||
: Handle( owner, NE )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleNorthEast Destructor
|
||||
///
|
||||
HandleNorthEast::~HandleNorthEast()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleNorthEast Clone
|
||||
///
|
||||
HandleNorthEast* HandleNorthEast::clone( LabelModelObject* newOwner ) const
|
||||
{
|
||||
return new HandleNorthEast( newOwner );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw HandleNorthEast
|
||||
///
|
||||
void HandleNorthEast::draw( QPainter* painter, double scale ) const
|
||||
{
|
||||
drawAt( painter, scale, mOwner->w(), 0, handleFillColor );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleNorthEast Path
|
||||
///
|
||||
QPainterPath HandleNorthEast::path( double scale ) const
|
||||
{
|
||||
return pathAt( scale, mOwner->w(), 0 );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleEast Constructor
|
||||
///
|
||||
HandleEast::HandleEast( LabelModelObject* owner )
|
||||
: Handle( owner, E )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleEast Destructor
|
||||
///
|
||||
HandleEast::~HandleEast()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleEast Clone
|
||||
///
|
||||
HandleEast* HandleEast::clone( LabelModelObject* newOwner ) const
|
||||
{
|
||||
return new HandleEast( newOwner );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw HandleEast
|
||||
///
|
||||
void HandleEast::draw( QPainter* painter, double scale ) const
|
||||
{
|
||||
drawAt( painter, scale, mOwner->w(), mOwner->h()/2, handleFillColor );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleEast Path
|
||||
///
|
||||
QPainterPath HandleEast::path( double scale ) const
|
||||
{
|
||||
return pathAt( scale, mOwner->w(), mOwner->h()/2 );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleSouthEast Constructor
|
||||
///
|
||||
HandleSouthEast::HandleSouthEast( LabelModelObject* owner )
|
||||
: Handle( owner, SE )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleSouthEast Destructor
|
||||
///
|
||||
HandleSouthEast::~HandleSouthEast()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleSouthEast Clone
|
||||
///
|
||||
HandleSouthEast* HandleSouthEast::clone( LabelModelObject* newOwner ) const
|
||||
{
|
||||
return new HandleSouthEast( newOwner );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw HandleSouthEast
|
||||
///
|
||||
void HandleSouthEast::draw( QPainter* painter, double scale ) const
|
||||
{
|
||||
drawAt( painter, scale, mOwner->w(), mOwner->h(), handleFillColor );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleSouthEast Path
|
||||
///
|
||||
QPainterPath HandleSouthEast::path( double scale ) const
|
||||
{
|
||||
return pathAt( scale, mOwner->w(), mOwner->h() );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleSouth Constructor
|
||||
///
|
||||
HandleSouth::HandleSouth( LabelModelObject* owner )
|
||||
: Handle( owner, S )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleSouth Destructor
|
||||
///
|
||||
HandleSouth::~HandleSouth()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleSouth Clone
|
||||
///
|
||||
HandleSouth* HandleSouth::clone( LabelModelObject* newOwner ) const
|
||||
{
|
||||
return new HandleSouth( newOwner );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw HandleSouth
|
||||
///
|
||||
void HandleSouth::draw( QPainter* painter, double scale ) const
|
||||
{
|
||||
drawAt( painter, scale, mOwner->w()/2, mOwner->h(), handleFillColor );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleSouth Path
|
||||
///
|
||||
QPainterPath HandleSouth::path( double scale ) const
|
||||
{
|
||||
return pathAt( scale, mOwner->w()/2, mOwner->h() );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleSouthWest Constructor
|
||||
///
|
||||
HandleSouthWest::HandleSouthWest( LabelModelObject* owner )
|
||||
: Handle( owner, SW )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleSouthWest Destructor
|
||||
///
|
||||
HandleSouthWest::~HandleSouthWest()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleSouthWest Clone
|
||||
///
|
||||
HandleSouthWest* HandleSouthWest::clone( LabelModelObject* newOwner ) const
|
||||
{
|
||||
return new HandleSouthWest( newOwner );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw HandleSouthWest
|
||||
///
|
||||
void HandleSouthWest::draw( QPainter* painter, double scale ) const
|
||||
{
|
||||
drawAt( painter, scale, 0, mOwner->h(), handleFillColor );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleSouthWest Path
|
||||
///
|
||||
QPainterPath HandleSouthWest::path( double scale ) const
|
||||
{
|
||||
return pathAt( scale, 0, mOwner->h() );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleWest Constructor
|
||||
///
|
||||
HandleWest::HandleWest( LabelModelObject* owner )
|
||||
: Handle( owner, W )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleWest Destructor
|
||||
///
|
||||
HandleWest::~HandleWest()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleWest Clone
|
||||
///
|
||||
HandleWest* HandleWest::clone( LabelModelObject* newOwner ) const
|
||||
{
|
||||
return new HandleWest( newOwner );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw HandleWest
|
||||
///
|
||||
void HandleWest::draw( QPainter* painter, double scale ) const
|
||||
{
|
||||
drawAt( painter, scale, 0, mOwner->h()/2, handleFillColor );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleWest Path
|
||||
///
|
||||
QPainterPath HandleWest::path( double scale ) const
|
||||
{
|
||||
return pathAt( scale, 0, mOwner->h()/2 );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleNorthWest Constructor
|
||||
///
|
||||
HandleNorthWest::HandleNorthWest( LabelModelObject* owner )
|
||||
: Handle( owner, NW )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleNorthWest Destructor
|
||||
///
|
||||
HandleNorthWest::~HandleNorthWest()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
///
|
||||
/// HandleNorthWest Clone
|
||||
///
|
||||
HandleNorthWest* HandleNorthWest::clone( LabelModelObject* newOwner ) const
|
||||
{
|
||||
return new HandleNorthWest( newOwner );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw HandleNorthWest
|
||||
///
|
||||
void HandleNorthWest::draw( QPainter* painter, double scale ) const
|
||||
{
|
||||
drawAt( painter, scale, 0, 0, originHandleFillColor );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleNorthWest Path
|
||||
///
|
||||
QPainterPath HandleNorthWest::path( double scale ) const
|
||||
{
|
||||
return pathAt( scale, 0, 0 );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleP1 Constructor
|
||||
///
|
||||
HandleP1::HandleP1( LabelModelObject* owner )
|
||||
: Handle( owner, P1 )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleP1 Destructor
|
||||
///
|
||||
HandleP1::~HandleP1()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleP1 Clone
|
||||
///
|
||||
HandleP1* HandleP1::clone( LabelModelObject* newOwner ) const
|
||||
{
|
||||
return new HandleP1( newOwner );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw HandleP1
|
||||
///
|
||||
void HandleP1::draw( QPainter* painter, double scale ) const
|
||||
{
|
||||
drawAt( painter, scale, 0, 0, originHandleFillColor );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleP1 Path
|
||||
///
|
||||
QPainterPath HandleP1::path( double scale ) const
|
||||
{
|
||||
return pathAt( scale, 0, 0 );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleP2 Constructor
|
||||
///
|
||||
HandleP2::HandleP2( LabelModelObject* owner )
|
||||
: Handle( owner, P2 )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleP2 Destructor
|
||||
///
|
||||
HandleP2::~HandleP2()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleP2 Clone
|
||||
///
|
||||
HandleP2* HandleP2::clone( LabelModelObject* newOwner ) const
|
||||
{
|
||||
return new HandleP2( newOwner );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw HandleP2
|
||||
///
|
||||
void HandleP2::draw( QPainter* painter, double scale ) const
|
||||
{
|
||||
drawAt( painter, scale, mOwner->w(), mOwner->h(), handleFillColor );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// HandleP2 Path
|
||||
///
|
||||
QPainterPath HandleP2::path( double scale ) const
|
||||
{
|
||||
return pathAt( scale, mOwner->w(), mOwner->h() );
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,336 +0,0 @@
|
||||
/* Handles.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef Handles_h
|
||||
#define Handles_h
|
||||
|
||||
|
||||
#include "Distance.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
// Forward References
|
||||
class LabelModelObject;
|
||||
|
||||
|
||||
///
|
||||
/// Handle Base Class
|
||||
///
|
||||
class Handle
|
||||
{
|
||||
////////////////////////////
|
||||
// Location enumeration
|
||||
////////////////////////////
|
||||
public:
|
||||
enum Location { NW, N, NE, E, SE, S, SW, W, P1, P2 };
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Lifecycle Methods
|
||||
////////////////////////////
|
||||
protected:
|
||||
Handle( LabelModelObject* owner, Location location );
|
||||
public:
|
||||
virtual ~Handle();
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Duplication
|
||||
////////////////////////////
|
||||
virtual Handle* clone( LabelModelObject* newOwner ) const = 0;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Attribue Methods
|
||||
////////////////////////////
|
||||
LabelModelObject* owner() const;
|
||||
Location location() const;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Drawing Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
virtual void draw( QPainter* painter, double scale ) const = 0;
|
||||
virtual QPainterPath path( double scale ) const = 0;
|
||||
protected:
|
||||
void drawAt( QPainter* painter,
|
||||
double scale,
|
||||
const Distance& x,
|
||||
const Distance& y,
|
||||
QColor color ) const;
|
||||
|
||||
QPainterPath pathAt( double scale,
|
||||
const Distance& x,
|
||||
const Distance& y ) const;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Protected Data
|
||||
////////////////////////////
|
||||
protected:
|
||||
LabelModelObject* mOwner;
|
||||
Location mLocation;
|
||||
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// HandleNorth Class
|
||||
///
|
||||
class HandleNorth : public Handle
|
||||
{
|
||||
////////////////////////////
|
||||
// Lifecycle Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
HandleNorth( LabelModelObject* owner );
|
||||
~HandleNorth() override;
|
||||
HandleNorth* clone( LabelModelObject* newOwner ) const override;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Drawing Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter, double scale ) const override;
|
||||
QPainterPath path( double scale ) const override;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// HandleNorthEast Class
|
||||
///
|
||||
class HandleNorthEast : public Handle
|
||||
{
|
||||
////////////////////////////
|
||||
// Lifecycle Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
HandleNorthEast( LabelModelObject* owner );
|
||||
~HandleNorthEast() override;
|
||||
HandleNorthEast* clone( LabelModelObject* newOwner ) const override;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Drawing Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter, double scale ) const override;
|
||||
QPainterPath path( double scale ) const override;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// HandleEast Class
|
||||
///
|
||||
class HandleEast : public Handle
|
||||
{
|
||||
////////////////////////////
|
||||
// Lifecycle Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
HandleEast( LabelModelObject* owner );
|
||||
~HandleEast() override;
|
||||
HandleEast* clone( LabelModelObject* newOwner ) const override;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Drawing Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter, double scale ) const override;
|
||||
QPainterPath path( double scale ) const override;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// HandleSouthEast Class
|
||||
///
|
||||
class HandleSouthEast : public Handle
|
||||
{
|
||||
////////////////////////////
|
||||
// Lifecycle Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
HandleSouthEast( LabelModelObject* owner );
|
||||
~HandleSouthEast() override;
|
||||
HandleSouthEast* clone( LabelModelObject* newOwner ) const override;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Drawing Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter, double scale ) const override;
|
||||
QPainterPath path( double scale ) const override;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// HandleSouth Class
|
||||
///
|
||||
class HandleSouth : public Handle
|
||||
{
|
||||
////////////////////////////
|
||||
// Lifecycle Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
HandleSouth( LabelModelObject* owner );
|
||||
~HandleSouth() override;
|
||||
HandleSouth* clone( LabelModelObject* newOwner ) const override;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Drawing Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter, double scale ) const override;
|
||||
QPainterPath path( double scale ) const override;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// HandleSouthWest Class
|
||||
///
|
||||
class HandleSouthWest : public Handle
|
||||
{
|
||||
////////////////////////////
|
||||
// Lifecycle Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
HandleSouthWest( LabelModelObject* owner );
|
||||
~HandleSouthWest() override;
|
||||
HandleSouthWest* clone( LabelModelObject* newOwner ) const override;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Drawing Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter, double scale ) const override;
|
||||
QPainterPath path( double scale ) const override;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// HandleWest Class
|
||||
///
|
||||
class HandleWest : public Handle
|
||||
{
|
||||
////////////////////////////
|
||||
// Lifecycle Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
HandleWest( LabelModelObject* owner );
|
||||
~HandleWest() override;
|
||||
HandleWest* clone( LabelModelObject* newOwner ) const override;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Drawing Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter, double scale ) const override;
|
||||
QPainterPath path( double scale ) const override;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// HandleNorthWest Class
|
||||
///
|
||||
class HandleNorthWest : public Handle
|
||||
{
|
||||
////////////////////////////
|
||||
// Lifecycle Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
HandleNorthWest( LabelModelObject* owner );
|
||||
~HandleNorthWest() override;
|
||||
HandleNorthWest* clone( LabelModelObject* newOwner ) const override;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Drawing Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter, double scale ) const override;
|
||||
QPainterPath path( double scale ) const override;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// HandleP1 Class
|
||||
///
|
||||
class HandleP1 : public Handle
|
||||
{
|
||||
////////////////////////////
|
||||
// Lifecycle Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
HandleP1( LabelModelObject* owner );
|
||||
~HandleP1() override;
|
||||
HandleP1* clone( LabelModelObject* newOwner ) const override;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Drawing Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter, double scale ) const override;
|
||||
QPainterPath path( double scale ) const override;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// HandleP2 Class
|
||||
///
|
||||
class HandleP2 : public Handle
|
||||
{
|
||||
////////////////////////////
|
||||
// Lifecycle Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
HandleP2( LabelModelObject* owner );
|
||||
~HandleP2() override;
|
||||
|
||||
////////////////////////////
|
||||
// Duplication
|
||||
////////////////////////////
|
||||
HandleP2* clone( LabelModelObject* newOwner ) const override;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Drawing Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter, double scale ) const override;
|
||||
QPainterPath path( double scale ) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // Handles_h
|
||||
+83
-82
@@ -21,22 +21,23 @@
|
||||
#include "LabelEditor.h"
|
||||
|
||||
#include "Cursors.h"
|
||||
#include "FrameCd.h"
|
||||
#include "FrameEllipse.h"
|
||||
#include "FrameRect.h"
|
||||
#include "FrameRound.h"
|
||||
#include "LabelModel.h"
|
||||
#include "LabelModelObject.h"
|
||||
#include "LabelModelBarcodeObject.h"
|
||||
#include "LabelModelBoxObject.h"
|
||||
#include "LabelModelEllipseObject.h"
|
||||
#include "LabelModelImageObject.h"
|
||||
#include "LabelModelLineObject.h"
|
||||
#include "LabelModelTextObject.h"
|
||||
#include "Markup.h"
|
||||
#include "Settings.h"
|
||||
#include "UndoRedoModel.h"
|
||||
|
||||
#include "model/FrameCd.h"
|
||||
#include "model/FrameEllipse.h"
|
||||
#include "model/FrameRect.h"
|
||||
#include "model/FrameRound.h"
|
||||
#include "model/Model.h"
|
||||
#include "model/ModelObject.h"
|
||||
#include "model/ModelBarcodeObject.h"
|
||||
#include "model/ModelBoxObject.h"
|
||||
#include "model/ModelEllipseObject.h"
|
||||
#include "model/ModelImageObject.h"
|
||||
#include "model/ModelLineObject.h"
|
||||
#include "model/ModelTextObject.h"
|
||||
#include "model/Markup.h"
|
||||
#include "model/Settings.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QtMath>
|
||||
#include <QtDebug>
|
||||
@@ -66,7 +67,7 @@ namespace glabels
|
||||
|
||||
const QColor gridLineColor( 192, 192, 192 );
|
||||
const double gridLineWidthPixels = 1;
|
||||
const Distance gridSpacing = Distance::pt(9); // TODO: determine from locale.
|
||||
const model::Distance gridSpacing = model::Distance::pt(9); // TODO: determine from locale.
|
||||
|
||||
const QColor markupLineColor( 240, 99, 99 );
|
||||
const double markupLineWidthPixels = 1;
|
||||
@@ -94,7 +95,7 @@ namespace glabels
|
||||
setMouseTracking( true );
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
connect( Settings::instance(), SIGNAL(changed()), this, SLOT(onSettingsChanged()) );
|
||||
connect( model::Settings::instance(), SIGNAL(changed()), this, SLOT(onSettingsChanged()) );
|
||||
onSettingsChanged();
|
||||
}
|
||||
|
||||
@@ -133,7 +134,7 @@ namespace glabels
|
||||
/// Model Parameter Setter
|
||||
///
|
||||
void
|
||||
LabelEditor::setModel( LabelModel* model, UndoRedoModel* undoRedoModel )
|
||||
LabelEditor::setModel( model::Model* model, UndoRedoModel* undoRedoModel )
|
||||
{
|
||||
mModel = model;
|
||||
mUndoRedoModel = undoRedoModel;
|
||||
@@ -246,7 +247,7 @@ namespace glabels
|
||||
|
||||
double x_scale = ( wPixels - ZOOM_TO_FIT_PAD ) / mModel->w().pt();
|
||||
double y_scale = ( hPixels - ZOOM_TO_FIT_PAD ) / mModel->h().pt();
|
||||
double newZoom = qMin( x_scale, y_scale ) * PTS_PER_INCH / physicalDpiX();
|
||||
double newZoom = qMin( x_scale, y_scale ) * model::PTS_PER_INCH / physicalDpiX();
|
||||
|
||||
// Limits
|
||||
newZoom = qMin( newZoom, zoomLevels[0] );
|
||||
@@ -286,7 +287,7 @@ namespace glabels
|
||||
mZoomToFitFlag = zoomToFitFlag;
|
||||
|
||||
/* Actual scale depends on DPI of display (assume DpiX == DpiY). */
|
||||
mScale = zoom * physicalDpiX() / PTS_PER_INCH;
|
||||
mScale = zoom * physicalDpiX() / model::PTS_PER_INCH;
|
||||
|
||||
setMinimumSize( mScale*mModel->w().pt() + ZOOM_TO_FIT_PAD,
|
||||
mScale*mModel->h().pt() + ZOOM_TO_FIT_PAD );
|
||||
@@ -432,8 +433,8 @@ namespace glabels
|
||||
transform.translate( mX0.pt(), mY0.pt() );
|
||||
|
||||
QPointF pWorld = transform.inverted().map( event->pos() );
|
||||
Distance xWorld = Distance::pt( pWorld.x() );
|
||||
Distance yWorld = Distance::pt( pWorld.y() );
|
||||
model::Distance xWorld = model::Distance::pt( pWorld.x() );
|
||||
model::Distance yWorld = model::Distance::pt( pWorld.y() );
|
||||
|
||||
|
||||
if ( event->button() & Qt::LeftButton )
|
||||
@@ -446,8 +447,8 @@ namespace glabels
|
||||
|
||||
case IdleState:
|
||||
{
|
||||
LabelModelObject* object = nullptr;
|
||||
Handle* handle = nullptr;
|
||||
model::ModelObject* object = nullptr;
|
||||
model::Handle* handle = nullptr;
|
||||
if ( mModel->isSelectionAtomic() &&
|
||||
(handle = mModel->handleAt( mScale, xWorld, yWorld )) != nullptr )
|
||||
{
|
||||
@@ -521,22 +522,22 @@ namespace glabels
|
||||
switch ( mCreateObjectType )
|
||||
{
|
||||
case Box:
|
||||
mCreateObject = new LabelModelBoxObject();
|
||||
mCreateObject = new model::ModelBoxObject();
|
||||
break;
|
||||
case Ellipse:
|
||||
mCreateObject = new LabelModelEllipseObject();
|
||||
mCreateObject = new model::ModelEllipseObject();
|
||||
break;
|
||||
case Line:
|
||||
mCreateObject = new LabelModelLineObject();
|
||||
mCreateObject = new model::ModelLineObject();
|
||||
break;
|
||||
case Image:
|
||||
mCreateObject = new LabelModelImageObject();
|
||||
mCreateObject = new model::ModelImageObject();
|
||||
break;
|
||||
case Text:
|
||||
mCreateObject = new LabelModelTextObject();
|
||||
mCreateObject = new model::ModelTextObject();
|
||||
break;
|
||||
case Barcode:
|
||||
mCreateObject = new LabelModelBarcodeObject();
|
||||
mCreateObject = new model::ModelBarcodeObject();
|
||||
break;
|
||||
default:
|
||||
qDebug() << "LabelEditor::mousePressEvent: Invalid creation type. Should not happen!";
|
||||
@@ -598,8 +599,8 @@ namespace glabels
|
||||
transform.translate( mX0.pt(), mY0.pt() );
|
||||
|
||||
QPointF pWorld = transform.inverted().map( event->pos() );
|
||||
Distance xWorld = Distance::pt( pWorld.x() );
|
||||
Distance yWorld = Distance::pt( pWorld.y() );
|
||||
model::Distance xWorld = model::Distance::pt( pWorld.x() );
|
||||
model::Distance yWorld = model::Distance::pt( pWorld.y() );
|
||||
|
||||
|
||||
/*
|
||||
@@ -700,8 +701,8 @@ namespace glabels
|
||||
transform.translate( mX0.pt(), mY0.pt() );
|
||||
|
||||
QPointF pWorld = transform.inverted().map( event->pos() );
|
||||
Distance xWorld = Distance::pt( pWorld.x() );
|
||||
Distance yWorld = Distance::pt( pWorld.y() );
|
||||
model::Distance xWorld = model::Distance::pt( pWorld.x() );
|
||||
model::Distance yWorld = model::Distance::pt( pWorld.y() );
|
||||
|
||||
|
||||
if ( event->button() & Qt::LeftButton )
|
||||
@@ -779,11 +780,11 @@ namespace glabels
|
||||
/// Handle resize motion
|
||||
///
|
||||
void
|
||||
LabelEditor::handleResizeMotion( const Distance& xWorld,
|
||||
const Distance& yWorld )
|
||||
LabelEditor::handleResizeMotion( const model::Distance& xWorld,
|
||||
const model::Distance& yWorld )
|
||||
{
|
||||
QPointF p( xWorld.pt(), yWorld.pt() );
|
||||
Handle::Location location = mResizeHandle->location();
|
||||
model::Handle::Location location = mResizeHandle->location();
|
||||
|
||||
/*
|
||||
* Change point to object relative coordinates
|
||||
@@ -809,39 +810,39 @@ namespace glabels
|
||||
double w, h;
|
||||
switch ( location )
|
||||
{
|
||||
case Handle::NW:
|
||||
case model::Handle::NW:
|
||||
w = std::max( x2 - p.x(), 0.0 );
|
||||
h = std::max( y2 - p.y(), 0.0 );
|
||||
break;
|
||||
case Handle::N:
|
||||
case model::Handle::N:
|
||||
w = x2 - x1;
|
||||
h = std::max( y2 - p.y(), 0.0 );
|
||||
break;
|
||||
case Handle::NE:
|
||||
case model::Handle::NE:
|
||||
w = std::max( p.x() - x1, 0.0 );
|
||||
h = std::max( y2 - p.y(), 0.0 );
|
||||
break;
|
||||
case Handle::E:
|
||||
case model::Handle::E:
|
||||
w = std::max( p.x() - x1, 0.0 );
|
||||
h = y2 - y1;
|
||||
break;
|
||||
case Handle::SE:
|
||||
case model::Handle::SE:
|
||||
w = std::max( p.x() - x1, 0.0 );
|
||||
h = std::max( p.y() - y1, 0.0 );
|
||||
break;
|
||||
case Handle::S:
|
||||
case model::Handle::S:
|
||||
w = x2 - x1;
|
||||
h = std::max( p.y() - y1, 0.0 );
|
||||
break;
|
||||
case Handle::SW:
|
||||
case model::Handle::SW:
|
||||
w = std::max( x2 - p.x(), 0.0 );
|
||||
h = std::max( p.y() - y1, 0.0 );
|
||||
break;
|
||||
case Handle::W:
|
||||
case model::Handle::W:
|
||||
w = std::max( x2 - p.x(), 0.0 );
|
||||
h = y2 - y1;
|
||||
break;
|
||||
case Handle::P1:
|
||||
case model::Handle::P1:
|
||||
x1 = p.x();
|
||||
y1 = p.y();
|
||||
w = x2 - p.x();
|
||||
@@ -849,7 +850,7 @@ namespace glabels
|
||||
x0 = x0 + x1;
|
||||
y0 = y0 + y1;
|
||||
break;
|
||||
case Handle::P2:
|
||||
case model::Handle::P2:
|
||||
w = p.x() - x1;
|
||||
h = p.y() - y1;
|
||||
x0 = x0 + x1;
|
||||
@@ -862,30 +863,30 @@ namespace glabels
|
||||
/*
|
||||
* Set size
|
||||
*/
|
||||
if ( !(location == Handle::P1) && !(location == Handle::P2) )
|
||||
if ( !(location == model::Handle::P1) && !(location == model::Handle::P2) )
|
||||
{
|
||||
if ( mResizeHonorAspect )
|
||||
{
|
||||
switch ( location )
|
||||
{
|
||||
case Handle::E:
|
||||
case Handle::W:
|
||||
mResizeObject->setWHonorAspect( Distance::pt(w) );
|
||||
case model::Handle::E:
|
||||
case model::Handle::W:
|
||||
mResizeObject->setWHonorAspect( model::Distance::pt(w) );
|
||||
break;
|
||||
case Handle::N:
|
||||
case Handle::S:
|
||||
mResizeObject->setHHonorAspect( Distance::pt(h) );
|
||||
case model::Handle::N:
|
||||
case model::Handle::S:
|
||||
mResizeObject->setHHonorAspect( model::Distance::pt(h) );
|
||||
break;
|
||||
default:
|
||||
mResizeObject->setSizeHonorAspect( Distance::pt(w),
|
||||
Distance::pt(h) );
|
||||
mResizeObject->setSizeHonorAspect( model::Distance::pt(w),
|
||||
model::Distance::pt(h) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mResizeObject->setSize( Distance::pt(w),
|
||||
Distance::pt(h) );
|
||||
mResizeObject->setSize( model::Distance::pt(w),
|
||||
model::Distance::pt(h) );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -893,16 +894,16 @@ namespace glabels
|
||||
*/
|
||||
switch ( location )
|
||||
{
|
||||
case Handle::NW:
|
||||
case model::Handle::NW:
|
||||
x0 += x2 - mResizeObject->w().pt();
|
||||
y0 += y2 - mResizeObject->h().pt();
|
||||
break;
|
||||
case Handle::N:
|
||||
case Handle::NE:
|
||||
case model::Handle::N:
|
||||
case model::Handle::NE:
|
||||
y0 += y2 - mResizeObject->h().pt();
|
||||
break;
|
||||
case Handle::W:
|
||||
case Handle::SW:
|
||||
case model::Handle::W:
|
||||
case model::Handle::SW:
|
||||
x0 += x2 - mResizeObject->w().pt();
|
||||
break;
|
||||
default:
|
||||
@@ -911,8 +912,8 @@ namespace glabels
|
||||
}
|
||||
else
|
||||
{
|
||||
mResizeObject->setSize( Distance::pt(w),
|
||||
Distance::pt(h) );
|
||||
mResizeObject->setSize( model::Distance::pt(w),
|
||||
model::Distance::pt(h) );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -921,8 +922,8 @@ namespace glabels
|
||||
QPointF p0( x0, y0 );
|
||||
p0 = mResizeObject->matrix().map( p0 );
|
||||
p0 += QPointF( mResizeObject->x0().pt(), mResizeObject->y0().pt() );
|
||||
mResizeObject->setPosition( Distance::pt(p0.x()),
|
||||
Distance::pt(p0.y()) );
|
||||
mResizeObject->setPosition( model::Distance::pt(p0.x()),
|
||||
model::Distance::pt(p0.y()) );
|
||||
}
|
||||
|
||||
|
||||
@@ -938,22 +939,22 @@ namespace glabels
|
||||
|
||||
case Qt::Key_Left:
|
||||
mUndoRedoModel->checkpoint( tr("Move") );
|
||||
mModel->moveSelection( -mStepSize, Distance(0) );
|
||||
mModel->moveSelection( -mStepSize, model::Distance(0) );
|
||||
break;
|
||||
|
||||
case Qt::Key_Up:
|
||||
mUndoRedoModel->checkpoint( tr("Move") );
|
||||
mModel->moveSelection( Distance(0), -mStepSize );
|
||||
mModel->moveSelection( model::Distance(0), -mStepSize );
|
||||
break;
|
||||
|
||||
case Qt::Key_Right:
|
||||
mUndoRedoModel->checkpoint( tr("Move") );
|
||||
mModel->moveSelection( mStepSize, Distance(0) );
|
||||
mModel->moveSelection( mStepSize, model::Distance(0) );
|
||||
break;
|
||||
|
||||
case Qt::Key_Down:
|
||||
mUndoRedoModel->checkpoint( tr("Move") );
|
||||
mModel->moveSelection( Distance(0), mStepSize );
|
||||
mModel->moveSelection( model::Distance(0), mStepSize );
|
||||
break;
|
||||
|
||||
case Qt::Key_Delete:
|
||||
@@ -1063,11 +1064,11 @@ namespace glabels
|
||||
{
|
||||
if ( mGridVisible )
|
||||
{
|
||||
Distance w = mModel->frame()->w();
|
||||
Distance h = mModel->frame()->h();
|
||||
model::Distance w = mModel->frame()->w();
|
||||
model::Distance h = mModel->frame()->h();
|
||||
|
||||
Distance x0, y0;
|
||||
if ( dynamic_cast<const FrameRect*>( mModel->frame() ) )
|
||||
model::Distance x0, y0;
|
||||
if ( dynamic_cast<const model::FrameRect*>( mModel->frame() ) )
|
||||
{
|
||||
x0 = gridSpacing;
|
||||
y0 = gridSpacing;
|
||||
@@ -1092,12 +1093,12 @@ namespace glabels
|
||||
pen.setCosmetic( true );
|
||||
painter->setPen( pen );
|
||||
|
||||
for ( Distance x = x0; x < w; x += gridSpacing )
|
||||
for ( model::Distance x = x0; x < w; x += gridSpacing )
|
||||
{
|
||||
painter->drawLine( x.pt(), 0, x.pt(), h.pt() );
|
||||
}
|
||||
|
||||
for ( Distance y = y0; y < h; y += gridSpacing )
|
||||
for ( model::Distance y = y0; y < h; y += gridSpacing )
|
||||
{
|
||||
painter->drawLine( 0, y.pt(), w.pt(), y.pt() );
|
||||
}
|
||||
@@ -1129,7 +1130,7 @@ namespace glabels
|
||||
painter->translate( -mModel->frame()->w().pt(), 0 );
|
||||
}
|
||||
|
||||
foreach( Markup* markup, mModel->frame()->markups() )
|
||||
foreach( model::Markup* markup, mModel->frame()->markups() )
|
||||
{
|
||||
painter->drawPath( markup->path() );
|
||||
}
|
||||
@@ -1184,7 +1185,7 @@ namespace glabels
|
||||
{
|
||||
painter->save();
|
||||
|
||||
foreach ( LabelModelObject* object, mModel->objectList() )
|
||||
foreach ( model::ModelObject* object, mModel->objectList() )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
@@ -1224,9 +1225,9 @@ namespace glabels
|
||||
///
|
||||
void LabelEditor::onSettingsChanged()
|
||||
{
|
||||
Units units = Settings::units();
|
||||
model::Units units = model::Settings::units();
|
||||
|
||||
mStepSize = Distance( units.resolution(), units );
|
||||
mStepSize = model::Distance( units.resolution(), units );
|
||||
}
|
||||
|
||||
|
||||
@@ -1242,7 +1243,7 @@ namespace glabels
|
||||
|
||||
double x_scale = ( wPixels - ZOOM_TO_FIT_PAD ) / mModel->w().pt();
|
||||
double y_scale = ( hPixels - ZOOM_TO_FIT_PAD ) / mModel->h().pt();
|
||||
double newZoom = qMin( x_scale, y_scale ) * PTS_PER_INCH / physicalDpiX();
|
||||
double newZoom = qMin( x_scale, y_scale ) * model::PTS_PER_INCH / physicalDpiX();
|
||||
|
||||
// Limits
|
||||
newZoom = qMin( newZoom, zoomLevels[0] );
|
||||
@@ -1252,7 +1253,7 @@ namespace glabels
|
||||
}
|
||||
|
||||
/* Actual scale depends on DPI of display (assume DpiX == DpiY). */
|
||||
mScale = mZoom * physicalDpiX() / PTS_PER_INCH;
|
||||
mScale = mZoom * physicalDpiX() / model::PTS_PER_INCH;
|
||||
|
||||
setMinimumSize( mScale*mModel->w().pt() + ZOOM_TO_FIT_PAD,
|
||||
mScale*mModel->h().pt() + ZOOM_TO_FIT_PAD );
|
||||
|
||||
+20
-20
@@ -22,7 +22,10 @@
|
||||
#define LabelEditor_h
|
||||
|
||||
|
||||
#include "Region.h"
|
||||
#include "model/Handles.h"
|
||||
#include "model/Model.h"
|
||||
#include "model/ModelObject.h"
|
||||
#include "model/Region.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QScrollArea>
|
||||
@@ -33,10 +36,7 @@ namespace glabels
|
||||
{
|
||||
|
||||
// Forward References
|
||||
class LabelModel;
|
||||
class LabelModelObject;
|
||||
class UndoRedoModel;
|
||||
class Handle;
|
||||
|
||||
|
||||
///
|
||||
@@ -59,7 +59,7 @@ namespace glabels
|
||||
signals:
|
||||
void contextMenuActivate();
|
||||
void zoomChanged();
|
||||
void pointerMoved( const Distance& x, const Distance& y );
|
||||
void pointerMoved( const model::Distance& x, const model::Distance& y );
|
||||
void pointerExited();
|
||||
void modeChanged();
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace glabels
|
||||
// Model
|
||||
/////////////////////////////////////
|
||||
public:
|
||||
void setModel( LabelModel* model, UndoRedoModel* undoRedoModel );
|
||||
void setModel( model::Model* model, UndoRedoModel* undoRedoModel );
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
@@ -132,8 +132,8 @@ namespace glabels
|
||||
// Private methods
|
||||
/////////////////////////////////////
|
||||
private:
|
||||
void handleResizeMotion( const Distance& xWorld,
|
||||
const Distance& yWorld );
|
||||
void handleResizeMotion( const model::Distance& xWorld,
|
||||
const model::Distance& yWorld );
|
||||
|
||||
void drawBgLayer( QPainter* painter );
|
||||
void drawGridLayer( QPainter* painter );
|
||||
@@ -179,38 +179,38 @@ namespace glabels
|
||||
double mZoom;
|
||||
bool mZoomToFitFlag;
|
||||
double mScale;
|
||||
Distance mX0;
|
||||
Distance mY0;
|
||||
model::Distance mX0;
|
||||
model::Distance mY0;
|
||||
|
||||
bool mMarkupVisible;
|
||||
bool mGridVisible;
|
||||
|
||||
double mGridSpacing;
|
||||
Distance mStepSize;
|
||||
model::Distance mStepSize;
|
||||
|
||||
LabelModel* mModel;
|
||||
model::Model* mModel;
|
||||
UndoRedoModel* mUndoRedoModel;
|
||||
|
||||
State mState;
|
||||
|
||||
/* ArrowSelectRegion state */
|
||||
bool mSelectRegionVisible;
|
||||
Region mSelectRegion;
|
||||
model::Region mSelectRegion;
|
||||
|
||||
/* ArrowMove state */
|
||||
Distance mMoveLastX;
|
||||
Distance mMoveLastY;
|
||||
model::Distance mMoveLastX;
|
||||
model::Distance mMoveLastY;
|
||||
|
||||
/* ArrowResize state */
|
||||
LabelModelObject* mResizeObject;
|
||||
Handle* mResizeHandle;
|
||||
model::ModelObject* mResizeObject;
|
||||
model::Handle* mResizeHandle;
|
||||
bool mResizeHonorAspect;
|
||||
|
||||
/* CreateDrag state */
|
||||
CreateType mCreateObjectType;
|
||||
LabelModelObject* mCreateObject;
|
||||
Distance mCreateX0;
|
||||
Distance mCreateY0;
|
||||
model::ModelObject* mCreateObject;
|
||||
model::Distance mCreateX0;
|
||||
model::Distance mCreateY0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,239 +0,0 @@
|
||||
/* LabelModel.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LabelModel_h
|
||||
#define LabelModel_h
|
||||
|
||||
|
||||
#include "Settings.h"
|
||||
#include "Template.h"
|
||||
|
||||
#include "Merge/Merge.h"
|
||||
#include "Merge/Record.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
#include <QPainter>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
// Forward References
|
||||
class ColorNode;
|
||||
class Handle;
|
||||
class LabelModelObject;
|
||||
class Region;
|
||||
|
||||
///
|
||||
/// LabelModel
|
||||
///
|
||||
class LabelModel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Lifecycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
LabelModel();
|
||||
~LabelModel() override {}
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Save/restore model state
|
||||
/////////////////////////////////
|
||||
LabelModel* save() const;
|
||||
void restore( const LabelModel *savedModel );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Signals
|
||||
/////////////////////////////////
|
||||
signals:
|
||||
void changed();
|
||||
void nameChanged();
|
||||
void sizeChanged();
|
||||
void selectionChanged();
|
||||
void modifiedChanged();
|
||||
void mergeChanged();
|
||||
void mergeSourceChanged();
|
||||
void mergeSelectionChanged();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
bool isModified() const;
|
||||
void setModified();
|
||||
void clearModified();
|
||||
|
||||
QString shortName();
|
||||
const QString& fileName() const;
|
||||
void setFileName( const QString &fileName );
|
||||
|
||||
int compressionLevel() const;
|
||||
void setCompressionLevel( int compressionLevel );
|
||||
|
||||
const Template* tmplate() const;
|
||||
const Frame* frame() const;
|
||||
void setTmplate( const Template* tmplate );
|
||||
|
||||
bool rotate() const;
|
||||
void setRotate( bool rotate );
|
||||
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
|
||||
const QList<LabelModelObject*>& objectList() const;
|
||||
|
||||
merge::Merge* merge() const;
|
||||
void setMerge( merge::Merge* merge );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Manage objects
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void addObject( LabelModelObject* object );
|
||||
void deleteObject( LabelModelObject* object );
|
||||
|
||||
LabelModelObject* objectAt( double scale,
|
||||
const Distance& x,
|
||||
const Distance& y ) const;
|
||||
|
||||
Handle* handleAt( double scale,
|
||||
const Distance& x,
|
||||
const Distance& y ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Manipulate selection
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void selectObject( LabelModelObject* object );
|
||||
void unselectObject( LabelModelObject* object );
|
||||
void selectAll();
|
||||
void unselectAll();
|
||||
void selectRegion( const Region& region );
|
||||
bool isSelectionEmpty();
|
||||
bool isSelectionAtomic();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Get selected objects
|
||||
/////////////////////////////////
|
||||
public:
|
||||
QList<LabelModelObject*> getSelection();
|
||||
LabelModelObject* getFirstSelectedObject();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Query selection capabilities
|
||||
/////////////////////////////////
|
||||
public:
|
||||
bool canSelectionText();
|
||||
bool canSelectionFill();
|
||||
bool canSelectionLineColor();
|
||||
bool canSelectionLineWidth();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Operations on selections
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void deleteSelection();
|
||||
void raiseSelectionToTop();
|
||||
void lowerSelectionToBottom();
|
||||
void rotateSelection( double thetaDegs );
|
||||
void rotateSelectionLeft();
|
||||
void rotateSelectionRight();
|
||||
void flipSelectionHoriz();
|
||||
void flipSelectionVert();
|
||||
void alignSelectionLeft();
|
||||
void alignSelectionRight();
|
||||
void alignSelectionHCenter();
|
||||
void alignSelectionTop();
|
||||
void alignSelectionBottom();
|
||||
void alignSelectionVCenter();
|
||||
void centerSelectionHoriz();
|
||||
void centerSelectionVert();
|
||||
void moveSelection( const Distance& dx, const Distance& dy );
|
||||
void setSelectionFontFamily( const QString& fontFamily );
|
||||
void setSelectionFontSize( double fontSize );
|
||||
void setSelectionFontWeight( QFont::Weight fontWeight );
|
||||
void setSelectionFontItalicFlag( bool fontItalicFlag );
|
||||
void setSelectionTextHAlign( Qt::Alignment textHAlign );
|
||||
void setSelectionTextVAlign( Qt::Alignment textVAlign );
|
||||
void setSelectionTextLineSpacing( double textLineSpacing );
|
||||
void setSelectionTextColorNode( ColorNode textColorNode );
|
||||
void setSelectionLineWidth( const Distance& lineWidth );
|
||||
void setSelectionLineColorNode( ColorNode lineColorNode );
|
||||
void setSelectionFillColorNode( ColorNode fillColorNode );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Clipboard operations
|
||||
/////////////////////////////////
|
||||
void copySelection();
|
||||
void cutSelection();
|
||||
bool canPaste();
|
||||
void paste();
|
||||
|
||||
/////////////////////////////////
|
||||
// Drawing operations
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter, bool inEditor = true, merge::Record* record = nullptr ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Slots
|
||||
/////////////////////////////////
|
||||
private slots:
|
||||
void onObjectChanged();
|
||||
void onObjectMoved();
|
||||
void onMergeSourceChanged();
|
||||
void onMergeSelectionChanged();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
int mUntitledInstance;
|
||||
bool mModified;
|
||||
QString mFileName;
|
||||
int mCompressionLevel;
|
||||
const Template* mTmplate;
|
||||
const Frame* mFrame;
|
||||
bool mRotate;
|
||||
|
||||
QList<LabelModelObject*> mObjectList;
|
||||
|
||||
merge::Merge* mMerge;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // LabelModel_h
|
||||
@@ -1,530 +0,0 @@
|
||||
/* LabelModelBarcodeObject.cpp
|
||||
*
|
||||
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "LabelModelBarcodeObject.h"
|
||||
|
||||
#include "BarcodeBackends.h"
|
||||
#include "Size.h"
|
||||
|
||||
#include "glbarcode/Factory.h"
|
||||
#include "glbarcode/QtRenderer.h"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QPen>
|
||||
#include <QTextDocument>
|
||||
#include <QTextBlock>
|
||||
#include <QRegularExpression>
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const QColor fillColor = QColor( 224, 224, 224, 255 );
|
||||
const Distance pad = Distance::pt(4);
|
||||
const Distance minW = Distance::pt(18);
|
||||
const Distance minH = Distance::pt(18);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
LabelModelBarcodeObject::LabelModelBarcodeObject()
|
||||
{
|
||||
mOutline = new Outline( this );
|
||||
|
||||
mHandles << new HandleNorthWest( this );
|
||||
mHandles << new HandleNorth( this );
|
||||
mHandles << new HandleNorthEast( this );
|
||||
mHandles << new HandleEast( this );
|
||||
mHandles << new HandleSouthEast( this );
|
||||
mHandles << new HandleSouth( this );
|
||||
mHandles << new HandleSouthWest( this );
|
||||
mHandles << new HandleWest( this );
|
||||
|
||||
mBcStyle = BarcodeBackends::defaultStyle();
|
||||
mBcTextFlag = mBcStyle.canText();
|
||||
mBcChecksumFlag = mBcStyle.canChecksum();
|
||||
mBcFormatDigits = mBcStyle.preferedN();
|
||||
mBcData = "";
|
||||
mBcColorNode = ColorNode( Qt::black );
|
||||
|
||||
mEditorBarcode = nullptr;
|
||||
mEditorDefaultBarcode = nullptr;
|
||||
|
||||
update(); // Initialize cached editor layouts
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
LabelModelBarcodeObject::LabelModelBarcodeObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const BarcodeStyle& bcStyle,
|
||||
bool bcTextFlag,
|
||||
bool bcChecksumFlag,
|
||||
QString bcData,
|
||||
const ColorNode& bcColorNode,
|
||||
const QMatrix& matrix )
|
||||
: LabelModelObject( x0, y0, w, h, matrix )
|
||||
{
|
||||
mOutline = new Outline( this );
|
||||
|
||||
mHandles << new HandleNorthWest( this );
|
||||
mHandles << new HandleNorth( this );
|
||||
mHandles << new HandleNorthEast( this );
|
||||
mHandles << new HandleEast( this );
|
||||
mHandles << new HandleSouthEast( this );
|
||||
mHandles << new HandleSouth( this );
|
||||
mHandles << new HandleSouthWest( this );
|
||||
mHandles << new HandleWest( this );
|
||||
|
||||
mBcStyle = bcStyle;
|
||||
mBcTextFlag = bcTextFlag;
|
||||
mBcChecksumFlag = bcChecksumFlag;
|
||||
mBcData = bcData;
|
||||
mBcColorNode = bcColorNode;
|
||||
|
||||
mEditorBarcode = nullptr;
|
||||
mEditorDefaultBarcode = nullptr;
|
||||
|
||||
update(); // Initialize cached editor layouts
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Copy constructor
|
||||
///
|
||||
LabelModelBarcodeObject::LabelModelBarcodeObject( const LabelModelBarcodeObject* object )
|
||||
: LabelModelObject(object)
|
||||
{
|
||||
mBcStyle = object->mBcStyle;
|
||||
mBcTextFlag = object->mBcTextFlag;
|
||||
mBcChecksumFlag = object->mBcChecksumFlag;
|
||||
mBcFormatDigits = object->mBcFormatDigits;
|
||||
mBcData = object->mBcData;
|
||||
mBcColorNode = object->mBcColorNode;
|
||||
|
||||
mEditorBarcode = nullptr;
|
||||
mEditorDefaultBarcode = nullptr;
|
||||
|
||||
update(); // Initialize cached editor layouts
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
LabelModelBarcodeObject::~LabelModelBarcodeObject()
|
||||
{
|
||||
delete mOutline;
|
||||
|
||||
foreach( Handle* handle, mHandles )
|
||||
{
|
||||
delete handle;
|
||||
}
|
||||
mHandles.clear();
|
||||
|
||||
delete mEditorBarcode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
LabelModelBarcodeObject* LabelModelBarcodeObject::clone() const
|
||||
{
|
||||
return new LabelModelBarcodeObject( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcData Property Getter
|
||||
///
|
||||
QString LabelModelBarcodeObject::bcData() const
|
||||
{
|
||||
return mBcData.toString();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcData Property Setter
|
||||
///
|
||||
void LabelModelBarcodeObject::setBcData( const QString& value )
|
||||
{
|
||||
if ( mBcData.toString() != value )
|
||||
{
|
||||
mBcData = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcTextFlag Property Getter
|
||||
///
|
||||
bool LabelModelBarcodeObject::bcTextFlag() const
|
||||
{
|
||||
return mBcTextFlag;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcTextFlag Property Setter
|
||||
///
|
||||
void LabelModelBarcodeObject::setBcTextFlag( bool value )
|
||||
{
|
||||
if ( mBcTextFlag != value )
|
||||
{
|
||||
mBcTextFlag = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcChecksumFlag Property Getter
|
||||
///
|
||||
bool LabelModelBarcodeObject::bcChecksumFlag() const
|
||||
{
|
||||
return mBcChecksumFlag;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcChecksumFlag Property Setter
|
||||
///
|
||||
void LabelModelBarcodeObject::setBcChecksumFlag( bool value )
|
||||
{
|
||||
if ( mBcChecksumFlag != value )
|
||||
{
|
||||
mBcChecksumFlag = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Barcode Color Node Property Getter
|
||||
///
|
||||
ColorNode LabelModelBarcodeObject::bcColorNode() const
|
||||
{
|
||||
return mBcColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Barcode Color Node Property Setter
|
||||
///
|
||||
void LabelModelBarcodeObject::setBcColorNode( const ColorNode& value )
|
||||
{
|
||||
if ( mBcColorNode != value )
|
||||
{
|
||||
mBcColorNode = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Barcode Style Property Getter
|
||||
///
|
||||
BarcodeStyle LabelModelBarcodeObject::bcStyle() const
|
||||
{
|
||||
return mBcStyle;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Barcode Style Property Setter
|
||||
///
|
||||
void LabelModelBarcodeObject::setBcStyle( const BarcodeStyle& value )
|
||||
{
|
||||
if ( mBcStyle != value )
|
||||
{
|
||||
mBcStyle = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Barcode Format Digits Property Getter
|
||||
///
|
||||
int LabelModelBarcodeObject::bcFormatDigits() const
|
||||
{
|
||||
return mBcFormatDigits;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Barcode Format Digits Property Setter
|
||||
///
|
||||
void LabelModelBarcodeObject::setBcFormatDigits( int value )
|
||||
{
|
||||
if ( mBcFormatDigits != value )
|
||||
{
|
||||
mBcFormatDigits = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw shadow of object
|
||||
///
|
||||
void LabelModelBarcodeObject::drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
merge::Record* record ) const
|
||||
{
|
||||
// Barcodes don't support shadows.
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw object itself
|
||||
///
|
||||
void LabelModelBarcodeObject::drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
merge::Record* record ) const
|
||||
{
|
||||
QColor bcColor = mBcColorNode.color( record );
|
||||
|
||||
if ( inEditor )
|
||||
{
|
||||
drawBcInEditor( painter, bcColor );
|
||||
}
|
||||
else
|
||||
{
|
||||
drawBc( painter, bcColor, record );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Path to test for hover condition
|
||||
///
|
||||
QPainterPath LabelModelBarcodeObject::hoverPath( double scale ) const
|
||||
{
|
||||
return mHoverPath;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Size updated
|
||||
///
|
||||
void LabelModelBarcodeObject::sizeUpdated()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Update cached information for editor view
|
||||
///
|
||||
void LabelModelBarcodeObject::update()
|
||||
{
|
||||
//
|
||||
// Build barcode from data
|
||||
//
|
||||
if ( mEditorBarcode )
|
||||
{
|
||||
delete mEditorBarcode;
|
||||
}
|
||||
mEditorBarcode = glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() );
|
||||
if ( !mEditorBarcode )
|
||||
{
|
||||
qWarning() << "Invalid barcode style" << mBcStyle.fullId() << "using \"code39\".";
|
||||
mBcStyle = BarcodeBackends::defaultStyle();
|
||||
mEditorBarcode = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() );
|
||||
}
|
||||
mEditorBarcode->setChecksum(mBcChecksumFlag);
|
||||
mEditorBarcode->setShowText(mBcTextFlag);
|
||||
|
||||
mEditorBarcode->build( mBcData.toStdString(), mW.pt(), mH.pt() );
|
||||
|
||||
//
|
||||
// Build a place holder barcode to display in editor, if cannot display actual barcode
|
||||
//
|
||||
if ( mEditorDefaultBarcode )
|
||||
{
|
||||
delete mEditorDefaultBarcode;
|
||||
}
|
||||
mEditorDefaultBarcode = glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() );
|
||||
if ( !mEditorDefaultBarcode )
|
||||
{
|
||||
qWarning() << "Invalid barcode style" << mBcStyle.fullId() << "using \"code39\".";
|
||||
mBcStyle = BarcodeBackends::defaultStyle();
|
||||
mEditorDefaultBarcode = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() );
|
||||
}
|
||||
mEditorDefaultBarcode->setChecksum(mBcChecksumFlag);
|
||||
mEditorDefaultBarcode->setShowText(mBcTextFlag);
|
||||
|
||||
mEditorDefaultBarcode->build( mBcStyle.defaultDigits().toStdString(), mW.pt(), mH.pt() );
|
||||
|
||||
//
|
||||
// Adjust size
|
||||
//
|
||||
if ( mEditorBarcode->isDataValid() )
|
||||
{
|
||||
mW = Distance::pt( mEditorBarcode->width() );
|
||||
mH = Distance::pt( mEditorBarcode->height() );
|
||||
}
|
||||
else
|
||||
{
|
||||
mW = Distance::pt( mEditorDefaultBarcode->width() );
|
||||
mH = Distance::pt( mEditorDefaultBarcode->height() );
|
||||
}
|
||||
|
||||
QPainterPath path;
|
||||
path.addRect( 0, 0, mW.pt(), mH.pt() );
|
||||
mHoverPath = path;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw barcode in editor from cached information
|
||||
///
|
||||
void LabelModelBarcodeObject::drawBcInEditor( QPainter* painter, const QColor& color ) const
|
||||
{
|
||||
if ( mBcData.isEmpty() )
|
||||
{
|
||||
drawPlaceHolder( painter, color, tr("No barcode data") );
|
||||
}
|
||||
else if ( mBcData.hasPlaceHolders() )
|
||||
{
|
||||
drawPlaceHolder( painter, color, mBcData.toString() );
|
||||
}
|
||||
else if ( mEditorBarcode->isDataValid() )
|
||||
{
|
||||
painter->setPen( QPen( color ) );
|
||||
glbarcode::QtRenderer renderer(painter);
|
||||
mEditorBarcode->render( renderer );
|
||||
}
|
||||
else
|
||||
{
|
||||
drawPlaceHolder( painter, color, tr("Invalid barcode data") );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw barcode in final printout or preview
|
||||
///
|
||||
void
|
||||
LabelModelBarcodeObject::drawBc( QPainter* painter,
|
||||
const QColor& color,
|
||||
merge::Record* record ) const
|
||||
{
|
||||
painter->setPen( QPen( color ) );
|
||||
|
||||
glbarcode::Barcode* bc = glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() );
|
||||
bc->setChecksum(mBcChecksumFlag);
|
||||
bc->setShowText(mBcTextFlag);
|
||||
|
||||
bc->build( mBcData.toStdString(), mW.pt(), mH.pt() );
|
||||
|
||||
glbarcode::QtRenderer renderer(painter);
|
||||
bc->render( renderer );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw barcode place holder in editor
|
||||
///
|
||||
void
|
||||
LabelModelBarcodeObject::drawPlaceHolder( QPainter* painter,
|
||||
const QColor& color,
|
||||
const QString& text ) const
|
||||
{
|
||||
QString shortText = text.left( 32 ); // Don't let the text get out of hand
|
||||
|
||||
//
|
||||
// Render box
|
||||
//
|
||||
painter->setPen( Qt::NoPen );
|
||||
painter->setBrush( QBrush( fillColor ) );
|
||||
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
|
||||
//
|
||||
// Render default barcode
|
||||
//
|
||||
painter->setPen( QPen( color ) );
|
||||
glbarcode::QtRenderer renderer(painter);
|
||||
mEditorDefaultBarcode->render( renderer );
|
||||
|
||||
//
|
||||
// Determine font size for text
|
||||
//
|
||||
QFont font( "Sans" );
|
||||
font.setPointSizeF( 6 );
|
||||
|
||||
QFontMetricsF fm( font );
|
||||
QRectF textRect = fm.boundingRect( shortText );
|
||||
|
||||
double wPts = (mW - 2*pad).pt();
|
||||
double hPts = (mH - 2*pad).pt();
|
||||
if ( (wPts < textRect.width()) || (hPts < textRect.height()) )
|
||||
{
|
||||
double scaleX = wPts / textRect.width();
|
||||
double scaleY = hPts / textRect.height();
|
||||
font.setPointSizeF( 6 * std::min( scaleX, scaleY ) );
|
||||
}
|
||||
|
||||
//
|
||||
// Render hole for text (font size may have changed above)
|
||||
//
|
||||
fm = QFontMetricsF( font );
|
||||
textRect = fm.boundingRect( shortText );
|
||||
|
||||
QRectF holeRect( (mW.pt() - textRect.width())/2 - pad.pt(),
|
||||
(mH.pt() - textRect.height())/2 - pad.pt(),
|
||||
textRect.width() + 2*pad.pt(),
|
||||
textRect.height() + 2*pad.pt() );
|
||||
|
||||
painter->setPen( Qt::NoPen );
|
||||
painter->setBrush( QBrush( fillColor ) );
|
||||
painter->drawRect( holeRect );
|
||||
|
||||
//
|
||||
// Render text
|
||||
//
|
||||
painter->setFont( font );
|
||||
painter->setPen( QPen( color ) );
|
||||
painter->drawText( QRectF( 0, 0, mW.pt(), mH.pt() ), Qt::AlignCenter, shortText );
|
||||
}
|
||||
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,166 +0,0 @@
|
||||
/* LabelModelBarcodeObject.h
|
||||
*
|
||||
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LabelModelBarcodeObject_h
|
||||
#define LabelModelBarcodeObject_h
|
||||
|
||||
|
||||
#include "LabelModelObject.h"
|
||||
|
||||
#include "RawText.h"
|
||||
|
||||
#include "glbarcode/Barcode.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Line Object
|
||||
///
|
||||
class LabelModelBarcodeObject : public LabelModelObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
LabelModelBarcodeObject();
|
||||
|
||||
LabelModelBarcodeObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const BarcodeStyle& bcStyle,
|
||||
bool bcTextFlag,
|
||||
bool bcChecksumFlag,
|
||||
QString bcData,
|
||||
const ColorNode& bcColorNode,
|
||||
const QMatrix& matrix = QMatrix() );
|
||||
|
||||
LabelModelBarcodeObject( const LabelModelBarcodeObject* object );
|
||||
|
||||
~LabelModelBarcodeObject() override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
LabelModelBarcodeObject* clone() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Property Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Barcode Property: bcData
|
||||
//
|
||||
QString bcData() const override;
|
||||
void setBcData( const QString &value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Barcode Property: bcTextFlag
|
||||
//
|
||||
bool bcTextFlag() const override;
|
||||
void setBcTextFlag( bool value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Barcode Property: bcChecksumFlag
|
||||
//
|
||||
bool bcChecksumFlag() const override;
|
||||
void setBcChecksumFlag( bool value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Barcode Property: bcColorNode
|
||||
//
|
||||
ColorNode bcColorNode() const override;
|
||||
void setBcColorNode( const ColorNode &value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Barcode Property: bcStyle
|
||||
//
|
||||
BarcodeStyle bcStyle() const override;
|
||||
void setBcStyle( const BarcodeStyle &value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Barcode Property: bcFormatDigits
|
||||
//
|
||||
int bcFormatDigits() const override;
|
||||
void setBcFormatDigits( int value ) override;
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capability Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override;
|
||||
void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override;
|
||||
QPainterPath hoverPath( double scale ) const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
void sizeUpdated() override;
|
||||
void update();
|
||||
|
||||
void drawBcInEditor( QPainter* painter, const QColor& color ) const;
|
||||
void drawBc( QPainter* painter, const QColor& color, merge::Record* record ) const;
|
||||
void drawPlaceHolder( QPainter* painter, const QColor& color, const QString& text ) const;
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
BarcodeStyle mBcStyle;
|
||||
bool mBcTextFlag;
|
||||
bool mBcChecksumFlag;
|
||||
int mBcFormatDigits;
|
||||
RawText mBcData;
|
||||
ColorNode mBcColorNode;
|
||||
|
||||
glbarcode::Barcode* mEditorBarcode;
|
||||
glbarcode::Barcode* mEditorDefaultBarcode;
|
||||
|
||||
QPainterPath mHoverPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // LabelModelBarcodeObject_h
|
||||
@@ -1,194 +0,0 @@
|
||||
/* LabelModelBoxObject.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "LabelModelBoxObject.h"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QPen>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const double slopPixels = 2;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
LabelModelBoxObject::LabelModelBoxObject()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
LabelModelBoxObject::LabelModelBoxObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
const QMatrix& matrix,
|
||||
bool shadowState,
|
||||
const Distance& shadowX,
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: LabelModelShapeObject( x0, y0, w, h,
|
||||
lineWidth, lineColorNode, fillColorNode,
|
||||
matrix,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Copy constructor
|
||||
///
|
||||
LabelModelBoxObject::LabelModelBoxObject( const LabelModelBoxObject* object )
|
||||
: LabelModelShapeObject( object )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
LabelModelBoxObject::~LabelModelBoxObject()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
LabelModelBoxObject* LabelModelBoxObject::clone() const
|
||||
{
|
||||
return new LabelModelBoxObject( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw shadow of object
|
||||
///
|
||||
void LabelModelBoxObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const
|
||||
{
|
||||
QColor lineColor = mLineColorNode.color( record );
|
||||
QColor fillColor = mFillColorNode.color( record );
|
||||
QColor shadowColor = mShadowColorNode.color( record );
|
||||
|
||||
shadowColor.setAlphaF( mShadowOpacity );
|
||||
|
||||
if ( fillColor.alpha() )
|
||||
{
|
||||
painter->setPen( Qt::NoPen );
|
||||
painter->setBrush( shadowColor );
|
||||
|
||||
if ( lineColor.alpha() )
|
||||
{
|
||||
/* Has FILL and OUTLINE: adjust size to account for line width. */
|
||||
painter->drawRect( QRectF( -mLineWidth.pt()/2,
|
||||
-mLineWidth.pt()/2,
|
||||
(mW + mLineWidth).pt(),
|
||||
(mH + mLineWidth).pt() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Has FILL, but no OUTLINE. */
|
||||
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( lineColor.alpha() )
|
||||
{
|
||||
/* Has only OUTLINE. */
|
||||
painter->setPen( QPen( shadowColor, mLineWidth.pt() ) );
|
||||
painter->setBrush( Qt::NoBrush );
|
||||
|
||||
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw object itself
|
||||
///
|
||||
void LabelModelBoxObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const
|
||||
{
|
||||
QColor lineColor = mLineColorNode.color( record );
|
||||
QColor fillColor = mFillColorNode.color( record );
|
||||
|
||||
painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
|
||||
painter->setBrush( fillColor );
|
||||
|
||||
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Path to test for hover condition
|
||||
///
|
||||
QPainterPath LabelModelBoxObject::hoverPath( double scale ) const
|
||||
{
|
||||
double s = 1 / scale;
|
||||
|
||||
QPainterPath path;
|
||||
|
||||
if ( mFillColorNode.color().alpha() && mLineColorNode.color().alpha() )
|
||||
{
|
||||
path.addRect( -mLineWidth.pt()/2, -mLineWidth.pt()/2, (mW+mLineWidth).pt(), (mH+mLineWidth).pt() );
|
||||
}
|
||||
else if ( mFillColorNode.color().alpha() && !(mLineColorNode.color().alpha()) )
|
||||
{
|
||||
path.addRect( 0, 0, mW.pt(), mH.pt() );
|
||||
}
|
||||
else if ( mLineColorNode.color().alpha() )
|
||||
{
|
||||
path.addRect( (-mLineWidth.pt()/2) - s*slopPixels,
|
||||
(-mLineWidth.pt()/2) - s*slopPixels,
|
||||
(mW + mLineWidth).pt() + s*2*slopPixels,
|
||||
(mH + mLineWidth).pt() + s*2*slopPixels );
|
||||
path.closeSubpath();
|
||||
path.addRect( mLineWidth.pt()/2 + s*slopPixels,
|
||||
mLineWidth.pt()/2 + s*slopPixels,
|
||||
(mW - mLineWidth).pt() - s*2*slopPixels,
|
||||
(mH - mLineWidth).pt() - s*2*slopPixels );
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,82 +0,0 @@
|
||||
/* LabelModelBoxObject.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LabelModelBoxObject_h
|
||||
#define LabelModelBoxObject_h
|
||||
|
||||
|
||||
#include "LabelModelShapeObject.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Box Object
|
||||
///
|
||||
class LabelModelBoxObject : public LabelModelShapeObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
LabelModelBoxObject();
|
||||
|
||||
LabelModelBoxObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
const QMatrix& matrix = QMatrix(),
|
||||
bool shadowState = false,
|
||||
const Distance& shadowX = 0,
|
||||
const Distance& shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
LabelModelBoxObject( const LabelModelBoxObject* object );
|
||||
|
||||
~LabelModelBoxObject() override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
LabelModelBoxObject* clone() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override;
|
||||
void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override;
|
||||
QPainterPath hoverPath( double scale ) const override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // LabelModelBoxObject_h
|
||||
@@ -1,194 +0,0 @@
|
||||
/* LabelModelEllipseObject.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "LabelModelEllipseObject.h"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QPen>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const double slopPixels = 2;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
LabelModelEllipseObject::LabelModelEllipseObject()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
LabelModelEllipseObject::LabelModelEllipseObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
const QMatrix& matrix,
|
||||
bool shadowState,
|
||||
const Distance& shadowX,
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: LabelModelShapeObject( x0, y0, w, h,
|
||||
lineWidth, lineColorNode, fillColorNode,
|
||||
matrix,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Copy constructor
|
||||
///
|
||||
LabelModelEllipseObject::LabelModelEllipseObject( const LabelModelEllipseObject* object )
|
||||
: LabelModelShapeObject( object )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
LabelModelEllipseObject::~LabelModelEllipseObject()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
LabelModelEllipseObject* LabelModelEllipseObject::clone() const
|
||||
{
|
||||
return new LabelModelEllipseObject( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw shadow of object
|
||||
///
|
||||
void LabelModelEllipseObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const
|
||||
{
|
||||
QColor lineColor = mLineColorNode.color( record );
|
||||
QColor fillColor = mFillColorNode.color( record );
|
||||
QColor shadowColor = mShadowColorNode.color( record );
|
||||
|
||||
shadowColor.setAlphaF( mShadowOpacity );
|
||||
|
||||
if ( fillColor.alpha() )
|
||||
{
|
||||
painter->setPen( Qt::NoPen );
|
||||
painter->setBrush( shadowColor );
|
||||
|
||||
if ( lineColor.alpha() )
|
||||
{
|
||||
/* Has FILL and OUTLINE: adjust size to account for line width. */
|
||||
painter->drawEllipse( QRectF( -mLineWidth.pt()/2,
|
||||
-mLineWidth.pt()/2,
|
||||
(mW + mLineWidth).pt(),
|
||||
(mH + mLineWidth).pt() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Has FILL, but no OUTLINE. */
|
||||
painter->drawEllipse( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( lineColor.alpha() )
|
||||
{
|
||||
/* Has only OUTLINE. */
|
||||
painter->setPen( QPen( shadowColor, mLineWidth.pt() ) );
|
||||
painter->setBrush( Qt::NoBrush );
|
||||
|
||||
painter->drawEllipse( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw object itself
|
||||
///
|
||||
void LabelModelEllipseObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const
|
||||
{
|
||||
QColor lineColor = mLineColorNode.color( record );
|
||||
QColor fillColor = mFillColorNode.color( record );
|
||||
|
||||
painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
|
||||
painter->setBrush( fillColor );
|
||||
|
||||
painter->drawEllipse( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Path to test for hover condition
|
||||
///
|
||||
QPainterPath LabelModelEllipseObject::hoverPath( double scale ) const
|
||||
{
|
||||
double s = 1 / scale;
|
||||
|
||||
QPainterPath path;
|
||||
|
||||
if ( mFillColorNode.color().alpha() && mLineColorNode.color().alpha() )
|
||||
{
|
||||
path.addEllipse( -mLineWidth.pt()/2, -mLineWidth.pt()/2, (mW+mLineWidth).pt(), (mH+mLineWidth).pt() );
|
||||
}
|
||||
else if ( mFillColorNode.color().alpha() && !(mLineColorNode.color().alpha()) )
|
||||
{
|
||||
path.addEllipse( 0, 0, mW.pt(), mH.pt() );
|
||||
}
|
||||
else if ( mLineColorNode.color().alpha() )
|
||||
{
|
||||
path.addEllipse( (-mLineWidth.pt()/2) - s*slopPixels,
|
||||
(-mLineWidth.pt()/2) - s*slopPixels,
|
||||
(mW + mLineWidth).pt() + s*2*slopPixels,
|
||||
(mH + mLineWidth).pt() + s*2*slopPixels );
|
||||
path.closeSubpath();
|
||||
path.addEllipse( mLineWidth.pt()/2 + s*slopPixels,
|
||||
mLineWidth.pt()/2 + s*slopPixels,
|
||||
(mW - mLineWidth).pt() - s*2*slopPixels,
|
||||
(mH - mLineWidth).pt() - s*2*slopPixels );
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,82 +0,0 @@
|
||||
/* LabelModelEllipseObject.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LabelModelEllipseObject_h
|
||||
#define LabelModelEllipseObject_h
|
||||
|
||||
|
||||
#include "LabelModelShapeObject.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Ellipse Object
|
||||
///
|
||||
class LabelModelEllipseObject : public LabelModelShapeObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
LabelModelEllipseObject();
|
||||
|
||||
LabelModelEllipseObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
const QMatrix& matrix = QMatrix(),
|
||||
bool shadowState = false,
|
||||
const Distance& shadowX = 0,
|
||||
const Distance& shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
LabelModelEllipseObject( const LabelModelEllipseObject* object );
|
||||
|
||||
~LabelModelEllipseObject() override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
LabelModelEllipseObject* clone() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override;
|
||||
void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override;
|
||||
QPainterPath hoverPath( double scale ) const override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // LabelModelEllipseObject_h
|
||||
@@ -1,566 +0,0 @@
|
||||
/* LabelModelImageObject.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "LabelModelImageObject.h"
|
||||
|
||||
#include "Size.h"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QFileInfo>
|
||||
#include <QImage>
|
||||
#include <QPen>
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Static data
|
||||
///
|
||||
QImage* LabelModelImageObject::smDefaultImage = nullptr;
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
LabelModelImageObject::LabelModelImageObject() : mImage(nullptr), mSvgRenderer(nullptr)
|
||||
{
|
||||
mOutline = new Outline( this );
|
||||
|
||||
mHandles << new HandleNorthWest( this );
|
||||
mHandles << new HandleNorth( this );
|
||||
mHandles << new HandleNorthEast( this );
|
||||
mHandles << new HandleEast( this );
|
||||
mHandles << new HandleSouthEast( this );
|
||||
mHandles << new HandleSouth( this );
|
||||
mHandles << new HandleSouthWest( this );
|
||||
mHandles << new HandleWest( this );
|
||||
|
||||
if ( smDefaultImage == nullptr )
|
||||
{
|
||||
smDefaultImage = new QImage( ":images/checkerboard.png" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
LabelModelImageObject::LabelModelImageObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const TextNode& filenameNode,
|
||||
const QMatrix& matrix,
|
||||
bool shadowState,
|
||||
const Distance& shadowX,
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: LabelModelObject( x0, y0, w, h,
|
||||
matrix,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
|
||||
{
|
||||
mOutline = new Outline( this );
|
||||
|
||||
mHandles << new HandleNorthWest( this );
|
||||
mHandles << new HandleNorth( this );
|
||||
mHandles << new HandleNorthEast( this );
|
||||
mHandles << new HandleEast( this );
|
||||
mHandles << new HandleSouthEast( this );
|
||||
mHandles << new HandleSouth( this );
|
||||
mHandles << new HandleSouthWest( this );
|
||||
mHandles << new HandleWest( this );
|
||||
|
||||
if ( smDefaultImage == nullptr )
|
||||
{
|
||||
smDefaultImage = new QImage( ":images/checkerboard.png" );
|
||||
}
|
||||
|
||||
mFilenameNode = filenameNode;
|
||||
|
||||
mImage = nullptr;
|
||||
mSvgRenderer = nullptr;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
LabelModelImageObject::LabelModelImageObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const QString& filename,
|
||||
const QImage& image,
|
||||
const QMatrix& matrix,
|
||||
bool shadowState,
|
||||
const Distance& shadowX,
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: LabelModelObject( x0, y0, w, h,
|
||||
matrix,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
|
||||
{
|
||||
mOutline = new Outline( this );
|
||||
|
||||
mHandles << new HandleNorthWest( this );
|
||||
mHandles << new HandleNorth( this );
|
||||
mHandles << new HandleNorthEast( this );
|
||||
mHandles << new HandleEast( this );
|
||||
mHandles << new HandleSouthEast( this );
|
||||
mHandles << new HandleSouth( this );
|
||||
mHandles << new HandleSouthWest( this );
|
||||
mHandles << new HandleWest( this );
|
||||
|
||||
if ( smDefaultImage == nullptr )
|
||||
{
|
||||
smDefaultImage = new QImage( ":images/checkerboard.png" );
|
||||
}
|
||||
|
||||
mImage = new QImage(image);
|
||||
mFilenameNode = TextNode( false, filename );
|
||||
mSvgRenderer = nullptr;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
LabelModelImageObject::LabelModelImageObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const QString& filename,
|
||||
const QByteArray& svg,
|
||||
const QMatrix& matrix,
|
||||
bool shadowState,
|
||||
const Distance& shadowX,
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: LabelModelObject( x0, y0, w, h,
|
||||
matrix,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
|
||||
{
|
||||
mOutline = new Outline( this );
|
||||
|
||||
mHandles << new HandleNorthWest( this );
|
||||
mHandles << new HandleNorth( this );
|
||||
mHandles << new HandleNorthEast( this );
|
||||
mHandles << new HandleEast( this );
|
||||
mHandles << new HandleSouthEast( this );
|
||||
mHandles << new HandleSouth( this );
|
||||
mHandles << new HandleSouthWest( this );
|
||||
mHandles << new HandleWest( this );
|
||||
|
||||
if ( smDefaultImage == nullptr )
|
||||
{
|
||||
smDefaultImage = new QImage( ":images/checkerboard.png" );
|
||||
}
|
||||
|
||||
mSvg = svg;
|
||||
mSvgRenderer = new QSvgRenderer( mSvg );
|
||||
mFilenameNode = TextNode( false, filename );
|
||||
mImage = nullptr;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Copy constructor
|
||||
///
|
||||
LabelModelImageObject::LabelModelImageObject( const LabelModelImageObject* object ) : LabelModelObject(object)
|
||||
{
|
||||
mFilenameNode = object->mFilenameNode;
|
||||
if ( object->mImage )
|
||||
{
|
||||
mImage = new QImage( *object->mImage );
|
||||
}
|
||||
else
|
||||
{
|
||||
mImage = nullptr;
|
||||
}
|
||||
if ( object->mSvgRenderer )
|
||||
{
|
||||
mSvgRenderer = new QSvgRenderer( object->mSvg );
|
||||
}
|
||||
else
|
||||
{
|
||||
mSvgRenderer = nullptr;
|
||||
}
|
||||
mSvg = object->mSvg;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
LabelModelImageObject::~LabelModelImageObject()
|
||||
{
|
||||
delete mOutline;
|
||||
|
||||
foreach( Handle* handle, mHandles )
|
||||
{
|
||||
delete handle;
|
||||
}
|
||||
mHandles.clear();
|
||||
|
||||
if ( mImage )
|
||||
{
|
||||
delete mImage;
|
||||
}
|
||||
if ( mSvgRenderer )
|
||||
{
|
||||
delete mSvgRenderer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
LabelModelImageObject* LabelModelImageObject::clone() const
|
||||
{
|
||||
return new LabelModelImageObject( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Image filenameNode Property Getter
|
||||
///
|
||||
TextNode LabelModelImageObject::filenameNode() const
|
||||
{
|
||||
return mFilenameNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Image filenameNode Property Setter
|
||||
///
|
||||
void LabelModelImageObject::setFilenameNode( const TextNode& value )
|
||||
{
|
||||
if ( mFilenameNode != value )
|
||||
{
|
||||
mFilenameNode = value;
|
||||
loadImage();
|
||||
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Image image Property Getter
|
||||
///
|
||||
const QImage* LabelModelImageObject::image() const
|
||||
{
|
||||
return mImage;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Image Property Setter
|
||||
///
|
||||
void LabelModelImageObject::setImage( const QImage& value )
|
||||
{
|
||||
if ( !value.isNull() )
|
||||
{
|
||||
if ( mImage )
|
||||
{
|
||||
delete mImage;
|
||||
mImage = nullptr;
|
||||
}
|
||||
if ( mSvgRenderer )
|
||||
{
|
||||
delete mSvgRenderer;
|
||||
mSvgRenderer = nullptr;
|
||||
}
|
||||
|
||||
mImage = new QImage(value);
|
||||
quint16 cs = qChecksum( (const char*)mImage->constBits(), mImage->byteCount() );
|
||||
mFilenameNode = TextNode( false, QString("%image_%1%").arg( cs ) );
|
||||
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Image Property Setter
|
||||
///
|
||||
void LabelModelImageObject::setImage( const QString& name, const QImage& value )
|
||||
{
|
||||
if ( !value.isNull() )
|
||||
{
|
||||
if ( mImage )
|
||||
{
|
||||
delete mImage;
|
||||
mImage = nullptr;
|
||||
}
|
||||
if ( mSvgRenderer )
|
||||
{
|
||||
delete mSvgRenderer;
|
||||
mSvgRenderer = nullptr;
|
||||
}
|
||||
|
||||
mImage = new QImage(value);
|
||||
mFilenameNode = TextNode( false, name );
|
||||
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Image svg Property Getter
|
||||
///
|
||||
QByteArray LabelModelImageObject::svg() const
|
||||
{
|
||||
return mSvg;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Image svgSource Property Setter
|
||||
///
|
||||
void LabelModelImageObject::setSvg( const QString& name, const QByteArray& value )
|
||||
{
|
||||
if ( !value.isEmpty() )
|
||||
{
|
||||
if ( mImage )
|
||||
{
|
||||
delete mImage;
|
||||
mImage = nullptr;
|
||||
}
|
||||
if ( mSvgRenderer )
|
||||
{
|
||||
delete mSvgRenderer;
|
||||
mSvgRenderer = nullptr;
|
||||
}
|
||||
|
||||
mSvg = value;
|
||||
mSvgRenderer = new QSvgRenderer( mSvg );
|
||||
mFilenameNode = TextNode( false, name );
|
||||
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// naturalSize Property Getter (assumes 72 DPI, i.e. 1pixel == 1pt)
|
||||
///
|
||||
Size LabelModelImageObject::naturalSize() const
|
||||
{
|
||||
Size size( Distance::pt(72), Distance::pt(72) );
|
||||
|
||||
if ( mImage )
|
||||
{
|
||||
QSize qsize = mImage->size();
|
||||
size.setW( Distance::pt( qsize.width() ) );
|
||||
size.setH( Distance::pt( qsize.height() ) );
|
||||
}
|
||||
else if ( mSvgRenderer )
|
||||
{
|
||||
QSize qsize = mSvgRenderer->defaultSize();
|
||||
size.setW( Distance::pt( qsize.width() ) );
|
||||
size.setH( Distance::pt( qsize.height() ) );
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw shadow of object
|
||||
///
|
||||
void LabelModelImageObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const
|
||||
{
|
||||
QRectF destRect( 0, 0, mW.pt(), mH.pt() );
|
||||
|
||||
QColor shadowColor = mShadowColorNode.color( record );
|
||||
shadowColor.setAlphaF( mShadowOpacity );
|
||||
|
||||
if ( mImage && mImage->hasAlphaChannel() && (mImage->depth() == 32) )
|
||||
{
|
||||
QImage* shadowImage = createShadowImage( shadowColor );
|
||||
painter->drawImage( destRect, *shadowImage );
|
||||
delete shadowImage;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( mImage || inEditor )
|
||||
{
|
||||
painter->setBrush( shadowColor );
|
||||
painter->setPen( QPen( Qt::NoPen ) );
|
||||
|
||||
painter->drawRect( destRect );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw object itself
|
||||
///
|
||||
void LabelModelImageObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const
|
||||
{
|
||||
QRectF destRect( 0, 0, mW.pt(), mH.pt() );
|
||||
|
||||
if ( inEditor && (mFilenameNode.isField() || (!mImage && !mSvgRenderer) ) )
|
||||
{
|
||||
painter->save();
|
||||
painter->setRenderHint( QPainter::SmoothPixmapTransform, false );
|
||||
painter->drawImage( destRect, *smDefaultImage );
|
||||
painter->restore();
|
||||
}
|
||||
else if ( mImage )
|
||||
{
|
||||
painter->drawImage( destRect, *mImage );
|
||||
}
|
||||
else if ( mSvgRenderer )
|
||||
{
|
||||
mSvgRenderer->render( painter, destRect );
|
||||
}
|
||||
else if ( mFilenameNode.isField() )
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Path to test for hover condition
|
||||
///
|
||||
QPainterPath LabelModelImageObject::hoverPath( double scale ) const
|
||||
{
|
||||
QPainterPath path;
|
||||
path.addRect( 0, 0, mW.pt(), mH.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Load image
|
||||
///
|
||||
void LabelModelImageObject::loadImage()
|
||||
{
|
||||
if ( mImage )
|
||||
{
|
||||
delete mImage;
|
||||
mImage = nullptr;
|
||||
}
|
||||
if ( mSvgRenderer )
|
||||
{
|
||||
delete mSvgRenderer;
|
||||
mSvgRenderer = nullptr;
|
||||
}
|
||||
|
||||
if ( !mFilenameNode.isField() )
|
||||
{
|
||||
QString filename = mFilenameNode.data();
|
||||
QFileInfo fileInfo( filename );
|
||||
|
||||
if ( fileInfo.isReadable() )
|
||||
{
|
||||
if ( (fileInfo.suffix() == "svg") || (fileInfo.suffix() == "SVG") )
|
||||
{
|
||||
QFile file( filename );
|
||||
if ( file.open( QFile::ReadOnly ) )
|
||||
{
|
||||
mSvg = file.readAll();
|
||||
file.close();
|
||||
mSvgRenderer = new QSvgRenderer( mSvg );
|
||||
if ( !mSvgRenderer->isValid() )
|
||||
{
|
||||
mSvgRenderer = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Adjust size based on aspect ratio of SVG image
|
||||
QRectF rect = mSvgRenderer->viewBoxF();
|
||||
double aspectRatio = rect.height() / rect.width();
|
||||
if ( mH > mW*aspectRatio )
|
||||
{
|
||||
mH = mW*aspectRatio;
|
||||
}
|
||||
else
|
||||
{
|
||||
mW = mH/aspectRatio;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mImage = new QImage( filename );
|
||||
if ( mImage->isNull() )
|
||||
{
|
||||
mImage = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Adjust size based on aspect ratio of image
|
||||
double imageW = mImage->width();
|
||||
double imageH = mImage->height();
|
||||
double aspectRatio = imageH / imageW;
|
||||
if ( mH > mW*aspectRatio )
|
||||
{
|
||||
mH = mW*aspectRatio;
|
||||
}
|
||||
else
|
||||
{
|
||||
mW = mH/aspectRatio;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Create shadow image
|
||||
///
|
||||
QImage* LabelModelImageObject::createShadowImage( const QColor& color ) const
|
||||
{
|
||||
int r = color.red();
|
||||
int g = color.green();
|
||||
int b = color.blue();
|
||||
int a = color.alpha();
|
||||
|
||||
QImage* shadow = new QImage( *mImage );
|
||||
for ( int iy = 0; iy < shadow->height(); iy++ )
|
||||
{
|
||||
QRgb* scanLine = (QRgb*)shadow->scanLine( iy );
|
||||
|
||||
for ( int ix = 0; ix < shadow->width(); ix++ )
|
||||
{
|
||||
scanLine[ix] = qRgba( r, g, b, (a*qAlpha(scanLine[ix]))/255 );
|
||||
}
|
||||
}
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,161 +0,0 @@
|
||||
/* LabelModelImageObject.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LabelModelImageObject_h
|
||||
#define LabelModelImageObject_h
|
||||
|
||||
|
||||
#include "LabelModelObject.h"
|
||||
|
||||
#include <QSvgRenderer>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Image Object
|
||||
///
|
||||
class LabelModelImageObject : public LabelModelObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
LabelModelImageObject();
|
||||
|
||||
LabelModelImageObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const TextNode& filenameNode,
|
||||
const QMatrix& matrix = QMatrix(),
|
||||
bool shadowState = false,
|
||||
const Distance& shadowX = 0,
|
||||
const Distance& shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
LabelModelImageObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const QString& filename,
|
||||
const QImage& image,
|
||||
const QMatrix& matrix = QMatrix(),
|
||||
bool shadowState = false,
|
||||
const Distance& shadowX = 0,
|
||||
const Distance& shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
LabelModelImageObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const QString& filename,
|
||||
const QByteArray& svg,
|
||||
const QMatrix& matrix = QMatrix(),
|
||||
bool shadowState = false,
|
||||
const Distance& shadowX = 0,
|
||||
const Distance& shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
LabelModelImageObject( const LabelModelImageObject* object );
|
||||
|
||||
~LabelModelImageObject() override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
LabelModelImageObject* clone() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Property Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Image Property: filenameNode
|
||||
//
|
||||
TextNode filenameNode() const override;
|
||||
void setFilenameNode( const TextNode& value ) override;
|
||||
|
||||
//
|
||||
// Image Property: image
|
||||
//
|
||||
const QImage* image() const override;
|
||||
void setImage( const QImage& value ) override;
|
||||
void setImage( const QString& name, const QImage& value ) override;
|
||||
|
||||
//
|
||||
// Image Property: svg
|
||||
//
|
||||
QByteArray svg() const override;
|
||||
void setSvg( const QString& name, const QByteArray& value ) override;
|
||||
|
||||
//
|
||||
// Property: naturalSize
|
||||
//
|
||||
Size naturalSize() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capability Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override;
|
||||
void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override;
|
||||
QPainterPath hoverPath( double scale ) const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private
|
||||
///////////////////////////////////////////////////////////////
|
||||
void loadImage();
|
||||
QImage* createShadowImage( const QColor& color ) const;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
TextNode mFilenameNode;
|
||||
QImage* mImage;
|
||||
QSvgRenderer* mSvgRenderer;
|
||||
QByteArray mSvg;
|
||||
|
||||
static QImage* smDefaultImage;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // LabelModelImageObject_h
|
||||
@@ -1,243 +0,0 @@
|
||||
/* LabelModelLineObject.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "LabelModelLineObject.h"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QPen>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const double slopPixels = 2;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
LabelModelLineObject::LabelModelLineObject()
|
||||
{
|
||||
mOutline = nullptr;
|
||||
|
||||
mHandles << new HandleP1( this );
|
||||
mHandles << new HandleP2( this );
|
||||
|
||||
mLineWidth = 1.0;
|
||||
mLineColorNode = ColorNode( QColor( 0, 0, 0 ) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
LabelModelLineObject::LabelModelLineObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& dx,
|
||||
const Distance& dy,
|
||||
const Distance& lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const QMatrix& matrix,
|
||||
bool shadowState,
|
||||
const Distance& shadowX,
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: LabelModelObject( x0, y0, dx, dy,
|
||||
matrix,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
|
||||
{
|
||||
mOutline = new Outline( this );
|
||||
|
||||
mHandles << new HandleNorthWest( this );
|
||||
mHandles << new HandleNorth( this );
|
||||
mHandles << new HandleNorthEast( this );
|
||||
mHandles << new HandleEast( this );
|
||||
mHandles << new HandleSouthEast( this );
|
||||
mHandles << new HandleSouth( this );
|
||||
mHandles << new HandleSouthWest( this );
|
||||
mHandles << new HandleWest( this );
|
||||
|
||||
mLineWidth = lineWidth;
|
||||
mLineColorNode = lineColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Copy constructor
|
||||
///
|
||||
LabelModelLineObject::LabelModelLineObject( const LabelModelLineObject* object )
|
||||
: LabelModelObject(object)
|
||||
{
|
||||
mLineWidth = object->mLineWidth;
|
||||
mLineColorNode = object->mLineColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
LabelModelLineObject::~LabelModelLineObject()
|
||||
{
|
||||
foreach( Handle* handle, mHandles )
|
||||
{
|
||||
delete handle;
|
||||
}
|
||||
mHandles.clear();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
LabelModelLineObject* LabelModelLineObject::clone() const
|
||||
{
|
||||
return new LabelModelLineObject( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Width Property Getter
|
||||
///
|
||||
Distance LabelModelLineObject::lineWidth() const
|
||||
{
|
||||
return mLineWidth;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Width Property Setter
|
||||
///
|
||||
void LabelModelLineObject::setLineWidth( const Distance& value )
|
||||
{
|
||||
if ( mLineWidth != value )
|
||||
{
|
||||
mLineWidth = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Color Node Property Getter
|
||||
///
|
||||
ColorNode LabelModelLineObject::lineColorNode() const
|
||||
{
|
||||
return mLineColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Color Node Property Setter
|
||||
///
|
||||
void LabelModelLineObject::setLineColorNode( const ColorNode& value )
|
||||
{
|
||||
if ( mLineColorNode != value )
|
||||
{
|
||||
mLineColorNode = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Line Color Capability Implementation
|
||||
///
|
||||
bool LabelModelLineObject::canLineColor()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Line Width Capability Implementation
|
||||
///
|
||||
bool LabelModelLineObject::canLineWidth()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw shadow of object
|
||||
///
|
||||
void LabelModelLineObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const
|
||||
{
|
||||
QColor lineColor = mLineColorNode.color( record );
|
||||
QColor shadowColor = mShadowColorNode.color( record );
|
||||
|
||||
shadowColor.setAlphaF( mShadowOpacity );
|
||||
|
||||
if ( lineColor.alpha() )
|
||||
{
|
||||
painter->setPen( QPen( shadowColor, mLineWidth.pt() ) );
|
||||
painter->drawLine( 0, 0, mW.pt(), mH.pt() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw object itself
|
||||
///
|
||||
void LabelModelLineObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const
|
||||
{
|
||||
QColor lineColor = mLineColorNode.color( record );
|
||||
|
||||
painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
|
||||
painter->drawLine( 0, 0, mW.pt(), mH.pt() );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Path to test for hover condition
|
||||
///
|
||||
QPainterPath LabelModelLineObject::hoverPath( double scale ) const
|
||||
{
|
||||
QPainterPath path;
|
||||
|
||||
if ( mLineColorNode.color().alpha() )
|
||||
{
|
||||
//
|
||||
// Build a thin rectangle representing line
|
||||
//
|
||||
double rPts = mLineWidth.pt()/2 + slopPixels / scale;
|
||||
|
||||
double lengthPts = sqrt( mW.pt()*mW.pt() + mH.pt()*mH.pt() );
|
||||
double dx = mH.pt() / lengthPts; // horizontal pitch of perpendicular line
|
||||
double dy = mW.pt() / lengthPts; // vertical pitch of perpendicular line
|
||||
|
||||
path.moveTo( rPts*dx, - rPts*dy );
|
||||
path.lineTo( mW.pt() + rPts*dx, mH.pt() - rPts*dy );
|
||||
path.lineTo( mW.pt() - rPts*dx, mH.pt() + rPts*dy );
|
||||
path.lineTo( - rPts*dx, rPts*dy );
|
||||
|
||||
path.closeSubpath();
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,115 +0,0 @@
|
||||
/* LabelModelLineObject.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LabelModelLineObject_h
|
||||
#define LabelModelLineObject_h
|
||||
|
||||
|
||||
#include "LabelModelObject.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Line Object
|
||||
///
|
||||
class LabelModelLineObject : public LabelModelObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
LabelModelLineObject();
|
||||
|
||||
LabelModelLineObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const QMatrix& matrix = QMatrix(),
|
||||
bool shadowState = false,
|
||||
const Distance& shadowX = 0,
|
||||
const Distance& shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
LabelModelLineObject( const LabelModelLineObject* object );
|
||||
|
||||
~LabelModelLineObject() override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
LabelModelLineObject* clone() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Property Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Line Property: lineWidth
|
||||
//
|
||||
Distance lineWidth() const override;
|
||||
void setLineWidth( const Distance& value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Line Property: lineColorNode
|
||||
//
|
||||
ColorNode lineColorNode() const override;
|
||||
void setLineColorNode( const ColorNode& value ) override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capability Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
virtual bool canLineColor();
|
||||
virtual bool canLineWidth();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override;
|
||||
void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override;
|
||||
QPainterPath hoverPath( double scale ) const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
Distance mLineWidth;
|
||||
ColorNode mLineColorNode;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // LabelModelLineObject_h
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,436 +0,0 @@
|
||||
/* LabelModelObject.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LabelModelObject_h
|
||||
#define LabelModelObject_h
|
||||
|
||||
|
||||
#include "BarcodeStyle.h"
|
||||
#include "ColorNode.h"
|
||||
#include "Distance.h"
|
||||
#include "Handles.h"
|
||||
#include "Outline.h"
|
||||
#include "TextNode.h"
|
||||
|
||||
#include "Merge/Record.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QFont>
|
||||
#include <QMatrix>
|
||||
#include <QPainter>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
// Forward References
|
||||
class Region;
|
||||
class Size;
|
||||
|
||||
|
||||
///
|
||||
/// Label Model Object Base Class
|
||||
///
|
||||
class LabelModelObject : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
LabelModelObject();
|
||||
|
||||
LabelModelObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const QMatrix& matrix = QMatrix(),
|
||||
bool shadowState = false,
|
||||
const Distance& shadowX = 0,
|
||||
const Distance& shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
LabelModelObject( const LabelModelObject* object );
|
||||
|
||||
public:
|
||||
~LabelModelObject() override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
virtual LabelModelObject* clone() const = 0;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Signals
|
||||
///////////////////////////////////////////////////////////////
|
||||
signals:
|
||||
void moved();
|
||||
void changed();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Common Properties
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// ID Property.
|
||||
//
|
||||
int id() const;
|
||||
|
||||
//
|
||||
// Selected Property.
|
||||
//
|
||||
bool isSelected() const;
|
||||
void select( bool value = true );
|
||||
void unselect();
|
||||
|
||||
|
||||
//
|
||||
// x0 Property ( x coordinate of origin )
|
||||
//
|
||||
Distance x0() const;
|
||||
void setX0( const Distance& value );
|
||||
|
||||
|
||||
//
|
||||
// y0 Property ( y coordinate of origin )
|
||||
//
|
||||
Distance y0() const;
|
||||
void setY0( const Distance& value );
|
||||
|
||||
|
||||
//
|
||||
// w Property ( width of bounding box )
|
||||
//
|
||||
Distance w() const;
|
||||
void setW( const Distance& value );
|
||||
|
||||
|
||||
//
|
||||
// h Property ( height of bounding box )
|
||||
//
|
||||
Distance h() const;
|
||||
void setH( const Distance& value );
|
||||
|
||||
|
||||
//
|
||||
// Transformation Matrix Property
|
||||
//
|
||||
QMatrix matrix() const;
|
||||
void setMatrix( const QMatrix& value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow State Property
|
||||
//
|
||||
bool shadow() const;
|
||||
void setShadow( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow x Offset Property
|
||||
//
|
||||
Distance shadowX() const;
|
||||
void setShadowX( const Distance& value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow y Offset Property
|
||||
//
|
||||
Distance shadowY() const;
|
||||
void setShadowY( const Distance& value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow opacity Property
|
||||
//
|
||||
double shadowOpacity() const;
|
||||
void setShadowOpacity( double value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow Color Property
|
||||
//
|
||||
ColorNode shadowColorNode() const;
|
||||
void setShadowColorNode( const ColorNode& value );
|
||||
|
||||
|
||||
//
|
||||
// Natural Size Property (read-only)
|
||||
//
|
||||
virtual Size naturalSize() const;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Text Properties Virtual Interface
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Virtual Text Property: text
|
||||
//
|
||||
virtual QString text() const;
|
||||
virtual void setText( const QString &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontFamily
|
||||
//
|
||||
virtual QString fontFamily() const;
|
||||
virtual void setFontFamily( const QString &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontSize
|
||||
//
|
||||
virtual double fontSize() const;
|
||||
virtual void setFontSize( double value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontWeight
|
||||
//
|
||||
virtual QFont::Weight fontWeight() const;
|
||||
virtual void setFontWeight( QFont::Weight value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontItalicFlag
|
||||
//
|
||||
virtual bool fontItalicFlag() const;
|
||||
virtual void setFontItalicFlag( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontUnderlineFlag
|
||||
//
|
||||
virtual bool fontUnderlineFlag() const;
|
||||
virtual void setFontUnderlineFlag( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textColorNode
|
||||
//
|
||||
virtual ColorNode textColorNode() const;
|
||||
virtual void setTextColorNode( const ColorNode &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textHAlign
|
||||
//
|
||||
virtual Qt::Alignment textHAlign() const;
|
||||
virtual void setTextHAlign( Qt::Alignment value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textVAlign
|
||||
//
|
||||
virtual Qt::Alignment textVAlign() const;
|
||||
virtual void setTextVAlign( Qt::Alignment value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textLineSpacing
|
||||
//
|
||||
virtual double textLineSpacing() const;
|
||||
virtual void setTextLineSpacing( double value );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Image Properties Virtual Interface
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Virtual Image Property: filenameNode
|
||||
//
|
||||
virtual TextNode filenameNode() const;
|
||||
virtual void setFilenameNode( const TextNode &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Image Property: image
|
||||
//
|
||||
virtual const QImage* image() const;
|
||||
virtual void setImage( const QImage& value );
|
||||
virtual void setImage( const QString& name, const QImage& value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Image Property: svg
|
||||
//
|
||||
virtual QByteArray svg() const;
|
||||
virtual void setSvg( const QString& name, const QByteArray& value );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Shape Properties Virtual Interface
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Virtual Shape Property: lineWidth
|
||||
//
|
||||
virtual Distance lineWidth() const;
|
||||
virtual void setLineWidth( const Distance& value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Shape Property: lineColorNode
|
||||
//
|
||||
virtual ColorNode lineColorNode() const;
|
||||
virtual void setLineColorNode( const ColorNode &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Shape Property: fillColorNode
|
||||
//
|
||||
virtual ColorNode fillColorNode() const;
|
||||
virtual void setFillColorNode( const ColorNode &value );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Barcode Properties Virtual Interface
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Virtual Barcode Property: bcData
|
||||
//
|
||||
virtual QString bcData() const;
|
||||
virtual void setBcData( const QString& value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcTextFlag
|
||||
//
|
||||
virtual bool bcTextFlag() const;
|
||||
virtual void setBcTextFlag( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcChecksumFlag
|
||||
//
|
||||
virtual bool bcChecksumFlag() const;
|
||||
virtual void setBcChecksumFlag( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcColorNode
|
||||
//
|
||||
virtual ColorNode bcColorNode() const;
|
||||
virtual void setBcColorNode( const ColorNode &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcStyle
|
||||
//
|
||||
virtual BarcodeStyle bcStyle() const;
|
||||
virtual void setBcStyle( const BarcodeStyle &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcFormatDigits
|
||||
//
|
||||
virtual int bcFormatDigits() const;
|
||||
virtual void setBcFormatDigits( int value );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capabilities (Overridden by concrete classes.)
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
virtual bool canText() const;
|
||||
virtual bool canFill() const;
|
||||
virtual bool canLineColor() const;
|
||||
virtual bool canLineWidth() const;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Position and Size methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
void setPosition( const Distance& x0, const Distance& y0 );
|
||||
void setPositionRelative( const Distance& dx, const Distance& dy );
|
||||
Size size() const;
|
||||
void setSize( const Distance& w, const Distance& h );
|
||||
void setSize( const Size& size );
|
||||
void setSizeHonorAspect( const Distance& w, const Distance& h );
|
||||
void setWHonorAspect( const Distance& w );
|
||||
void setHHonorAspect( const Distance& h );
|
||||
Region getExtent();
|
||||
void rotate( double thetaDegs );
|
||||
void flipHoriz();
|
||||
void flipVert();
|
||||
bool isLocatedAt( double scale, const Distance& x, const Distance& y ) const;
|
||||
Handle* handleAt( double scale, const Distance& x, const Distance& y ) const;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter, bool inEditor, merge::Record* record ) const;
|
||||
void drawSelectionHighlight( QPainter* painter, double scale ) const;
|
||||
|
||||
protected:
|
||||
virtual void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const = 0;
|
||||
virtual void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const = 0;
|
||||
virtual QPainterPath hoverPath( double scale ) const = 0;
|
||||
|
||||
virtual void sizeUpdated();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Protected Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
bool mSelectedFlag;
|
||||
|
||||
Distance mX0;
|
||||
Distance mY0;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
|
||||
bool mShadowState;
|
||||
Distance mShadowX;
|
||||
Distance mShadowY;
|
||||
double mShadowOpacity;
|
||||
ColorNode mShadowColorNode;
|
||||
|
||||
QList<Handle*> mHandles;
|
||||
Outline* mOutline;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
static int msNextId;
|
||||
int mId;
|
||||
|
||||
QMatrix mMatrix;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // LabelModelObject_h
|
||||
@@ -1,207 +0,0 @@
|
||||
/* LabelModelShapeObject.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "LabelModelShapeObject.h"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QPen>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
LabelModelShapeObject::LabelModelShapeObject()
|
||||
{
|
||||
mOutline = new Outline( this );
|
||||
|
||||
mHandles << new HandleNorthWest( this );
|
||||
mHandles << new HandleNorth( this );
|
||||
mHandles << new HandleNorthEast( this );
|
||||
mHandles << new HandleEast( this );
|
||||
mHandles << new HandleSouthEast( this );
|
||||
mHandles << new HandleSouth( this );
|
||||
mHandles << new HandleSouthWest( this );
|
||||
mHandles << new HandleWest( this );
|
||||
|
||||
mLineWidth = 1.0;
|
||||
mLineColorNode = ColorNode( QColor( 0, 0, 0 ) );
|
||||
mFillColorNode = ColorNode( QColor( 0, 255, 0 ) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
LabelModelShapeObject::LabelModelShapeObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
const QMatrix& matrix,
|
||||
bool shadowState,
|
||||
const Distance& shadowX,
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: LabelModelObject( x0, y0, w, h,
|
||||
matrix,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
|
||||
{
|
||||
mOutline = new Outline( this );
|
||||
|
||||
mHandles << new HandleNorthWest( this );
|
||||
mHandles << new HandleNorth( this );
|
||||
mHandles << new HandleNorthEast( this );
|
||||
mHandles << new HandleEast( this );
|
||||
mHandles << new HandleSouthEast( this );
|
||||
mHandles << new HandleSouth( this );
|
||||
mHandles << new HandleSouthWest( this );
|
||||
mHandles << new HandleWest( this );
|
||||
|
||||
mLineWidth = lineWidth;
|
||||
mLineColorNode = lineColorNode;
|
||||
mFillColorNode = fillColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Copy constructor
|
||||
///
|
||||
LabelModelShapeObject::LabelModelShapeObject( const LabelModelShapeObject* object ) : LabelModelObject(object)
|
||||
{
|
||||
mLineWidth = object->mLineWidth;
|
||||
mLineColorNode = object->mLineColorNode;
|
||||
mFillColorNode = object->mFillColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
LabelModelShapeObject::~LabelModelShapeObject()
|
||||
{
|
||||
delete mOutline;
|
||||
|
||||
foreach( Handle* handle, mHandles )
|
||||
{
|
||||
delete handle;
|
||||
}
|
||||
mHandles.clear();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Width Property Getter
|
||||
///
|
||||
Distance LabelModelShapeObject::lineWidth() const
|
||||
{
|
||||
return mLineWidth;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Width Property Setter
|
||||
///
|
||||
void LabelModelShapeObject::setLineWidth( const Distance& value )
|
||||
{
|
||||
if ( mLineWidth != value )
|
||||
{
|
||||
mLineWidth = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Color Node Property Getter
|
||||
///
|
||||
ColorNode LabelModelShapeObject::lineColorNode() const
|
||||
{
|
||||
return mLineColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Color Node Property Setter
|
||||
///
|
||||
void LabelModelShapeObject::setLineColorNode( const ColorNode& value )
|
||||
{
|
||||
if ( mLineColorNode != value )
|
||||
{
|
||||
mLineColorNode = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Fill Color Node Property Getter
|
||||
///
|
||||
ColorNode LabelModelShapeObject::fillColorNode() const
|
||||
{
|
||||
return mFillColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Fill Color Node Property Setter
|
||||
///
|
||||
void LabelModelShapeObject::setFillColorNode( const ColorNode& value )
|
||||
{
|
||||
if ( mFillColorNode != value )
|
||||
{
|
||||
mFillColorNode = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Fill Capability Implementation
|
||||
///
|
||||
bool LabelModelShapeObject::canFill()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Line Color Capability Implementation
|
||||
///
|
||||
bool LabelModelShapeObject::canLineColor()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Line Width Capability Implementation
|
||||
///
|
||||
bool LabelModelShapeObject::canLineWidth()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,110 +0,0 @@
|
||||
/* LabelModelShapeObject.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LabelModelShapeObject_h
|
||||
#define LabelModelShapeObject_h
|
||||
|
||||
|
||||
#include "LabelModelObject.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Shape Object (Box or Ellipse)
|
||||
///
|
||||
class LabelModelShapeObject : public LabelModelObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
LabelModelShapeObject();
|
||||
|
||||
LabelModelShapeObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
const QMatrix& matrix,
|
||||
bool shadowState,
|
||||
const Distance& shadowX,
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode );
|
||||
|
||||
LabelModelShapeObject( const LabelModelShapeObject* object );
|
||||
public:
|
||||
~LabelModelShapeObject() override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Property Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Shape Property: lineWidth
|
||||
//
|
||||
Distance lineWidth() const override;
|
||||
void setLineWidth( const Distance& value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Shape Property: lineColorNode
|
||||
//
|
||||
ColorNode lineColorNode() const override;
|
||||
void setLineColorNode( const ColorNode& value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Shape Property: fillColorNode
|
||||
//
|
||||
ColorNode fillColorNode() const override;
|
||||
void setFillColorNode( const ColorNode& value ) override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capability Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
virtual bool canFill();
|
||||
virtual bool canLineColor();
|
||||
virtual bool canLineWidth();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
Distance mLineWidth;
|
||||
ColorNode mLineColorNode;
|
||||
ColorNode mFillColorNode;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // LabelModelShapeObject_h
|
||||
@@ -1,720 +0,0 @@
|
||||
/* LabelModelTextObject.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "LabelModelTextObject.h"
|
||||
|
||||
#include "Size.h"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QPen>
|
||||
#include <QTextDocument>
|
||||
#include <QTextBlock>
|
||||
#include <QRegularExpression>
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const double marginPts = 3;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
LabelModelTextObject::LabelModelTextObject()
|
||||
{
|
||||
mOutline = new Outline( this );
|
||||
|
||||
mHandles << new HandleNorthWest( this );
|
||||
mHandles << new HandleNorth( this );
|
||||
mHandles << new HandleNorthEast( this );
|
||||
mHandles << new HandleEast( this );
|
||||
mHandles << new HandleSouthEast( this );
|
||||
mHandles << new HandleSouth( this );
|
||||
mHandles << new HandleSouthWest( this );
|
||||
mHandles << new HandleWest( this );
|
||||
|
||||
mText = "";
|
||||
mFontFamily = "Sans";
|
||||
mFontSize = 10;
|
||||
mFontWeight = QFont::Normal;
|
||||
mFontItalicFlag = false;
|
||||
mFontUnderlineFlag = false;
|
||||
mTextColorNode = ColorNode( QColor( 0, 0, 0 ) );
|
||||
mTextHAlign = Qt::AlignLeft;
|
||||
mTextVAlign = Qt::AlignTop;
|
||||
mTextLineSpacing = 1;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
LabelModelTextObject::LabelModelTextObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const QString& text,
|
||||
const QString& fontFamily,
|
||||
double fontSize,
|
||||
QFont::Weight fontWeight,
|
||||
bool fontItalicFlag,
|
||||
bool fontUnderlineFlag,
|
||||
ColorNode textColorNode,
|
||||
Qt::Alignment textHAlign,
|
||||
Qt::Alignment textVAlign,
|
||||
double textLineSpacing,
|
||||
const QMatrix& matrix,
|
||||
bool shadowState,
|
||||
const Distance& shadowX,
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: LabelModelObject( x0, y0, w, h,
|
||||
matrix,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
|
||||
{
|
||||
mOutline = new Outline( this );
|
||||
|
||||
mHandles << new HandleNorthWest( this );
|
||||
mHandles << new HandleNorth( this );
|
||||
mHandles << new HandleNorthEast( this );
|
||||
mHandles << new HandleEast( this );
|
||||
mHandles << new HandleSouthEast( this );
|
||||
mHandles << new HandleSouth( this );
|
||||
mHandles << new HandleSouthWest( this );
|
||||
mHandles << new HandleWest( this );
|
||||
|
||||
mText = text;
|
||||
mFontFamily = fontFamily;
|
||||
mFontSize = fontSize;
|
||||
mFontWeight = fontWeight;
|
||||
mFontItalicFlag = fontItalicFlag;
|
||||
mFontUnderlineFlag = fontUnderlineFlag;
|
||||
mTextColorNode = textColorNode;
|
||||
mTextHAlign = textHAlign;
|
||||
mTextVAlign = textVAlign;
|
||||
mTextLineSpacing = textLineSpacing;
|
||||
|
||||
update(); // Initialize cached editor layouts
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Copy constructor
|
||||
///
|
||||
LabelModelTextObject::LabelModelTextObject( const LabelModelTextObject* object )
|
||||
: LabelModelObject(object)
|
||||
{
|
||||
mText = object->mText;
|
||||
mFontFamily = object->mFontFamily;
|
||||
mFontSize = object->mFontSize;
|
||||
mFontWeight = object->mFontWeight;
|
||||
mFontItalicFlag = object->mFontItalicFlag;
|
||||
mFontUnderlineFlag = object->mFontUnderlineFlag;
|
||||
mTextColorNode = object->mTextColorNode;
|
||||
mTextHAlign = object->mTextHAlign;
|
||||
mTextVAlign = object->mTextVAlign;
|
||||
mTextLineSpacing = object->mTextLineSpacing;
|
||||
|
||||
update(); // Initialize cached editor layouts
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
LabelModelTextObject::~LabelModelTextObject()
|
||||
{
|
||||
delete mOutline;
|
||||
|
||||
foreach( Handle* handle, mHandles )
|
||||
{
|
||||
delete handle;
|
||||
}
|
||||
mHandles.clear();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
LabelModelTextObject* LabelModelTextObject::clone() const
|
||||
{
|
||||
return new LabelModelTextObject( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Text Property Getter
|
||||
///
|
||||
QString LabelModelTextObject::text() const
|
||||
{
|
||||
return mText.toString();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Text Property Setter
|
||||
///
|
||||
void LabelModelTextObject::setText( const QString& value )
|
||||
{
|
||||
if ( mText.toString() != value )
|
||||
{
|
||||
mText = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// FontFamily Property Getter
|
||||
///
|
||||
QString LabelModelTextObject::fontFamily() const
|
||||
{
|
||||
return mFontFamily;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// FontFamily Property Setter
|
||||
///
|
||||
void LabelModelTextObject::setFontFamily( const QString& value )
|
||||
{
|
||||
if ( mFontFamily != value )
|
||||
{
|
||||
mFontFamily = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// FontSize Property Getter
|
||||
///
|
||||
double LabelModelTextObject::fontSize() const
|
||||
{
|
||||
return mFontSize;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// FontSize Property Setter
|
||||
///
|
||||
void LabelModelTextObject::setFontSize( double value )
|
||||
{
|
||||
if ( mFontSize != value )
|
||||
{
|
||||
mFontSize = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// FontWeight Property Getter
|
||||
///
|
||||
QFont::Weight LabelModelTextObject::fontWeight() const
|
||||
{
|
||||
return mFontWeight;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// FontWeight Property Setter
|
||||
///
|
||||
void LabelModelTextObject::setFontWeight( QFont::Weight value )
|
||||
{
|
||||
if ( mFontWeight != value )
|
||||
{
|
||||
mFontWeight = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// FontItalicFlag Property Getter
|
||||
///
|
||||
bool LabelModelTextObject::fontItalicFlag() const
|
||||
{
|
||||
return mFontItalicFlag;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// FontItalicFlag Property Setter
|
||||
///
|
||||
void LabelModelTextObject::setFontItalicFlag( bool value )
|
||||
{
|
||||
if ( mFontItalicFlag != value )
|
||||
{
|
||||
mFontItalicFlag = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// FontUnderlineFlag Property Getter
|
||||
///
|
||||
bool LabelModelTextObject::fontUnderlineFlag() const
|
||||
{
|
||||
return mFontUnderlineFlag;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// FontUnderlineFlag Property Setter
|
||||
///
|
||||
void LabelModelTextObject::setFontUnderlineFlag( bool value )
|
||||
{
|
||||
if ( mFontUnderlineFlag != value )
|
||||
{
|
||||
mFontUnderlineFlag = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Text Color Node Property Getter
|
||||
///
|
||||
ColorNode LabelModelTextObject::textColorNode() const
|
||||
{
|
||||
return mTextColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Text Color Node Property Setter
|
||||
///
|
||||
void LabelModelTextObject::setTextColorNode( const ColorNode& value )
|
||||
{
|
||||
if ( mTextColorNode != value )
|
||||
{
|
||||
mTextColorNode = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// TextHAlign Property Getter
|
||||
///
|
||||
Qt::Alignment LabelModelTextObject::textHAlign() const
|
||||
{
|
||||
return mTextHAlign;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// TextHAlign Property Setter
|
||||
///
|
||||
void LabelModelTextObject::setTextHAlign( Qt::Alignment value )
|
||||
{
|
||||
if ( mTextHAlign != value )
|
||||
{
|
||||
mTextHAlign = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// TextVAlign Property Getter
|
||||
///
|
||||
Qt::Alignment LabelModelTextObject::textVAlign() const
|
||||
{
|
||||
return mTextVAlign;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// TextVAlign Property Setter
|
||||
///
|
||||
void LabelModelTextObject::setTextVAlign( Qt::Alignment value )
|
||||
{
|
||||
if ( mTextVAlign != value )
|
||||
{
|
||||
mTextVAlign = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// TextLineSpacing Property Getter
|
||||
///
|
||||
double LabelModelTextObject::textLineSpacing() const
|
||||
{
|
||||
return mTextLineSpacing;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// TextLineSpacing Property Setter
|
||||
///
|
||||
void LabelModelTextObject::setTextLineSpacing( double value )
|
||||
{
|
||||
if ( mTextLineSpacing != value )
|
||||
{
|
||||
mTextLineSpacing = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// NaturalSize Property Getter
|
||||
///
|
||||
Size LabelModelTextObject::naturalSize() const
|
||||
{
|
||||
QFont font;
|
||||
font.setFamily( mFontFamily );
|
||||
font.setPointSizeF( mFontSize );
|
||||
font.setWeight( mFontWeight );
|
||||
font.setItalic( mFontItalicFlag );
|
||||
font.setUnderline( mFontUnderlineFlag );
|
||||
|
||||
QTextOption textOption;
|
||||
textOption.setAlignment( mTextHAlign );
|
||||
textOption.setWrapMode( QTextOption::WordWrap );
|
||||
|
||||
QFontMetricsF fontMetrics( font );
|
||||
double dy = fontMetrics.lineSpacing() * mTextLineSpacing;
|
||||
|
||||
QString displayText = mText.isEmpty() ? tr("Text") : mText.toString();
|
||||
QTextDocument document( displayText );
|
||||
|
||||
// Do layouts
|
||||
double x = 0;
|
||||
double y = 0;
|
||||
QRectF boundingRect;
|
||||
for ( int i = 0; i < document.blockCount(); i++ )
|
||||
{
|
||||
QTextLayout* layout = new QTextLayout( document.findBlockByNumber(i).text() );
|
||||
|
||||
layout->setFont( font );
|
||||
layout->setTextOption( textOption );
|
||||
layout->setCacheEnabled(true);
|
||||
|
||||
layout->beginLayout();
|
||||
for ( QTextLine l = layout->createLine(); l.isValid(); l = layout->createLine() )
|
||||
{
|
||||
l.setPosition( QPointF( x, y ) );
|
||||
y += dy;
|
||||
}
|
||||
layout->endLayout();
|
||||
|
||||
boundingRect = layout->boundingRect().united( boundingRect );
|
||||
}
|
||||
|
||||
return Size( boundingRect.width() + 2*marginPts, boundingRect.height() + 2*marginPts );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Text Capability Implementation
|
||||
///
|
||||
bool LabelModelTextObject::canText()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw shadow of object
|
||||
///
|
||||
void LabelModelTextObject::drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
merge::Record* record ) const
|
||||
{
|
||||
QColor textColor = mTextColorNode.color( record );
|
||||
|
||||
if ( textColor.alpha() )
|
||||
{
|
||||
QColor shadowColor = mShadowColorNode.color( record );
|
||||
shadowColor.setAlphaF( mShadowOpacity );
|
||||
|
||||
if ( inEditor )
|
||||
{
|
||||
drawTextInEditor( painter, shadowColor );
|
||||
}
|
||||
else
|
||||
{
|
||||
drawText( painter, shadowColor, record );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw object itself
|
||||
///
|
||||
void LabelModelTextObject::drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
merge::Record* record ) const
|
||||
{
|
||||
QColor textColor = mTextColorNode.color( record );
|
||||
|
||||
if ( inEditor )
|
||||
{
|
||||
drawTextInEditor( painter, textColor );
|
||||
}
|
||||
else
|
||||
{
|
||||
drawText( painter, textColor, record );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Path to test for hover condition
|
||||
///
|
||||
QPainterPath LabelModelTextObject::hoverPath( double scale ) const
|
||||
{
|
||||
return mHoverPath;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Size updated
|
||||
///
|
||||
void LabelModelTextObject::sizeUpdated()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Update cached information for editor view
|
||||
///
|
||||
void LabelModelTextObject::update()
|
||||
{
|
||||
QFont font;
|
||||
font.setFamily( mFontFamily );
|
||||
font.setPointSizeF( mFontSize );
|
||||
font.setWeight( mFontWeight );
|
||||
font.setItalic( mFontItalicFlag );
|
||||
font.setUnderline( mFontUnderlineFlag );
|
||||
|
||||
QTextOption textOption;
|
||||
textOption.setAlignment( mTextHAlign );
|
||||
textOption.setWrapMode( QTextOption::WordWrap );
|
||||
|
||||
QFontMetricsF fontMetrics( font );
|
||||
double dy = fontMetrics.lineSpacing() * mTextLineSpacing;
|
||||
|
||||
QString displayText = mText.isEmpty() ? tr("Text") : mText.toString();
|
||||
QTextDocument document( displayText );
|
||||
|
||||
qDeleteAll( mEditorLayouts );
|
||||
mEditorLayouts.clear();
|
||||
|
||||
// Pass #1 -- do initial layouts
|
||||
double x = 0;
|
||||
double y = 0;
|
||||
QRectF boundingRect;
|
||||
for ( int i = 0; i < document.blockCount(); i++ )
|
||||
{
|
||||
QTextLayout* layout = new QTextLayout( document.findBlockByNumber(i).text() );
|
||||
|
||||
layout->setFont( font );
|
||||
layout->setTextOption( textOption );
|
||||
layout->setCacheEnabled(true);
|
||||
|
||||
layout->beginLayout();
|
||||
for ( QTextLine l = layout->createLine(); l.isValid(); l = layout->createLine() )
|
||||
{
|
||||
l.setLineWidth( mW.pt() - 2*marginPts );
|
||||
l.setPosition( QPointF( x, y ) );
|
||||
y += dy;
|
||||
}
|
||||
layout->endLayout();
|
||||
|
||||
mEditorLayouts.append( layout );
|
||||
|
||||
boundingRect = layout->boundingRect().united( boundingRect );
|
||||
}
|
||||
double h = boundingRect.height();
|
||||
|
||||
|
||||
// Pass #2 -- adjust layout positions for vertical alignment and create hover path
|
||||
x = marginPts;
|
||||
switch ( mTextVAlign )
|
||||
{
|
||||
case Qt::AlignVCenter:
|
||||
y = mH.pt()/2 - h/2;
|
||||
break;
|
||||
case Qt::AlignBottom:
|
||||
y = mH.pt() - h - marginPts;
|
||||
break;
|
||||
default:
|
||||
y = marginPts;
|
||||
break;
|
||||
}
|
||||
QPainterPath hoverPath; // new empty hover path
|
||||
foreach ( QTextLayout* layout, mEditorLayouts )
|
||||
{
|
||||
for ( int j = 0; j < layout->lineCount(); j++ )
|
||||
{
|
||||
QTextLine l = layout->lineAt(j);
|
||||
l.setPosition( QPointF( x, y ) );
|
||||
y += dy;
|
||||
|
||||
hoverPath.addRect( l.naturalTextRect() ); // add to new hover path
|
||||
}
|
||||
}
|
||||
|
||||
mHoverPath = hoverPath; // save new hover path
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw text in editor from cached information
|
||||
///
|
||||
void LabelModelTextObject::drawTextInEditor( QPainter* painter, const QColor& color ) const
|
||||
{
|
||||
if ( mText.isEmpty() )
|
||||
{
|
||||
QColor mutedColor = color;
|
||||
mutedColor.setAlphaF( 0.5 * color.alphaF() );
|
||||
painter->setPen( QPen( mutedColor ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->setPen( QPen( color ) );
|
||||
}
|
||||
|
||||
foreach ( QTextLayout* layout, mEditorLayouts )
|
||||
{
|
||||
layout->draw( painter, QPointF( 0, 0 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw text in final printout or preview
|
||||
///
|
||||
void
|
||||
LabelModelTextObject::drawText( QPainter* painter,
|
||||
const QColor& color,
|
||||
merge::Record* record ) const
|
||||
{
|
||||
QFont font;
|
||||
font.setFamily( mFontFamily );
|
||||
font.setPointSizeF( mFontSize );
|
||||
font.setWeight( mFontWeight );
|
||||
font.setItalic( mFontItalicFlag );
|
||||
font.setUnderline( mFontUnderlineFlag );
|
||||
|
||||
QTextOption textOption;
|
||||
textOption.setAlignment( mTextHAlign );
|
||||
textOption.setWrapMode( QTextOption::WordWrap );
|
||||
|
||||
QFontMetricsF fontMetrics( font );
|
||||
double dy = fontMetrics.lineSpacing() * mTextLineSpacing;
|
||||
|
||||
QTextDocument document( mText.expand( record ) );
|
||||
|
||||
QList<QTextLayout*> layouts;
|
||||
|
||||
// Pass #1 -- do initial layouts
|
||||
double x = 0;
|
||||
double y = 0;
|
||||
QRectF boundingRect;
|
||||
for ( int i = 0; i < document.blockCount(); i++ )
|
||||
{
|
||||
QTextLayout* layout = new QTextLayout( document.findBlockByNumber(i).text() );
|
||||
|
||||
layout->setFont( font );
|
||||
layout->setTextOption( textOption );
|
||||
layout->setCacheEnabled(true);
|
||||
|
||||
layout->beginLayout();
|
||||
for ( QTextLine l = layout->createLine(); l.isValid(); l = layout->createLine() )
|
||||
{
|
||||
l.setLineWidth( mW.pt() - 2*marginPts );
|
||||
l.setPosition( QPointF( x, y ) );
|
||||
y += dy;
|
||||
}
|
||||
layout->endLayout();
|
||||
|
||||
layouts.append( layout );
|
||||
|
||||
boundingRect = layout->boundingRect().united( boundingRect );
|
||||
}
|
||||
double h = boundingRect.height();
|
||||
|
||||
|
||||
// Pass #2 -- adjust layout positions for vertical alignment and create hover path
|
||||
x = marginPts;
|
||||
switch ( mTextVAlign )
|
||||
{
|
||||
case Qt::AlignVCenter:
|
||||
y = mH.pt()/2 - h/2;
|
||||
break;
|
||||
case Qt::AlignBottom:
|
||||
y = mH.pt() - h - marginPts;
|
||||
break;
|
||||
default:
|
||||
y = marginPts;
|
||||
break;
|
||||
}
|
||||
foreach ( QTextLayout* layout, layouts )
|
||||
{
|
||||
for ( int j = 0; j < layout->lineCount(); j++ )
|
||||
{
|
||||
QTextLine l = layout->lineAt(j);
|
||||
l.setPosition( QPointF( x, y ) );
|
||||
y += dy;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw layouts
|
||||
painter->setPen( QPen( color ) );
|
||||
foreach ( QTextLayout* layout, layouts )
|
||||
{
|
||||
layout->draw( painter, QPointF( 0, 0 ) );
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
qDeleteAll( layouts );
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,209 +0,0 @@
|
||||
/* LabelModelTextObject.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LabelModelTextObject_h
|
||||
#define LabelModelTextObject_h
|
||||
|
||||
|
||||
#include "LabelModelObject.h"
|
||||
#include "RawText.h"
|
||||
|
||||
#include <QTextLayout>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Line Object
|
||||
///
|
||||
class LabelModelTextObject : public LabelModelObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
LabelModelTextObject();
|
||||
|
||||
LabelModelTextObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const QString& text,
|
||||
const QString& fontFamily,
|
||||
double fontSize,
|
||||
QFont::Weight fontWeight,
|
||||
bool fontItalicFlag,
|
||||
bool fontUnderlineFlag,
|
||||
ColorNode textColorNode,
|
||||
Qt::Alignment textHAlign,
|
||||
Qt::Alignment textVAlign,
|
||||
double textLineSpacing,
|
||||
const QMatrix& matrix = QMatrix(),
|
||||
bool shadowState = false,
|
||||
const Distance& shadowX = 0,
|
||||
const Distance& shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
LabelModelTextObject( const LabelModelTextObject* object );
|
||||
|
||||
~LabelModelTextObject() override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
LabelModelTextObject* clone() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Property Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Text Property: text
|
||||
//
|
||||
QString text() const override;
|
||||
void setText( const QString &value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: fontFamily
|
||||
//
|
||||
QString fontFamily() const override;
|
||||
void setFontFamily( const QString &value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: fontSize
|
||||
//
|
||||
double fontSize() const override;
|
||||
void setFontSize( double value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: fontWeight
|
||||
//
|
||||
QFont::Weight fontWeight() const override;
|
||||
void setFontWeight( QFont::Weight value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: fontItalicFlag
|
||||
//
|
||||
bool fontItalicFlag() const override;
|
||||
void setFontItalicFlag( bool value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: fontUnderlineFlag
|
||||
//
|
||||
bool fontUnderlineFlag() const override;
|
||||
void setFontUnderlineFlag( bool value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: textColorNode
|
||||
//
|
||||
ColorNode textColorNode() const override;
|
||||
void setTextColorNode( const ColorNode &value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: textHAlign
|
||||
//
|
||||
Qt::Alignment textHAlign() const override;
|
||||
void setTextHAlign( Qt::Alignment value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: textVAlign
|
||||
//
|
||||
Qt::Alignment textVAlign() const override;
|
||||
void setTextVAlign( Qt::Alignment value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: textLineSpacing
|
||||
//
|
||||
double textLineSpacing() const override;
|
||||
void setTextLineSpacing( double value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Property: naturalSize
|
||||
//
|
||||
Size naturalSize() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capability Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
virtual bool canText();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override;
|
||||
void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override;
|
||||
QPainterPath hoverPath( double scale ) const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
void sizeUpdated() override;
|
||||
void update();
|
||||
void drawTextInEditor( QPainter* painter, const QColor& color ) const;
|
||||
void drawText( QPainter* painter, const QColor&color, merge::Record* record ) const;
|
||||
QString expandText( QString text, merge::Record* record ) const;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
RawText mText;
|
||||
QString mFontFamily;
|
||||
double mFontSize;
|
||||
QFont::Weight mFontWeight;
|
||||
bool mFontItalicFlag;
|
||||
bool mFontUnderlineFlag;
|
||||
ColorNode mTextColorNode;
|
||||
Qt::Alignment mTextHAlign;
|
||||
Qt::Alignment mTextVAlign;
|
||||
double mTextLineSpacing;
|
||||
|
||||
QList<QTextLayout*> mEditorLayouts;
|
||||
QPainterPath mHoverPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // LabelModelTextObject_h
|
||||
@@ -1,104 +0,0 @@
|
||||
/* Layout.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Layout.h"
|
||||
|
||||
#include "Constants.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
Layout::Layout( int nx,
|
||||
int ny,
|
||||
const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& dx,
|
||||
const Distance& dy )
|
||||
: mNx(nx), mNy(ny), mX0(x0), mY0(y0), mDx(dx), mDy(dy)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
Layout::Layout( const Layout& other )
|
||||
: mNx(other.mNx), mNy(other.mNy), mX0(other.mX0), mY0(other.mY0),
|
||||
mDx(other.mDx), mDy(other.mDy)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
int Layout::nx() const
|
||||
{
|
||||
return mNx;
|
||||
}
|
||||
|
||||
|
||||
int Layout::ny() const
|
||||
{
|
||||
return mNy;
|
||||
}
|
||||
|
||||
|
||||
Distance Layout::x0() const
|
||||
{
|
||||
return mX0;
|
||||
}
|
||||
|
||||
|
||||
Distance Layout::y0() const
|
||||
{
|
||||
return mY0;
|
||||
}
|
||||
|
||||
|
||||
Distance Layout::dx() const
|
||||
{
|
||||
return mDx;
|
||||
}
|
||||
|
||||
|
||||
Distance Layout::dy() const
|
||||
{
|
||||
return mDy;
|
||||
}
|
||||
|
||||
|
||||
bool Layout::isSimilarTo( const Layout *other )
|
||||
{
|
||||
return ( (mNx == other->mNx) &&
|
||||
(mNy == other->mNy) &&
|
||||
(fabs(mX0 - other->mX0) < EPSILON) &&
|
||||
(fabs(mY0 - other->mY0) < EPSILON) &&
|
||||
(fabs(mDx - other->mDx) < EPSILON) &&
|
||||
(fabs(mDy - other->mDy) < EPSILON) );
|
||||
}
|
||||
|
||||
|
||||
Layout* Layout::dup() const
|
||||
{
|
||||
Layout *other = new Layout( *this );
|
||||
return other;
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,71 +0,0 @@
|
||||
/* Layout.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_Layout_h
|
||||
#define glabels_Layout_h
|
||||
|
||||
|
||||
#include "Distance.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class Layout
|
||||
{
|
||||
|
||||
public:
|
||||
Layout( int nx,
|
||||
int ny,
|
||||
const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& dx,
|
||||
const Distance& dy );
|
||||
|
||||
Layout( const Layout &other );
|
||||
|
||||
int nx() const;
|
||||
int ny() const;
|
||||
|
||||
Distance x0() const;
|
||||
Distance y0() const;
|
||||
|
||||
Distance dx() const;
|
||||
Distance dy() const;
|
||||
|
||||
bool isSimilarTo( const Layout *other );
|
||||
|
||||
Layout* dup() const;
|
||||
|
||||
|
||||
private:
|
||||
int mNx;
|
||||
int mNy;
|
||||
Distance mX0;
|
||||
Distance mY0;
|
||||
Distance mDx;
|
||||
Distance mDy;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_Layout_h
|
||||
@@ -20,12 +20,10 @@
|
||||
|
||||
#include "MainWindow.h"
|
||||
|
||||
#include "Db.h"
|
||||
#include "File.h"
|
||||
#include "Help.h"
|
||||
#include "Icons.h"
|
||||
#include "LabelEditor.h"
|
||||
#include "LabelModel.h"
|
||||
#include "MergeView.h"
|
||||
#include "ObjectEditor.h"
|
||||
#include "PreferencesDialog.h"
|
||||
@@ -34,6 +32,9 @@
|
||||
#include "StartupView.h"
|
||||
#include "UndoRedoModel.h"
|
||||
|
||||
#include "model/Db.h"
|
||||
#include "model/Model.h"
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QFrame>
|
||||
#include <QMessageBox>
|
||||
@@ -151,7 +152,7 @@ namespace glabels
|
||||
///
|
||||
/// Get model accessor
|
||||
///
|
||||
LabelModel* MainWindow::model() const
|
||||
model::Model* MainWindow::model() const
|
||||
{
|
||||
return mModel;
|
||||
}
|
||||
@@ -160,9 +161,9 @@ namespace glabels
|
||||
///
|
||||
/// Set model accessor
|
||||
///
|
||||
void MainWindow::setModel( LabelModel *label )
|
||||
void MainWindow::setModel( model::Model* model )
|
||||
{
|
||||
mModel = label;
|
||||
mModel = model;
|
||||
mUndoRedoModel = new UndoRedoModel( mModel );
|
||||
|
||||
mPropertiesView->setModel( mModel, mUndoRedoModel );
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#ifndef MainWindow_h
|
||||
#define MainWindow_h
|
||||
|
||||
#include <model/Model.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QCloseEvent>
|
||||
@@ -39,7 +40,6 @@ namespace glabels
|
||||
|
||||
// Forward References
|
||||
class LabelEditor;
|
||||
class LabelModel;
|
||||
class MergeView;
|
||||
class ObjectEditor;
|
||||
class PrintView;
|
||||
@@ -68,8 +68,8 @@ namespace glabels
|
||||
// Public Methods
|
||||
/////////////////////////////////////
|
||||
public:
|
||||
LabelModel* model() const;
|
||||
void setModel( LabelModel* label );
|
||||
model::Model* model() const;
|
||||
void setModel( model::Model* model );
|
||||
bool isEmpty() const;
|
||||
|
||||
|
||||
@@ -209,7 +209,7 @@ namespace glabels
|
||||
QToolBar* fileToolBar;
|
||||
QToolBar* editorToolBar;
|
||||
|
||||
LabelModel* mModel;
|
||||
model::Model* mModel;
|
||||
UndoRedoModel* mUndoRedoModel;
|
||||
|
||||
QListWidget* mContents;
|
||||
|
||||
@@ -1,212 +0,0 @@
|
||||
/* Markup.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Markup.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
const QPainterPath& Markup::path() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
|
||||
MarkupMargin::MarkupMargin( const Frame* frame,
|
||||
const Distance& size )
|
||||
: mFrame(frame), mSize(size)
|
||||
{
|
||||
mPath = frame->marginPath( size );
|
||||
}
|
||||
|
||||
|
||||
Markup* MarkupMargin::dup() const
|
||||
{
|
||||
return new MarkupMargin( mFrame, mSize );
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupMargin::size() const
|
||||
{
|
||||
return mSize;
|
||||
}
|
||||
|
||||
|
||||
MarkupLine::MarkupLine( const Distance& x1,
|
||||
const Distance& y1,
|
||||
const Distance& x2,
|
||||
const Distance& y2 )
|
||||
: mX1(x1), mY1(y1), mX2(x2), mY2(y2)
|
||||
{
|
||||
mPath.moveTo( x1.pt(), y1.pt() );
|
||||
mPath.lineTo( x2.pt(), y2.pt() );
|
||||
}
|
||||
|
||||
|
||||
Markup* MarkupLine::dup() const
|
||||
{
|
||||
return new MarkupLine( mX1, mY1, mX2, mY2 );
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupLine::x1() const
|
||||
{
|
||||
return mX1;
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupLine::y1() const
|
||||
{
|
||||
return mY1;
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupLine::x2() const
|
||||
{
|
||||
return mX2;
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupLine::y2() const
|
||||
{
|
||||
return mY2;
|
||||
}
|
||||
|
||||
|
||||
MarkupRect::MarkupRect( const Distance& x1,
|
||||
const Distance& y1,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& r )
|
||||
: mX1(x1), mY1(y1), mW(w), mH(h), mR(r)
|
||||
{
|
||||
mPath.addRoundedRect( x1.pt(), y1.pt(), w.pt(), h.pt(), r.pt(), r.pt() );
|
||||
}
|
||||
|
||||
|
||||
Markup* MarkupRect::dup() const
|
||||
{
|
||||
return new MarkupRect( mX1, mY1, mW, mH, mR );
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupRect::x1() const
|
||||
{
|
||||
return mX1;
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupRect::y1() const
|
||||
{
|
||||
return mY1;
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupRect::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupRect::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupRect::r() const
|
||||
{
|
||||
return mR;
|
||||
}
|
||||
|
||||
|
||||
MarkupEllipse::MarkupEllipse( const Distance& x1,
|
||||
const Distance& y1,
|
||||
const Distance& w,
|
||||
const Distance& h )
|
||||
: mX1(x1), mY1(y1), mW(w), mH(h)
|
||||
{
|
||||
mPath.addEllipse( x1.pt(), y1.pt(), w.pt(), h.pt() );
|
||||
}
|
||||
|
||||
|
||||
Markup* MarkupEllipse::dup() const
|
||||
{
|
||||
return new MarkupEllipse( mX1, mY1, mW, mH );
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupEllipse::x1() const
|
||||
{
|
||||
return mX1;
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupEllipse::y1() const
|
||||
{
|
||||
return mY1;
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupEllipse::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupEllipse::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
|
||||
|
||||
MarkupCircle::MarkupCircle( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& r )
|
||||
: mX0(x0), mY0(y0), mR(r)
|
||||
{
|
||||
mPath.addEllipse( (x0-r).pt(), (y0-r).pt(), 2*r.pt(), 2*r.pt() );
|
||||
}
|
||||
|
||||
Markup* MarkupCircle::dup() const
|
||||
{
|
||||
return new MarkupCircle( mX0, mY0, mR );
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupCircle::x0() const
|
||||
{
|
||||
return mX0;
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupCircle::y0() const
|
||||
{
|
||||
return mY0;
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupCircle::r() const
|
||||
{
|
||||
return mR;
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,156 +0,0 @@
|
||||
/* Markup.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_Markup_h
|
||||
#define glabels_Markup_h
|
||||
|
||||
|
||||
#include "Frame.h"
|
||||
|
||||
#include <QPainterPath>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class Markup
|
||||
{
|
||||
public:
|
||||
virtual Markup* dup() const = 0;
|
||||
|
||||
const QPainterPath& path() const;
|
||||
|
||||
protected:
|
||||
QPainterPath mPath;
|
||||
};
|
||||
|
||||
|
||||
class MarkupMargin : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupMargin( const Frame* frame,
|
||||
const Distance& size );
|
||||
|
||||
Distance size() const;
|
||||
|
||||
Markup* dup() const override;
|
||||
|
||||
private:
|
||||
const Frame* mFrame;
|
||||
Distance mSize;
|
||||
};
|
||||
|
||||
|
||||
class MarkupLine : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupLine( const Distance& x1,
|
||||
const Distance& y1,
|
||||
const Distance& x2,
|
||||
const Distance& y2 );
|
||||
|
||||
Distance x1() const;
|
||||
Distance y1() const;
|
||||
Distance x2() const;
|
||||
Distance y2() const;
|
||||
|
||||
Markup* dup() const override;
|
||||
|
||||
private:
|
||||
Distance mX1;
|
||||
Distance mY1;
|
||||
Distance mX2;
|
||||
Distance mY2;
|
||||
};
|
||||
|
||||
|
||||
class MarkupRect : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupRect( const Distance& x1,
|
||||
const Distance& y1,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& r );
|
||||
|
||||
Distance x1() const;
|
||||
Distance y1() const;
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
Distance r() const;
|
||||
|
||||
Markup* dup() const override;
|
||||
|
||||
private:
|
||||
Distance mX1;
|
||||
Distance mY1;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mR;
|
||||
};
|
||||
|
||||
|
||||
class MarkupEllipse : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupEllipse( const Distance& x1,
|
||||
const Distance& y1,
|
||||
const Distance& w,
|
||||
const Distance& h );
|
||||
|
||||
Distance x1() const;
|
||||
Distance y1() const;
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
|
||||
Markup* dup() const override;
|
||||
|
||||
private:
|
||||
Distance mX1;
|
||||
Distance mY1;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
};
|
||||
|
||||
|
||||
class MarkupCircle : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupCircle( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& r );
|
||||
|
||||
Distance x0() const;
|
||||
Distance y0() const;
|
||||
Distance r() const;
|
||||
|
||||
Markup* dup() const override;
|
||||
|
||||
private:
|
||||
Distance mX0;
|
||||
Distance mY0;
|
||||
Distance mR;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_Markup_h
|
||||
@@ -1,50 +0,0 @@
|
||||
#=======================================
|
||||
# Sources
|
||||
#=======================================
|
||||
set (merge_sources
|
||||
Factory.cpp
|
||||
Record.cpp
|
||||
Merge.cpp
|
||||
None.cpp
|
||||
Text.cpp
|
||||
TextCsv.cpp
|
||||
TextCsvKeys.cpp
|
||||
TextTsv.cpp
|
||||
TextTsvKeys.cpp
|
||||
TextColon.cpp
|
||||
TextColonKeys.cpp
|
||||
TextSemicolon.cpp
|
||||
TextSemicolonKeys.cpp
|
||||
)
|
||||
|
||||
set (merge_qobject_headers
|
||||
Merge.h
|
||||
)
|
||||
|
||||
qt5_wrap_cpp (merge_moc_sources ${merge_qobject_headers})
|
||||
|
||||
add_library (Merge STATIC
|
||||
${merge_sources}
|
||||
${merge_moc_sources}
|
||||
)
|
||||
|
||||
|
||||
#=======================================
|
||||
# Where to find stuff
|
||||
#=======================================
|
||||
include_directories (
|
||||
${Qt5Widgets_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
link_directories (
|
||||
)
|
||||
|
||||
|
||||
#=======================================
|
||||
# Subdirectories
|
||||
#=======================================
|
||||
|
||||
|
||||
#=======================================
|
||||
# Install
|
||||
#=======================================
|
||||
@@ -1,224 +0,0 @@
|
||||
/* Merge/Factory.cpp
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Factory.h"
|
||||
|
||||
#include "None.h"
|
||||
#include "TextCsv.h"
|
||||
#include "TextCsvKeys.h"
|
||||
#include "TextTsv.h"
|
||||
#include "TextTsvKeys.h"
|
||||
#include "TextColon.h"
|
||||
#include "TextColonKeys.h"
|
||||
#include "TextSemicolon.h"
|
||||
#include "TextSemicolonKeys.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
|
||||
//
|
||||
// Static data
|
||||
//
|
||||
QMap<QString,Factory::BackendEntry> Factory::mBackendIdMap;
|
||||
QMap<QString,Factory::BackendEntry> Factory::mBackendNameMap;
|
||||
QStringList Factory::mNameList;
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
Factory::Factory()
|
||||
{
|
||||
registerBackend( None::id(),
|
||||
tr("None"),
|
||||
NONE,
|
||||
&None::create );
|
||||
|
||||
registerBackend( TextCsv::id(),
|
||||
tr("Text: Comma Separated Values (CSV)"),
|
||||
FILE,
|
||||
&TextCsv::create );
|
||||
|
||||
registerBackend( TextCsvKeys::id(),
|
||||
tr("Text: Comma Separated Values (CSV), keys on line 1"),
|
||||
FILE,
|
||||
&TextCsvKeys::create );
|
||||
|
||||
registerBackend( TextTsv::id(),
|
||||
tr("Text: Tab Separated Values (TSV)"),
|
||||
FILE,
|
||||
&TextTsv::create );
|
||||
|
||||
registerBackend( TextTsvKeys::id(),
|
||||
tr("Text: Tab Separated Values (TSV), keys on line 1"),
|
||||
FILE,
|
||||
&TextTsvKeys::create );
|
||||
|
||||
registerBackend( TextColon::id(),
|
||||
tr("Text: Colon Separated Values"),
|
||||
FILE,
|
||||
&TextColon::create );
|
||||
|
||||
registerBackend( TextColonKeys::id(),
|
||||
tr("Text: Colon Separated Values, keys on line 1"),
|
||||
FILE,
|
||||
&TextColonKeys::create );
|
||||
|
||||
registerBackend( TextSemicolon::id(),
|
||||
tr("Text: Semicolon Separated Values"),
|
||||
FILE,
|
||||
&TextSemicolon::create );
|
||||
|
||||
registerBackend( TextSemicolonKeys::id(),
|
||||
tr("Text: Semicolon Separated Values, keys on line 1"),
|
||||
FILE,
|
||||
&TextSemicolonKeys::create );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Initialize
|
||||
///
|
||||
void Factory::init()
|
||||
{
|
||||
static Factory* singletonInstance = nullptr;
|
||||
if ( !singletonInstance )
|
||||
{
|
||||
singletonInstance = new Factory();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Create Merge object
|
||||
///
|
||||
Merge* Factory::createMerge( const QString& id )
|
||||
{
|
||||
QMap<QString,BackendEntry>::iterator iBackend = mBackendIdMap.find( id );
|
||||
if ( iBackend != mBackendIdMap.end() )
|
||||
{
|
||||
return iBackend->create();
|
||||
}
|
||||
|
||||
return None::create();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get name list
|
||||
///
|
||||
QStringList Factory::nameList()
|
||||
{
|
||||
return mNameList;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Convert ID to name
|
||||
///
|
||||
QString Factory::idToName( const QString& id )
|
||||
{
|
||||
if ( mBackendIdMap.contains( id ) )
|
||||
{
|
||||
return mBackendIdMap[id].name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return tr("None");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Convert name to ID
|
||||
///
|
||||
QString Factory::nameToId( const QString& name )
|
||||
{
|
||||
if ( mBackendNameMap.contains( name ) )
|
||||
{
|
||||
return mBackendNameMap[name].id;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "None";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Convert ID to type
|
||||
///
|
||||
Factory::SourceType Factory::idToType( const QString& id )
|
||||
{
|
||||
if ( mBackendIdMap.contains( id ) )
|
||||
{
|
||||
return mBackendIdMap[id].type;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Lookup ID from index
|
||||
///
|
||||
QString Factory::indexToId( int index )
|
||||
{
|
||||
if ( (index > 0) && (index < mNameList.size()) )
|
||||
{
|
||||
QString name = mNameList[index];
|
||||
|
||||
return mBackendNameMap[ name ].id;
|
||||
}
|
||||
|
||||
return "None";
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Register backend
|
||||
///
|
||||
void Factory::registerBackend( const QString& id,
|
||||
const QString& name,
|
||||
SourceType type,
|
||||
CreateFct create )
|
||||
{
|
||||
BackendEntry backend;
|
||||
|
||||
backend.id = id;
|
||||
backend.name = name;
|
||||
backend.type = type;
|
||||
backend.create = create;
|
||||
|
||||
mBackendIdMap[ id ] = backend;
|
||||
mBackendNameMap[ name ] = backend;
|
||||
|
||||
mNameList << name;
|
||||
}
|
||||
|
||||
} // namespace merge
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,112 +0,0 @@
|
||||
/* Merge/Factory.h
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef merge_Factory_h
|
||||
#define merge_Factory_h
|
||||
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QStringList>
|
||||
#include <QMap>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
|
||||
// Forward references
|
||||
class Merge;
|
||||
|
||||
|
||||
///
|
||||
/// Factory
|
||||
///
|
||||
class Factory
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Factory)
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Source Type
|
||||
/////////////////////////////////
|
||||
public:
|
||||
enum SourceType { NONE, FIXED, FILE };
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
protected:
|
||||
Factory();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Static methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
static void init();
|
||||
|
||||
static Merge* createMerge( const QString& id );
|
||||
|
||||
static QStringList nameList();
|
||||
static QString idToName( const QString& id );
|
||||
static QString nameToId( const QString& name );
|
||||
static SourceType idToType( const QString& id );
|
||||
static QString indexToId( int index );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// private methods
|
||||
/////////////////////////////////
|
||||
private:
|
||||
typedef Merge* (*CreateFct)();
|
||||
|
||||
static void registerBackend( const QString& id,
|
||||
const QString& name,
|
||||
SourceType type,
|
||||
CreateFct create );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// private data
|
||||
/////////////////////////////////
|
||||
class BackendEntry
|
||||
{
|
||||
public:
|
||||
QString id;
|
||||
QString name;
|
||||
SourceType type;
|
||||
CreateFct create;
|
||||
};
|
||||
|
||||
static QMap<QString,BackendEntry> mBackendIdMap;
|
||||
static QMap<QString,BackendEntry> mBackendNameMap;
|
||||
|
||||
static QStringList mNameList;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // merge_Factory_h
|
||||
@@ -1,215 +0,0 @@
|
||||
/* Merge/Merge.cpp
|
||||
*
|
||||
* Copyright (C) 2015-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Merge.h"
|
||||
|
||||
#include "Record.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
Merge::Merge()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
Merge::Merge( const Merge* merge ) : mSource(merge->mSource)
|
||||
{
|
||||
foreach ( Record* record, merge->mRecordList )
|
||||
{
|
||||
mRecordList << record->clone();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
Merge::~Merge()
|
||||
{
|
||||
foreach ( Record* record, mRecordList )
|
||||
{
|
||||
delete record;
|
||||
}
|
||||
mRecordList.clear();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get id
|
||||
///
|
||||
QString Merge::id() const
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get source
|
||||
///
|
||||
QString Merge::source() const
|
||||
{
|
||||
return mSource;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set source
|
||||
///
|
||||
void Merge::setSource( const QString& source )
|
||||
{
|
||||
mSource = source;
|
||||
|
||||
// Clear out any old records
|
||||
foreach ( Record* record, mRecordList )
|
||||
{
|
||||
delete record;
|
||||
}
|
||||
mRecordList.clear();
|
||||
|
||||
open();
|
||||
for ( Record* record = readNextRecord(); record != nullptr; record = readNextRecord() )
|
||||
{
|
||||
mRecordList.append( record );
|
||||
}
|
||||
close();
|
||||
|
||||
emit sourceChanged();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get record list
|
||||
///
|
||||
const QList<Record*>& Merge::recordList( ) const
|
||||
{
|
||||
return mRecordList;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Select matching record
|
||||
///
|
||||
void Merge::select( Record* record )
|
||||
{
|
||||
record->setSelected( true );
|
||||
emit selectionChanged();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Unselect matching record
|
||||
///
|
||||
void Merge::unselect( Record* record )
|
||||
{
|
||||
record->setSelected( false );
|
||||
emit selectionChanged();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Select/unselect i'th record
|
||||
///
|
||||
void Merge::setSelected( int i, bool state )
|
||||
{
|
||||
if ( (i >= 0) && (i < mRecordList.size()) )
|
||||
{
|
||||
mRecordList[i]->setSelected( state );
|
||||
emit selectionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Select all records
|
||||
///
|
||||
void Merge::selectAll()
|
||||
{
|
||||
foreach ( Record* record, mRecordList )
|
||||
{
|
||||
record->setSelected( true );
|
||||
}
|
||||
emit selectionChanged();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Unselect all records
|
||||
///
|
||||
void Merge::unselectAll()
|
||||
{
|
||||
foreach ( Record* record, mRecordList )
|
||||
{
|
||||
record->setSelected( false );
|
||||
}
|
||||
emit selectionChanged();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Return count of selected records
|
||||
///
|
||||
int Merge::nSelectedRecords() const
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
foreach ( Record* record, mRecordList )
|
||||
{
|
||||
if ( record->isSelected() )
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Return list of selected records
|
||||
///
|
||||
const QList<Record*> Merge::selectedRecords() const
|
||||
{
|
||||
QList<Record*> list;
|
||||
|
||||
foreach ( Record* record, mRecordList )
|
||||
{
|
||||
if ( record->isSelected() )
|
||||
{
|
||||
list.append( record );
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
} // namespace merge
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,125 +0,0 @@
|
||||
/* Merge/Merge.h
|
||||
*
|
||||
* Copyright (C) 2015-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef merge_Merge_h
|
||||
#define merge_Merge_h
|
||||
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QList>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
|
||||
// Forward references
|
||||
class Record;
|
||||
|
||||
|
||||
///
|
||||
/// Merge Object
|
||||
///
|
||||
struct Merge : QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
protected:
|
||||
Merge();
|
||||
Merge( const Merge* merge );
|
||||
public:
|
||||
~Merge() override;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Object duplication
|
||||
/////////////////////////////////
|
||||
virtual Merge* clone() const = 0;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
QString id() const;
|
||||
QString source() const;
|
||||
void setSource( const QString& source );
|
||||
|
||||
const QList<Record*>& recordList( void ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Selection methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void select( Record* record );
|
||||
void unselect( Record* record );
|
||||
void setSelected( int i, bool state = true );
|
||||
void selectAll();
|
||||
void unselectAll();
|
||||
|
||||
int nSelectedRecords() const;
|
||||
const QList<Record*> selectedRecords() const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Virtual methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
virtual QStringList keys() const = 0;
|
||||
virtual QString primaryKey() const = 0;
|
||||
protected:
|
||||
virtual void open() = 0;
|
||||
virtual void close() = 0;
|
||||
virtual Record* readNextRecord() = 0;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Signals
|
||||
/////////////////////////////////
|
||||
signals:
|
||||
void sourceChanged();
|
||||
void selectionChanged();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private data
|
||||
/////////////////////////////////
|
||||
protected:
|
||||
QString mId;
|
||||
private:
|
||||
QString mSource;
|
||||
QList<Record*> mRecordList;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // merge_Merge_h
|
||||
@@ -1,127 +0,0 @@
|
||||
/* Merge/None.cpp
|
||||
*
|
||||
* Copyright (C) 2015-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "None.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
None::None() : Merge()
|
||||
{
|
||||
mId = "None";
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
None::None( const None* merge ) : Merge( merge )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
None::~None()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
None* None::clone() const
|
||||
{
|
||||
return new None( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get ID
|
||||
///
|
||||
QString None::id()
|
||||
{
|
||||
return "None";
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Create
|
||||
///
|
||||
Merge* None::create()
|
||||
{
|
||||
return new None();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get key list
|
||||
///
|
||||
QStringList None::keys() const
|
||||
{
|
||||
QStringList emptyList;
|
||||
return emptyList;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get primary key
|
||||
///
|
||||
QString None::primaryKey() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Open source
|
||||
///
|
||||
void None::open()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Close source
|
||||
///
|
||||
void None::close()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Read next record
|
||||
///
|
||||
Record* None::readNextRecord()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace merge
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,80 +0,0 @@
|
||||
/* Merge/None.h
|
||||
*
|
||||
* Copyright (C) 2015-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef merge_None_h
|
||||
#define merge_None_h
|
||||
|
||||
#include "Merge.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
|
||||
///
|
||||
/// None Merge Backend
|
||||
///
|
||||
struct None : public Merge
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
None();
|
||||
None( const None* merge );
|
||||
~None() override;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Object duplication
|
||||
/////////////////////////////////
|
||||
None* clone() const override;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Static methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
static QString id();
|
||||
static Merge* create();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Implementation of virtual methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
QStringList keys() const override;
|
||||
QString primaryKey() const override;
|
||||
protected:
|
||||
void open() override;
|
||||
void close() override;
|
||||
Record* readNextRecord() override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // merge_None_h
|
||||
@@ -1,75 +0,0 @@
|
||||
/* Merge/Record.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Record.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
Record::Record() : mSelected( true )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
Record::Record( const Record* record )
|
||||
: QMap<QString,QString>(*record), mSelected(record->mSelected)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
Record* Record::clone() const
|
||||
{
|
||||
return new Record( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Is record selected?
|
||||
///
|
||||
bool Record::isSelected() const
|
||||
{
|
||||
return mSelected;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set selected on not selected
|
||||
///
|
||||
void Record::setSelected( bool value )
|
||||
{
|
||||
mSelected = value;
|
||||
}
|
||||
|
||||
} // namespace merge
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,76 +0,0 @@
|
||||
/* Merge/Record.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef merge_Record_h
|
||||
#define merge_Record_h
|
||||
|
||||
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
|
||||
///
|
||||
/// Merge Record
|
||||
///
|
||||
struct Record : public QMap<QString,QString>
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
Record();
|
||||
Record( const Record* record );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Object duplication
|
||||
/////////////////////////////////
|
||||
Record* clone() const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
bool isSelected() const;
|
||||
void setSelected( bool value );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
bool mSelected;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // merge_Record_h
|
||||
@@ -1,421 +0,0 @@
|
||||
/* Merge/Text.cpp
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Text.h"
|
||||
|
||||
#include "Record.h"
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
Text::Text( QChar delimiter, bool line1HasKeys )
|
||||
: mDelimeter(delimiter), mLine1HasKeys(line1HasKeys), mNFieldsMax(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
Text::Text( const Text* merge )
|
||||
: Merge( merge ),
|
||||
mDelimeter(merge->mDelimeter), mLine1HasKeys(merge->mLine1HasKeys),
|
||||
mNFieldsMax(merge->mNFieldsMax)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
Text::~Text()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get key list
|
||||
///
|
||||
QStringList Text::keys() const
|
||||
{
|
||||
QStringList keys;
|
||||
for ( int iField = 0; iField < mNFieldsMax; iField++ )
|
||||
{
|
||||
keys << keyFromIndex(iField);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get primary key
|
||||
///
|
||||
QString Text::primaryKey() const
|
||||
{
|
||||
return keyFromIndex(0);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Open source
|
||||
///
|
||||
void Text::open()
|
||||
{
|
||||
mFile.setFileName( source() );
|
||||
mFile.open( QIODevice::ReadOnly|QIODevice::Text );
|
||||
|
||||
mKeys.clear();
|
||||
mNFieldsMax = 0;
|
||||
|
||||
if ( mLine1HasKeys && mFile.isOpen() )
|
||||
{
|
||||
mKeys = parseLine();
|
||||
if ( (mKeys.size() == 1) && (mKeys[0] == "") )
|
||||
{
|
||||
mKeys.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
mNFieldsMax = mKeys.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Close source
|
||||
///
|
||||
void Text::close()
|
||||
{
|
||||
if ( mFile.isOpen() )
|
||||
{
|
||||
mFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Read next record
|
||||
///
|
||||
Record* Text::readNextRecord()
|
||||
{
|
||||
QStringList values = parseLine();
|
||||
if ( !values.isEmpty() )
|
||||
{
|
||||
Record* record = new Record();
|
||||
|
||||
int iField = 0;
|
||||
foreach ( QString value, values )
|
||||
{
|
||||
(*record)[ keyFromIndex(iField) ] = value;
|
||||
iField++;
|
||||
}
|
||||
mNFieldsMax = std::max( mNFieldsMax, iField );
|
||||
|
||||
return record;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Key from field index
|
||||
///
|
||||
QString Text::keyFromIndex( int iField ) const
|
||||
{
|
||||
if ( mLine1HasKeys && ( iField < mKeys.size() ) )
|
||||
{
|
||||
return mKeys[iField];
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString::number( iField+1 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Parse line.
|
||||
///
|
||||
/// Attempt to be a robust parser of various CSV (and similar) formats.
|
||||
///
|
||||
/// Based on CSV format described in RFC 4180 section 2.
|
||||
///
|
||||
/// Additions to RFC 4180 rules:
|
||||
/// - delimeters and other special characters may be "escaped" by a leading
|
||||
/// backslash (\)
|
||||
/// - C escape sequences for newline (\n) and tab (\t) are also translated.
|
||||
/// - if quoted text is not followed by a delimeter, any additional text is
|
||||
/// concatenated with quoted portion.
|
||||
///
|
||||
/// Returns a list of fields. A blank line is considered a line with one
|
||||
/// empty field. Returns an empty list when done.
|
||||
///
|
||||
QStringList Text::parseLine()
|
||||
{
|
||||
QStringList fields;
|
||||
|
||||
enum State
|
||||
{
|
||||
DELIM, QUOTED, QUOTED_QUOTE1, QUOTED_ESCAPED, SIMPLE, SIMPLE_ESCAPED, DONE
|
||||
} state = DELIM;
|
||||
|
||||
QByteArray field;
|
||||
|
||||
while ( state != DONE )
|
||||
{
|
||||
char c;
|
||||
if ( mFile.getChar( &c ) )
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
|
||||
case DELIM:
|
||||
switch (c)
|
||||
{
|
||||
case '\n':
|
||||
/* last field is empty. */
|
||||
fields << "";
|
||||
state = DONE;
|
||||
break;
|
||||
case '\r':
|
||||
/* ignore */
|
||||
state = DELIM;
|
||||
break;
|
||||
case '"':
|
||||
/* start a quoted field. */
|
||||
state = QUOTED;
|
||||
break;
|
||||
case '\\':
|
||||
/* simple field, but 1st character is an escape. */
|
||||
state = SIMPLE_ESCAPED;
|
||||
break;
|
||||
default:
|
||||
if ( c == mDelimeter )
|
||||
{
|
||||
/* field is empty. */
|
||||
fields << "";
|
||||
state = DELIM;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* begining of a simple field. */
|
||||
field.append( c );
|
||||
state = SIMPLE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case QUOTED:
|
||||
switch (c)
|
||||
{
|
||||
case '"':
|
||||
/* Possible end of field, but could be 1st of a pair. */
|
||||
state = QUOTED_QUOTE1;
|
||||
break;
|
||||
case '\\':
|
||||
/* Escape next character, or special escape, e.g. \n. */
|
||||
state = QUOTED_ESCAPED;
|
||||
break;
|
||||
default:
|
||||
/* Use character literally. */
|
||||
field.append( c );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case QUOTED_QUOTE1:
|
||||
switch (c)
|
||||
{
|
||||
case '\n':
|
||||
/* line ended after quoted item */
|
||||
fields << QString( field );
|
||||
state = DONE;
|
||||
break;
|
||||
case '"':
|
||||
/* second quote, insert and stay quoted. */
|
||||
field.append( c );
|
||||
state = QUOTED;
|
||||
break;
|
||||
case '\r':
|
||||
/* ignore and go to fallback */
|
||||
state = SIMPLE;
|
||||
break;
|
||||
default:
|
||||
if ( c == mDelimeter )
|
||||
{
|
||||
/* end of field. */
|
||||
fields << QString( field );
|
||||
field.clear();
|
||||
state = DELIM;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* fallback if not a delim or another quote. */
|
||||
field.append( c );
|
||||
state = SIMPLE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case QUOTED_ESCAPED:
|
||||
switch (c)
|
||||
{
|
||||
case 'n':
|
||||
/* Decode "\n" as newline. */
|
||||
field.append( '\n' );
|
||||
state = QUOTED;
|
||||
break;
|
||||
case 't':
|
||||
/* Decode "\t" as tab. */
|
||||
field.append( '\t' );
|
||||
state = QUOTED;
|
||||
break;
|
||||
default:
|
||||
/* Use character literally. */
|
||||
field.append( c );
|
||||
state = QUOTED;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case SIMPLE:
|
||||
switch (c)
|
||||
{
|
||||
case '\n':
|
||||
/* line ended */
|
||||
fields << QString( field );
|
||||
state = DONE;
|
||||
break;
|
||||
case '\r':
|
||||
/* ignore */
|
||||
state = SIMPLE;
|
||||
break;
|
||||
case '\\':
|
||||
/* Escape next character, or special escape, e.g. \n. */
|
||||
state = SIMPLE_ESCAPED;
|
||||
break;
|
||||
default:
|
||||
if ( c == mDelimeter )
|
||||
{
|
||||
/* end of field. */
|
||||
fields << QString( field );
|
||||
field.clear();
|
||||
state = DELIM;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Use character literally. */
|
||||
field.append( c );
|
||||
state = SIMPLE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case SIMPLE_ESCAPED:
|
||||
switch (c)
|
||||
{
|
||||
case 'n':
|
||||
/* Decode "\n" as newline. */
|
||||
field.append( '\n' );
|
||||
state = SIMPLE;
|
||||
break;
|
||||
case 't':
|
||||
/* Decode "\t" as tab. */
|
||||
field.append( '\t' );
|
||||
state = SIMPLE;
|
||||
break;
|
||||
default:
|
||||
/* Use character literally. */
|
||||
field.append( (char)c );
|
||||
state = SIMPLE;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
qWarning( "merge::Text::parseLine()::Should not be reached! #1" );
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Handle EOF (could also be an error while reading). */
|
||||
switch (state)
|
||||
{
|
||||
|
||||
case DELIM:
|
||||
/* EOF, no more lines. */
|
||||
break;
|
||||
|
||||
case QUOTED:
|
||||
/* File ended midway through quoted item. Truncate field. */
|
||||
fields << QString( field );
|
||||
break;
|
||||
|
||||
case QUOTED_QUOTE1:
|
||||
/* File ended after quoted item. */
|
||||
fields << QString( field );
|
||||
break;
|
||||
|
||||
case QUOTED_ESCAPED:
|
||||
/* File ended midway through quoted item. Truncate field. */
|
||||
fields << QString( field );
|
||||
break;
|
||||
|
||||
case SIMPLE:
|
||||
/* File ended after simple item. */
|
||||
fields << QString( field );
|
||||
break;
|
||||
|
||||
case SIMPLE_ESCAPED:
|
||||
/* File ended midway through escaped item. */
|
||||
fields << QString( field );
|
||||
break;
|
||||
|
||||
default:
|
||||
qWarning( "merge::Text::parseLine()::Should not be reached! #2" );
|
||||
break;
|
||||
}
|
||||
|
||||
state = DONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
} // namespace merge
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,86 +0,0 @@
|
||||
/* Merge/Text.h
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef merge_Text_h
|
||||
#define merge_Text_h
|
||||
|
||||
#include "Merge.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
|
||||
///
|
||||
/// Text Merge Backend
|
||||
///
|
||||
struct Text : public Merge
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
protected:
|
||||
Text( QChar delimiter, bool line1HasKeys );
|
||||
Text( const Text* merge );
|
||||
~Text() override;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Implementation of virtual methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
QStringList keys() const override;
|
||||
QString primaryKey() const override;
|
||||
protected:
|
||||
void open() override;
|
||||
void close() override;
|
||||
Record* readNextRecord() override;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private methods
|
||||
/////////////////////////////////
|
||||
QString keyFromIndex( int iField ) const;
|
||||
QStringList parseLine();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
QChar mDelimeter;
|
||||
bool mLine1HasKeys;
|
||||
|
||||
QFile mFile;
|
||||
QStringList mKeys;
|
||||
int mNFieldsMax;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // merge_Text_h
|
||||
@@ -1,85 +0,0 @@
|
||||
/* Merge/TextColon.cpp
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "TextColon.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
static const QString ID = "Text/Colon";
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
TextColon::TextColon() : Text(':',false)
|
||||
{
|
||||
mId = ID;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
TextColon::TextColon( const TextColon* merge ) : Text( merge )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
TextColon::~TextColon()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
TextColon* TextColon::clone() const
|
||||
{
|
||||
return new TextColon( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get ID
|
||||
///
|
||||
QString TextColon::id()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Create
|
||||
///
|
||||
Merge* TextColon::create()
|
||||
{
|
||||
return new TextColon();
|
||||
}
|
||||
|
||||
} // namespace merge
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,70 +0,0 @@
|
||||
/* Merge/TextColon.h
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef merge_TextColon_h
|
||||
#define merge_TextColon_h
|
||||
|
||||
|
||||
#include "Text.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
|
||||
///
|
||||
/// TextColon Merge Backend
|
||||
///
|
||||
struct TextColon : public Text
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
private:
|
||||
TextColon();
|
||||
TextColon( const TextColon* merge );
|
||||
~TextColon() override;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Object duplication
|
||||
/////////////////////////////////
|
||||
public:
|
||||
TextColon* clone() const override;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Static methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
static QString id();
|
||||
static Merge* create();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // merge_TextColon_h
|
||||
@@ -1,85 +0,0 @@
|
||||
/* Merge/TextColonKeys.cpp
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "TextColonKeys.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
static const QString ID = "Text/Colon/Line1Keys";
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
TextColonKeys::TextColonKeys() : Text(':',true)
|
||||
{
|
||||
mId = ID;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
TextColonKeys::TextColonKeys( const TextColonKeys* merge ) : Text( merge )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
TextColonKeys::~TextColonKeys()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
TextColonKeys* TextColonKeys::clone() const
|
||||
{
|
||||
return new TextColonKeys( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get ID
|
||||
///
|
||||
QString TextColonKeys::id()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Create
|
||||
///
|
||||
Merge* TextColonKeys::create()
|
||||
{
|
||||
return new TextColonKeys();
|
||||
}
|
||||
|
||||
} // namespace merge
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,70 +0,0 @@
|
||||
/* Merge/TextColonKeys.h
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef merge_TextColonKeys_h
|
||||
#define merge_TextColonKeys_h
|
||||
|
||||
|
||||
#include "Text.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
|
||||
///
|
||||
/// TextColonKeys Merge Backend
|
||||
///
|
||||
struct TextColonKeys : public Text
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
private:
|
||||
TextColonKeys();
|
||||
TextColonKeys( const TextColonKeys* merge );
|
||||
~TextColonKeys() override;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Object duplication
|
||||
/////////////////////////////////
|
||||
public:
|
||||
TextColonKeys* clone() const override;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Static methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
static QString id();
|
||||
static Merge* create();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // merge_TextColonKeys_h
|
||||
@@ -1,85 +0,0 @@
|
||||
/* Merge/TextCsv.cpp
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "TextCsv.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
static const QString ID = "Text/Comma";
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
TextCsv::TextCsv() : Text(',',false)
|
||||
{
|
||||
mId = ID;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
TextCsv::TextCsv( const TextCsv* merge ) : Text( merge )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
TextCsv::~TextCsv()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
TextCsv* TextCsv::clone() const
|
||||
{
|
||||
return new TextCsv( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get ID
|
||||
///
|
||||
QString TextCsv::id()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Create
|
||||
///
|
||||
Merge* TextCsv::create()
|
||||
{
|
||||
return new TextCsv();
|
||||
}
|
||||
|
||||
} // namespace merge
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,70 +0,0 @@
|
||||
/* Merge/TextCsv.h
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef merge_TextCsv_h
|
||||
#define merge_TextCsv_h
|
||||
|
||||
|
||||
#include "Text.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
|
||||
///
|
||||
/// TextCsv Merge Backend
|
||||
///
|
||||
struct TextCsv : public Text
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
private:
|
||||
TextCsv();
|
||||
TextCsv( const TextCsv* merge );
|
||||
~TextCsv() override;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Object duplication
|
||||
/////////////////////////////////
|
||||
public:
|
||||
TextCsv* clone() const override;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Static methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
static QString id();
|
||||
static Merge* create();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // merge_TextCsv_h
|
||||
@@ -1,85 +0,0 @@
|
||||
/* Merge/TextCsvKeys.cpp
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "TextCsvKeys.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
static const QString ID = "Text/Comma/Line1Keys";
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
TextCsvKeys::TextCsvKeys() : Text(',',true)
|
||||
{
|
||||
mId = ID;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
TextCsvKeys::TextCsvKeys( const TextCsvKeys* merge ) : Text( merge )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
TextCsvKeys::~TextCsvKeys()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
TextCsvKeys* TextCsvKeys::clone() const
|
||||
{
|
||||
return new TextCsvKeys( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get ID
|
||||
///
|
||||
QString TextCsvKeys::id()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Create
|
||||
///
|
||||
Merge* TextCsvKeys::create()
|
||||
{
|
||||
return new TextCsvKeys();
|
||||
}
|
||||
|
||||
} // namespace merge
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,70 +0,0 @@
|
||||
/* Merge/TextCsvKeys.h
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef merge_TextCsvKeys_h
|
||||
#define merge_TextCsvKeys_h
|
||||
|
||||
|
||||
#include "Text.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
|
||||
///
|
||||
/// TextCsvKeys Merge Backend
|
||||
///
|
||||
struct TextCsvKeys : public Text
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
private:
|
||||
TextCsvKeys();
|
||||
TextCsvKeys( const TextCsvKeys* merge );
|
||||
~TextCsvKeys() override;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Object duplication
|
||||
/////////////////////////////////
|
||||
public:
|
||||
TextCsvKeys* clone() const override;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Static methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
static QString id();
|
||||
static Merge* create();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // merge_TextCsvKeys_h
|
||||
@@ -1,85 +0,0 @@
|
||||
/* Merge/TextSemicolon.cpp
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "TextSemicolon.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
static const QString ID = "Text/Semicolon";
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
TextSemicolon::TextSemicolon() : Text(';',false)
|
||||
{
|
||||
mId = ID;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
TextSemicolon::TextSemicolon( const TextSemicolon* merge ) : Text( merge )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
TextSemicolon::~TextSemicolon()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
TextSemicolon* TextSemicolon::clone() const
|
||||
{
|
||||
return new TextSemicolon( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get ID
|
||||
///
|
||||
QString TextSemicolon::id()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Create
|
||||
///
|
||||
Merge* TextSemicolon::create()
|
||||
{
|
||||
return new TextSemicolon();
|
||||
}
|
||||
|
||||
} // namespace merge
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,70 +0,0 @@
|
||||
/* Merge/TextSemicolon.h
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef merge_TextSemicolon_h
|
||||
#define merge_TextSemicolon_h
|
||||
|
||||
|
||||
#include "Text.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
|
||||
///
|
||||
/// TextSemicolon Merge Backend
|
||||
///
|
||||
struct TextSemicolon : public Text
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
private:
|
||||
TextSemicolon();
|
||||
TextSemicolon( const TextSemicolon* merge );
|
||||
~TextSemicolon() override;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Object duplication
|
||||
/////////////////////////////////
|
||||
public:
|
||||
TextSemicolon* clone() const override;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Static methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
static QString id();
|
||||
static Merge* create();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // merge_TextSemicolon_h
|
||||
@@ -1,85 +0,0 @@
|
||||
/* Merge/TextSemicolonKeys.cpp
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "TextSemicolonKeys.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
static const QString ID = "Text/Semicolon/Keys";
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
TextSemicolonKeys::TextSemicolonKeys() : Text(';',true)
|
||||
{
|
||||
mId = ID;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
TextSemicolonKeys::TextSemicolonKeys( const TextSemicolonKeys* merge ) : Text( merge )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
TextSemicolonKeys::~TextSemicolonKeys()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
TextSemicolonKeys* TextSemicolonKeys::clone() const
|
||||
{
|
||||
return new TextSemicolonKeys( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get ID
|
||||
///
|
||||
QString TextSemicolonKeys::id()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Create
|
||||
///
|
||||
Merge* TextSemicolonKeys::create()
|
||||
{
|
||||
return new TextSemicolonKeys();
|
||||
}
|
||||
|
||||
} // namespace merge
|
||||
|
||||
} // namespace glabels
|
||||
@@ -1,70 +0,0 @@
|
||||
/* Merge/TextSemicolonKeys.h
|
||||
*
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef merge_TextSemicolonKeys_h
|
||||
#define merge_TextSemicolonKeys_h
|
||||
|
||||
|
||||
#include "Text.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace merge
|
||||
{
|
||||
|
||||
///
|
||||
/// TextSemicolonKeys Merge Backend
|
||||
///
|
||||
struct TextSemicolonKeys : public Text
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
private:
|
||||
TextSemicolonKeys();
|
||||
TextSemicolonKeys( const TextSemicolonKeys* merge );
|
||||
~TextSemicolonKeys() override;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Object duplication
|
||||
/////////////////////////////////
|
||||
public:
|
||||
TextSemicolonKeys* clone() const override;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Static methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
static QString id();
|
||||
static Merge* create();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // merge_TextSemicolonKeys_h
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user