UBGraphicsLineItem

lineStyle
thomas_lucky13 2 years ago
parent 9f1c38c36d
commit dbfe174730
  1. 1
      src/core/UB.h
  2. 191
      src/domain/UBGraphicsLineItem.cpp
  3. 134
      src/domain/UBGraphicsLineItem.h
  4. 2
      src/domain/domain.pri

@ -173,6 +173,7 @@ struct UBGraphicsItemType
GraphicsWidgetItemType, //65556 GraphicsWidgetItemType, //65556
UserTypesCount, //65557 UserTypesCount, //65557
AxesItemType, //65558 AxesItemType, //65558
LineItemType, //65559
SelectionFrameType // this line must be the last line in this enum because it is types counter. SelectionFrameType // this line must be the last line in this enum because it is types counter.
}; };
}; };

@ -0,0 +1,191 @@
#include "UBGraphicsLineItem.h"
#include "frameworks/UBGeometryUtils.h"
#include "UBGraphicsScene.h"
#include "domain/UBGraphicsPolygonItem.h"
#include "domain/UBGraphicsStroke.h"
#include "core/memcheck.h"
#include <iostream>
UBGraphicsLineItem::UBGraphicsLineItem (QGraphicsItem * parent)
: QGraphicsLineItem(parent)
, mHasAlpha(false)
, mOriginalWidth(-1)
, mIsNominalLine(false)
, mStroke(0)
, mpGroup(NULL)
{
// NOOP
initialize();
}
UBGraphicsLineItem::UBGraphicsLineItem (const QLineF & line, QGraphicsItem * parent)
: QGraphicsLineItem(line, parent)
, mOriginalWidth(-1)
, mIsNominalLine(false)
, mStroke(0)
, mpGroup(NULL)
{
// NOOP
initialize();
}
UBGraphicsLineItem::UBGraphicsLineItem (const QLineF& pLine, qreal pWidth)
: QGraphicsLineItem(pLine)
, mOriginalLine(pLine)
, mOriginalWidth(pWidth)
, mIsNominalLine(true)
, mStroke(0)
, mpGroup(NULL)
{
// NOOP
initialize();
}
UBGraphicsLineItem::UBGraphicsLineItem (const QLineF& pLine, qreal pStartWidth, qreal pEndWidth)
: QGraphicsLineItem(pLine)
, mOriginalLine(pLine)
, mOriginalWidth(pEndWidth)
, mIsNominalLine(true)
, mStroke(0)
, mpGroup(NULL)
{
// NOOP
initialize();
}
void UBGraphicsLineItem::initialize()
{
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::DrawingItem)); //Necessary to set if we want z value to be assigned correctly
setUuid(QUuid::createUuid());
}
void UBGraphicsLineItem::setUuid(const QUuid &pUuid)
{
UBItem::setUuid(pUuid);
setData(UBGraphicsItemData::ItemUuid, QVariant(pUuid)); //store item uuid inside the QGraphicsItem to fast operations with Items on the scene
}
void UBGraphicsLineItem::clearStroke()
{
if (mStroke!=NULL)
{
//mStroke->remove(this);
if (mStroke->polygons().empty())
delete mStroke;
mStroke = NULL;
}
}
UBGraphicsLineItem::~UBGraphicsLineItem()
{
//clearStroke();
}
void UBGraphicsLineItem::setStrokesGroup(UBGraphicsStrokesGroup *group)
{
mpGroup = group;
}
void UBGraphicsLineItem::setStroke(UBGraphicsStroke* stroke)
{
if (stroke) {
clearStroke();
mStroke = stroke;
//mStroke->addPolygon(this);
}
}
UBGraphicsStroke* UBGraphicsLineItem::stroke() const
{
return mStroke;
}
void UBGraphicsLineItem::setColor(const QColor& pColor)
{
QPen pen = QPen(pColor);
pen.setStyle(style());
if (style()==Qt::PenStyle::DotLine)
{
pen.setCapStyle(Qt::PenCapStyle::RoundCap);
}
pen.setWidth(mOriginalWidth);
QGraphicsLineItem::setPen(pen);
mHasAlpha = (pColor.alphaF() < 1.0);
}
QColor UBGraphicsLineItem::color() const
{
return QGraphicsLineItem::pen().color();
}
void UBGraphicsLineItem::setStyle(const Qt::PenStyle& style)
{
QPen pen = QPen(color());
pen.setStyle(style);
if (style==Qt::PenStyle::DotLine)
{
pen.setCapStyle(Qt::PenCapStyle::RoundCap);
}
pen.setWidth(mOriginalWidth);
QGraphicsLineItem::setPen(pen);
}
Qt::PenStyle UBGraphicsLineItem::style() const
{
return QGraphicsLineItem::pen().style();
}
UBItem* UBGraphicsLineItem::deepCopy() const
{
UBGraphicsLineItem* copy = new UBGraphicsLineItem(line());
copyItemParameters(copy);
return copy;
}
void UBGraphicsLineItem::copyItemParameters(UBItem *copy) const
{
UBGraphicsLineItem *cp = dynamic_cast<UBGraphicsLineItem*>(copy);
if (cp)
{
cp->mOriginalLine = this->mOriginalLine;
cp->mOriginalWidth = this->mOriginalWidth;
cp->mIsNominalLine = this->mIsNominalLine;
cp->setTransform(transform());
cp->setPen(this->pen());
cp->mHasAlpha = this->mHasAlpha;
cp->setColorOnDarkBackground(this->colorOnDarkBackground());
cp->setColorOnLightBackground(this->colorOnLightBackground());
cp->setZValue(this->zValue());
cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType));
}
}
void UBGraphicsLineItem::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
{
if(mHasAlpha && scene() && scene()->isLightBackground())
painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
painter->setRenderHints(QPainter::Antialiasing);
QGraphicsLineItem::paint(painter, option, widget);
}
UBGraphicsScene* UBGraphicsLineItem::scene()
{
return qobject_cast<UBGraphicsScene*>(QGraphicsLineItem::scene());
}

@ -0,0 +1,134 @@
#ifndef UBGRAPHICSLINEITEM_H
#define UBGRAPHICSLINEITEM_H
#include <QtGui>
#include "core/UB.h"
#include "UBItem.h"
#include "UBGraphicsStrokesGroup.h"
#include "domain/UBGraphicsGroupContainerItem.h"
class UBItem;
class UBGraphicsScene;
class UBGraphicsStroke;
class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem
{
public:
UBGraphicsLineItem(QGraphicsItem * parent = 0 );
UBGraphicsLineItem(const QLineF& line, qreal pWidth);
UBGraphicsLineItem(const QLineF& pLine, qreal pStartWidth, qreal pEndWidth);
UBGraphicsLineItem(const QLineF & line, QGraphicsItem * parent = 0);
~UBGraphicsLineItem();
void initialize();
void setUuid(const QUuid &pUuid);
void setStrokesGroup(UBGraphicsStrokesGroup* group);
UBGraphicsStrokesGroup* strokesGroup() const{return mpGroup;}
void setColor(const QColor& color);
void setStyle(const Qt::PenStyle& style);
QColor color() const;
Qt::PenStyle style() const;
virtual UBGraphicsScene* scene();
inline void subtract(UBGraphicsLineItem *pi)
{
if (boundingRect().intersects(pi->boundingRect()))
{
//QLineF subtractedLine = line().substracted(pi->line());
/*if (line() != subtractedLine)
{
mIsNominalLine = false;
QGraphicsLineItem::setLine(subtractedLine);
}*/
}
}
inline void subtractIntersecting(UBGraphicsLineItem *pi)
{
/*QLineF subtractedLine = line().substracted(pi->line())
if (line() != subtractedLine)
{
mIsNominalLine = false;
QGraphicsLineItem::setLine(subtractedLine);
}*/
}
enum { Type = UBGraphicsItemType::LineItemType };
virtual int type() const
{
return Type;
}
void setLine(const QLineF pLine)
{
mIsNominalLine = false;
QGraphicsLineItem::setLine(pLine);
}
virtual UBItem* deepCopy() const;
virtual void copyItemParameters(UBItem *copy) const;
QLineF originalLine() { return mOriginalLine;}
qreal originalWidth() { return mOriginalWidth;}
bool isNominalLine() {return mIsNominalLine;}
void setNominalLine(bool isNominalLine) { mIsNominalLine = isNominalLine; }
QColor colorOnDarkBackground() const
{
return mColorOnDarkBackground;
}
void setColorOnDarkBackground(QColor pColorOnDarkBackground)
{
mColorOnDarkBackground = pColorOnDarkBackground;
}
QColor colorOnLightBackground() const
{
return mColorOnLightBackground;
}
void setColorOnLightBackground(QColor pColorOnLightBackground)
{
mColorOnLightBackground = pColorOnLightBackground;
}
void setStroke(UBGraphicsStroke* stroke);
UBGraphicsStroke* stroke() const;
protected:
void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
private:
void clearStroke();
bool mHasAlpha;
QLineF mOriginalLine;
qreal mOriginalWidth;
bool mIsNominalLine;
QColor mColorOnDarkBackground;
QColor mColorOnLightBackground;
UBGraphicsStroke* mStroke;
UBGraphicsStrokesGroup* mpGroup;
};
#endif // UBGRAPHICSLINEITEM_H

@ -6,6 +6,7 @@ HEADERS += src/domain/UBGraphicsScene.h \
src/domain/UBPageSizeUndoCommand.h \ src/domain/UBPageSizeUndoCommand.h \
src/domain/UBGraphicsProxyWidget.h \ src/domain/UBGraphicsProxyWidget.h \
src/domain/UBGraphicsSvgItem.h \ src/domain/UBGraphicsSvgItem.h \
src/domain/UBGraphicsLineItem.h \
src/domain/UBGraphicsPolygonItem.h \ src/domain/UBGraphicsPolygonItem.h \
src/domain/UBItem.h \ src/domain/UBItem.h \
src/domain/UBGraphicsWidgetItem.h \ src/domain/UBGraphicsWidgetItem.h \
@ -35,6 +36,7 @@ SOURCES += src/domain/UBGraphicsScene.cpp \
src/domain/UBPageSizeUndoCommand.cpp \ src/domain/UBPageSizeUndoCommand.cpp \
src/domain/UBGraphicsProxyWidget.cpp \ src/domain/UBGraphicsProxyWidget.cpp \
src/domain/UBGraphicsSvgItem.cpp \ src/domain/UBGraphicsSvgItem.cpp \
src/domain/UBGraphicsLineItem.cpp \
src/domain/UBGraphicsPolygonItem.cpp \ src/domain/UBGraphicsPolygonItem.cpp \
src/domain/UBItem.cpp \ src/domain/UBItem.cpp \
src/domain/UBGraphicsWidgetItem.cpp \ src/domain/UBGraphicsWidgetItem.cpp \

Loading…
Cancel
Save