LineItem Delegate

lineStyle
thomas_lucky13 2 years ago
parent 9a02d1a654
commit fa9c808b3f
  1. 4
      src/board/UBBoardView.cpp
  2. 32
      src/domain/UBGraphicsLineItem.cpp
  3. 6
      src/domain/UBGraphicsLineItem.h
  4. 4
      src/domain/UBGraphicsScene.cpp
  5. 3
      src/domain/UBItem.cpp

@ -67,6 +67,7 @@
#include "domain/UBGraphicsWidgetItem.h"
#include "domain/UBGraphicsPDFItem.h"
#include "domain/UBGraphicsPolygonItem.h"
#include "domain/UBGraphicsLineItem.h"
#include "domain/UBItem.h"
#include "domain/UBGraphicsMediaItem.h"
#include "domain/UBGraphicsSvgItem.h"
@ -1210,7 +1211,8 @@ void UBBoardView::mouseMoveEvent (QMouseEvent *event)
|| item->type() == UBGraphicsSvgItem::Type
|| item->type() == UBGraphicsTextItem::Type
|| item->type() == UBGraphicsStrokesGroup::Type
|| item->type() == UBGraphicsGroupContainerItem::Type) {
|| item->type() == UBGraphicsGroupContainerItem::Type
|| item->type() == UBGraphicsLineItem::Type) {
if (!mJustSelectedItems.contains(item)) {

@ -3,7 +3,6 @@
#include "frameworks/UBGeometryUtils.h"
#include "UBGraphicsScene.h"
#include "domain/UBGraphicsLineStroke.h"
#include "core/memcheck.h"
@ -59,7 +58,15 @@ UBGraphicsLineItem::UBGraphicsLineItem (const QLineF& pLine, qreal pStartWidth,
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)
@ -175,28 +182,51 @@ void UBGraphicsLineItem::copyItemParameters(UBItem *copy) const
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);
}

@ -11,7 +11,7 @@ class UBItem;
class UBGraphicsScene;
class UBGraphicsLineStroke;
class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem
class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem, public UBGraphicsItem
{
public:
@ -109,9 +109,11 @@ class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem
void setStroke(UBGraphicsLineStroke* stroke);
UBGraphicsLineStroke* stroke() const;
void SetDelegate();
protected:
void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
private:

@ -1020,6 +1020,10 @@ void UBGraphicsScene::addPolygonItemToCurrentStroke(UBGraphicsPolygonItem* polyg
void UBGraphicsScene::addLineItemToCurrentStroke(UBGraphicsLineItem* lineItem)
{
lineItem->setFlag(QGraphicsItem::ItemIsMovable, true);
lineItem->setFlag(QGraphicsItem::ItemIsSelectable, true);
lineItem->SetDelegate();
mpLastLine = lineItem;
mAddedItems.insert(lineItem);

@ -41,6 +41,7 @@
#include "domain/UBGraphicsScene.h"
#include "tools/UBGraphicsCurtainItem.h"
#include "domain/UBGraphicsItemDelegate.h"
#include "domain/UBGraphicsLineItem.h"
UBItem::UBItem()
: mUuid(QUuid())
@ -135,6 +136,8 @@ UBGraphicsItemDelegate *UBGraphicsItem::Delegate(QGraphicsItem *pItem)
case UBGraphicsCurtainItem::Type :
result = (static_cast<UBGraphicsCurtainItem*>(pItem))->Delegate();
break;
case UBGraphicsLineItem::Type :
result = (static_cast<UBGraphicsLineItem*>(pItem))->Delegate();
}
return result;

Loading…
Cancel
Save