Big-Ugly Style Update (#278)
* Bulk replaced tabs with spaces * Bulk removed trailing whitespace from lines * Replaced c-style comments with c++-style comments in file banners * Replace nested namespace definitions with single concise definitions (C++17), this keeps the indentation more manageable * Cleanup ordering and spacing of include directives * Bulk renaming of header file extensions from '.h' to '.hpp'. * Update CODING-STYLE.md * Update target_compile_features from cxx_std_11 to cxx_std_20. * Refresh .clang-format file. Still needs a lot of tweaking.
This commit is contained in:
+15
-15
@@ -14,8 +14,8 @@ endif ()
|
||||
# Sources
|
||||
#=======================================
|
||||
# Auto-generated files
|
||||
configure_file (Version.h.in ${CMAKE_CURRENT_BINARY_DIR}/Version.h @ONLY)
|
||||
configure_file (Config.h.in ${CMAKE_CURRENT_BINARY_DIR}/Config.h @ONLY)
|
||||
configure_file (Version.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/Version.hpp @ONLY)
|
||||
configure_file (Config.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/Config.hpp @ONLY)
|
||||
|
||||
set (Model_sources
|
||||
Category.cpp
|
||||
@@ -73,18 +73,18 @@ set (Model_sources
|
||||
)
|
||||
|
||||
set (Model_qobject_headers
|
||||
Model.h
|
||||
ModelObject.h
|
||||
ModelBarcodeObject.h
|
||||
ModelBoxObject.h
|
||||
ModelEllipseObject.h
|
||||
ModelImageObject.h
|
||||
ModelLineObject.h
|
||||
ModelShapeObject.h
|
||||
ModelTextObject.h
|
||||
PageRenderer.h
|
||||
Settings.h
|
||||
Variables.h
|
||||
Model.hpp
|
||||
ModelObject.hpp
|
||||
ModelBarcodeObject.hpp
|
||||
ModelBoxObject.hpp
|
||||
ModelEllipseObject.hpp
|
||||
ModelImageObject.hpp
|
||||
ModelLineObject.hpp
|
||||
ModelShapeObject.hpp
|
||||
ModelTextObject.hpp
|
||||
PageRenderer.hpp
|
||||
Settings.hpp
|
||||
Variables.hpp
|
||||
)
|
||||
|
||||
qt6_wrap_cpp (Model_moc_sources ${Model_qobject_headers})
|
||||
@@ -98,7 +98,7 @@ add_library (Model STATIC
|
||||
)
|
||||
|
||||
target_compile_features (Model
|
||||
PUBLIC cxx_std_11
|
||||
PUBLIC cxx_std_20
|
||||
)
|
||||
|
||||
target_include_directories (Model
|
||||
|
||||
+37
-39
@@ -1,49 +1,47 @@
|
||||
/* Category.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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"
|
||||
// Category.cpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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/>.
|
||||
//
|
||||
|
||||
|
||||
namespace glabels
|
||||
#include "Category.hpp"
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
Category::Category( const QString &id, const QString &name )
|
||||
: mId(id),
|
||||
mName(name)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
Category::Category( const QString &id, const QString &name )
|
||||
: mId(id),
|
||||
mName(name)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
QString Category::id() const
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
QString Category::id() const
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
|
||||
|
||||
QString Category::name() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
QString Category::name() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/* Category.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_Category_h
|
||||
#define model_Category_h
|
||||
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
class Category
|
||||
{
|
||||
|
||||
public:
|
||||
Category() = default;
|
||||
Category( const QString& id, const QString& name );
|
||||
~Category() = default;
|
||||
|
||||
QString id() const;
|
||||
QString name() const;
|
||||
|
||||
|
||||
private:
|
||||
QString mId;
|
||||
QString mName;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_Category_h
|
||||
@@ -0,0 +1,52 @@
|
||||
// Category.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_Category_hpp
|
||||
#define model_Category_hpp
|
||||
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
class Category
|
||||
{
|
||||
|
||||
public:
|
||||
Category() = default;
|
||||
Category( const QString& id, const QString& name );
|
||||
~Category() = default;
|
||||
|
||||
QString id() const;
|
||||
QString name() const;
|
||||
|
||||
|
||||
private:
|
||||
QString mId;
|
||||
QString mName;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_Category_hpp
|
||||
+180
-174
@@ -1,206 +1,212 @@
|
||||
/* ColorNode.cpp
|
||||
*
|
||||
* Copyright (C) 2017 Jaye 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/>.
|
||||
*/
|
||||
// ColorNode.cpp
|
||||
//
|
||||
// Copyright (C) 2017 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include "ColorNode.h"
|
||||
#include "ColorNode.hpp"
|
||||
|
||||
|
||||
namespace glabels
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
///
|
||||
/// Default Constructor
|
||||
///
|
||||
ColorNode::ColorNode()
|
||||
: mIsField(false), mColor(QColor::fromRgba(0x00000000)), mKey("")
|
||||
{
|
||||
// empty
|
||||
}
|
||||
///
|
||||
/// Default Constructor
|
||||
///
|
||||
ColorNode::ColorNode()
|
||||
: mIsField(false),
|
||||
mColor(QColor::fromRgba(0x00000000)),
|
||||
mKey("")
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor From Data
|
||||
///
|
||||
ColorNode::ColorNode( bool isField, const QColor& color, const QString& key )
|
||||
: mIsField(isField), mColor(color), mKey(key)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
///
|
||||
/// Constructor From Data
|
||||
///
|
||||
ColorNode::ColorNode( bool isField, const QColor& color, const QString& key )
|
||||
: mIsField(isField),
|
||||
mColor(color),
|
||||
mKey(key)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor From Data
|
||||
///
|
||||
ColorNode::ColorNode( bool isField, uint32_t rgba, const QString& key )
|
||||
: mIsField(isField), mKey(key)
|
||||
{
|
||||
mColor = QColor( (rgba >> 24) & 0xFF,
|
||||
(rgba >> 16) & 0xFF,
|
||||
(rgba >> 8) & 0xFF,
|
||||
(rgba ) & 0xFF );
|
||||
}
|
||||
///
|
||||
/// Constructor From Data
|
||||
///
|
||||
ColorNode::ColorNode( bool isField, uint32_t rgba, const QString& key )
|
||||
: mIsField(isField),
|
||||
mKey(key)
|
||||
{
|
||||
mColor = QColor( (rgba >> 24) & 0xFF,
|
||||
(rgba >> 16) & 0xFF,
|
||||
(rgba >> 8) & 0xFF,
|
||||
(rgba ) & 0xFF );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor From Color
|
||||
///
|
||||
ColorNode::ColorNode( const QColor& color )
|
||||
: mIsField(false), mColor(color), mKey("")
|
||||
{
|
||||
// empty
|
||||
}
|
||||
///
|
||||
/// Constructor From Color
|
||||
///
|
||||
ColorNode::ColorNode( const QColor& color )
|
||||
: mIsField(false),
|
||||
mColor(color),
|
||||
mKey("")
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor From Key
|
||||
///
|
||||
ColorNode::ColorNode( const QString& key )
|
||||
: mIsField(true), mColor(QColor::fromRgba(0x00000000)), mKey(key)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
///
|
||||
/// Constructor From Key
|
||||
///
|
||||
ColorNode::ColorNode( const QString& key )
|
||||
: mIsField(true),
|
||||
mColor(QColor::fromRgba(0x00000000)),
|
||||
mKey(key)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// == Operator
|
||||
///
|
||||
bool ColorNode::operator==( const ColorNode& cn )
|
||||
{
|
||||
return (mIsField == cn.mIsField) &&
|
||||
(mColor == cn.mColor) &&
|
||||
(mKey == cn.mKey);
|
||||
}
|
||||
///
|
||||
/// == Operator
|
||||
///
|
||||
bool ColorNode::operator==( const ColorNode& cn )
|
||||
{
|
||||
return (mIsField == cn.mIsField) &&
|
||||
(mColor == cn.mColor) &&
|
||||
(mKey == cn.mKey);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// != Operator
|
||||
///
|
||||
bool ColorNode::operator!=( const ColorNode& cn )
|
||||
{
|
||||
return (mIsField != cn.mIsField) ||
|
||||
(mColor != cn.mColor) ||
|
||||
(mKey != cn.mKey);
|
||||
}
|
||||
///
|
||||
/// != Operator
|
||||
///
|
||||
bool ColorNode::operator!=( const ColorNode& cn )
|
||||
{
|
||||
return (mIsField != cn.mIsField) ||
|
||||
(mColor != cn.mColor) ||
|
||||
(mKey != cn.mKey);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Field Flag Property Getter
|
||||
///
|
||||
bool ColorNode::isField() const
|
||||
{
|
||||
return mIsField;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Field Flag Property Setter
|
||||
///
|
||||
void ColorNode::setField( bool isField )
|
||||
{
|
||||
mIsField = isField;
|
||||
}
|
||||
///
|
||||
/// Field Flag Property Getter
|
||||
///
|
||||
bool ColorNode::isField() const
|
||||
{
|
||||
return mIsField;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Color Property Getter
|
||||
///
|
||||
const QColor& ColorNode::color() const
|
||||
{
|
||||
return mColor;
|
||||
}
|
||||
///
|
||||
/// Field Flag Property Setter
|
||||
///
|
||||
void ColorNode::setField( bool isField )
|
||||
{
|
||||
mIsField = isField;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Color Property Setter
|
||||
///
|
||||
void ColorNode::setColor( const QColor& color )
|
||||
{
|
||||
mColor = color;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Key Property Getter
|
||||
///
|
||||
const QString& ColorNode::key() const
|
||||
{
|
||||
return mKey;
|
||||
}
|
||||
///
|
||||
/// Color Property Getter
|
||||
///
|
||||
const QColor& ColorNode::color() const
|
||||
{
|
||||
return mColor;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Key Property Setter
|
||||
///
|
||||
void ColorNode::setKey( const QString& key )
|
||||
{
|
||||
mKey = key;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get color encoded as an RGBA 32-bit number
|
||||
///
|
||||
uint32_t ColorNode::rgba() const
|
||||
{
|
||||
uint32_t c =
|
||||
mColor.red() << 24 |
|
||||
mColor.green() << 16 |
|
||||
mColor.blue() << 8 |
|
||||
mColor.alpha();
|
||||
|
||||
return c;
|
||||
}
|
||||
///
|
||||
/// Color Property Setter
|
||||
///
|
||||
void ColorNode::setColor( const QColor& color )
|
||||
{
|
||||
mColor = color;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get color, expand if necessary
|
||||
///
|
||||
QColor ColorNode::color( const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
QColor value = QColor( 192, 192, 192, 128 );
|
||||
|
||||
bool haveRecordField = mIsField &&
|
||||
record.contains(mKey) &&
|
||||
!record.value(mKey).isEmpty();
|
||||
bool haveVariable = mIsField &&
|
||||
variables.contains(mKey) &&
|
||||
!variables[mKey].value().isEmpty();
|
||||
///
|
||||
/// Key Property Getter
|
||||
///
|
||||
const QString& ColorNode::key() const
|
||||
{
|
||||
return mKey;
|
||||
}
|
||||
|
||||
if ( haveRecordField )
|
||||
{
|
||||
value = QColor( record.value(mKey) );
|
||||
}
|
||||
else if ( haveVariable )
|
||||
{
|
||||
value = QColor( variables[mKey].value() );
|
||||
}
|
||||
else if ( !mIsField )
|
||||
{
|
||||
value = mColor;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
///
|
||||
/// Key Property Setter
|
||||
///
|
||||
void ColorNode::setKey( const QString& key )
|
||||
{
|
||||
mKey = key;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get color encoded as an RGBA 32-bit number
|
||||
///
|
||||
uint32_t ColorNode::rgba() const
|
||||
{
|
||||
uint32_t c =
|
||||
mColor.red() << 24 |
|
||||
mColor.green() << 16 |
|
||||
mColor.blue() << 8 |
|
||||
mColor.alpha();
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get color, expand if necessary
|
||||
///
|
||||
QColor ColorNode::color( const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
QColor value = QColor( 192, 192, 192, 128 );
|
||||
|
||||
bool haveRecordField = mIsField &&
|
||||
record.contains(mKey) &&
|
||||
!record.value(mKey).isEmpty();
|
||||
bool haveVariable = mIsField &&
|
||||
variables.contains(mKey) &&
|
||||
!variables[mKey].value().isEmpty();
|
||||
|
||||
if ( haveRecordField )
|
||||
{
|
||||
value = QColor( record.value(mKey) );
|
||||
}
|
||||
else if ( haveVariable )
|
||||
{
|
||||
value = QColor( variables[mKey].value() );
|
||||
}
|
||||
else if ( !mIsField )
|
||||
{
|
||||
value = mColor;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,117 +0,0 @@
|
||||
/* ColorNode.h
|
||||
*
|
||||
* Copyright (C) 2017 Jaye 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 model_ColorNode_h
|
||||
#define model_ColorNode_h
|
||||
|
||||
|
||||
#include "Variables.h"
|
||||
#include "merge/Record.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QColor>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
///
|
||||
/// Color Node Type
|
||||
///
|
||||
class ColorNode
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
ColorNode();
|
||||
|
||||
ColorNode( bool isField, const QColor& color, const QString& key );
|
||||
|
||||
ColorNode( bool isField, uint32_t rgba, const QString& key );
|
||||
|
||||
ColorNode( const QColor& color );
|
||||
|
||||
ColorNode( const QString& key );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Operators
|
||||
/////////////////////////////////
|
||||
public:
|
||||
bool operator==( const ColorNode& cn );
|
||||
|
||||
bool operator!=( const ColorNode& cn );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Field Flag Property
|
||||
//
|
||||
bool isField() const;
|
||||
void setField( bool isField );
|
||||
|
||||
|
||||
//
|
||||
// Color Property
|
||||
//
|
||||
const QColor& color() const;
|
||||
void setColor( const QColor& color );
|
||||
|
||||
|
||||
//
|
||||
// Key Property
|
||||
//
|
||||
const QString& key() const;
|
||||
void setKey( const QString& key );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Misc. Methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
uint32_t rgba() const;
|
||||
QColor color( const merge::Record& record,
|
||||
const Variables& variables ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
bool mIsField;
|
||||
QColor mColor;
|
||||
QString mKey;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ColorNode_h
|
||||
@@ -0,0 +1,114 @@
|
||||
// ColorNode.hpp
|
||||
//
|
||||
// Copyright (C) 2017 Jaye 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 model_ColorNode_hpp
|
||||
#define model_ColorNode_hpp
|
||||
|
||||
|
||||
#include "Variables.hpp"
|
||||
#include "merge/Record.hpp"
|
||||
|
||||
#include <QString>
|
||||
#include <QColor>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
///
|
||||
/// Color Node Type
|
||||
///
|
||||
class ColorNode
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
ColorNode();
|
||||
|
||||
ColorNode( bool isField, const QColor& color, const QString& key );
|
||||
|
||||
ColorNode( bool isField, uint32_t rgba, const QString& key );
|
||||
|
||||
ColorNode( const QColor& color );
|
||||
|
||||
ColorNode( const QString& key );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Operators
|
||||
/////////////////////////////////
|
||||
public:
|
||||
bool operator==( const ColorNode& cn );
|
||||
|
||||
bool operator!=( const ColorNode& cn );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Field Flag Property
|
||||
//
|
||||
bool isField() const;
|
||||
void setField( bool isField );
|
||||
|
||||
|
||||
//
|
||||
// Color Property
|
||||
//
|
||||
const QColor& color() const;
|
||||
void setColor( const QColor& color );
|
||||
|
||||
|
||||
//
|
||||
// Key Property
|
||||
//
|
||||
const QString& key() const;
|
||||
void setKey( const QString& key );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Misc. Methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
uint32_t rgba() const;
|
||||
QColor color( const merge::Record& record,
|
||||
const Variables& variables ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
bool mIsField;
|
||||
QColor mColor;
|
||||
QString mKey;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ColorNode_hpp
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Config.h
|
||||
/* Config.hpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
@@ -18,23 +18,20 @@
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef model_Config_h
|
||||
#define model_Config_h
|
||||
#ifndef model_Config_hpp
|
||||
#define model_Config_hpp
|
||||
|
||||
|
||||
namespace glabels
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
namespace Config
|
||||
{
|
||||
const QString PROJECT_SOURCE_DIR = "@glabels-qt_SOURCE_DIR@";
|
||||
const QString PROJECT_BUILD_DIR = "@glabels-qt_BINARY_DIR@";
|
||||
}
|
||||
namespace Config
|
||||
{
|
||||
const QString PROJECT_SOURCE_DIR = "@glabels-qt_SOURCE_DIR@";
|
||||
const QString PROJECT_BUILD_DIR = "@glabels-qt_BINARY_DIR@";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_Config_h
|
||||
#endif // model_Config_hpp
|
||||
@@ -1,41 +0,0 @@
|
||||
/* Constants.h
|
||||
*
|
||||
* Copyright (C) 2016 Jaye 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 model_Constants_h
|
||||
#define model_Constants_h
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
const double PTS_PER_PT = 1.0;
|
||||
const double PTS_PER_INCH = 72.0;
|
||||
const double PTS_PER_MM = 2.83464566929;
|
||||
const double PTS_PER_CM = (10.0*PTS_PER_MM);
|
||||
const double PTS_PER_PICA = 12.0;
|
||||
|
||||
const Distance EPSILON( 0.5, Units::PT );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_Constants_h
|
||||
@@ -0,0 +1,39 @@
|
||||
// Constants.hpp
|
||||
//
|
||||
// Copyright (C) 2016 Jaye 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 model_Constants_hpp
|
||||
#define model_Constants_hpp
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
const double PTS_PER_PT = 1.0;
|
||||
const double PTS_PER_INCH = 72.0;
|
||||
const double PTS_PER_MM = 2.83464566929;
|
||||
const double PTS_PER_CM = (10.0*PTS_PER_MM);
|
||||
const double PTS_PER_PICA = 12.0;
|
||||
|
||||
const Distance EPSILON( 0.5, Units::PT );
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_Constants_hpp
|
||||
+90
-92
@@ -1,114 +1,112 @@
|
||||
/* DataCache.cpp
|
||||
*
|
||||
* Copyright (C) 2017 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "DataCache.h"
|
||||
|
||||
#include "ModelImageObject.h"
|
||||
// DataCache.cpp
|
||||
//
|
||||
// Copyright (C) 2017 Jaye 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/>.
|
||||
//
|
||||
|
||||
|
||||
namespace glabels
|
||||
#include "DataCache.hpp"
|
||||
|
||||
#include "ModelImageObject.hpp"
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
DataCache::DataCache()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
DataCache::DataCache()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
DataCache::DataCache( const QList<ModelObject*>& objects )
|
||||
{
|
||||
for ( ModelObject* object : objects )
|
||||
{
|
||||
if ( auto* imageObject = dynamic_cast<ModelImageObject*>(object) )
|
||||
{
|
||||
TextNode filenameNode = imageObject->filenameNode();
|
||||
if ( !filenameNode.isField() )
|
||||
{
|
||||
auto& image = imageObject->image();
|
||||
if ( !image.isNull() )
|
||||
{
|
||||
addImage( filenameNode.data(), image );
|
||||
}
|
||||
else
|
||||
{
|
||||
auto& svg = imageObject->svg();
|
||||
if ( !svg.isEmpty() )
|
||||
{
|
||||
addSvg( filenameNode.data(), svg );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DataCache::DataCache( const QList<ModelObject*>& objects )
|
||||
{
|
||||
for ( ModelObject* object : objects )
|
||||
{
|
||||
if ( auto* imageObject = dynamic_cast<ModelImageObject*>(object) )
|
||||
{
|
||||
TextNode filenameNode = imageObject->filenameNode();
|
||||
if ( !filenameNode.isField() )
|
||||
{
|
||||
auto& image = imageObject->image();
|
||||
if ( !image.isNull() )
|
||||
{
|
||||
addImage( filenameNode.data(), image );
|
||||
}
|
||||
else
|
||||
{
|
||||
auto& svg = imageObject->svg();
|
||||
if ( !svg.isEmpty() )
|
||||
{
|
||||
addSvg( filenameNode.data(), svg );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool DataCache::hasImage( const QString& name ) const
|
||||
{
|
||||
return mImageMap.contains( name );
|
||||
}
|
||||
bool DataCache::hasImage( const QString& name ) const
|
||||
{
|
||||
return mImageMap.contains( name );
|
||||
}
|
||||
|
||||
|
||||
QImage DataCache::getImage( const QString& name ) const
|
||||
{
|
||||
return mImageMap[ name ];
|
||||
}
|
||||
QImage DataCache::getImage( const QString& name ) const
|
||||
{
|
||||
return mImageMap[ name ];
|
||||
}
|
||||
|
||||
|
||||
void DataCache::addImage( const QString& name, const QImage& image )
|
||||
{
|
||||
mImageMap[ name ] = image;
|
||||
}
|
||||
void DataCache::addImage( const QString& name, const QImage& image )
|
||||
{
|
||||
mImageMap[ name ] = image;
|
||||
}
|
||||
|
||||
|
||||
QList<QString> DataCache::imageNames() const
|
||||
{
|
||||
return mImageMap.keys();
|
||||
}
|
||||
|
||||
|
||||
bool DataCache::hasSvg( const QString& name ) const
|
||||
{
|
||||
return mSvgMap.contains( name );
|
||||
}
|
||||
QList<QString> DataCache::imageNames() const
|
||||
{
|
||||
return mImageMap.keys();
|
||||
}
|
||||
|
||||
|
||||
QByteArray DataCache::getSvg( const QString& name ) const
|
||||
{
|
||||
return mSvgMap[ name ];
|
||||
}
|
||||
bool DataCache::hasSvg( const QString& name ) const
|
||||
{
|
||||
return mSvgMap.contains( name );
|
||||
}
|
||||
|
||||
|
||||
void DataCache::addSvg( const QString& name, const QByteArray& svg )
|
||||
{
|
||||
mSvgMap[ name ] = svg;
|
||||
}
|
||||
QByteArray DataCache::getSvg( const QString& name ) const
|
||||
{
|
||||
return mSvgMap[ name ];
|
||||
}
|
||||
|
||||
|
||||
QList<QString> DataCache::svgNames() const
|
||||
{
|
||||
return mSvgMap.keys();
|
||||
}
|
||||
void DataCache::addSvg( const QString& name, const QByteArray& svg )
|
||||
{
|
||||
mSvgMap[ name ] = svg;
|
||||
}
|
||||
|
||||
|
||||
QList<QString> DataCache::svgNames() const
|
||||
{
|
||||
return mSvgMap.keys();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/* DataCache.h
|
||||
*
|
||||
* Copyright (C) 2017 Jaye 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 model_DataCache_h
|
||||
#define model_DataCache_h
|
||||
|
||||
|
||||
#include "Model.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
class DataCache
|
||||
{
|
||||
public:
|
||||
DataCache();
|
||||
|
||||
DataCache( const QList<ModelObject*>& objects );
|
||||
|
||||
bool hasImage( const QString& name ) const;
|
||||
QImage getImage( const QString& name ) const;
|
||||
void addImage( const QString& name, const QImage& image );
|
||||
QList<QString> imageNames() const;
|
||||
|
||||
bool hasSvg( const QString& name ) const;
|
||||
QByteArray getSvg( const QString& name ) const;
|
||||
void addSvg( const QString& name, const QByteArray& svg );
|
||||
QList<QString> svgNames() const;
|
||||
|
||||
|
||||
private:
|
||||
QMap<QString,QImage> mImageMap;
|
||||
QMap<QString,QByteArray> mSvgMap;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_DataCache_h
|
||||
@@ -0,0 +1,58 @@
|
||||
// DataCache.hpp
|
||||
//
|
||||
// Copyright (C) 2017 Jaye 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 model_DataCache_hpp
|
||||
#define model_DataCache_hpp
|
||||
|
||||
|
||||
#include "Model.hpp"
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
class DataCache
|
||||
{
|
||||
public:
|
||||
DataCache();
|
||||
|
||||
DataCache( const QList<ModelObject*>& objects );
|
||||
|
||||
bool hasImage( const QString& name ) const;
|
||||
QImage getImage( const QString& name ) const;
|
||||
void addImage( const QString& name, const QImage& image );
|
||||
QList<QString> imageNames() const;
|
||||
|
||||
bool hasSvg( const QString& name ) const;
|
||||
QByteArray getSvg( const QString& name ) const;
|
||||
void addSvg( const QString& name, const QByteArray& svg );
|
||||
QList<QString> svgNames() const;
|
||||
|
||||
|
||||
private:
|
||||
QMap<QString,QImage> mImageMap;
|
||||
QMap<QString,QByteArray> mSvgMap;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_DataCache_hpp
|
||||
+704
-704
File diff suppressed because it is too large
Load Diff
-150
@@ -1,150 +0,0 @@
|
||||
/* Db.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_Db_h
|
||||
#define model_Db_h
|
||||
|
||||
|
||||
#include "Category.h"
|
||||
#include "Paper.h"
|
||||
#include "Template.h"
|
||||
#include "Vendor.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
class Db
|
||||
{
|
||||
|
||||
public:
|
||||
Db() = delete;
|
||||
|
||||
static void init();
|
||||
|
||||
|
||||
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 QList<Template> templates();
|
||||
|
||||
|
||||
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 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 const Vendor lookupVendorFromName( const QString& name );
|
||||
static QString lookupVendorUrlFromName( const QString& name );
|
||||
static bool isVendorNameKnown( const QString& id );
|
||||
|
||||
static const Template lookupTemplateFromName( const QString& name );
|
||||
static const Template lookupTemplateFromBrandPart( const QString& brand,
|
||||
const QString& part );
|
||||
static const Template lookupUserTemplateFromBrandPart( const QString& brand,
|
||||
const QString& part );
|
||||
static bool isTemplateKnown( const QString& brand, const QString& part );
|
||||
static bool isSystemTemplateKnown( const QString& brand, const QString& part );
|
||||
static bool isUserTemplateKnown( const QString& brand, const QString& part );
|
||||
static QStringList getNameListOfSimilarTemplates( const QString& name );
|
||||
|
||||
static QString userTemplateFileName( const QString& brand, const QString& part );
|
||||
static void registerUserTemplate( const Template &tmplate );
|
||||
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 registerPaper( const Paper& paper );
|
||||
|
||||
static void readCategories();
|
||||
static void readCategoriesFromDir( const QDir& dir );
|
||||
static void registerCategory( const Category& category );
|
||||
|
||||
static void readVendors();
|
||||
static void readVendorsFromDir( const QDir& dir );
|
||||
static void registerVendor( const Vendor& vendor );
|
||||
|
||||
static void readTemplates();
|
||||
static void readTemplatesFromDir( const QDir& dir );
|
||||
static void registerTemplate( const Template& tmplate );
|
||||
|
||||
static void readUserTemplatesFromDir( const QDir& dir );
|
||||
|
||||
|
||||
private:
|
||||
static QList<Paper> mPapers;
|
||||
static QMap<QString,Paper> mPapersNameMap;
|
||||
static QMap<QString,Paper> mPapersIdMap;
|
||||
static QStringList mPaperIds;
|
||||
static QStringList mPaperNames;
|
||||
|
||||
static QList<Category> mCategories;
|
||||
static QMap<QString,Category> mCategoriesNameMap;
|
||||
static QMap<QString,Category> mCategoriesIdMap;
|
||||
static QStringList mCategoryIds;
|
||||
static QStringList mCategoryNames;
|
||||
|
||||
static QList<Vendor> mVendors;
|
||||
static QMap<QString,Vendor> mVendorsNameMap;
|
||||
static QStringList mVendorNames;
|
||||
|
||||
static QList<Template> mTemplates;
|
||||
static QMap<QString,Template> mTemplatesNameMap;
|
||||
|
||||
static QMap<QString,Template> mUserTemplatesNameMap;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_Db_h
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
// Db.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_Db_hpp
|
||||
#define model_Db_hpp
|
||||
|
||||
|
||||
#include "Category.hpp"
|
||||
#include "Paper.hpp"
|
||||
#include "Template.hpp"
|
||||
#include "Vendor.hpp"
|
||||
|
||||
#include <QDir>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
class Db
|
||||
{
|
||||
|
||||
public:
|
||||
Db() = delete;
|
||||
|
||||
static void init();
|
||||
|
||||
|
||||
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 QList<Template> templates();
|
||||
|
||||
|
||||
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 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 const Vendor lookupVendorFromName( const QString& name );
|
||||
static QString lookupVendorUrlFromName( const QString& name );
|
||||
static bool isVendorNameKnown( const QString& id );
|
||||
|
||||
static const Template lookupTemplateFromName( const QString& name );
|
||||
static const Template lookupTemplateFromBrandPart( const QString& brand,
|
||||
const QString& part );
|
||||
static const Template lookupUserTemplateFromBrandPart( const QString& brand,
|
||||
const QString& part );
|
||||
static bool isTemplateKnown( const QString& brand, const QString& part );
|
||||
static bool isSystemTemplateKnown( const QString& brand, const QString& part );
|
||||
static bool isUserTemplateKnown( const QString& brand, const QString& part );
|
||||
static QStringList getNameListOfSimilarTemplates( const QString& name );
|
||||
|
||||
static QString userTemplateFileName( const QString& brand, const QString& part );
|
||||
static void registerUserTemplate( const Template &tmplate );
|
||||
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 registerPaper( const Paper& paper );
|
||||
|
||||
static void readCategories();
|
||||
static void readCategoriesFromDir( const QDir& dir );
|
||||
static void registerCategory( const Category& category );
|
||||
|
||||
static void readVendors();
|
||||
static void readVendorsFromDir( const QDir& dir );
|
||||
static void registerVendor( const Vendor& vendor );
|
||||
|
||||
static void readTemplates();
|
||||
static void readTemplatesFromDir( const QDir& dir );
|
||||
static void registerTemplate( const Template& tmplate );
|
||||
|
||||
static void readUserTemplatesFromDir( const QDir& dir );
|
||||
|
||||
|
||||
private:
|
||||
static QList<Paper> mPapers;
|
||||
static QMap<QString,Paper> mPapersNameMap;
|
||||
static QMap<QString,Paper> mPapersIdMap;
|
||||
static QStringList mPaperIds;
|
||||
static QStringList mPaperNames;
|
||||
|
||||
static QList<Category> mCategories;
|
||||
static QMap<QString,Category> mCategoriesNameMap;
|
||||
static QMap<QString,Category> mCategoriesIdMap;
|
||||
static QStringList mCategoryIds;
|
||||
static QStringList mCategoryNames;
|
||||
|
||||
static QList<Vendor> mVendors;
|
||||
static QMap<QString,Vendor> mVendorsNameMap;
|
||||
static QStringList mVendorNames;
|
||||
|
||||
static QList<Template> mTemplates;
|
||||
static QMap<QString,Template> mTemplatesNameMap;
|
||||
|
||||
static QMap<QString,Template> mUserTemplatesNameMap;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_Db_hpp
|
||||
+188
-190
@@ -1,227 +1,225 @@
|
||||
/* Distance.cpp
|
||||
*
|
||||
* Copyright (C) 2016 Jaye 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/>.
|
||||
*/
|
||||
// Distance.cpp
|
||||
//
|
||||
// Copyright (C) 2016 Jaye 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 "Distance.hpp"
|
||||
|
||||
#include <QTextStream>
|
||||
#include <QDebug>
|
||||
#include <QIODevice>
|
||||
|
||||
|
||||
namespace glabels
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
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, 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, 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, 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( 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 );
|
||||
Distance Distance::fromString( const QString& string )
|
||||
{
|
||||
QString stringCopy = string;
|
||||
QTextStream valueStream( &stringCopy, QIODevice::ReadOnly );
|
||||
|
||||
double value;
|
||||
QString unitsString;
|
||||
valueStream >> value >> unitsString;
|
||||
double value;
|
||||
QString unitsString;
|
||||
valueStream >> value >> unitsString;
|
||||
|
||||
if ( !unitsString.isEmpty() && !Units::isIdValid( unitsString ) )
|
||||
{
|
||||
qWarning() << "Invalid Units in string: \"" << string << "\"";
|
||||
}
|
||||
if ( !unitsString.isEmpty() && !Units::isIdValid( unitsString ) )
|
||||
{
|
||||
qWarning() << "Invalid Units in string: \"" << string << "\"";
|
||||
}
|
||||
|
||||
return Distance( value, unitsString );
|
||||
}
|
||||
return Distance( value, unitsString );
|
||||
}
|
||||
|
||||
|
||||
double Distance::inUnits( Units units ) const
|
||||
{
|
||||
double d;
|
||||
double Distance::inUnits( 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;
|
||||
default:
|
||||
d = mDPts;
|
||||
break;
|
||||
}
|
||||
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;
|
||||
default:
|
||||
d = mDPts;
|
||||
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;
|
||||
default:
|
||||
d = mDPts;
|
||||
break;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
double Distance::inUnits( const QString& unitsId ) const
|
||||
{
|
||||
return inUnits( Units( unitsId ) );
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
QString Distance::toString( Units units ) const
|
||||
{
|
||||
return QString::number( inUnits(units) ) + units.toIdString();
|
||||
}
|
||||
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;
|
||||
default:
|
||||
d = mDPts;
|
||||
break;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
QString Distance::toString( Units::Enum unitsEnum ) const
|
||||
{
|
||||
Units units(unitsEnum);
|
||||
return QString::number( inUnits(units) ) + units.toIdString();
|
||||
}
|
||||
double Distance::inUnits( const QString& unitsId ) const
|
||||
{
|
||||
return inUnits( Units( unitsId ) );
|
||||
}
|
||||
|
||||
|
||||
QString Distance::toString( const QString& unitsId ) const
|
||||
{
|
||||
Units units(unitsId);
|
||||
return QString::number( inUnits(units) ) + units.toIdString();
|
||||
}
|
||||
QString Distance::toString( 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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QDebug operator<<( QDebug dbg, glabels::model::Distance distance )
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
QDebugStateSaver saver(dbg);
|
||||
|
||||
dbg.nospace() << distance.pt() << "pt";
|
||||
dbg.nospace() << distance.pt() << "pt";
|
||||
|
||||
return dbg;
|
||||
return dbg;
|
||||
}
|
||||
|
||||
@@ -1,319 +0,0 @@
|
||||
/* Distance.h
|
||||
*
|
||||
* Copyright (C) 2016 Jaye 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 model_Distance_h
|
||||
#define model_Distance_h
|
||||
|
||||
|
||||
#include "Units.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
#include <QtMath>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
class Distance
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Distance)
|
||||
|
||||
public:
|
||||
Distance();
|
||||
Distance( double d, Units::Enum unitsEnum = Units::PT );
|
||||
Distance( double d, 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( Units units ) const;
|
||||
double inUnits( Units::Enum unitsEnum ) const;
|
||||
double inUnits( const QString& unitsId ) const;
|
||||
|
||||
|
||||
QString toString( Units units ) const;
|
||||
QString toString( Units::Enum unitsEnum ) const;
|
||||
QString toString( const QString& unitsId ) const;
|
||||
|
||||
Distance& operator+=( Distance d );
|
||||
Distance& operator-=( Distance d );
|
||||
Distance& operator*=( double f );
|
||||
Distance operator-();
|
||||
|
||||
friend inline Distance operator+( Distance d1, Distance d2 );
|
||||
friend inline Distance operator-( Distance d1, Distance d2 );
|
||||
friend inline Distance operator*( double x, Distance d );
|
||||
friend inline Distance operator*( Distance d, double x );
|
||||
friend inline double operator/( Distance d1, Distance d2 );
|
||||
friend inline Distance operator/( Distance d, double x );
|
||||
|
||||
friend inline bool operator<( Distance d1, Distance d2 );
|
||||
friend inline bool operator<=( Distance d1, Distance d2 );
|
||||
friend inline bool operator>( Distance d1, Distance d2 );
|
||||
friend inline bool operator>=( Distance d1, Distance d2 );
|
||||
friend inline bool operator==( Distance d1, Distance d2 );
|
||||
friend inline bool operator!=( Distance d1, Distance d2 );
|
||||
|
||||
friend inline Distance fabs( Distance d );
|
||||
friend inline Distance min( Distance d1, Distance d2 );
|
||||
friend inline Distance max( Distance d1, Distance d2 );
|
||||
friend inline Distance fmod( Distance d1, Distance d2 );
|
||||
|
||||
|
||||
private:
|
||||
double mDPts;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
QDebug operator<<( QDebug dbg, const glabels::model::Distance distance );
|
||||
|
||||
|
||||
//
|
||||
// Inline methods
|
||||
//
|
||||
|
||||
#include "Constants.h"
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
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+=( Distance d )
|
||||
{
|
||||
mDPts += d.mDPts;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Distance& Distance::operator-=( Distance d )
|
||||
{
|
||||
mDPts -= d.mDPts;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Distance& Distance::operator*=( double f )
|
||||
{
|
||||
mDPts *= f;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Distance Distance::operator-()
|
||||
{
|
||||
return Distance::pt( -mDPts );
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator+( Distance d1, Distance d2 )
|
||||
{
|
||||
return Distance::pt( d1.mDPts + d2.mDPts );
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator-( Distance d1, Distance d2 )
|
||||
{
|
||||
return Distance::pt( d1.mDPts - d2.mDPts );
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator*( double x, Distance d )
|
||||
{
|
||||
return Distance::pt( x * d.mDPts );
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator*( Distance d, double x )
|
||||
{
|
||||
return Distance::pt( d.mDPts * x );
|
||||
}
|
||||
|
||||
|
||||
inline double operator/( Distance d1, Distance d2 )
|
||||
{
|
||||
return d1.mDPts / d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator/( Distance d, double x )
|
||||
{
|
||||
return Distance::pt( d.mDPts / x );
|
||||
}
|
||||
|
||||
|
||||
inline bool operator<( Distance d1, Distance d2 )
|
||||
{
|
||||
return d1.mDPts < d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator<=( Distance d1, Distance d2 )
|
||||
{
|
||||
return d1.mDPts <= d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator>( Distance d1, Distance d2 )
|
||||
{
|
||||
return d1.mDPts > d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator>=( Distance d1, Distance d2 )
|
||||
{
|
||||
return d1.mDPts >= d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator==( Distance d1, Distance d2 )
|
||||
{
|
||||
return d1.mDPts == d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator!=( Distance d1, Distance d2 )
|
||||
{
|
||||
return d1.mDPts != d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline Distance fabs( Distance d )
|
||||
{
|
||||
return Distance::pt( qFabs( d.mDPts ) );
|
||||
}
|
||||
|
||||
|
||||
inline Distance min( Distance d1, Distance d2 )
|
||||
{
|
||||
return (d1.mDPts < d2.mDPts) ? d1 : d2;
|
||||
}
|
||||
|
||||
|
||||
inline Distance max( Distance d1, Distance d2 )
|
||||
{
|
||||
return (d1.mDPts > d2.mDPts) ? d1 : d2;
|
||||
}
|
||||
|
||||
|
||||
inline Distance fmod( Distance d1, Distance d2 )
|
||||
{
|
||||
return Distance::pt( std::fmod( d1.mDPts, d2.mDPts ) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_Distance_h
|
||||
@@ -0,0 +1,313 @@
|
||||
// Distance.hpp
|
||||
//
|
||||
// Copyright (C) 2016 Jaye 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 model_Distance_hpp
|
||||
#define model_Distance_hpp
|
||||
|
||||
|
||||
#include "Units.hpp"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
#include <QtMath>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
class Distance
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Distance)
|
||||
|
||||
public:
|
||||
Distance();
|
||||
Distance( double d, Units::Enum unitsEnum = Units::PT );
|
||||
Distance( double d, 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( Units units ) const;
|
||||
double inUnits( Units::Enum unitsEnum ) const;
|
||||
double inUnits( const QString& unitsId ) const;
|
||||
|
||||
|
||||
QString toString( Units units ) const;
|
||||
QString toString( Units::Enum unitsEnum ) const;
|
||||
QString toString( const QString& unitsId ) const;
|
||||
|
||||
Distance& operator+=( Distance d );
|
||||
Distance& operator-=( Distance d );
|
||||
Distance& operator*=( double f );
|
||||
Distance operator-();
|
||||
|
||||
friend inline Distance operator+( Distance d1, Distance d2 );
|
||||
friend inline Distance operator-( Distance d1, Distance d2 );
|
||||
friend inline Distance operator*( double x, Distance d );
|
||||
friend inline Distance operator*( Distance d, double x );
|
||||
friend inline double operator/( Distance d1, Distance d2 );
|
||||
friend inline Distance operator/( Distance d, double x );
|
||||
|
||||
friend inline bool operator<( Distance d1, Distance d2 );
|
||||
friend inline bool operator<=( Distance d1, Distance d2 );
|
||||
friend inline bool operator>( Distance d1, Distance d2 );
|
||||
friend inline bool operator>=( Distance d1, Distance d2 );
|
||||
friend inline bool operator==( Distance d1, Distance d2 );
|
||||
friend inline bool operator!=( Distance d1, Distance d2 );
|
||||
|
||||
friend inline Distance fabs( Distance d );
|
||||
friend inline Distance min( Distance d1, Distance d2 );
|
||||
friend inline Distance max( Distance d1, Distance d2 );
|
||||
friend inline Distance fmod( Distance d1, Distance d2 );
|
||||
|
||||
|
||||
private:
|
||||
double mDPts{ 0 };
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
QDebug operator<<( QDebug dbg, const glabels::model::Distance distance );
|
||||
|
||||
|
||||
//
|
||||
// Inline methods
|
||||
//
|
||||
|
||||
#include "Constants.hpp"
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
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+=( Distance d )
|
||||
{
|
||||
mDPts += d.mDPts;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Distance& Distance::operator-=( Distance d )
|
||||
{
|
||||
mDPts -= d.mDPts;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Distance& Distance::operator*=( double f )
|
||||
{
|
||||
mDPts *= f;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Distance Distance::operator-()
|
||||
{
|
||||
return Distance::pt( -mDPts );
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator+( Distance d1, Distance d2 )
|
||||
{
|
||||
return Distance::pt( d1.mDPts + d2.mDPts );
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator-( Distance d1, Distance d2 )
|
||||
{
|
||||
return Distance::pt( d1.mDPts - d2.mDPts );
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator*( double x, Distance d )
|
||||
{
|
||||
return Distance::pt( x * d.mDPts );
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator*( Distance d, double x )
|
||||
{
|
||||
return Distance::pt( d.mDPts * x );
|
||||
}
|
||||
|
||||
|
||||
inline double operator/( Distance d1, Distance d2 )
|
||||
{
|
||||
return d1.mDPts / d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator/( Distance d, double x )
|
||||
{
|
||||
return Distance::pt( d.mDPts / x );
|
||||
}
|
||||
|
||||
|
||||
inline bool operator<( Distance d1, Distance d2 )
|
||||
{
|
||||
return d1.mDPts < d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator<=( Distance d1, Distance d2 )
|
||||
{
|
||||
return d1.mDPts <= d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator>( Distance d1, Distance d2 )
|
||||
{
|
||||
return d1.mDPts > d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator>=( Distance d1, Distance d2 )
|
||||
{
|
||||
return d1.mDPts >= d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator==( Distance d1, Distance d2 )
|
||||
{
|
||||
return d1.mDPts == d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator!=( Distance d1, Distance d2 )
|
||||
{
|
||||
return d1.mDPts != d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline Distance fabs( Distance d )
|
||||
{
|
||||
return Distance::pt( qFabs( d.mDPts ) );
|
||||
}
|
||||
|
||||
|
||||
inline Distance min( Distance d1, Distance d2 )
|
||||
{
|
||||
return (d1.mDPts < d2.mDPts) ? d1 : d2;
|
||||
}
|
||||
|
||||
|
||||
inline Distance max( Distance d1, Distance d2 )
|
||||
{
|
||||
return (d1.mDPts > d2.mDPts) ? d1 : d2;
|
||||
}
|
||||
|
||||
|
||||
inline Distance fmod( Distance d1, Distance d2 )
|
||||
{
|
||||
return Distance::pt( std::fmod( d1.mDPts, d2.mDPts ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_Distance_hpp
|
||||
+100
-102
@@ -1,124 +1,122 @@
|
||||
/* FileUtil.cpp
|
||||
*
|
||||
* Copyright (C) 2015 Jaye 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/>.
|
||||
*/
|
||||
// FileUtil.cpp
|
||||
//
|
||||
// Copyright (C) 2015 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "FileUtil.h"
|
||||
|
||||
#include "Config.h"
|
||||
#include "FileUtil.hpp"
|
||||
|
||||
#include "Config.hpp"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QStandardPaths>
|
||||
|
||||
|
||||
namespace glabels
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
QString FileUtil::addExtension( const QString& rawFilename, const QString& extension )
|
||||
{
|
||||
if ( rawFilename.endsWith( extension ) )
|
||||
{
|
||||
return rawFilename;
|
||||
}
|
||||
QString FileUtil::addExtension( const QString& rawFilename, const QString& extension )
|
||||
{
|
||||
if ( rawFilename.endsWith( extension ) )
|
||||
{
|
||||
return rawFilename;
|
||||
}
|
||||
|
||||
return rawFilename + extension;
|
||||
}
|
||||
return rawFilename + extension;
|
||||
}
|
||||
|
||||
|
||||
QDir FileUtil::systemTemplatesDir()
|
||||
{
|
||||
QDir dir;
|
||||
QDir FileUtil::systemTemplatesDir()
|
||||
{
|
||||
QDir dir;
|
||||
|
||||
// First, try finding templates directory relative to application path
|
||||
dir.cd( QApplication::applicationDirPath() );
|
||||
if ( (dir.dirName() == "bin") &&
|
||||
dir.cdUp() && dir.cd( "share" ) && dir.cd( "glabels-qt" ) && dir.cd( "templates" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
// First, try finding templates directory relative to application path
|
||||
dir.cd( QApplication::applicationDirPath() );
|
||||
if ( (dir.dirName() == "bin") &&
|
||||
dir.cdUp() && dir.cd( "share" ) && dir.cd( "glabels-qt" ) && dir.cd( "templates" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
// Next, try running out of the source directory.
|
||||
if ( dir.cd( Config::PROJECT_SOURCE_DIR ) && dir.cd( "templates" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
// Next, try running out of the source directory.
|
||||
if ( dir.cd( Config::PROJECT_SOURCE_DIR ) && dir.cd( "templates" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
qFatal( "Cannot locate system template directory!" );
|
||||
return QDir("/");
|
||||
}
|
||||
qFatal( "Cannot locate system template directory!" );
|
||||
return QDir("/");
|
||||
}
|
||||
|
||||
|
||||
QDir FileUtil::manualUserTemplatesDir()
|
||||
{
|
||||
// Location for manually created user-defined templates
|
||||
QDir dir( QStandardPaths::writableLocation(QStandardPaths::HomeLocation) );
|
||||
dir.mkpath( ".glabels" );
|
||||
dir.cd( ".glabels" );
|
||||
QDir FileUtil::manualUserTemplatesDir()
|
||||
{
|
||||
// Location for manually created user-defined templates
|
||||
QDir dir( QStandardPaths::writableLocation(QStandardPaths::HomeLocation) );
|
||||
dir.mkpath( ".glabels" );
|
||||
dir.cd( ".glabels" );
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
QDir FileUtil::userTemplatesDir()
|
||||
{
|
||||
// Location for user-defined templates created using TemplateDesigner
|
||||
QDir dir( QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) );
|
||||
dir.mkpath( "." );
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
QDir FileUtil::translationsDir()
|
||||
{
|
||||
QDir dir;
|
||||
|
||||
// First, try finding translations directory relative to application path
|
||||
dir.cd( QApplication::applicationDirPath() );
|
||||
if ( (dir.dirName() == "bin") &&
|
||||
dir.cdUp() && dir.cd( "share" ) && dir.cd( "glabels-qt" ) && dir.cd( "translations" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
// Next, try running out of the source directory.
|
||||
if ( dir.cd( Config::PROJECT_BUILD_DIR ) && dir.cd( "translations" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
qFatal( "Cannot locate system template directory!" );
|
||||
return QDir("/");
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
QString FileUtil::makeRelativeIfInDir( const QDir& dir,
|
||||
const QString& filename )
|
||||
{
|
||||
QString relativeFilePath = dir.relativeFilePath( filename ); // Note: directory separators canonicalized to slash by Qt path methods
|
||||
if ( !relativeFilePath.startsWith( "../" ) )
|
||||
{
|
||||
return relativeFilePath;
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
QDir FileUtil::userTemplatesDir()
|
||||
{
|
||||
// Location for user-defined templates created using TemplateDesigner
|
||||
QDir dir( QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) );
|
||||
dir.mkpath( "." );
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
QDir FileUtil::translationsDir()
|
||||
{
|
||||
QDir dir;
|
||||
|
||||
// First, try finding translations directory relative to application path
|
||||
dir.cd( QApplication::applicationDirPath() );
|
||||
if ( (dir.dirName() == "bin") &&
|
||||
dir.cdUp() && dir.cd( "share" ) && dir.cd( "glabels-qt" ) && dir.cd( "translations" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
// Next, try running out of the source directory.
|
||||
if ( dir.cd( Config::PROJECT_BUILD_DIR ) && dir.cd( "translations" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
qFatal( "Cannot locate system template directory!" );
|
||||
return QDir("/");
|
||||
}
|
||||
|
||||
|
||||
QString FileUtil::makeRelativeIfInDir( const QDir& dir,
|
||||
const QString& filename )
|
||||
{
|
||||
QString relativeFilePath = dir.relativeFilePath( filename ); // Note: directory separators canonicalized to slash by Qt path methods
|
||||
if ( !relativeFilePath.startsWith( "../" ) )
|
||||
{
|
||||
return relativeFilePath;
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/* FileUtil.h
|
||||
*
|
||||
* Copyright (C) 2015 Jaye 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 model_FileUtil_h
|
||||
#define model_FileUtil_h
|
||||
|
||||
|
||||
#include <QString>
|
||||
#include <QDir>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
namespace FileUtil
|
||||
{
|
||||
|
||||
QString addExtension( const QString& rawFilename, const QString& extension );
|
||||
|
||||
QDir systemTemplatesDir();
|
||||
QDir manualUserTemplatesDir();
|
||||
QDir userTemplatesDir();
|
||||
|
||||
QDir translationsDir();
|
||||
|
||||
QString makeRelativeIfInDir( const QDir& dir,
|
||||
const QString& filename );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_FileUtil_h
|
||||
@@ -0,0 +1,50 @@
|
||||
// FileUtil.hpp
|
||||
//
|
||||
// Copyright (C) 2015 Jaye 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 model_FileUtil_hpp
|
||||
#define model_FileUtil_hpp
|
||||
|
||||
|
||||
#include <QString>
|
||||
#include <QDir>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
namespace FileUtil
|
||||
{
|
||||
|
||||
QString addExtension( const QString& rawFilename, const QString& extension );
|
||||
|
||||
QDir systemTemplatesDir();
|
||||
QDir manualUserTemplatesDir();
|
||||
QDir userTemplatesDir();
|
||||
|
||||
QDir translationsDir();
|
||||
|
||||
QString makeRelativeIfInDir( const QDir& dir,
|
||||
const QString& filename );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_FileUtil_hpp
|
||||
+128
-132
@@ -1,162 +1,158 @@
|
||||
/* Frame.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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/>.
|
||||
*/
|
||||
// Frame.cpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 "Frame.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace glabels
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
Frame::Frame( const QString& id )
|
||||
: mId(id),
|
||||
mNLabels(0),
|
||||
mLayoutDescription("")
|
||||
{
|
||||
// empty
|
||||
}
|
||||
Frame::Frame( const QString& id )
|
||||
: mId(id),
|
||||
mNLabels(0),
|
||||
mLayoutDescription("")
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
Frame::Frame( const Frame& other )
|
||||
{
|
||||
mId = other.mId;
|
||||
mNLabels = 0;
|
||||
Frame::Frame( const Frame& other )
|
||||
{
|
||||
mId = other.mId;
|
||||
mNLabels = 0;
|
||||
|
||||
for ( const auto& layout : other.mLayouts )
|
||||
{
|
||||
addLayout( layout );
|
||||
}
|
||||
|
||||
for ( const auto& markup : other.mMarkups )
|
||||
{
|
||||
mMarkups.push_back( markup->clone() );
|
||||
}
|
||||
}
|
||||
for ( const auto& layout : other.mLayouts )
|
||||
{
|
||||
addLayout( layout );
|
||||
}
|
||||
|
||||
for ( const auto& markup : other.mMarkups )
|
||||
{
|
||||
mMarkups.push_back( markup->clone() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString Frame::id() const
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
|
||||
|
||||
int Frame::nLabels() const
|
||||
{
|
||||
return mNLabels;
|
||||
}
|
||||
|
||||
|
||||
QString Frame::layoutDescription() const
|
||||
{
|
||||
return mLayoutDescription;
|
||||
}
|
||||
|
||||
|
||||
const std::list<Layout>& Frame::layouts() const
|
||||
{
|
||||
return mLayouts;
|
||||
}
|
||||
|
||||
|
||||
const std::list<std::unique_ptr<Markup>>& Frame::markups() const
|
||||
{
|
||||
return mMarkups;
|
||||
}
|
||||
|
||||
|
||||
QVector<Point> Frame::getOrigins() const
|
||||
{
|
||||
QVector<Point> origins( nLabels() );
|
||||
|
||||
int i = 0;
|
||||
for ( auto& layout : mLayouts )
|
||||
{
|
||||
for ( int iy = 0; iy < layout.ny(); iy++ )
|
||||
{
|
||||
for ( int ix = 0; ix < layout.nx(); ix++ )
|
||||
{
|
||||
origins[i++] = Point( ix*layout.dx() + layout.x0(), iy*layout.dy() + layout.y0() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::stable_sort( origins.begin(), origins.end() );
|
||||
|
||||
return origins;
|
||||
}
|
||||
QString Frame::id() const
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
|
||||
|
||||
void Frame::addLayout( const Layout& layout )
|
||||
{
|
||||
mLayouts.push_back( 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);
|
||||
}
|
||||
}
|
||||
int Frame::nLabels() const
|
||||
{
|
||||
return mNLabels;
|
||||
}
|
||||
|
||||
|
||||
void Frame::addMarkup( const Markup& markup )
|
||||
{
|
||||
mMarkups.push_back( markup.clone() );
|
||||
}
|
||||
QString Frame::layoutDescription() const
|
||||
{
|
||||
return mLayoutDescription;
|
||||
}
|
||||
|
||||
|
||||
bool Frame::setH( Distance h )
|
||||
{
|
||||
// Default implementation does nothing
|
||||
return false;
|
||||
}
|
||||
const std::list<Layout>& Frame::layouts() const
|
||||
{
|
||||
return mLayouts;
|
||||
}
|
||||
|
||||
|
||||
const std::list<std::unique_ptr<Markup>>& Frame::markups() const
|
||||
{
|
||||
return mMarkups;
|
||||
}
|
||||
|
||||
|
||||
QVector<Point> Frame::getOrigins() const
|
||||
{
|
||||
QVector<Point> origins( nLabels() );
|
||||
|
||||
int i = 0;
|
||||
for ( auto& layout : mLayouts )
|
||||
{
|
||||
for ( int iy = 0; iy < layout.ny(); iy++ )
|
||||
{
|
||||
for ( int ix = 0; ix < layout.nx(); ix++ )
|
||||
{
|
||||
origins[i++] = Point( ix*layout.dx() + layout.x0(), iy*layout.dy() + layout.y0() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::stable_sort( origins.begin(), origins.end() );
|
||||
|
||||
return origins;
|
||||
}
|
||||
|
||||
|
||||
void Frame::addLayout( const Layout& layout )
|
||||
{
|
||||
mLayouts.push_back( 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( const Markup& markup )
|
||||
{
|
||||
mMarkups.push_back( markup.clone() );
|
||||
}
|
||||
|
||||
|
||||
bool Frame::setH( Distance h )
|
||||
{
|
||||
// Default implementation does nothing
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QDebug operator<<( QDebug dbg, const glabels::model::Frame& frame )
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
QDebugStateSaver saver(dbg);
|
||||
|
||||
frame.print( dbg );
|
||||
frame.print( dbg );
|
||||
|
||||
return dbg;
|
||||
return dbg;
|
||||
}
|
||||
|
||||
-101
@@ -1,101 +0,0 @@
|
||||
/* Frame.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_Frame_h
|
||||
#define model_Frame_h
|
||||
|
||||
|
||||
#include "Distance.h"
|
||||
#include "Layout.h"
|
||||
#include "Markup.h"
|
||||
#include "Point.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QPainterPath>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
#include <list>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
class Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Frame)
|
||||
|
||||
protected:
|
||||
Frame( const QString& id = "0" );
|
||||
Frame( const Frame& other );
|
||||
|
||||
public:
|
||||
virtual ~Frame() = default;
|
||||
|
||||
virtual std::unique_ptr<Frame> clone() const = 0;
|
||||
|
||||
QString id() const;
|
||||
int nLabels() const;
|
||||
QString layoutDescription() const;
|
||||
const std::list<Layout>& layouts() const;
|
||||
const std::list<std::unique_ptr<Markup>>& markups() const;
|
||||
|
||||
QVector<Point> getOrigins() const;
|
||||
|
||||
void addLayout( const Layout& layout );
|
||||
void addMarkup( const Markup& markup );
|
||||
|
||||
virtual Distance w() const = 0;
|
||||
virtual Distance h() const = 0;
|
||||
|
||||
virtual bool setH( Distance h );
|
||||
|
||||
virtual QString sizeDescription( Units units ) const = 0;
|
||||
virtual bool isSimilarTo( const Frame& other ) const = 0;
|
||||
|
||||
virtual const QPainterPath& path() const = 0;
|
||||
virtual const QPainterPath& clipPath() const = 0;
|
||||
virtual QPainterPath marginPath( Distance xSize, Distance ySize ) const = 0;
|
||||
|
||||
// Debugging support
|
||||
virtual void print( QDebug& dbg ) const = 0;
|
||||
|
||||
|
||||
private:
|
||||
QString mId;
|
||||
int mNLabels;
|
||||
QString mLayoutDescription;
|
||||
|
||||
std::list<Layout> mLayouts;
|
||||
std::list<std::unique_ptr<Markup>> mMarkups;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
QDebug operator<<( QDebug dbg, const glabels::model::Frame& frame );
|
||||
|
||||
|
||||
#endif // model_Frame_h
|
||||
@@ -0,0 +1,98 @@
|
||||
// Frame.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_Frame_hpp
|
||||
#define model_Frame_hpp
|
||||
|
||||
|
||||
#include "Distance.hpp"
|
||||
#include "Layout.hpp"
|
||||
#include "Markup.hpp"
|
||||
#include "Point.hpp"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QPainterPath>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
#include <list>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
class Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Frame)
|
||||
|
||||
protected:
|
||||
Frame( const QString& id = "0" );
|
||||
Frame( const Frame& other );
|
||||
|
||||
public:
|
||||
virtual ~Frame() = default;
|
||||
|
||||
virtual std::unique_ptr<Frame> clone() const = 0;
|
||||
|
||||
QString id() const;
|
||||
int nLabels() const;
|
||||
QString layoutDescription() const;
|
||||
const std::list<Layout>& layouts() const;
|
||||
const std::list<std::unique_ptr<Markup>>& markups() const;
|
||||
|
||||
QVector<Point> getOrigins() const;
|
||||
|
||||
void addLayout( const Layout& layout );
|
||||
void addMarkup( const Markup& markup );
|
||||
|
||||
virtual Distance w() const = 0;
|
||||
virtual Distance h() const = 0;
|
||||
|
||||
virtual bool setH( Distance h );
|
||||
|
||||
virtual QString sizeDescription( Units units ) const = 0;
|
||||
virtual bool isSimilarTo( const Frame& other ) const = 0;
|
||||
|
||||
virtual const QPainterPath& path() const = 0;
|
||||
virtual const QPainterPath& clipPath() const = 0;
|
||||
virtual QPainterPath marginPath( Distance xSize, Distance ySize ) const = 0;
|
||||
|
||||
// Debugging support
|
||||
virtual void print( QDebug& dbg ) const = 0;
|
||||
|
||||
|
||||
private:
|
||||
QString mId;
|
||||
int mNLabels;
|
||||
QString mLayoutDescription;
|
||||
|
||||
std::list<Layout> mLayouts;
|
||||
std::list<std::unique_ptr<Markup>> mMarkups;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
QDebug operator<<( QDebug dbg, const glabels::model::Frame& frame );
|
||||
|
||||
|
||||
#endif // model_Frame_hpp
|
||||
+201
-206
@@ -1,244 +1,239 @@
|
||||
/* FrameCd.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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/>.
|
||||
*/
|
||||
// FrameCd.cpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 "FrameCd.hpp"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "StrUtil.h"
|
||||
#include "Constants.hpp"
|
||||
#include "StrUtil.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace glabels
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
FrameCd::FrameCd( Distance r1,
|
||||
Distance r2,
|
||||
Distance w,
|
||||
Distance h,
|
||||
Distance waste,
|
||||
const QString& id )
|
||||
: Frame(id),
|
||||
mR1(r1),
|
||||
mR2(r2),
|
||||
mW(w),
|
||||
mH(h),
|
||||
mWaste(waste)
|
||||
{
|
||||
Distance wReal = (mW == 0) ? 2*mR1 : mW;
|
||||
Distance hReal = (mH == 0) ? 2*mR1 : mH;
|
||||
FrameCd::FrameCd( Distance r1,
|
||||
Distance r2,
|
||||
Distance w,
|
||||
Distance h,
|
||||
Distance waste,
|
||||
const QString& id )
|
||||
: Frame(id),
|
||||
mR1(r1),
|
||||
mR2(r2),
|
||||
mW(w),
|
||||
mH(h),
|
||||
mWaste(waste)
|
||||
{
|
||||
Distance wReal = (mW == 0) ? 2*mR1 : mW;
|
||||
Distance hReal = (mH == 0) ? 2*mR1 : mH;
|
||||
|
||||
//
|
||||
// Create path
|
||||
//
|
||||
{
|
||||
/*
|
||||
* Construct outer subpath (may be clipped if it's a business card CD)
|
||||
*/
|
||||
QPainterPath outerPath;
|
||||
outerPath.addEllipse( (wReal/2 - r1).pt(), (hReal/2 - r1).pt(), 2*r1.pt(), 2*r1.pt() );
|
||||
//
|
||||
// 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() );
|
||||
QPainterPath clipPath;
|
||||
clipPath.addRect( 0, 0, wReal.pt(), hReal.pt() );
|
||||
|
||||
mPath.addPath( outerPath & clipPath );
|
||||
mPath.closeSubpath();
|
||||
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() );
|
||||
}
|
||||
/*
|
||||
* 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;
|
||||
//
|
||||
// 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() );
|
||||
/*
|
||||
* 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() );
|
||||
QPainterPath clipPath;
|
||||
clipPath.addRect( -mWaste.pt(), -mWaste.pt(), wClip.pt(), hClip.pt() );
|
||||
|
||||
mClipPath.addPath( outerPath & clipPath );
|
||||
mClipPath.closeSubpath();
|
||||
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() );
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Add inner subpath
|
||||
*/
|
||||
mClipPath.addEllipse( (wReal/2 - r2Clip).pt(), (hReal/2 - r2Clip).pt(), 2*r2Clip.pt(), 2*r2Clip.pt() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Frame> FrameCd::clone() const
|
||||
{
|
||||
return std::make_unique<FrameCd>( *this );
|
||||
}
|
||||
|
||||
|
||||
Distance FrameCd::w() const
|
||||
{
|
||||
return (mW == 0) ? 2*mR1 : mW;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameCd::h() const
|
||||
{
|
||||
return (mH == 0) ? 2*mR1 : mH;
|
||||
}
|
||||
std::unique_ptr<Frame> FrameCd::clone() const
|
||||
{
|
||||
return std::make_unique<FrameCd>( *this );
|
||||
}
|
||||
|
||||
|
||||
Distance FrameCd::r1() const
|
||||
{
|
||||
return mR1;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameCd::r2() const
|
||||
{
|
||||
return mR2;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameCd::waste() const
|
||||
{
|
||||
return mWaste;
|
||||
}
|
||||
|
||||
|
||||
QString FrameCd::sizeDescription( Units units ) const
|
||||
{
|
||||
if ( units.toEnum() == Units::IN )
|
||||
{
|
||||
QString dStr = StrUtil::formatFraction( 2 * mR1.in() );
|
||||
|
||||
return QString("%1 %2 %3").arg(dStr).arg(units.toTrName()).arg(tr("diameter"));
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString("%1 %2 %3").arg(2 * mR1.inUnits(units), 0, 'g', 5)
|
||||
.arg(units.toTrName()).arg(tr("diameter"));
|
||||
}
|
||||
}
|
||||
Distance FrameCd::w() const
|
||||
{
|
||||
return (mW == 0) ? 2*mR1 : mW;
|
||||
}
|
||||
|
||||
|
||||
bool FrameCd::isSimilarTo( const Frame& other ) const
|
||||
{
|
||||
if ( auto *otherCd = dynamic_cast<const FrameCd*>(&other) )
|
||||
{
|
||||
if ( (fabs( mW - otherCd->mW ) <= EPSILON) &&
|
||||
(fabs( mH - otherCd->mH ) <= EPSILON) &&
|
||||
(fabs( mR1 - otherCd->mR1 ) <= EPSILON) &&
|
||||
(fabs( mR2 - otherCd->mR2 ) <= EPSILON) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Distance FrameCd::h() const
|
||||
{
|
||||
return (mH == 0) ? 2*mR1 : mH;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameCd::path() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
Distance FrameCd::r1() const
|
||||
{
|
||||
return mR1;
|
||||
}
|
||||
|
||||
const QPainterPath& FrameCd::clipPath() const
|
||||
{
|
||||
return mClipPath;
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FrameCd::marginPath( Distance xSize, Distance ySize ) const
|
||||
{
|
||||
// Note: ignore ySize, assume xSize == ySize
|
||||
Distance size = xSize;
|
||||
|
||||
Distance wReal = (mW == 0) ? 2*mR1 : mW;
|
||||
Distance hReal = (mH == 0) ? 2*mR1 : mH;
|
||||
Distance FrameCd::r2() const
|
||||
{
|
||||
return mR2;
|
||||
}
|
||||
|
||||
Distance r1 = mR1 - size;
|
||||
Distance r2 = mR2 + size;
|
||||
|
||||
QPainterPath path;
|
||||
Distance FrameCd::waste() const
|
||||
{
|
||||
return mWaste;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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() );
|
||||
QString FrameCd::sizeDescription( Units units ) const
|
||||
{
|
||||
if ( units.toEnum() == Units::IN )
|
||||
{
|
||||
QString dStr = StrUtil::formatFraction( 2 * mR1.in() );
|
||||
|
||||
path.addPath( outerPath & clipPath );
|
||||
path.closeSubpath();
|
||||
return QString("%1 %2 %3").arg(dStr).arg(units.toTrName()).arg(tr("diameter"));
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString("%1 %2 %3").arg(2 * mR1.inUnits(units), 0, 'g', 5)
|
||||
.arg(units.toTrName()).arg(tr("diameter"));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Add inner subpath
|
||||
*/
|
||||
path.addEllipse( (wReal/2 - r2).pt(), (hReal/2 - r2).pt(), 2*r2.pt(), 2*r2.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
bool FrameCd::isSimilarTo( const Frame& other ) const
|
||||
{
|
||||
if ( auto *otherCd = dynamic_cast<const FrameCd*>(&other) )
|
||||
{
|
||||
if ( (fabs( mW - otherCd->mW ) <= EPSILON) &&
|
||||
(fabs( mH - otherCd->mH ) <= EPSILON) &&
|
||||
(fabs( mR1 - otherCd->mR1 ) <= EPSILON) &&
|
||||
(fabs( mR2 - otherCd->mR2 ) <= EPSILON) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
void FrameCd::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "FrameCd{ "
|
||||
<< id() << ","
|
||||
<< r1() << ","
|
||||
<< r2() << ","
|
||||
<< waste() << ","
|
||||
<< w() << ","
|
||||
<< h() << ","
|
||||
<< "list{ ";
|
||||
for ( auto& layout : layouts() )
|
||||
{
|
||||
dbg.nospace() << layout << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< "list{ ";
|
||||
for ( auto& markup : markups() )
|
||||
{
|
||||
dbg.nospace() << *markup << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< " }";
|
||||
}
|
||||
|
||||
}
|
||||
const QPainterPath& FrameCd::path() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameCd::clipPath() const
|
||||
{
|
||||
return mClipPath;
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FrameCd::marginPath( Distance xSize, Distance ySize ) const
|
||||
{
|
||||
// Note: ignore ySize, assume xSize == ySize
|
||||
Distance size = xSize;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
void FrameCd::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "FrameCd{ "
|
||||
<< id() << ","
|
||||
<< r1() << ","
|
||||
<< r2() << ","
|
||||
<< waste() << ","
|
||||
<< w() << ","
|
||||
<< h() << ","
|
||||
<< "list{ ";
|
||||
for ( auto& layout : layouts() )
|
||||
{
|
||||
dbg.nospace() << layout << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< "list{ ";
|
||||
for ( auto& markup : markups() )
|
||||
{
|
||||
dbg.nospace() << *markup << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< " }";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
/* FrameCd.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_FrameCd_h
|
||||
#define model_FrameCd_h
|
||||
|
||||
|
||||
#include "Frame.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
class FrameCd : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FrameCd)
|
||||
|
||||
public:
|
||||
FrameCd( Distance r1,
|
||||
Distance r2,
|
||||
Distance w,
|
||||
Distance h,
|
||||
Distance waste,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameCd( const FrameCd &other ) = default;
|
||||
|
||||
std::unique_ptr<Frame> clone() const override;
|
||||
|
||||
Distance r1() const;
|
||||
Distance r2() const;
|
||||
Distance waste() const;
|
||||
|
||||
Distance w() const override;
|
||||
Distance h() const override;
|
||||
|
||||
QString sizeDescription( Units units ) const override;
|
||||
bool isSimilarTo( const Frame& other ) const override;
|
||||
|
||||
const QPainterPath& path() const override;
|
||||
const QPainterPath& clipPath() const override;
|
||||
QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
|
||||
private:
|
||||
Distance mR1;
|
||||
Distance mR2;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
QPainterPath mClipPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_FrameCd_h
|
||||
@@ -0,0 +1,80 @@
|
||||
// FrameCd.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_FrameCd_hpp
|
||||
#define model_FrameCd_hpp
|
||||
|
||||
|
||||
#include "Frame.hpp"
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
class FrameCd : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FrameCd)
|
||||
|
||||
public:
|
||||
FrameCd( Distance r1,
|
||||
Distance r2,
|
||||
Distance w,
|
||||
Distance h,
|
||||
Distance waste,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameCd( const FrameCd &other ) = default;
|
||||
|
||||
std::unique_ptr<Frame> clone() const override;
|
||||
|
||||
Distance r1() const;
|
||||
Distance r2() const;
|
||||
Distance waste() const;
|
||||
|
||||
Distance w() const override;
|
||||
Distance h() const override;
|
||||
|
||||
QString sizeDescription( Units units ) const override;
|
||||
bool isSimilarTo( const Frame& other ) const override;
|
||||
|
||||
const QPainterPath& path() const override;
|
||||
const QPainterPath& clipPath() const override;
|
||||
QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
|
||||
private:
|
||||
Distance mR1;
|
||||
Distance mR2;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
QPainterPath mClipPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_FrameCd_hpp
|
||||
+144
-147
@@ -1,175 +1,172 @@
|
||||
/* FrameContinuous.cpp
|
||||
*
|
||||
* Copyright (C) 2018 Jaye 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/>.
|
||||
*/
|
||||
// FrameContinuous.cpp
|
||||
//
|
||||
// Copyright (C) 2018 Jaye 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 "FrameContinuous.h"
|
||||
#include "FrameContinuous.hpp"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "StrUtil.h"
|
||||
#include "Constants.hpp"
|
||||
#include "StrUtil.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace glabels
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
FrameContinuous::FrameContinuous( Distance w,
|
||||
Distance hMin,
|
||||
Distance hMax,
|
||||
Distance hDefault,
|
||||
const QString& id )
|
||||
: Frame(id),
|
||||
mW(w),
|
||||
mHMin(hMin),
|
||||
mHMax(hMax),
|
||||
mHDefault(hDefault),
|
||||
mH(hDefault)
|
||||
{
|
||||
mPath.addRect( 0, 0, mW.pt(), mH.pt() );
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Frame> FrameContinuous::clone() const
|
||||
{
|
||||
return std::make_unique<FrameContinuous>( *this );
|
||||
}
|
||||
FrameContinuous::FrameContinuous( Distance w,
|
||||
Distance hMin,
|
||||
Distance hMax,
|
||||
Distance hDefault,
|
||||
const QString& id )
|
||||
: Frame(id),
|
||||
mW(w),
|
||||
mHMin(hMin),
|
||||
mHMax(hMax),
|
||||
mHDefault(hDefault),
|
||||
mH(hDefault)
|
||||
{
|
||||
mPath.addRect( 0, 0, mW.pt(), mH.pt() );
|
||||
}
|
||||
|
||||
|
||||
Distance FrameContinuous::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameContinuous::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
std::unique_ptr<Frame> FrameContinuous::clone() const
|
||||
{
|
||||
return std::make_unique<FrameContinuous>( *this );
|
||||
}
|
||||
|
||||
|
||||
Distance FrameContinuous::hMin() const
|
||||
{
|
||||
return mHMin;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameContinuous::hMax() const
|
||||
{
|
||||
return mHMax;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameContinuous::hDefault() const
|
||||
{
|
||||
return mHDefault;
|
||||
}
|
||||
Distance FrameContinuous::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
|
||||
bool FrameContinuous::setH( Distance h )
|
||||
{
|
||||
mH = h;
|
||||
mPath = QPainterPath(); // clear path
|
||||
mPath.addRect( 0, 0, mW.pt(), mH.pt() );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
QString FrameContinuous::sizeDescription( Units units ) const
|
||||
{
|
||||
if ( units.toEnum() == Units::IN )
|
||||
{
|
||||
QString wStr = StrUtil::formatFraction( mW.in() );
|
||||
|
||||
return QString("%1 %2 %3").arg(wStr).arg(units.toTrName()).arg(tr("wide"));
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString("%1 %2 %3").arg(mW.inUnits(units), 0, 'f', 3).arg(units.toTrName()).arg(tr("wide"));
|
||||
}
|
||||
}
|
||||
Distance FrameContinuous::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
|
||||
|
||||
bool FrameContinuous::isSimilarTo( const Frame& other ) const
|
||||
{
|
||||
if ( auto *otherContinuous = dynamic_cast<const FrameContinuous*>(&other) )
|
||||
{
|
||||
if ( fabs( mW - otherContinuous->mW ) <= EPSILON )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Distance FrameContinuous::hMin() const
|
||||
{
|
||||
return mHMin;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameContinuous::path() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
Distance FrameContinuous::hMax() const
|
||||
{
|
||||
return mHMax;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameContinuous::clipPath() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
Distance FrameContinuous::hDefault() const
|
||||
{
|
||||
return mHDefault;
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FrameContinuous::marginPath( Distance xSize, Distance ySize ) const
|
||||
{
|
||||
Distance w = mW - 2*xSize;
|
||||
Distance h = mH - 2*ySize;
|
||||
|
||||
QPainterPath path;
|
||||
path.addRect( xSize.pt(), ySize.pt(), w.pt(), h.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
bool FrameContinuous::setH( Distance h )
|
||||
{
|
||||
mH = h;
|
||||
mPath = QPainterPath(); // clear path
|
||||
mPath.addRect( 0, 0, mW.pt(), mH.pt() );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
void FrameContinuous::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "FrameContinuous{ "
|
||||
<< id() << ","
|
||||
<< w() << ","
|
||||
<< h() << ","
|
||||
<< hMin() << ","
|
||||
<< hMax() << ","
|
||||
<< hDefault() << ","
|
||||
<< "list{ ";
|
||||
for ( auto& layout : layouts() )
|
||||
{
|
||||
dbg.nospace() << layout << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< "list{ ";
|
||||
for ( auto& markup : markups() )
|
||||
{
|
||||
dbg.nospace() << *markup << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< " }";
|
||||
}
|
||||
QString FrameContinuous::sizeDescription( Units units ) const
|
||||
{
|
||||
if ( units.toEnum() == Units::IN )
|
||||
{
|
||||
QString wStr = StrUtil::formatFraction( mW.in() );
|
||||
|
||||
return QString("%1 %2 %3").arg(wStr).arg(units.toTrName()).arg(tr("wide"));
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString("%1 %2 %3").arg(mW.inUnits(units), 0, 'f', 3).arg(units.toTrName()).arg(tr("wide"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool FrameContinuous::isSimilarTo( const Frame& other ) const
|
||||
{
|
||||
if ( auto *otherContinuous = dynamic_cast<const FrameContinuous*>(&other) )
|
||||
{
|
||||
if ( fabs( mW - otherContinuous->mW ) <= EPSILON )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameContinuous::path() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameContinuous::clipPath() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FrameContinuous::marginPath( Distance xSize, Distance ySize ) const
|
||||
{
|
||||
Distance w = mW - 2*xSize;
|
||||
Distance h = mH - 2*ySize;
|
||||
|
||||
QPainterPath path;
|
||||
path.addRect( xSize.pt(), ySize.pt(), w.pt(), h.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
void FrameContinuous::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "FrameContinuous{ "
|
||||
<< id() << ","
|
||||
<< w() << ","
|
||||
<< h() << ","
|
||||
<< hMin() << ","
|
||||
<< hMax() << ","
|
||||
<< hDefault() << ","
|
||||
<< "list{ ";
|
||||
for ( auto& layout : layouts() )
|
||||
{
|
||||
dbg.nospace() << layout << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< "list{ ";
|
||||
for ( auto& markup : markups() )
|
||||
{
|
||||
dbg.nospace() << *markup << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< " }";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
/* FrameContinuous.h
|
||||
*
|
||||
* Copyright (C) 2018 Jaye 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 model_FrameContinuous_h
|
||||
#define model_FrameContinuous_h
|
||||
|
||||
|
||||
#include "Frame.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
class FrameContinuous : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FrameContinuous)
|
||||
|
||||
public:
|
||||
FrameContinuous( Distance w,
|
||||
Distance hMin,
|
||||
Distance hMax,
|
||||
Distance hDefault,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameContinuous( const FrameContinuous& other ) = default;
|
||||
|
||||
std::unique_ptr<Frame> clone() const override;
|
||||
|
||||
Distance w() const override;
|
||||
Distance h() const override;
|
||||
|
||||
Distance hMin() const;
|
||||
Distance hMax() const;
|
||||
Distance hDefault() const;
|
||||
|
||||
bool setH( Distance h ) override;
|
||||
|
||||
QString sizeDescription( Units units ) const override;
|
||||
|
||||
bool isSimilarTo( const Frame& other ) const override;
|
||||
|
||||
const QPainterPath& path() const override;
|
||||
const QPainterPath& clipPath() const override;
|
||||
QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
|
||||
private:
|
||||
Distance mW;
|
||||
Distance mHMin;
|
||||
Distance mHMax;
|
||||
Distance mHDefault;
|
||||
Distance mH;
|
||||
|
||||
QPainterPath mPath;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_FrameContinuous_h
|
||||
@@ -0,0 +1,80 @@
|
||||
// FrameContinuous.hpp
|
||||
//
|
||||
// Copyright (C) 2018 Jaye 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 model_FrameContinuous_hpp
|
||||
#define model_FrameContinuous_hpp
|
||||
|
||||
|
||||
#include "Frame.hpp"
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
class FrameContinuous : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FrameContinuous)
|
||||
|
||||
public:
|
||||
FrameContinuous( Distance w,
|
||||
Distance hMin,
|
||||
Distance hMax,
|
||||
Distance hDefault,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameContinuous( const FrameContinuous& other ) = default;
|
||||
|
||||
std::unique_ptr<Frame> clone() const override;
|
||||
|
||||
Distance w() const override;
|
||||
Distance h() const override;
|
||||
|
||||
Distance hMin() const;
|
||||
Distance hMax() const;
|
||||
Distance hDefault() const;
|
||||
|
||||
bool setH( Distance h ) override;
|
||||
|
||||
QString sizeDescription( Units units ) const override;
|
||||
|
||||
bool isSimilarTo( const Frame& other ) const override;
|
||||
|
||||
const QPainterPath& path() const override;
|
||||
const QPainterPath& clipPath() const override;
|
||||
QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
|
||||
private:
|
||||
Distance mW;
|
||||
Distance mHMin;
|
||||
Distance mHMax;
|
||||
Distance mHDefault;
|
||||
Distance mH;
|
||||
|
||||
QPainterPath mPath;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_FrameContinuous_hpp
|
||||
+130
-133
@@ -1,157 +1,154 @@
|
||||
/* FrameEllipse.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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/>.
|
||||
*/
|
||||
// FrameEllipse.cpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 "FrameEllipse.hpp"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "StrUtil.h"
|
||||
#include "Constants.hpp"
|
||||
#include "StrUtil.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace glabels
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
FrameEllipse::FrameEllipse( Distance w,
|
||||
Distance h,
|
||||
Distance waste,
|
||||
const QString& id )
|
||||
: Frame(id),
|
||||
mW(w),
|
||||
mH(h),
|
||||
mWaste(waste)
|
||||
{
|
||||
mPath.addEllipse( 0, 0, mW.pt(), mH.pt() );
|
||||
mClipPath.addEllipse( -mWaste.pt(), -mWaste.pt(), (mW+2*mWaste).pt(), (mH+2*mWaste).pt() );
|
||||
}
|
||||
FrameEllipse::FrameEllipse( Distance w,
|
||||
Distance h,
|
||||
Distance waste,
|
||||
const QString& id )
|
||||
: Frame(id),
|
||||
mW(w),
|
||||
mH(h),
|
||||
mWaste(waste)
|
||||
{
|
||||
mPath.addEllipse( 0, 0, mW.pt(), mH.pt() );
|
||||
mClipPath.addEllipse( -mWaste.pt(), -mWaste.pt(), (mW+2*mWaste).pt(), (mH+2*mWaste).pt() );
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Frame> FrameEllipse::clone() const
|
||||
{
|
||||
return std::make_unique<FrameEllipse>( *this );
|
||||
}
|
||||
std::unique_ptr<Frame> FrameEllipse::clone() const
|
||||
{
|
||||
return std::make_unique<FrameEllipse>( *this );
|
||||
}
|
||||
|
||||
|
||||
Distance FrameEllipse::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameEllipse::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameEllipse::waste() const
|
||||
{
|
||||
return mWaste;
|
||||
}
|
||||
Distance FrameEllipse::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
|
||||
QString FrameEllipse::sizeDescription( Units units ) const
|
||||
{
|
||||
if ( units.toEnum() == Units::IN )
|
||||
{
|
||||
QString wStr = StrUtil::formatFraction( mW.in() );
|
||||
QString hStr = StrUtil::formatFraction( mH.in() );
|
||||
|
||||
return QString("%1 x %2 %3").arg(wStr).arg(hStr).arg(units.toTrName());
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString("%1 x %2 %3").arg(mW.inUnits(units), 0, 'g', 5)
|
||||
.arg(mH.inUnits(units), 0, 'g', 5)
|
||||
.arg(units.toTrName());
|
||||
}
|
||||
}
|
||||
Distance FrameEllipse::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
|
||||
|
||||
bool FrameEllipse::isSimilarTo( const Frame& other ) const
|
||||
{
|
||||
if ( auto* otherEllipse = dynamic_cast<const FrameEllipse*>(&other) )
|
||||
{
|
||||
if ( (fabs( mW - otherEllipse->mW ) <= EPSILON) &&
|
||||
(fabs( mH - otherEllipse->mH ) <= EPSILON) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Distance FrameEllipse::waste() const
|
||||
{
|
||||
return mWaste;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameEllipse::path() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
QString FrameEllipse::sizeDescription( Units units ) const
|
||||
{
|
||||
if ( units.toEnum() == Units::IN )
|
||||
{
|
||||
QString wStr = StrUtil::formatFraction( mW.in() );
|
||||
QString hStr = StrUtil::formatFraction( mH.in() );
|
||||
|
||||
|
||||
const QPainterPath& FrameEllipse::clipPath() const
|
||||
{
|
||||
return mClipPath;
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FrameEllipse::marginPath( Distance xSize, Distance ySize ) const
|
||||
{
|
||||
// Note: ignore ySize, assume xSize == ySize
|
||||
Distance size = xSize;
|
||||
|
||||
Distance w = mW - 2*size;
|
||||
Distance h = mH - 2*size;
|
||||
|
||||
QPainterPath path;
|
||||
path.addEllipse( size.pt(), size.pt(), w.pt(), h.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
return QString("%1 x %2 %3").arg(wStr).arg(hStr).arg(units.toTrName());
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString("%1 x %2 %3").arg(mW.inUnits(units), 0, 'g', 5)
|
||||
.arg(mH.inUnits(units), 0, 'g', 5)
|
||||
.arg(units.toTrName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
void FrameEllipse::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "FrameEllipse{ "
|
||||
<< id() << ","
|
||||
<< w() << ","
|
||||
<< h() << ","
|
||||
<< waste() << ","
|
||||
<< "list{ ";
|
||||
for ( auto& layout : layouts() )
|
||||
{
|
||||
dbg.nospace() << layout << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< "list{ ";
|
||||
for ( auto& markup : markups() )
|
||||
{
|
||||
dbg.nospace() << *markup << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< " }";
|
||||
}
|
||||
bool FrameEllipse::isSimilarTo( const Frame& other ) const
|
||||
{
|
||||
if ( auto* otherEllipse = dynamic_cast<const FrameEllipse*>(&other) )
|
||||
{
|
||||
if ( (fabs( mW - otherEllipse->mW ) <= EPSILON) &&
|
||||
(fabs( mH - otherEllipse->mH ) <= EPSILON) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameEllipse::path() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameEllipse::clipPath() const
|
||||
{
|
||||
return mClipPath;
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FrameEllipse::marginPath( Distance xSize, Distance ySize ) const
|
||||
{
|
||||
// Note: ignore ySize, assume xSize == ySize
|
||||
Distance size = xSize;
|
||||
|
||||
Distance w = mW - 2*size;
|
||||
Distance h = mH - 2*size;
|
||||
|
||||
QPainterPath path;
|
||||
path.addEllipse( size.pt(), size.pt(), w.pt(), h.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
void FrameEllipse::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "FrameEllipse{ "
|
||||
<< id() << ","
|
||||
<< w() << ","
|
||||
<< h() << ","
|
||||
<< waste() << ","
|
||||
<< "list{ ";
|
||||
for ( auto& layout : layouts() )
|
||||
{
|
||||
dbg.nospace() << layout << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< "list{ ";
|
||||
for ( auto& markup : markups() )
|
||||
{
|
||||
dbg.nospace() << *markup << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< " }";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
/* FrameEllipse.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_FrameEllipse_h
|
||||
#define model_FrameEllipse_h
|
||||
|
||||
|
||||
#include "Frame.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
class FrameEllipse : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FrameEllipse)
|
||||
|
||||
public:
|
||||
FrameEllipse( Distance w,
|
||||
Distance h,
|
||||
Distance waste,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameEllipse( const FrameEllipse& other ) = default;
|
||||
|
||||
std::unique_ptr<Frame> clone() const override;
|
||||
|
||||
Distance waste() const;
|
||||
|
||||
Distance w() const override;
|
||||
Distance h() const override;
|
||||
|
||||
QString sizeDescription( Units units ) const override;
|
||||
bool isSimilarTo( const Frame& other ) const override;
|
||||
|
||||
const QPainterPath& path() const override;
|
||||
const QPainterPath& clipPath() const override;
|
||||
QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
|
||||
private:
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
QPainterPath mClipPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_FrameEllipse_h
|
||||
@@ -0,0 +1,74 @@
|
||||
// FrameEllipse.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_FrameEllipse_hpp
|
||||
#define model_FrameEllipse_hpp
|
||||
|
||||
|
||||
#include "Frame.hpp"
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
class FrameEllipse : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FrameEllipse)
|
||||
|
||||
public:
|
||||
FrameEllipse( Distance w,
|
||||
Distance h,
|
||||
Distance waste,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameEllipse( const FrameEllipse& other ) = default;
|
||||
|
||||
std::unique_ptr<Frame> clone() const override;
|
||||
|
||||
Distance waste() const;
|
||||
|
||||
Distance w() const override;
|
||||
Distance h() const override;
|
||||
|
||||
QString sizeDescription( Units units ) const override;
|
||||
bool isSimilarTo( const Frame& other ) const override;
|
||||
|
||||
const QPainterPath& path() const override;
|
||||
const QPainterPath& clipPath() const override;
|
||||
QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
|
||||
private:
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
QPainterPath mClipPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_FrameEllipse_hpp
|
||||
+131
-134
@@ -1,166 +1,163 @@
|
||||
/* FramePath.cpp
|
||||
*
|
||||
* Copyright (C) 2018 Jaye 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/>.
|
||||
*/
|
||||
// FramePath.cpp
|
||||
//
|
||||
// Copyright (C) 2018 Jaye 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 "FramePath.h"
|
||||
#include "FramePath.hpp"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "StrUtil.h"
|
||||
#include "Constants.hpp"
|
||||
#include "StrUtil.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace glabels
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
FramePath::FramePath( const QPainterPath& path,
|
||||
Distance xWaste,
|
||||
Distance yWaste,
|
||||
Units originalUnits,
|
||||
const QString& id )
|
||||
: Frame(id),
|
||||
mXWaste(xWaste),
|
||||
mYWaste(yWaste),
|
||||
mPath(path),
|
||||
mOriginalUnits(originalUnits)
|
||||
{
|
||||
QRectF r = path.boundingRect();
|
||||
|
||||
mW = Distance::pt( r.width() );
|
||||
mH = Distance::pt( r.height() );
|
||||
FramePath::FramePath( const QPainterPath& path,
|
||||
Distance xWaste,
|
||||
Distance yWaste,
|
||||
Units originalUnits,
|
||||
const QString& id )
|
||||
: Frame(id),
|
||||
mXWaste(xWaste),
|
||||
mYWaste(yWaste),
|
||||
mPath(path),
|
||||
mOriginalUnits(originalUnits)
|
||||
{
|
||||
QRectF r = path.boundingRect();
|
||||
|
||||
mClipPath.addRect( r.x()-mXWaste.pt(), r.y()-mYWaste.pt(),
|
||||
r.width() + 2*mXWaste.pt(), r.height() + 2*mYWaste.pt() );
|
||||
}
|
||||
mW = Distance::pt( r.width() );
|
||||
mH = Distance::pt( r.height() );
|
||||
|
||||
|
||||
std::unique_ptr<Frame> FramePath::clone() const
|
||||
{
|
||||
return std::make_unique<FramePath>( *this );
|
||||
}
|
||||
mClipPath.addRect( r.x()-mXWaste.pt(), r.y()-mYWaste.pt(),
|
||||
r.width() + 2*mXWaste.pt(), r.height() + 2*mYWaste.pt() );
|
||||
}
|
||||
|
||||
|
||||
Distance FramePath::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
|
||||
Distance FramePath::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
std::unique_ptr<Frame> FramePath::clone() const
|
||||
{
|
||||
return std::make_unique<FramePath>( *this );
|
||||
}
|
||||
|
||||
|
||||
Distance FramePath::xWaste() const
|
||||
{
|
||||
return mXWaste;
|
||||
}
|
||||
|
||||
|
||||
Distance FramePath::yWaste() const
|
||||
{
|
||||
return mYWaste;
|
||||
}
|
||||
Distance FramePath::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
|
||||
Units FramePath::originalUnits() const
|
||||
{
|
||||
return mOriginalUnits;
|
||||
}
|
||||
Distance FramePath::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
|
||||
|
||||
QString FramePath::sizeDescription( Units units ) const
|
||||
{
|
||||
if ( units.toEnum() == Units::IN )
|
||||
{
|
||||
QString wStr = StrUtil::formatFraction( mW.in() );
|
||||
QString hStr = StrUtil::formatFraction( mH.in() );
|
||||
|
||||
return QString("%1 x %2 %3").arg(wStr).arg(hStr).arg(units.toTrName());
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString("%1 x %2 %3").arg(mW.inUnits(units), 0, 'g', 5)
|
||||
.arg(mH.inUnits(units), 0, 'g', 5)
|
||||
.arg(units.toTrName());
|
||||
}
|
||||
}
|
||||
Distance FramePath::xWaste() const
|
||||
{
|
||||
return mXWaste;
|
||||
}
|
||||
|
||||
|
||||
bool FramePath::isSimilarTo( const Frame& other ) const
|
||||
{
|
||||
if ( auto *otherPath = dynamic_cast<const FramePath*>(&other) )
|
||||
{
|
||||
if ( mPath == otherPath->mPath )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Distance FramePath::yWaste() const
|
||||
{
|
||||
return mYWaste;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FramePath::path() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
Units FramePath::originalUnits() const
|
||||
{
|
||||
return mOriginalUnits;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FramePath::clipPath() const
|
||||
{
|
||||
return mClipPath;
|
||||
}
|
||||
QString FramePath::sizeDescription( Units units ) const
|
||||
{
|
||||
if ( units.toEnum() == Units::IN )
|
||||
{
|
||||
QString wStr = StrUtil::formatFraction( mW.in() );
|
||||
QString hStr = StrUtil::formatFraction( mH.in() );
|
||||
|
||||
return QString("%1 x %2 %3").arg(wStr).arg(hStr).arg(units.toTrName());
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString("%1 x %2 %3").arg(mW.inUnits(units), 0, 'g', 5)
|
||||
.arg(mH.inUnits(units), 0, 'g', 5)
|
||||
.arg(units.toTrName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FramePath::marginPath( Distance xSize, Distance ySize ) const
|
||||
{
|
||||
return mPath; // No margin
|
||||
}
|
||||
bool FramePath::isSimilarTo( const Frame& other ) const
|
||||
{
|
||||
if ( auto *otherPath = dynamic_cast<const FramePath*>(&other) )
|
||||
{
|
||||
if ( mPath == otherPath->mPath )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
void FramePath::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "FramePath{ "
|
||||
<< id() << ","
|
||||
<< path() << ","
|
||||
<< xWaste() << ","
|
||||
<< yWaste() << ","
|
||||
<< "list{ ";
|
||||
for ( auto& layout : layouts() )
|
||||
{
|
||||
dbg.nospace() << layout << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< "list{ ";
|
||||
for ( auto& markup : markups() )
|
||||
{
|
||||
dbg.nospace() << *markup << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< " }";
|
||||
}
|
||||
const QPainterPath& FramePath::path() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FramePath::clipPath() const
|
||||
{
|
||||
return mClipPath;
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FramePath::marginPath( Distance xSize, Distance ySize ) const
|
||||
{
|
||||
return mPath; // No margin
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
void FramePath::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "FramePath{ "
|
||||
<< id() << ","
|
||||
<< path() << ","
|
||||
<< xWaste() << ","
|
||||
<< yWaste() << ","
|
||||
<< "list{ ";
|
||||
for ( auto& layout : layouts() )
|
||||
{
|
||||
dbg.nospace() << layout << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< "list{ ";
|
||||
for ( auto& markup : markups() )
|
||||
{
|
||||
dbg.nospace() << *markup << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< " }";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
/* FramePath.h
|
||||
*
|
||||
* Copyright (C) 2018 Jaye 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 model_FramePath_h
|
||||
#define model_FramePath_h
|
||||
|
||||
|
||||
#include "Frame.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
class FramePath : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FramePath)
|
||||
|
||||
public:
|
||||
FramePath( const QPainterPath& path,
|
||||
Distance xWaste,
|
||||
Distance yWaste,
|
||||
Units originalUnits,
|
||||
const QString& id = "0" );
|
||||
|
||||
FramePath( const FramePath& other ) = default;
|
||||
|
||||
std::unique_ptr<Frame> clone() const override;
|
||||
|
||||
Distance xWaste() const;
|
||||
Distance yWaste() const;
|
||||
|
||||
Units originalUnits() const;
|
||||
|
||||
Distance w() const override;
|
||||
Distance h() const override;
|
||||
|
||||
QString sizeDescription( Units units ) const override;
|
||||
|
||||
bool isSimilarTo( const Frame& other ) const override;
|
||||
|
||||
const QPainterPath& path() const override;
|
||||
const QPainterPath& clipPath() const override;
|
||||
QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
|
||||
private:
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mXWaste;
|
||||
Distance mYWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
QPainterPath mClipPath;
|
||||
|
||||
Units mOriginalUnits;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_FramePath_h
|
||||
@@ -0,0 +1,81 @@
|
||||
// FramePath.hpp
|
||||
//
|
||||
// Copyright (C) 2018 Jaye 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 model_FramePath_hpp
|
||||
#define model_FramePath_hpp
|
||||
|
||||
|
||||
#include "Frame.hpp"
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
class FramePath : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FramePath)
|
||||
|
||||
public:
|
||||
FramePath( const QPainterPath& path,
|
||||
Distance xWaste,
|
||||
Distance yWaste,
|
||||
Units originalUnits,
|
||||
const QString& id = "0" );
|
||||
|
||||
FramePath( const FramePath& other ) = default;
|
||||
|
||||
std::unique_ptr<Frame> clone() const override;
|
||||
|
||||
Distance xWaste() const;
|
||||
Distance yWaste() const;
|
||||
|
||||
Units originalUnits() const;
|
||||
|
||||
Distance w() const override;
|
||||
Distance h() const override;
|
||||
|
||||
QString sizeDescription( Units units ) const override;
|
||||
|
||||
bool isSimilarTo( const Frame& other ) const override;
|
||||
|
||||
const QPainterPath& path() const override;
|
||||
const QPainterPath& clipPath() const override;
|
||||
QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
|
||||
private:
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mXWaste;
|
||||
Distance mYWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
QPainterPath mClipPath;
|
||||
|
||||
Units mOriginalUnits;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_FramePath_hpp
|
||||
+143
-146
@@ -1,176 +1,173 @@
|
||||
/* FrameRect.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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/>.
|
||||
*/
|
||||
// FrameRect.cpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 "FrameRect.hpp"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "StrUtil.h"
|
||||
#include "Constants.hpp"
|
||||
#include "StrUtil.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace glabels
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
FrameRect::FrameRect( Distance w,
|
||||
Distance h,
|
||||
Distance r,
|
||||
Distance xWaste,
|
||||
Distance yWaste,
|
||||
const QString& id )
|
||||
: Frame(id),
|
||||
mW(w),
|
||||
mH(h),
|
||||
mR(r),
|
||||
mXWaste(xWaste),
|
||||
mYWaste(yWaste)
|
||||
{
|
||||
mPath.addRoundedRect( 0, 0, mW.pt(), mH.pt(), mR.pt(), mR.pt() );
|
||||
|
||||
mClipPath.addRoundedRect( -mXWaste.pt(), -mYWaste.pt(),
|
||||
mW.pt() + 2*mXWaste.pt(), mH.pt() + 2*mYWaste.pt(),
|
||||
mR.pt(), mR.pt() );
|
||||
}
|
||||
FrameRect::FrameRect( Distance w,
|
||||
Distance h,
|
||||
Distance r,
|
||||
Distance xWaste,
|
||||
Distance yWaste,
|
||||
const QString& id )
|
||||
: Frame(id),
|
||||
mW(w),
|
||||
mH(h),
|
||||
mR(r),
|
||||
mXWaste(xWaste),
|
||||
mYWaste(yWaste)
|
||||
{
|
||||
mPath.addRoundedRect( 0, 0, mW.pt(), mH.pt(), mR.pt(), mR.pt() );
|
||||
|
||||
mClipPath.addRoundedRect( -mXWaste.pt(), -mYWaste.pt(),
|
||||
mW.pt() + 2*mXWaste.pt(), mH.pt() + 2*mYWaste.pt(),
|
||||
mR.pt(), mR.pt() );
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Frame> FrameRect::clone() const
|
||||
{
|
||||
return std::make_unique<FrameRect>( *this );
|
||||
}
|
||||
std::unique_ptr<Frame> FrameRect::clone() const
|
||||
{
|
||||
return std::make_unique<FrameRect>( *this );
|
||||
}
|
||||
|
||||
|
||||
Distance FrameRect::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameRect::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
Distance FrameRect::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameRect::r() const
|
||||
{
|
||||
return mR;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameRect::xWaste() const
|
||||
{
|
||||
return mXWaste;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameRect::yWaste() const
|
||||
{
|
||||
return mYWaste;
|
||||
}
|
||||
Distance FrameRect::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
|
||||
|
||||
QString FrameRect::sizeDescription( Units units ) const
|
||||
{
|
||||
if ( units.toEnum() == Units::IN )
|
||||
{
|
||||
QString wStr = StrUtil::formatFraction( mW.in() );
|
||||
QString hStr = StrUtil::formatFraction( mH.in() );
|
||||
|
||||
return QString("%1 x %2 %3").arg(wStr).arg(hStr).arg(units.toTrName());
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString("%1 x %2 %3").arg(mW.inUnits(units), 0, 'g', 5)
|
||||
.arg(mH.inUnits(units), 0, 'g', 5)
|
||||
.arg(units.toTrName());
|
||||
}
|
||||
}
|
||||
Distance FrameRect::r() const
|
||||
{
|
||||
return mR;
|
||||
}
|
||||
|
||||
|
||||
bool FrameRect::isSimilarTo( const Frame& other ) const
|
||||
{
|
||||
if ( auto *otherRect = dynamic_cast<const FrameRect*>(&other) )
|
||||
{
|
||||
if ( (fabs( mW - otherRect->mW ) <= EPSILON) &&
|
||||
(fabs( mH - otherRect->mH ) <= EPSILON) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Distance FrameRect::xWaste() const
|
||||
{
|
||||
return mXWaste;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameRect::path() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
Distance FrameRect::yWaste() const
|
||||
{
|
||||
return mYWaste;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameRect::clipPath() const
|
||||
{
|
||||
return mClipPath;
|
||||
}
|
||||
QString FrameRect::sizeDescription( Units units ) const
|
||||
{
|
||||
if ( units.toEnum() == Units::IN )
|
||||
{
|
||||
QString wStr = StrUtil::formatFraction( mW.in() );
|
||||
QString hStr = StrUtil::formatFraction( mH.in() );
|
||||
|
||||
return QString("%1 x %2 %3").arg(wStr).arg(hStr).arg(units.toTrName());
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString("%1 x %2 %3").arg(mW.inUnits(units), 0, 'g', 5)
|
||||
.arg(mH.inUnits(units), 0, 'g', 5)
|
||||
.arg(units.toTrName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FrameRect::marginPath( Distance xSize, Distance ySize ) const
|
||||
{
|
||||
Distance w = mW - 2*xSize;
|
||||
Distance h = mH - 2*ySize;
|
||||
Distance r = std::max( mR - std::min(xSize, ySize), Distance(0.0) );
|
||||
|
||||
QPainterPath path;
|
||||
path.addRoundedRect( xSize.pt(), ySize.pt(), w.pt(), h.pt(), r.pt(), r.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
bool FrameRect::isSimilarTo( const Frame& other ) const
|
||||
{
|
||||
if ( auto *otherRect = dynamic_cast<const FrameRect*>(&other) )
|
||||
{
|
||||
if ( (fabs( mW - otherRect->mW ) <= EPSILON) &&
|
||||
(fabs( mH - otherRect->mH ) <= EPSILON) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
void FrameRect::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "FrameRect{ "
|
||||
<< id() << ","
|
||||
<< w() << ","
|
||||
<< h() << ","
|
||||
<< r() << ","
|
||||
<< xWaste() << ","
|
||||
<< yWaste() << ","
|
||||
<< "list{ ";
|
||||
for ( auto& layout : layouts() )
|
||||
{
|
||||
dbg.nospace() << layout << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< "list{ ";
|
||||
for ( auto& markup : markups() )
|
||||
{
|
||||
dbg.nospace() << *markup << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< " }";
|
||||
}
|
||||
const QPainterPath& FrameRect::path() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameRect::clipPath() const
|
||||
{
|
||||
return mClipPath;
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FrameRect::marginPath( Distance xSize, Distance ySize ) const
|
||||
{
|
||||
Distance w = mW - 2*xSize;
|
||||
Distance h = mH - 2*ySize;
|
||||
Distance r = std::max( mR - std::min(xSize, ySize), Distance(0.0) );
|
||||
|
||||
QPainterPath path;
|
||||
path.addRoundedRect( xSize.pt(), ySize.pt(), w.pt(), h.pt(), r.pt(), r.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
void FrameRect::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "FrameRect{ "
|
||||
<< id() << ","
|
||||
<< w() << ","
|
||||
<< h() << ","
|
||||
<< r() << ","
|
||||
<< xWaste() << ","
|
||||
<< yWaste() << ","
|
||||
<< "list{ ";
|
||||
for ( auto& layout : layouts() )
|
||||
{
|
||||
dbg.nospace() << layout << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< "list{ ";
|
||||
for ( auto& markup : markups() )
|
||||
{
|
||||
dbg.nospace() << *markup << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< " }";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
/* FrameRect.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_FrameRect_h
|
||||
#define model_FrameRect_h
|
||||
|
||||
|
||||
#include "Frame.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
class FrameRect : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FrameRect)
|
||||
|
||||
public:
|
||||
FrameRect( Distance w,
|
||||
Distance h,
|
||||
Distance r,
|
||||
Distance xWaste,
|
||||
Distance yWaste,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameRect( const FrameRect& other ) = default;
|
||||
|
||||
std::unique_ptr<Frame> clone() const override;
|
||||
|
||||
Distance r() const;
|
||||
Distance xWaste() const;
|
||||
Distance yWaste() const;
|
||||
|
||||
Distance w() const override;
|
||||
Distance h() const override;
|
||||
|
||||
QString sizeDescription( Units units ) const override;
|
||||
|
||||
bool isSimilarTo( const Frame& other ) const override;
|
||||
|
||||
const QPainterPath& path() const override;
|
||||
const QPainterPath& clipPath() const override;
|
||||
QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
|
||||
private:
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mR;
|
||||
Distance mXWaste;
|
||||
Distance mYWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
QPainterPath mClipPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_FrameRect_h
|
||||
@@ -0,0 +1,81 @@
|
||||
// FrameRect.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_FrameRect_hpp
|
||||
#define model_FrameRect_hpp
|
||||
|
||||
|
||||
#include "Frame.hpp"
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
class FrameRect : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FrameRect)
|
||||
|
||||
public:
|
||||
FrameRect( Distance w,
|
||||
Distance h,
|
||||
Distance r,
|
||||
Distance xWaste,
|
||||
Distance yWaste,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameRect( const FrameRect& other ) = default;
|
||||
|
||||
std::unique_ptr<Frame> clone() const override;
|
||||
|
||||
Distance r() const;
|
||||
Distance xWaste() const;
|
||||
Distance yWaste() const;
|
||||
|
||||
Distance w() const override;
|
||||
Distance h() const override;
|
||||
|
||||
QString sizeDescription( Units units ) const override;
|
||||
|
||||
bool isSimilarTo( const Frame& other ) const override;
|
||||
|
||||
const QPainterPath& path() const override;
|
||||
const QPainterPath& clipPath() const override;
|
||||
QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
|
||||
private:
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mR;
|
||||
Distance mXWaste;
|
||||
Distance mYWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
QPainterPath mClipPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_FrameRect_hpp
|
||||
+127
-131
@@ -1,158 +1,154 @@
|
||||
/* FrameRound.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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/>.
|
||||
*/
|
||||
// FrameRound.cpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 "FrameRound.hpp"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "StrUtil.h"
|
||||
#include "Constants.hpp"
|
||||
#include "StrUtil.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace glabels
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
FrameRound::FrameRound( Distance r,
|
||||
Distance waste,
|
||||
const QString& id )
|
||||
: Frame(id),
|
||||
mR(r),
|
||||
mWaste(waste)
|
||||
{
|
||||
mPath.addEllipse( 0, 0, 2*mR.pt(), 2*mR.pt() );
|
||||
mClipPath.addEllipse( -mWaste.pt(), -mWaste.pt(),
|
||||
2*(mR+mWaste).pt(), 2*(mR+mWaste).pt() );
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Frame> FrameRound::clone() const
|
||||
{
|
||||
return std::make_unique<FrameRound>( *this );
|
||||
}
|
||||
|
||||
|
||||
Distance FrameRound::w() const
|
||||
{
|
||||
return 2*mR;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameRound::h() const
|
||||
{
|
||||
return 2*mR;
|
||||
}
|
||||
|
||||
|
||||
Distance FrameRound::r() const
|
||||
{
|
||||
return mR;
|
||||
}
|
||||
FrameRound::FrameRound( Distance r,
|
||||
Distance waste,
|
||||
const QString& id )
|
||||
: Frame(id),
|
||||
mR(r),
|
||||
mWaste(waste)
|
||||
{
|
||||
mPath.addEllipse( 0, 0, 2*mR.pt(), 2*mR.pt() );
|
||||
mClipPath.addEllipse( -mWaste.pt(), -mWaste.pt(),
|
||||
2*(mR+mWaste).pt(), 2*(mR+mWaste).pt() );
|
||||
}
|
||||
|
||||
|
||||
Distance FrameRound::waste() const
|
||||
{
|
||||
return mWaste;
|
||||
}
|
||||
std::unique_ptr<Frame> FrameRound::clone() const
|
||||
{
|
||||
return std::make_unique<FrameRound>( *this );
|
||||
}
|
||||
|
||||
|
||||
QString FrameRound::sizeDescription( Units units ) const
|
||||
{
|
||||
if ( units.toEnum() == Units::IN )
|
||||
{
|
||||
QString dStr = StrUtil::formatFraction( 2 * mR.in() );
|
||||
|
||||
return QString("%1 %2 %3").arg(dStr).arg(units.toTrName()).arg(tr("diameter"));
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString("%1 %2 %3").arg(2 * mR.inUnits(units), 0, 'g', 5)
|
||||
.arg(units.toTrName()).arg(tr("diameter"));
|
||||
}
|
||||
}
|
||||
Distance FrameRound::w() const
|
||||
{
|
||||
return 2*mR;
|
||||
}
|
||||
|
||||
|
||||
bool FrameRound::isSimilarTo( const Frame& other ) const
|
||||
{
|
||||
if ( auto *otherRound = dynamic_cast<const FrameRound*>(&other) )
|
||||
{
|
||||
if ( fabs( mR - otherRound->mR ) <= EPSILON )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Distance FrameRound::h() const
|
||||
{
|
||||
return 2*mR;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameRound::path() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
Distance FrameRound::r() const
|
||||
{
|
||||
return mR;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameRound::clipPath() const
|
||||
{
|
||||
return mClipPath;
|
||||
}
|
||||
Distance FrameRound::waste() const
|
||||
{
|
||||
return mWaste;
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FrameRound::marginPath( Distance xSize, Distance ySize ) const
|
||||
{
|
||||
// Note: ignore ySize, assume xSize == ySize
|
||||
Distance size = xSize;
|
||||
QString FrameRound::sizeDescription( Units units ) const
|
||||
{
|
||||
if ( units.toEnum() == Units::IN )
|
||||
{
|
||||
QString dStr = StrUtil::formatFraction( 2 * mR.in() );
|
||||
|
||||
Distance r = mR - size;
|
||||
|
||||
QPainterPath path;
|
||||
path.addEllipse( size.pt(), size.pt(), 2*r.pt(), 2*r.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
return QString("%1 %2 %3").arg(dStr).arg(units.toTrName()).arg(tr("diameter"));
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString("%1 %2 %3").arg(2 * mR.inUnits(units), 0, 'g', 5)
|
||||
.arg(units.toTrName()).arg(tr("diameter"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
void FrameRound::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "FrameRound{ "
|
||||
<< id() << ","
|
||||
<< r() << ","
|
||||
<< waste() << ","
|
||||
<< "list{ ";
|
||||
for ( auto& layout : layouts() )
|
||||
{
|
||||
dbg.nospace() << layout << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< "list{ ";
|
||||
for ( auto& markup : markups() )
|
||||
{
|
||||
dbg.nospace() << *markup << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< " }";
|
||||
}
|
||||
bool FrameRound::isSimilarTo( const Frame& other ) const
|
||||
{
|
||||
if ( auto *otherRound = dynamic_cast<const FrameRound*>(&other) )
|
||||
{
|
||||
if ( fabs( mR - otherRound->mR ) <= EPSILON )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameRound::path() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
|
||||
const QPainterPath& FrameRound::clipPath() const
|
||||
{
|
||||
return mClipPath;
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FrameRound::marginPath( Distance xSize, Distance ySize ) const
|
||||
{
|
||||
// Note: ignore ySize, assume xSize == ySize
|
||||
Distance size = xSize;
|
||||
|
||||
Distance r = mR - size;
|
||||
|
||||
QPainterPath path;
|
||||
path.addEllipse( size.pt(), size.pt(), 2*r.pt(), 2*r.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
void FrameRound::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "FrameRound{ "
|
||||
<< id() << ","
|
||||
<< r() << ","
|
||||
<< waste() << ","
|
||||
<< "list{ ";
|
||||
for ( auto& layout : layouts() )
|
||||
{
|
||||
dbg.nospace() << layout << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< "list{ ";
|
||||
for ( auto& markup : markups() )
|
||||
{
|
||||
dbg.nospace() << *markup << ",";
|
||||
}
|
||||
dbg.nospace() << " }"
|
||||
<< " }";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/* FrameRound.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_FrameRound_h
|
||||
#define model_FrameRound_h
|
||||
|
||||
|
||||
#include "Frame.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
class FrameRound : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FrameRound)
|
||||
|
||||
public:
|
||||
FrameRound( Distance r,
|
||||
Distance waste,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameRound( const FrameRound &other ) = default;
|
||||
|
||||
std::unique_ptr<Frame> clone() const override;
|
||||
|
||||
Distance r() const;
|
||||
Distance waste() const;
|
||||
|
||||
Distance w() const override;
|
||||
Distance h() const override;
|
||||
|
||||
QString sizeDescription( Units units ) const override;
|
||||
bool isSimilarTo( const Frame& other ) const override;
|
||||
|
||||
const QPainterPath& path() const override;
|
||||
const QPainterPath& clipPath() const override;
|
||||
QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
|
||||
private:
|
||||
Distance mR;
|
||||
Distance mWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
QPainterPath mClipPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_FrameRound_h
|
||||
@@ -0,0 +1,73 @@
|
||||
// FrameRound.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_FrameRound_hpp
|
||||
#define model_FrameRound_hpp
|
||||
|
||||
|
||||
#include "Frame.hpp"
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
class FrameRound : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FrameRound)
|
||||
|
||||
public:
|
||||
FrameRound( Distance r,
|
||||
Distance waste,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameRound( const FrameRound &other ) = default;
|
||||
|
||||
std::unique_ptr<Frame> clone() const override;
|
||||
|
||||
Distance r() const;
|
||||
Distance waste() const;
|
||||
|
||||
Distance w() const override;
|
||||
Distance h() const override;
|
||||
|
||||
QString sizeDescription( Units units ) const override;
|
||||
bool isSimilarTo( const Frame& other ) const override;
|
||||
|
||||
const QPainterPath& path() const override;
|
||||
const QPainterPath& clipPath() const override;
|
||||
QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
|
||||
private:
|
||||
Distance mR;
|
||||
Distance mWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
QPainterPath mClipPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_FrameRound_hpp
|
||||
+190
-195
@@ -1,225 +1,220 @@
|
||||
/* Handles.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jaye 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/>.
|
||||
*/
|
||||
// Handles.cpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye 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 "Handle.h"
|
||||
#include "Handle.hpp"
|
||||
|
||||
#include "ModelObject.h"
|
||||
#include "ModelObject.hpp"
|
||||
|
||||
#include <QColor>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace glabels
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const double handlePixels = 7;
|
||||
const double handleOutlineWidthPixels = 1;
|
||||
|
||||
const QColor handleFillColor( 0, 192, 0, 96 );
|
||||
const QColor originHandleFillColor( 192, 0, 0, 96 );
|
||||
const QColor handleOutlineColor( 0, 0, 0, 192 );
|
||||
}
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
namespace model
|
||||
{
|
||||
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const double handlePixels = 7;
|
||||
const double handleOutlineWidthPixels = 1;
|
||||
|
||||
const QColor handleFillColor( 0, 192, 0, 96 );
|
||||
const QColor originHandleFillColor( 192, 0, 0, 96 );
|
||||
const QColor handleOutlineColor( 0, 0, 0, 192 );
|
||||
}
|
||||
///
|
||||
/// Handle Constructor
|
||||
///
|
||||
Handle::Handle( ModelObject* owner, Location location )
|
||||
: mOwner(owner), mLocation(location)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Handle Constructor
|
||||
///
|
||||
Handle::Handle( ModelObject* owner, Location location )
|
||||
: mOwner(owner), mLocation(location)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
///
|
||||
/// Is Handle null?
|
||||
///
|
||||
bool Handle::isNull() const
|
||||
{
|
||||
return mLocation == NULL_HANDLE;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Is Handle null?
|
||||
///
|
||||
bool Handle::isNull() const
|
||||
{
|
||||
return mLocation == NULL_HANDLE;
|
||||
}
|
||||
///
|
||||
/// Handle owner
|
||||
///
|
||||
ModelObject* Handle::owner() const
|
||||
{
|
||||
return mOwner;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Handle owner
|
||||
///
|
||||
ModelObject* Handle::owner() const
|
||||
{
|
||||
return mOwner;
|
||||
}
|
||||
///
|
||||
/// Handle location
|
||||
///
|
||||
Handle::Location Handle::location() const
|
||||
{
|
||||
return mLocation;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Handle location
|
||||
///
|
||||
Handle::Location Handle::location() const
|
||||
{
|
||||
return mLocation;
|
||||
}
|
||||
///
|
||||
/// Draw Handle
|
||||
///
|
||||
void Handle::draw( QPainter* painter, double scale ) const
|
||||
{
|
||||
switch ( mLocation )
|
||||
{
|
||||
case NW:
|
||||
drawAt( painter, scale, 0, 0, originHandleFillColor );
|
||||
break;
|
||||
case N:
|
||||
drawAt( painter, scale, mOwner->w()/2, 0, handleFillColor );
|
||||
break;
|
||||
case NE:
|
||||
drawAt( painter, scale, mOwner->w(), 0, handleFillColor );
|
||||
break;
|
||||
case E:
|
||||
drawAt( painter, scale, mOwner->w(), mOwner->h()/2, handleFillColor );
|
||||
break;
|
||||
case SE:
|
||||
drawAt( painter, scale, mOwner->w(), mOwner->h(), handleFillColor );
|
||||
break;
|
||||
case S:
|
||||
drawAt( painter, scale, mOwner->w()/2, mOwner->h(), handleFillColor );
|
||||
break;
|
||||
case SW:
|
||||
drawAt( painter, scale, 0, mOwner->h(), handleFillColor );
|
||||
break;
|
||||
case W:
|
||||
drawAt( painter, scale, 0, mOwner->h()/2, handleFillColor );
|
||||
break;
|
||||
case P1:
|
||||
drawAt( painter, scale, 0, 0, originHandleFillColor );
|
||||
break;
|
||||
case P2:
|
||||
drawAt( painter, scale, mOwner->w(), mOwner->h(), handleFillColor );
|
||||
break;
|
||||
default:
|
||||
qWarning() << "Unknown Handle location";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw Handle
|
||||
///
|
||||
void Handle::draw( QPainter* painter, double scale ) const
|
||||
{
|
||||
switch ( mLocation )
|
||||
{
|
||||
case NW:
|
||||
drawAt( painter, scale, 0, 0, originHandleFillColor );
|
||||
break;
|
||||
case N:
|
||||
drawAt( painter, scale, mOwner->w()/2, 0, handleFillColor );
|
||||
break;
|
||||
case NE:
|
||||
drawAt( painter, scale, mOwner->w(), 0, handleFillColor );
|
||||
break;
|
||||
case E:
|
||||
drawAt( painter, scale, mOwner->w(), mOwner->h()/2, handleFillColor );
|
||||
break;
|
||||
case SE:
|
||||
drawAt( painter, scale, mOwner->w(), mOwner->h(), handleFillColor );
|
||||
break;
|
||||
case S:
|
||||
drawAt( painter, scale, mOwner->w()/2, mOwner->h(), handleFillColor );
|
||||
break;
|
||||
case SW:
|
||||
drawAt( painter, scale, 0, mOwner->h(), handleFillColor );
|
||||
break;
|
||||
case W:
|
||||
drawAt( painter, scale, 0, mOwner->h()/2, handleFillColor );
|
||||
break;
|
||||
case P1:
|
||||
drawAt( painter, scale, 0, 0, originHandleFillColor );
|
||||
break;
|
||||
case P2:
|
||||
drawAt( painter, scale, mOwner->w(), mOwner->h(), handleFillColor );
|
||||
break;
|
||||
default:
|
||||
qWarning() << "Unknown Handle location";
|
||||
break;
|
||||
}
|
||||
}
|
||||
///
|
||||
/// Handle Path
|
||||
///
|
||||
QPainterPath Handle::path( double scale ) const
|
||||
{
|
||||
switch ( mLocation )
|
||||
{
|
||||
case NW:
|
||||
return pathAt( scale, 0, 0 );
|
||||
break;
|
||||
case N:
|
||||
return pathAt( scale, mOwner->w()/2, 0 );
|
||||
break;
|
||||
case NE:
|
||||
return pathAt( scale, mOwner->w(), 0 );
|
||||
break;
|
||||
case E:
|
||||
return pathAt( scale, mOwner->w(), mOwner->h()/2 );
|
||||
break;
|
||||
case SE:
|
||||
return pathAt( scale, mOwner->w(), mOwner->h() );
|
||||
break;
|
||||
case S:
|
||||
return pathAt( scale, mOwner->w()/2, mOwner->h() );
|
||||
break;
|
||||
case SW:
|
||||
return pathAt( scale, 0, mOwner->h() );
|
||||
break;
|
||||
case W:
|
||||
return pathAt( scale, 0, mOwner->h()/2 );
|
||||
break;
|
||||
case P1:
|
||||
return pathAt( scale, 0, 0 );
|
||||
break;
|
||||
case P2:
|
||||
return pathAt( scale, mOwner->w(), mOwner->h() );
|
||||
break;
|
||||
default:
|
||||
qWarning() << "Unknown Handle location";
|
||||
return QPainterPath(); // Empty
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Handle Path
|
||||
///
|
||||
QPainterPath Handle::path( double scale ) const
|
||||
{
|
||||
switch ( mLocation )
|
||||
{
|
||||
case NW:
|
||||
return pathAt( scale, 0, 0 );
|
||||
break;
|
||||
case N:
|
||||
return pathAt( scale, mOwner->w()/2, 0 );
|
||||
break;
|
||||
case NE:
|
||||
return pathAt( scale, mOwner->w(), 0 );
|
||||
break;
|
||||
case E:
|
||||
return pathAt( scale, mOwner->w(), mOwner->h()/2 );
|
||||
break;
|
||||
case SE:
|
||||
return pathAt( scale, mOwner->w(), mOwner->h() );
|
||||
break;
|
||||
case S:
|
||||
return pathAt( scale, mOwner->w()/2, mOwner->h() );
|
||||
break;
|
||||
case SW:
|
||||
return pathAt( scale, 0, mOwner->h() );
|
||||
break;
|
||||
case W:
|
||||
return pathAt( scale, 0, mOwner->h()/2 );
|
||||
break;
|
||||
case P1:
|
||||
return pathAt( scale, 0, 0 );
|
||||
break;
|
||||
case P2:
|
||||
return pathAt( scale, mOwner->w(), mOwner->h() );
|
||||
break;
|
||||
default:
|
||||
qWarning() << "Unknown Handle location";
|
||||
return QPainterPath(); // Empty
|
||||
break;
|
||||
}
|
||||
}
|
||||
///
|
||||
/// Draw Handle at x,y
|
||||
///
|
||||
void Handle::drawAt( QPainter* painter,
|
||||
double scale,
|
||||
Distance x,
|
||||
Distance y,
|
||||
QColor color ) const
|
||||
{
|
||||
painter->save();
|
||||
|
||||
painter->translate( x.pt(), y.pt() );
|
||||
|
||||
double s = 1.0 / scale;
|
||||
|
||||
QPen pen( handleOutlineColor );
|
||||
pen.setCosmetic( true );
|
||||
pen.setWidth( handleOutlineWidthPixels );
|
||||
|
||||
painter->setPen( pen );
|
||||
painter->setBrush( color );
|
||||
|
||||
painter->drawRect( QRectF( -s*handlePixels/2.0, -s*handlePixels/2.0,
|
||||
s*handlePixels, s*handlePixels ) );
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw Handle at x,y
|
||||
///
|
||||
void Handle::drawAt( QPainter* painter,
|
||||
double scale,
|
||||
Distance x,
|
||||
Distance y,
|
||||
QColor color ) const
|
||||
{
|
||||
painter->save();
|
||||
///
|
||||
/// Create Handle path at x,y
|
||||
///
|
||||
QPainterPath Handle::pathAt( double scale,
|
||||
Distance x,
|
||||
Distance y ) const
|
||||
{
|
||||
QPainterPath path;
|
||||
|
||||
painter->translate( x.pt(), y.pt() );
|
||||
double s = 1/scale;
|
||||
|
||||
double s = 1.0 / scale;
|
||||
path.addRect( -s*handlePixels/2, -s*handlePixels/2, s*handlePixels, s*handlePixels );
|
||||
path.translate( x.pt(), y.pt() );
|
||||
|
||||
QPen pen( handleOutlineColor );
|
||||
pen.setCosmetic( true );
|
||||
pen.setWidth( handleOutlineWidthPixels );
|
||||
return path;
|
||||
}
|
||||
|
||||
painter->setPen( pen );
|
||||
painter->setBrush( color );
|
||||
|
||||
painter->drawRect( QRectF( -s*handlePixels/2.0, -s*handlePixels/2.0,
|
||||
s*handlePixels, s*handlePixels ) );
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Create Handle path at x,y
|
||||
///
|
||||
QPainterPath Handle::pathAt( double scale,
|
||||
Distance x,
|
||||
Distance y ) const
|
||||
{
|
||||
QPainterPath path;
|
||||
|
||||
double s = 1/scale;
|
||||
|
||||
path.addRect( -s*handlePixels/2, -s*handlePixels/2, s*handlePixels, s*handlePixels );
|
||||
path.translate( x.pt(), y.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-101
@@ -1,101 +0,0 @@
|
||||
/* Handles.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye 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 model_Handles_h
|
||||
#define model_Handles_h
|
||||
|
||||
|
||||
#include "Distance.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
// Forward References
|
||||
class ModelObject;
|
||||
|
||||
|
||||
///
|
||||
/// Handle Base Class
|
||||
///
|
||||
class Handle
|
||||
{
|
||||
////////////////////////////
|
||||
// Location enumeration
|
||||
////////////////////////////
|
||||
public:
|
||||
enum Location { NULL_HANDLE, NW, N, NE, E, SE, S, SW, W, P1, P2 };
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Lifecycle Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
Handle() = default;
|
||||
Handle( ModelObject* owner, Location location );
|
||||
~Handle() = default;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Attribute Methods
|
||||
////////////////////////////
|
||||
bool isNull() const;
|
||||
ModelObject* owner() const;
|
||||
Location location() const;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Drawing Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter, double scale ) const;
|
||||
QPainterPath path( double scale ) const;
|
||||
|
||||
private:
|
||||
void drawAt( QPainter* painter,
|
||||
double scale,
|
||||
Distance x,
|
||||
Distance y,
|
||||
QColor color ) const;
|
||||
|
||||
QPainterPath pathAt( double scale,
|
||||
Distance x,
|
||||
Distance y ) const;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Private Data
|
||||
////////////////////////////
|
||||
protected:
|
||||
ModelObject* mOwner{ nullptr };
|
||||
Location mLocation{ NULL_HANDLE };
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_Handles_h
|
||||
@@ -0,0 +1,98 @@
|
||||
// Handles.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye 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 model_Handles_hpp
|
||||
#define model_Handles_hpp
|
||||
|
||||
|
||||
#include "Distance.hpp"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
// Forward References
|
||||
class ModelObject;
|
||||
|
||||
|
||||
///
|
||||
/// Handle Base Class
|
||||
///
|
||||
class Handle
|
||||
{
|
||||
////////////////////////////
|
||||
// Location enumeration
|
||||
////////////////////////////
|
||||
public:
|
||||
enum Location { NULL_HANDLE, NW, N, NE, E, SE, S, SW, W, P1, P2 };
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Lifecycle Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
Handle() = default;
|
||||
Handle( ModelObject* owner, Location location );
|
||||
~Handle() = default;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Attribute Methods
|
||||
////////////////////////////
|
||||
bool isNull() const;
|
||||
ModelObject* owner() const;
|
||||
Location location() const;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Drawing Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter, double scale ) const;
|
||||
QPainterPath path( double scale ) const;
|
||||
|
||||
private:
|
||||
void drawAt( QPainter* painter,
|
||||
double scale,
|
||||
Distance x,
|
||||
Distance y,
|
||||
QColor color ) const;
|
||||
|
||||
QPainterPath pathAt( double scale,
|
||||
Distance x,
|
||||
Distance y ) const;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Private Data
|
||||
////////////////////////////
|
||||
protected:
|
||||
ModelObject* mOwner{ nullptr };
|
||||
Location mLocation{ NULL_HANDLE };
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_Handles_hpp
|
||||
+93
-95
@@ -1,114 +1,112 @@
|
||||
/* Layout.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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/>.
|
||||
*/
|
||||
// Layout.cpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "Layout.h"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "Layout.hpp"
|
||||
|
||||
#include "Constants.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
||||
namespace glabels
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
Layout::Layout( int nx,
|
||||
int ny,
|
||||
Distance x0,
|
||||
Distance y0,
|
||||
Distance dx,
|
||||
Distance dy )
|
||||
: mNx(nx),
|
||||
mNy(ny),
|
||||
mX0(x0),
|
||||
mY0(y0),
|
||||
mDx(dx),
|
||||
mDy(dy)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
int Layout::nx() const
|
||||
{
|
||||
return mNx;
|
||||
}
|
||||
|
||||
|
||||
int Layout::ny() const
|
||||
{
|
||||
return mNy;
|
||||
}
|
||||
|
||||
|
||||
Distance Layout::x0() const
|
||||
{
|
||||
return mX0;
|
||||
}
|
||||
|
||||
|
||||
Distance Layout::y0() const
|
||||
{
|
||||
return mY0;
|
||||
}
|
||||
|
||||
|
||||
Distance Layout::dx() const
|
||||
{
|
||||
return mDx;
|
||||
}
|
||||
|
||||
|
||||
Distance Layout::dy() const
|
||||
{
|
||||
return mDy;
|
||||
}
|
||||
Layout::Layout( int nx,
|
||||
int ny,
|
||||
Distance x0,
|
||||
Distance y0,
|
||||
Distance dx,
|
||||
Distance dy )
|
||||
: mNx(nx),
|
||||
mNy(ny),
|
||||
mX0(x0),
|
||||
mY0(y0),
|
||||
mDx(dx),
|
||||
mDy(dy)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
bool Layout::isSimilarTo( const Layout& other ) const
|
||||
{
|
||||
return ( (mNx == other.mNx) &&
|
||||
(mNy == other.mNy) &&
|
||||
(fabs(mX0 - other.mX0) < EPSILON) &&
|
||||
(fabs(mY0 - other.mY0) < EPSILON) &&
|
||||
(fabs(mDx - other.mDx) < EPSILON) &&
|
||||
(fabs(mDy - other.mDy) < EPSILON) );
|
||||
}
|
||||
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 ) const
|
||||
{
|
||||
return ( (mNx == other.mNx) &&
|
||||
(mNy == other.mNy) &&
|
||||
(fabs(mX0 - other.mX0) < EPSILON) &&
|
||||
(fabs(mY0 - other.mY0) < EPSILON) &&
|
||||
(fabs(mDx - other.mDx) < EPSILON) &&
|
||||
(fabs(mDy - other.mDy) < EPSILON) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QDebug operator<<( QDebug dbg, const glabels::model::Layout& layout )
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
QDebugStateSaver saver(dbg);
|
||||
|
||||
dbg.nospace() << "Layout{ "
|
||||
<< layout.nx() << ","
|
||||
<< layout.ny() << ","
|
||||
<< layout.x0() << ","
|
||||
<< layout.y0() << ","
|
||||
<< layout.dx() << ","
|
||||
<< layout.dy()
|
||||
<< " }";
|
||||
dbg.nospace() << "Layout{ "
|
||||
<< layout.nx() << ","
|
||||
<< layout.ny() << ","
|
||||
<< layout.x0() << ","
|
||||
<< layout.y0() << ","
|
||||
<< layout.dx() << ","
|
||||
<< layout.dy()
|
||||
<< " }";
|
||||
|
||||
return dbg;
|
||||
return dbg;
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
/* Layout.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_Layout_h
|
||||
#define model_Layout_h
|
||||
|
||||
|
||||
#include "Distance.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
class Layout
|
||||
{
|
||||
|
||||
public:
|
||||
Layout( int nx,
|
||||
int ny,
|
||||
Distance x0,
|
||||
Distance y0,
|
||||
Distance dx,
|
||||
Distance dy );
|
||||
|
||||
Layout( const Layout& other ) = default;
|
||||
|
||||
int nx() const;
|
||||
int ny() const;
|
||||
|
||||
Distance x0() const;
|
||||
Distance y0() const;
|
||||
|
||||
Distance dx() const;
|
||||
Distance dy() const;
|
||||
|
||||
bool isSimilarTo( const Layout& other ) const;
|
||||
|
||||
|
||||
private:
|
||||
int mNx;
|
||||
int mNy;
|
||||
Distance mX0;
|
||||
Distance mY0;
|
||||
Distance mDx;
|
||||
Distance mDy;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
QDebug operator<<( QDebug dbg, const glabels::model::Layout& layout );
|
||||
|
||||
|
||||
#endif // model_Layout_h
|
||||
@@ -0,0 +1,75 @@
|
||||
// Layout.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_Layout_hpp
|
||||
#define model_Layout_hpp
|
||||
|
||||
|
||||
#include "Distance.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
class Layout
|
||||
{
|
||||
|
||||
public:
|
||||
Layout( int nx,
|
||||
int ny,
|
||||
Distance x0,
|
||||
Distance y0,
|
||||
Distance dx,
|
||||
Distance dy );
|
||||
|
||||
Layout( const Layout& other ) = default;
|
||||
|
||||
int nx() const;
|
||||
int ny() const;
|
||||
|
||||
Distance x0() const;
|
||||
Distance y0() const;
|
||||
|
||||
Distance dx() const;
|
||||
Distance dy() const;
|
||||
|
||||
bool isSimilarTo( const Layout& other ) const;
|
||||
|
||||
|
||||
private:
|
||||
int mNx;
|
||||
int mNy;
|
||||
Distance mX0;
|
||||
Distance mY0;
|
||||
Distance mDx;
|
||||
Distance mDy;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
QDebug operator<<( QDebug dbg, const glabels::model::Layout& layout );
|
||||
|
||||
|
||||
#endif // model_Layout_hpp
|
||||
+260
-263
@@ -1,307 +1,304 @@
|
||||
/* Markup.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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/>.
|
||||
*/
|
||||
// Markup.cpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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"
|
||||
#include "Markup.hpp"
|
||||
|
||||
#include "Frame.h"
|
||||
#include "Frame.hpp"
|
||||
|
||||
|
||||
namespace glabels
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
QPainterPath Markup::path( const Frame& frame ) const
|
||||
{
|
||||
// Use cached path -- default does not depend on frame size
|
||||
return mPath;
|
||||
}
|
||||
|
||||
|
||||
MarkupMargin::MarkupMargin( Distance size )
|
||||
: mXSize(size),
|
||||
mYSize(size)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MarkupMargin::MarkupMargin( Distance xSize,
|
||||
Distance ySize )
|
||||
: mXSize(xSize),
|
||||
mYSize(ySize)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QPainterPath MarkupMargin::path( const Frame& frame ) const
|
||||
{
|
||||
// Re-calculate path -- frame size may have changed
|
||||
return frame.marginPath( mXSize, mYSize );
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Markup> MarkupMargin::clone() const
|
||||
{
|
||||
return std::make_unique<MarkupMargin>( mXSize, mYSize );
|
||||
}
|
||||
QPainterPath Markup::path( const Frame& frame ) const
|
||||
{
|
||||
// Use cached path -- default does not depend on frame size
|
||||
return mPath;
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupMargin::xSize() const
|
||||
{
|
||||
return mXSize;
|
||||
}
|
||||
MarkupMargin::MarkupMargin( Distance size )
|
||||
: mXSize(size),
|
||||
mYSize(size)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupMargin::ySize() const
|
||||
{
|
||||
return mYSize;
|
||||
}
|
||||
MarkupMargin::MarkupMargin( Distance xSize,
|
||||
Distance ySize )
|
||||
: mXSize(xSize),
|
||||
mYSize(ySize)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MarkupMargin::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "MarkupMargin{ "
|
||||
<< mXSize << "," << mYSize
|
||||
<< " }";
|
||||
}
|
||||
QPainterPath MarkupMargin::path( const Frame& frame ) const
|
||||
{
|
||||
// Re-calculate path -- frame size may have changed
|
||||
return frame.marginPath( mXSize, mYSize );
|
||||
}
|
||||
|
||||
|
||||
MarkupLine::MarkupLine( Distance x1,
|
||||
Distance y1,
|
||||
Distance x2,
|
||||
Distance y2 )
|
||||
: mX1(x1),
|
||||
mY1(y1),
|
||||
mX2(x2),
|
||||
mY2(y2)
|
||||
{
|
||||
mPath.moveTo( x1.pt(), y1.pt() );
|
||||
mPath.lineTo( x2.pt(), y2.pt() );
|
||||
}
|
||||
std::unique_ptr<Markup> MarkupMargin::clone() const
|
||||
{
|
||||
return std::make_unique<MarkupMargin>( mXSize, mYSize );
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Markup> MarkupLine::clone() const
|
||||
{
|
||||
return std::make_unique<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;
|
||||
}
|
||||
Distance MarkupMargin::xSize() const
|
||||
{
|
||||
return mXSize;
|
||||
}
|
||||
|
||||
|
||||
void MarkupLine::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "MarkupLine{ "
|
||||
<< mX1 << "," << mY1 << ","
|
||||
<< mX2 << "," << mY2
|
||||
<< " }";
|
||||
}
|
||||
Distance MarkupMargin::ySize() const
|
||||
{
|
||||
return mYSize;
|
||||
}
|
||||
|
||||
|
||||
MarkupRect::MarkupRect( Distance x1,
|
||||
Distance y1,
|
||||
Distance w,
|
||||
Distance h,
|
||||
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() );
|
||||
}
|
||||
void MarkupMargin::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "MarkupMargin{ "
|
||||
<< mXSize << "," << mYSize
|
||||
<< " }";
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Markup> MarkupRect::clone() const
|
||||
{
|
||||
return std::make_unique<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;
|
||||
}
|
||||
|
||||
|
||||
void MarkupRect::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "MarkupRect{ "
|
||||
<< mX1 << "," << mY1 << ","
|
||||
<< mW << "," << mH << ","
|
||||
<< mR
|
||||
<< " }";
|
||||
}
|
||||
MarkupLine::MarkupLine( Distance x1,
|
||||
Distance y1,
|
||||
Distance x2,
|
||||
Distance y2 )
|
||||
: mX1(x1),
|
||||
mY1(y1),
|
||||
mX2(x2),
|
||||
mY2(y2)
|
||||
{
|
||||
mPath.moveTo( x1.pt(), y1.pt() );
|
||||
mPath.lineTo( x2.pt(), y2.pt() );
|
||||
}
|
||||
|
||||
|
||||
MarkupEllipse::MarkupEllipse( Distance x1,
|
||||
Distance y1,
|
||||
Distance w,
|
||||
Distance h )
|
||||
: mX1(x1),
|
||||
mY1(y1),
|
||||
mW(w),
|
||||
mH(h)
|
||||
{
|
||||
mPath.addEllipse( x1.pt(), y1.pt(), w.pt(), h.pt() );
|
||||
}
|
||||
std::unique_ptr<Markup> MarkupLine::clone() const
|
||||
{
|
||||
return std::make_unique<MarkupLine>( mX1, mY1, mX2, mY2 );
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Markup> MarkupEllipse::clone() const
|
||||
{
|
||||
return std::make_unique<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;
|
||||
}
|
||||
Distance MarkupLine::x1() const
|
||||
{
|
||||
return mX1;
|
||||
}
|
||||
|
||||
|
||||
void MarkupEllipse::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "MarkupEllipse{ "
|
||||
<< mX1 << "," << mY1 << ","
|
||||
<< mW << "," << mH
|
||||
<< " }";
|
||||
}
|
||||
Distance MarkupLine::y1() const
|
||||
{
|
||||
return mY1;
|
||||
}
|
||||
|
||||
|
||||
MarkupCircle::MarkupCircle( Distance x0,
|
||||
Distance y0,
|
||||
Distance r )
|
||||
: mX0(x0),
|
||||
mY0(y0),
|
||||
mR(r)
|
||||
{
|
||||
mPath.addEllipse( (x0-r).pt(), (y0-r).pt(), 2*r.pt(), 2*r.pt() );
|
||||
}
|
||||
|
||||
std::unique_ptr<Markup> MarkupCircle::clone() const
|
||||
{
|
||||
return std::make_unique<MarkupCircle>( mX0, mY0, mR );
|
||||
}
|
||||
Distance MarkupLine::x2() const
|
||||
{
|
||||
return mX2;
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupCircle::x0() const
|
||||
{
|
||||
return mX0;
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupCircle::y0() const
|
||||
{
|
||||
return mY0;
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupCircle::r() const
|
||||
{
|
||||
return mR;
|
||||
}
|
||||
Distance MarkupLine::y2() const
|
||||
{
|
||||
return mY2;
|
||||
}
|
||||
|
||||
|
||||
void MarkupCircle::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "MarkupCircle{ "
|
||||
<< mX0 << "," << mY0 << ","
|
||||
<< mR
|
||||
<< " }";
|
||||
}
|
||||
void MarkupLine::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "MarkupLine{ "
|
||||
<< mX1 << "," << mY1 << ","
|
||||
<< mX2 << "," << mY2
|
||||
<< " }";
|
||||
}
|
||||
|
||||
|
||||
MarkupRect::MarkupRect( Distance x1,
|
||||
Distance y1,
|
||||
Distance w,
|
||||
Distance h,
|
||||
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() );
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Markup> MarkupRect::clone() const
|
||||
{
|
||||
return std::make_unique<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;
|
||||
}
|
||||
|
||||
|
||||
void MarkupRect::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "MarkupRect{ "
|
||||
<< mX1 << "," << mY1 << ","
|
||||
<< mW << "," << mH << ","
|
||||
<< mR
|
||||
<< " }";
|
||||
}
|
||||
|
||||
|
||||
MarkupEllipse::MarkupEllipse( Distance x1,
|
||||
Distance y1,
|
||||
Distance w,
|
||||
Distance h )
|
||||
: mX1(x1),
|
||||
mY1(y1),
|
||||
mW(w),
|
||||
mH(h)
|
||||
{
|
||||
mPath.addEllipse( x1.pt(), y1.pt(), w.pt(), h.pt() );
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Markup> MarkupEllipse::clone() const
|
||||
{
|
||||
return std::make_unique<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;
|
||||
}
|
||||
|
||||
|
||||
void MarkupEllipse::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "MarkupEllipse{ "
|
||||
<< mX1 << "," << mY1 << ","
|
||||
<< mW << "," << mH
|
||||
<< " }";
|
||||
}
|
||||
|
||||
|
||||
MarkupCircle::MarkupCircle( Distance x0,
|
||||
Distance y0,
|
||||
Distance r )
|
||||
: mX0(x0),
|
||||
mY0(y0),
|
||||
mR(r)
|
||||
{
|
||||
mPath.addEllipse( (x0-r).pt(), (y0-r).pt(), 2*r.pt(), 2*r.pt() );
|
||||
}
|
||||
|
||||
std::unique_ptr<Markup> MarkupCircle::clone() const
|
||||
{
|
||||
return std::make_unique<MarkupCircle>( mX0, mY0, mR );
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupCircle::x0() const
|
||||
{
|
||||
return mX0;
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupCircle::y0() const
|
||||
{
|
||||
return mY0;
|
||||
}
|
||||
|
||||
|
||||
Distance MarkupCircle::r() const
|
||||
{
|
||||
return mR;
|
||||
}
|
||||
|
||||
|
||||
void MarkupCircle::print( QDebug& dbg ) const
|
||||
{
|
||||
dbg.nospace() << "MarkupCircle{ "
|
||||
<< mX0 << "," << mY0 << ","
|
||||
<< mR
|
||||
<< " }";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QDebug operator<<( QDebug dbg, const glabels::model::Markup& markup )
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
QDebugStateSaver saver(dbg);
|
||||
|
||||
markup.print( dbg );
|
||||
markup.print( dbg );
|
||||
|
||||
return dbg;
|
||||
return dbg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
-192
@@ -1,192 +0,0 @@
|
||||
/* Markup.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_Markup_h
|
||||
#define model_Markup_h
|
||||
|
||||
|
||||
#include "Distance.h"
|
||||
|
||||
#include <QPainterPath>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
class Frame; // Forward reference
|
||||
|
||||
|
||||
class Markup
|
||||
{
|
||||
public:
|
||||
virtual ~Markup() = default;
|
||||
|
||||
virtual std::unique_ptr<Markup> clone() const = 0;
|
||||
|
||||
virtual QPainterPath path( const Frame& frame ) const;
|
||||
|
||||
// Debugging support
|
||||
virtual void print( QDebug& dbg ) const = 0;
|
||||
|
||||
protected:
|
||||
QPainterPath mPath;
|
||||
};
|
||||
|
||||
|
||||
class MarkupMargin : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupMargin( Distance size );
|
||||
|
||||
MarkupMargin( Distance xSize,
|
||||
Distance ySize );
|
||||
|
||||
QPainterPath path( const Frame& frame ) const override;
|
||||
|
||||
Distance xSize() const;
|
||||
Distance ySize() const;
|
||||
|
||||
std::unique_ptr<Markup> clone() const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
private:
|
||||
Distance mXSize;
|
||||
Distance mYSize;
|
||||
};
|
||||
|
||||
|
||||
class MarkupLine : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupLine( Distance x1,
|
||||
Distance y1,
|
||||
Distance x2,
|
||||
Distance y2 );
|
||||
|
||||
Distance x1() const;
|
||||
Distance y1() const;
|
||||
Distance x2() const;
|
||||
Distance y2() const;
|
||||
|
||||
std::unique_ptr<Markup> clone() const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
private:
|
||||
Distance mX1;
|
||||
Distance mY1;
|
||||
Distance mX2;
|
||||
Distance mY2;
|
||||
};
|
||||
|
||||
|
||||
class MarkupRect : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupRect( Distance x1,
|
||||
Distance y1,
|
||||
Distance w,
|
||||
Distance h,
|
||||
Distance r );
|
||||
|
||||
Distance x1() const;
|
||||
Distance y1() const;
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
Distance r() const;
|
||||
|
||||
std::unique_ptr<Markup> clone() const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
private:
|
||||
Distance mX1;
|
||||
Distance mY1;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mR;
|
||||
};
|
||||
|
||||
|
||||
class MarkupEllipse : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupEllipse( Distance x1,
|
||||
Distance y1,
|
||||
Distance w,
|
||||
Distance h );
|
||||
|
||||
Distance x1() const;
|
||||
Distance y1() const;
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
|
||||
std::unique_ptr<Markup> clone() const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
private:
|
||||
Distance mX1;
|
||||
Distance mY1;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
};
|
||||
|
||||
|
||||
class MarkupCircle : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupCircle( Distance x0,
|
||||
Distance y0,
|
||||
Distance r );
|
||||
|
||||
Distance x0() const;
|
||||
Distance y0() const;
|
||||
Distance r() const;
|
||||
|
||||
std::unique_ptr<Markup> clone() const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
private:
|
||||
Distance mX0;
|
||||
Distance mY0;
|
||||
Distance mR;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
QDebug operator<<( QDebug dbg, const glabels::model::Markup& markup );
|
||||
|
||||
|
||||
#endif // model_Markup_h
|
||||
@@ -0,0 +1,190 @@
|
||||
// Markup.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_Markup_hpp
|
||||
#define model_Markup_hpp
|
||||
|
||||
|
||||
#include "Distance.hpp"
|
||||
|
||||
#include <QPainterPath>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
class Frame; // Forward reference
|
||||
|
||||
|
||||
class Markup
|
||||
{
|
||||
public:
|
||||
virtual ~Markup() = default;
|
||||
|
||||
virtual std::unique_ptr<Markup> clone() const = 0;
|
||||
|
||||
virtual QPainterPath path( const Frame& frame ) const;
|
||||
|
||||
// Debugging support
|
||||
virtual void print( QDebug& dbg ) const = 0;
|
||||
|
||||
protected:
|
||||
QPainterPath mPath;
|
||||
};
|
||||
|
||||
|
||||
class MarkupMargin : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupMargin( Distance size );
|
||||
|
||||
MarkupMargin( Distance xSize,
|
||||
Distance ySize );
|
||||
|
||||
QPainterPath path( const Frame& frame ) const override;
|
||||
|
||||
Distance xSize() const;
|
||||
Distance ySize() const;
|
||||
|
||||
std::unique_ptr<Markup> clone() const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
private:
|
||||
Distance mXSize;
|
||||
Distance mYSize;
|
||||
};
|
||||
|
||||
|
||||
class MarkupLine : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupLine( Distance x1,
|
||||
Distance y1,
|
||||
Distance x2,
|
||||
Distance y2 );
|
||||
|
||||
Distance x1() const;
|
||||
Distance y1() const;
|
||||
Distance x2() const;
|
||||
Distance y2() const;
|
||||
|
||||
std::unique_ptr<Markup> clone() const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
private:
|
||||
Distance mX1;
|
||||
Distance mY1;
|
||||
Distance mX2;
|
||||
Distance mY2;
|
||||
};
|
||||
|
||||
|
||||
class MarkupRect : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupRect( Distance x1,
|
||||
Distance y1,
|
||||
Distance w,
|
||||
Distance h,
|
||||
Distance r );
|
||||
|
||||
Distance x1() const;
|
||||
Distance y1() const;
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
Distance r() const;
|
||||
|
||||
std::unique_ptr<Markup> clone() const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
private:
|
||||
Distance mX1;
|
||||
Distance mY1;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mR;
|
||||
};
|
||||
|
||||
|
||||
class MarkupEllipse : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupEllipse( Distance x1,
|
||||
Distance y1,
|
||||
Distance w,
|
||||
Distance h );
|
||||
|
||||
Distance x1() const;
|
||||
Distance y1() const;
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
|
||||
std::unique_ptr<Markup> clone() const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
private:
|
||||
Distance mX1;
|
||||
Distance mY1;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
};
|
||||
|
||||
|
||||
class MarkupCircle : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupCircle( Distance x0,
|
||||
Distance y0,
|
||||
Distance r );
|
||||
|
||||
Distance x0() const;
|
||||
Distance y0() const;
|
||||
Distance r() const;
|
||||
|
||||
std::unique_ptr<Markup> clone() const override;
|
||||
|
||||
// Debugging support
|
||||
void print( QDebug& dbg ) const override;
|
||||
|
||||
private:
|
||||
Distance mX0;
|
||||
Distance mY0;
|
||||
Distance mR;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Debugging support
|
||||
QDebug operator<<( QDebug dbg, const glabels::model::Markup& markup );
|
||||
|
||||
|
||||
#endif // model_Markup_hpp
|
||||
+1605
-1608
File diff suppressed because it is too large
Load Diff
-260
@@ -1,260 +0,0 @@
|
||||
/* Model.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_Model_h
|
||||
#define model_Model_h
|
||||
|
||||
|
||||
#include "Settings.h"
|
||||
#include "Template.h"
|
||||
#include "Variables.h"
|
||||
|
||||
#include "merge/Merge.h"
|
||||
#include "merge/Record.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QList>
|
||||
#include <QMimeData>
|
||||
#include <QObject>
|
||||
#include <QPainter>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
// Forward References
|
||||
class ColorNode;
|
||||
class Handle;
|
||||
class ModelObject;
|
||||
class Region;
|
||||
|
||||
///
|
||||
/// Model
|
||||
///
|
||||
class Model : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Lifecycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
Model();
|
||||
Model( merge::Merge* merge );
|
||||
~Model();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Save/restore model state
|
||||
/////////////////////////////////
|
||||
Model* save() const;
|
||||
void restore( const Model *savedModel );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Signals
|
||||
/////////////////////////////////
|
||||
signals:
|
||||
void changed();
|
||||
void nameChanged();
|
||||
void sizeChanged();
|
||||
void selectionChanged();
|
||||
void modifiedChanged();
|
||||
void variablesChanged();
|
||||
void mergeChanged();
|
||||
void mergeSourceChanged();
|
||||
void mergeSelectionChanged();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
bool isModified() const;
|
||||
void setModified();
|
||||
void clearModified();
|
||||
|
||||
QDir dir() const;
|
||||
QString dirPath() const;
|
||||
QString shortName();
|
||||
const QString& fileName() const;
|
||||
void setFileName( const QString &fileName );
|
||||
|
||||
const Template& tmplate() const;
|
||||
const Frame* frame( const QString& id = "0" ) const;
|
||||
void setTmplate( const Template& tmplate );
|
||||
|
||||
bool rotate() const;
|
||||
void setRotate( bool rotate );
|
||||
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
|
||||
void setH( Distance h );
|
||||
|
||||
const QList<ModelObject*>& objectList() const;
|
||||
|
||||
Variables& variables();
|
||||
const Variables& constVariables() const;
|
||||
|
||||
merge::Merge* merge() const;
|
||||
void setMerge( merge::Merge* merge );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Manage objects
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void addObject( ModelObject* object );
|
||||
void deleteObject( ModelObject* object );
|
||||
|
||||
ModelObject* objectAt( double scale,
|
||||
Distance x,
|
||||
Distance y ) const;
|
||||
|
||||
const Handle& handleAt( double scale,
|
||||
Distance x,
|
||||
Distance y ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Manipulate selection
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void selectObject( ModelObject* object );
|
||||
void unselectObject( ModelObject* object );
|
||||
void selectAll();
|
||||
void unselectAll();
|
||||
void selectRegion( const Region& region );
|
||||
bool isSelectionEmpty();
|
||||
bool isSelectionAtomic();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Get selected objects
|
||||
/////////////////////////////////
|
||||
public:
|
||||
QList<ModelObject*> getSelection();
|
||||
ModelObject* getFirstSelectedObject();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Query selection capabilities
|
||||
/////////////////////////////////
|
||||
public:
|
||||
bool canSelectionText();
|
||||
bool canSelectionFill();
|
||||
bool canSelectionLineColor();
|
||||
bool canSelectionLineWidth();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Operations on selections
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void deleteSelection();
|
||||
void raiseSelectionToTop();
|
||||
void lowerSelectionToBottom();
|
||||
void rotateSelection( double thetaDegs );
|
||||
void rotateSelectionLeft();
|
||||
void rotateSelectionRight();
|
||||
void flipSelectionHoriz();
|
||||
void flipSelectionVert();
|
||||
void alignSelectionLeft();
|
||||
void alignSelectionRight();
|
||||
void alignSelectionHCenter();
|
||||
void alignSelectionTop();
|
||||
void alignSelectionBottom();
|
||||
void alignSelectionVCenter();
|
||||
void centerSelection();
|
||||
void centerSelectionHoriz();
|
||||
void centerSelectionVert();
|
||||
void moveSelection( Distance dx, Distance dy );
|
||||
void setSelectionFontFamily( const QString& fontFamily );
|
||||
void setSelectionFontSize( double fontSize );
|
||||
void setSelectionFontWeight( QFont::Weight fontWeight );
|
||||
void setSelectionFontItalicFlag( bool fontItalicFlag );
|
||||
void setSelectionTextHAlign( Qt::Alignment textHAlign );
|
||||
void setSelectionTextVAlign( Qt::Alignment textVAlign );
|
||||
void setSelectionTextLineSpacing( double textLineSpacing );
|
||||
void setSelectionTextColorNode( ColorNode textColorNode );
|
||||
void setSelectionLineWidth( Distance lineWidth );
|
||||
void setSelectionLineColorNode( ColorNode lineColorNode );
|
||||
void setSelectionFillColorNode( ColorNode fillColorNode );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Clipboard operations
|
||||
/////////////////////////////////
|
||||
void copySelection();
|
||||
void cutSelection();
|
||||
bool canPaste();
|
||||
void paste( Point p );
|
||||
void pasteAsNativeObjects( const QMimeData* mimeData, Point p );
|
||||
void pasteAsUrls( const QMimeData* mimeData, Point p );
|
||||
void pasteAsImage( const QMimeData* mimeData, Point p );
|
||||
void pasteAsText( const QMimeData* mimeData, Point p );
|
||||
|
||||
/////////////////////////////////
|
||||
// Drawing operations
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variablesInstance ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Slots
|
||||
/////////////////////////////////
|
||||
private slots:
|
||||
void onObjectChanged();
|
||||
void onObjectMoved();
|
||||
void onVariablesChanged();
|
||||
void onMergeSourceChanged();
|
||||
void onMergeSelectionChanged();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
int mUntitledInstance{0};
|
||||
bool mModified{true};
|
||||
QString mFileName;
|
||||
Template mTmplate;
|
||||
bool mRotate{false};
|
||||
|
||||
QList<ModelObject*> mObjectList;
|
||||
|
||||
Variables mVariables;
|
||||
|
||||
QSharedPointer<merge::Merge> mMerge;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_Model_h
|
||||
+257
@@ -0,0 +1,257 @@
|
||||
// Model.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_Model_hpp
|
||||
#define model_Model_hpp
|
||||
|
||||
|
||||
#include "Settings.hpp"
|
||||
#include "Template.hpp"
|
||||
#include "Variables.hpp"
|
||||
|
||||
#include "merge/Merge.hpp"
|
||||
#include "merge/Record.hpp"
|
||||
|
||||
#include <QDir>
|
||||
#include <QList>
|
||||
#include <QMimeData>
|
||||
#include <QObject>
|
||||
#include <QPainter>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
// Forward References
|
||||
class ColorNode;
|
||||
class Handle;
|
||||
class ModelObject;
|
||||
class Region;
|
||||
|
||||
///
|
||||
/// Model
|
||||
///
|
||||
class Model : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Lifecycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
Model();
|
||||
Model( merge::Merge* merge );
|
||||
~Model();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Save/restore model state
|
||||
/////////////////////////////////
|
||||
Model* save() const;
|
||||
void restore( const Model *savedModel );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Signals
|
||||
/////////////////////////////////
|
||||
signals:
|
||||
void changed();
|
||||
void nameChanged();
|
||||
void sizeChanged();
|
||||
void selectionChanged();
|
||||
void modifiedChanged();
|
||||
void variablesChanged();
|
||||
void mergeChanged();
|
||||
void mergeSourceChanged();
|
||||
void mergeSelectionChanged();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
bool isModified() const;
|
||||
void setModified();
|
||||
void clearModified();
|
||||
|
||||
QDir dir() const;
|
||||
QString dirPath() const;
|
||||
QString shortName();
|
||||
const QString& fileName() const;
|
||||
void setFileName( const QString &fileName );
|
||||
|
||||
const Template& tmplate() const;
|
||||
const Frame* frame( const QString& id = "0" ) const;
|
||||
void setTmplate( const Template& tmplate );
|
||||
|
||||
bool rotate() const;
|
||||
void setRotate( bool rotate );
|
||||
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
|
||||
void setH( Distance h );
|
||||
|
||||
const QList<ModelObject*>& objectList() const;
|
||||
|
||||
Variables& variables();
|
||||
const Variables& constVariables() const;
|
||||
|
||||
merge::Merge* merge() const;
|
||||
void setMerge( merge::Merge* merge );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Manage objects
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void addObject( ModelObject* object );
|
||||
void deleteObject( ModelObject* object );
|
||||
|
||||
ModelObject* objectAt( double scale,
|
||||
Distance x,
|
||||
Distance y ) const;
|
||||
|
||||
const Handle& handleAt( double scale,
|
||||
Distance x,
|
||||
Distance y ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Manipulate selection
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void selectObject( ModelObject* object );
|
||||
void unselectObject( ModelObject* object );
|
||||
void selectAll();
|
||||
void unselectAll();
|
||||
void selectRegion( const Region& region );
|
||||
bool isSelectionEmpty();
|
||||
bool isSelectionAtomic();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Get selected objects
|
||||
/////////////////////////////////
|
||||
public:
|
||||
QList<ModelObject*> getSelection();
|
||||
ModelObject* getFirstSelectedObject();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Query selection capabilities
|
||||
/////////////////////////////////
|
||||
public:
|
||||
bool canSelectionText();
|
||||
bool canSelectionFill();
|
||||
bool canSelectionLineColor();
|
||||
bool canSelectionLineWidth();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Operations on selections
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void deleteSelection();
|
||||
void raiseSelectionToTop();
|
||||
void lowerSelectionToBottom();
|
||||
void rotateSelection( double thetaDegs );
|
||||
void rotateSelectionLeft();
|
||||
void rotateSelectionRight();
|
||||
void flipSelectionHoriz();
|
||||
void flipSelectionVert();
|
||||
void alignSelectionLeft();
|
||||
void alignSelectionRight();
|
||||
void alignSelectionHCenter();
|
||||
void alignSelectionTop();
|
||||
void alignSelectionBottom();
|
||||
void alignSelectionVCenter();
|
||||
void centerSelection();
|
||||
void centerSelectionHoriz();
|
||||
void centerSelectionVert();
|
||||
void moveSelection( Distance dx, Distance dy );
|
||||
void setSelectionFontFamily( const QString& fontFamily );
|
||||
void setSelectionFontSize( double fontSize );
|
||||
void setSelectionFontWeight( QFont::Weight fontWeight );
|
||||
void setSelectionFontItalicFlag( bool fontItalicFlag );
|
||||
void setSelectionTextHAlign( Qt::Alignment textHAlign );
|
||||
void setSelectionTextVAlign( Qt::Alignment textVAlign );
|
||||
void setSelectionTextLineSpacing( double textLineSpacing );
|
||||
void setSelectionTextColorNode( ColorNode textColorNode );
|
||||
void setSelectionLineWidth( Distance lineWidth );
|
||||
void setSelectionLineColorNode( ColorNode lineColorNode );
|
||||
void setSelectionFillColorNode( ColorNode fillColorNode );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Clipboard operations
|
||||
/////////////////////////////////
|
||||
void copySelection();
|
||||
void cutSelection();
|
||||
bool canPaste();
|
||||
void paste( Point p );
|
||||
void pasteAsNativeObjects( const QMimeData* mimeData, Point p );
|
||||
void pasteAsUrls( const QMimeData* mimeData, Point p );
|
||||
void pasteAsImage( const QMimeData* mimeData, Point p );
|
||||
void pasteAsText( const QMimeData* mimeData, Point p );
|
||||
|
||||
/////////////////////////////////
|
||||
// Drawing operations
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variablesInstance ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Slots
|
||||
/////////////////////////////////
|
||||
private slots:
|
||||
void onObjectChanged();
|
||||
void onObjectMoved();
|
||||
void onVariablesChanged();
|
||||
void onMergeSourceChanged();
|
||||
void onMergeSelectionChanged();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
int mUntitledInstance{0};
|
||||
bool mModified{true};
|
||||
QString mFileName;
|
||||
Template mTmplate;
|
||||
bool mRotate{false};
|
||||
|
||||
QList<ModelObject*> mObjectList;
|
||||
|
||||
Variables mVariables;
|
||||
|
||||
QSharedPointer<merge::Merge> mMerge;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_Model_hpp
|
||||
+491
-493
@@ -1,507 +1,505 @@
|
||||
/* ModelBarcodeObject.cpp
|
||||
*
|
||||
* Copyright (C) 2017 Jaye 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/>.
|
||||
*/
|
||||
// ModelBarcodeObject.cpp
|
||||
//
|
||||
// Copyright (C) 2017 Jaye 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 "ModelBarcodeObject.h"
|
||||
#include "ModelBarcodeObject.hpp"
|
||||
|
||||
#include "Size.h"
|
||||
#include "Size.hpp"
|
||||
|
||||
#include "barcode/Backends.h"
|
||||
#include "barcode/Backends.hpp"
|
||||
|
||||
#include "glbarcode/Factory.h"
|
||||
#include "glbarcode/QtRenderer.h"
|
||||
#include "glbarcode/Factory.hpp"
|
||||
#include "glbarcode/QtRenderer.hpp"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QDebug>
|
||||
#include <QPen>
|
||||
#include <QTextDocument>
|
||||
#include <QTextBlock>
|
||||
#include <QRegularExpression>
|
||||
#include <QtDebug>
|
||||
#include <QTextBlock>
|
||||
#include <QTextDocument>
|
||||
|
||||
|
||||
namespace glabels
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
using namespace glabels::model;
|
||||
|
||||
const QColor fillColor = QColor( 224, 224, 224, 255 );
|
||||
const Distance pad = Distance::pt(4);
|
||||
const Distance minW = Distance::pt(18);
|
||||
const Distance minH = Distance::pt(18);
|
||||
const double MIN_POINT_SIZE = 0.4; // Less than ~0.37 causes issues for QFontMetricsF
|
||||
}
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelBarcodeObject::ModelBarcodeObject()
|
||||
{
|
||||
mOutline.setOwner( this );
|
||||
|
||||
mHandles.push_back( Handle( this, Handle::NW ) );
|
||||
mHandles.push_back( Handle( this, Handle::N ) );
|
||||
mHandles.push_back( Handle( this, Handle::NE ) );
|
||||
mHandles.push_back( Handle( this, Handle::E ) );
|
||||
mHandles.push_back( Handle( this, Handle::SE ) );
|
||||
mHandles.push_back( Handle( this, Handle::S ) );
|
||||
mHandles.push_back( Handle( this, Handle::SW ) );
|
||||
mHandles.push_back( Handle( this, Handle::W ) );
|
||||
|
||||
mBcStyle = barcode::Backends::defaultStyle();
|
||||
mBcTextFlag = mBcStyle.canText();
|
||||
mBcChecksumFlag = mBcStyle.canChecksum();
|
||||
mBcFormatDigits = mBcStyle.preferedN();
|
||||
mBcData = "";
|
||||
mBcColorNode = ColorNode( Qt::black );
|
||||
|
||||
update(); // Initialize cached editor layouts
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelBarcodeObject::ModelBarcodeObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
const barcode::Style& bcStyle,
|
||||
bool bcTextFlag,
|
||||
bool bcChecksumFlag,
|
||||
QString bcData,
|
||||
const ColorNode& bcColorNode,
|
||||
const QTransform& matrix )
|
||||
: ModelObject( x0, y0, w, h, lockAspectRatio, matrix )
|
||||
{
|
||||
mOutline.setOwner( this );
|
||||
|
||||
mHandles.push_back( Handle( this, Handle::NW ) );
|
||||
mHandles.push_back( Handle( this, Handle::N ) );
|
||||
mHandles.push_back( Handle( this, Handle::NE ) );
|
||||
mHandles.push_back( Handle( this, Handle::E ) );
|
||||
mHandles.push_back( Handle( this, Handle::SE ) );
|
||||
mHandles.push_back( Handle( this, Handle::S ) );
|
||||
mHandles.push_back( Handle( this, Handle::SW ) );
|
||||
mHandles.push_back( Handle( this, Handle::W ) );
|
||||
|
||||
mBcStyle = bcStyle;
|
||||
mBcTextFlag = bcTextFlag;
|
||||
mBcChecksumFlag = bcChecksumFlag;
|
||||
mBcFormatDigits = mBcStyle.preferedN();
|
||||
mBcData = bcData;
|
||||
mBcColorNode = bcColorNode;
|
||||
|
||||
update(); // Initialize cached editor layouts
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Copy constructor
|
||||
///
|
||||
ModelBarcodeObject::ModelBarcodeObject( const ModelBarcodeObject* object )
|
||||
: ModelObject(object)
|
||||
{
|
||||
mBcStyle = object->mBcStyle;
|
||||
mBcTextFlag = object->mBcTextFlag;
|
||||
mBcChecksumFlag = object->mBcChecksumFlag;
|
||||
mBcFormatDigits = object->mBcFormatDigits;
|
||||
mBcData = object->mBcData;
|
||||
mBcColorNode = object->mBcColorNode;
|
||||
|
||||
update(); // Initialize cached editor layouts
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
ModelBarcodeObject* ModelBarcodeObject::clone() const
|
||||
{
|
||||
return new ModelBarcodeObject( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcData Property Getter
|
||||
///
|
||||
QString ModelBarcodeObject::bcData() const
|
||||
{
|
||||
return mBcData.toString();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcData Property Setter
|
||||
///
|
||||
void ModelBarcodeObject::setBcData( const QString& value )
|
||||
{
|
||||
if ( mBcData.toString() != value )
|
||||
{
|
||||
mBcData = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcTextFlag Property Getter
|
||||
///
|
||||
bool ModelBarcodeObject::bcTextFlag() const
|
||||
{
|
||||
return mBcTextFlag;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcTextFlag Property Setter
|
||||
///
|
||||
void ModelBarcodeObject::setBcTextFlag( bool value )
|
||||
{
|
||||
if ( mBcTextFlag != value )
|
||||
{
|
||||
mBcTextFlag = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcChecksumFlag Property Getter
|
||||
///
|
||||
bool ModelBarcodeObject::bcChecksumFlag() const
|
||||
{
|
||||
return mBcChecksumFlag;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcChecksumFlag Property Setter
|
||||
///
|
||||
void ModelBarcodeObject::setBcChecksumFlag( bool value )
|
||||
{
|
||||
if ( mBcChecksumFlag != value )
|
||||
{
|
||||
mBcChecksumFlag = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Barcode Color Node Property Getter
|
||||
///
|
||||
ColorNode ModelBarcodeObject::bcColorNode() const
|
||||
{
|
||||
return mBcColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Barcode Color Node Property Setter
|
||||
///
|
||||
void ModelBarcodeObject::setBcColorNode( const ColorNode& value )
|
||||
{
|
||||
if ( mBcColorNode != value )
|
||||
{
|
||||
mBcColorNode = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Barcode Style Property Getter
|
||||
///
|
||||
barcode::Style ModelBarcodeObject::bcStyle() const
|
||||
{
|
||||
return mBcStyle;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Barcode Style Property Setter
|
||||
///
|
||||
void ModelBarcodeObject::setBcStyle( const barcode::Style& value )
|
||||
{
|
||||
if ( mBcStyle != value )
|
||||
{
|
||||
mBcStyle = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Barcode Format Digits Property Getter
|
||||
///
|
||||
int ModelBarcodeObject::bcFormatDigits() const
|
||||
{
|
||||
return mBcFormatDigits;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Barcode Format Digits Property Setter
|
||||
///
|
||||
void ModelBarcodeObject::setBcFormatDigits( int value )
|
||||
{
|
||||
if ( mBcFormatDigits != value )
|
||||
{
|
||||
mBcFormatDigits = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw shadow of object
|
||||
///
|
||||
void ModelBarcodeObject::drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
// Barcodes don't support shadows.
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw object itself
|
||||
///
|
||||
void ModelBarcodeObject::drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
QColor bcColor = mBcColorNode.color( record, variables );
|
||||
|
||||
if ( inEditor )
|
||||
{
|
||||
drawBcInEditor( painter, bcColor );
|
||||
}
|
||||
else
|
||||
{
|
||||
drawBc( painter, bcColor, record, variables );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Path to test for hover condition
|
||||
///
|
||||
QPainterPath ModelBarcodeObject::hoverPath( double scale ) const
|
||||
{
|
||||
return mHoverPath;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Size updated
|
||||
///
|
||||
void ModelBarcodeObject::sizeUpdated()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Update cached information for editor view
|
||||
///
|
||||
void ModelBarcodeObject::update()
|
||||
{
|
||||
//
|
||||
// Build barcode from data
|
||||
//
|
||||
mEditorBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() ) );
|
||||
if ( !mEditorBarcode )
|
||||
{
|
||||
qWarning() << "Invalid barcode style" << mBcStyle.fullId() << "using \"code39\".";
|
||||
mBcStyle = barcode::Backends::defaultStyle();
|
||||
mEditorBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() ) );
|
||||
}
|
||||
mEditorBarcode->setChecksum(mBcChecksumFlag);
|
||||
mEditorBarcode->setShowText(mBcTextFlag);
|
||||
|
||||
mEditorBarcode->build( mBcData.toStdString(), mW.pt(), mH.pt() );
|
||||
|
||||
//
|
||||
// Build a place holder barcode to display in editor, if cannot display actual barcode
|
||||
//
|
||||
mEditorDefaultBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() ) );
|
||||
if ( !mEditorDefaultBarcode )
|
||||
{
|
||||
qWarning() << "Invalid barcode style" << mBcStyle.fullId() << "using \"code39\".";
|
||||
mBcStyle = barcode::Backends::defaultStyle();
|
||||
mEditorDefaultBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() ) );
|
||||
}
|
||||
mEditorDefaultBarcode->setChecksum(mBcChecksumFlag);
|
||||
mEditorDefaultBarcode->setShowText(mBcTextFlag);
|
||||
|
||||
mEditorDefaultBarcode->build( mBcStyle.defaultDigits().toStdString(), mW.pt(), mH.pt() );
|
||||
|
||||
//
|
||||
// Adjust size
|
||||
//
|
||||
if ( mEditorBarcode->isDataValid() )
|
||||
{
|
||||
mW = Distance::pt( mEditorBarcode->width() );
|
||||
mH = Distance::pt( mEditorBarcode->height() );
|
||||
}
|
||||
else
|
||||
{
|
||||
mW = Distance::pt( mEditorDefaultBarcode->width() );
|
||||
mH = Distance::pt( mEditorDefaultBarcode->height() );
|
||||
}
|
||||
|
||||
QPainterPath path;
|
||||
path.addRect( 0, 0, mW.pt(), mH.pt() );
|
||||
mHoverPath = path;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw barcode in editor from cached information
|
||||
///
|
||||
void ModelBarcodeObject::drawBcInEditor( QPainter* painter, const QColor& color ) const
|
||||
{
|
||||
if ( mBcData.isEmpty() )
|
||||
{
|
||||
drawPlaceHolder( painter, color, tr("No barcode data") );
|
||||
}
|
||||
else if ( mBcData.hasPlaceHolders() )
|
||||
{
|
||||
drawPlaceHolder( painter, color, mBcData.toString() );
|
||||
}
|
||||
else if ( mEditorBarcode->isDataValid() )
|
||||
{
|
||||
painter->setPen( QPen( color ) );
|
||||
glbarcode::QtRenderer renderer(painter);
|
||||
mEditorBarcode->render( renderer );
|
||||
}
|
||||
else
|
||||
{
|
||||
drawPlaceHolder( painter, color, tr("Invalid barcode data") );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw barcode in final printout or preview
|
||||
///
|
||||
void
|
||||
ModelBarcodeObject::drawBc( QPainter* painter,
|
||||
const QColor& color,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
painter->setPen( QPen( color ) );
|
||||
|
||||
glbarcode::Barcode* bc = glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() );
|
||||
bc->setChecksum(mBcChecksumFlag);
|
||||
bc->setShowText(mBcTextFlag);
|
||||
|
||||
bc->build( mBcData.expand( record, variables ).toStdString(), mW.pt(), mH.pt() );
|
||||
|
||||
glbarcode::QtRenderer renderer(painter);
|
||||
bc->render( renderer );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw barcode place holder in editor
|
||||
///
|
||||
void
|
||||
ModelBarcodeObject::drawPlaceHolder( QPainter* painter,
|
||||
const QColor& color,
|
||||
const QString& text ) const
|
||||
{
|
||||
QString shortText = text.left( 32 ); // Don't let the text get out of hand
|
||||
|
||||
//
|
||||
// Render box
|
||||
//
|
||||
painter->setPen( Qt::NoPen );
|
||||
painter->setBrush( QBrush( fillColor ) );
|
||||
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
|
||||
//
|
||||
// Render default barcode
|
||||
//
|
||||
painter->setPen( QPen( color ) );
|
||||
glbarcode::QtRenderer renderer(painter);
|
||||
mEditorDefaultBarcode->render( renderer );
|
||||
|
||||
//
|
||||
// Determine font size for text
|
||||
//
|
||||
QFont font( "Sans" );
|
||||
font.setPointSizeF( 6 );
|
||||
|
||||
QFontMetricsF fm( font );
|
||||
QRectF textRect = fm.boundingRect( shortText );
|
||||
|
||||
double wPts = (mW - 2*pad).pt();
|
||||
double hPts = (mH - 2*pad).pt();
|
||||
if ( (wPts < textRect.width()) || (hPts < textRect.height()) )
|
||||
{
|
||||
double scaleX = wPts / textRect.width();
|
||||
double scaleY = hPts / textRect.height();
|
||||
font.setPointSizeF( std::max( 6 * std::min( scaleX, scaleY ), MIN_POINT_SIZE ) );
|
||||
}
|
||||
|
||||
//
|
||||
// Render hole for text (font size may have changed above)
|
||||
//
|
||||
fm = QFontMetricsF( font );
|
||||
textRect = fm.boundingRect( shortText );
|
||||
|
||||
QRectF holeRect( (mW.pt() - textRect.width())/2 - pad.pt(),
|
||||
(mH.pt() - textRect.height())/2 - pad.pt(),
|
||||
textRect.width() + 2*pad.pt(),
|
||||
textRect.height() + 2*pad.pt() );
|
||||
|
||||
painter->setPen( Qt::NoPen );
|
||||
painter->setBrush( QBrush( fillColor ) );
|
||||
painter->drawRect( holeRect );
|
||||
|
||||
//
|
||||
// Render text
|
||||
//
|
||||
painter->setFont( font );
|
||||
painter->setPen( QPen( color ) );
|
||||
painter->drawText( QRectF( 0, 0, mW.pt(), mH.pt() ), Qt::AlignCenter, shortText );
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const QColor fillColor = QColor( 224, 224, 224, 255 );
|
||||
const Distance pad = Distance::pt(4);
|
||||
const Distance minW = Distance::pt(18);
|
||||
const Distance minH = Distance::pt(18);
|
||||
const double MIN_POINT_SIZE = 0.4; // Less than ~0.37 causes issues for QFontMetricsF
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelBarcodeObject::ModelBarcodeObject()
|
||||
{
|
||||
mOutline.setOwner( this );
|
||||
|
||||
mHandles.push_back( Handle( this, Handle::NW ) );
|
||||
mHandles.push_back( Handle( this, Handle::N ) );
|
||||
mHandles.push_back( Handle( this, Handle::NE ) );
|
||||
mHandles.push_back( Handle( this, Handle::E ) );
|
||||
mHandles.push_back( Handle( this, Handle::SE ) );
|
||||
mHandles.push_back( Handle( this, Handle::S ) );
|
||||
mHandles.push_back( Handle( this, Handle::SW ) );
|
||||
mHandles.push_back( Handle( this, Handle::W ) );
|
||||
|
||||
mBcStyle = barcode::Backends::defaultStyle();
|
||||
mBcTextFlag = mBcStyle.canText();
|
||||
mBcChecksumFlag = mBcStyle.canChecksum();
|
||||
mBcFormatDigits = mBcStyle.preferedN();
|
||||
mBcData = "";
|
||||
mBcColorNode = ColorNode( Qt::black );
|
||||
|
||||
update(); // Initialize cached editor layouts
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelBarcodeObject::ModelBarcodeObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
const barcode::Style& bcStyle,
|
||||
bool bcTextFlag,
|
||||
bool bcChecksumFlag,
|
||||
QString bcData,
|
||||
const ColorNode& bcColorNode,
|
||||
const QTransform& matrix )
|
||||
: ModelObject( x0, y0, w, h, lockAspectRatio, matrix )
|
||||
{
|
||||
mOutline.setOwner( this );
|
||||
|
||||
mHandles.push_back( Handle( this, Handle::NW ) );
|
||||
mHandles.push_back( Handle( this, Handle::N ) );
|
||||
mHandles.push_back( Handle( this, Handle::NE ) );
|
||||
mHandles.push_back( Handle( this, Handle::E ) );
|
||||
mHandles.push_back( Handle( this, Handle::SE ) );
|
||||
mHandles.push_back( Handle( this, Handle::S ) );
|
||||
mHandles.push_back( Handle( this, Handle::SW ) );
|
||||
mHandles.push_back( Handle( this, Handle::W ) );
|
||||
|
||||
mBcStyle = bcStyle;
|
||||
mBcTextFlag = bcTextFlag;
|
||||
mBcChecksumFlag = bcChecksumFlag;
|
||||
mBcFormatDigits = mBcStyle.preferedN();
|
||||
mBcData = bcData;
|
||||
mBcColorNode = bcColorNode;
|
||||
|
||||
update(); // Initialize cached editor layouts
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Copy constructor
|
||||
///
|
||||
ModelBarcodeObject::ModelBarcodeObject( const ModelBarcodeObject* object )
|
||||
: ModelObject(object)
|
||||
{
|
||||
mBcStyle = object->mBcStyle;
|
||||
mBcTextFlag = object->mBcTextFlag;
|
||||
mBcChecksumFlag = object->mBcChecksumFlag;
|
||||
mBcFormatDigits = object->mBcFormatDigits;
|
||||
mBcData = object->mBcData;
|
||||
mBcColorNode = object->mBcColorNode;
|
||||
|
||||
update(); // Initialize cached editor layouts
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
ModelBarcodeObject* ModelBarcodeObject::clone() const
|
||||
{
|
||||
return new ModelBarcodeObject( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcData Property Getter
|
||||
///
|
||||
QString ModelBarcodeObject::bcData() const
|
||||
{
|
||||
return mBcData.toString();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcData Property Setter
|
||||
///
|
||||
void ModelBarcodeObject::setBcData( const QString& value )
|
||||
{
|
||||
if ( mBcData.toString() != value )
|
||||
{
|
||||
mBcData = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcTextFlag Property Getter
|
||||
///
|
||||
bool ModelBarcodeObject::bcTextFlag() const
|
||||
{
|
||||
return mBcTextFlag;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcTextFlag Property Setter
|
||||
///
|
||||
void ModelBarcodeObject::setBcTextFlag( bool value )
|
||||
{
|
||||
if ( mBcTextFlag != value )
|
||||
{
|
||||
mBcTextFlag = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcChecksumFlag Property Getter
|
||||
///
|
||||
bool ModelBarcodeObject::bcChecksumFlag() const
|
||||
{
|
||||
return mBcChecksumFlag;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcChecksumFlag Property Setter
|
||||
///
|
||||
void ModelBarcodeObject::setBcChecksumFlag( bool value )
|
||||
{
|
||||
if ( mBcChecksumFlag != value )
|
||||
{
|
||||
mBcChecksumFlag = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Barcode Color Node Property Getter
|
||||
///
|
||||
ColorNode ModelBarcodeObject::bcColorNode() const
|
||||
{
|
||||
return mBcColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Barcode Color Node Property Setter
|
||||
///
|
||||
void ModelBarcodeObject::setBcColorNode( const ColorNode& value )
|
||||
{
|
||||
if ( mBcColorNode != value )
|
||||
{
|
||||
mBcColorNode = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Barcode Style Property Getter
|
||||
///
|
||||
barcode::Style ModelBarcodeObject::bcStyle() const
|
||||
{
|
||||
return mBcStyle;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Barcode Style Property Setter
|
||||
///
|
||||
void ModelBarcodeObject::setBcStyle( const barcode::Style& value )
|
||||
{
|
||||
if ( mBcStyle != value )
|
||||
{
|
||||
mBcStyle = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Barcode Format Digits Property Getter
|
||||
///
|
||||
int ModelBarcodeObject::bcFormatDigits() const
|
||||
{
|
||||
return mBcFormatDigits;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Barcode Format Digits Property Setter
|
||||
///
|
||||
void ModelBarcodeObject::setBcFormatDigits( int value )
|
||||
{
|
||||
if ( mBcFormatDigits != value )
|
||||
{
|
||||
mBcFormatDigits = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw shadow of object
|
||||
///
|
||||
void ModelBarcodeObject::drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
// Barcodes don't support shadows.
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw object itself
|
||||
///
|
||||
void ModelBarcodeObject::drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
QColor bcColor = mBcColorNode.color( record, variables );
|
||||
|
||||
if ( inEditor )
|
||||
{
|
||||
drawBcInEditor( painter, bcColor );
|
||||
}
|
||||
else
|
||||
{
|
||||
drawBc( painter, bcColor, record, variables );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Path to test for hover condition
|
||||
///
|
||||
QPainterPath ModelBarcodeObject::hoverPath( double scale ) const
|
||||
{
|
||||
return mHoverPath;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Size updated
|
||||
///
|
||||
void ModelBarcodeObject::sizeUpdated()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Update cached information for editor view
|
||||
///
|
||||
void ModelBarcodeObject::update()
|
||||
{
|
||||
//
|
||||
// Build barcode from data
|
||||
//
|
||||
mEditorBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() ) );
|
||||
if ( !mEditorBarcode )
|
||||
{
|
||||
qWarning() << "Invalid barcode style" << mBcStyle.fullId() << "using \"code39\".";
|
||||
mBcStyle = barcode::Backends::defaultStyle();
|
||||
mEditorBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() ) );
|
||||
}
|
||||
mEditorBarcode->setChecksum(mBcChecksumFlag);
|
||||
mEditorBarcode->setShowText(mBcTextFlag);
|
||||
|
||||
mEditorBarcode->build( mBcData.toStdString(), mW.pt(), mH.pt() );
|
||||
|
||||
//
|
||||
// Build a place holder barcode to display in editor, if cannot display actual barcode
|
||||
//
|
||||
mEditorDefaultBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() ) );
|
||||
if ( !mEditorDefaultBarcode )
|
||||
{
|
||||
qWarning() << "Invalid barcode style" << mBcStyle.fullId() << "using \"code39\".";
|
||||
mBcStyle = barcode::Backends::defaultStyle();
|
||||
mEditorDefaultBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() ) );
|
||||
}
|
||||
mEditorDefaultBarcode->setChecksum(mBcChecksumFlag);
|
||||
mEditorDefaultBarcode->setShowText(mBcTextFlag);
|
||||
|
||||
mEditorDefaultBarcode->build( mBcStyle.defaultDigits().toStdString(), mW.pt(), mH.pt() );
|
||||
|
||||
//
|
||||
// Adjust size
|
||||
//
|
||||
if ( mEditorBarcode->isDataValid() )
|
||||
{
|
||||
mW = Distance::pt( mEditorBarcode->width() );
|
||||
mH = Distance::pt( mEditorBarcode->height() );
|
||||
}
|
||||
else
|
||||
{
|
||||
mW = Distance::pt( mEditorDefaultBarcode->width() );
|
||||
mH = Distance::pt( mEditorDefaultBarcode->height() );
|
||||
}
|
||||
|
||||
QPainterPath path;
|
||||
path.addRect( 0, 0, mW.pt(), mH.pt() );
|
||||
mHoverPath = path;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw barcode in editor from cached information
|
||||
///
|
||||
void ModelBarcodeObject::drawBcInEditor( QPainter* painter, const QColor& color ) const
|
||||
{
|
||||
if ( mBcData.isEmpty() )
|
||||
{
|
||||
drawPlaceHolder( painter, color, tr("No barcode data") );
|
||||
}
|
||||
else if ( mBcData.hasPlaceHolders() )
|
||||
{
|
||||
drawPlaceHolder( painter, color, mBcData.toString() );
|
||||
}
|
||||
else if ( mEditorBarcode->isDataValid() )
|
||||
{
|
||||
painter->setPen( QPen( color ) );
|
||||
glbarcode::QtRenderer renderer(painter);
|
||||
mEditorBarcode->render( renderer );
|
||||
}
|
||||
else
|
||||
{
|
||||
drawPlaceHolder( painter, color, tr("Invalid barcode data") );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw barcode in final printout or preview
|
||||
///
|
||||
void
|
||||
ModelBarcodeObject::drawBc( QPainter* painter,
|
||||
const QColor& color,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
painter->setPen( QPen( color ) );
|
||||
|
||||
glbarcode::Barcode* bc = glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() );
|
||||
bc->setChecksum(mBcChecksumFlag);
|
||||
bc->setShowText(mBcTextFlag);
|
||||
|
||||
bc->build( mBcData.expand( record, variables ).toStdString(), mW.pt(), mH.pt() );
|
||||
|
||||
glbarcode::QtRenderer renderer(painter);
|
||||
bc->render( renderer );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw barcode place holder in editor
|
||||
///
|
||||
void
|
||||
ModelBarcodeObject::drawPlaceHolder( QPainter* painter,
|
||||
const QColor& color,
|
||||
const QString& text ) const
|
||||
{
|
||||
QString shortText = text.left( 32 ); // Don't let the text get out of hand
|
||||
|
||||
//
|
||||
// Render box
|
||||
//
|
||||
painter->setPen( Qt::NoPen );
|
||||
painter->setBrush( QBrush( fillColor ) );
|
||||
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
|
||||
//
|
||||
// Render default barcode
|
||||
//
|
||||
painter->setPen( QPen( color ) );
|
||||
glbarcode::QtRenderer renderer(painter);
|
||||
mEditorDefaultBarcode->render( renderer );
|
||||
|
||||
//
|
||||
// Determine font size for text
|
||||
//
|
||||
QFont font( "Sans" );
|
||||
font.setPointSizeF( 6 );
|
||||
|
||||
QFontMetricsF fm( font );
|
||||
QRectF textRect = fm.boundingRect( shortText );
|
||||
|
||||
double wPts = (mW - 2*pad).pt();
|
||||
double hPts = (mH - 2*pad).pt();
|
||||
if ( (wPts < textRect.width()) || (hPts < textRect.height()) )
|
||||
{
|
||||
double scaleX = wPts / textRect.width();
|
||||
double scaleY = hPts / textRect.height();
|
||||
font.setPointSizeF( std::max( 6 * std::min( scaleX, scaleY ), MIN_POINT_SIZE ) );
|
||||
}
|
||||
|
||||
//
|
||||
// Render hole for text (font size may have changed above)
|
||||
//
|
||||
fm = QFontMetricsF( font );
|
||||
textRect = fm.boundingRect( shortText );
|
||||
|
||||
QRectF holeRect( (mW.pt() - textRect.width())/2 - pad.pt(),
|
||||
(mH.pt() - textRect.height())/2 - pad.pt(),
|
||||
textRect.width() + 2*pad.pt(),
|
||||
textRect.height() + 2*pad.pt() );
|
||||
|
||||
painter->setPen( Qt::NoPen );
|
||||
painter->setBrush( QBrush( fillColor ) );
|
||||
painter->drawRect( holeRect );
|
||||
|
||||
//
|
||||
// Render text
|
||||
//
|
||||
painter->setFont( font );
|
||||
painter->setPen( QPen( color ) );
|
||||
painter->drawText( QRectF( 0, 0, mW.pt(), mH.pt() ), Qt::AlignCenter, shortText );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,185 +0,0 @@
|
||||
/* ModelBarcodeObject.h
|
||||
*
|
||||
* Copyright (C) 2017 Jaye 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 model_ModelBarcodeObject_h
|
||||
#define model_ModelBarcodeObject_h
|
||||
|
||||
|
||||
#include "ModelObject.h"
|
||||
|
||||
#include "RawText.h"
|
||||
|
||||
#include "glbarcode/Barcode.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Line Object
|
||||
///
|
||||
class ModelBarcodeObject : public ModelObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
ModelBarcodeObject();
|
||||
|
||||
ModelBarcodeObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
const barcode::Style& bcStyle,
|
||||
bool bcTextFlag,
|
||||
bool bcChecksumFlag,
|
||||
QString bcData,
|
||||
const ColorNode& bcColorNode,
|
||||
const QTransform& matrix = QTransform() );
|
||||
|
||||
ModelBarcodeObject( const ModelBarcodeObject* object );
|
||||
|
||||
virtual ~ModelBarcodeObject() = default;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
ModelBarcodeObject* clone() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Property Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Barcode Property: bcData
|
||||
//
|
||||
QString bcData() const override;
|
||||
void setBcData( const QString &value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Barcode Property: bcTextFlag
|
||||
//
|
||||
bool bcTextFlag() const override;
|
||||
void setBcTextFlag( bool value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Barcode Property: bcChecksumFlag
|
||||
//
|
||||
bool bcChecksumFlag() const override;
|
||||
void setBcChecksumFlag( bool value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Barcode Property: bcColorNode
|
||||
//
|
||||
ColorNode bcColorNode() const override;
|
||||
void setBcColorNode( const ColorNode &value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Barcode Property: bcStyle
|
||||
//
|
||||
barcode::Style bcStyle() const override;
|
||||
void setBcStyle( const barcode::Style &value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Barcode Property: bcFormatDigits
|
||||
//
|
||||
int bcFormatDigits() const override;
|
||||
void setBcFormatDigits( int value ) override;
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capability Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
void drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
void drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
QPainterPath hoverPath( double scale ) const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
void sizeUpdated() override;
|
||||
void update();
|
||||
|
||||
void drawBcInEditor( QPainter* painter, const QColor& color ) const;
|
||||
|
||||
void drawBc( QPainter* painter,
|
||||
const QColor& color,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const;
|
||||
|
||||
void drawPlaceHolder( QPainter* painter, const QColor& color, const QString& text ) const;
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
barcode::Style mBcStyle;
|
||||
bool mBcTextFlag;
|
||||
bool mBcChecksumFlag;
|
||||
int mBcFormatDigits;
|
||||
RawText mBcData;
|
||||
ColorNode mBcColorNode;
|
||||
|
||||
std::unique_ptr<glbarcode::Barcode> mEditorBarcode;
|
||||
std::unique_ptr<glbarcode::Barcode> mEditorDefaultBarcode;
|
||||
|
||||
QPainterPath mHoverPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ModelBarcodeObject_h
|
||||
@@ -0,0 +1,182 @@
|
||||
// ModelBarcodeObject.hpp
|
||||
//
|
||||
// Copyright (C) 2017 Jaye 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 model_ModelBarcodeObject_hpp
|
||||
#define model_ModelBarcodeObject_hpp
|
||||
|
||||
|
||||
#include "ModelObject.hpp"
|
||||
|
||||
#include "RawText.hpp"
|
||||
|
||||
#include "glbarcode/Barcode.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Line Object
|
||||
///
|
||||
class ModelBarcodeObject : public ModelObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
ModelBarcodeObject();
|
||||
|
||||
ModelBarcodeObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
const barcode::Style& bcStyle,
|
||||
bool bcTextFlag,
|
||||
bool bcChecksumFlag,
|
||||
QString bcData,
|
||||
const ColorNode& bcColorNode,
|
||||
const QTransform& matrix = QTransform() );
|
||||
|
||||
ModelBarcodeObject( const ModelBarcodeObject* object );
|
||||
|
||||
virtual ~ModelBarcodeObject() = default;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
ModelBarcodeObject* clone() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Property Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Barcode Property: bcData
|
||||
//
|
||||
QString bcData() const override;
|
||||
void setBcData( const QString &value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Barcode Property: bcTextFlag
|
||||
//
|
||||
bool bcTextFlag() const override;
|
||||
void setBcTextFlag( bool value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Barcode Property: bcChecksumFlag
|
||||
//
|
||||
bool bcChecksumFlag() const override;
|
||||
void setBcChecksumFlag( bool value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Barcode Property: bcColorNode
|
||||
//
|
||||
ColorNode bcColorNode() const override;
|
||||
void setBcColorNode( const ColorNode &value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Barcode Property: bcStyle
|
||||
//
|
||||
barcode::Style bcStyle() const override;
|
||||
void setBcStyle( const barcode::Style &value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Barcode Property: bcFormatDigits
|
||||
//
|
||||
int bcFormatDigits() const override;
|
||||
void setBcFormatDigits( int value ) override;
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capability Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
void drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
void drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
QPainterPath hoverPath( double scale ) const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
void sizeUpdated() override;
|
||||
void update();
|
||||
|
||||
void drawBcInEditor( QPainter* painter, const QColor& color ) const;
|
||||
|
||||
void drawBc( QPainter* painter,
|
||||
const QColor& color,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const;
|
||||
|
||||
void drawPlaceHolder( QPainter* painter, const QColor& color, const QString& text ) const;
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
barcode::Style mBcStyle;
|
||||
bool mBcTextFlag;
|
||||
bool mBcChecksumFlag;
|
||||
int mBcFormatDigits;
|
||||
RawText mBcData;
|
||||
ColorNode mBcColorNode;
|
||||
|
||||
std::unique_ptr<glbarcode::Barcode> mEditorBarcode;
|
||||
std::unique_ptr<glbarcode::Barcode> mEditorDefaultBarcode;
|
||||
|
||||
QPainterPath mHoverPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ModelBarcodeObject_hpp
|
||||
+185
-197
@@ -1,206 +1,194 @@
|
||||
/* ModelBoxObject.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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/>.
|
||||
*/
|
||||
// ModelBoxObject.cpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 "ModelBoxObject.h"
|
||||
#include "ModelBoxObject.hpp"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QPen>
|
||||
|
||||
|
||||
namespace glabels
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const double slopPixels = 2;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelBoxObject::ModelBoxObject()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelBoxObject::ModelBoxObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
Distance lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
const QTransform& matrix,
|
||||
bool shadowState,
|
||||
Distance shadowX,
|
||||
Distance shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: ModelShapeObject( x0,
|
||||
y0,
|
||||
w,
|
||||
h,
|
||||
lockAspectRatio,
|
||||
lineWidth,
|
||||
lineColorNode,
|
||||
fillColorNode,
|
||||
matrix,
|
||||
shadowState,
|
||||
shadowX,
|
||||
shadowY,
|
||||
shadowOpacity,
|
||||
shadowColorNode )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Copy constructor
|
||||
///
|
||||
ModelBoxObject::ModelBoxObject( const ModelBoxObject* object )
|
||||
: ModelShapeObject( object )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
ModelBoxObject* ModelBoxObject::clone() const
|
||||
{
|
||||
return new ModelBoxObject( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw shadow of object
|
||||
///
|
||||
void ModelBoxObject::drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
QColor lineColor = mLineColorNode.color( record, variables );
|
||||
QColor fillColor = mFillColorNode.color( record, variables );
|
||||
QColor shadowColor = mShadowColorNode.color( record, variables );
|
||||
|
||||
shadowColor.setAlphaF( mShadowOpacity );
|
||||
|
||||
if ( fillColor.alpha() )
|
||||
{
|
||||
painter->setPen( Qt::NoPen );
|
||||
painter->setBrush( shadowColor );
|
||||
|
||||
if ( lineColor.alpha() )
|
||||
{
|
||||
/* Has FILL and OUTLINE: adjust size to account for line width. */
|
||||
painter->drawRect( QRectF( -mLineWidth.pt()/2,
|
||||
-mLineWidth.pt()/2,
|
||||
(mW + mLineWidth).pt(),
|
||||
(mH + mLineWidth).pt() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Has FILL, but no OUTLINE. */
|
||||
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( lineColor.alpha() )
|
||||
{
|
||||
/* Has only OUTLINE. */
|
||||
painter->setPen( QPen( shadowColor, mLineWidth.pt() ) );
|
||||
painter->setBrush( Qt::NoBrush );
|
||||
|
||||
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw object itself
|
||||
///
|
||||
void ModelBoxObject::drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
QColor lineColor = mLineColorNode.color( record, variables );
|
||||
QColor fillColor = mFillColorNode.color( record, variables );
|
||||
|
||||
painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
|
||||
painter->setBrush( fillColor );
|
||||
|
||||
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Path to test for hover condition
|
||||
///
|
||||
QPainterPath ModelBoxObject::hoverPath( double scale ) const
|
||||
{
|
||||
double s = 1 / scale;
|
||||
|
||||
QPainterPath path;
|
||||
|
||||
if ( mFillColorNode.color().alpha() && mLineColorNode.color().alpha() )
|
||||
{
|
||||
path.addRect( -mLineWidth.pt()/2, -mLineWidth.pt()/2, (mW+mLineWidth).pt(), (mH+mLineWidth).pt() );
|
||||
}
|
||||
else if ( mFillColorNode.color().alpha() && !(mLineColorNode.color().alpha()) )
|
||||
{
|
||||
path.addRect( 0, 0, mW.pt(), mH.pt() );
|
||||
}
|
||||
else if ( mLineColorNode.color().alpha() )
|
||||
{
|
||||
path.addRect( (-mLineWidth.pt()/2) - s*slopPixels,
|
||||
(-mLineWidth.pt()/2) - s*slopPixels,
|
||||
(mW + mLineWidth).pt() + s*2*slopPixels,
|
||||
(mH + mLineWidth).pt() + s*2*slopPixels );
|
||||
path.closeSubpath();
|
||||
path.addRect( mLineWidth.pt()/2 + s*slopPixels,
|
||||
mLineWidth.pt()/2 + s*slopPixels,
|
||||
(mW - mLineWidth).pt() - s*2*slopPixels,
|
||||
(mH - mLineWidth).pt() - s*2*slopPixels );
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
const double slopPixels = 2;
|
||||
}
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelBoxObject::ModelBoxObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
Distance lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
const QTransform& matrix,
|
||||
bool shadowState,
|
||||
Distance shadowX,
|
||||
Distance shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: ModelShapeObject( x0,
|
||||
y0,
|
||||
w,
|
||||
h,
|
||||
lockAspectRatio,
|
||||
lineWidth,
|
||||
lineColorNode,
|
||||
fillColorNode,
|
||||
matrix,
|
||||
shadowState,
|
||||
shadowX,
|
||||
shadowY,
|
||||
shadowOpacity,
|
||||
shadowColorNode )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Copy constructor
|
||||
///
|
||||
ModelBoxObject::ModelBoxObject( const ModelBoxObject* object )
|
||||
: ModelShapeObject( object )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
ModelBoxObject* ModelBoxObject::clone() const
|
||||
{
|
||||
return new ModelBoxObject( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw shadow of object
|
||||
///
|
||||
void ModelBoxObject::drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
QColor lineColor = mLineColorNode.color( record, variables );
|
||||
QColor fillColor = mFillColorNode.color( record, variables );
|
||||
QColor shadowColor = mShadowColorNode.color( record, variables );
|
||||
|
||||
shadowColor.setAlphaF( mShadowOpacity );
|
||||
|
||||
if ( fillColor.alpha() )
|
||||
{
|
||||
painter->setPen( Qt::NoPen );
|
||||
painter->setBrush( shadowColor );
|
||||
|
||||
if ( lineColor.alpha() )
|
||||
{
|
||||
/* Has FILL and OUTLINE: adjust size to account for line width. */
|
||||
painter->drawRect( QRectF( -mLineWidth.pt()/2,
|
||||
-mLineWidth.pt()/2,
|
||||
(mW + mLineWidth).pt(),
|
||||
(mH + mLineWidth).pt() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Has FILL, but no OUTLINE. */
|
||||
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( lineColor.alpha() )
|
||||
{
|
||||
/* Has only OUTLINE. */
|
||||
painter->setPen( QPen( shadowColor, mLineWidth.pt() ) );
|
||||
painter->setBrush( Qt::NoBrush );
|
||||
|
||||
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw object itself
|
||||
///
|
||||
void ModelBoxObject::drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
QColor lineColor = mLineColorNode.color( record, variables );
|
||||
QColor fillColor = mFillColorNode.color( record, variables );
|
||||
|
||||
painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
|
||||
painter->setBrush( fillColor );
|
||||
|
||||
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Path to test for hover condition
|
||||
///
|
||||
QPainterPath ModelBoxObject::hoverPath( double scale ) const
|
||||
{
|
||||
double s = 1 / scale;
|
||||
|
||||
QPainterPath path;
|
||||
|
||||
if ( mFillColorNode.color().alpha() && mLineColorNode.color().alpha() )
|
||||
{
|
||||
path.addRect( -mLineWidth.pt()/2, -mLineWidth.pt()/2, (mW+mLineWidth).pt(), (mH+mLineWidth).pt() );
|
||||
}
|
||||
else if ( mFillColorNode.color().alpha() && !(mLineColorNode.color().alpha()) )
|
||||
{
|
||||
path.addRect( 0, 0, mW.pt(), mH.pt() );
|
||||
}
|
||||
else if ( mLineColorNode.color().alpha() )
|
||||
{
|
||||
path.addRect( (-mLineWidth.pt()/2) - s*slopPixels,
|
||||
(-mLineWidth.pt()/2) - s*slopPixels,
|
||||
(mW + mLineWidth).pt() + s*2*slopPixels,
|
||||
(mH + mLineWidth).pt() + s*2*slopPixels );
|
||||
path.closeSubpath();
|
||||
path.addRect( mLineWidth.pt()/2 + s*slopPixels,
|
||||
mLineWidth.pt()/2 + s*slopPixels,
|
||||
(mW - mLineWidth).pt() - s*2*slopPixels,
|
||||
(mH - mLineWidth).pt() - s*2*slopPixels );
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
/* ModelBoxObject.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_ModelBoxObject_h
|
||||
#define model_ModelBoxObject_h
|
||||
|
||||
|
||||
#include "ModelShapeObject.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Box Object
|
||||
///
|
||||
class ModelBoxObject : public ModelShapeObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
ModelBoxObject();
|
||||
|
||||
ModelBoxObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
Distance lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
const QTransform& matrix = QTransform(),
|
||||
bool shadowState = false,
|
||||
Distance shadowX = 0,
|
||||
Distance shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
ModelBoxObject( const ModelBoxObject* object );
|
||||
|
||||
virtual ~ModelBoxObject() = default;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
ModelBoxObject* clone() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
void drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
void drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
QPainterPath hoverPath( double scale ) const override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ModelBoxObject_h
|
||||
@@ -0,0 +1,91 @@
|
||||
// ModelBoxObject.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_ModelBoxObject_hpp
|
||||
#define model_ModelBoxObject_hpp
|
||||
|
||||
|
||||
#include "ModelShapeObject.hpp"
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Box Object
|
||||
///
|
||||
class ModelBoxObject : public ModelShapeObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
ModelBoxObject() = default;
|
||||
|
||||
ModelBoxObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
Distance lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
const QTransform& matrix = QTransform(),
|
||||
bool shadowState = false,
|
||||
Distance shadowX = 0,
|
||||
Distance shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
ModelBoxObject( const ModelBoxObject* object );
|
||||
|
||||
virtual ~ModelBoxObject() = default;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
ModelBoxObject* clone() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
void drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
void drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
QPainterPath hoverPath( double scale ) const override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ModelBoxObject_hpp
|
||||
+185
-197
@@ -1,206 +1,194 @@
|
||||
/* ModelEllipseObject.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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/>.
|
||||
*/
|
||||
// ModelEllipseObject.cpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 "ModelEllipseObject.h"
|
||||
#include "ModelEllipseObject.hpp"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QPen>
|
||||
|
||||
|
||||
namespace glabels
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const double slopPixels = 2;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelEllipseObject::ModelEllipseObject()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelEllipseObject::ModelEllipseObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
Distance lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
const QTransform& matrix,
|
||||
bool shadowState,
|
||||
Distance shadowX,
|
||||
Distance shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: ModelShapeObject( x0,
|
||||
y0,
|
||||
w,
|
||||
h,
|
||||
lockAspectRatio,
|
||||
lineWidth,
|
||||
lineColorNode,
|
||||
fillColorNode,
|
||||
matrix,
|
||||
shadowState,
|
||||
shadowX,
|
||||
shadowY,
|
||||
shadowOpacity,
|
||||
shadowColorNode )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Copy constructor
|
||||
///
|
||||
ModelEllipseObject::ModelEllipseObject( const ModelEllipseObject* object )
|
||||
: ModelShapeObject( object )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
ModelEllipseObject* ModelEllipseObject::clone() const
|
||||
{
|
||||
return new ModelEllipseObject( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw shadow of object
|
||||
///
|
||||
void ModelEllipseObject::drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
QColor lineColor = mLineColorNode.color( record, variables );
|
||||
QColor fillColor = mFillColorNode.color( record, variables );
|
||||
QColor shadowColor = mShadowColorNode.color( record, variables );
|
||||
|
||||
shadowColor.setAlphaF( mShadowOpacity );
|
||||
|
||||
if ( fillColor.alpha() )
|
||||
{
|
||||
painter->setPen( Qt::NoPen );
|
||||
painter->setBrush( shadowColor );
|
||||
|
||||
if ( lineColor.alpha() )
|
||||
{
|
||||
/* Has FILL and OUTLINE: adjust size to account for line width. */
|
||||
painter->drawEllipse( QRectF( -mLineWidth.pt()/2,
|
||||
-mLineWidth.pt()/2,
|
||||
(mW + mLineWidth).pt(),
|
||||
(mH + mLineWidth).pt() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Has FILL, but no OUTLINE. */
|
||||
painter->drawEllipse( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( lineColor.alpha() )
|
||||
{
|
||||
/* Has only OUTLINE. */
|
||||
painter->setPen( QPen( shadowColor, mLineWidth.pt() ) );
|
||||
painter->setBrush( Qt::NoBrush );
|
||||
|
||||
painter->drawEllipse( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw object itself
|
||||
///
|
||||
void ModelEllipseObject::drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
QColor lineColor = mLineColorNode.color( record, variables );
|
||||
QColor fillColor = mFillColorNode.color( record, variables );
|
||||
|
||||
painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
|
||||
painter->setBrush( fillColor );
|
||||
|
||||
painter->drawEllipse( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Path to test for hover condition
|
||||
///
|
||||
QPainterPath ModelEllipseObject::hoverPath( double scale ) const
|
||||
{
|
||||
double s = 1 / scale;
|
||||
|
||||
QPainterPath path;
|
||||
|
||||
if ( mFillColorNode.color().alpha() && mLineColorNode.color().alpha() )
|
||||
{
|
||||
path.addEllipse( -mLineWidth.pt()/2, -mLineWidth.pt()/2, (mW+mLineWidth).pt(), (mH+mLineWidth).pt() );
|
||||
}
|
||||
else if ( mFillColorNode.color().alpha() && !(mLineColorNode.color().alpha()) )
|
||||
{
|
||||
path.addEllipse( 0, 0, mW.pt(), mH.pt() );
|
||||
}
|
||||
else if ( mLineColorNode.color().alpha() )
|
||||
{
|
||||
path.addEllipse( (-mLineWidth.pt()/2) - s*slopPixels,
|
||||
(-mLineWidth.pt()/2) - s*slopPixels,
|
||||
(mW + mLineWidth).pt() + s*2*slopPixels,
|
||||
(mH + mLineWidth).pt() + s*2*slopPixels );
|
||||
path.closeSubpath();
|
||||
path.addEllipse( mLineWidth.pt()/2 + s*slopPixels,
|
||||
mLineWidth.pt()/2 + s*slopPixels,
|
||||
(mW - mLineWidth).pt() - s*2*slopPixels,
|
||||
(mH - mLineWidth).pt() - s*2*slopPixels );
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
const double slopPixels = 2;
|
||||
}
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelEllipseObject::ModelEllipseObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
Distance lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
const QTransform& matrix,
|
||||
bool shadowState,
|
||||
Distance shadowX,
|
||||
Distance shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: ModelShapeObject( x0,
|
||||
y0,
|
||||
w,
|
||||
h,
|
||||
lockAspectRatio,
|
||||
lineWidth,
|
||||
lineColorNode,
|
||||
fillColorNode,
|
||||
matrix,
|
||||
shadowState,
|
||||
shadowX,
|
||||
shadowY,
|
||||
shadowOpacity,
|
||||
shadowColorNode )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Copy constructor
|
||||
///
|
||||
ModelEllipseObject::ModelEllipseObject( const ModelEllipseObject* object )
|
||||
: ModelShapeObject( object )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
ModelEllipseObject* ModelEllipseObject::clone() const
|
||||
{
|
||||
return new ModelEllipseObject( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw shadow of object
|
||||
///
|
||||
void ModelEllipseObject::drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
QColor lineColor = mLineColorNode.color( record, variables );
|
||||
QColor fillColor = mFillColorNode.color( record, variables );
|
||||
QColor shadowColor = mShadowColorNode.color( record, variables );
|
||||
|
||||
shadowColor.setAlphaF( mShadowOpacity );
|
||||
|
||||
if ( fillColor.alpha() )
|
||||
{
|
||||
painter->setPen( Qt::NoPen );
|
||||
painter->setBrush( shadowColor );
|
||||
|
||||
if ( lineColor.alpha() )
|
||||
{
|
||||
/* Has FILL and OUTLINE: adjust size to account for line width. */
|
||||
painter->drawEllipse( QRectF( -mLineWidth.pt()/2,
|
||||
-mLineWidth.pt()/2,
|
||||
(mW + mLineWidth).pt(),
|
||||
(mH + mLineWidth).pt() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Has FILL, but no OUTLINE. */
|
||||
painter->drawEllipse( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( lineColor.alpha() )
|
||||
{
|
||||
/* Has only OUTLINE. */
|
||||
painter->setPen( QPen( shadowColor, mLineWidth.pt() ) );
|
||||
painter->setBrush( Qt::NoBrush );
|
||||
|
||||
painter->drawEllipse( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw object itself
|
||||
///
|
||||
void ModelEllipseObject::drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
QColor lineColor = mLineColorNode.color( record, variables );
|
||||
QColor fillColor = mFillColorNode.color( record, variables );
|
||||
|
||||
painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
|
||||
painter->setBrush( fillColor );
|
||||
|
||||
painter->drawEllipse( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Path to test for hover condition
|
||||
///
|
||||
QPainterPath ModelEllipseObject::hoverPath( double scale ) const
|
||||
{
|
||||
double s = 1 / scale;
|
||||
|
||||
QPainterPath path;
|
||||
|
||||
if ( mFillColorNode.color().alpha() && mLineColorNode.color().alpha() )
|
||||
{
|
||||
path.addEllipse( -mLineWidth.pt()/2, -mLineWidth.pt()/2, (mW+mLineWidth).pt(), (mH+mLineWidth).pt() );
|
||||
}
|
||||
else if ( mFillColorNode.color().alpha() && !(mLineColorNode.color().alpha()) )
|
||||
{
|
||||
path.addEllipse( 0, 0, mW.pt(), mH.pt() );
|
||||
}
|
||||
else if ( mLineColorNode.color().alpha() )
|
||||
{
|
||||
path.addEllipse( (-mLineWidth.pt()/2) - s*slopPixels,
|
||||
(-mLineWidth.pt()/2) - s*slopPixels,
|
||||
(mW + mLineWidth).pt() + s*2*slopPixels,
|
||||
(mH + mLineWidth).pt() + s*2*slopPixels );
|
||||
path.closeSubpath();
|
||||
path.addEllipse( mLineWidth.pt()/2 + s*slopPixels,
|
||||
mLineWidth.pt()/2 + s*slopPixels,
|
||||
(mW - mLineWidth).pt() - s*2*slopPixels,
|
||||
(mH - mLineWidth).pt() - s*2*slopPixels );
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
/* ModelEllipseObject.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_ModelEllipseObject_h
|
||||
#define model_ModelEllipseObject_h
|
||||
|
||||
|
||||
#include "ModelShapeObject.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Ellipse Object
|
||||
///
|
||||
class ModelEllipseObject : public ModelShapeObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
ModelEllipseObject();
|
||||
|
||||
ModelEllipseObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
Distance lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
const QTransform& matrix = QTransform(),
|
||||
bool shadowState = false,
|
||||
Distance shadowX = 0,
|
||||
Distance shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
ModelEllipseObject( const ModelEllipseObject* object );
|
||||
|
||||
virtual ~ModelEllipseObject() = default;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
ModelEllipseObject* clone() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
void drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
void drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
QPainterPath hoverPath( double scale ) const override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ModelEllipseObject_h
|
||||
@@ -0,0 +1,91 @@
|
||||
// ModelEllipseObject.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_ModelEllipseObject_hpp
|
||||
#define model_ModelEllipseObject_hpp
|
||||
|
||||
|
||||
#include "ModelShapeObject.hpp"
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Ellipse Object
|
||||
///
|
||||
class ModelEllipseObject : public ModelShapeObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
ModelEllipseObject() = default;
|
||||
|
||||
ModelEllipseObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
Distance lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
const QTransform& matrix = QTransform(),
|
||||
bool shadowState = false,
|
||||
Distance shadowX = 0,
|
||||
Distance shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
ModelEllipseObject( const ModelEllipseObject* object );
|
||||
|
||||
virtual ~ModelEllipseObject() = default;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
ModelEllipseObject* clone() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
void drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
void drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
QPainterPath hoverPath( double scale ) const override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ModelEllipseObject_hpp
|
||||
+614
-615
File diff suppressed because it is too large
Load Diff
@@ -1,180 +0,0 @@
|
||||
/* ModelImageObject.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_ModelImageObject_h
|
||||
#define model_ModelImageObject_h
|
||||
|
||||
|
||||
#include "ModelObject.h"
|
||||
|
||||
#include <QSvgRenderer>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Image Object
|
||||
///
|
||||
class ModelImageObject : public ModelObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
ModelImageObject();
|
||||
|
||||
ModelImageObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
const TextNode& filenameNode,
|
||||
const QTransform& matrix = QTransform(),
|
||||
bool shadowState = false,
|
||||
Distance shadowX = 0,
|
||||
Distance shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
ModelImageObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
const QString& filename,
|
||||
const QImage& image,
|
||||
const QTransform& matrix = QTransform(),
|
||||
bool shadowState = false,
|
||||
Distance shadowX = 0,
|
||||
Distance shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
ModelImageObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
const QString& filename,
|
||||
const QByteArray& svg,
|
||||
const QTransform& matrix = QTransform(),
|
||||
bool shadowState = false,
|
||||
Distance shadowX = 0,
|
||||
Distance shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
ModelImageObject( const ModelImageObject* object );
|
||||
|
||||
virtual ~ModelImageObject() = default;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
ModelImageObject* clone() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Property Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Image Property: filenameNode
|
||||
//
|
||||
TextNode filenameNode() const override;
|
||||
void setFilenameNode( const TextNode& value ) override;
|
||||
|
||||
//
|
||||
// Image Property: image
|
||||
//
|
||||
const QImage& image() const override;
|
||||
void setImage( const QImage& value ) override;
|
||||
void setImage( const QString& name, const QImage& value ) override;
|
||||
|
||||
//
|
||||
// Image Property: svg
|
||||
//
|
||||
const QByteArray& svg() const override;
|
||||
void setSvg( const QString& name, const QByteArray& value ) override;
|
||||
|
||||
//
|
||||
// Property: naturalSize
|
||||
//
|
||||
Size naturalSize() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capability Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
void drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
void drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
QPainterPath hoverPath( double scale ) const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private
|
||||
///////////////////////////////////////////////////////////////
|
||||
void loadImage();
|
||||
|
||||
bool readImageFile( const QString& fileName,
|
||||
QImage& image,
|
||||
QByteArray& svg ) const;
|
||||
|
||||
QImage createShadowImage( const QImage& image,
|
||||
const QColor& color ) const;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
TextNode mFilenameNode;
|
||||
QImage mImage;
|
||||
QByteArray mSvg;
|
||||
|
||||
static QImage smDefaultImage;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ModelImageObject_h
|
||||
@@ -0,0 +1,177 @@
|
||||
// ModelImageObject.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_ModelImageObject_hpp
|
||||
#define model_ModelImageObject_hpp
|
||||
|
||||
|
||||
#include "ModelObject.hpp"
|
||||
|
||||
#include <QSvgRenderer>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Image Object
|
||||
///
|
||||
class ModelImageObject : public ModelObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
ModelImageObject();
|
||||
|
||||
ModelImageObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
const TextNode& filenameNode,
|
||||
const QTransform& matrix = QTransform(),
|
||||
bool shadowState = false,
|
||||
Distance shadowX = 0,
|
||||
Distance shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
ModelImageObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
const QString& filename,
|
||||
const QImage& image,
|
||||
const QTransform& matrix = QTransform(),
|
||||
bool shadowState = false,
|
||||
Distance shadowX = 0,
|
||||
Distance shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
ModelImageObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
const QString& filename,
|
||||
const QByteArray& svg,
|
||||
const QTransform& matrix = QTransform(),
|
||||
bool shadowState = false,
|
||||
Distance shadowX = 0,
|
||||
Distance shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
ModelImageObject( const ModelImageObject* object );
|
||||
|
||||
virtual ~ModelImageObject() = default;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
ModelImageObject* clone() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Property Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Image Property: filenameNode
|
||||
//
|
||||
TextNode filenameNode() const override;
|
||||
void setFilenameNode( const TextNode& value ) override;
|
||||
|
||||
//
|
||||
// Image Property: image
|
||||
//
|
||||
const QImage& image() const override;
|
||||
void setImage( const QImage& value ) override;
|
||||
void setImage( const QString& name, const QImage& value ) override;
|
||||
|
||||
//
|
||||
// Image Property: svg
|
||||
//
|
||||
const QByteArray& svg() const override;
|
||||
void setSvg( const QString& name, const QByteArray& value ) override;
|
||||
|
||||
//
|
||||
// Property: naturalSize
|
||||
//
|
||||
Size naturalSize() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capability Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
void drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
void drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
QPainterPath hoverPath( double scale ) const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private
|
||||
///////////////////////////////////////////////////////////////
|
||||
void loadImage();
|
||||
|
||||
bool readImageFile( const QString& fileName,
|
||||
QImage& image,
|
||||
QByteArray& svg ) const;
|
||||
|
||||
QImage createShadowImage( const QImage& image,
|
||||
const QColor& color ) const;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
TextNode mFilenameNode;
|
||||
QImage mImage;
|
||||
QByteArray mSvg;
|
||||
|
||||
static QImage smDefaultImage;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ModelImageObject_hpp
|
||||
+226
-229
@@ -1,238 +1,235 @@
|
||||
/* ModelLineObject.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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/>.
|
||||
*/
|
||||
// ModelLineObject.cpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 "ModelLineObject.h"
|
||||
#include "ModelLineObject.hpp"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QPen>
|
||||
|
||||
|
||||
namespace glabels
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const double slopPixels = 2;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelLineObject::ModelLineObject()
|
||||
{
|
||||
mHandles.push_back( Handle( this, Handle::P1 ) );
|
||||
mHandles.push_back( Handle( this, Handle::P2 ) );
|
||||
|
||||
mLineWidth = 1.0;
|
||||
mLineColorNode = ColorNode( QColor( 0, 0, 0 ) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelLineObject::ModelLineObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance dx,
|
||||
Distance dy,
|
||||
Distance lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const QTransform& matrix,
|
||||
bool shadowState,
|
||||
Distance shadowX,
|
||||
Distance shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: ModelObject( x0,
|
||||
y0,
|
||||
dx,
|
||||
dy,
|
||||
false /*lockAspectRatio*/,
|
||||
matrix,
|
||||
shadowState,
|
||||
shadowX,
|
||||
shadowY,
|
||||
shadowOpacity,
|
||||
shadowColorNode )
|
||||
{
|
||||
mHandles.push_back( Handle( this, Handle::P1 ) );
|
||||
mHandles.push_back( Handle( this, Handle::P2 ) );
|
||||
|
||||
mLineWidth = lineWidth;
|
||||
mLineColorNode = lineColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Copy constructor
|
||||
///
|
||||
ModelLineObject::ModelLineObject( const ModelLineObject* object )
|
||||
: ModelObject(object)
|
||||
{
|
||||
mLineWidth = object->mLineWidth;
|
||||
mLineColorNode = object->mLineColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
ModelLineObject* ModelLineObject::clone() const
|
||||
{
|
||||
return new ModelLineObject( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Width Property Getter
|
||||
///
|
||||
Distance ModelLineObject::lineWidth() const
|
||||
{
|
||||
return mLineWidth;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Width Property Setter
|
||||
///
|
||||
void ModelLineObject::setLineWidth( Distance value )
|
||||
{
|
||||
if ( mLineWidth != value )
|
||||
{
|
||||
mLineWidth = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Color Node Property Getter
|
||||
///
|
||||
ColorNode ModelLineObject::lineColorNode() const
|
||||
{
|
||||
return mLineColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Color Node Property Setter
|
||||
///
|
||||
void ModelLineObject::setLineColorNode( const ColorNode& value )
|
||||
{
|
||||
if ( mLineColorNode != value )
|
||||
{
|
||||
mLineColorNode = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Line Color Capability Implementation
|
||||
///
|
||||
bool ModelLineObject::canLineColor() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Line Width Capability Implementation
|
||||
///
|
||||
bool ModelLineObject::canLineWidth() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw shadow of object
|
||||
///
|
||||
void ModelLineObject::drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
QColor lineColor = mLineColorNode.color( record, variables );
|
||||
QColor shadowColor = mShadowColorNode.color( record, variables );
|
||||
|
||||
shadowColor.setAlphaF( mShadowOpacity );
|
||||
|
||||
if ( lineColor.alpha() )
|
||||
{
|
||||
painter->setPen( QPen( shadowColor, mLineWidth.pt() ) );
|
||||
painter->drawLine( 0, 0, mW.pt(), mH.pt() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw object itself
|
||||
///
|
||||
void ModelLineObject::drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
QColor lineColor = mLineColorNode.color( record, variables );
|
||||
|
||||
painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
|
||||
painter->drawLine( 0, 0, mW.pt(), mH.pt() );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Path to test for hover condition
|
||||
///
|
||||
QPainterPath ModelLineObject::hoverPath( double scale ) const
|
||||
{
|
||||
QPainterPath path;
|
||||
|
||||
if ( mLineColorNode.color().alpha() )
|
||||
{
|
||||
//
|
||||
// Build a thin rectangle representing line
|
||||
//
|
||||
double rPts = mLineWidth.pt()/2 + slopPixels / scale;
|
||||
|
||||
double lengthPts = sqrt( mW.pt()*mW.pt() + mH.pt()*mH.pt() );
|
||||
double dx = mH.pt() / lengthPts; // horizontal pitch of perpendicular line
|
||||
double dy = mW.pt() / lengthPts; // vertical pitch of perpendicular line
|
||||
|
||||
path.moveTo( rPts*dx, - rPts*dy );
|
||||
path.lineTo( mW.pt() + rPts*dx, mH.pt() - rPts*dy );
|
||||
path.lineTo( mW.pt() - rPts*dx, mH.pt() + rPts*dy );
|
||||
path.lineTo( - rPts*dx, rPts*dy );
|
||||
|
||||
path.closeSubpath();
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
const double slopPixels = 2;
|
||||
}
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelLineObject::ModelLineObject()
|
||||
{
|
||||
mHandles.push_back( Handle( this, Handle::P1 ) );
|
||||
mHandles.push_back( Handle( this, Handle::P2 ) );
|
||||
|
||||
mLineWidth = 1.0;
|
||||
mLineColorNode = ColorNode( QColor( 0, 0, 0 ) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelLineObject::ModelLineObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance dx,
|
||||
Distance dy,
|
||||
Distance lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const QTransform& matrix,
|
||||
bool shadowState,
|
||||
Distance shadowX,
|
||||
Distance shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: ModelObject( x0,
|
||||
y0,
|
||||
dx,
|
||||
dy,
|
||||
false /*lockAspectRatio*/,
|
||||
matrix,
|
||||
shadowState,
|
||||
shadowX,
|
||||
shadowY,
|
||||
shadowOpacity,
|
||||
shadowColorNode )
|
||||
{
|
||||
mHandles.push_back( Handle( this, Handle::P1 ) );
|
||||
mHandles.push_back( Handle( this, Handle::P2 ) );
|
||||
|
||||
mLineWidth = lineWidth;
|
||||
mLineColorNode = lineColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Copy constructor
|
||||
///
|
||||
ModelLineObject::ModelLineObject( const ModelLineObject* object )
|
||||
: ModelObject(object)
|
||||
{
|
||||
mLineWidth = object->mLineWidth;
|
||||
mLineColorNode = object->mLineColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clone
|
||||
///
|
||||
ModelLineObject* ModelLineObject::clone() const
|
||||
{
|
||||
return new ModelLineObject( this );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Width Property Getter
|
||||
///
|
||||
Distance ModelLineObject::lineWidth() const
|
||||
{
|
||||
return mLineWidth;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Width Property Setter
|
||||
///
|
||||
void ModelLineObject::setLineWidth( Distance value )
|
||||
{
|
||||
if ( mLineWidth != value )
|
||||
{
|
||||
mLineWidth = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Color Node Property Getter
|
||||
///
|
||||
ColorNode ModelLineObject::lineColorNode() const
|
||||
{
|
||||
return mLineColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Color Node Property Setter
|
||||
///
|
||||
void ModelLineObject::setLineColorNode( const ColorNode& value )
|
||||
{
|
||||
if ( mLineColorNode != value )
|
||||
{
|
||||
mLineColorNode = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Line Color Capability Implementation
|
||||
///
|
||||
bool ModelLineObject::canLineColor() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Line Width Capability Implementation
|
||||
///
|
||||
bool ModelLineObject::canLineWidth() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw shadow of object
|
||||
///
|
||||
void ModelLineObject::drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
QColor lineColor = mLineColorNode.color( record, variables );
|
||||
QColor shadowColor = mShadowColorNode.color( record, variables );
|
||||
|
||||
shadowColor.setAlphaF( mShadowOpacity );
|
||||
|
||||
if ( lineColor.alpha() )
|
||||
{
|
||||
painter->setPen( QPen( shadowColor, mLineWidth.pt() ) );
|
||||
painter->drawLine( 0, 0, mW.pt(), mH.pt() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw object itself
|
||||
///
|
||||
void ModelLineObject::drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const
|
||||
{
|
||||
QColor lineColor = mLineColorNode.color( record, variables );
|
||||
|
||||
painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
|
||||
painter->drawLine( 0, 0, mW.pt(), mH.pt() );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Path to test for hover condition
|
||||
///
|
||||
QPainterPath ModelLineObject::hoverPath( double scale ) const
|
||||
{
|
||||
QPainterPath path;
|
||||
|
||||
if ( mLineColorNode.color().alpha() )
|
||||
{
|
||||
//
|
||||
// Build a thin rectangle representing line
|
||||
//
|
||||
double rPts = mLineWidth.pt()/2 + slopPixels / scale;
|
||||
|
||||
double lengthPts = sqrt( mW.pt()*mW.pt() + mH.pt()*mH.pt() );
|
||||
double dx = mH.pt() / lengthPts; // horizontal pitch of perpendicular line
|
||||
double dy = mW.pt() / lengthPts; // vertical pitch of perpendicular line
|
||||
|
||||
path.moveTo( rPts*dx, - rPts*dy );
|
||||
path.lineTo( mW.pt() + rPts*dx, mH.pt() - rPts*dy );
|
||||
path.lineTo( mW.pt() - rPts*dx, mH.pt() + rPts*dy );
|
||||
path.lineTo( - rPts*dx, rPts*dy );
|
||||
|
||||
path.closeSubpath();
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
/* ModelLineObject.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_ModelLineObject_h
|
||||
#define model_ModelLineObject_h
|
||||
|
||||
|
||||
#include "ModelObject.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Line Object
|
||||
///
|
||||
class ModelLineObject : public ModelObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
ModelLineObject();
|
||||
|
||||
ModelLineObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
Distance lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const QTransform& matrix = QTransform(),
|
||||
bool shadowState = false,
|
||||
Distance shadowX = 0,
|
||||
Distance shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
ModelLineObject( const ModelLineObject* object );
|
||||
|
||||
virtual ~ModelLineObject() = default;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
ModelLineObject* clone() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Property Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Line Property: lineWidth
|
||||
//
|
||||
Distance lineWidth() const override;
|
||||
void setLineWidth( Distance value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Line Property: lineColorNode
|
||||
//
|
||||
ColorNode lineColorNode() const override;
|
||||
void setLineColorNode( const ColorNode& value ) override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capability Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
bool canLineColor() const override;
|
||||
bool canLineWidth() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
void drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
void drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
QPainterPath hoverPath( double scale ) const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
Distance mLineWidth;
|
||||
ColorNode mLineColorNode;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ModelLineObject_h
|
||||
@@ -0,0 +1,123 @@
|
||||
// ModelLineObject.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_ModelLineObject_hpp
|
||||
#define model_ModelLineObject_hpp
|
||||
|
||||
|
||||
#include "ModelObject.hpp"
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Line Object
|
||||
///
|
||||
class ModelLineObject : public ModelObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
ModelLineObject();
|
||||
|
||||
ModelLineObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
Distance lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const QTransform& matrix = QTransform(),
|
||||
bool shadowState = false,
|
||||
Distance shadowX = 0,
|
||||
Distance shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
ModelLineObject( const ModelLineObject* object );
|
||||
|
||||
virtual ~ModelLineObject() = default;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
ModelLineObject* clone() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Property Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Line Property: lineWidth
|
||||
//
|
||||
Distance lineWidth() const override;
|
||||
void setLineWidth( Distance value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Line Property: lineColorNode
|
||||
//
|
||||
ColorNode lineColorNode() const override;
|
||||
void setLineColorNode( const ColorNode& value ) override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capability Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
bool canLineColor() const override;
|
||||
bool canLineWidth() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
void drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
void drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
QPainterPath hoverPath( double scale ) const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
Distance mLineWidth;
|
||||
ColorNode mLineColorNode;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ModelLineObject_hpp
|
||||
+1262
-1265
File diff suppressed because it is too large
Load Diff
@@ -1,479 +0,0 @@
|
||||
/* ModelObject.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_ModelObject_h
|
||||
#define model_ModelObject_h
|
||||
|
||||
|
||||
#include "ColorNode.h"
|
||||
#include "Distance.h"
|
||||
#include "Handle.h"
|
||||
#include "Outline.h"
|
||||
#include "TextNode.h"
|
||||
#include "Variables.h"
|
||||
|
||||
#include "barcode/Style.h"
|
||||
#include "merge/Record.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QFont>
|
||||
#include <QTransform>
|
||||
#include <QPainter>
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
// Forward References
|
||||
class Region;
|
||||
class Size;
|
||||
|
||||
|
||||
///
|
||||
/// Label Model Object Base Class
|
||||
///
|
||||
class ModelObject : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
ModelObject();
|
||||
|
||||
ModelObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio = false,
|
||||
const QTransform& matrix = QTransform(),
|
||||
bool shadowState = false,
|
||||
Distance shadowX = 0,
|
||||
Distance shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
ModelObject( const ModelObject* object );
|
||||
|
||||
public:
|
||||
virtual ~ModelObject() = default;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
virtual ModelObject* clone() const = 0;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Signals
|
||||
///////////////////////////////////////////////////////////////
|
||||
signals:
|
||||
void moved();
|
||||
void changed();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Common Properties
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// ID Property.
|
||||
//
|
||||
int id() const;
|
||||
|
||||
//
|
||||
// Selected Property.
|
||||
//
|
||||
bool isSelected() const;
|
||||
void select( bool value = true );
|
||||
void unselect();
|
||||
|
||||
|
||||
//
|
||||
// x0 Property ( x coordinate of origin )
|
||||
//
|
||||
Distance x0() const;
|
||||
void setX0( Distance value );
|
||||
|
||||
|
||||
//
|
||||
// y0 Property ( y coordinate of origin )
|
||||
//
|
||||
Distance y0() const;
|
||||
void setY0( Distance value );
|
||||
|
||||
|
||||
//
|
||||
// w Property ( width of bounding box )
|
||||
//
|
||||
Distance w() const;
|
||||
void setW( Distance value );
|
||||
|
||||
|
||||
//
|
||||
// h Property ( height of bounding box )
|
||||
//
|
||||
Distance h() const;
|
||||
void setH( Distance value );
|
||||
|
||||
|
||||
//
|
||||
// Lock Aspect Ratio Property
|
||||
//
|
||||
bool lockAspectRatio() const;
|
||||
void setLockAspectRatio( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Transformation Matrix Property
|
||||
//
|
||||
QTransform matrix() const;
|
||||
void setMatrix( const QTransform& value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow State Property
|
||||
//
|
||||
bool shadow() const;
|
||||
void setShadow( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow x Offset Property
|
||||
//
|
||||
Distance shadowX() const;
|
||||
void setShadowX( Distance value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow y Offset Property
|
||||
//
|
||||
Distance shadowY() const;
|
||||
void setShadowY( Distance value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow opacity Property
|
||||
//
|
||||
double shadowOpacity() const;
|
||||
void setShadowOpacity( double value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow Color Property
|
||||
//
|
||||
ColorNode shadowColorNode() const;
|
||||
void setShadowColorNode( const ColorNode& value );
|
||||
|
||||
|
||||
//
|
||||
// Natural Size Property (read-only)
|
||||
//
|
||||
virtual Size naturalSize() const;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Text Properties Virtual Interface
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Virtual Text Property: text
|
||||
//
|
||||
virtual QString text() const;
|
||||
virtual void setText( const QString &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontFamily
|
||||
//
|
||||
virtual QString fontFamily() const;
|
||||
virtual void setFontFamily( const QString &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontSize
|
||||
//
|
||||
virtual double fontSize() const;
|
||||
virtual void setFontSize( double value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontWeight
|
||||
//
|
||||
virtual QFont::Weight fontWeight() const;
|
||||
virtual void setFontWeight( QFont::Weight value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontItalicFlag
|
||||
//
|
||||
virtual bool fontItalicFlag() const;
|
||||
virtual void setFontItalicFlag( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontUnderlineFlag
|
||||
//
|
||||
virtual bool fontUnderlineFlag() const;
|
||||
virtual void setFontUnderlineFlag( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textColorNode
|
||||
//
|
||||
virtual ColorNode textColorNode() const;
|
||||
virtual void setTextColorNode( const ColorNode &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textHAlign
|
||||
//
|
||||
virtual Qt::Alignment textHAlign() const;
|
||||
virtual void setTextHAlign( Qt::Alignment value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textVAlign
|
||||
//
|
||||
virtual Qt::Alignment textVAlign() const;
|
||||
virtual void setTextVAlign( Qt::Alignment value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textWrapMode
|
||||
//
|
||||
virtual QTextOption::WrapMode textWrapMode() const;
|
||||
virtual void setTextWrapMode( QTextOption::WrapMode value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textLineSpacing
|
||||
//
|
||||
virtual double textLineSpacing() const;
|
||||
virtual void setTextLineSpacing( double value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textAutoShrink
|
||||
//
|
||||
virtual bool textAutoShrink() const;
|
||||
virtual void setTextAutoShrink( bool value );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Image Properties Virtual Interface
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Virtual Image Property: filenameNode
|
||||
//
|
||||
virtual TextNode filenameNode() const;
|
||||
virtual void setFilenameNode( const TextNode &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Image Property: image
|
||||
//
|
||||
virtual const QImage& image() const;
|
||||
virtual void setImage( const QImage& value );
|
||||
virtual void setImage( const QString& name, const QImage& value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Image Property: svg
|
||||
//
|
||||
virtual const QByteArray& svg() const;
|
||||
virtual void setSvg( const QString& name, const QByteArray& value );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Shape Properties Virtual Interface
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Virtual Shape Property: lineWidth
|
||||
//
|
||||
virtual Distance lineWidth() const;
|
||||
virtual void setLineWidth( Distance value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Shape Property: lineColorNode
|
||||
//
|
||||
virtual ColorNode lineColorNode() const;
|
||||
virtual void setLineColorNode( const ColorNode &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Shape Property: fillColorNode
|
||||
//
|
||||
virtual ColorNode fillColorNode() const;
|
||||
virtual void setFillColorNode( const ColorNode &value );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Barcode Properties Virtual Interface
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Virtual Barcode Property: bcData
|
||||
//
|
||||
virtual QString bcData() const;
|
||||
virtual void setBcData( const QString& value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcTextFlag
|
||||
//
|
||||
virtual bool bcTextFlag() const;
|
||||
virtual void setBcTextFlag( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcChecksumFlag
|
||||
//
|
||||
virtual bool bcChecksumFlag() const;
|
||||
virtual void setBcChecksumFlag( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcColorNode
|
||||
//
|
||||
virtual ColorNode bcColorNode() const;
|
||||
virtual void setBcColorNode( const ColorNode &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcStyle
|
||||
//
|
||||
virtual barcode::Style bcStyle() const;
|
||||
virtual void setBcStyle( const barcode::Style &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcFormatDigits
|
||||
//
|
||||
virtual int bcFormatDigits() const;
|
||||
virtual void setBcFormatDigits( int value );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capabilities (Overridden by concrete classes.)
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
virtual bool canText() const;
|
||||
virtual bool canFill() const;
|
||||
virtual bool canLineColor() const;
|
||||
virtual bool canLineWidth() const;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Position and Size methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
void setPosition( Distance x0, Distance y0 );
|
||||
void setPositionRelative( Distance dx, Distance dy );
|
||||
Size size() const;
|
||||
void setSize( Distance w, Distance h );
|
||||
void setSize( Size size );
|
||||
void setSizeHonorAspect( Distance w, Distance h );
|
||||
void setWHonorAspect( Distance w );
|
||||
void setHHonorAspect( Distance h );
|
||||
Region getExtent();
|
||||
void rotate( double thetaDegs );
|
||||
void flipHoriz();
|
||||
void flipVert();
|
||||
bool isLocatedAt( double scale, Distance x, Distance y ) const;
|
||||
const Handle& handleAt( double scale, Distance x, Distance y ) const;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const;
|
||||
|
||||
void drawSelectionHighlight( QPainter* painter, double scale ) const;
|
||||
|
||||
protected:
|
||||
virtual void drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const = 0;
|
||||
|
||||
virtual void drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const = 0;
|
||||
|
||||
virtual QPainterPath hoverPath( double scale ) const = 0;
|
||||
|
||||
virtual void sizeUpdated();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Protected Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
bool mSelectedFlag;
|
||||
|
||||
Distance mX0;
|
||||
Distance mY0;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
bool mLockAspectRatio;
|
||||
|
||||
bool mShadowState;
|
||||
Distance mShadowX;
|
||||
Distance mShadowY;
|
||||
double mShadowOpacity;
|
||||
ColorNode mShadowColorNode;
|
||||
|
||||
Outline mOutline;
|
||||
|
||||
QList<Handle> mHandles;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
static int msNextId;
|
||||
int mId;
|
||||
|
||||
QTransform mMatrix;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ModelObject_h
|
||||
@@ -0,0 +1,476 @@
|
||||
// ModelObject.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_ModelObject_hpp
|
||||
#define model_ModelObject_hpp
|
||||
|
||||
|
||||
#include "ColorNode.hpp"
|
||||
#include "Distance.hpp"
|
||||
#include "Handle.hpp"
|
||||
#include "Outline.hpp"
|
||||
#include "TextNode.hpp"
|
||||
#include "Variables.hpp"
|
||||
|
||||
#include "barcode/Style.hpp"
|
||||
#include "merge/Record.hpp"
|
||||
|
||||
#include <QObject>
|
||||
#include <QFont>
|
||||
#include <QTransform>
|
||||
#include <QPainter>
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
// Forward References
|
||||
class Region;
|
||||
class Size;
|
||||
|
||||
|
||||
///
|
||||
/// Label Model Object Base Class
|
||||
///
|
||||
class ModelObject : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
ModelObject();
|
||||
|
||||
ModelObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio = false,
|
||||
const QTransform& matrix = QTransform(),
|
||||
bool shadowState = false,
|
||||
Distance shadowX = 0,
|
||||
Distance shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
ModelObject( const ModelObject* object );
|
||||
|
||||
public:
|
||||
virtual ~ModelObject() = default;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
virtual ModelObject* clone() const = 0;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Signals
|
||||
///////////////////////////////////////////////////////////////
|
||||
signals:
|
||||
void moved();
|
||||
void changed();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Common Properties
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// ID Property.
|
||||
//
|
||||
int id() const;
|
||||
|
||||
//
|
||||
// Selected Property.
|
||||
//
|
||||
bool isSelected() const;
|
||||
void select( bool value = true );
|
||||
void unselect();
|
||||
|
||||
|
||||
//
|
||||
// x0 Property ( x coordinate of origin )
|
||||
//
|
||||
Distance x0() const;
|
||||
void setX0( Distance value );
|
||||
|
||||
|
||||
//
|
||||
// y0 Property ( y coordinate of origin )
|
||||
//
|
||||
Distance y0() const;
|
||||
void setY0( Distance value );
|
||||
|
||||
|
||||
//
|
||||
// w Property ( width of bounding box )
|
||||
//
|
||||
Distance w() const;
|
||||
void setW( Distance value );
|
||||
|
||||
|
||||
//
|
||||
// h Property ( height of bounding box )
|
||||
//
|
||||
Distance h() const;
|
||||
void setH( Distance value );
|
||||
|
||||
|
||||
//
|
||||
// Lock Aspect Ratio Property
|
||||
//
|
||||
bool lockAspectRatio() const;
|
||||
void setLockAspectRatio( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Transformation Matrix Property
|
||||
//
|
||||
QTransform matrix() const;
|
||||
void setMatrix( const QTransform& value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow State Property
|
||||
//
|
||||
bool shadow() const;
|
||||
void setShadow( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow x Offset Property
|
||||
//
|
||||
Distance shadowX() const;
|
||||
void setShadowX( Distance value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow y Offset Property
|
||||
//
|
||||
Distance shadowY() const;
|
||||
void setShadowY( Distance value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow opacity Property
|
||||
//
|
||||
double shadowOpacity() const;
|
||||
void setShadowOpacity( double value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow Color Property
|
||||
//
|
||||
ColorNode shadowColorNode() const;
|
||||
void setShadowColorNode( const ColorNode& value );
|
||||
|
||||
|
||||
//
|
||||
// Natural Size Property (read-only)
|
||||
//
|
||||
virtual Size naturalSize() const;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Text Properties Virtual Interface
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Virtual Text Property: text
|
||||
//
|
||||
virtual QString text() const;
|
||||
virtual void setText( const QString &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontFamily
|
||||
//
|
||||
virtual QString fontFamily() const;
|
||||
virtual void setFontFamily( const QString &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontSize
|
||||
//
|
||||
virtual double fontSize() const;
|
||||
virtual void setFontSize( double value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontWeight
|
||||
//
|
||||
virtual QFont::Weight fontWeight() const;
|
||||
virtual void setFontWeight( QFont::Weight value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontItalicFlag
|
||||
//
|
||||
virtual bool fontItalicFlag() const;
|
||||
virtual void setFontItalicFlag( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontUnderlineFlag
|
||||
//
|
||||
virtual bool fontUnderlineFlag() const;
|
||||
virtual void setFontUnderlineFlag( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textColorNode
|
||||
//
|
||||
virtual ColorNode textColorNode() const;
|
||||
virtual void setTextColorNode( const ColorNode &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textHAlign
|
||||
//
|
||||
virtual Qt::Alignment textHAlign() const;
|
||||
virtual void setTextHAlign( Qt::Alignment value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textVAlign
|
||||
//
|
||||
virtual Qt::Alignment textVAlign() const;
|
||||
virtual void setTextVAlign( Qt::Alignment value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textWrapMode
|
||||
//
|
||||
virtual QTextOption::WrapMode textWrapMode() const;
|
||||
virtual void setTextWrapMode( QTextOption::WrapMode value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textLineSpacing
|
||||
//
|
||||
virtual double textLineSpacing() const;
|
||||
virtual void setTextLineSpacing( double value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textAutoShrink
|
||||
//
|
||||
virtual bool textAutoShrink() const;
|
||||
virtual void setTextAutoShrink( bool value );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Image Properties Virtual Interface
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Virtual Image Property: filenameNode
|
||||
//
|
||||
virtual TextNode filenameNode() const;
|
||||
virtual void setFilenameNode( const TextNode &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Image Property: image
|
||||
//
|
||||
virtual const QImage& image() const;
|
||||
virtual void setImage( const QImage& value );
|
||||
virtual void setImage( const QString& name, const QImage& value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Image Property: svg
|
||||
//
|
||||
virtual const QByteArray& svg() const;
|
||||
virtual void setSvg( const QString& name, const QByteArray& value );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Shape Properties Virtual Interface
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Virtual Shape Property: lineWidth
|
||||
//
|
||||
virtual Distance lineWidth() const;
|
||||
virtual void setLineWidth( Distance value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Shape Property: lineColorNode
|
||||
//
|
||||
virtual ColorNode lineColorNode() const;
|
||||
virtual void setLineColorNode( const ColorNode &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Shape Property: fillColorNode
|
||||
//
|
||||
virtual ColorNode fillColorNode() const;
|
||||
virtual void setFillColorNode( const ColorNode &value );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Barcode Properties Virtual Interface
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Virtual Barcode Property: bcData
|
||||
//
|
||||
virtual QString bcData() const;
|
||||
virtual void setBcData( const QString& value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcTextFlag
|
||||
//
|
||||
virtual bool bcTextFlag() const;
|
||||
virtual void setBcTextFlag( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcChecksumFlag
|
||||
//
|
||||
virtual bool bcChecksumFlag() const;
|
||||
virtual void setBcChecksumFlag( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcColorNode
|
||||
//
|
||||
virtual ColorNode bcColorNode() const;
|
||||
virtual void setBcColorNode( const ColorNode &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcStyle
|
||||
//
|
||||
virtual barcode::Style bcStyle() const;
|
||||
virtual void setBcStyle( const barcode::Style &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcFormatDigits
|
||||
//
|
||||
virtual int bcFormatDigits() const;
|
||||
virtual void setBcFormatDigits( int value );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capabilities (Overridden by concrete classes.)
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
virtual bool canText() const;
|
||||
virtual bool canFill() const;
|
||||
virtual bool canLineColor() const;
|
||||
virtual bool canLineWidth() const;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Position and Size methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
void setPosition( Distance x0, Distance y0 );
|
||||
void setPositionRelative( Distance dx, Distance dy );
|
||||
Size size() const;
|
||||
void setSize( Distance w, Distance h );
|
||||
void setSize( Size size );
|
||||
void setSizeHonorAspect( Distance w, Distance h );
|
||||
void setWHonorAspect( Distance w );
|
||||
void setHHonorAspect( Distance h );
|
||||
Region getExtent();
|
||||
void rotate( double thetaDegs );
|
||||
void flipHoriz();
|
||||
void flipVert();
|
||||
bool isLocatedAt( double scale, Distance x, Distance y ) const;
|
||||
const Handle& handleAt( double scale, Distance x, Distance y ) const;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const;
|
||||
|
||||
void drawSelectionHighlight( QPainter* painter, double scale ) const;
|
||||
|
||||
protected:
|
||||
virtual void drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const = 0;
|
||||
|
||||
virtual void drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const = 0;
|
||||
|
||||
virtual QPainterPath hoverPath( double scale ) const = 0;
|
||||
|
||||
virtual void sizeUpdated();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Protected Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
bool mSelectedFlag;
|
||||
|
||||
Distance mX0;
|
||||
Distance mY0;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
bool mLockAspectRatio;
|
||||
|
||||
bool mShadowState;
|
||||
Distance mShadowX;
|
||||
Distance mShadowY;
|
||||
double mShadowOpacity;
|
||||
ColorNode mShadowColorNode;
|
||||
|
||||
Outline mOutline;
|
||||
|
||||
QList<Handle> mHandles;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
static int msNextId;
|
||||
int mId;
|
||||
|
||||
QTransform mMatrix;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ModelObject_hpp
|
||||
+172
-174
@@ -1,204 +1,202 @@
|
||||
/* ModelShapeObject.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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/>.
|
||||
*/
|
||||
// ModelShapeObject.cpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 "ModelShapeObject.h"
|
||||
|
||||
#include "ModelShapeObject.hpp"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QPen>
|
||||
|
||||
|
||||
namespace glabels
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelShapeObject::ModelShapeObject()
|
||||
{
|
||||
mOutline.setOwner( this );
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelShapeObject::ModelShapeObject()
|
||||
{
|
||||
mOutline.setOwner( this );
|
||||
|
||||
mHandles.push_back( Handle( this, Handle::NW ) );
|
||||
mHandles.push_back( Handle( this, Handle::N ) );
|
||||
mHandles.push_back( Handle( this, Handle::NE ) );
|
||||
mHandles.push_back( Handle( this, Handle::E ) );
|
||||
mHandles.push_back( Handle( this, Handle::SE ) );
|
||||
mHandles.push_back( Handle( this, Handle::S ) );
|
||||
mHandles.push_back( Handle( this, Handle::SW ) );
|
||||
mHandles.push_back( Handle( this, Handle::W ) );
|
||||
mHandles.push_back( Handle( this, Handle::NW ) );
|
||||
mHandles.push_back( Handle( this, Handle::N ) );
|
||||
mHandles.push_back( Handle( this, Handle::NE ) );
|
||||
mHandles.push_back( Handle( this, Handle::E ) );
|
||||
mHandles.push_back( Handle( this, Handle::SE ) );
|
||||
mHandles.push_back( Handle( this, Handle::S ) );
|
||||
mHandles.push_back( Handle( this, Handle::SW ) );
|
||||
mHandles.push_back( Handle( this, Handle::W ) );
|
||||
|
||||
mLineWidth = 1.0;
|
||||
mLineColorNode = ColorNode( QColor( 0, 0, 0 ) );
|
||||
mFillColorNode = ColorNode( QColor( 0, 255, 0 ) );
|
||||
}
|
||||
mLineWidth = 1.0;
|
||||
mLineColorNode = ColorNode( QColor( 0, 0, 0 ) );
|
||||
mFillColorNode = ColorNode( QColor( 0, 255, 0 ) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelShapeObject::ModelShapeObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
Distance lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
const QTransform& matrix,
|
||||
bool shadowState,
|
||||
Distance shadowX,
|
||||
Distance shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: ModelObject( x0,
|
||||
y0,
|
||||
w,
|
||||
h,
|
||||
lockAspectRatio,
|
||||
matrix,
|
||||
shadowState,
|
||||
shadowX,
|
||||
shadowY,
|
||||
shadowOpacity,
|
||||
shadowColorNode )
|
||||
{
|
||||
mOutline.setOwner( this );
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelShapeObject::ModelShapeObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
Distance lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
const QTransform& matrix,
|
||||
bool shadowState,
|
||||
Distance shadowX,
|
||||
Distance shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: ModelObject( x0,
|
||||
y0,
|
||||
w,
|
||||
h,
|
||||
lockAspectRatio,
|
||||
matrix,
|
||||
shadowState,
|
||||
shadowX,
|
||||
shadowY,
|
||||
shadowOpacity,
|
||||
shadowColorNode )
|
||||
{
|
||||
mOutline.setOwner( this );
|
||||
|
||||
mHandles.push_back( Handle( this, Handle::NW ) );
|
||||
mHandles.push_back( Handle( this, Handle::N ) );
|
||||
mHandles.push_back( Handle( this, Handle::NE ) );
|
||||
mHandles.push_back( Handle( this, Handle::E ) );
|
||||
mHandles.push_back( Handle( this, Handle::SE ) );
|
||||
mHandles.push_back( Handle( this, Handle::S ) );
|
||||
mHandles.push_back( Handle( this, Handle::SW ) );
|
||||
mHandles.push_back( Handle( this, Handle::W ) );
|
||||
mHandles.push_back( Handle( this, Handle::NW ) );
|
||||
mHandles.push_back( Handle( this, Handle::N ) );
|
||||
mHandles.push_back( Handle( this, Handle::NE ) );
|
||||
mHandles.push_back( Handle( this, Handle::E ) );
|
||||
mHandles.push_back( Handle( this, Handle::SE ) );
|
||||
mHandles.push_back( Handle( this, Handle::S ) );
|
||||
mHandles.push_back( Handle( this, Handle::SW ) );
|
||||
mHandles.push_back( Handle( this, Handle::W ) );
|
||||
|
||||
mLineWidth = lineWidth;
|
||||
mLineColorNode = lineColorNode;
|
||||
mFillColorNode = fillColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Copy constructor
|
||||
///
|
||||
ModelShapeObject::ModelShapeObject( const ModelShapeObject* object ) : ModelObject(object)
|
||||
{
|
||||
mLineWidth = object->mLineWidth;
|
||||
mLineColorNode = object->mLineColorNode;
|
||||
mFillColorNode = object->mFillColorNode;
|
||||
}
|
||||
mLineWidth = lineWidth;
|
||||
mLineColorNode = lineColorNode;
|
||||
mFillColorNode = fillColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Width Property Getter
|
||||
///
|
||||
Distance ModelShapeObject::lineWidth() const
|
||||
{
|
||||
return mLineWidth;
|
||||
}
|
||||
///
|
||||
/// Copy constructor
|
||||
///
|
||||
ModelShapeObject::ModelShapeObject( const ModelShapeObject* object ) : ModelObject(object)
|
||||
{
|
||||
mLineWidth = object->mLineWidth;
|
||||
mLineColorNode = object->mLineColorNode;
|
||||
mFillColorNode = object->mFillColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Width Property Setter
|
||||
///
|
||||
void ModelShapeObject::setLineWidth( Distance value )
|
||||
{
|
||||
if ( mLineWidth != value )
|
||||
{
|
||||
mLineWidth = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
///
|
||||
/// Line Width Property Getter
|
||||
///
|
||||
Distance ModelShapeObject::lineWidth() const
|
||||
{
|
||||
return mLineWidth;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Color Node Property Getter
|
||||
///
|
||||
ColorNode ModelShapeObject::lineColorNode() const
|
||||
{
|
||||
return mLineColorNode;
|
||||
}
|
||||
///
|
||||
/// Line Width Property Setter
|
||||
///
|
||||
void ModelShapeObject::setLineWidth( Distance value )
|
||||
{
|
||||
if ( mLineWidth != value )
|
||||
{
|
||||
mLineWidth = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Color Node Property Setter
|
||||
///
|
||||
void ModelShapeObject::setLineColorNode( const ColorNode& value )
|
||||
{
|
||||
if ( mLineColorNode != value )
|
||||
{
|
||||
mLineColorNode = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Fill Color Node Property Getter
|
||||
///
|
||||
ColorNode ModelShapeObject::fillColorNode() const
|
||||
{
|
||||
return mFillColorNode;
|
||||
}
|
||||
///
|
||||
/// Line Color Node Property Getter
|
||||
///
|
||||
ColorNode ModelShapeObject::lineColorNode() const
|
||||
{
|
||||
return mLineColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Fill Color Node Property Setter
|
||||
///
|
||||
void ModelShapeObject::setFillColorNode( const ColorNode& value )
|
||||
{
|
||||
if ( mFillColorNode != value )
|
||||
{
|
||||
mFillColorNode = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Fill Capability Implementation
|
||||
///
|
||||
bool ModelShapeObject::canFill() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
///
|
||||
/// Line Color Node Property Setter
|
||||
///
|
||||
void ModelShapeObject::setLineColorNode( const ColorNode& value )
|
||||
{
|
||||
if ( mLineColorNode != value )
|
||||
{
|
||||
mLineColorNode = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Line Color Capability Implementation
|
||||
///
|
||||
bool ModelShapeObject::canLineColor() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
///
|
||||
/// Fill Color Node Property Getter
|
||||
///
|
||||
ColorNode ModelShapeObject::fillColorNode() const
|
||||
{
|
||||
return mFillColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Line Width Capability Implementation
|
||||
///
|
||||
bool ModelShapeObject::canLineWidth() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
///
|
||||
/// Fill Color Node Property Setter
|
||||
///
|
||||
void ModelShapeObject::setFillColorNode( const ColorNode& value )
|
||||
{
|
||||
if ( mFillColorNode != value )
|
||||
{
|
||||
mFillColorNode = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Fill Capability Implementation
|
||||
///
|
||||
bool ModelShapeObject::canFill() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Line Color Capability Implementation
|
||||
///
|
||||
bool ModelShapeObject::canLineColor() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Line Width Capability Implementation
|
||||
///
|
||||
bool ModelShapeObject::canLineWidth() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
/* ModelShapeObject.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_ModelShapeObject_h
|
||||
#define model_ModelShapeObject_h
|
||||
|
||||
|
||||
#include "ModelObject.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Shape Object (Box or Ellipse)
|
||||
///
|
||||
class ModelShapeObject : public ModelObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
ModelShapeObject();
|
||||
|
||||
ModelShapeObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
Distance lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
const QTransform& matrix,
|
||||
bool shadowState,
|
||||
Distance shadowX,
|
||||
Distance shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode );
|
||||
|
||||
ModelShapeObject( const ModelShapeObject* object );
|
||||
public:
|
||||
virtual ~ModelShapeObject() = default;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Property Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Shape Property: lineWidth
|
||||
//
|
||||
Distance lineWidth() const override;
|
||||
void setLineWidth( Distance value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Shape Property: lineColorNode
|
||||
//
|
||||
ColorNode lineColorNode() const override;
|
||||
void setLineColorNode( const ColorNode& value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Shape Property: fillColorNode
|
||||
//
|
||||
ColorNode fillColorNode() const override;
|
||||
void setFillColorNode( const ColorNode& value ) override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capability Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
bool canFill() const override;
|
||||
bool canLineColor() const override;
|
||||
bool canLineWidth() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
Distance mLineWidth;
|
||||
ColorNode mLineColorNode;
|
||||
ColorNode mFillColorNode;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ModelShapeObject_h
|
||||
@@ -0,0 +1,111 @@
|
||||
// ModelShapeObject.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_ModelShapeObject_hpp
|
||||
#define model_ModelShapeObject_hpp
|
||||
|
||||
|
||||
#include "ModelObject.hpp"
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Shape Object (Box or Ellipse)
|
||||
///
|
||||
class ModelShapeObject : public ModelObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
ModelShapeObject();
|
||||
|
||||
ModelShapeObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
Distance lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
const QTransform& matrix,
|
||||
bool shadowState,
|
||||
Distance shadowX,
|
||||
Distance shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode );
|
||||
|
||||
ModelShapeObject( const ModelShapeObject* object );
|
||||
public:
|
||||
virtual ~ModelShapeObject() = default;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Property Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Shape Property: lineWidth
|
||||
//
|
||||
Distance lineWidth() const override;
|
||||
void setLineWidth( Distance value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Shape Property: lineColorNode
|
||||
//
|
||||
ColorNode lineColorNode() const override;
|
||||
void setLineColorNode( const ColorNode& value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Shape Property: fillColorNode
|
||||
//
|
||||
ColorNode fillColorNode() const override;
|
||||
void setFillColorNode( const ColorNode& value ) override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capability Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
bool canFill() const override;
|
||||
bool canLineColor() const override;
|
||||
bool canLineWidth() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
Distance mLineWidth;
|
||||
ColorNode mLineColorNode;
|
||||
ColorNode mFillColorNode;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ModelShapeObject_hpp
|
||||
+853
-862
File diff suppressed because it is too large
Load Diff
@@ -1,247 +0,0 @@
|
||||
/* ModelTextObject.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_ModelTextObject_h
|
||||
#define model_ModelTextObject_h
|
||||
|
||||
|
||||
#include "ModelObject.h"
|
||||
#include "RawText.h"
|
||||
|
||||
#include <QTextLayout>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Line Object
|
||||
///
|
||||
class ModelTextObject : public ModelObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
ModelTextObject();
|
||||
|
||||
ModelTextObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
const QString& text,
|
||||
const QString& fontFamily,
|
||||
double fontSize,
|
||||
QFont::Weight fontWeight,
|
||||
bool fontItalicFlag,
|
||||
bool fontUnderlineFlag,
|
||||
ColorNode textColorNode,
|
||||
Qt::Alignment textHAlign,
|
||||
Qt::Alignment textVAlign,
|
||||
QTextOption::WrapMode textWrapMode,
|
||||
double textLineSpacing,
|
||||
bool textAutoShrink,
|
||||
const QTransform& matrix = QTransform(),
|
||||
bool shadowState = false,
|
||||
Distance shadowX = 0,
|
||||
Distance shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
ModelTextObject( const ModelTextObject* object );
|
||||
|
||||
virtual ~ModelTextObject();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
ModelTextObject* clone() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Property Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Text Property: text
|
||||
//
|
||||
QString text() const override;
|
||||
void setText( const QString &value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: fontFamily
|
||||
//
|
||||
QString fontFamily() const override;
|
||||
void setFontFamily( const QString &value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: fontSize
|
||||
//
|
||||
double fontSize() const override;
|
||||
void setFontSize( double value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: fontWeight
|
||||
//
|
||||
QFont::Weight fontWeight() const override;
|
||||
void setFontWeight( QFont::Weight value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: fontItalicFlag
|
||||
//
|
||||
bool fontItalicFlag() const override;
|
||||
void setFontItalicFlag( bool value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: fontUnderlineFlag
|
||||
//
|
||||
bool fontUnderlineFlag() const override;
|
||||
void setFontUnderlineFlag( bool value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: textColorNode
|
||||
//
|
||||
ColorNode textColorNode() const override;
|
||||
void setTextColorNode( const ColorNode &value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: textHAlign
|
||||
//
|
||||
Qt::Alignment textHAlign() const override;
|
||||
void setTextHAlign( Qt::Alignment value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: textVAlign
|
||||
//
|
||||
Qt::Alignment textVAlign() const override;
|
||||
void setTextVAlign( Qt::Alignment value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: textWrapMode
|
||||
//
|
||||
QTextOption::WrapMode textWrapMode() const override;
|
||||
void setTextWrapMode( QTextOption::WrapMode value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: textLineSpacing
|
||||
//
|
||||
double textLineSpacing() const override;
|
||||
void setTextLineSpacing( double value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: textAutoShrink
|
||||
//
|
||||
bool textAutoShrink() const override;
|
||||
void setTextAutoShrink( bool value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Property: naturalSize
|
||||
//
|
||||
Size naturalSize() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capability Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
bool canText() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
void drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
void drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
QPainterPath hoverPath( double scale ) const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
void sizeUpdated() override;
|
||||
void update();
|
||||
|
||||
void drawTextInEditor( QPainter* painter,
|
||||
const QColor& color ) const;
|
||||
|
||||
void drawText( QPainter* painter,
|
||||
const QColor& color,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const;
|
||||
|
||||
double autoShrinkFontSize( const merge::Record& record,
|
||||
const Variables& variables ) const;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
RawText mText;
|
||||
QString mFontFamily;
|
||||
double mFontSize;
|
||||
QFont::Weight mFontWeight;
|
||||
bool mFontItalicFlag;
|
||||
bool mFontUnderlineFlag;
|
||||
ColorNode mTextColorNode;
|
||||
Qt::Alignment mTextHAlign;
|
||||
Qt::Alignment mTextVAlign;
|
||||
QTextOption::WrapMode mTextWrapMode;
|
||||
double mTextLineSpacing;
|
||||
bool mTextAutoShrink;
|
||||
|
||||
QList<QTextLayout*> mEditorLayouts;
|
||||
QPainterPath mHoverPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ModelTextObject_h
|
||||
@@ -0,0 +1,244 @@
|
||||
// ModelTextObject.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_ModelTextObject_hpp
|
||||
#define model_ModelTextObject_hpp
|
||||
|
||||
|
||||
#include "ModelObject.hpp"
|
||||
#include "RawText.hpp"
|
||||
|
||||
#include <QTextLayout>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Line Object
|
||||
///
|
||||
class ModelTextObject : public ModelObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
ModelTextObject();
|
||||
|
||||
ModelTextObject( Distance x0,
|
||||
Distance y0,
|
||||
Distance w,
|
||||
Distance h,
|
||||
bool lockAspectRatio,
|
||||
const QString& text,
|
||||
const QString& fontFamily,
|
||||
double fontSize,
|
||||
QFont::Weight fontWeight,
|
||||
bool fontItalicFlag,
|
||||
bool fontUnderlineFlag,
|
||||
ColorNode textColorNode,
|
||||
Qt::Alignment textHAlign,
|
||||
Qt::Alignment textVAlign,
|
||||
QTextOption::WrapMode textWrapMode,
|
||||
double textLineSpacing,
|
||||
bool textAutoShrink,
|
||||
const QTransform& matrix = QTransform(),
|
||||
bool shadowState = false,
|
||||
Distance shadowX = 0,
|
||||
Distance shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
ModelTextObject( const ModelTextObject* object );
|
||||
|
||||
virtual ~ModelTextObject();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Object duplication
|
||||
///////////////////////////////////////////////////////////////
|
||||
ModelTextObject* clone() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Property Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Text Property: text
|
||||
//
|
||||
QString text() const override;
|
||||
void setText( const QString &value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: fontFamily
|
||||
//
|
||||
QString fontFamily() const override;
|
||||
void setFontFamily( const QString &value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: fontSize
|
||||
//
|
||||
double fontSize() const override;
|
||||
void setFontSize( double value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: fontWeight
|
||||
//
|
||||
QFont::Weight fontWeight() const override;
|
||||
void setFontWeight( QFont::Weight value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: fontItalicFlag
|
||||
//
|
||||
bool fontItalicFlag() const override;
|
||||
void setFontItalicFlag( bool value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: fontUnderlineFlag
|
||||
//
|
||||
bool fontUnderlineFlag() const override;
|
||||
void setFontUnderlineFlag( bool value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: textColorNode
|
||||
//
|
||||
ColorNode textColorNode() const override;
|
||||
void setTextColorNode( const ColorNode &value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: textHAlign
|
||||
//
|
||||
Qt::Alignment textHAlign() const override;
|
||||
void setTextHAlign( Qt::Alignment value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: textVAlign
|
||||
//
|
||||
Qt::Alignment textVAlign() const override;
|
||||
void setTextVAlign( Qt::Alignment value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: textWrapMode
|
||||
//
|
||||
QTextOption::WrapMode textWrapMode() const override;
|
||||
void setTextWrapMode( QTextOption::WrapMode value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: textLineSpacing
|
||||
//
|
||||
double textLineSpacing() const override;
|
||||
void setTextLineSpacing( double value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: textAutoShrink
|
||||
//
|
||||
bool textAutoShrink() const override;
|
||||
void setTextAutoShrink( bool value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Property: naturalSize
|
||||
//
|
||||
Size naturalSize() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capability Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
bool canText() const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
void drawShadow( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
void drawObject( QPainter* painter,
|
||||
bool inEditor,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const override;
|
||||
|
||||
QPainterPath hoverPath( double scale ) const override;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
void sizeUpdated() override;
|
||||
void update();
|
||||
|
||||
void drawTextInEditor( QPainter* painter,
|
||||
const QColor& color ) const;
|
||||
|
||||
void drawText( QPainter* painter,
|
||||
const QColor& color,
|
||||
const merge::Record& record,
|
||||
const Variables& variables ) const;
|
||||
|
||||
double autoShrinkFontSize( const merge::Record& record,
|
||||
const Variables& variables ) const;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
RawText mText;
|
||||
QString mFontFamily;
|
||||
double mFontSize;
|
||||
QFont::Weight mFontWeight;
|
||||
bool mFontItalicFlag;
|
||||
bool mFontUnderlineFlag;
|
||||
ColorNode mTextColorNode;
|
||||
Qt::Alignment mTextHAlign;
|
||||
Qt::Alignment mTextVAlign;
|
||||
QTextOption::WrapMode mTextWrapMode;
|
||||
double mTextLineSpacing;
|
||||
bool mTextAutoShrink;
|
||||
|
||||
QList<QTextLayout*> mEditorLayouts;
|
||||
QPainterPath mHoverPath;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ModelTextObject_hpp
|
||||
+113
-115
@@ -1,124 +1,122 @@
|
||||
/* Outline.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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/>.
|
||||
*/
|
||||
// Outline.cpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 "Outline.h"
|
||||
|
||||
#include "ModelObject.h"
|
||||
#include "Outline.hpp"
|
||||
|
||||
#include "ModelObject.hpp"
|
||||
|
||||
#include <QColor>
|
||||
|
||||
|
||||
namespace glabels
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
const qreal dashSize = 2;
|
||||
|
||||
const double slopPixels = 2;
|
||||
const double outlineWidthPixels = 1;
|
||||
const QColor outlineColor1( 0, 0, 0 );
|
||||
const QColor outlineColor2( 255, 255, 255 );
|
||||
}
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
///
|
||||
/// Set owner and enable outline
|
||||
///
|
||||
void Outline::setOwner( ModelObject* owner )
|
||||
{
|
||||
mOwner = owner;
|
||||
|
||||
mDashes << dashSize << dashSize;
|
||||
|
||||
mPen1.setColor( outlineColor1 );
|
||||
mPen1.setWidth( outlineWidthPixels );
|
||||
mPen1.setCosmetic( true );
|
||||
mPen1.setCapStyle( Qt::FlatCap );
|
||||
mPen1.setDashPattern( mDashes );
|
||||
|
||||
mPen2.setColor( outlineColor2 );
|
||||
mPen2.setWidth( outlineWidthPixels );
|
||||
mPen2.setCosmetic( true );
|
||||
mPen2.setCapStyle( Qt::FlatCap );
|
||||
mPen2.setDashPattern( mDashes );
|
||||
mPen2.setDashOffset( dashSize );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Is enabled? (I.e. not all objects have an outline (e.g. line objects))
|
||||
///
|
||||
bool Outline::isEnabled() const
|
||||
{
|
||||
return mOwner;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw Outline
|
||||
///
|
||||
void Outline::draw( QPainter* painter ) const
|
||||
{
|
||||
if ( mOwner )
|
||||
{
|
||||
painter->save();
|
||||
|
||||
painter->setBrush( Qt::NoBrush );
|
||||
|
||||
painter->setPen( mPen1 );
|
||||
painter->drawRect( QRectF( 0, 0, mOwner->w().pt(), mOwner->h().pt() ) );
|
||||
|
||||
painter->setPen( mPen2 );
|
||||
painter->drawRect( QRectF( 0, 0, mOwner->w().pt(), mOwner->h().pt() ) );
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Create path for testing for hover condition
|
||||
///
|
||||
QPainterPath Outline::hoverPath( double scale ) const
|
||||
{
|
||||
QPainterPath path;
|
||||
|
||||
if ( mOwner )
|
||||
{
|
||||
double s = 1 / scale;
|
||||
|
||||
path.addRect( -s*slopPixels, -s*slopPixels,
|
||||
mOwner->w().pt()+s*2*slopPixels, mOwner->h().pt()+s*2*slopPixels );
|
||||
path.closeSubpath();
|
||||
path.addRect( s*slopPixels, s*slopPixels,
|
||||
mOwner->w().pt()-s*2*slopPixels, mOwner->h().pt()-s*2*slopPixels );
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const qreal dashSize = 2;
|
||||
|
||||
const double slopPixels = 2;
|
||||
const double outlineWidthPixels = 1;
|
||||
const QColor outlineColor1( 0, 0, 0 );
|
||||
const QColor outlineColor2( 255, 255, 255 );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set owner and enable outline
|
||||
///
|
||||
void Outline::setOwner( ModelObject* owner )
|
||||
{
|
||||
mOwner = owner;
|
||||
|
||||
mDashes << dashSize << dashSize;
|
||||
|
||||
mPen1.setColor( outlineColor1 );
|
||||
mPen1.setWidth( outlineWidthPixels );
|
||||
mPen1.setCosmetic( true );
|
||||
mPen1.setCapStyle( Qt::FlatCap );
|
||||
mPen1.setDashPattern( mDashes );
|
||||
|
||||
mPen2.setColor( outlineColor2 );
|
||||
mPen2.setWidth( outlineWidthPixels );
|
||||
mPen2.setCosmetic( true );
|
||||
mPen2.setCapStyle( Qt::FlatCap );
|
||||
mPen2.setDashPattern( mDashes );
|
||||
mPen2.setDashOffset( dashSize );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Is enabled? (I.e. not all objects have an outline (e.g. line objects))
|
||||
///
|
||||
bool Outline::isEnabled() const
|
||||
{
|
||||
return mOwner;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw Outline
|
||||
///
|
||||
void Outline::draw( QPainter* painter ) const
|
||||
{
|
||||
if ( mOwner )
|
||||
{
|
||||
painter->save();
|
||||
|
||||
painter->setBrush( Qt::NoBrush );
|
||||
|
||||
painter->setPen( mPen1 );
|
||||
painter->drawRect( QRectF( 0, 0, mOwner->w().pt(), mOwner->h().pt() ) );
|
||||
|
||||
painter->setPen( mPen2 );
|
||||
painter->drawRect( QRectF( 0, 0, mOwner->w().pt(), mOwner->h().pt() ) );
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Create path for testing for hover condition
|
||||
///
|
||||
QPainterPath Outline::hoverPath( double scale ) const
|
||||
{
|
||||
QPainterPath path;
|
||||
|
||||
if ( mOwner )
|
||||
{
|
||||
double s = 1 / scale;
|
||||
|
||||
path.addRect( -s*slopPixels, -s*slopPixels,
|
||||
mOwner->w().pt()+s*2*slopPixels, mOwner->h().pt()+s*2*slopPixels );
|
||||
path.closeSubpath();
|
||||
path.addRect( s*slopPixels, s*slopPixels,
|
||||
mOwner->w().pt()-s*2*slopPixels, mOwner->h().pt()-s*2*slopPixels );
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
/* Outline.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_Outline_h
|
||||
#define model_Outline_h
|
||||
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
// Forward references
|
||||
class ModelObject;
|
||||
|
||||
|
||||
///
|
||||
/// Outline Class
|
||||
///
|
||||
class Outline
|
||||
{
|
||||
////////////////////////////
|
||||
// Lifecycle Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
Outline() = default;
|
||||
~Outline() = default;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Ownership
|
||||
////////////////////////////
|
||||
void setOwner( ModelObject* owner );
|
||||
bool isEnabled() const;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Drawing Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter ) const;
|
||||
QPainterPath hoverPath( double scale ) const;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Private Data
|
||||
////////////////////////////
|
||||
private:
|
||||
ModelObject* mOwner{ nullptr };
|
||||
|
||||
QVector<qreal> mDashes;
|
||||
QPen mPen1;
|
||||
QPen mPen2;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_Outline_h
|
||||
@@ -0,0 +1,81 @@
|
||||
// Outline.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_Outline_hpp
|
||||
#define model_Outline_hpp
|
||||
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
// Forward references
|
||||
class ModelObject;
|
||||
|
||||
|
||||
///
|
||||
/// Outline Class
|
||||
///
|
||||
class Outline
|
||||
{
|
||||
////////////////////////////
|
||||
// Lifecycle Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
Outline() = default;
|
||||
~Outline() = default;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Ownership
|
||||
////////////////////////////
|
||||
void setOwner( ModelObject* owner );
|
||||
bool isEnabled() const;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Drawing Methods
|
||||
////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter ) const;
|
||||
QPainterPath hoverPath( double scale ) const;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Private Data
|
||||
////////////////////////////
|
||||
private:
|
||||
ModelObject* mOwner{ nullptr };
|
||||
|
||||
QVector<qreal> mDashes;
|
||||
QPen mPen1;
|
||||
QPen mPen2;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_Outline_hpp
|
||||
+591
-593
File diff suppressed because it is too large
Load Diff
@@ -1,144 +0,0 @@
|
||||
/* PageRenderer.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_PageRenderer_h
|
||||
#define model_PageRenderer_h
|
||||
|
||||
|
||||
#include "Point.h"
|
||||
#include "Variables.h"
|
||||
|
||||
#include "merge/Merge.h"
|
||||
#include "merge/Record.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPrinter>
|
||||
#include <QRect>
|
||||
#include <QVector>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
// Forward references
|
||||
class Model;
|
||||
|
||||
|
||||
///
|
||||
/// PageRenderer Widget
|
||||
///
|
||||
class PageRenderer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
PageRenderer( const Model* model = nullptr );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Public Methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void setModel( const Model* model );
|
||||
const Model* model() const;
|
||||
void setNCopies( int nCopies );
|
||||
void setStartItem( int startItem );
|
||||
void setIsCollated( bool isCollated );
|
||||
void setAreGroupsContiguous( bool areGroupscontiguous );
|
||||
void setPrintOutlines( bool printOutlinesFlag );
|
||||
void setPrintCropMarks( bool printCropMarksFlag );
|
||||
void setPrintReverse( bool printReverseFlag );
|
||||
void setIPage( int iPage );
|
||||
int nItems() const;
|
||||
int nPages() const;
|
||||
QRectF pageRect() const;
|
||||
void print( QPrinter* printer ) const;
|
||||
void printPage( QPainter* painter ) const;
|
||||
void printPage( QPainter* painter, int iPage ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Signals
|
||||
/////////////////////////////////
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private slots
|
||||
/////////////////////////////////
|
||||
private slots:
|
||||
void onModelChanged();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Internal Methods
|
||||
/////////////////////////////////
|
||||
private:
|
||||
void updateNPages();
|
||||
void printSimplePage( QPainter* painter, int iPage ) const;
|
||||
void printCollatedMergePage( QPainter* painter, int iPage ) const;
|
||||
void printUnCollatedMergePage( QPainter* painter, int iPage ) const;
|
||||
void printCropMarks( QPainter* painter ) const;
|
||||
void printOutline( QPainter* painter ) const;
|
||||
void clipLabel( QPainter* painter ) const;
|
||||
void printLabel( QPainter* painter, const merge::Record& record, Variables& variables ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
const Model* mModel{ nullptr };
|
||||
const merge::Merge* mMerge{ nullptr };
|
||||
|
||||
int mNCopies{ 0 };
|
||||
int mStartItem{ 0 };
|
||||
int mLastItem{ 0 };
|
||||
int mNGroups{ 0 };
|
||||
int mNItemsPerGroup{ 0 };
|
||||
int mNPagesPerGroup{ 0 };
|
||||
int mIPage{ 0 };
|
||||
|
||||
bool mIsMerge{ false };
|
||||
|
||||
int mNItems{ 0 };
|
||||
int mNPages{ 0 };
|
||||
int mNItemsPerPage{ 0 };
|
||||
|
||||
bool mIsCollated{ false };
|
||||
bool mAreGroupsContiguous{ false };
|
||||
bool mPrintOutlines{ false };
|
||||
bool mPrintCropMarks{ false };
|
||||
bool mPrintReverse{ false };
|
||||
|
||||
QVector<Point> mOrigins;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_PageRenderer_h
|
||||
@@ -0,0 +1,141 @@
|
||||
// PageRenderer.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_PageRenderer_hpp
|
||||
#define model_PageRenderer_hpp
|
||||
|
||||
|
||||
#include "Point.hpp"
|
||||
#include "Variables.hpp"
|
||||
|
||||
#include "merge/Merge.hpp"
|
||||
#include "merge/Record.hpp"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPrinter>
|
||||
#include <QRect>
|
||||
#include <QVector>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
// Forward references
|
||||
class Model;
|
||||
|
||||
|
||||
///
|
||||
/// PageRenderer Widget
|
||||
///
|
||||
class PageRenderer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
PageRenderer( const Model* model = nullptr );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Public Methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void setModel( const Model* model );
|
||||
const Model* model() const;
|
||||
void setNCopies( int nCopies );
|
||||
void setStartItem( int startItem );
|
||||
void setIsCollated( bool isCollated );
|
||||
void setAreGroupsContiguous( bool areGroupscontiguous );
|
||||
void setPrintOutlines( bool printOutlinesFlag );
|
||||
void setPrintCropMarks( bool printCropMarksFlag );
|
||||
void setPrintReverse( bool printReverseFlag );
|
||||
void setIPage( int iPage );
|
||||
int nItems() const;
|
||||
int nPages() const;
|
||||
QRectF pageRect() const;
|
||||
void print( QPrinter* printer ) const;
|
||||
void printPage( QPainter* painter ) const;
|
||||
void printPage( QPainter* painter, int iPage ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Signals
|
||||
/////////////////////////////////
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private slots
|
||||
/////////////////////////////////
|
||||
private slots:
|
||||
void onModelChanged();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Internal Methods
|
||||
/////////////////////////////////
|
||||
private:
|
||||
void updateNPages();
|
||||
void printSimplePage( QPainter* painter, int iPage ) const;
|
||||
void printCollatedMergePage( QPainter* painter, int iPage ) const;
|
||||
void printUnCollatedMergePage( QPainter* painter, int iPage ) const;
|
||||
void printCropMarks( QPainter* painter ) const;
|
||||
void printOutline( QPainter* painter ) const;
|
||||
void clipLabel( QPainter* painter ) const;
|
||||
void printLabel( QPainter* painter, const merge::Record& record, Variables& variables ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
const Model* mModel{ nullptr };
|
||||
const merge::Merge* mMerge{ nullptr };
|
||||
|
||||
int mNCopies{ 0 };
|
||||
int mStartItem{ 0 };
|
||||
int mLastItem{ 0 };
|
||||
int mNGroups{ 0 };
|
||||
int mNItemsPerGroup{ 0 };
|
||||
int mNPagesPerGroup{ 0 };
|
||||
int mIPage{ 0 };
|
||||
|
||||
bool mIsMerge{ false };
|
||||
|
||||
int mNItems{ 0 };
|
||||
int mNPages{ 0 };
|
||||
int mNItemsPerPage{ 0 };
|
||||
|
||||
bool mIsCollated{ false };
|
||||
bool mAreGroupsContiguous{ false };
|
||||
bool mPrintOutlines{ false };
|
||||
bool mPrintCropMarks{ false };
|
||||
bool mPrintReverse{ false };
|
||||
|
||||
QVector<Point> mOrigins;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_PageRenderer_hpp
|
||||
+71
-73
@@ -1,86 +1,84 @@
|
||||
/* Paper.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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"
|
||||
// Paper.cpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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/>.
|
||||
//
|
||||
|
||||
|
||||
namespace glabels
|
||||
#include "Paper.hpp"
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
Paper::Paper( const QString& id,
|
||||
const QString& name,
|
||||
Distance width,
|
||||
Distance height,
|
||||
const QString& pwgSize )
|
||||
: mId(id),
|
||||
mName(name),
|
||||
mWidth(width),
|
||||
mHeight(height),
|
||||
mPwgSize(pwgSize)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
Paper::Paper( const QString& id,
|
||||
const QString& name,
|
||||
Distance width,
|
||||
Distance height,
|
||||
const QString& pwgSize )
|
||||
: mId(id),
|
||||
mName(name),
|
||||
mWidth(width),
|
||||
mHeight(height),
|
||||
mPwgSize(pwgSize)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
QString Paper::id() const
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
QString Paper::id() const
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
|
||||
|
||||
QString Paper::name() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
|
||||
Distance Paper::width() const
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
QString Paper::name() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
|
||||
Distance Paper::height() const
|
||||
{
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
|
||||
QString Paper::pwgSize() const
|
||||
{
|
||||
return mPwgSize;
|
||||
}
|
||||
|
||||
Distance Paper::width() const
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
bool Paper::isSizeIso() const
|
||||
{
|
||||
return mPwgSize.startsWith( "iso_" );
|
||||
}
|
||||
|
||||
|
||||
bool Paper::isSizeUs() const
|
||||
{
|
||||
return mPwgSize.startsWith( "na_" );
|
||||
}
|
||||
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_" );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
/* Paper.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_Paper_h
|
||||
#define model_Paper_h
|
||||
|
||||
|
||||
#include "Distance.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
class Paper
|
||||
{
|
||||
public:
|
||||
Paper() = default;
|
||||
Paper( const QString& id,
|
||||
const QString& name,
|
||||
Distance width,
|
||||
Distance height,
|
||||
const QString& pwgSize );
|
||||
~Paper() = default;
|
||||
|
||||
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 // model_Paper_h
|
||||
@@ -0,0 +1,70 @@
|
||||
// Paper.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_Paper_hpp
|
||||
#define model_Paper_hpp
|
||||
|
||||
|
||||
#include "Distance.hpp"
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
class Paper
|
||||
{
|
||||
public:
|
||||
Paper() = default;
|
||||
Paper( const QString& id,
|
||||
const QString& name,
|
||||
Distance width,
|
||||
Distance height,
|
||||
const QString& pwgSize );
|
||||
~Paper() = default;
|
||||
|
||||
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 // model_Paper_hpp
|
||||
+64
-67
@@ -1,87 +1,84 @@
|
||||
/* ParserState.cpp
|
||||
*
|
||||
* Copyright (C) 2025 Jaye 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/>.
|
||||
*/
|
||||
// ParserState.cpp
|
||||
//
|
||||
// Copyright (C) 2025 Jaye 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 "ParserState.h"
|
||||
#include "ParserState.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace glabels
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
ParserState::ParserState( const QString& string,
|
||||
qsizetype pos )
|
||||
: mString(&string),
|
||||
mPos( pos )
|
||||
{
|
||||
}
|
||||
ParserState::ParserState( const QString& string,
|
||||
qsizetype pos )
|
||||
: mString(&string),
|
||||
mPos( pos )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QChar
|
||||
ParserState::operator[]( qsizetype i ) const
|
||||
{
|
||||
auto ii = mPos + i;
|
||||
if ( ii < mString->size() )
|
||||
{
|
||||
return (*mString)[ii];
|
||||
}
|
||||
else
|
||||
{
|
||||
return '\0';
|
||||
}
|
||||
}
|
||||
QChar
|
||||
ParserState::operator[]( qsizetype i ) const
|
||||
{
|
||||
auto ii = mPos + i;
|
||||
if ( ii < mString->size() )
|
||||
{
|
||||
return (*mString)[ii];
|
||||
}
|
||||
else
|
||||
{
|
||||
return '\0';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
ParserState::isNextSubString( const QString& s ) const
|
||||
{
|
||||
for ( qsizetype i = 0; i < s.size(); i++ )
|
||||
{
|
||||
if ( operator[](i) != s[i] ) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool
|
||||
ParserState::isNextSubString( const QString& s ) const
|
||||
{
|
||||
for ( qsizetype i = 0; i < s.size(); i++ )
|
||||
{
|
||||
if ( operator[](i) != s[i] ) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
qsizetype
|
||||
ParserState::pos() const
|
||||
{
|
||||
return mPos;
|
||||
}
|
||||
qsizetype
|
||||
ParserState::pos() const
|
||||
{
|
||||
return mPos;
|
||||
}
|
||||
|
||||
|
||||
qsizetype
|
||||
ParserState::charsLeft() const
|
||||
{
|
||||
return std::max( mString->size() - mPos, qsizetype(0) );
|
||||
}
|
||||
qsizetype
|
||||
ParserState::charsLeft() const
|
||||
{
|
||||
return std::max( mString->size() - mPos, qsizetype(0) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ParserState::advanceChars( qsizetype i )
|
||||
{
|
||||
mPos = std::min( mPos + i, mString->size() );
|
||||
}
|
||||
void
|
||||
ParserState::advanceChars( qsizetype i )
|
||||
{
|
||||
mPos = std::min( mPos + i, mString->size() );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/* ParserState.h
|
||||
*
|
||||
* Copyright (C) 2025 Jaye 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 model_ParserState_h
|
||||
#define model_ParserState_h
|
||||
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
class ParserState
|
||||
{
|
||||
public:
|
||||
ParserState() = default;
|
||||
ParserState( const QString& string,
|
||||
qsizetype pos = 0 );
|
||||
~ParserState() = default;
|
||||
|
||||
QChar operator[]( qsizetype i ) const;
|
||||
bool isNextSubString( const QString& s ) const;
|
||||
qsizetype pos() const;
|
||||
qsizetype charsLeft() const;
|
||||
|
||||
void advanceChars( qsizetype i );
|
||||
|
||||
|
||||
private:
|
||||
const QString* mString{ nullptr };
|
||||
qsizetype mPos{ 0 };
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ParserState_h
|
||||
@@ -0,0 +1,55 @@
|
||||
// ParserState.hpp
|
||||
//
|
||||
// Copyright (C) 2025 Jaye 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 model_ParserState_hpp
|
||||
#define model_ParserState_hpp
|
||||
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
class ParserState
|
||||
{
|
||||
public:
|
||||
ParserState() = default;
|
||||
ParserState( const QString& string,
|
||||
qsizetype pos = 0 );
|
||||
~ParserState() = default;
|
||||
|
||||
QChar operator[]( qsizetype i ) const;
|
||||
bool isNextSubString( const QString& s ) const;
|
||||
qsizetype pos() const;
|
||||
qsizetype charsLeft() const;
|
||||
|
||||
void advanceChars( qsizetype i );
|
||||
|
||||
|
||||
private:
|
||||
const QString* mString{ nullptr };
|
||||
qsizetype mPos{ 0 };
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_ParserState_hpp
|
||||
+48
-55
@@ -1,67 +1,60 @@
|
||||
/* Point.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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"
|
||||
// Point.cpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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/>.
|
||||
//
|
||||
|
||||
|
||||
namespace glabels
|
||||
#include "Point.hpp"
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
Point::Point() : mX(Distance(0)), mY(Distance(0))
|
||||
{
|
||||
// empty
|
||||
}
|
||||
Point::Point( Distance x, Distance y )
|
||||
: mX(x), mY(y)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
Point::Point( Distance x, Distance y ) : mX(x), mY(y)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
Distance Point::x() const
|
||||
{
|
||||
return mX;
|
||||
}
|
||||
|
||||
|
||||
Distance Point::x() const
|
||||
{
|
||||
return mX;
|
||||
}
|
||||
|
||||
|
||||
Distance Point::y() const
|
||||
{
|
||||
return mY;
|
||||
}
|
||||
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;
|
||||
}
|
||||
bool Point::operator<( const Point &other ) const
|
||||
{
|
||||
if ( mY < other.mY )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( mY == other.mY )
|
||||
{
|
||||
return mX < other.mX;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/* Point.h
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 model_Point_h
|
||||
#define model_Point_h
|
||||
|
||||
|
||||
#include "Distance.h"
|
||||
|
||||
#include <QMetaType>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Q_DECLARE_METATYPE( glabels::model::Point )
|
||||
|
||||
|
||||
#endif // model_Point_h
|
||||
@@ -0,0 +1,57 @@
|
||||
// Point.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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 model_Point_hpp
|
||||
#define model_Point_hpp
|
||||
|
||||
|
||||
#include "Distance.hpp"
|
||||
|
||||
#include <QMetaType>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
class Point
|
||||
{
|
||||
public:
|
||||
Point() = default;
|
||||
|
||||
Point( Distance x, Distance y );
|
||||
|
||||
Distance x() const;
|
||||
Distance y() const;
|
||||
|
||||
bool operator<( const Point &other ) const;
|
||||
|
||||
|
||||
private:
|
||||
Distance mX;
|
||||
Distance mY;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
Q_DECLARE_METATYPE( glabels::model::Point )
|
||||
|
||||
|
||||
#endif // model_Point_hpp
|
||||
+132
-135
@@ -1,157 +1,154 @@
|
||||
/* RawText.cpp
|
||||
*
|
||||
* Copyright (C) 2017 Jaye 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/>.
|
||||
*/
|
||||
// RawText.cpp
|
||||
//
|
||||
// Copyright (C) 2017 Jaye 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 "RawText.h"
|
||||
#include "RawText.hpp"
|
||||
|
||||
#include "ParserState.h"
|
||||
#include "ParserState.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QRegularExpression>
|
||||
|
||||
|
||||
namespace glabels
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor from QString
|
||||
///
|
||||
RawText::RawText( const QString& string ) : mString(string)
|
||||
{
|
||||
tokenize();
|
||||
}
|
||||
///
|
||||
/// Constructor from QString
|
||||
///
|
||||
RawText::RawText( const QString& string ) : mString(string)
|
||||
{
|
||||
tokenize();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor from C string operator
|
||||
///
|
||||
RawText::RawText( const char* cString ) : mString(QString(cString))
|
||||
{
|
||||
tokenize();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Access as QString
|
||||
///
|
||||
QString RawText::toString() const
|
||||
{
|
||||
return mString;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Access as std::string
|
||||
///
|
||||
std::string RawText::toStdString() const
|
||||
{
|
||||
return mString.toStdString();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Expand all place holders
|
||||
///
|
||||
QString RawText::expand( const merge::Record& record, const Variables& variables ) const
|
||||
{
|
||||
QString text;
|
||||
|
||||
for ( const Token& token : mTokens )
|
||||
{
|
||||
if ( token.isField )
|
||||
{
|
||||
text += token.field.evaluate( record, variables );
|
||||
}
|
||||
else
|
||||
{
|
||||
text += token.text;
|
||||
}
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
///
|
||||
/// Constructor from C string operator
|
||||
///
|
||||
RawText::RawText( const char* cString ) : mString(QString(cString))
|
||||
{
|
||||
tokenize();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Does raw text contain place holders?
|
||||
///
|
||||
bool RawText::hasPlaceHolders() const
|
||||
{
|
||||
QRegularExpression re("\\${\\w+}");
|
||||
return mString.contains( re );
|
||||
}
|
||||
///
|
||||
/// Access as QString
|
||||
///
|
||||
QString RawText::toString() const
|
||||
{
|
||||
return mString;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Is raw text empty?
|
||||
///
|
||||
bool RawText::isEmpty() const
|
||||
{
|
||||
return mString.isEmpty();
|
||||
}
|
||||
///
|
||||
/// Access as std::string
|
||||
///
|
||||
std::string RawText::toStdString() const
|
||||
{
|
||||
return mString.toStdString();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Tokenize string
|
||||
///
|
||||
void RawText::tokenize()
|
||||
{
|
||||
Token token;
|
||||
///
|
||||
/// Expand all place holders
|
||||
///
|
||||
QString RawText::expand( const merge::Record& record, const Variables& variables ) const
|
||||
{
|
||||
QString text;
|
||||
|
||||
ParserState s( mString );
|
||||
while ( s.charsLeft() )
|
||||
{
|
||||
SubstitutionField field;
|
||||
if ( SubstitutionField::parse( s, field ) )
|
||||
{
|
||||
// Finalize current text token, if apropos
|
||||
if ( !token.text.isEmpty() )
|
||||
{
|
||||
token.isField = false;
|
||||
mTokens.append( token );
|
||||
}
|
||||
|
||||
// Create and finalize field token
|
||||
token.isField = true;
|
||||
token.text = "";
|
||||
token.field = field;
|
||||
mTokens.append( token );
|
||||
}
|
||||
else
|
||||
{
|
||||
token.text += s[0];
|
||||
s.advanceChars(1);
|
||||
}
|
||||
}
|
||||
for ( const Token& token : mTokens )
|
||||
{
|
||||
if ( token.isField )
|
||||
{
|
||||
text += token.field.evaluate( record, variables );
|
||||
}
|
||||
else
|
||||
{
|
||||
text += token.text;
|
||||
}
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Does raw text contain place holders?
|
||||
///
|
||||
bool RawText::hasPlaceHolders() const
|
||||
{
|
||||
QRegularExpression re("\\${\\w+}");
|
||||
return mString.contains( re );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Is raw text empty?
|
||||
///
|
||||
bool RawText::isEmpty() const
|
||||
{
|
||||
return mString.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Tokenize string
|
||||
///
|
||||
void RawText::tokenize()
|
||||
{
|
||||
Token token;
|
||||
|
||||
ParserState s( mString );
|
||||
while ( s.charsLeft() )
|
||||
{
|
||||
SubstitutionField field;
|
||||
if ( SubstitutionField::parse( s, field ) )
|
||||
{
|
||||
// Finalize current text token, if apropos
|
||||
if ( !token.text.isEmpty() )
|
||||
{
|
||||
token.isField = false;
|
||||
mTokens.append( token );
|
||||
}
|
||||
|
||||
// Create and finalize field token
|
||||
token.isField = true;
|
||||
token.text = "";
|
||||
token.field = field;
|
||||
mTokens.append( token );
|
||||
}
|
||||
else
|
||||
{
|
||||
token.text += s[0];
|
||||
s.advanceChars(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Finalize last text token, if apropos
|
||||
if ( !token.text.isEmpty() )
|
||||
{
|
||||
token.isField = false;
|
||||
mTokens.append( token );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Finalize last text token, if apropos
|
||||
if ( !token.text.isEmpty() )
|
||||
{
|
||||
token.isField = false;
|
||||
mTokens.append( token );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
/* RawText.h
|
||||
*
|
||||
* Copyright (C) 2017 Jaye 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 model_RawText_h
|
||||
#define model_RawText_h
|
||||
|
||||
|
||||
#include "SubstitutionField.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
///
|
||||
/// Raw Text Type
|
||||
///
|
||||
struct RawText
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
RawText() = default;
|
||||
RawText( const QString& string );
|
||||
RawText( const char* cString );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Misc. Methods
|
||||
/////////////////////////////////
|
||||
QString toString() const;
|
||||
std::string toStdString() const;
|
||||
QString expand( const merge::Record& record, const Variables& variables ) const;
|
||||
bool hasPlaceHolders() const;
|
||||
bool isEmpty() const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Methods
|
||||
/////////////////////////////////
|
||||
private:
|
||||
void tokenize();
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
QString mString;
|
||||
|
||||
struct Token
|
||||
{
|
||||
bool isField{ false };
|
||||
QString text;
|
||||
SubstitutionField field;
|
||||
};
|
||||
|
||||
QList<Token> mTokens;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_RawText_h
|
||||
@@ -0,0 +1,84 @@
|
||||
// RawText.hpp
|
||||
//
|
||||
// Copyright (C) 2017 Jaye 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 model_RawText_hpp
|
||||
#define model_RawText_hpp
|
||||
|
||||
|
||||
#include "SubstitutionField.hpp"
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
///
|
||||
/// Raw Text Type
|
||||
///
|
||||
struct RawText
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
RawText() = default;
|
||||
RawText( const QString& string );
|
||||
RawText( const char* cString );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Misc. Methods
|
||||
/////////////////////////////////
|
||||
QString toString() const;
|
||||
std::string toStdString() const;
|
||||
QString expand( const merge::Record& record, const Variables& variables ) const;
|
||||
bool hasPlaceHolders() const;
|
||||
bool isEmpty() const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Methods
|
||||
/////////////////////////////////
|
||||
private:
|
||||
void tokenize();
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
QString mString;
|
||||
|
||||
struct Token
|
||||
{
|
||||
bool isField{ false };
|
||||
QString text;
|
||||
SubstitutionField field;
|
||||
};
|
||||
|
||||
QList<Token> mTokens;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_RawText_hpp
|
||||
+116
-118
@@ -1,146 +1,144 @@
|
||||
/* Region.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye 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 "Region.h"
|
||||
// Region.cpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye 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/>.
|
||||
//
|
||||
|
||||
|
||||
namespace glabels
|
||||
#include "Region.hpp"
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
Region::Region()
|
||||
: mX1(0),
|
||||
mY1(0),
|
||||
mX2(0),
|
||||
mY2(0)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
Region::Region()
|
||||
: mX1(0),
|
||||
mY1(0),
|
||||
mX2(0),
|
||||
mY2(0)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
Region::Region( Distance x1,
|
||||
Distance y1,
|
||||
Distance x2,
|
||||
Distance y2 )
|
||||
: mX1(x1),
|
||||
mY1(y1),
|
||||
mX2(x2),
|
||||
mY2(y2)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
Region::Region( Distance x1,
|
||||
Distance y1,
|
||||
Distance x2,
|
||||
Distance y2 )
|
||||
: mX1(x1),
|
||||
mY1(y1),
|
||||
mX2(x2),
|
||||
mY2(y2)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get x1
|
||||
///
|
||||
Distance Region::x1() const
|
||||
{
|
||||
return mX1;
|
||||
}
|
||||
///
|
||||
/// Get x1
|
||||
///
|
||||
Distance Region::x1() const
|
||||
{
|
||||
return mX1;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set x1
|
||||
///
|
||||
void Region::setX1( Distance value )
|
||||
{
|
||||
mX1 = value;
|
||||
}
|
||||
///
|
||||
/// Set x1
|
||||
///
|
||||
void Region::setX1( Distance value )
|
||||
{
|
||||
mX1 = value;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get y1
|
||||
///
|
||||
Distance Region::y1() const
|
||||
{
|
||||
return mY1;
|
||||
}
|
||||
///
|
||||
/// Get y1
|
||||
///
|
||||
Distance Region::y1() const
|
||||
{
|
||||
return mY1;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set y1
|
||||
///
|
||||
void Region::setY1( Distance value )
|
||||
{
|
||||
mY1 = value;
|
||||
}
|
||||
///
|
||||
/// Set y1
|
||||
///
|
||||
void Region::setY1( Distance value )
|
||||
{
|
||||
mY1 = value;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get x2
|
||||
///
|
||||
Distance Region::x2() const
|
||||
{
|
||||
return mX2;
|
||||
}
|
||||
///
|
||||
/// Get x2
|
||||
///
|
||||
Distance Region::x2() const
|
||||
{
|
||||
return mX2;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set x2
|
||||
///
|
||||
void Region::setX2( Distance value )
|
||||
{
|
||||
mX2 = value;
|
||||
}
|
||||
///
|
||||
/// Set x2
|
||||
///
|
||||
void Region::setX2( Distance value )
|
||||
{
|
||||
mX2 = value;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get y2
|
||||
///
|
||||
Distance Region::y2() const
|
||||
{
|
||||
return mY2;
|
||||
}
|
||||
///
|
||||
/// Get y2
|
||||
///
|
||||
Distance Region::y2() const
|
||||
{
|
||||
return mY2;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set y2
|
||||
///
|
||||
void Region::setY2( Distance value )
|
||||
{
|
||||
mY2 = value;
|
||||
}
|
||||
///
|
||||
/// Set y2
|
||||
///
|
||||
void Region::setY2( Distance value )
|
||||
{
|
||||
mY2 = value;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Convert to a QRectF
|
||||
///
|
||||
QRectF Region::rect() const
|
||||
{
|
||||
QRectF r;
|
||||
///
|
||||
/// Convert to a QRectF
|
||||
///
|
||||
QRectF Region::rect() const
|
||||
{
|
||||
QRectF r;
|
||||
|
||||
r.setX( min( mX1, mX2 ).pt() );
|
||||
r.setY( min( mY1, mY2 ).pt() );
|
||||
r.setWidth( fabs( mX2 - mX1 ).pt() );
|
||||
r.setHeight( fabs( mY2 - mY1 ).pt() );
|
||||
r.setX( min( mX1, mX2 ).pt() );
|
||||
r.setY( min( mY1, mY2 ).pt() );
|
||||
r.setWidth( fabs( mX2 - mX1 ).pt() );
|
||||
r.setHeight( fabs( mY2 - mY1 ).pt() );
|
||||
|
||||
return r;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
-106
@@ -1,106 +0,0 @@
|
||||
/* Region.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye 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 model_Region_h
|
||||
#define model_Region_h
|
||||
|
||||
|
||||
#include "Distance.h"
|
||||
|
||||
#include <QRectF>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Region Type
|
||||
///
|
||||
class Region
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Constructors
|
||||
/////////////////////////////////
|
||||
public:
|
||||
Region();
|
||||
Region( Distance x1,
|
||||
Distance y1,
|
||||
Distance x2,
|
||||
Distance y2 );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// X1 Property
|
||||
//
|
||||
Distance x1() const;
|
||||
void setX1( Distance value );
|
||||
|
||||
|
||||
//
|
||||
// Y1 Property
|
||||
//
|
||||
Distance y1() const;
|
||||
void setY1( Distance value );
|
||||
|
||||
|
||||
//
|
||||
// X2 Property
|
||||
//
|
||||
Distance x2() const;
|
||||
void setX2( Distance value );
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Y2 Property
|
||||
//
|
||||
Distance y2() const;
|
||||
void setY2( Distance value );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
QRectF rect() const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
Distance mX1;
|
||||
Distance mY1;
|
||||
Distance mX2;
|
||||
Distance mY2;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // model_Region_h
|
||||
@@ -0,0 +1,103 @@
|
||||
// Region.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye 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 model_Region_hpp
|
||||
#define model_Region_hpp
|
||||
|
||||
|
||||
#include "Distance.hpp"
|
||||
|
||||
#include <QRectF>
|
||||
|
||||
|
||||
namespace glabels::model
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Region Type
|
||||
///
|
||||
class Region
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Constructors
|
||||
/////////////////////////////////
|
||||
public:
|
||||
Region();
|
||||
Region( Distance x1,
|
||||
Distance y1,
|
||||
Distance x2,
|
||||
Distance y2 );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// X1 Property
|
||||
//
|
||||
Distance x1() const;
|
||||
void setX1( Distance value );
|
||||
|
||||
|
||||
//
|
||||
// Y1 Property
|
||||
//
|
||||
Distance y1() const;
|
||||
void setY1( Distance value );
|
||||
|
||||
|
||||
//
|
||||
// X2 Property
|
||||
//
|
||||
Distance x2() const;
|
||||
void setX2( Distance value );
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Y2 Property
|
||||
//
|
||||
Distance y2() const;
|
||||
void setY2( Distance value );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
QRectF rect() const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
Distance mX1;
|
||||
Distance mY1;
|
||||
Distance mX2;
|
||||
Distance mY2;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // model_Region_hpp
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user