Compare commits
10 Commits
Author | SHA1 | Date |
---|---|---|
thomas_lucky13 | b70db94681 | 2 years ago |
thomas_lucky13 | a8a0c0b720 | 2 years ago |
thomas_lucky13 | 9194120bc8 | 2 years ago |
thomas_lucky13 | e6d6d29566 | 2 years ago |
thomas_lucky13 | fa9c808b3f | 2 years ago |
thomas_lucky13 | 9a02d1a654 | 2 years ago |
thomas_lucky13 | 67a6ce6c6c | 2 years ago |
thomas_lucky13 | 8095c5b5b7 | 2 years ago |
thomas_lucky13 | dbfe174730 | 2 years ago |
thomas_lucky13 | 9f1c38c36d | 2 years ago |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
@ -0,0 +1,191 @@ |
||||
#include "UBGraphicsLineItem.h" |
||||
|
||||
#include "frameworks/UBGeometryUtils.h" |
||||
#include "UBGraphicsScene.h" |
||||
#include "core/memcheck.h" |
||||
|
||||
|
||||
UBGraphicsLineItem::UBGraphicsLineItem (QGraphicsItem * parent) |
||||
: QGraphicsLineItem(parent) |
||||
, mHasAlpha(false) |
||||
, mOriginalWidth(-1) |
||||
, mIsNominalLine(false) |
||||
{ |
||||
// NOOP
|
||||
initialize(); |
||||
} |
||||
|
||||
UBGraphicsLineItem::UBGraphicsLineItem (const QLineF & line, QGraphicsItem * parent) |
||||
: QGraphicsLineItem(line, parent) |
||||
, mOriginalWidth(-1) |
||||
, mIsNominalLine(false) |
||||
{ |
||||
// NOOP
|
||||
initialize(); |
||||
} |
||||
|
||||
|
||||
UBGraphicsLineItem::UBGraphicsLineItem (const QLineF& pLine, qreal pWidth) |
||||
: QGraphicsLineItem(pLine) |
||||
, mOriginalLine(pLine) |
||||
, mOriginalWidth(pWidth) |
||||
, mIsNominalLine(true) |
||||
{ |
||||
// NOOP
|
||||
initialize(); |
||||
} |
||||
|
||||
UBGraphicsLineItem::UBGraphicsLineItem (const QLineF& pLine, qreal pStartWidth, qreal pEndWidth) |
||||
: QGraphicsLineItem(pLine) |
||||
, mOriginalLine(pLine) |
||||
, mOriginalWidth(pEndWidth) |
||||
, mIsNominalLine(true) |
||||
{ |
||||
// NOOP
|
||||
initialize(); |
||||
} |
||||
|
||||
|
||||
void UBGraphicsLineItem::initialize() |
||||
{ |
||||
//setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::DrawingItem)); //Necessary to set if we want z value to be assigned correctly
|
||||
setDelegate(new UBGraphicsItemDelegate(this, 0, GF_COMMON |
||||
| GF_RESPECT_RATIO |
||||
| GF_REVOLVABLE |
||||
| GF_FLIPPABLE_ALL_AXIS)); |
||||
setUuid(QUuid::createUuid()); |
||||
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
|
||||
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); |
||||
setFlag(QGraphicsItem::ItemIsSelectable, true); |
||||
setFlag(QGraphicsItem::ItemIsMovable, true); |
||||
} |
||||
|
||||
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
|
||||
} |
||||
|
||||
UBGraphicsLineItem::~UBGraphicsLineItem() |
||||
{ |
||||
|
||||
} |
||||
|
||||
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(); |
||||
} |
||||
|
||||
QList<QPointF> UBGraphicsLineItem::linePoints() |
||||
{ |
||||
QList<QPointF> points = QList<QPointF>(); |
||||
qreal incr = 1/line().length(); |
||||
if (incr<0) incr*=-1; |
||||
if (incr>0) |
||||
{ |
||||
for (qreal t = 0; t <= 1; t+=incr) |
||||
{ |
||||
points.push_back(line().pointAt(t)); |
||||
} |
||||
} |
||||
return points; |
||||
} |
||||
|
||||
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->setPos(pos()); |
||||
cp->setPen(this->pen()); |
||||
cp->mHasAlpha = this->mHasAlpha; |
||||
|
||||
cp->setColorOnDarkBackground(this->colorOnDarkBackground()); |
||||
cp->setColorOnLightBackground(this->colorOnLightBackground()); |
||||
|
||||
cp->setFlag(QGraphicsItem::ItemIsMovable, true); |
||||
cp->setFlag(QGraphicsItem::ItemIsSelectable, true); |
||||
cp->setZValue(this->zValue()); |
||||
cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); |
||||
cp->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); |
||||
} |
||||
} |
||||
|
||||
void UBGraphicsLineItem::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) |
||||
{ |
||||
QStyleOptionGraphicsItem styleOption = QStyleOptionGraphicsItem(*option); |
||||
if(mHasAlpha && scene() && scene()->isLightBackground()) |
||||
painter->setCompositionMode(QPainter::CompositionMode_SourceOver); |
||||
|
||||
painter->setRenderHints(QPainter::Antialiasing); |
||||
|
||||
QGraphicsLineItem::paint(painter, option, widget); |
||||
Delegate()->postpaint(painter, &styleOption, widget); |
||||
} |
||||
|
||||
UBGraphicsScene* UBGraphicsLineItem::scene() |
||||
{ |
||||
return qobject_cast<UBGraphicsScene*>(QGraphicsLineItem::scene()); |
||||
} |
||||
|
||||
void UBGraphicsLineItem::SetDelegate() |
||||
{ |
||||
Delegate()->createControls(); |
||||
} |
||||
|
||||
QVariant UBGraphicsLineItem::itemChange(GraphicsItemChange change, const QVariant &value) |
||||
{ |
||||
QVariant newValue = Delegate()->itemChange(change, value); |
||||
UBGraphicsItem *item = dynamic_cast<UBGraphicsItem*>(this); |
||||
if (item) |
||||
{ |
||||
item->Delegate()->positionHandles(); |
||||
} |
||||
|
||||
return QGraphicsItem::itemChange(change, newValue); |
||||
} |
@ -0,0 +1,100 @@ |
||||
#ifndef UBGRAPHICSLINEITEM_H |
||||
#define UBGRAPHICSLINEITEM_H |
||||
|
||||
#include <QtGui> |
||||
#include "core/UB.h" |
||||
#include "UBItem.h" |
||||
|
||||
class UBItem; |
||||
class UBGraphicsScene; |
||||
|
||||
class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem, public UBGraphicsItem |
||||
{ |
||||
|
||||
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 setColor(const QColor& color); |
||||
void setStyle(const Qt::PenStyle& style); |
||||
|
||||
QColor color() const; |
||||
Qt::PenStyle style() const; |
||||
|
||||
virtual UBGraphicsScene* scene(); |
||||
|
||||
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; } |
||||
|
||||
QList<QPointF> linePoints(); |
||||
|
||||
QColor colorOnDarkBackground() const |
||||
{ |
||||
return mColorOnDarkBackground; |
||||
} |
||||
|
||||
void setColorOnDarkBackground(QColor pColorOnDarkBackground) |
||||
{ |
||||
mColorOnDarkBackground = pColorOnDarkBackground; |
||||
} |
||||
|
||||
QColor colorOnLightBackground() const |
||||
{ |
||||
return mColorOnLightBackground; |
||||
} |
||||
|
||||
void setColorOnLightBackground(QColor pColorOnLightBackground) |
||||
{ |
||||
mColorOnLightBackground = pColorOnLightBackground; |
||||
} |
||||
|
||||
void SetDelegate(); |
||||
|
||||
protected: |
||||
void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget); |
||||
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); |
||||
|
||||
private: |
||||
|
||||
bool mHasAlpha; |
||||
|
||||
QLineF mOriginalLine; |
||||
qreal mOriginalWidth; |
||||
bool mIsNominalLine; |
||||
|
||||
QColor mColorOnDarkBackground; |
||||
QColor mColorOnLightBackground; |
||||
|
||||
}; |
||||
|
||||
#endif // UBGRAPHICSLINEITEM_H
|
||||
|
Loading…
Reference in new issue