Added object layer to view. Added draw methods to objects.

This commit is contained in:
Jim Evins
2015-08-12 12:09:11 -04:00
parent 527d2e73dc
commit 781f299394
7 changed files with 121 additions and 75 deletions
+12
View File
@@ -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 );
}
}
} }
+9
View File
@@ -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
///////////////////////////////// /////////////////////////////////
+44 -31
View File
@@ -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
QColor lineColor = mLineColorNode.color();
QColor fillColor = mFillColorNode.color();
QColor shadowColor = mShadowColorNode.color();
QBrush brush( fillColorNode().color() ); shadowColor.setAlphaF( mShadowOpacity );
rectItem->setBrush( brush );
QPen pen( lineColorNode().color() ); if ( fillColor.alpha() )
pen.setJoinStyle( Qt::MiterJoin ); {
pen.setWidthF( lineWidth() ); painter->setPen( Qt::NoPen );
rectItem->setPen( pen ); painter->setBrush( shadowColor );
updateGraphicsItemMatrix( rectItem ); if ( lineColor.alpha() )
updateGraphicsItemShadow( rectItem ); {
/* 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 );
return rectItem; painter->drawRect( 0, 0, mW, mH );
}
}
} }
/// ///
/// 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 )
{ QColor lineColor = mLineColorNode.color();
rectItem->setRect( x0(), y0(), w(), h() ); QColor fillColor = mFillColorNode.color();
QBrush brush( fillColorNode().color() ); painter->setPen( QPen( lineColor, mLineWidth ) );
rectItem->setBrush( brush ); painter->setBrush( fillColor );
painter->drawRect( 0, 0, mW, mH );
QPen pen( lineColorNode().color() );
pen.setJoinStyle( Qt::MiterJoin );
pen.setWidthF( lineWidth() );
rectItem->setPen( pen );
updateGraphicsItemMatrix( rectItem );
updateGraphicsItemShadow( rectItem );
}
} }
} }
+4 -4
View File
@@ -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;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
+18 -22
View File
@@ -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 )
{
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
View File
@@ -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;
}; };
} }
+11
View File
@@ -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 );
}