Add hooks to sync QGraphicsItems with label objects.
This commit is contained in:
@@ -10,6 +10,7 @@ set (glabels_sources
|
||||
Help.cpp
|
||||
LabelModel.cpp
|
||||
LabelModelItem.cpp
|
||||
LabelModelBoxItem.cpp
|
||||
LabelRegion.cpp
|
||||
MainWindow.cpp
|
||||
MergeField.cpp
|
||||
@@ -24,6 +25,7 @@ set (glabels_sources
|
||||
set (glabels_qobject_headers
|
||||
LabelModel.h
|
||||
LabelModelItem.h
|
||||
LabelModelBoxItem.h
|
||||
MainWindow.h
|
||||
TemplatePicker.h
|
||||
NewLabelDialog.h
|
||||
|
||||
+4
-2
@@ -52,18 +52,20 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
void LabelModel::itemChanged( LabelModelItem *item )
|
||||
void LabelModel::onItemChanged( LabelModelItem *item )
|
||||
{
|
||||
mModified = true;
|
||||
|
||||
emit itemChanged( item );
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
void LabelModel::itemMoved( LabelModelItem *item )
|
||||
void LabelModel::onItemMoved( LabelModelItem *item )
|
||||
{
|
||||
mModified = true;
|
||||
|
||||
emit itemMoved( item );
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -44,6 +44,8 @@ namespace glabels
|
||||
void nameChanged();
|
||||
void sizeChanged();
|
||||
void selectionChanged();
|
||||
void itemChanged( LabelModelItem *item );
|
||||
void itemMoved( LabelModelItem *item );
|
||||
void itemAdded( LabelModelItem *item );
|
||||
void itemDeleted( LabelModelItem *item );
|
||||
void itemToTop( LabelModelItem *item );
|
||||
@@ -157,8 +159,8 @@ namespace glabels
|
||||
|
||||
|
||||
private slots:
|
||||
void itemChanged( LabelModelItem *item );
|
||||
void itemMoved( LabelModelItem *item );
|
||||
void onItemChanged( LabelModelItem *item );
|
||||
void onItemMoved( LabelModelItem *item );
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/* LabelModelBoxItem.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "LabelModelBoxItem.h"
|
||||
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QBrush>
|
||||
#include <QPen>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
// Create QGraphicsItem suitable for representing this object
|
||||
QGraphicsItem* LabelModelBoxItem::createGraphicsItem()
|
||||
{
|
||||
QGraphicsRectItem *rectItem = new QGraphicsRectItem( x0(), y0(), w(), h() );
|
||||
|
||||
QBrush brush( fillColorNode().color() );
|
||||
rectItem->setBrush( brush );
|
||||
|
||||
QPen pen( lineColorNode().color() );
|
||||
pen.setWidthF( lineWidth() );
|
||||
rectItem->setPen( pen );
|
||||
|
||||
return rectItem;
|
||||
}
|
||||
|
||||
|
||||
// Update a QGraphicsItem to keep it in sync with this object
|
||||
void LabelModelBoxItem::updateGraphicsItem( QGraphicsItem* graphicsItem )
|
||||
{
|
||||
QGraphicsRectItem *rectItem = dynamic_cast<QGraphicsRectItem*>(graphicsItem);
|
||||
if ( rectItem )
|
||||
{
|
||||
rectItem->setRect( x0(), y0(), w(), h() );
|
||||
|
||||
QBrush brush( fillColorNode().color() );
|
||||
rectItem->setBrush( brush );
|
||||
|
||||
QPen pen( lineColorNode().color() );
|
||||
pen.setWidthF( lineWidth() );
|
||||
rectItem->setPen( pen );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/* LabelModelBoxItem.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_LabelModelBoxItem_h
|
||||
#define glabels_LabelModelBoxItem_h
|
||||
|
||||
#include "LabelModelItem.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
class LabelModelBoxItem : public LabelModelItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
LabelModelBoxItem( QObject *parent = 0 ) : LabelModelItem(parent) { /* TODO: initialize default line and fill poperties. */ };
|
||||
virtual ~LabelModelBoxItem() {}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Properties
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
/*
|
||||
* Virtual Shape Property: lineWidth
|
||||
*/
|
||||
double lineWidth( void ) const { return mLineWidth; }
|
||||
void setLineWidth( double value ) { mLineWidth = value; }
|
||||
|
||||
|
||||
/*
|
||||
* Virtual Shape Property: lineColorNode
|
||||
*/
|
||||
ColorNode lineColorNode( void ) { return mLineColorNode; }
|
||||
void setLineColorNode( const ColorNode &value ) { mLineColorNode = value; }
|
||||
|
||||
|
||||
/*
|
||||
* Virtual Shape Property: fillColorNode
|
||||
*/
|
||||
ColorNode fillColorNode( void ) { return mFillColorNode; }
|
||||
void setFillColorNode( const ColorNode &value ) { mFillColorNode = value; }
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capabilities
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
bool canFill() { return true; }
|
||||
|
||||
bool canLineColor() { return true; }
|
||||
|
||||
bool canLineWidth() { return true; }
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// QGraphicsItem methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
QGraphicsItem* createGraphicsItem();
|
||||
void updateGraphicsItem( QGraphicsItem* graphicsItem );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
double mLineWidth;
|
||||
ColorNode mLineColorNode;
|
||||
ColorNode mFillColorNode;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_LabelModelBoxItem_h
|
||||
@@ -24,11 +24,15 @@
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
int LabelModelItem::lastId = 0;
|
||||
|
||||
/*
|
||||
* Default constructor.
|
||||
*/
|
||||
LabelModelItem::LabelModelItem( QObject *parent = 0 ) : QObject(parent)
|
||||
{
|
||||
mId = lastId++;
|
||||
|
||||
mX0 = 0;
|
||||
mY0 = 0;
|
||||
mW = 0;
|
||||
|
||||
+50
-32
@@ -24,7 +24,7 @@
|
||||
#include <QObject>
|
||||
#include <QTransform>
|
||||
#include <QFont>
|
||||
#include <QPainter>
|
||||
#include <QGraphicsItem>
|
||||
|
||||
#include "ColorNode.h"
|
||||
#include "TextNode.h"
|
||||
@@ -60,14 +60,21 @@ namespace glabels
|
||||
// Common Properties
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
/*
|
||||
* ID Property.
|
||||
*/
|
||||
Q_PROPERTY( int id READ id )
|
||||
|
||||
int id() const { return mId; }
|
||||
|
||||
/*
|
||||
* Selected Property.
|
||||
*/
|
||||
Q_PROPERTY( bool selected READ isSelected WRITE select RESET unselect )
|
||||
|
||||
bool isSelected( void ) { return mSelectedFlag; }
|
||||
bool isSelected() { return mSelectedFlag; }
|
||||
void select( bool value = true ) { mSelectedFlag = value; }
|
||||
void unselect( void ) { mSelectedFlag = false; }
|
||||
void unselect() { mSelectedFlag = false; }
|
||||
|
||||
|
||||
/*
|
||||
@@ -75,7 +82,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( double x0 READ x0 WRITE setX0 );
|
||||
|
||||
double x0( void ) { return mX0; }
|
||||
double x0() { return mX0; }
|
||||
void setX0( double value )
|
||||
{
|
||||
if ( mX0 != value ) { mX0 = value; emit moved(); }
|
||||
@@ -87,7 +94,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( double y0 READ y0 WRITE setY0 );
|
||||
|
||||
double y0( void ) { return mY0; }
|
||||
double y0() { return mY0; }
|
||||
void setY0( double value )
|
||||
{
|
||||
if ( mY0 != value ) { mY0 = value; emit moved(); }
|
||||
@@ -99,7 +106,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( double w READ w WRITE setW );
|
||||
|
||||
double w( void ) { return mW; }
|
||||
double w() { return mW; }
|
||||
void setW( double value )
|
||||
{
|
||||
if ( mW != value ) { mW = value; emit moved(); }
|
||||
@@ -111,7 +118,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( double h READ h WRITE setH );
|
||||
|
||||
double h( void ) { return mH; }
|
||||
double h() { return mH; }
|
||||
void setH( double value )
|
||||
{
|
||||
if ( mH != value ) { mH = value; emit moved(); }
|
||||
@@ -123,7 +130,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( QTransform matrix READ matrix WRITE setMatrix );
|
||||
|
||||
QTransform matrix( void ) { return mMatrix; }
|
||||
QTransform matrix() { return mMatrix; }
|
||||
void setMatrix( const QTransform &value )
|
||||
{
|
||||
if ( mMatrix != value ) { mMatrix = value; emit changed(); }
|
||||
@@ -135,7 +142,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( bool shadow READ shadow WRITE setShadow );
|
||||
|
||||
bool shadow( void ) { return mShadowState; }
|
||||
bool shadow() { return mShadowState; }
|
||||
void setShadow( bool value )
|
||||
{
|
||||
if ( mShadowState != value ) { mShadowState = value; emit changed(); }
|
||||
@@ -147,7 +154,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( double shadowX READ shadowX WRITE setShadowX );
|
||||
|
||||
double shadowX( void ) { return mShadowX; }
|
||||
double shadowX() { return mShadowX; }
|
||||
void setShadowX( double value )
|
||||
{
|
||||
if ( mShadowX != value ) { mShadowX = value; emit changed(); }
|
||||
@@ -159,7 +166,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( double shadowY READ shadowY WRITE setShadowY );
|
||||
|
||||
double shadowY( void ) { return mShadowY; }
|
||||
double shadowY() { return mShadowY; }
|
||||
void setShadowY( double value )
|
||||
{
|
||||
if ( mShadowY != value ) { mShadowY = value; emit changed(); }
|
||||
@@ -171,7 +178,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( double shadowOpacity READ shadowOpacity WRITE setShadowOpacity );
|
||||
|
||||
double shadowOpacity( void ) { return mShadowOpacity; }
|
||||
double shadowOpacity() { return mShadowOpacity; }
|
||||
void setShadowOpacity( double value )
|
||||
{
|
||||
if ( mShadowOpacity != value ) { mShadowOpacity = value; emit changed(); }
|
||||
@@ -183,7 +190,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( ColorNode shadowColorNode READ shadowColorNode WRITE setShadowColorNode );
|
||||
|
||||
ColorNode shadowColorNode( void ) { return mShadowColorNode; }
|
||||
ColorNode shadowColorNode() { return mShadowColorNode; }
|
||||
void setShadowColorNode( const ColorNode &value )
|
||||
{
|
||||
if ( mShadowColorNode != value ) { mShadowColorNode = value; emit changed(); }
|
||||
@@ -199,7 +206,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( QString fontFamily READ fontFamily WRITE setFontFamily );
|
||||
|
||||
virtual QString fontFamily( void ) { return ""; }
|
||||
virtual QString fontFamily() { return ""; }
|
||||
virtual void setFontFamily( const QString &value ) { }
|
||||
|
||||
|
||||
@@ -208,7 +215,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( double fontSize READ fontSize WRITE setFontSize );
|
||||
|
||||
virtual double fontSize( void ) { return 0; }
|
||||
virtual double fontSize() { return 0; }
|
||||
virtual void setFontSize( double value ) { }
|
||||
|
||||
|
||||
@@ -217,7 +224,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( QFont::Weight fontWeight READ fontWeight WRITE setFontWeight );
|
||||
|
||||
virtual QFont::Weight fontWeight( void ) { return QFont::Normal; }
|
||||
virtual QFont::Weight fontWeight() { return QFont::Normal; }
|
||||
virtual void setFontWeight( QFont::Weight value ) { }
|
||||
|
||||
|
||||
@@ -226,7 +233,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( bool fontItalicFlag READ fontItalicFlag WRITE setFontItalicFlag );
|
||||
|
||||
virtual bool fontItalicFlag( void ) { return false; }
|
||||
virtual bool fontItalicFlag() { return false; }
|
||||
virtual void setFontItalicFlag( bool value ) { }
|
||||
|
||||
|
||||
@@ -235,7 +242,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( bool fontUnderlineFlag READ fontUnderlineFlag WRITE setFontUnderlineFlag );
|
||||
|
||||
virtual bool fontUnderlineFlag( void ) { return false; }
|
||||
virtual bool fontUnderlineFlag() { return false; }
|
||||
virtual void setFontUnderlineFlag( bool value ) { }
|
||||
|
||||
|
||||
@@ -244,7 +251,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( ColorNode textColorNode READ textColorNode WRITE setTextColorNode );
|
||||
|
||||
virtual ColorNode textColorNode( void ) { return ColorNode( QColor::fromRgba(0x00000000) ); }
|
||||
virtual ColorNode textColorNode() { return ColorNode( QColor::fromRgba(0x00000000) ); }
|
||||
virtual void setTextColorNode( const ColorNode &value ) { }
|
||||
|
||||
|
||||
@@ -253,7 +260,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( Qt::Alignment textHAlign READ textHAlign WRITE setTextHAlign );
|
||||
|
||||
virtual Qt::Alignment textHAlign( void ) { return Qt::AlignLeft; }
|
||||
virtual Qt::Alignment textHAlign() { return Qt::AlignLeft; }
|
||||
virtual void setTextHAlign( Qt::Alignment value ) { }
|
||||
|
||||
|
||||
@@ -262,7 +269,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( Qt::Alignment textVAlign READ textVAlign WRITE setTextVAlign );
|
||||
|
||||
virtual Qt::Alignment textVAlign( void ) { return Qt::AlignTop; }
|
||||
virtual Qt::Alignment textVAlign() { return Qt::AlignTop; }
|
||||
virtual void setTextVAlign( Qt::Alignment value ) { }
|
||||
|
||||
|
||||
@@ -271,7 +278,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( double textLineSpacing READ textLineSpacing WRITE setTextLineSpacing );
|
||||
|
||||
virtual double textLineSpacing( void ) { return 0; }
|
||||
virtual double textLineSpacing() { return 0; }
|
||||
virtual void setTextLineSpacing( double value ) { }
|
||||
|
||||
|
||||
@@ -284,7 +291,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( TextNode filenameNode READ filenameNode WRITE setFilenameNode );
|
||||
|
||||
virtual TextNode filenameNode( void ) { return TextNode(); }
|
||||
virtual TextNode filenameNode() { return TextNode(); }
|
||||
virtual void setFilenameNode( const TextNode &value ) { }
|
||||
|
||||
|
||||
@@ -297,7 +304,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( double lineWidth READ lineWidth WRITE setLineWidth );
|
||||
|
||||
virtual double lineWidth( void ) { return 0; }
|
||||
virtual double lineWidth() { return 0; }
|
||||
virtual void setLineWidth( double value ) { }
|
||||
|
||||
|
||||
@@ -306,7 +313,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( ColorNode lineColorNode READ lineColorNode WRITE setLineColorNode );
|
||||
|
||||
virtual ColorNode lineColorNode( void ) { return ColorNode( QColor::fromRgba(0x00000000) ); }
|
||||
virtual ColorNode lineColorNode() { return ColorNode( QColor::fromRgba(0x00000000) ); }
|
||||
virtual void setLineColorNode( const ColorNode &value ) { }
|
||||
|
||||
|
||||
@@ -315,7 +322,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( ColorNode fillColorNode READ fillColorNode WRITE setFillColorNode );
|
||||
|
||||
virtual ColorNode fillColorNode( void ) { return ColorNode( QColor::fromRgba(0x00000000) ); }
|
||||
virtual ColorNode fillColorNode() { return ColorNode( QColor::fromRgba(0x00000000) ); }
|
||||
virtual void setFillColorNode( const ColorNode &value ) { }
|
||||
|
||||
|
||||
@@ -328,7 +335,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( TextNode bcDataNode READ bcDataNode WRITE setBcDataNode );
|
||||
|
||||
virtual TextNode bcDataNode( void ) { return TextNode(); }
|
||||
virtual TextNode bcDataNode() { return TextNode(); }
|
||||
virtual void setBcDataNode( const TextNode &value ) { }
|
||||
|
||||
|
||||
@@ -337,7 +344,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( bool bcTextFlag READ bcTextFlag WRITE setBcTextFlag );
|
||||
|
||||
virtual bool bcTextFlag( void ) { return false; }
|
||||
virtual bool bcTextFlag() { return false; }
|
||||
virtual void setBcTextFlag( bool value ) { }
|
||||
|
||||
|
||||
@@ -346,7 +353,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( bool bcChecksumFlag READ bcChecksumFlag WRITE setBcChecksumFlag );
|
||||
|
||||
virtual bool bcChecksumFlag( void ) { return false; }
|
||||
virtual bool bcChecksumFlag() { return false; }
|
||||
virtual void setBcChecksumFlag( bool value ) { }
|
||||
|
||||
|
||||
@@ -355,7 +362,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( ColorNode bcColorNode READ bcColorNode WRITE setBcColorNode );
|
||||
|
||||
virtual ColorNode bcColorNode( void ) { return ColorNode( QColor::fromRgba(0x00000000) ); }
|
||||
virtual ColorNode bcColorNode() { return ColorNode( QColor::fromRgba(0x00000000) ); }
|
||||
virtual void setBcColorNode( const ColorNode &value ) { }
|
||||
|
||||
|
||||
@@ -364,7 +371,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( BarcodeStyle bcStyle READ bcStyle WRITE setBcStyle );
|
||||
|
||||
virtual BarcodeStyle bcStyle( void ) { return BarcodeStyle(); }
|
||||
virtual BarcodeStyle bcStyle() { return BarcodeStyle(); }
|
||||
virtual void setBcStyle( const BarcodeStyle &value ) { }
|
||||
|
||||
|
||||
@@ -373,7 +380,7 @@ namespace glabels
|
||||
*/
|
||||
Q_PROPERTY( int bcFormatDigits READ bcFormatDigits WRITE setBcFormatDigits );
|
||||
|
||||
virtual int bcFormatDigits( void ) { return false; }
|
||||
virtual int bcFormatDigits() { return false; }
|
||||
virtual void setBcFormatDigits( int value ) { }
|
||||
|
||||
|
||||
@@ -415,10 +422,21 @@ namespace glabels
|
||||
void flipVert();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// QGraphicsItem methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
virtual QGraphicsItem* createGraphicsItem() = 0;
|
||||
virtual void updateGraphicsItem( QGraphicsItem* graphicsItem ) = 0;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
static int lastId;
|
||||
int mId;
|
||||
|
||||
bool mSelectedFlag;
|
||||
|
||||
double mX0;
|
||||
|
||||
Reference in New Issue
Block a user