diff --git a/glabels/CMakeLists.txt b/glabels/CMakeLists.txt index 6755657..fd6d289 100644 --- a/glabels/CMakeLists.txt +++ b/glabels/CMakeLists.txt @@ -42,7 +42,6 @@ set (glabels_sources DataCache.cpp Db.cpp Distance.cpp - EnumUtil.cpp FieldButton.cpp File.cpp FileUtil.cpp diff --git a/glabels/EnumUtil.cpp b/glabels/EnumUtil.cpp deleted file mode 100644 index a6d4e50..0000000 --- a/glabels/EnumUtil.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* EnumUtil.cpp - * - * Copyright (C) 2015 Jim Evins - * - * 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 . - */ - -#include "EnumUtil.h" - - -namespace glabels -{ - - namespace EnumUtil - { - - QString weightToString( QFont::Weight weight ) - { - switch (weight) - { - case QFont::Bold: - return "bold"; - break; - default: - return "normal"; - break; - } - } - - - QFont::Weight stringToWeight( const QString& string ) - { - if ( string == "bold" ) - { - return QFont::Bold; - } - else - { - return QFont::Normal; - } - } - - - QString hAlignToString( Qt::Alignment align ) - { - switch (align) - { - case Qt::AlignRight: - return "right"; - break; - case Qt::AlignHCenter: - return "center"; - break; - default: - return "left"; - break; - } - } - - - Qt::Alignment stringToHAlign( const QString& string ) - { - if ( string == "right" ) - { - return Qt::AlignRight; - } - else if ( string == "center" ) - { - return Qt::AlignHCenter; - } - else - { - return Qt::AlignLeft; - } - } - - - QString vAlignToString( Qt::Alignment align ) - { - switch (align) - { - case Qt::AlignBottom: - return "bottom"; - break; - case Qt::AlignVCenter: - return "center"; - break; - default: - return "top"; - break; - } - } - - - Qt::Alignment stringToVAlign( const QString& string ) - { - if ( string == "bottom" ) - { - return Qt::AlignBottom; - } - else if ( string == "center" ) - { - return Qt::AlignVCenter; - } - else - { - return Qt::AlignTop; - } - } - - } - -} // namespace glabels diff --git a/glabels/EnumUtil.h b/glabels/EnumUtil.h deleted file mode 100644 index 2d40926..0000000 --- a/glabels/EnumUtil.h +++ /dev/null @@ -1,50 +0,0 @@ -/* FileUtil.h - * - * Copyright (C) 2015 Jim Evins - * - * 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 . - */ - -#ifndef EnumUtil_h -#define EnumUtil_h - - -#include -#include -#include - - -namespace glabels -{ - - namespace EnumUtil - { - - QString weightToString( QFont::Weight weight ); - QFont::Weight stringToWeight( const QString& string ); - - QString hAlignToString( Qt::Alignment align ); - Qt::Alignment stringToHAlign( const QString& string ); - - QString vAlignToString( Qt::Alignment align ); - Qt::Alignment stringToVAlign( const QString& string ); - - } - -} - - -#endif // EnumUtil_h diff --git a/glabels/XmlLabelCreator.cpp b/glabels/XmlLabelCreator.cpp index 4b19683..7b37685 100644 --- a/glabels/XmlLabelCreator.cpp +++ b/glabels/XmlLabelCreator.cpp @@ -20,7 +20,6 @@ #include "XmlLabelCreator.h" -#include "EnumUtil.h" #include "LabelModel.h" #include "LabelModelObject.h" #include "LabelModelBarcodeObject.h" @@ -332,14 +331,14 @@ namespace glabels /* font attrs */ XmlUtil::setStringAttr( node, "font_family", object->fontFamily() ); XmlUtil::setDoubleAttr( node, "font_size", object->fontSize() ); - XmlUtil::setStringAttr( node, "font_weight", EnumUtil::weightToString( object->fontWeight() ) ); + XmlUtil::setWeightAttr( node, "font_weight", object->fontWeight() ); XmlUtil::setBoolAttr( node, "font_italic", object->fontItalicFlag() ); XmlUtil::setBoolAttr( node, "font_underline", object->fontUnderlineFlag() ); /* text attrs */ XmlUtil::setDoubleAttr( node, "line_spacing", object->textLineSpacing() ); - XmlUtil::setStringAttr( node, "align", EnumUtil::hAlignToString( object->textHAlign() ) ); - XmlUtil::setStringAttr( node, "valign", EnumUtil::vAlignToString( object->textVAlign() ) ); + XmlUtil::setAlignmentAttr( node, "align", object->textHAlign() ); + XmlUtil::setAlignmentAttr( node, "valign", object->textVAlign() ); /* affine attrs */ createAffineAttrs( node, object ); diff --git a/glabels/XmlLabelParser.cpp b/glabels/XmlLabelParser.cpp index e4ae253..f3c2d88 100644 --- a/glabels/XmlLabelParser.cpp +++ b/glabels/XmlLabelParser.cpp @@ -21,7 +21,6 @@ #include "XmlLabelParser.h" #include "BarcodeBackends.h" -#include "EnumUtil.h" #include "LabelModel.h" #include "LabelModelObject.h" #include "LabelModelBarcodeObject.h" @@ -615,14 +614,14 @@ namespace glabels /* font attrs */ QString fontFamily = XmlUtil::getStringAttr( node, "font_family", "Sans" ); double fontSize = XmlUtil::getDoubleAttr( node, "font_size", 10 ); - QFont::Weight fontWeight = EnumUtil::stringToWeight( XmlUtil::getStringAttr( node, "font_weight", "normal" ) ); + QFont::Weight fontWeight = XmlUtil::getWeightAttr( node, "font_weight", QFont::Normal ); bool fontItalicFlag = XmlUtil::getBoolAttr( node, "font_italic", false ); bool fontUnderlineFlag = XmlUtil::getBoolAttr( node, "font_underline", false ); /* text attrs */ double textLineSpacing = XmlUtil::getDoubleAttr( node, "line_spacing", 1 ); - Qt::Alignment textHAlign = EnumUtil::stringToHAlign( XmlUtil::getStringAttr( node, "align", "left" ) ); - Qt::Alignment textVAlign = EnumUtil::stringToVAlign( XmlUtil::getStringAttr( node, "valign", "top" ) ); + Qt::Alignment textHAlign = XmlUtil::getAlignmentAttr( node, "align", Qt::AlignLeft ); + Qt::Alignment textVAlign = XmlUtil::getAlignmentAttr( node, "valign", Qt::AlignTop ); /* affine attrs */ double a[6]; diff --git a/glabels/XmlUtil.cpp b/glabels/XmlUtil.cpp index d14469f..7bb30cc 100644 --- a/glabels/XmlUtil.cpp +++ b/glabels/XmlUtil.cpp @@ -234,6 +234,68 @@ namespace glabels } + QFont::Weight XmlUtil::getWeightAttr( const QDomElement& node, + const QString& name, + QFont::Weight default_value ) + { + init(); + + QString valueString = node.attribute( name, "" ); + if ( valueString != "" ) + { + if ( valueString == "bold" ) + { + return QFont::Bold; + } + else if ( valueString == "normal" ) + { + return QFont::Normal; + } + } + + return default_value; + } + + + Qt::Alignment XmlUtil::getAlignmentAttr( const QDomElement& node, + const QString& name, + Qt::Alignment default_value ) + { + init(); + + QString valueString = node.attribute( name, "" ); + if ( valueString != "" ) + { + if ( valueString == "right" ) + { + return Qt::AlignRight; + } + else if ( valueString == "hcenter" ) + { + return Qt::AlignHCenter; + } + else if ( valueString == "left" ) + { + return Qt::AlignLeft; + } + else if ( valueString == "bottom" ) + { + return Qt::AlignBottom; + } + else if ( valueString == "vcenter" ) + { + return Qt::AlignVCenter; + } + else if ( valueString == "top" ) + { + return Qt::AlignTop; + } + } + + return default_value; + } + + void XmlUtil::setStringAttr( QDomElement& node, const QString& name, const QString& value ) @@ -294,4 +356,52 @@ namespace glabels node.setAttribute( name, QString::number(value.inUnits(units)) + units.toIdString() ); } + + void XmlUtil::setWeightAttr( QDomElement& node, + const QString& name, + QFont::Weight value ) + { + switch (value) + { + case QFont::Bold: + node.setAttribute( name, "bold" ); + break; + default: + node.setAttribute( name, "normal" ); + break; + } + } + + + void XmlUtil::setAlignmentAttr( QDomElement& node, + const QString& name, + Qt::Alignment value ) + { + switch (value) + { + case Qt::AlignRight: + node.setAttribute( name, "right" ); + break; + case Qt::AlignHCenter: + node.setAttribute( name, "hcenter" ); + break; + case Qt::AlignLeft: + node.setAttribute( name, "left" ); + break; + case Qt::AlignBottom: + node.setAttribute( name, "bottom" ); + break; + case Qt::AlignVCenter: + node.setAttribute( name, "vcenter" ); + break; + case Qt::AlignTop: + node.setAttribute( name, "top" ); + break; + default: + node.setAttribute( name, "left" ); + break; + } + } + + } // namespace glabels diff --git a/glabels/XmlUtil.h b/glabels/XmlUtil.h index e850b01..9935a96 100644 --- a/glabels/XmlUtil.h +++ b/glabels/XmlUtil.h @@ -25,7 +25,9 @@ #include "Distance.h" #include +#include #include +#include #include @@ -74,6 +76,15 @@ namespace glabels const QString& name, const Distance& default_value ); + static QFont::Weight getWeightAttr( const QDomElement& node, + const QString& name, + QFont::Weight default_value ); + + static Qt::Alignment getAlignmentAttr( const QDomElement& node, + const QString& name, + Qt::Alignment default_value ); + + static void setStringAttr( QDomElement& node, const QString& name, const QString& value ); @@ -98,6 +109,15 @@ namespace glabels const QString& name, const Distance& value ); + static void setWeightAttr( QDomElement& node, + const QString& name, + QFont::Weight value ); + + static void setAlignmentAttr( QDomElement& node, + const QString& name, + Qt::Alignment value ); + + private: Units mUnits; diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 7de98be..410af72 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -1128,8 +1128,8 @@ glabels::LabelModelTextObject - - + + Text