new Line drawing

lineStyle
thomas_lucky13 3 years ago
parent 8095c5b5b7
commit 67a6ce6c6c
  1. 65
      src/domain/UBGraphicsScene.cpp
  2. 5
      src/domain/UBGraphicsScene.h

@ -70,6 +70,7 @@
#include "UBGraphicsPixmapItem.h"
#include "UBGraphicsSvgItem.h"
#include "UBGraphicsPolygonItem.h"
#include "UBGraphicsLineItem.h"
#include "UBGraphicsMediaItem.h"
#include "UBGraphicsWidgetItem.h"
#include "UBGraphicsPDFItem.h"
@ -667,7 +668,16 @@ bool UBGraphicsScene::inputDeviceRelease(int tool)
if (currentTool == UBStylusTool::Eraser)
hideEraser();
if(currentTool == UBStylusTool::Line)
{
if (mUndoRedoStackEnabled)
{ //should be deleted after scene own undo stack implemented
UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, NULL, mpLastLine);
UBApplication::undoStack->push(uc);
mAddedItems.clear();
}
} else{
UBDrawingController *dc = UBDrawingController::drawingController();
@ -741,6 +751,7 @@ bool UBGraphicsScene::inputDeviceRelease(int tool)
mCurrentPolygon = 0;
}
}
}
if (mRemovedItems.size() > 0 || mAddedItems.size() > 0)
{
@ -943,8 +954,17 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &startWid
mAddedItems.clear();
}
UBGraphicsPolygonItem *polygonItem = lineToPolygonItem(QLineF(mPreviousPoint, pEndPoint), initialWidth, endWidth);
addPolygonItemToCurrentStroke(polygonItem);
if (UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Line)
{
UBGraphicsPolygonItem *polygonItem = lineToPolygonItem(QLineF(mPreviousPoint, pEndPoint), initialWidth, endWidth);
addPolygonItemToCurrentStroke(polygonItem);
} else
{
UBGraphicsLineItem *lineItem = new UBGraphicsLineItem(QLineF(mPreviousPoint, pEndPoint), initialWidth, endWidth);
initLineItem(lineItem);
addLineItemToCurrentStroke(lineItem);
}
if (!bLineStyle) {
mPreviousPoint = pEndPoint;
@ -998,6 +1018,16 @@ void UBGraphicsScene::addPolygonItemToCurrentStroke(UBGraphicsPolygonItem* polyg
}
void UBGraphicsScene::addLineItemToCurrentStroke(UBGraphicsLineItem* lineItem)
{
mpLastLine = lineItem;
mAddedItems.insert(lineItem);
// Here we add the item to the scene
addItem(lineItem);
}
void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
{
const QLineF line(mPreviousPoint, pEndPoint);
@ -1271,6 +1301,37 @@ void UBGraphicsScene::initPolygonItem(UBGraphicsPolygonItem* polygonItem)
polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic));
}
void UBGraphicsScene::initLineItem(UBGraphicsLineItem* lineItem)
{
QColor colorOnDarkBG;
QColor colorOnLightBG;
if (UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Marker)
{
colorOnDarkBG = UBApplication::boardController->penColorOnDarkBackground();
colorOnLightBG = UBApplication::boardController->penColorOnLightBackground();
}
if (mDarkBackground)
{
lineItem->setColor(colorOnDarkBG);
}
else
{
lineItem->setColor(colorOnLightBG);
}
lineItem->setColorOnDarkBackground(colorOnDarkBG);
lineItem->setColorOnLightBackground(colorOnLightBG);
lineItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic));
//lineItem->setStyle(UBSettings::settings()->currentLineStyle());
QPen linePen = lineItem->pen();
linePen.setWidth(lineItem->originalWidth());
lineItem->setPen(linePen);
}
UBGraphicsPolygonItem* UBGraphicsScene::arcToPolygonItem(const QLineF& pStartRadius, qreal pSpanAngle, qreal pWidth)
{
QPolygonF polygon = UBGeometryUtils::arcToPolygon(pStartRadius, pSpanAngle, pWidth);

@ -41,6 +41,7 @@ class UBGraphicsPixmapItem;
class UBGraphicsProxyWidget;
class UBGraphicsSvgItem;
class UBGraphicsPolygonItem;
class UBGraphicsLineItem;
class UBGraphicsMediaItem;
class UBGraphicsWidgetItem;
class UBGraphicsW3CWidgetItem;
@ -400,8 +401,11 @@ public slots:
UBGraphicsPolygonItem* curveToPolygonItem(const QList<QPair<QPointF, qreal> > &points);
UBGraphicsPolygonItem* curveToPolygonItem(const QList<QPointF> &points, qreal startWidth, qreal endWidth);
void addPolygonItemToCurrentStroke(UBGraphicsPolygonItem* polygonItem);
void addLineItemToCurrentStroke(UBGraphicsLineItem* lineItem);
void initPolygonItem(UBGraphicsPolygonItem*);
void initLineItem(UBGraphicsLineItem*);
void drawEraser(const QPointF& pEndPoint, bool pressed = true);
void redrawEraser(bool pressed);
@ -493,6 +497,7 @@ public slots:
UBZLayerController *mZLayerController;
UBGraphicsPolygonItem* mpLastPolygon;
UBGraphicsPolygonItem* mTempPolygon;
UBGraphicsLineItem* mpLastLine;
bool mDrawWithCompass;
UBGraphicsPolygonItem *mCurrentPolygon;

Loading…
Cancel
Save