Added object layer to view. Added draw methods to objects.
This commit is contained in:
@@ -1056,5 +1056,17 @@ namespace glabels
|
||||
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 <QList>
|
||||
#include <QPainter>
|
||||
|
||||
#include "MergeRecord.h"
|
||||
#include "libglabels/Template.h"
|
||||
|
||||
|
||||
@@ -166,6 +168,13 @@ namespace glabels
|
||||
void setSelectionFillColorNode( ColorNode fillColorNode );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Drawing operations
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void draw( QPainter* painter, bool inEditor = true, MergeRecord* record = 0 ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Slots
|
||||
/////////////////////////////////
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include "LabelModelBoxObject.h"
|
||||
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QBrush>
|
||||
#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() );
|
||||
rectItem->setBrush( brush );
|
||||
QColor lineColor = mLineColorNode.color();
|
||||
QColor fillColor = mFillColorNode.color();
|
||||
QColor shadowColor = mShadowColorNode.color();
|
||||
|
||||
QPen pen( lineColorNode().color() );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
pen.setWidthF( lineWidth() );
|
||||
rectItem->setPen( pen );
|
||||
shadowColor.setAlphaF( mShadowOpacity );
|
||||
|
||||
updateGraphicsItemMatrix( rectItem );
|
||||
updateGraphicsItemShadow( rectItem );
|
||||
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( -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);
|
||||
if ( rectItem )
|
||||
{
|
||||
rectItem->setRect( x0(), y0(), w(), h() );
|
||||
/// TODO expand colors based on record
|
||||
|
||||
QBrush brush( fillColorNode().color() );
|
||||
rectItem->setBrush( brush );
|
||||
QColor lineColor = mLineColorNode.color();
|
||||
QColor fillColor = mFillColorNode.color();
|
||||
|
||||
QPen pen( lineColorNode().color() );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
pen.setWidthF( lineWidth() );
|
||||
rectItem->setPen( pen );
|
||||
|
||||
updateGraphicsItemMatrix( rectItem );
|
||||
updateGraphicsItemShadow( rectItem );
|
||||
}
|
||||
painter->setPen( QPen( lineColor, mLineWidth ) );
|
||||
painter->setBrush( fillColor );
|
||||
painter->drawRect( 0, 0, mW, mH );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -77,11 +77,11 @@ namespace glabels
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// QGraphicsItem Method Implementations
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
virtual QGraphicsItem* createGraphicsItem();
|
||||
virtual void updateGraphicsItem( QGraphicsItem* graphicsItem );
|
||||
protected:
|
||||
virtual void drawShadow( QPainter* painter, bool inEditor, MergeRecord* record ) const;
|
||||
virtual void drawObject( QPainter* painter, bool inEditor, MergeRecord* record ) const;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -20,10 +20,8 @@
|
||||
|
||||
#include "LabelModelObject.h"
|
||||
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#include <QTransform>
|
||||
#include <QFont>
|
||||
#include <QGraphicsItem>
|
||||
#include <algorithm>
|
||||
|
||||
#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 )
|
||||
{
|
||||
painter->save();
|
||||
painter->translate( mShadowX, mShadowY );
|
||||
painter->setTransform( mMatrix, true );
|
||||
drawShadow( painter, inEditor, record );
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
painter->setTransform( mMatrix, true );
|
||||
drawObject( painter, inEditor, record );
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Update Representative Graphics Item with Object's Shadow Properties
|
||||
///
|
||||
void LabelModelObject::updateGraphicsItemShadow( QGraphicsItem* graphicsItem )
|
||||
{
|
||||
QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect();
|
||||
|
||||
QColor color = mShadowColorNode.color();
|
||||
color.setAlphaF( mShadowOpacity );
|
||||
|
||||
shadowEffect->setColor( color );
|
||||
shadowEffect->setOffset( mShadowX, mShadowY );
|
||||
shadowEffect->setBlurRadius( 0 );
|
||||
|
||||
graphicsItem->setGraphicsEffect( shadowEffect );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+23
-18
@@ -24,6 +24,7 @@
|
||||
#include <QObject>
|
||||
#include <QFont>
|
||||
#include <QTransform>
|
||||
#include <QPainter>
|
||||
|
||||
#include "ColorNode.h"
|
||||
#include "TextNode.h"
|
||||
@@ -388,15 +389,32 @@ namespace glabels
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// QGraphicsItem methods
|
||||
// Drawing operations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
virtual QGraphicsItem* createGraphicsItem() = 0;
|
||||
virtual void updateGraphicsItem( QGraphicsItem* graphicsItem ) = 0;
|
||||
void draw( QPainter* painter, bool inEditor, MergeRecord* record ) const;
|
||||
|
||||
protected:
|
||||
void updateGraphicsItemMatrix( QGraphicsItem* graphicsItem );
|
||||
void updateGraphicsItemShadow( QGraphicsItem* graphicsItem );
|
||||
virtual void drawShadow( QPainter* painter, bool inEditor, MergeRecord* record ) const = 0;
|
||||
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;
|
||||
int mId;
|
||||
|
||||
bool mSelectedFlag;
|
||||
|
||||
double mX0;
|
||||
double mY0;
|
||||
double mW;
|
||||
double mH;
|
||||
|
||||
QTransform mMatrix;
|
||||
|
||||
bool mShadowState;
|
||||
double mShadowX;
|
||||
double mShadowY;
|
||||
double mShadowOpacity;
|
||||
ColorNode mShadowColorNode;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -288,6 +288,7 @@ glabels::View::paintEvent( QPaintEvent* event )
|
||||
drawBgLayer( &painter );
|
||||
drawGridLayer( &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