Added object layer to view. Added draw methods to objects.
This commit is contained in:
@@ -1056,5 +1056,17 @@ namespace glabels
|
|||||||
emit modifiedChanged();
|
emit modifiedChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Draw label objects
|
||||||
|
///
|
||||||
|
void LabelModel::draw( QPainter* painter, bool inEditor, MergeRecord* record ) const
|
||||||
|
{
|
||||||
|
foreach ( LabelModelObject* object, mObjectList )
|
||||||
|
{
|
||||||
|
object->draw( painter, inEditor, record );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,9 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
#include "MergeRecord.h"
|
||||||
#include "libglabels/Template.h"
|
#include "libglabels/Template.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -166,6 +168,13 @@ namespace glabels
|
|||||||
void setSelectionFillColorNode( ColorNode fillColorNode );
|
void setSelectionFillColorNode( ColorNode fillColorNode );
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////
|
||||||
|
// Drawing operations
|
||||||
|
/////////////////////////////////
|
||||||
|
public:
|
||||||
|
void draw( QPainter* painter, bool inEditor = true, MergeRecord* record = 0 ) const;
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
// Slots
|
// Slots
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
#include "LabelModelBoxObject.h"
|
#include "LabelModelBoxObject.h"
|
||||||
|
|
||||||
#include <QGraphicsRectItem>
|
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
#include <QPen>
|
#include <QPen>
|
||||||
|
|
||||||
@@ -139,48 +138,62 @@ namespace glabels
|
|||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Create QGraphicsItem suitable for representing this object
|
/// Draw shadow of object
|
||||||
///
|
///
|
||||||
QGraphicsItem* LabelModelBoxObject::createGraphicsItem()
|
void LabelModelBoxObject::drawShadow( QPainter* painter, bool inEditor, MergeRecord* record ) const
|
||||||
{
|
{
|
||||||
QGraphicsRectItem *rectItem = new QGraphicsRectItem( x0(), y0(), w(), h() );
|
/// TODO expand colors based on record
|
||||||
|
|
||||||
QBrush brush( fillColorNode().color() );
|
QColor lineColor = mLineColorNode.color();
|
||||||
rectItem->setBrush( brush );
|
QColor fillColor = mFillColorNode.color();
|
||||||
|
QColor shadowColor = mShadowColorNode.color();
|
||||||
|
|
||||||
QPen pen( lineColorNode().color() );
|
shadowColor.setAlphaF( mShadowOpacity );
|
||||||
pen.setJoinStyle( Qt::MiterJoin );
|
|
||||||
pen.setWidthF( lineWidth() );
|
|
||||||
rectItem->setPen( pen );
|
|
||||||
|
|
||||||
updateGraphicsItemMatrix( rectItem );
|
if ( fillColor.alpha() )
|
||||||
updateGraphicsItemShadow( rectItem );
|
{
|
||||||
|
painter->setPen( Qt::NoPen );
|
||||||
|
painter->setBrush( shadowColor );
|
||||||
|
|
||||||
|
if ( lineColor.alpha() )
|
||||||
|
{
|
||||||
|
/* Has FILL and OUTLINE: adjust size to account for line width. */
|
||||||
|
painter->drawRect( -mLineWidth/2, -mLineWidth/2, mW+mLineWidth, mH+mLineWidth );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Has FILL, but no OUTLINE. */
|
||||||
|
painter->drawRect( 0, 0, mW, mH );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( lineColor.alpha() )
|
||||||
|
{
|
||||||
|
/* Has only OUTLINE. */
|
||||||
|
painter->setPen( QPen( shadowColor, mLineWidth ) );
|
||||||
|
painter->setBrush( Qt::NoBrush );
|
||||||
|
|
||||||
|
painter->drawRect( 0, 0, mW, mH );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return rectItem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Update a QGraphicsItem to keep it in sync with this object
|
/// Draw object itself
|
||||||
///
|
///
|
||||||
void LabelModelBoxObject::updateGraphicsItem( QGraphicsItem* graphicsItem )
|
void LabelModelBoxObject::drawObject( QPainter* painter, bool inEditor, MergeRecord* record ) const
|
||||||
{
|
{
|
||||||
QGraphicsRectItem *rectItem = dynamic_cast<QGraphicsRectItem*>(graphicsItem);
|
/// TODO expand colors based on record
|
||||||
if ( rectItem )
|
|
||||||
{
|
|
||||||
rectItem->setRect( x0(), y0(), w(), h() );
|
|
||||||
|
|
||||||
QBrush brush( fillColorNode().color() );
|
QColor lineColor = mLineColorNode.color();
|
||||||
rectItem->setBrush( brush );
|
QColor fillColor = mFillColorNode.color();
|
||||||
|
|
||||||
QPen pen( lineColorNode().color() );
|
painter->setPen( QPen( lineColor, mLineWidth ) );
|
||||||
pen.setJoinStyle( Qt::MiterJoin );
|
painter->setBrush( fillColor );
|
||||||
pen.setWidthF( lineWidth() );
|
painter->drawRect( 0, 0, mW, mH );
|
||||||
rectItem->setPen( pen );
|
|
||||||
|
|
||||||
updateGraphicsItemMatrix( rectItem );
|
|
||||||
updateGraphicsItemShadow( rectItem );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,11 +77,11 @@ namespace glabels
|
|||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
// QGraphicsItem Method Implementations
|
// Drawing operations
|
||||||
///////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
public:
|
protected:
|
||||||
virtual QGraphicsItem* createGraphicsItem();
|
virtual void drawShadow( QPainter* painter, bool inEditor, MergeRecord* record ) const;
|
||||||
virtual void updateGraphicsItem( QGraphicsItem* graphicsItem );
|
virtual void drawObject( QPainter* painter, bool inEditor, MergeRecord* record ) const;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -20,10 +20,8 @@
|
|||||||
|
|
||||||
#include "LabelModelObject.h"
|
#include "LabelModelObject.h"
|
||||||
|
|
||||||
#include <QGraphicsDropShadowEffect>
|
|
||||||
#include <QTransform>
|
#include <QTransform>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QGraphicsItem>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "ColorNode.h"
|
#include "ColorNode.h"
|
||||||
@@ -903,30 +901,28 @@ namespace glabels
|
|||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Update Representative Graphics Item with Object's Transformation Matrix
|
/// Draw object + shadow
|
||||||
///
|
///
|
||||||
void LabelModelObject::updateGraphicsItemMatrix( QGraphicsItem* graphicsItem )
|
void LabelModelObject::draw( QPainter* painter, bool inEditor, MergeRecord* record ) const
|
||||||
{
|
{
|
||||||
graphicsItem->setTransform( mMatrix );
|
painter->save();
|
||||||
}
|
painter->translate( mX0, mY0 );
|
||||||
|
|
||||||
|
if ( mShadowState )
|
||||||
///
|
|
||||||
/// Update Representative Graphics Item with Object's Shadow Properties
|
|
||||||
///
|
|
||||||
void LabelModelObject::updateGraphicsItemShadow( QGraphicsItem* graphicsItem )
|
|
||||||
{
|
{
|
||||||
QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect();
|
painter->save();
|
||||||
|
painter->translate( mShadowX, mShadowY );
|
||||||
QColor color = mShadowColorNode.color();
|
painter->setTransform( mMatrix, true );
|
||||||
color.setAlphaF( mShadowOpacity );
|
drawShadow( painter, inEditor, record );
|
||||||
|
painter->restore();
|
||||||
shadowEffect->setColor( color );
|
|
||||||
shadowEffect->setOffset( mShadowX, mShadowY );
|
|
||||||
shadowEffect->setBlurRadius( 0 );
|
|
||||||
|
|
||||||
graphicsItem->setGraphicsEffect( shadowEffect );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
painter->setTransform( mMatrix, true );
|
||||||
|
drawObject( painter, inEditor, record );
|
||||||
|
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+23
-18
@@ -24,6 +24,7 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QTransform>
|
#include <QTransform>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
#include "ColorNode.h"
|
#include "ColorNode.h"
|
||||||
#include "TextNode.h"
|
#include "TextNode.h"
|
||||||
@@ -388,15 +389,32 @@ namespace glabels
|
|||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
// QGraphicsItem methods
|
// Drawing operations
|
||||||
///////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
public:
|
public:
|
||||||
virtual QGraphicsItem* createGraphicsItem() = 0;
|
void draw( QPainter* painter, bool inEditor, MergeRecord* record ) const;
|
||||||
virtual void updateGraphicsItem( QGraphicsItem* graphicsItem ) = 0;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateGraphicsItemMatrix( QGraphicsItem* graphicsItem );
|
virtual void drawShadow( QPainter* painter, bool inEditor, MergeRecord* record ) const = 0;
|
||||||
void updateGraphicsItemShadow( QGraphicsItem* graphicsItem );
|
virtual void drawObject( QPainter* painter, bool inEditor, MergeRecord* record ) const = 0;
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
// Protected Members
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
protected:
|
||||||
|
bool mSelectedFlag;
|
||||||
|
|
||||||
|
double mX0;
|
||||||
|
double mY0;
|
||||||
|
double mW;
|
||||||
|
double mH;
|
||||||
|
|
||||||
|
bool mShadowState;
|
||||||
|
double mShadowX;
|
||||||
|
double mShadowY;
|
||||||
|
double mShadowOpacity;
|
||||||
|
ColorNode mShadowColorNode;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
@@ -406,21 +424,8 @@ namespace glabels
|
|||||||
static int msNextId;
|
static int msNextId;
|
||||||
int mId;
|
int mId;
|
||||||
|
|
||||||
bool mSelectedFlag;
|
|
||||||
|
|
||||||
double mX0;
|
|
||||||
double mY0;
|
|
||||||
double mW;
|
|
||||||
double mH;
|
|
||||||
|
|
||||||
QTransform mMatrix;
|
QTransform mMatrix;
|
||||||
|
|
||||||
bool mShadowState;
|
|
||||||
double mShadowX;
|
|
||||||
double mShadowY;
|
|
||||||
double mShadowOpacity;
|
|
||||||
ColorNode mShadowColorNode;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -288,6 +288,7 @@ glabels::View::paintEvent( QPaintEvent* event )
|
|||||||
drawBgLayer( &painter );
|
drawBgLayer( &painter );
|
||||||
drawGridLayer( &painter );
|
drawGridLayer( &painter );
|
||||||
drawMarkupLayer( &painter );
|
drawMarkupLayer( &painter );
|
||||||
|
drawObjectsLayer( &painter );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -628,3 +629,13 @@ glabels::View::drawMarkupLayer( QPainter* painter )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Draw Objects Layer
|
||||||
|
///
|
||||||
|
void
|
||||||
|
glabels::View::drawObjectsLayer( QPainter* painter )
|
||||||
|
{
|
||||||
|
mModel->draw( painter );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user