Some reorganization of source tree.
- Merged libglabels back into glabels. - Created docs directory. - Adjusted COPYING files to reflect above changes.
This commit is contained in:
+24
-1
@@ -10,6 +10,7 @@ project (app CXX)
|
||||
# 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)
|
||||
|
||||
|
||||
#=======================================
|
||||
@@ -23,6 +24,7 @@ set (glabels_sources
|
||||
BarcodeMenuButton.cpp
|
||||
BarcodeMenuItem.cpp
|
||||
BarcodeStyle.cpp
|
||||
Category.cpp
|
||||
ColorButton.cpp
|
||||
ColorHistory.cpp
|
||||
ColorNode.cpp
|
||||
@@ -31,10 +33,17 @@ set (glabels_sources
|
||||
ColorPaletteButtonItem.cpp
|
||||
ColorSwatch.cpp
|
||||
Cursors.cpp
|
||||
Db.cpp
|
||||
Distance.cpp
|
||||
EnumUtil.cpp
|
||||
FieldButton.cpp
|
||||
File.cpp
|
||||
FileUtil.cpp
|
||||
Frame.cpp
|
||||
FrameCd.cpp
|
||||
FrameEllipse.cpp
|
||||
FrameRect.cpp
|
||||
FrameRound.cpp
|
||||
Handles.cpp
|
||||
Help.cpp
|
||||
Icons.cpp
|
||||
@@ -47,11 +56,16 @@ set (glabels_sources
|
||||
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
|
||||
@@ -63,12 +77,22 @@ set (glabels_sources
|
||||
SimplePreview.cpp
|
||||
Size.cpp
|
||||
StartupView.cpp
|
||||
StrUtil.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
|
||||
@@ -138,7 +162,6 @@ add_executable (glabels-qt
|
||||
|
||||
target_link_libraries (glabels-qt
|
||||
Merge
|
||||
libglabels
|
||||
${Qt5Widgets_LIBRARIES}
|
||||
${Qt5PrintSupport_LIBRARIES}
|
||||
${Qt5Xml_LIBRARIES}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/* 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QString Category::id() const
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
|
||||
|
||||
QString Category::name() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/* 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
|
||||
@@ -0,0 +1,36 @@
|
||||
/* 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_qt_SOURCE_DIR@";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_Config_h
|
||||
@@ -0,0 +1,36 @@
|
||||
/* 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;
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_Constants_h
|
||||
+702
@@ -0,0 +1,702 @@
|
||||
/* 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 <QApplication>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "Config.h"
|
||||
#include "StrUtil.h"
|
||||
#include "XmlCategoryParser.h"
|
||||
#include "XmlPaperParser.h"
|
||||
#include "XmlTemplateParser.h"
|
||||
#include "XmlVendorParser.h"
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
bool partNameLessThan( const glabels::Template *a, const glabels::Template *b )
|
||||
{
|
||||
return glabels::StrUtil::comparePartNames( a->name(), b->name() ) < 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
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;
|
||||
QString Db::mEmpty = "";
|
||||
|
||||
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 NULL;
|
||||
}
|
||||
|
||||
|
||||
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 NULL;
|
||||
}
|
||||
|
||||
|
||||
QString Db::lookupPaperIdFromName( const QString& name )
|
||||
{
|
||||
if ( !name.isNull() && !name.isEmpty() )
|
||||
{
|
||||
const Paper *paper = lookupPaperFromName( name );
|
||||
if ( paper != NULL )
|
||||
{
|
||||
return paper->id();
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unknown paper name: " << name;
|
||||
return mEmpty;
|
||||
}
|
||||
|
||||
|
||||
QString Db::lookupPaperNameFromId( const QString& id )
|
||||
{
|
||||
if ( !id.isNull() && !id.isEmpty() )
|
||||
{
|
||||
if ( isPaperIdOther( id ) )
|
||||
{
|
||||
return mPaperNameOther;
|
||||
}
|
||||
|
||||
const Paper *paper = lookupPaperFromId( id );
|
||||
if ( paper != NULL )
|
||||
{
|
||||
return paper->name();
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unknown paper id: " << id;
|
||||
return mEmpty;
|
||||
}
|
||||
|
||||
|
||||
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 NULL;
|
||||
}
|
||||
|
||||
|
||||
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 NULL;
|
||||
}
|
||||
|
||||
|
||||
QString Db::lookupCategoryIdFromName( const QString& name )
|
||||
{
|
||||
if ( !name.isNull() && !name.isEmpty() )
|
||||
{
|
||||
const Category *category = lookupCategoryFromName( name );
|
||||
if ( category != NULL )
|
||||
{
|
||||
return category->id();
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unknown category name: " << name;
|
||||
return mEmpty;
|
||||
}
|
||||
|
||||
|
||||
QString Db::lookupCategoryNameFromId( const QString& id )
|
||||
{
|
||||
if ( !id.isNull() && !id.isEmpty() )
|
||||
{
|
||||
const Category *category = lookupCategoryFromId( id );
|
||||
if ( category != NULL )
|
||||
{
|
||||
return category->name();
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unknown category id: " << id;
|
||||
return mEmpty;
|
||||
}
|
||||
|
||||
|
||||
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 NULL;
|
||||
}
|
||||
|
||||
|
||||
QString Db::lookupVendorUrlFromName( const QString& name )
|
||||
{
|
||||
if ( !name.isNull() && !name.isEmpty() )
|
||||
{
|
||||
const Vendor *vendor = lookupVendorFromName( name );
|
||||
if ( vendor != NULL )
|
||||
{
|
||||
return vendor->url();
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unknown vendor name: " << name;
|
||||
return mEmpty;
|
||||
}
|
||||
|
||||
|
||||
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() ) )
|
||||
{
|
||||
tmplate->initPreview();
|
||||
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 NULL;
|
||||
}
|
||||
|
||||
|
||||
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 NULL;
|
||||
}
|
||||
|
||||
|
||||
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 == NULL )
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
QDir Db::systemTemplatesDir()
|
||||
{
|
||||
QDir dir(QApplication::applicationDirPath());
|
||||
|
||||
if ( dir.dirName() == "bin" )
|
||||
{
|
||||
dir.cdUp();
|
||||
dir.cd( "share" );
|
||||
dir.cd( "libglabels-3.0" ); // TODO: install qt version
|
||||
}
|
||||
else
|
||||
{
|
||||
// Working out of build directory
|
||||
dir.cd( Config::PROJECT_SOURCE_DIR );
|
||||
}
|
||||
|
||||
dir.cd( "templates" );
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
void Db::readPapers()
|
||||
{
|
||||
readPapersFromDir( 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( 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( 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( systemTemplatesDir() );
|
||||
|
||||
// TODO: Read user directories
|
||||
|
||||
qStableSort( 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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
/* 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 <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
#include "Category.h"
|
||||
#include "Paper.h"
|
||||
#include "Template.h"
|
||||
#include "Vendor.h"
|
||||
|
||||
|
||||
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;
|
||||
static QString mEmpty;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_Db_h
|
||||
@@ -0,0 +1,207 @@
|
||||
/* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/* 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 <QCoreApplication>
|
||||
#include <QString>
|
||||
|
||||
#include "Units.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -0,0 +1,219 @@
|
||||
/* 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 ) );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
/* 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"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
Frame::Frame( const QString& id )
|
||||
: mId(id), mNLabels(0), mLayoutDescription("")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qStableSort( 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/* 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 <QCoreApplication>
|
||||
#include <QList>
|
||||
#include <QPainterPath>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
#include "Distance.h"
|
||||
#include "Layout.h"
|
||||
#include "Point.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -0,0 +1,218 @@
|
||||
/* 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 <QtDebug>
|
||||
|
||||
#include "privateConstants.h"
|
||||
#include "StrUtil.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
FrameCd::FrameCd( const Distance& r1,
|
||||
const Distance& r2,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& waste,
|
||||
const QString& id )
|
||||
: mR1(r1), mR2(r2), mW(w), mH(h), mWaste(waste), Frame(id)
|
||||
{
|
||||
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 )
|
||||
: mR1(other.mR1), mR2(other.mR2), mW(other.mW), mH(other.mH), mWaste(other.mWaste),
|
||||
mPath(other.mPath), Frame(other)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
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 ) <= Constants::EPSILON) &&
|
||||
(fabs( mH - otherCd->mH ) <= Constants::EPSILON) &&
|
||||
(fabs( mR1 - otherCd->mR1 ) <= Constants::EPSILON) &&
|
||||
(fabs( mR2 - otherCd->mR2 ) <= Constants::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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/* 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
|
||||
{
|
||||
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;
|
||||
|
||||
Distance r1() const;
|
||||
Distance r2() const;
|
||||
Distance waste() const;
|
||||
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
|
||||
QString sizeDescription( const Units& units ) const;
|
||||
bool isSimilarTo( Frame* other ) const;
|
||||
|
||||
const QPainterPath& path() const;
|
||||
const QPainterPath& clipPath() const;
|
||||
QPainterPath marginPath( const Distance& size ) const;
|
||||
|
||||
|
||||
private:
|
||||
Distance mR1;
|
||||
Distance mR2;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
QPainterPath mClipPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_FrameCd_h
|
||||
@@ -0,0 +1,131 @@
|
||||
/* 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 "privateConstants.h"
|
||||
#include "StrUtil.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
FrameEllipse::FrameEllipse( const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& waste,
|
||||
const QString& id )
|
||||
: mW(w), mH(h), mWaste(waste), Frame(id)
|
||||
{
|
||||
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 )
|
||||
: mW(other.mW), mH(other.mH), mWaste(other.mWaste), mPath(other.mPath), Frame(other)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
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 ) <= Constants::EPSILON) &&
|
||||
(fabs( mH - otherEllipse->mH ) <= Constants::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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/* 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
|
||||
{
|
||||
|
||||
public:
|
||||
FrameEllipse( const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& waste,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameEllipse( const FrameEllipse& other );
|
||||
|
||||
Frame* dup() const;
|
||||
|
||||
Distance waste() const;
|
||||
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
|
||||
QString sizeDescription( const Units& units ) const;
|
||||
bool isSimilarTo( Frame* other ) const;
|
||||
|
||||
const QPainterPath& path() const;
|
||||
const QPainterPath& clipPath() const;
|
||||
QPainterPath marginPath( const Distance& size ) const;
|
||||
|
||||
|
||||
private:
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
QPainterPath mClipPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_FrameEllipse_h
|
||||
@@ -0,0 +1,152 @@
|
||||
/* 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 "privateConstants.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 )
|
||||
: mW(w), mH(h), mR(r), mXWaste(xWaste), mYWaste(yWaste), Frame(id)
|
||||
{
|
||||
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 )
|
||||
: mW(other.mW), mH(other.mH), mR(other.mR), mXWaste(other.mXWaste),
|
||||
mYWaste(other.mYWaste), mPath(other.mPath), Frame(other)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
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 ) <= Constants::EPSILON) &&
|
||||
(fabs( mH - otherRect->mH ) <= Constants::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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/* 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
|
||||
{
|
||||
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;
|
||||
|
||||
Distance r() const;
|
||||
Distance xWaste() const;
|
||||
Distance yWaste() const;
|
||||
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
|
||||
QString sizeDescription( const Units& units ) const;
|
||||
|
||||
bool isSimilarTo( Frame* other ) const;
|
||||
|
||||
const QPainterPath& path() const;
|
||||
const QPainterPath& clipPath() const;
|
||||
QPainterPath marginPath( const Distance& size ) const;
|
||||
|
||||
|
||||
private:
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mR;
|
||||
Distance mXWaste;
|
||||
Distance mYWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
QPainterPath mClipPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_FrameRect_h
|
||||
@@ -0,0 +1,134 @@
|
||||
/* 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 "privateConstants.h"
|
||||
#include "StrUtil.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
FrameRound::FrameRound( const Distance& r,
|
||||
const Distance& waste,
|
||||
const QString& id )
|
||||
: mR(r), mWaste(waste), Frame(id)
|
||||
{
|
||||
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 )
|
||||
: mR(other.mR), mWaste(other.mWaste), mPath(other.mPath), Frame(other)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
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 ) <= Constants::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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/* 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
|
||||
{
|
||||
|
||||
public:
|
||||
FrameRound( const Distance& r,
|
||||
const Distance& waste,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameRound( const FrameRound &other );
|
||||
|
||||
Frame *dup() const;
|
||||
|
||||
Distance r() const;
|
||||
Distance waste() const;
|
||||
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
|
||||
QString sizeDescription( const Units& units ) const;
|
||||
bool isSimilarTo( Frame* other ) const;
|
||||
|
||||
const QPainterPath& path() const;
|
||||
const QPainterPath& clipPath() const;
|
||||
QPainterPath marginPath( const Distance& size ) const;
|
||||
|
||||
|
||||
private:
|
||||
Distance mR;
|
||||
Distance mWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
QPainterPath mClipPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_FrameRound_h
|
||||
+1
-1
@@ -25,7 +25,7 @@
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
|
||||
#include "libglabels/Distance.h"
|
||||
#include "Distance.h"
|
||||
|
||||
// Forward References
|
||||
class LabelModelObject;
|
||||
|
||||
@@ -26,6 +26,10 @@
|
||||
#include <QtDebug>
|
||||
|
||||
#include "Cursors.h"
|
||||
#include "FrameCd.h"
|
||||
#include "FrameEllipse.h"
|
||||
#include "FrameRect.h"
|
||||
#include "FrameRound.h"
|
||||
#include "LabelModel.h"
|
||||
#include "LabelModelObject.h"
|
||||
#include "LabelModelBoxObject.h"
|
||||
@@ -33,15 +37,10 @@
|
||||
#include "LabelModelImageObject.h"
|
||||
#include "LabelModelLineObject.h"
|
||||
#include "LabelModelTextObject.h"
|
||||
#include "Markup.h"
|
||||
#include "Settings.h"
|
||||
#include "UndoRedoModel.h"
|
||||
|
||||
#include "libglabels/Markup.h"
|
||||
#include "libglabels/FrameRect.h"
|
||||
#include "libglabels/FrameRound.h"
|
||||
#include "libglabels/FrameEllipse.h"
|
||||
#include "libglabels/FrameCd.h"
|
||||
|
||||
|
||||
//
|
||||
// Private Configuration Data
|
||||
|
||||
@@ -27,12 +27,11 @@
|
||||
#include <QPainter>
|
||||
|
||||
#include "Settings.h"
|
||||
#include "Template.h"
|
||||
|
||||
#include "Merge/Merge.h"
|
||||
#include "Merge/Record.h"
|
||||
|
||||
#include "libglabels/Template.h"
|
||||
|
||||
// Forward References
|
||||
class ColorNode;
|
||||
class Handle;
|
||||
|
||||
@@ -27,15 +27,15 @@
|
||||
#include <QMatrix>
|
||||
#include <QPainter>
|
||||
|
||||
#include "ColorNode.h"
|
||||
#include "TextNode.h"
|
||||
#include "BarcodeStyle.h"
|
||||
#include "ColorNode.h"
|
||||
#include "Distance.h"
|
||||
#include "Handles.h"
|
||||
#include "Outline.h"
|
||||
#include "TextNode.h"
|
||||
|
||||
#include "Merge/Record.h"
|
||||
|
||||
#include "libglabels/Distance.h"
|
||||
|
||||
// Forward References
|
||||
class Region;
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/* 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 <cmath>
|
||||
|
||||
#include "privateConstants.h"
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Layout::Layout( const Layout& other )
|
||||
: mNx(other.mNx), mNy(other.mNy), mX0(other.mX0), mY0(other.mY0),
|
||||
mDx(other.mDx), mDy(other.mDy)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
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) < Constants::EPSILON) &&
|
||||
(fabs(mY0 - other->mY0) < Constants::EPSILON) &&
|
||||
(fabs(mDx - other->mDx) < Constants::EPSILON) &&
|
||||
(fabs(mDy - other->mDy) < Constants::EPSILON) );
|
||||
}
|
||||
|
||||
|
||||
Layout* Layout::dup() const
|
||||
{
|
||||
Layout *other = new Layout( *this );
|
||||
return other;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/* 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
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <QToolBar>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "Db.h"
|
||||
#include "File.h"
|
||||
#include "Help.h"
|
||||
#include "Icons.h"
|
||||
@@ -50,8 +51,6 @@
|
||||
#include "StartupView.h"
|
||||
#include "UndoRedoModel.h"
|
||||
|
||||
#include "libglabels/Db.h"
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
/* 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/* 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 <QPainterPath>
|
||||
|
||||
#include "Frame.h"
|
||||
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
private:
|
||||
Distance mX0;
|
||||
Distance mY0;
|
||||
Distance mR;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_Markup_h
|
||||
@@ -0,0 +1,135 @@
|
||||
/* MiniPreviewPixmap.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 "MiniPreviewPixmap.h"
|
||||
|
||||
|
||||
#include "Template.h"
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
const QColor paperColor( 217, 217, 217 );
|
||||
const QColor paperOutlineColor( 0, 0, 0 );
|
||||
const double paperOutlineWidthPixels = 1.0;
|
||||
|
||||
const QColor labelColor( 242, 242, 242 );
|
||||
const QColor labelOutlineColor( 64, 64, 64 );
|
||||
const double labelOutlineWidthPixels = 1.0;
|
||||
}
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
MiniPreviewPixmap::MiniPreviewPixmap()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MiniPreviewPixmap::MiniPreviewPixmap( const Template* tmplate, int width, int height )
|
||||
: QPixmap( width, height )
|
||||
{
|
||||
draw( tmplate, width, height );
|
||||
}
|
||||
|
||||
|
||||
void MiniPreviewPixmap::draw( const Template* tmplate, int width, int height )
|
||||
{
|
||||
fill( Qt::transparent );
|
||||
|
||||
QPainter painter( this );
|
||||
|
||||
painter.setBackgroundMode( Qt::TransparentMode );
|
||||
painter.setRenderHint( QPainter::Antialiasing, true );
|
||||
|
||||
double w = width - 1;
|
||||
double h = height - 1;
|
||||
double scale;
|
||||
if ( (w/tmplate->pageWidth().pt()) > (h/tmplate->pageHeight().pt()) )
|
||||
{
|
||||
scale = h / tmplate->pageHeight().pt();
|
||||
}
|
||||
else
|
||||
{
|
||||
scale = w / tmplate->pageWidth().pt();
|
||||
}
|
||||
painter.scale( scale, scale );
|
||||
|
||||
Distance xOffset = ( Distance::pt(width/scale) - tmplate->pageWidth() ) / 2;
|
||||
Distance yOffset = ( Distance::pt(height/scale) - tmplate->pageHeight() ) / 2;
|
||||
painter.translate( xOffset.pt(), yOffset.pt() );
|
||||
|
||||
drawPaper( painter, tmplate, scale );
|
||||
drawLabelOutlines( painter, tmplate, scale );
|
||||
}
|
||||
|
||||
|
||||
void MiniPreviewPixmap::drawPaper( QPainter& painter, const Template* tmplate, double scale )
|
||||
{
|
||||
QBrush brush( paperColor );
|
||||
QPen pen( paperOutlineColor );
|
||||
pen.setWidth( paperOutlineWidthPixels/scale );
|
||||
|
||||
painter.save();
|
||||
|
||||
painter.setBrush( brush );
|
||||
painter.setPen( pen );
|
||||
painter.drawRect( 0, 0, tmplate->pageWidth().pt(), tmplate->pageHeight().pt() );
|
||||
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
|
||||
void MiniPreviewPixmap::drawLabelOutlines( QPainter& painter, const Template* tmplate, double scale )
|
||||
{
|
||||
QBrush brush( labelColor );
|
||||
QPen pen( labelOutlineColor );
|
||||
pen.setWidth( labelOutlineWidthPixels/scale );
|
||||
|
||||
painter.save();
|
||||
|
||||
painter.setBrush( brush );
|
||||
painter.setPen( pen );
|
||||
|
||||
Frame *frame = tmplate->frames().first();
|
||||
QVector<Point> origins = frame->getOrigins();
|
||||
|
||||
foreach ( Point p0, origins )
|
||||
{
|
||||
drawLabelOutline( painter, frame, p0 );
|
||||
}
|
||||
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
|
||||
void MiniPreviewPixmap::drawLabelOutline( QPainter& painter, const Frame* frame, const Point& p0 )
|
||||
{
|
||||
painter.save();
|
||||
|
||||
painter.translate( p0.x().pt(), p0.y().pt() );
|
||||
painter.drawPath( frame->path() );
|
||||
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/* MiniPreviewPixmap.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_MiniPreviewPixmap_h
|
||||
#define glabels_MiniPreviewPixmap_h
|
||||
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QPainter>
|
||||
|
||||
#include "Point.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
// Forward references
|
||||
class Template;
|
||||
class Frame;
|
||||
|
||||
|
||||
class MiniPreviewPixmap : public QPixmap
|
||||
{
|
||||
|
||||
public:
|
||||
MiniPreviewPixmap();
|
||||
|
||||
MiniPreviewPixmap( const Template* tmplate, int width, int height );
|
||||
|
||||
|
||||
private:
|
||||
void draw( const Template* tmplate, int width, int height );
|
||||
void drawPaper( QPainter& painter, const Template* tmplate, double scale );
|
||||
void drawLabelOutlines( QPainter& painter, const Template* tmplate, double scale );
|
||||
void drawLabelOutline( QPainter& painter, const Frame *frame, const Point& point0 );
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_MiniPreviewPixmap_h
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
#include "ui_ObjectEditor.h"
|
||||
|
||||
#include "libglabels/Distance.h"
|
||||
#include "Distance.h"
|
||||
|
||||
// Forward references
|
||||
class LabelModel;
|
||||
|
||||
@@ -26,11 +26,11 @@
|
||||
#include <QRect>
|
||||
#include <QVector>
|
||||
|
||||
#include "Point.h"
|
||||
|
||||
#include "Merge/Merge.h"
|
||||
#include "Merge/Record.h"
|
||||
|
||||
#include "libglabels/Point.h"
|
||||
|
||||
// Forward references
|
||||
class LabelModel;
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/* Paper.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 "Paper.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
Paper::Paper( const QString& id,
|
||||
const QString& name,
|
||||
const Distance& width,
|
||||
const Distance& height,
|
||||
const QString& pwgSize )
|
||||
: mId(id), mName(name), mWidth(width), mHeight(height), mPwgSize(pwgSize)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QString Paper::id() const
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
|
||||
|
||||
QString Paper::name() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
|
||||
Distance Paper::width() const
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
|
||||
Distance Paper::height() const
|
||||
{
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
|
||||
QString Paper::pwgSize() const
|
||||
{
|
||||
return mPwgSize;
|
||||
}
|
||||
|
||||
|
||||
bool Paper::isSizeIso() const
|
||||
{
|
||||
return mPwgSize.startsWith( "iso_" );
|
||||
}
|
||||
|
||||
|
||||
bool Paper::isSizeUs() const
|
||||
{
|
||||
return mPwgSize.startsWith( "na_" );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/* Paper.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_Paper_h
|
||||
#define glabels_Paper_h
|
||||
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "Distance.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class Paper
|
||||
{
|
||||
public:
|
||||
Paper( const QString& id,
|
||||
const QString& name,
|
||||
const Distance& width,
|
||||
const Distance& height,
|
||||
const QString& pwgSize );
|
||||
|
||||
QString id() const;
|
||||
QString name() const;
|
||||
|
||||
/* Width */
|
||||
Distance width() const;
|
||||
|
||||
/* Height */
|
||||
Distance height() const;
|
||||
|
||||
/* PWG 5101.1-2002 size name */
|
||||
QString pwgSize() const;
|
||||
|
||||
bool isSizeIso() const;
|
||||
bool isSizeUs() const;
|
||||
|
||||
private:
|
||||
QString mId;
|
||||
QString mName;
|
||||
Distance mWidth;
|
||||
Distance mHeight;
|
||||
QString mPwgSize;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_Paper_h
|
||||
@@ -0,0 +1,62 @@
|
||||
/* Point.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 "Point.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
Point::Point() : mX(Distance(0)), mY(Distance(0))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Point::Point( Distance x, Distance y ) : mX(x), mY(y)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Distance Point::x() const
|
||||
{
|
||||
return mX;
|
||||
}
|
||||
|
||||
|
||||
Distance Point::y() const
|
||||
{
|
||||
return mY;
|
||||
}
|
||||
|
||||
|
||||
bool Point::operator<( const Point &other ) const
|
||||
{
|
||||
if ( mY < other.mY )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( mY == other.mY )
|
||||
{
|
||||
return mX < other.mX;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/* Point.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_Point_h
|
||||
#define glabels_Point_h
|
||||
|
||||
|
||||
#include "Distance.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class Point
|
||||
{
|
||||
public:
|
||||
Point();
|
||||
|
||||
Point( Distance x, Distance y );
|
||||
|
||||
Distance x() const;
|
||||
Distance y() const;
|
||||
|
||||
bool operator<( const Point &other ) const;
|
||||
|
||||
|
||||
private:
|
||||
Distance mX;
|
||||
Distance mY;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_Point_h
|
||||
@@ -24,13 +24,12 @@
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "Db.h"
|
||||
#include "LabelModel.h"
|
||||
#include "SelectProductDialog.h"
|
||||
#include "Settings.h"
|
||||
#include "UndoRedoModel.h"
|
||||
|
||||
#include "libglabels/Db.h"
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "ui_PropertiesView.h"
|
||||
|
||||
#include "libglabels/Units.h"
|
||||
#include "Units.h"
|
||||
|
||||
// Forward references
|
||||
class LabelModel;
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
|
||||
#include <QRectF>
|
||||
|
||||
#include "libglabels/Distance.h"
|
||||
#include "Distance.h"
|
||||
|
||||
|
||||
///
|
||||
|
||||
@@ -23,11 +23,10 @@
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
#include "Db.h"
|
||||
#include "Settings.h"
|
||||
#include "TemplatePickerItem.h"
|
||||
|
||||
#include "libglabels/Db.h"
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@
|
||||
#include <QSettings>
|
||||
#include <QStringList>
|
||||
|
||||
#include "libglabels/Distance.h"
|
||||
#include "Distance.h"
|
||||
|
||||
|
||||
///
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <QGraphicsScene>
|
||||
#include <QList>
|
||||
|
||||
#include "libglabels/Template.h"
|
||||
#include "Template.h"
|
||||
|
||||
|
||||
///
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
|
||||
#include <QSizeF>
|
||||
|
||||
#include "libglabels/Distance.h"
|
||||
#include "Distance.h"
|
||||
|
||||
|
||||
///
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
/* StrUtil.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 "StrUtil.h"
|
||||
|
||||
|
||||
#include <QtMath>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
const double FRAC_EPSILON = 0.00005;
|
||||
const double denom[] = { 1.0, 2.0, 3.0, 4.0, 8.0, 16.0, 32.0, 0.0 };
|
||||
const char* denom_string[] = { "1", "₂", "₃", "₄", "₈", "₁₆", "₃₂", NULL };
|
||||
const char* num_string[] = { "⁰", "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹",
|
||||
"¹⁰", "¹¹", "¹²", "¹³", "¹⁴", "¹⁵", "¹⁶", "¹⁷", "¹⁸", "¹⁹",
|
||||
"²⁰", "²¹", "²²", "²³", "²⁴", "²⁵", "²⁶", "²⁷", "²⁸", "²⁹",
|
||||
"³⁰", "³¹" };
|
||||
}
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace StrUtil
|
||||
{
|
||||
|
||||
QString formatFraction( double x )
|
||||
{
|
||||
int i;
|
||||
double product, remainder;
|
||||
|
||||
for ( i=0; denom[i] != 0.0; i++ )
|
||||
{
|
||||
product = x * denom[i];
|
||||
remainder = qFabs(product - ((int)(product+0.5)));
|
||||
if ( remainder < FRAC_EPSILON ) break;
|
||||
}
|
||||
|
||||
if ( denom[i] == 0.0 )
|
||||
{
|
||||
/* None of our denominators work. */
|
||||
return QString().sprintf( "%.5g", x );
|
||||
}
|
||||
if ( denom[i] == 1.0 )
|
||||
{
|
||||
/* Simple integer. */
|
||||
return QString().sprintf( "%.0f", x );
|
||||
}
|
||||
int n = (int)( x * denom[i] + 0.5 );
|
||||
int d = (int)denom[i];
|
||||
if ( n > d )
|
||||
{
|
||||
return QString::number(n/d) +
|
||||
QString::fromUtf8(num_string[n%d]) + "/" + QString::fromUtf8(denom_string[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString::fromUtf8(num_string[n%d]) + "/" + QString::fromUtf8(denom_string[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString spanDigits( const QString &s, int *i )
|
||||
{
|
||||
QString chunk;
|
||||
|
||||
for ( int j = *i; (j < s.size()) && s.at(j).isNumber(); j++ )
|
||||
{
|
||||
chunk.append( s.at(j) );
|
||||
*i = j+1; /* only advance i, if character is used. */
|
||||
}
|
||||
|
||||
return chunk;
|
||||
}
|
||||
|
||||
|
||||
QString spanNonDigits( const QString &s, int *i )
|
||||
{
|
||||
QString chunk;
|
||||
|
||||
for ( int j = *i; (j < s.size()) && !s.at(j).isNumber(); j++ )
|
||||
{
|
||||
chunk.append( s.at(j) );
|
||||
*i = j+1; /* only advance i, if character is used. */
|
||||
}
|
||||
|
||||
return chunk;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compare part names
|
||||
* @s1: string to compare with s2.
|
||||
* @s2: string to compare with s1.
|
||||
*
|
||||
* Compare two strings representing part names or numbers. This function
|
||||
* uses a natural sort order:
|
||||
*
|
||||
* - Ignores case.
|
||||
*
|
||||
* - Strings are divided into chunks (numeric and non-numeric)
|
||||
*
|
||||
* - Non-numeric chunks are compared character by character
|
||||
*
|
||||
* - Numerical chunks are compared numerically, so that "20" precedes "100".
|
||||
*
|
||||
* - Comparison of chunks is performed left to right until the first difference
|
||||
* is encountered or all chunks evaluate as equal.
|
||||
*
|
||||
* Numeric chunks are converted to 64 bit unsigned integers for comparison,
|
||||
* so the behaviour may be unpredictable for numeric chunks that exceed
|
||||
* 18446744073709551615.
|
||||
*
|
||||
* Returns: 0 if the strings match, a negative value if s1 < s2,
|
||||
* or a positive value if s1 > s2.
|
||||
*
|
||||
*/
|
||||
int comparePartNames( const QString &s1, const QString &s2 )
|
||||
{
|
||||
if ( s1 == s2 ) return 0;
|
||||
if ( s1 == "" ) return -1;
|
||||
if ( s2 == "" ) return 1;
|
||||
|
||||
QString folded_s1 = s1.toUpper();
|
||||
QString folded_s2 = s2.toUpper();
|
||||
|
||||
int i1 = 0;
|
||||
int i2 = 0;
|
||||
int result = 0;
|
||||
bool done = false;
|
||||
|
||||
while ( (result == 0) && !done )
|
||||
{
|
||||
QString chunk1, chunk2;
|
||||
bool isnum1, isnum2;
|
||||
|
||||
if ( (i1 < folded_s1.size()) && folded_s1.at( i1 ).isNumber() )
|
||||
{
|
||||
chunk1 = spanDigits( folded_s1, &i1 );
|
||||
isnum1 = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
chunk1 = spanNonDigits( folded_s1, &i1 );
|
||||
isnum1 = false;
|
||||
}
|
||||
|
||||
if ( (i2 < folded_s2.size()) && folded_s2.at( i2 ).isNumber() )
|
||||
{
|
||||
chunk2 = spanDigits( folded_s2, &i2 );
|
||||
isnum2 = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
chunk2 = spanNonDigits( folded_s2, &i2 );
|
||||
isnum2 = false;
|
||||
}
|
||||
|
||||
|
||||
if ( ( chunk1 == "" ) && ( chunk2 == "" ) )
|
||||
{
|
||||
/* Case 1: Both are empty. */
|
||||
done = true;
|
||||
}
|
||||
else if ( isnum1 && isnum2 )
|
||||
{
|
||||
/* Case 2: They both contain numbers */
|
||||
qlonglong n1 = chunk1.toLongLong();
|
||||
qlonglong n2 = chunk2.toLongLong();
|
||||
|
||||
if ( n1 < n2 ) result = -1;
|
||||
else if ( n1 > n2 ) result = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Case 3: One or both do not contain numbers */
|
||||
if ( chunk1 < chunk2 ) result = -1;
|
||||
else if( chunk1 > chunk2 ) result = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/* StrUtil.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_StrUtil_h
|
||||
#define glabels_StrUtil_h
|
||||
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace StrUtil
|
||||
{
|
||||
|
||||
QString formatFraction( double x );
|
||||
|
||||
int comparePartNames( const QString &s1, const QString &s2 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_StrUtil_h
|
||||
@@ -0,0 +1,302 @@
|
||||
/* Template.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 "Template.h"
|
||||
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
#include "Db.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
Template::Template( const QString& brand,
|
||||
const QString& part,
|
||||
const QString& description,
|
||||
const QString& paperId,
|
||||
const Distance& pageWidth,
|
||||
const Distance& pageHeight )
|
||||
: mBrand(brand),
|
||||
mPart(part),
|
||||
mDescription(description),
|
||||
mPaperId(paperId),
|
||||
mPageWidth(pageWidth),
|
||||
mPageHeight(pageHeight),
|
||||
mIsSizeIso(false),
|
||||
mIsSizeUs(false),
|
||||
mName("")
|
||||
{
|
||||
mName.append( brand ).append( " " ).append( part );
|
||||
|
||||
if ( Db::isPaperIdKnown( paperId ) )
|
||||
{
|
||||
const Paper* paper = Db::lookupPaperFromId( paperId );
|
||||
mIsSizeIso = paper->isSizeIso();
|
||||
mIsSizeUs = paper->isSizeUs();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Template::Template( const Template& other )
|
||||
{
|
||||
mBrand = other.mBrand;
|
||||
mPart = other.mPart;
|
||||
mDescription = other.mDescription;
|
||||
mPaperId = other.mPaperId;
|
||||
mPageWidth = other.mPageWidth;
|
||||
mPageHeight = other.mPageHeight;
|
||||
mIsSizeIso = other.mIsSizeIso;
|
||||
mIsSizeUs = other.mIsSizeUs;
|
||||
mEquivPart = other.mEquivPart;
|
||||
mName = other.mName;
|
||||
mProductUrl = other.mProductUrl;
|
||||
|
||||
foreach ( Frame* frame, other.mFrames )
|
||||
{
|
||||
addFrame( frame );
|
||||
}
|
||||
|
||||
foreach ( QString categoryId, other.mCategoryIds )
|
||||
{
|
||||
addCategory( categoryId );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Template* Template::dup() const
|
||||
{
|
||||
return new Template( *this );
|
||||
}
|
||||
|
||||
|
||||
// Generic full page template
|
||||
Template* Template::fullPage( const QString& paperId )
|
||||
{
|
||||
// TODO
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// From equivalent part number
|
||||
Template* Template::fromEquiv( const QString& brand,
|
||||
const QString& part,
|
||||
const QString& equivPart )
|
||||
{
|
||||
const Template* other = Db::lookupTemplateFromBrandPart( brand, equivPart );
|
||||
if ( other != NULL )
|
||||
{
|
||||
Template* tmplate = other->dup();
|
||||
|
||||
tmplate->mPart = part;
|
||||
tmplate->mEquivPart = equivPart;
|
||||
|
||||
tmplate->mName = "";
|
||||
tmplate->mName.append( brand ).append( " " ).append( part );
|
||||
|
||||
return tmplate;
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Error: cannot create equivalent template for "
|
||||
<< brand << ", " << equivPart
|
||||
<< ". Forward references not supported.";
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString Template::brand() const
|
||||
{
|
||||
return mBrand;
|
||||
}
|
||||
|
||||
|
||||
QString Template::part() const
|
||||
{
|
||||
return mPart;
|
||||
}
|
||||
|
||||
|
||||
QString Template::description() const
|
||||
{
|
||||
return mDescription;
|
||||
}
|
||||
|
||||
|
||||
QString Template::paperId() const
|
||||
{
|
||||
return mPaperId;
|
||||
}
|
||||
|
||||
|
||||
Distance Template::pageWidth() const
|
||||
{
|
||||
return mPageWidth;
|
||||
}
|
||||
|
||||
|
||||
Distance Template::pageHeight() const
|
||||
{
|
||||
return mPageHeight;
|
||||
}
|
||||
|
||||
|
||||
bool Template::isSizeIso() const
|
||||
{
|
||||
return mIsSizeIso;
|
||||
}
|
||||
|
||||
|
||||
bool Template::isSizeUs() const
|
||||
{
|
||||
return mIsSizeUs;
|
||||
}
|
||||
|
||||
|
||||
bool Template::isSizeOther() const
|
||||
{
|
||||
return !mIsSizeIso && !mIsSizeUs;
|
||||
}
|
||||
|
||||
|
||||
QString Template::equivPart() const
|
||||
{
|
||||
return mEquivPart;
|
||||
}
|
||||
|
||||
|
||||
void Template::setEquivPart( const QString& value )
|
||||
{
|
||||
mEquivPart = value;
|
||||
}
|
||||
|
||||
|
||||
QString Template::productUrl() const
|
||||
{
|
||||
return mProductUrl;
|
||||
}
|
||||
|
||||
|
||||
void Template::setProductUrl( const QString& value )
|
||||
{
|
||||
mProductUrl = value;
|
||||
}
|
||||
|
||||
|
||||
QString Template::name() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
|
||||
const MiniPreviewPixmap& Template::preview() const
|
||||
{
|
||||
return mPreview;
|
||||
}
|
||||
|
||||
|
||||
const QList<Frame*>& Template::frames() const
|
||||
{
|
||||
return mFrames;
|
||||
}
|
||||
|
||||
|
||||
void Template::addCategory( const QString& categoryId )
|
||||
{
|
||||
mCategoryIds << categoryId;
|
||||
}
|
||||
|
||||
|
||||
void Template::addFrame( Frame* frame )
|
||||
{
|
||||
mFrames << frame;
|
||||
}
|
||||
|
||||
|
||||
void Template::initPreview()
|
||||
{
|
||||
mPreview = MiniPreviewPixmap( this, TEMPLATE_PREVIEW_SIZE, TEMPLATE_PREVIEW_SIZE );
|
||||
}
|
||||
|
||||
|
||||
bool Template::operator==( const Template& other ) const
|
||||
{
|
||||
return (mBrand == other.mBrand) && (mPart == other.mPart);
|
||||
}
|
||||
|
||||
|
||||
bool Template::hasCategory( const QString& categoryId ) const
|
||||
{
|
||||
foreach ( QString testCategoryId, mCategoryIds )
|
||||
{
|
||||
if ( categoryId == testCategoryId )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Template::isSimilarTo( const Template* other ) const
|
||||
{
|
||||
// Does page size match?
|
||||
if ( (mPaperId != other->mPaperId) ||
|
||||
(mPageWidth != other->mPageWidth ) ||
|
||||
(mPageHeight != other->mPageHeight ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Are frames similar
|
||||
Frame* frame1 = mFrames.first();
|
||||
Frame* frame2 = other->mFrames.first();
|
||||
if ( !frame1->isSimilarTo( frame2 ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Are they layed out similarly?
|
||||
foreach ( Layout* layout1, frame1->layouts() )
|
||||
{
|
||||
bool matchFound = false;
|
||||
foreach ( Layout* layout2, frame2->layouts() )
|
||||
{
|
||||
if ( layout1->isSimilarTo(layout2) )
|
||||
{
|
||||
matchFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( !matchFound )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
/* Template.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_Template_h
|
||||
#define glabels_Template_h
|
||||
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QList>
|
||||
|
||||
#include "Distance.h"
|
||||
#include "Frame.h"
|
||||
#include "MiniPreviewPixmap.h"
|
||||
#include "Point.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
const int TEMPLATE_PREVIEW_SIZE = 80;
|
||||
|
||||
|
||||
class Template
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Template)
|
||||
|
||||
public:
|
||||
|
||||
Template( const QString& brand,
|
||||
const QString& part,
|
||||
const QString& description,
|
||||
const QString& paperId,
|
||||
const Distance& pageWidth,
|
||||
const Distance& pageHeight );
|
||||
|
||||
Template( const Template& other );
|
||||
|
||||
Template* dup() const;
|
||||
|
||||
// Generic full page template
|
||||
static Template* fullPage( const QString& paperId );
|
||||
|
||||
// From equivalent part number
|
||||
static Template* fromEquiv( const QString& brand,
|
||||
const QString& part,
|
||||
const QString& equivPart );
|
||||
|
||||
|
||||
QString brand() const;
|
||||
QString part() const;
|
||||
QString description() const;
|
||||
|
||||
QString paperId() const;
|
||||
Distance pageWidth() const;
|
||||
Distance pageHeight() const;
|
||||
bool isSizeIso() const;
|
||||
bool isSizeUs() const;
|
||||
bool isSizeOther() const;
|
||||
|
||||
QString equivPart() const;
|
||||
void setEquivPart( const QString& value );
|
||||
|
||||
QString productUrl() const;
|
||||
void setProductUrl( const QString& value );
|
||||
|
||||
QString name() const;
|
||||
|
||||
void addCategory( const QString& categoryId );
|
||||
void addFrame( Frame* frame );
|
||||
|
||||
void initPreview();
|
||||
const MiniPreviewPixmap& preview() const;
|
||||
|
||||
const QList<Frame*>& frames() const;
|
||||
|
||||
bool operator==( const Template& other ) const;
|
||||
|
||||
bool hasCategory( const QString& categoryId ) const;
|
||||
bool isSimilarTo( const Template* other ) const;
|
||||
|
||||
|
||||
private:
|
||||
QString mBrand;
|
||||
QString mPart;
|
||||
QString mDescription;
|
||||
|
||||
QString mPaperId;
|
||||
Distance mPageWidth;
|
||||
Distance mPageHeight;
|
||||
bool mIsSizeIso;
|
||||
bool mIsSizeUs;
|
||||
|
||||
QString mEquivPart;
|
||||
QString mName;
|
||||
|
||||
QString mProductUrl;
|
||||
QStringList mCategoryIds;
|
||||
|
||||
QList<Frame*> mFrames;
|
||||
|
||||
MiniPreviewPixmap mPreview;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_Template_h
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <QList>
|
||||
#include <QListWidget>
|
||||
|
||||
#include "libglabels/Template.h"
|
||||
#include "Template.h"
|
||||
|
||||
|
||||
///
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <QLabel>
|
||||
#include <QListWidget>
|
||||
|
||||
#include "libglabels/Template.h"
|
||||
#include "Template.h"
|
||||
|
||||
|
||||
///
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
/* Units.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 "Units.h"
|
||||
|
||||
|
||||
#include <QTextStream>
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
|
||||
Units::Units() : mEnumValue(PT)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Units::Units( Units::Enum enumValue ) : mEnumValue(enumValue)
|
||||
{
|
||||
switch (enumValue)
|
||||
{
|
||||
case PT:
|
||||
case IN:
|
||||
case MM:
|
||||
case CM:
|
||||
case PC:
|
||||
/* Catch all valid enum values. */
|
||||
break;
|
||||
default:
|
||||
/* Catch invalid enum values, reset to PT. */
|
||||
qWarning() << "Bad Units::Enum value = " << enumValue << ".";
|
||||
mEnumValue = PT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Units::Units( const QString& idString )
|
||||
{
|
||||
if ( idString == "pt" )
|
||||
{
|
||||
mEnumValue = PT;
|
||||
}
|
||||
else if ( idString == "in" )
|
||||
{
|
||||
mEnumValue = IN;
|
||||
}
|
||||
else if ( idString == "mm" )
|
||||
{
|
||||
mEnumValue = MM;
|
||||
}
|
||||
else if ( idString == "cm" )
|
||||
{
|
||||
mEnumValue = CM;
|
||||
}
|
||||
else if ( idString == "pc" )
|
||||
{
|
||||
mEnumValue = PC;
|
||||
}
|
||||
else
|
||||
{
|
||||
mEnumValue = PT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Units Units::pt()
|
||||
{
|
||||
return Units(PT);
|
||||
}
|
||||
|
||||
|
||||
Units Units::in()
|
||||
{
|
||||
return Units(IN);
|
||||
}
|
||||
|
||||
|
||||
Units Units::mm()
|
||||
{
|
||||
return Units(MM);
|
||||
}
|
||||
|
||||
|
||||
Units Units::cm()
|
||||
{
|
||||
return Units(CM);
|
||||
}
|
||||
|
||||
|
||||
Units Units::pc()
|
||||
{
|
||||
return Units(PC);
|
||||
}
|
||||
|
||||
|
||||
Units::Enum Units::toEnum() const
|
||||
{
|
||||
return mEnumValue;
|
||||
}
|
||||
|
||||
|
||||
QString Units::toIdString() const
|
||||
{
|
||||
QString idString;
|
||||
|
||||
switch (mEnumValue)
|
||||
{
|
||||
case Units::PT:
|
||||
idString = "pt";
|
||||
break;
|
||||
case Units::IN:
|
||||
idString = "in";
|
||||
break;
|
||||
case Units::MM:
|
||||
idString = "mm";
|
||||
break;
|
||||
case Units::CM:
|
||||
idString = "cm";
|
||||
break;
|
||||
case Units::PC:
|
||||
idString = "pc";
|
||||
break;
|
||||
}
|
||||
|
||||
return idString;
|
||||
}
|
||||
|
||||
|
||||
QString Units::toTrName() const
|
||||
{
|
||||
QString nameString;
|
||||
|
||||
switch (mEnumValue)
|
||||
{
|
||||
case Units::PT:
|
||||
nameString = tr("points");
|
||||
break;
|
||||
case Units::IN:
|
||||
nameString = tr("inches");
|
||||
break;
|
||||
case Units::MM:
|
||||
nameString = tr("mm");
|
||||
break;
|
||||
case Units::CM:
|
||||
nameString = tr("cm");
|
||||
break;
|
||||
case Units::PC:
|
||||
nameString = tr("picas");
|
||||
break;
|
||||
}
|
||||
|
||||
return nameString;
|
||||
}
|
||||
|
||||
|
||||
double Units::resolution() const
|
||||
{
|
||||
double value;
|
||||
|
||||
switch (mEnumValue)
|
||||
{
|
||||
case glabels::Units::PT:
|
||||
value = 0.01;
|
||||
break;
|
||||
case glabels::Units::IN:
|
||||
value = 0.001;
|
||||
break;
|
||||
case glabels::Units::MM:
|
||||
value = 0.01;
|
||||
break;
|
||||
case glabels::Units::CM:
|
||||
value = 0.001;
|
||||
break;
|
||||
case glabels::Units::PC:
|
||||
value = 0.01;
|
||||
break;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
int Units::resolutionDigits() const
|
||||
{
|
||||
int digits;
|
||||
|
||||
switch (mEnumValue)
|
||||
{
|
||||
case glabels::Units::PT:
|
||||
digits = 2;
|
||||
break;
|
||||
case glabels::Units::IN:
|
||||
digits = 3;
|
||||
break;
|
||||
case glabels::Units::MM:
|
||||
digits = 2;
|
||||
break;
|
||||
case glabels::Units::CM:
|
||||
digits = 3;
|
||||
break;
|
||||
case glabels::Units::PC:
|
||||
digits = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
return digits;
|
||||
}
|
||||
|
||||
|
||||
bool Units::isIdValid( const QString& idString )
|
||||
{
|
||||
bool retValue = false;
|
||||
|
||||
if ( idString == "pt" )
|
||||
{
|
||||
retValue = true;
|
||||
}
|
||||
else if ( idString == "in" )
|
||||
{
|
||||
retValue = true;
|
||||
}
|
||||
else if ( idString == "mm" )
|
||||
{
|
||||
retValue = true;
|
||||
}
|
||||
else if ( idString == "cm" )
|
||||
{
|
||||
retValue = true;
|
||||
}
|
||||
else if ( idString == "pc" )
|
||||
{
|
||||
retValue = true;
|
||||
}
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/* Units.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_Units_h
|
||||
#define glabels_Units_h
|
||||
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
|
||||
class Units
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Units)
|
||||
|
||||
public:
|
||||
enum Enum { PT, IN, MM, CM, PC };
|
||||
|
||||
Units();
|
||||
Units( Enum enumValue );
|
||||
Units( const QString& idString );
|
||||
|
||||
static Units pt();
|
||||
static Units in();
|
||||
static Units mm();
|
||||
static Units cm();
|
||||
static Units pc();
|
||||
|
||||
Enum toEnum() const;
|
||||
|
||||
QString toIdString() const;
|
||||
QString toTrName() const;
|
||||
|
||||
double resolution() const;
|
||||
int resolutionDigits() const;
|
||||
|
||||
static bool isIdValid( const QString& unitsId );
|
||||
|
||||
|
||||
private:
|
||||
Enum mEnumValue;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_Units_h
|
||||
@@ -0,0 +1,43 @@
|
||||
/* Vendor.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 "Vendor.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
Vendor::Vendor( const QString &name, const QString &url ) : mName(name), mUrl(url)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QString Vendor::name() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
|
||||
QString Vendor::url() const
|
||||
{
|
||||
return mUrl;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/* Vendor.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_Vendor_h
|
||||
#define glabels_Vendor_h
|
||||
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class Vendor
|
||||
{
|
||||
public:
|
||||
Vendor( const QString &name, const QString &url );
|
||||
|
||||
QString name() const;
|
||||
QString url() const;
|
||||
|
||||
private:
|
||||
QString mName;
|
||||
QString mUrl;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_Vendor_h
|
||||
@@ -0,0 +1,105 @@
|
||||
/* XmlCategoryParser.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 "XmlCategoryParser.h"
|
||||
|
||||
|
||||
#include <QDomDocument>
|
||||
#include <QDomNode>
|
||||
#include <QFile>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "Category.h"
|
||||
#include "Db.h"
|
||||
#include "XmlUtil.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
bool XmlCategoryParser::readFile( const QString &fileName )
|
||||
{
|
||||
QFile file( fileName );
|
||||
|
||||
if ( !file.open( QFile::ReadOnly | QFile::Text) )
|
||||
{
|
||||
qWarning() << "Error: Cannot read file " << fileName
|
||||
<< ": " << file.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
QDomDocument doc;
|
||||
QString errorString;
|
||||
int errorLine;
|
||||
int errorColumn;
|
||||
|
||||
if ( !doc.setContent( &file, false, &errorString, &errorLine, &errorColumn ) )
|
||||
{
|
||||
qWarning() << "Error: Parse error at line " << errorLine
|
||||
<< "column " << errorColumn
|
||||
<< ": " << errorString;
|
||||
return false;
|
||||
}
|
||||
|
||||
QDomElement root = doc.documentElement();
|
||||
if ( root.tagName() != "Glabels-categories" )
|
||||
{
|
||||
qWarning() << "Error: Not a Glabels-categories file.";
|
||||
return false;
|
||||
}
|
||||
|
||||
parseRootNode( root );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void XmlCategoryParser::parseRootNode( const QDomElement &node )
|
||||
{
|
||||
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
|
||||
{
|
||||
if ( child.toElement().tagName() == "Category" )
|
||||
{
|
||||
parseCategoryNode( child.toElement() );
|
||||
}
|
||||
else if ( !child.isComment() )
|
||||
{
|
||||
qWarning() << "Warning: bad element: "
|
||||
<< child.toElement().tagName()
|
||||
<< ", Ignored.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void XmlCategoryParser::parseCategoryNode( const QDomElement &node )
|
||||
{
|
||||
QString id = XmlUtil::getStringAttr( node, "id", "" );
|
||||
QString name = XmlUtil::getI18nAttr( node, "name", "" );
|
||||
|
||||
Category *category = new Category( id, name );
|
||||
if ( category != NULL )
|
||||
{
|
||||
Db::registerCategory( category );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/* XmlCategoryParser.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_XmlCategoryParser_h
|
||||
#define glabels_XmlCategoryParser_h
|
||||
|
||||
|
||||
#include <QDomElement>
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class XmlCategoryParser
|
||||
{
|
||||
public:
|
||||
XmlCategoryParser() {}
|
||||
|
||||
bool readFile( const QString &fileName );
|
||||
|
||||
private:
|
||||
void parseRootNode( const QDomElement &node );
|
||||
void parseCategoryNode( const QDomElement &node );
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_XmlCategoryParser_h
|
||||
@@ -36,13 +36,11 @@
|
||||
#include "LabelModelLineObject.h"
|
||||
#include "LabelModelImageObject.h"
|
||||
#include "LabelModelTextObject.h"
|
||||
#include "XmlTemplateCreator.h"
|
||||
#include "XmlUtil.h"
|
||||
|
||||
#include "Merge/None.h"
|
||||
|
||||
#include "libglabels/XmlTemplateCreator.h"
|
||||
#include "libglabels/XmlUtil.h"
|
||||
|
||||
|
||||
|
||||
void
|
||||
XmlLabelCreator::writeFile( const LabelModel* label, const QString& fileName )
|
||||
|
||||
@@ -38,12 +38,11 @@
|
||||
#include "LabelModelImageObject.h"
|
||||
#include "LabelModelLineObject.h"
|
||||
#include "LabelModelTextObject.h"
|
||||
#include "XmlTemplateParser.h"
|
||||
#include "XmlUtil.h"
|
||||
|
||||
#include "Merge/Factory.h"
|
||||
|
||||
#include "libglabels/XmlTemplateParser.h"
|
||||
#include "libglabels/XmlUtil.h"
|
||||
|
||||
|
||||
LabelModel*
|
||||
XmlLabelParser::readFile( const QString& fileName )
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
/* XmlPaperParser.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 "XmlPaperParser.h"
|
||||
|
||||
|
||||
#include <QDomDocument>
|
||||
#include <QDomNode>
|
||||
#include <QFile>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "Db.h"
|
||||
#include "Paper.h"
|
||||
#include "XmlUtil.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
bool XmlPaperParser::readFile( const QString &fileName )
|
||||
{
|
||||
QFile file( fileName );
|
||||
|
||||
if ( !file.open( QFile::ReadOnly | QFile::Text) )
|
||||
{
|
||||
qWarning() << "Error: Cannot read file " << fileName
|
||||
<< ": " << file.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
QDomDocument doc;
|
||||
QString errorString;
|
||||
int errorLine;
|
||||
int errorColumn;
|
||||
|
||||
if ( !doc.setContent( &file, false, &errorString, &errorLine, &errorColumn ) )
|
||||
{
|
||||
qWarning() << "Error: Parse error at line " << errorLine
|
||||
<< "column " << errorColumn
|
||||
<< ": " << errorString;
|
||||
return false;
|
||||
}
|
||||
|
||||
QDomElement root = doc.documentElement();
|
||||
if ( root.tagName() != "Glabels-paper-sizes" )
|
||||
{
|
||||
qWarning() << "Error: Not a Glabels-paper-sizes file.";
|
||||
return false;
|
||||
}
|
||||
|
||||
parseRootNode( root );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void XmlPaperParser::parseRootNode( const QDomElement &node )
|
||||
{
|
||||
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
|
||||
{
|
||||
if ( child.toElement().tagName() == "Paper-size" )
|
||||
{
|
||||
parsePaperSizeNode( child.toElement() );
|
||||
}
|
||||
else if ( !child.isComment() )
|
||||
{
|
||||
qWarning() << "Warning: bad element: "
|
||||
<< child.toElement().tagName()
|
||||
<< ", Ignored.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void XmlPaperParser::parsePaperSizeNode( const QDomElement &node )
|
||||
{
|
||||
QString id = XmlUtil::getStringAttr( node, "id", "" );
|
||||
QString name = XmlUtil::getI18nAttr( node, "name", "" );
|
||||
|
||||
Distance width = XmlUtil::getLengthAttr( node, "width", Distance(0) );
|
||||
Distance height = XmlUtil::getLengthAttr( node, "height", Distance(0) );
|
||||
|
||||
QString pwgSize = XmlUtil::getStringAttr( node, "pwg_size", "" );
|
||||
|
||||
Paper *paper = new Paper( id, name, width, height, pwgSize );
|
||||
if ( paper != NULL )
|
||||
{
|
||||
Db::registerPaper( paper );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/* XmlPaperParser.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_XmlPaperParser_h
|
||||
#define glabels_XmlPaperParser_h
|
||||
|
||||
|
||||
#include <QString>
|
||||
#include <QDomElement>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class XmlPaperParser
|
||||
{
|
||||
public:
|
||||
XmlPaperParser() {}
|
||||
|
||||
bool readFile( const QString &fileName );
|
||||
|
||||
private:
|
||||
void parseRootNode( const QDomElement &node );
|
||||
void parsePaperSizeNode( const QDomElement &node );
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_XmlPaperParser_h
|
||||
@@ -0,0 +1,335 @@
|
||||
/* XmlTemplateCreator.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 "XmlTemplateCreator.h"
|
||||
|
||||
|
||||
#include <QDomNode>
|
||||
#include <QFile>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "Db.h"
|
||||
#include "Template.h"
|
||||
#include "XmlUtil.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
bool XmlTemplateCreator::writeTemplates( const QList<const Template*> tmplates, const QString &fileName )
|
||||
{
|
||||
QDomDocument doc( "Glabels-templates" );
|
||||
QDomElement root = doc.createElement( "Glabels-templates" );
|
||||
doc.appendChild( root );
|
||||
|
||||
foreach ( const Template* tmplate, tmplates )
|
||||
{
|
||||
createTemplateNode( root, tmplate );
|
||||
}
|
||||
|
||||
QFile file( fileName );
|
||||
|
||||
if ( !file.open( QFile::WriteOnly | QFile::Text) )
|
||||
{
|
||||
qWarning() << "Error: Cannot open file " << fileName
|
||||
<< ": " << file.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if ( file.write( doc.toByteArray() ) < 0 )
|
||||
{
|
||||
qWarning() << "Error: Cannot write file " << fileName
|
||||
<< ": " << file.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool XmlTemplateCreator::writeTemplate( const Template* tmplate, const QString& fileName )
|
||||
{
|
||||
QList<const Template*> tmplates;
|
||||
|
||||
tmplates.append(tmplate);
|
||||
|
||||
return writeTemplates( tmplates, fileName );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateCreator::createTemplateNode( QDomElement &parent, const Template* tmplate )
|
||||
{
|
||||
QDomDocument doc = parent.ownerDocument();
|
||||
QDomElement node = doc.createElement( "Template" );
|
||||
parent.appendChild( node );
|
||||
|
||||
XmlUtil::setStringAttr( node, "brand", tmplate->brand() );
|
||||
XmlUtil::setStringAttr( node, "part", tmplate->part() );
|
||||
|
||||
XmlUtil::setStringAttr( node, "size", tmplate->paperId() );
|
||||
if ( tmplate->isSizeOther() )
|
||||
{
|
||||
XmlUtil::setLengthAttr( node, "width", tmplate->pageWidth() );
|
||||
XmlUtil::setLengthAttr( node, "height", tmplate->pageWidth() );
|
||||
}
|
||||
|
||||
|
||||
XmlUtil::setStringAttr( node, "description", tmplate->description() );
|
||||
|
||||
if ( !tmplate->productUrl().isEmpty() )
|
||||
{
|
||||
createMetaNode( node, "product_url", tmplate->productUrl() );
|
||||
}
|
||||
#if TODO
|
||||
foreach ( QString categoryId, tmplate->categoryIds() )
|
||||
{
|
||||
createMetaNode( node, "category", categoryId );
|
||||
}
|
||||
#endif
|
||||
|
||||
foreach ( Frame* frame, tmplate->frames() )
|
||||
{
|
||||
createLabelNode( node, frame );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateCreator::createMetaNode( QDomElement &parent, const QString& attr, const QString& value )
|
||||
{
|
||||
QDomDocument doc = parent.ownerDocument();
|
||||
QDomElement node = doc.createElement( "Meta" );
|
||||
parent.appendChild( node );
|
||||
|
||||
XmlUtil::setStringAttr( node, attr, value );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateCreator::createLabelNode( QDomElement &parent, const Frame* frame )
|
||||
{
|
||||
if ( const FrameRect* frameRect = dynamic_cast<const FrameRect*>(frame) )
|
||||
{
|
||||
createLabelRectangleNode( parent, frameRect );
|
||||
}
|
||||
else if ( const FrameEllipse* frameEllipse = dynamic_cast<const FrameEllipse*>(frame) )
|
||||
{
|
||||
createLabelEllipseNode( parent, frameEllipse );
|
||||
}
|
||||
else if ( const FrameRound* frameRound = dynamic_cast<const FrameRound*>(frame) )
|
||||
{
|
||||
createLabelRoundNode( parent, frameRound );
|
||||
}
|
||||
else if ( const FrameCd* frameCd = dynamic_cast<const FrameCd*>(frame) )
|
||||
{
|
||||
createLabelCdNode( parent, frameCd );
|
||||
}
|
||||
else
|
||||
{
|
||||
Q_ASSERT_X( false, "XmlTemplateCreator::createLabelNode", "Invalid frame type." );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateCreator::createLabelRectangleNode( QDomElement &parent, const FrameRect* frame )
|
||||
{
|
||||
QDomDocument doc = parent.ownerDocument();
|
||||
QDomElement node = doc.createElement( "Label-rectangle" );
|
||||
parent.appendChild( node );
|
||||
|
||||
XmlUtil::setStringAttr( node, "id", frame->id() );
|
||||
XmlUtil::setLengthAttr( node, "width", frame->w() );
|
||||
XmlUtil::setLengthAttr( node, "height", frame->h() );
|
||||
XmlUtil::setLengthAttr( node, "round", frame->r() );
|
||||
XmlUtil::setLengthAttr( node, "x_waste", frame->xWaste() );
|
||||
XmlUtil::setLengthAttr( node, "y_waste", frame->yWaste() );
|
||||
|
||||
createLabelNodeCommon( node, frame );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateCreator::createLabelEllipseNode( QDomElement &parent, const FrameEllipse* frame )
|
||||
{
|
||||
QDomDocument doc = parent.ownerDocument();
|
||||
QDomElement node = doc.createElement( "Label-ellipse" );
|
||||
parent.appendChild( node );
|
||||
|
||||
XmlUtil::setStringAttr( node, "id", frame->id() );
|
||||
XmlUtil::setLengthAttr( node, "width", frame->w() );
|
||||
XmlUtil::setLengthAttr( node, "height", frame->h() );
|
||||
XmlUtil::setLengthAttr( node, "waste", frame->waste() );
|
||||
|
||||
createLabelNodeCommon( node, frame );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateCreator::createLabelRoundNode( QDomElement &parent, const FrameRound* frame )
|
||||
{
|
||||
QDomDocument doc = parent.ownerDocument();
|
||||
QDomElement node = doc.createElement( "Label-round" );
|
||||
parent.appendChild( node );
|
||||
|
||||
XmlUtil::setStringAttr( node, "id", frame->id() );
|
||||
XmlUtil::setLengthAttr( node, "radius", frame->r() );
|
||||
XmlUtil::setLengthAttr( node, "waste", frame->waste() );
|
||||
|
||||
createLabelNodeCommon( node, frame );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateCreator::createLabelCdNode( QDomElement &parent, const FrameCd* frame )
|
||||
{
|
||||
QDomDocument doc = parent.ownerDocument();
|
||||
QDomElement node = doc.createElement( "Label-cd" );
|
||||
parent.appendChild( node );
|
||||
|
||||
XmlUtil::setStringAttr( node, "id", frame->id() );
|
||||
XmlUtil::setLengthAttr( node, "radius", frame->r1() );
|
||||
XmlUtil::setLengthAttr( node, "hole", frame->r2() );
|
||||
XmlUtil::setLengthAttr( node, "waste", frame->waste() );
|
||||
if ( frame->w() != Distance(0) )
|
||||
{
|
||||
XmlUtil::setLengthAttr( node, "width", frame->w() );
|
||||
}
|
||||
if ( frame->h() != Distance(0) )
|
||||
{
|
||||
XmlUtil::setLengthAttr( node, "height", frame->h() );
|
||||
}
|
||||
|
||||
createLabelNodeCommon( node, frame );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateCreator::createLabelNodeCommon( QDomElement &node, const Frame *frame )
|
||||
{
|
||||
foreach ( Markup* markup, frame->markups() )
|
||||
{
|
||||
if ( MarkupMargin* markupMargin = dynamic_cast<MarkupMargin*>(markup) )
|
||||
{
|
||||
createMarkupMarginNode( node, markupMargin );
|
||||
}
|
||||
else if ( MarkupLine* markupLine = dynamic_cast<MarkupLine*>(markup) )
|
||||
{
|
||||
createMarkupLineNode( node, markupLine );
|
||||
}
|
||||
else if ( MarkupCircle* markupCircle = dynamic_cast<MarkupCircle*>(markup) )
|
||||
{
|
||||
createMarkupCircleNode( node, markupCircle );
|
||||
}
|
||||
else if ( MarkupRect* markupRect = dynamic_cast<MarkupRect*>(markup) )
|
||||
{
|
||||
createMarkupRectNode( node, markupRect );
|
||||
}
|
||||
else if ( MarkupEllipse* markupEllipse = dynamic_cast<MarkupEllipse*>(markup) )
|
||||
{
|
||||
createMarkupEllipseNode( node, markupEllipse );
|
||||
}
|
||||
else
|
||||
{
|
||||
Q_ASSERT_X( false, "XmlTemplateCreator::createLabelNodeCommon", "Invalid markup type." );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( Layout* layout, frame->layouts() )
|
||||
{
|
||||
createLayoutNode( node, layout );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateCreator::createLayoutNode( QDomElement& parent, const Layout* layout )
|
||||
{
|
||||
QDomDocument doc = parent.ownerDocument();
|
||||
QDomElement node = doc.createElement( "Layout" );
|
||||
parent.appendChild( node );
|
||||
|
||||
XmlUtil::setIntAttr( node, "nx", layout->nx() );
|
||||
XmlUtil::setIntAttr( node, "ny", layout->ny() );
|
||||
|
||||
XmlUtil::setLengthAttr( node, "x0", layout->x0() );
|
||||
XmlUtil::setLengthAttr( node, "y0", layout->y0() );
|
||||
|
||||
XmlUtil::setLengthAttr( node, "dx", layout->dx() );
|
||||
XmlUtil::setLengthAttr( node, "dy", layout->dy() );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateCreator::createMarkupMarginNode( QDomElement& parent, const MarkupMargin* markup )
|
||||
{
|
||||
QDomDocument doc = parent.ownerDocument();
|
||||
QDomElement node = doc.createElement( "Markup-margin" );
|
||||
parent.appendChild( node );
|
||||
|
||||
XmlUtil::setLengthAttr( node, "size", markup->size() );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateCreator::createMarkupLineNode( QDomElement& parent, const MarkupLine* markup )
|
||||
{
|
||||
QDomDocument doc = parent.ownerDocument();
|
||||
QDomElement node = doc.createElement( "Markup-line" );
|
||||
parent.appendChild( node );
|
||||
|
||||
XmlUtil::setLengthAttr( node, "x1", markup->x1() );
|
||||
XmlUtil::setLengthAttr( node, "y1", markup->y1() );
|
||||
XmlUtil::setLengthAttr( node, "x2", markup->x2() );
|
||||
XmlUtil::setLengthAttr( node, "y2", markup->y2() );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateCreator::createMarkupCircleNode( QDomElement& parent, const MarkupCircle* markup )
|
||||
{
|
||||
QDomDocument doc = parent.ownerDocument();
|
||||
QDomElement node = doc.createElement( "Markup-circle" );
|
||||
parent.appendChild( node );
|
||||
|
||||
XmlUtil::setLengthAttr( node, "x0", markup->x0() );
|
||||
XmlUtil::setLengthAttr( node, "y0", markup->y0() );
|
||||
XmlUtil::setLengthAttr( node, "radius", markup->r() );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateCreator::createMarkupRectNode( QDomElement& parent, const MarkupRect* markup )
|
||||
{
|
||||
QDomDocument doc = parent.ownerDocument();
|
||||
QDomElement node = doc.createElement( "Markup-rect" );
|
||||
parent.appendChild( node );
|
||||
|
||||
XmlUtil::setLengthAttr( node, "x1", markup->x1() );
|
||||
XmlUtil::setLengthAttr( node, "y1", markup->y1() );
|
||||
XmlUtil::setLengthAttr( node, "w", markup->w() );
|
||||
XmlUtil::setLengthAttr( node, "h", markup->h() );
|
||||
XmlUtil::setLengthAttr( node, "r", markup->r() );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateCreator::createMarkupEllipseNode( QDomElement& parent, const MarkupEllipse* markup )
|
||||
{
|
||||
QDomDocument doc = parent.ownerDocument();
|
||||
QDomElement node = doc.createElement( "Markup-ellipse" );
|
||||
parent.appendChild( node );
|
||||
|
||||
XmlUtil::setLengthAttr( node, "x1", markup->x1() );
|
||||
XmlUtil::setLengthAttr( node, "y1", markup->y1() );
|
||||
XmlUtil::setLengthAttr( node, "w", markup->w() );
|
||||
XmlUtil::setLengthAttr( node, "h", markup->h() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/* XmlTemplateCreator.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_XmlTemplateCreator_h
|
||||
#define glabels_XmlTemplateCreator_h
|
||||
|
||||
|
||||
#include <QDomElement>
|
||||
#include <QString>
|
||||
|
||||
#include "FrameCd.h"
|
||||
#include "FrameEllipse.h"
|
||||
#include "FrameRect.h"
|
||||
#include "FrameRound.h"
|
||||
#include "Layout.h"
|
||||
#include "Markup.h"
|
||||
#include "Template.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class XmlTemplateCreator
|
||||
{
|
||||
public:
|
||||
XmlTemplateCreator() {}
|
||||
|
||||
bool writeTemplates( const QList<const Template*> tmplates, const QString& fileName );
|
||||
bool writeTemplate( const Template* tmplate, const QString& fileName );
|
||||
void createTemplateNode( QDomElement& parent, const Template* tmplate );
|
||||
|
||||
private:
|
||||
void createMetaNode( QDomElement& parent, const QString& attr, const QString& value );
|
||||
void createLabelNode( QDomElement& parent, const Frame* frame );
|
||||
void createLabelRectangleNode( QDomElement& parent, const FrameRect* frame );
|
||||
void createLabelEllipseNode( QDomElement& parent, const FrameEllipse* frame );
|
||||
void createLabelRoundNode( QDomElement& parent, const FrameRound* frame );
|
||||
void createLabelCdNode( QDomElement& parent, const FrameCd* frame );
|
||||
void createLabelNodeCommon( QDomElement& node, const Frame* frame );
|
||||
void createLayoutNode( QDomElement& parent, const Layout* layout );
|
||||
void createMarkupMarginNode( QDomElement& parent, const MarkupMargin* markupMargin );
|
||||
void createMarkupLineNode( QDomElement& parent, const MarkupLine* markupLine );
|
||||
void createMarkupCircleNode( QDomElement& parent, const MarkupCircle* markupCircle );
|
||||
void createMarkupRectNode( QDomElement& parent, const MarkupRect* markupRect );
|
||||
void createMarkupEllipseNode( QDomElement& parent, const MarkupEllipse* markupEllipse );
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_XmlTemplateCreator_h
|
||||
@@ -0,0 +1,410 @@
|
||||
/* XmlTemplateParser.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 "XmlTemplateParser.h"
|
||||
|
||||
|
||||
#include <QFile>
|
||||
#include <QDomDocument>
|
||||
#include <QDomNode>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "Db.h"
|
||||
#include "FrameRect.h"
|
||||
#include "FrameCd.h"
|
||||
#include "FrameRound.h"
|
||||
#include "FrameEllipse.h"
|
||||
#include "Layout.h"
|
||||
#include "Markup.h"
|
||||
#include "Template.h"
|
||||
#include "XmlUtil.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
bool XmlTemplateParser::readFile( const QString &fileName )
|
||||
{
|
||||
QFile file( fileName );
|
||||
|
||||
if ( !file.open( QFile::ReadOnly | QFile::Text) )
|
||||
{
|
||||
qWarning() << "Error: Cannot read file " << fileName
|
||||
<< ": " << file.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
QDomDocument doc;
|
||||
QString errorString;
|
||||
int errorLine;
|
||||
int errorColumn;
|
||||
|
||||
if ( !doc.setContent( &file, false, &errorString, &errorLine, &errorColumn ) )
|
||||
{
|
||||
qWarning() << "Error: Parse error at line " << errorLine
|
||||
<< "column " << errorColumn
|
||||
<< ": " << errorString;
|
||||
return false;
|
||||
}
|
||||
|
||||
QDomElement root = doc.documentElement();
|
||||
if ( root.tagName() != "Glabels-templates" )
|
||||
{
|
||||
qWarning() << "Error: Not a Glabels-templates file";
|
||||
return false;
|
||||
}
|
||||
|
||||
parseRootNode( root );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateParser::parseRootNode( const QDomElement &node )
|
||||
{
|
||||
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
|
||||
{
|
||||
if ( child.toElement().tagName() == "Template" )
|
||||
{
|
||||
Template *tmplate = parseTemplateNode( child.toElement() );
|
||||
if ( tmplate != NULL )
|
||||
{
|
||||
Db::registerTemplate( tmplate );
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Warning: could not create template, Ignored.";
|
||||
}
|
||||
}
|
||||
else if ( !child.isComment() )
|
||||
{
|
||||
qWarning() << "Warning: bad element: "
|
||||
<< child.toElement().tagName()
|
||||
<< ", Ignored.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Template *XmlTemplateParser::parseTemplateNode( const QDomElement &node )
|
||||
{
|
||||
QString brand = XmlUtil::getStringAttr( node, "brand", "" );
|
||||
QString part = XmlUtil::getStringAttr( node, "part", "" );
|
||||
|
||||
if ( (brand == "") || (part == "") )
|
||||
{
|
||||
// Try the deprecated "name" attribute.
|
||||
QString name = XmlUtil::getStringAttr( node, "name", "" );
|
||||
if ( name != "" )
|
||||
{
|
||||
QStringList fields = name.split( " ", QString::SkipEmptyParts );
|
||||
brand = fields[0];
|
||||
part = fields[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Error: missing name or brand/part attributes.";
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Template *tmplate = NULL;
|
||||
|
||||
QString equivPart = XmlUtil::getStringAttr( node, "equiv", "" );
|
||||
if ( equivPart != NULL )
|
||||
{
|
||||
tmplate = Template::fromEquiv( brand, part, equivPart );
|
||||
|
||||
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
|
||||
{
|
||||
if ( child.toElement().tagName() == "Meta" )
|
||||
{
|
||||
parseMetaNode( child.toElement(), tmplate );
|
||||
}
|
||||
else if ( !child.isComment() )
|
||||
{
|
||||
qWarning() << "Warning: bad element: "
|
||||
<< child.toElement().tagName()
|
||||
<< ", Ignored.";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QString description = XmlUtil::getI18nAttr( node, "description", "" );
|
||||
QString paperId = XmlUtil::getStringAttr( node, "size", "" );
|
||||
|
||||
if ( !Db::isPaperIdOther( paperId ) )
|
||||
{
|
||||
const Paper *paper = Db::lookupPaperFromId( paperId );
|
||||
if ( paper == NULL )
|
||||
{
|
||||
qWarning() << "Error: unknown paper ID: " << paperId;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tmplate = new Template( brand, part, description,
|
||||
paper->id(), paper->width(), paper->height() );
|
||||
}
|
||||
else
|
||||
{
|
||||
Distance width = XmlUtil::getLengthAttr( node, "width", Distance(0) );
|
||||
Distance height = XmlUtil::getLengthAttr( node, "height", Distance(0) );
|
||||
|
||||
tmplate = new Template( brand, part, description, paperId, width, height );
|
||||
}
|
||||
|
||||
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
|
||||
{
|
||||
if ( child.toElement().tagName() == "Meta" )
|
||||
{
|
||||
parseMetaNode( child.toElement(), tmplate );
|
||||
}
|
||||
else if ( child.toElement().tagName() == "Label-rectangle" )
|
||||
{
|
||||
parseLabelRectangleNode( child.toElement(), tmplate );
|
||||
}
|
||||
else if ( child.toElement().tagName() == "Label-ellipse" )
|
||||
{
|
||||
parseLabelEllipseNode( child.toElement(), tmplate );
|
||||
}
|
||||
else if ( child.toElement().tagName() == "Label-round" )
|
||||
{
|
||||
parseLabelRoundNode( child.toElement(), tmplate );
|
||||
}
|
||||
else if ( child.toElement().tagName() == "Label-cd" )
|
||||
{
|
||||
parseLabelCdNode( child.toElement(), tmplate );
|
||||
}
|
||||
else if ( !child.isComment() )
|
||||
{
|
||||
qWarning() << "Warning: bad element: "
|
||||
<< child.toElement().tagName()
|
||||
<< ", Ignored.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tmplate;
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateParser::parseMetaNode( const QDomElement &node, Template *tmplate )
|
||||
{
|
||||
QString productUrl = XmlUtil::getStringAttr( node, "product_url", "" );
|
||||
if ( productUrl != "" )
|
||||
{
|
||||
tmplate->setProductUrl( productUrl );
|
||||
}
|
||||
|
||||
QString categoryId = XmlUtil::getStringAttr( node, "category", "" );
|
||||
if ( categoryId != "" )
|
||||
{
|
||||
tmplate->addCategory( categoryId );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateParser::parseLabelRectangleNode( const QDomElement &node, Template *tmplate )
|
||||
{
|
||||
QString id = XmlUtil::getStringAttr( node, "id", "0" );
|
||||
|
||||
Distance w = XmlUtil::getLengthAttr( node, "width", Distance(0) );
|
||||
Distance h = XmlUtil::getLengthAttr( node, "height", Distance(0) );
|
||||
Distance r = XmlUtil::getLengthAttr( node, "round", Distance(0) );
|
||||
|
||||
Distance xWaste, yWaste;
|
||||
|
||||
Distance waste = XmlUtil::getLengthAttr( node, "waste", Distance(-1) );
|
||||
if ( waste >= Distance(0) )
|
||||
{
|
||||
xWaste = waste;
|
||||
yWaste = waste;
|
||||
}
|
||||
else
|
||||
{
|
||||
xWaste = XmlUtil::getLengthAttr( node, "x_waste", Distance(0) );
|
||||
yWaste = XmlUtil::getLengthAttr( node, "y_waste", Distance(0) );
|
||||
}
|
||||
|
||||
Frame *frame = new FrameRect( w, h, r, xWaste, yWaste, id );
|
||||
|
||||
parseLabelNodeCommon( node, frame );
|
||||
|
||||
tmplate->addFrame( frame );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateParser::parseLabelEllipseNode( const QDomElement &node, Template *tmplate )
|
||||
{
|
||||
QString id = XmlUtil::getStringAttr( node, "id", "0" );
|
||||
|
||||
Distance w = XmlUtil::getLengthAttr( node, "width", Distance(0) );
|
||||
Distance h = XmlUtil::getLengthAttr( node, "height", Distance(0) );
|
||||
Distance waste = XmlUtil::getLengthAttr( node, "waste", Distance(0) );
|
||||
|
||||
Frame *frame = new FrameEllipse( w, h, waste, id );
|
||||
|
||||
parseLabelNodeCommon( node, frame );
|
||||
|
||||
tmplate->addFrame( frame );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateParser::parseLabelRoundNode( const QDomElement &node, Template *tmplate )
|
||||
{
|
||||
QString id = XmlUtil::getStringAttr( node, "id", "0" );
|
||||
|
||||
Distance r = XmlUtil::getLengthAttr( node, "radius", Distance(0) );
|
||||
Distance waste = XmlUtil::getLengthAttr( node, "waste", Distance(0) );
|
||||
|
||||
Frame *frame = new FrameRound( r, waste, id );
|
||||
|
||||
parseLabelNodeCommon( node, frame );
|
||||
|
||||
tmplate->addFrame( frame );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateParser::parseLabelCdNode( const QDomElement &node, Template *tmplate )
|
||||
{
|
||||
QString id = XmlUtil::getStringAttr( node, "id", "0" );
|
||||
|
||||
Distance r1 = XmlUtil::getLengthAttr( node, "radius", Distance(0) );
|
||||
Distance r2 = XmlUtil::getLengthAttr( node, "hole", Distance(0) );
|
||||
Distance w = XmlUtil::getLengthAttr( node, "width", Distance(0) );
|
||||
Distance h = XmlUtil::getLengthAttr( node, "height", Distance(0) );
|
||||
Distance waste = XmlUtil::getLengthAttr( node, "waste", Distance(0) );
|
||||
|
||||
Frame *frame = new FrameCd( r1, r2, w, h, waste, id );
|
||||
|
||||
parseLabelNodeCommon( node, frame );
|
||||
|
||||
tmplate->addFrame( frame );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateParser::parseLabelNodeCommon( const QDomElement &node, Frame *frame )
|
||||
{
|
||||
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
|
||||
{
|
||||
if ( child.toElement().tagName() == "Layout" )
|
||||
{
|
||||
parseLayoutNode( child.toElement(), frame );
|
||||
}
|
||||
else if ( child.toElement().tagName() == "Markup-margin" )
|
||||
{
|
||||
parseMarkupMarginNode( child.toElement(), frame );
|
||||
}
|
||||
else if ( child.toElement().tagName() == "Markup-line" )
|
||||
{
|
||||
parseMarkupLineNode( child.toElement(), frame );
|
||||
}
|
||||
else if ( child.toElement().tagName() == "Markup-circle" )
|
||||
{
|
||||
parseMarkupCircleNode( child.toElement(), frame );
|
||||
}
|
||||
else if ( child.toElement().tagName() == "Markup-rect" )
|
||||
{
|
||||
parseMarkupRectNode( child.toElement(), frame );
|
||||
}
|
||||
else if ( child.toElement().tagName() == "Markup-ellipse" )
|
||||
{
|
||||
parseMarkupEllipseNode( child.toElement(), frame );
|
||||
}
|
||||
else if ( !child.isComment() )
|
||||
{
|
||||
qWarning() << "Warning: bad element: "
|
||||
<< child.toElement().tagName()
|
||||
<< ", Ignored.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateParser::parseLayoutNode( const QDomElement &node, Frame *frame )
|
||||
{
|
||||
int nX = XmlUtil::getIntAttr( node, "nx", 1 );
|
||||
int nY = XmlUtil::getIntAttr( node, "ny", 1 );
|
||||
|
||||
Distance x0 = XmlUtil::getLengthAttr( node, "x0", Distance(0) );
|
||||
Distance y0 = XmlUtil::getLengthAttr( node, "y0", Distance(0) );
|
||||
|
||||
Distance dX = XmlUtil::getLengthAttr( node, "dx", Distance(0) );
|
||||
Distance dY = XmlUtil::getLengthAttr( node, "dy", Distance(0) );
|
||||
|
||||
frame->addLayout( new Layout( nX, nY, x0, y0, dX, dY ) );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateParser::parseMarkupMarginNode( const QDomElement &node, Frame *frame )
|
||||
{
|
||||
Distance size = XmlUtil::getLengthAttr( node, "size", Distance(0) );
|
||||
|
||||
frame->addMarkup( new MarkupMargin( frame, size ) );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateParser::parseMarkupLineNode( const QDomElement &node, Frame *frame )
|
||||
{
|
||||
Distance x1 = XmlUtil::getLengthAttr( node, "x1", Distance(0) );
|
||||
Distance y1 = XmlUtil::getLengthAttr( node, "y1", Distance(0) );
|
||||
Distance x2 = XmlUtil::getLengthAttr( node, "x2", Distance(0) );
|
||||
Distance y2 = XmlUtil::getLengthAttr( node, "y2", Distance(0) );
|
||||
|
||||
frame->addMarkup( new MarkupLine( x1, y1, x2, y2 ) );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateParser::parseMarkupCircleNode( const QDomElement &node, Frame *frame )
|
||||
{
|
||||
Distance x0 = XmlUtil::getLengthAttr( node, "x0", Distance(0) );
|
||||
Distance y0 = XmlUtil::getLengthAttr( node, "y0", Distance(0) );
|
||||
Distance r = XmlUtil::getLengthAttr( node, "radius", Distance(0) );
|
||||
|
||||
frame->addMarkup( new MarkupCircle( x0, y0, r ) );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateParser::parseMarkupRectNode( const QDomElement &node, Frame *frame )
|
||||
{
|
||||
Distance x1 = XmlUtil::getLengthAttr( node, "x1", Distance(0) );
|
||||
Distance y1 = XmlUtil::getLengthAttr( node, "y1", Distance(0) );
|
||||
Distance w = XmlUtil::getLengthAttr( node, "w", Distance(0) );
|
||||
Distance h = XmlUtil::getLengthAttr( node, "h", Distance(0) );
|
||||
Distance r = XmlUtil::getLengthAttr( node, "r", Distance(0) );
|
||||
|
||||
frame->addMarkup( new MarkupRect( x1, y1, w, h, r ) );
|
||||
}
|
||||
|
||||
|
||||
void XmlTemplateParser::parseMarkupEllipseNode( const QDomElement &node, Frame *frame )
|
||||
{
|
||||
Distance x1 = XmlUtil::getLengthAttr( node, "x1", Distance(0) );
|
||||
Distance y1 = XmlUtil::getLengthAttr( node, "y1", Distance(0) );
|
||||
Distance w = XmlUtil::getLengthAttr( node, "w", Distance(0) );
|
||||
Distance h = XmlUtil::getLengthAttr( node, "h", Distance(0) );
|
||||
|
||||
frame->addMarkup( new MarkupEllipse( x1, y1, w, h ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/* XmlTemplateParser.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_XmlTemplateParser_h
|
||||
#define glabels_XmlTemplateParser_h
|
||||
|
||||
|
||||
#include <QDomElement>
|
||||
#include <QString>
|
||||
|
||||
#include "Template.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class XmlTemplateParser
|
||||
{
|
||||
public:
|
||||
XmlTemplateParser() {}
|
||||
|
||||
bool readFile( const QString &fileName );
|
||||
Template *parseTemplateNode( const QDomElement &node );
|
||||
|
||||
private:
|
||||
void parseRootNode( const QDomElement &node );
|
||||
void parseMetaNode( const QDomElement &node, Template *tmplate );
|
||||
void parseLabelRectangleNode( const QDomElement &node, Template *tmplate );
|
||||
void parseLabelEllipseNode( const QDomElement &node, Template *tmplate );
|
||||
void parseLabelRoundNode( const QDomElement &node, Template *tmplate );
|
||||
void parseLabelCdNode( const QDomElement &node, Template *tmplate );
|
||||
void parseLabelNodeCommon( const QDomElement &node, Frame *frame );
|
||||
void parseLayoutNode( const QDomElement &node, Frame *frame );
|
||||
void parseMarkupMarginNode( const QDomElement &node, Frame *frame );
|
||||
void parseMarkupLineNode( const QDomElement &node, Frame *frame );
|
||||
void parseMarkupCircleNode( const QDomElement &node, Frame *frame );
|
||||
void parseMarkupRectNode( const QDomElement &node, Frame *frame );
|
||||
void parseMarkupEllipseNode( const QDomElement &node, Frame *frame );
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_XmlTemplateParser_h
|
||||
@@ -0,0 +1,291 @@
|
||||
/* XmlUtil.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 "XmlUtil.h"
|
||||
|
||||
|
||||
#include <QTextStream>
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
Units XmlUtil::mUnits;
|
||||
|
||||
|
||||
XmlUtil::XmlUtil()
|
||||
{
|
||||
mUnits = Units(Units::PT);
|
||||
}
|
||||
|
||||
|
||||
void XmlUtil::init()
|
||||
{
|
||||
static XmlUtil* xmlUtil = new XmlUtil();
|
||||
}
|
||||
|
||||
|
||||
Units XmlUtil::units()
|
||||
{
|
||||
init();
|
||||
|
||||
return mUnits;
|
||||
}
|
||||
|
||||
|
||||
void XmlUtil::setUnits( const Units& units )
|
||||
{
|
||||
init();
|
||||
|
||||
mUnits = units;
|
||||
}
|
||||
|
||||
|
||||
QString XmlUtil::getStringAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
const QString& default_value )
|
||||
{
|
||||
init();
|
||||
|
||||
return node.attribute( name, default_value );
|
||||
}
|
||||
|
||||
|
||||
double XmlUtil::getDoubleAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
double default_value )
|
||||
{
|
||||
init();
|
||||
|
||||
QString valueString = node.attribute( name, "" );
|
||||
if ( valueString != "" )
|
||||
{
|
||||
bool ok;
|
||||
double value = valueString.toDouble(& ok );
|
||||
|
||||
if ( !ok )
|
||||
{
|
||||
qWarning() << "Error: bad double value in attribute "
|
||||
<< node.tagName() << ":" << name << "=" << valueString;
|
||||
return default_value;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
return default_value;
|
||||
}
|
||||
|
||||
|
||||
bool XmlUtil::getBoolAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
bool default_value )
|
||||
{
|
||||
init();
|
||||
|
||||
QString valueString = node.attribute( name, "" );
|
||||
if ( valueString != "" )
|
||||
{
|
||||
int intValue = valueString.toInt();
|
||||
|
||||
if ( (valueString == "True") ||
|
||||
(valueString == "TRUE") ||
|
||||
(valueString == "true") ||
|
||||
(intValue == 1) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( (valueString == "False") ||
|
||||
(valueString == "FALSE") ||
|
||||
(valueString == "false") ||
|
||||
(intValue == 0) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
qWarning() << "Error: bad boolean value in attribute "
|
||||
<< node.tagName() << ":" << name << "=" << valueString;
|
||||
return default_value;
|
||||
}
|
||||
|
||||
return default_value;
|
||||
}
|
||||
|
||||
|
||||
int XmlUtil::getIntAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
int default_value )
|
||||
{
|
||||
init();
|
||||
|
||||
QString valueString = node.attribute( name, "" );
|
||||
if ( valueString != "" )
|
||||
{
|
||||
bool ok;
|
||||
int value = valueString.toInt(& ok );
|
||||
|
||||
if ( !ok )
|
||||
{
|
||||
qWarning() << "Error: bad integer value in attribute "
|
||||
<< node.tagName() << ":" << name << "=" << valueString;
|
||||
return default_value;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
return default_value;
|
||||
}
|
||||
|
||||
|
||||
uint32_t XmlUtil::getUIntAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
uint32_t default_value )
|
||||
{
|
||||
init();
|
||||
|
||||
QString valueString = node.attribute( name, "" );
|
||||
if ( valueString != "" )
|
||||
{
|
||||
bool ok;
|
||||
uint32_t value = valueString.toUInt(& ok, 0 );
|
||||
|
||||
if ( !ok )
|
||||
{
|
||||
qWarning() << "Error: bad unsigned integer value in attribute "
|
||||
<< node.tagName() << ":" << name << "=" << valueString;
|
||||
return default_value;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
return default_value;
|
||||
}
|
||||
|
||||
|
||||
QString XmlUtil::getI18nAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
const QString& default_value )
|
||||
{
|
||||
init();
|
||||
|
||||
// TODO: are translations done in a compatable way, so that we can use "_name" attributes?
|
||||
QString i18nString = node.attribute( QString("_").append(name), "" );
|
||||
|
||||
if ( i18nString == "" )
|
||||
{
|
||||
return node.attribute( name, default_value );
|
||||
}
|
||||
|
||||
return i18nString;
|
||||
}
|
||||
|
||||
|
||||
Distance XmlUtil::getLengthAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
const Distance& default_value )
|
||||
{
|
||||
init();
|
||||
|
||||
QString valueString = node.attribute( name, "" );
|
||||
if ( valueString != "" )
|
||||
{
|
||||
double value;
|
||||
QString unitsString;
|
||||
QTextStream valueStream( &valueString, QIODevice::ReadOnly );
|
||||
|
||||
valueStream >> value >> unitsString;
|
||||
|
||||
if ( !unitsString.isEmpty() && !Units::isIdValid( unitsString ) )
|
||||
{
|
||||
qWarning() << "Error: bad length value in attribute "
|
||||
<< node.tagName() << ":" << name << "=" << valueString;
|
||||
}
|
||||
|
||||
return Distance( value, unitsString );
|
||||
}
|
||||
|
||||
return default_value;
|
||||
}
|
||||
|
||||
|
||||
void XmlUtil::setStringAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
const QString& value )
|
||||
{
|
||||
init();
|
||||
|
||||
node.setAttribute( name, value );
|
||||
}
|
||||
|
||||
|
||||
void XmlUtil::setDoubleAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
double value )
|
||||
{
|
||||
init();
|
||||
|
||||
node.setAttribute( name, QString::number(value) );
|
||||
}
|
||||
|
||||
|
||||
void XmlUtil::setBoolAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
bool value )
|
||||
{
|
||||
init();
|
||||
|
||||
node.setAttribute( name, value ? "true" : "false" );
|
||||
}
|
||||
|
||||
|
||||
void XmlUtil::setIntAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
int value )
|
||||
{
|
||||
init();
|
||||
|
||||
node.setAttribute( name, QString::number(value) );
|
||||
}
|
||||
|
||||
|
||||
void XmlUtil::setUIntAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
uint32_t value )
|
||||
{
|
||||
init();
|
||||
|
||||
node.setAttribute( name, "0x" + QString::number(value, 16) );
|
||||
}
|
||||
|
||||
|
||||
void XmlUtil::setLengthAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
const Distance& value )
|
||||
{
|
||||
init();
|
||||
|
||||
node.setAttribute( name, QString::number(value.inUnits(mUnits)) + mUnits.toIdString() );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/* XmlUtil.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_XmlUtil_h
|
||||
#define glabels_XmlUtil_h
|
||||
|
||||
|
||||
#include <cstdint>
|
||||
#include <QDomElement>
|
||||
#include <QString>
|
||||
|
||||
#include "Distance.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class XmlUtil
|
||||
{
|
||||
private:
|
||||
XmlUtil();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
static void init();
|
||||
|
||||
static Units units();
|
||||
static void setUnits( const Units& units );
|
||||
|
||||
static QString getStringAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
const QString& default_value );
|
||||
|
||||
static double getDoubleAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
double default_value );
|
||||
|
||||
static bool getBoolAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
bool default_value );
|
||||
|
||||
static int getIntAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
int default_value );
|
||||
|
||||
static uint32_t getUIntAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
uint32_t default_value );
|
||||
|
||||
static QString getI18nAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
const QString& default_value );
|
||||
|
||||
static Distance getLengthAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
const Distance& default_value );
|
||||
|
||||
static void setStringAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
const QString& value );
|
||||
|
||||
static void setDoubleAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
double value );
|
||||
|
||||
static void setBoolAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
bool value );
|
||||
|
||||
static void setIntAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
int value );
|
||||
|
||||
static void setUIntAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
uint32_t value );
|
||||
|
||||
static void setLengthAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
const Distance& value );
|
||||
|
||||
private:
|
||||
static Units mUnits;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_XmlUtil_h
|
||||
@@ -0,0 +1,105 @@
|
||||
/* XmlVendorParser.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 "XmlVendorParser.h"
|
||||
|
||||
|
||||
#include <QDomDocument>
|
||||
#include <QDomNode>
|
||||
#include <QFile>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "Db.h"
|
||||
#include "Vendor.h"
|
||||
#include "XmlUtil.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
bool XmlVendorParser::readFile( const QString &fileName )
|
||||
{
|
||||
QFile file( fileName );
|
||||
|
||||
if ( !file.open( QFile::ReadOnly | QFile::Text) )
|
||||
{
|
||||
qWarning() << "Error: Cannot read file " << fileName
|
||||
<< ": " << file.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
QDomDocument doc;
|
||||
QString errorString;
|
||||
int errorLine;
|
||||
int errorColumn;
|
||||
|
||||
if ( !doc.setContent( &file, false, &errorString, &errorLine, &errorColumn ) )
|
||||
{
|
||||
qWarning() << "Error: Parse error at line " << errorLine
|
||||
<< "column " << errorColumn
|
||||
<< ": " << errorString;
|
||||
return false;
|
||||
}
|
||||
|
||||
QDomElement root = doc.documentElement();
|
||||
if ( root.tagName() != "Glabels-vendors" )
|
||||
{
|
||||
qWarning() << "Error: Not a Glabels-vendors file.";
|
||||
return false;
|
||||
}
|
||||
|
||||
parseRootNode( root );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void XmlVendorParser::parseRootNode( const QDomElement &node )
|
||||
{
|
||||
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
|
||||
{
|
||||
if ( child.toElement().tagName() == "Vendor" )
|
||||
{
|
||||
parseVendorNode( child.toElement() );
|
||||
}
|
||||
else if ( !child.isComment() )
|
||||
{
|
||||
qWarning() << "Warning: bad element: "
|
||||
<< child.toElement().tagName()
|
||||
<< ", Ignored.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void XmlVendorParser::parseVendorNode( const QDomElement &node )
|
||||
{
|
||||
QString name = XmlUtil::getStringAttr( node, "name", "" );
|
||||
QString url = XmlUtil::getStringAttr( node, "url", "" );
|
||||
|
||||
Vendor *vendor = new Vendor( name, url );
|
||||
if ( vendor != NULL )
|
||||
{
|
||||
Db::registerVendor( vendor );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/* XmlVendorParser.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_XmlVendorParser_h
|
||||
#define glabels_XmlVendorParser_h
|
||||
|
||||
|
||||
#include <QDomElement>
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class XmlVendorParser
|
||||
{
|
||||
public:
|
||||
XmlVendorParser() {}
|
||||
|
||||
bool readFile( const QString &fileName );
|
||||
|
||||
private:
|
||||
void parseRootNode( const QDomElement &node );
|
||||
void parseVendorNode( const QDomElement &node );
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_XmlVendorParser_h
|
||||
@@ -21,13 +21,12 @@
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include "Settings.h"
|
||||
#include "Db.h"
|
||||
#include "MainWindow.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#include "Merge/Factory.h"
|
||||
|
||||
#include "libglabels/Db.h"
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/* privateConstants.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_privateConstants_h
|
||||
#define glabels_privateConstants_h
|
||||
|
||||
|
||||
#include "Distance.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace Constants
|
||||
{
|
||||
|
||||
const Distance EPSILON( 0.5, Units::PT );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_privateConstants_h
|
||||
Reference in New Issue
Block a user