Compare commits

...

4 Commits

  1. 21
      resources/forms/mainWindow.ui
  2. 3
      src/api/UBWidgetUniboardAPI.cpp
  3. 2
      src/board/UBBoardController.cpp
  4. 5
      src/board/UBBoardView.cpp
  5. 22
      src/board/UBDrawingController.cpp
  6. 1
      src/board/UBDrawingController.h
  7. 2
      src/core/UB.h
  8. 112
      src/domain/UBGraphicsScene.cpp
  9. 6
      src/domain/UBGraphicsScene.h
  10. 206
      src/domain/UBGraphicsVectorItem.cpp
  11. 107
      src/domain/UBGraphicsVectorItem.h
  12. 2
      src/domain/domain.pri
  13. 1
      src/gui/UBStylusPalette.cpp
  14. 1
      src/gui/UBToolbarButtonGroup.cpp

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1342</width> <width>1342</width>
<height>223</height> <height>268</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -1702,6 +1702,25 @@
<string>Draw intermediate grid lines</string> <string>Draw intermediate grid lines</string>
</property> </property>
</action> </action>
<action name="actionVector">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../OpenBoard.qrc">
<normaloff>:/images/stylusPalette/line.png</normaloff>
<normalon>:/images/stylusPalette/lineOn.png</normalon>:/images/stylusPalette/line.png</iconset>
</property>
<property name="text">
<string>Vector</string>
</property>
<property name="toolTip">
<string>Draw Vectors</string>
</property>
<property name="shortcut">
<string>Ctrl+J</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="../OpenBoard.qrc"/> <include location="../OpenBoard.qrc"/>

@ -144,6 +144,9 @@ void UBWidgetUniboardAPI::setTool(const QString& toolString)
else if (lower == "line") else if (lower == "line")
{ {
UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Line); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Line);
} else if (lower == "vector")
{
UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Vector);
} }
} }

@ -1981,6 +1981,7 @@ void UBBoardController::setColorIndex(int pColorIndex)
if (UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Marker && if (UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Marker &&
UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Line && UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Line &&
UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Vector &&
UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Text && UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Text &&
UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Selector) UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Selector)
{ {
@ -1989,6 +1990,7 @@ void UBBoardController::setColorIndex(int pColorIndex)
if (UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Pen || if (UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Pen ||
UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line || UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line ||
UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Vector ||
UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Text || UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Text ||
UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Selector) UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Selector)
{ {

@ -367,7 +367,7 @@ void UBBoardView::tabletEvent (QTabletEvent * event)
QPointF scenePos = viewportTransform ().inverted ().map (tabletPos); QPointF scenePos = viewportTransform ().inverted ().map (tabletPos);
qreal pressure = 1.0; qreal pressure = 1.0;
if (((currentTool == UBStylusTool::Pen || currentTool == UBStylusTool::Line) && mPenPressureSensitive) || if (((currentTool == UBStylusTool::Pen || currentTool == UBStylusTool::Line || currentTool == UBStylusTool::Vector) && mPenPressureSensitive) ||
(currentTool == UBStylusTool::Marker && mMarkerPressureSensitive)) (currentTool == UBStylusTool::Marker && mMarkerPressureSensitive))
pressure = event->pressure (); pressure = event->pressure ();
else{ else{
@ -1821,6 +1821,9 @@ void UBBoardView::setToolCursor (int tool)
case UBStylusTool::Line: case UBStylusTool::Line:
controlViewport->setCursor (UBResources::resources ()->penCursor); controlViewport->setCursor (UBResources::resources ()->penCursor);
break; break;
case UBStylusTool::Vector:
controlViewport->setCursor (UBResources::resources ()->penCursor);
break;
case UBStylusTool::Text: case UBStylusTool::Text:
controlViewport->setCursor (UBResources::resources ()->textCursor); controlViewport->setCursor (UBResources::resources ()->textCursor);
break; break;

@ -75,6 +75,7 @@ UBDrawingController::UBDrawingController(QObject * parent)
connect(UBApplication::mainWindow->actionZoomOut, SIGNAL(triggered(bool)), this, SLOT(zoomOutToolSelected(bool))); connect(UBApplication::mainWindow->actionZoomOut, SIGNAL(triggered(bool)), this, SLOT(zoomOutToolSelected(bool)));
connect(UBApplication::mainWindow->actionPointer, SIGNAL(triggered(bool)), this, SLOT(pointerToolSelected(bool))); connect(UBApplication::mainWindow->actionPointer, SIGNAL(triggered(bool)), this, SLOT(pointerToolSelected(bool)));
connect(UBApplication::mainWindow->actionLine, SIGNAL(triggered(bool)), this, SLOT(lineToolSelected(bool))); connect(UBApplication::mainWindow->actionLine, SIGNAL(triggered(bool)), this, SLOT(lineToolSelected(bool)));
connect(UBApplication::mainWindow->actionVector, SIGNAL(triggered(bool)), this, SLOT(vectorToolSelected(bool)));
connect(UBApplication::mainWindow->actionText, SIGNAL(triggered(bool)), this, SLOT(textToolSelected(bool))); connect(UBApplication::mainWindow->actionText, SIGNAL(triggered(bool)), this, SLOT(textToolSelected(bool)));
connect(UBApplication::mainWindow->actionCapture, SIGNAL(triggered(bool)), this, SLOT(captureToolSelected(bool))); connect(UBApplication::mainWindow->actionCapture, SIGNAL(triggered(bool)), this, SLOT(captureToolSelected(bool)));
} }
@ -104,12 +105,12 @@ void UBDrawingController::setStylusTool(int tool)
{ {
UBApplication::boardController->activeScene()->deselectAllItems(); UBApplication::boardController->activeScene()->deselectAllItems();
if (mStylusTool == UBStylusTool::Pen || mStylusTool == UBStylusTool::Marker if (mStylusTool == UBStylusTool::Pen || mStylusTool == UBStylusTool::Marker
|| mStylusTool == UBStylusTool::Line) || mStylusTool == UBStylusTool::Line || mStylusTool == UBStylusTool::Vector)
{ {
mLatestDrawingTool = mStylusTool; mLatestDrawingTool = mStylusTool;
} }
if (tool == UBStylusTool::Pen || tool == UBStylusTool::Line) if (tool == UBStylusTool::Pen || tool == UBStylusTool::Line || tool == UBStylusTool::Vector)
{ {
emit lineWidthIndexChanged(UBSettings::settings()->penWidthIndex()); emit lineWidthIndexChanged(UBSettings::settings()->penWidthIndex());
emit colorIndexChanged(UBSettings::settings()->penColorIndex()); emit colorIndexChanged(UBSettings::settings()->penColorIndex());
@ -144,6 +145,8 @@ void UBDrawingController::setStylusTool(int tool)
UBApplication::mainWindow->actionPointer->setChecked(true); UBApplication::mainWindow->actionPointer->setChecked(true);
else if (mStylusTool == UBStylusTool::Line) else if (mStylusTool == UBStylusTool::Line)
UBApplication::mainWindow->actionLine->setChecked(true); UBApplication::mainWindow->actionLine->setChecked(true);
else if (mStylusTool == UBStylusTool::Vector)
UBApplication::mainWindow->actionVector->setChecked(true);
else if (mStylusTool == UBStylusTool::Text) else if (mStylusTool == UBStylusTool::Text)
UBApplication::mainWindow->actionText->setChecked(true); UBApplication::mainWindow->actionText->setChecked(true);
else if (mStylusTool == UBStylusTool::Capture) else if (mStylusTool == UBStylusTool::Capture)
@ -160,13 +163,14 @@ bool UBDrawingController::isDrawingTool()
{ {
return (stylusTool() == UBStylusTool::Pen) return (stylusTool() == UBStylusTool::Pen)
|| (stylusTool() == UBStylusTool::Marker) || (stylusTool() == UBStylusTool::Marker)
|| (stylusTool() == UBStylusTool::Vector)
|| (stylusTool() == UBStylusTool::Line); || (stylusTool() == UBStylusTool::Line);
} }
int UBDrawingController::currentToolWidthIndex() int UBDrawingController::currentToolWidthIndex()
{ {
if (stylusTool() == UBStylusTool::Pen || stylusTool() == UBStylusTool::Line) if (stylusTool() == UBStylusTool::Pen || stylusTool() == UBStylusTool::Line || stylusTool() == UBStylusTool::Vector)
return UBSettings::settings()->penWidthIndex(); return UBSettings::settings()->penWidthIndex();
else if (stylusTool() == UBStylusTool::Marker) else if (stylusTool() == UBStylusTool::Marker)
return UBSettings::settings()->markerWidthIndex(); return UBSettings::settings()->markerWidthIndex();
@ -177,7 +181,7 @@ int UBDrawingController::currentToolWidthIndex()
qreal UBDrawingController::currentToolWidth() qreal UBDrawingController::currentToolWidth()
{ {
if (stylusTool() == UBStylusTool::Pen || stylusTool() == UBStylusTool::Line) if (stylusTool() == UBStylusTool::Pen || stylusTool() == UBStylusTool::Line || stylusTool() == UBStylusTool::Vector)
return UBSettings::settings()->currentPenWidth(); return UBSettings::settings()->currentPenWidth();
else if (stylusTool() == UBStylusTool::Marker) else if (stylusTool() == UBStylusTool::Marker)
return UBSettings::settings()->currentMarkerWidth(); return UBSettings::settings()->currentMarkerWidth();
@ -198,6 +202,7 @@ void UBDrawingController::setLineWidthIndex(int index)
UBSettings::settings()->setPenWidthIndex(index); UBSettings::settings()->setPenWidthIndex(index);
if(stylusTool() != UBStylusTool::Line if(stylusTool() != UBStylusTool::Line
&& stylusTool() != UBStylusTool::Vector
&& stylusTool() != UBStylusTool::Selector) && stylusTool() != UBStylusTool::Selector)
{ {
setStylusTool(UBStylusTool::Pen); setStylusTool(UBStylusTool::Pen);
@ -210,7 +215,7 @@ void UBDrawingController::setLineWidthIndex(int index)
int UBDrawingController::currentToolColorIndex() int UBDrawingController::currentToolColorIndex()
{ {
if (stylusTool() == UBStylusTool::Pen || stylusTool() == UBStylusTool::Line) if (stylusTool() == UBStylusTool::Pen || stylusTool() == UBStylusTool::Line || stylusTool() == UBStylusTool::Vector)
{ {
return UBSettings::settings()->penColorIndex(); return UBSettings::settings()->penColorIndex();
} }
@ -233,7 +238,7 @@ QColor UBDrawingController::currentToolColor()
QColor UBDrawingController::toolColor(bool onDarkBackground) QColor UBDrawingController::toolColor(bool onDarkBackground)
{ {
if (stylusTool() == UBStylusTool::Pen || stylusTool() == UBStylusTool::Line) if (stylusTool() == UBStylusTool::Pen || stylusTool() == UBStylusTool::Line || stylusTool() == UBStylusTool::Vector)
{ {
return UBSettings::settings()->penColor(onDarkBackground); return UBSettings::settings()->penColor(onDarkBackground);
} }
@ -390,6 +395,11 @@ void UBDrawingController::lineToolSelected(bool checked)
setStylusTool(UBStylusTool::Line); setStylusTool(UBStylusTool::Line);
} }
void UBDrawingController::vectorToolSelected(bool checked)
{
if (checked)
setStylusTool(UBStylusTool::Vector);
}
void UBDrawingController::textToolSelected(bool checked) void UBDrawingController::textToolSelected(bool checked)
{ {

@ -107,6 +107,7 @@ class UBDrawingController : public QObject
void zoomOutToolSelected(bool checked); void zoomOutToolSelected(bool checked);
void pointerToolSelected(bool checked); void pointerToolSelected(bool checked);
void lineToolSelected(bool checked); void lineToolSelected(bool checked);
void vectorToolSelected(bool checked);
void textToolSelected(bool checked); void textToolSelected(bool checked);
void captureToolSelected(bool checked); void captureToolSelected(bool checked);
}; };

@ -71,6 +71,7 @@ struct UBStylusTool
ZoomOut, ZoomOut,
Pointer, Pointer,
Line, Line,
Vector,
Text, Text,
Capture Capture
}; };
@ -173,6 +174,7 @@ struct UBGraphicsItemType
GraphicsWidgetItemType, //65556 GraphicsWidgetItemType, //65556
UserTypesCount, //65557 UserTypesCount, //65557
AxesItemType, //65558 AxesItemType, //65558
VectorItemType,
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.
}; };
}; };

@ -70,6 +70,7 @@
#include "UBGraphicsPixmapItem.h" #include "UBGraphicsPixmapItem.h"
#include "UBGraphicsSvgItem.h" #include "UBGraphicsSvgItem.h"
#include "UBGraphicsPolygonItem.h" #include "UBGraphicsPolygonItem.h"
#include "UBGraphicsVectorItem.h"
#include "UBGraphicsMediaItem.h" #include "UBGraphicsMediaItem.h"
#include "UBGraphicsWidgetItem.h" #include "UBGraphicsWidgetItem.h"
#include "UBGraphicsPDFItem.h" #include "UBGraphicsPDFItem.h"
@ -539,8 +540,9 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
width /= UBApplication::boardController->systemScaleFactor(); width /= UBApplication::boardController->systemScaleFactor();
width /= UBApplication::boardController->currentZoom(); width /= UBApplication::boardController->currentZoom();
if (currentTool == UBStylusTool::Line || dc->mActiveRuler) if (currentTool == UBStylusTool::Line || dc->mActiveRuler || currentTool == UBStylusTool::Vector)
{ {
if (UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Vector)
if (UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Marker) if (UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Marker)
if(NULL != mpLastPolygon && NULL != mCurrentStroke && mAddedItems.size() > 0){ if(NULL != mpLastPolygon && NULL != mCurrentStroke && mAddedItems.size() > 0){
UBCoreGraphicsScene::removeItemFromDeletion(mpLastPolygon); UBCoreGraphicsScene::removeItemFromDeletion(mpLastPolygon);
@ -580,7 +582,9 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
else if (currentTool == UBStylusTool::Line) { else if (currentTool == UBStylusTool::Line) {
drawLineTo(position, width, true); drawLineTo(position, width, true);
} }
else if (currentTool == UBStylusTool::Vector) {
drawLineTo(position, width, true);
}
else { else {
bool interpolate = false; bool interpolate = false;
@ -667,7 +671,16 @@ bool UBGraphicsScene::inputDeviceRelease(int tool)
if (currentTool == UBStylusTool::Eraser) if (currentTool == UBStylusTool::Eraser)
hideEraser(); hideEraser();
if(currentTool == UBStylusTool::Vector)
{
if (mUndoRedoStackEnabled)
{ //should be deleted after scene own undo stack implemented
UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, NULL, mpLastVector);
UBApplication::undoStack->push(uc);
mAddedItems.clear();
}
} else{
UBDrawingController *dc = UBDrawingController::drawingController(); UBDrawingController *dc = UBDrawingController::drawingController();
@ -741,6 +754,7 @@ bool UBGraphicsScene::inputDeviceRelease(int tool)
mCurrentPolygon = 0; mCurrentPolygon = 0;
} }
} }
}
if (mRemovedItems.size() > 0 || mAddedItems.size() > 0) if (mRemovedItems.size() > 0 || mAddedItems.size() > 0)
{ {
@ -920,6 +934,7 @@ void UBGraphicsScene::moveTo(const QPointF &pPoint)
} }
void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth, bool bLineStyle) void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth, bool bLineStyle)
{ {
if(UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Vector) bLineStyle = true;
drawLineTo(pEndPoint, pWidth, pWidth, bLineStyle); drawLineTo(pEndPoint, pWidth, pWidth, bLineStyle);
} }
@ -943,8 +958,16 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &startWid
mAddedItems.clear(); mAddedItems.clear();
} }
if (UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Vector)
{
UBGraphicsPolygonItem *polygonItem = lineToPolygonItem(QLineF(mPreviousPoint, pEndPoint), initialWidth, endWidth); UBGraphicsPolygonItem *polygonItem = lineToPolygonItem(QLineF(mPreviousPoint, pEndPoint), initialWidth, endWidth);
addPolygonItemToCurrentStroke(polygonItem); addPolygonItemToCurrentStroke(polygonItem);
} else
{
UBGraphicsVectorItem *vectorItem = new UBGraphicsVectorItem(QLineF(mPreviousPoint, pEndPoint), initialWidth, endWidth);
initVectorItem(vectorItem);
addVectorItemToCurrentStroke(vectorItem);
}
if (!bLineStyle) { if (!bLineStyle) {
mPreviousPoint = pEndPoint; mPreviousPoint = pEndPoint;
@ -998,6 +1021,19 @@ void UBGraphicsScene::addPolygonItemToCurrentStroke(UBGraphicsPolygonItem* polyg
} }
void UBGraphicsScene::addVectorItemToCurrentStroke(UBGraphicsVectorItem* vectorItem)
{
vectorItem->setFlag(QGraphicsItem::ItemIsMovable, true);
vectorItem->setFlag(QGraphicsItem::ItemIsSelectable, true);
vectorItem->SetDelegate();
mpLastVector = vectorItem;
mAddedItems.insert(vectorItem);
// Here we add the item to the scene
addItem(vectorItem);
}
void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
{ {
const QLineF line(mPreviousPoint, pEndPoint); const QLineF line(mPreviousPoint, pEndPoint);
@ -1017,13 +1053,15 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
typedef QList<QPolygonF> POLYGONSLIST; typedef QList<QPolygonF> POLYGONSLIST;
QList<POLYGONSLIST> intersectedPolygons; QList<POLYGONSLIST> intersectedPolygons;
QList<UBGraphicsVectorItem*> intersectedVectorItems;
#pragma omp parallel for #pragma omp parallel for
for(int i=0; i<collidItems.size(); i++) for(int i=0; i<collidItems.size(); i++)
{ {
UBGraphicsPolygonItem *pi = qgraphicsitem_cast<UBGraphicsPolygonItem*>(collidItems[i]); UBGraphicsPolygonItem *pi = qgraphicsitem_cast<UBGraphicsPolygonItem*>(collidItems[i]);
if(pi == NULL) UBGraphicsVectorItem *vi = qgraphicsitem_cast<UBGraphicsVectorItem*>(collidItems[i]);
continue; if(pi != NULL)
{
QPainterPath itemPainterPath; QPainterPath itemPainterPath;
itemPainterPath.addPolygon(pi->sceneTransform().map(pi->polygon())); itemPainterPath.addPolygon(pi->sceneTransform().map(pi->polygon()));
@ -1046,6 +1084,23 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
intersectedPolygons << newPath.simplified().toFillPolygons(pi->sceneTransform().inverted()); intersectedPolygons << newPath.simplified().toFillPolygons(pi->sceneTransform().inverted());
} }
} }
} else if (vi != NULL)
{
QPainterPath itemPainterPath;
QList<QPointF> linePoints = vi->linePoints();
for (int i=0; i < linePoints.count(); ++i)
{
itemPainterPath.addEllipse(linePoints[i], 1, 1);
}
if (eraserPath.contains(itemPainterPath) || eraserPath.intersects(itemPainterPath))
{
#pragma omp critical
{
// Compete remove item
intersectedVectorItems << vi;
}
}
}
} }
for(int i=0; i<intersectedItems.size(); i++) for(int i=0; i<intersectedItems.size(); i++)
@ -1093,7 +1148,21 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
intersectedPolygonItem->setTransform(t); intersectedPolygonItem->setTransform(t);
} }
if (!intersectedItems.empty()) for (int i=0; i<intersectedVectorItems.size(); i++)
{
UBGraphicsVectorItem *intersectedVectorItem = intersectedVectorItems[i];
mRemovedItems << intersectedVectorItem;
QTransform t;
bool bApplyTransform = false;
removeItem(intersectedVectorItem);
if (bApplyTransform)
{
intersectedVectorItem ->setTransform(t);
}
}
if (!intersectedItems.empty() || !intersectedVectorItems.empty())
setModified(true); setModified(true);
} }
@ -1271,6 +1340,28 @@ void UBGraphicsScene::initPolygonItem(UBGraphicsPolygonItem* polygonItem)
polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic)); polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic));
} }
void UBGraphicsScene::initVectorItem(UBGraphicsVectorItem* vectorItem)
{
QColor colorOnDarkBG;
QColor colorOnLightBG;
colorOnDarkBG = UBApplication::boardController->penColorOnDarkBackground();
colorOnLightBG = UBApplication::boardController->penColorOnLightBackground();
if (mDarkBackground)
{
vectorItem->setColor(colorOnDarkBG);
}
else
{
vectorItem->setColor(colorOnLightBG);
}
vectorItem->setColorOnDarkBackground(colorOnDarkBG);
vectorItem->setColorOnLightBackground(colorOnLightBG);
vectorItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic));
}
UBGraphicsPolygonItem* UBGraphicsScene::arcToPolygonItem(const QLineF& pStartRadius, qreal pSpanAngle, qreal pWidth) UBGraphicsPolygonItem* UBGraphicsScene::arcToPolygonItem(const QLineF& pStartRadius, qreal pSpanAngle, qreal pWidth)
{ {
QPolygonF polygon = UBGeometryUtils::arcToPolygon(pStartRadius, pSpanAngle, pWidth); QPolygonF polygon = UBGeometryUtils::arcToPolygon(pStartRadius, pSpanAngle, pWidth);
@ -1491,7 +1582,7 @@ void UBGraphicsScene::clearContent(clearCase pCase)
? qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(item->parentItem()) ? qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(item->parentItem())
: 0; : 0;
UBGraphicsItemDelegate *curDelegate = UBGraphicsItem::Delegate(item); UBGraphicsItemDelegate *curDelegate = UBGraphicsItem::Delegate(item);
if (!curDelegate) { if (!curDelegate && item->type() != UBGraphicsVectorItem::Type) {
continue; continue;
} }
@ -1499,6 +1590,12 @@ void UBGraphicsScene::clearContent(clearCase pCase)
bool isStrokesGroup = item->type() == UBGraphicsStrokesGroup::Type; bool isStrokesGroup = item->type() == UBGraphicsStrokesGroup::Type;
bool shouldDelete = false; bool shouldDelete = false;
if(item->type()==UBGraphicsVectorItem::Type)
{
removedItems << item;
this->removeItem(item);
} else
{
switch (static_cast<int>(pCase)) { switch (static_cast<int>(pCase)) {
case clearAnnotations : case clearAnnotations :
shouldDelete = isStrokesGroup; shouldDelete = isStrokesGroup;
@ -1510,6 +1607,7 @@ void UBGraphicsScene::clearContent(clearCase pCase)
shouldDelete = !isGroup && !isBackgroundObject(item); shouldDelete = !isGroup && !isBackgroundObject(item);
break; break;
} }
}
if(shouldDelete) { if(shouldDelete) {
if (itemGroup) { if (itemGroup) {

@ -41,6 +41,7 @@ class UBGraphicsPixmapItem;
class UBGraphicsProxyWidget; class UBGraphicsProxyWidget;
class UBGraphicsSvgItem; class UBGraphicsSvgItem;
class UBGraphicsPolygonItem; class UBGraphicsPolygonItem;
class UBGraphicsVectorItem;
class UBGraphicsMediaItem; class UBGraphicsMediaItem;
class UBGraphicsWidgetItem; class UBGraphicsWidgetItem;
class UBGraphicsW3CWidgetItem; class UBGraphicsW3CWidgetItem;
@ -400,8 +401,11 @@ public slots:
UBGraphicsPolygonItem* curveToPolygonItem(const QList<QPair<QPointF, qreal> > &points); UBGraphicsPolygonItem* curveToPolygonItem(const QList<QPair<QPointF, qreal> > &points);
UBGraphicsPolygonItem* curveToPolygonItem(const QList<QPointF> &points, qreal startWidth, qreal endWidth); UBGraphicsPolygonItem* curveToPolygonItem(const QList<QPointF> &points, qreal startWidth, qreal endWidth);
void addPolygonItemToCurrentStroke(UBGraphicsPolygonItem* polygonItem); void addPolygonItemToCurrentStroke(UBGraphicsPolygonItem* polygonItem);
void addVectorItemToCurrentStroke(UBGraphicsVectorItem* vectorItem);
void initPolygonItem(UBGraphicsPolygonItem*); void initPolygonItem(UBGraphicsPolygonItem*);
void initVectorItem(UBGraphicsVectorItem*);
void drawEraser(const QPointF& pEndPoint, bool pressed = true); void drawEraser(const QPointF& pEndPoint, bool pressed = true);
void redrawEraser(bool pressed); void redrawEraser(bool pressed);
@ -494,6 +498,8 @@ public slots:
UBGraphicsPolygonItem* mpLastPolygon; UBGraphicsPolygonItem* mpLastPolygon;
UBGraphicsPolygonItem* mTempPolygon; UBGraphicsPolygonItem* mTempPolygon;
UBGraphicsVectorItem* mpLastVector;
bool mDrawWithCompass; bool mDrawWithCompass;
UBGraphicsPolygonItem *mCurrentPolygon; UBGraphicsPolygonItem *mCurrentPolygon;
UBSelectionFrame *mSelectionFrame; UBSelectionFrame *mSelectionFrame;

@ -0,0 +1,206 @@
#include "UBGraphicsVectorItem.h"
#include "frameworks/UBGeometryUtils.h"
#include "UBGraphicsScene.h"
#include "core/memcheck.h"
#include <iostream>
UBGraphicsVectorItem::UBGraphicsVectorItem (QGraphicsItem * parent)
: QGraphicsLineItem(parent)
, mHasAlpha(false)
, mOriginalWidth(-1)
, mIsNominalLine(false)
{
// NOOP
initialize();
}
UBGraphicsVectorItem::UBGraphicsVectorItem (const QLineF & line, QGraphicsItem * parent)
: QGraphicsLineItem(line, parent)
, mOriginalWidth(-1)
, mIsNominalLine(false)
{
// NOOP
initialize();
}
UBGraphicsVectorItem::UBGraphicsVectorItem (const QLineF& pLine, qreal pWidth)
: QGraphicsLineItem(pLine)
, mOriginalLine(pLine)
, mOriginalWidth(pWidth)
, mIsNominalLine(true)
{
// NOOP
initialize();
}
UBGraphicsVectorItem::UBGraphicsVectorItem (const QLineF& pLine, qreal pStartWidth, qreal pEndWidth)
: QGraphicsLineItem(pLine)
, mOriginalLine(pLine)
, mOriginalWidth(pEndWidth)
, mIsNominalLine(true)
{
// NOOP
initialize();
}
void UBGraphicsVectorItem::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);
setSublines();
}
void UBGraphicsVectorItem::setSublines()
{
QLineF thisLine = QLineF(this->line().p2().x(), this->line().p2().y(),this->line().p2().x()+this->line().length()/10, this->line().p2().y());
thisLine.setAngle(this->line().angle() - 135);
sublines.push_back(new QGraphicsLineItem(thisLine));
thisLine = QLineF(this->line().p2().x(), this->line().p2().y(),this->line().p2().x()+this->line().length()/10, this->line().p2().y());
thisLine.setAngle(this->line().angle() + 135);
sublines.push_back(new QGraphicsLineItem(thisLine));
}
void UBGraphicsVectorItem::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
}
UBGraphicsVectorItem::~UBGraphicsVectorItem()
{
for (int i = 0; i < sublines.size(); ++i)
delete sublines[i];
sublines.clear();
}
void UBGraphicsVectorItem::setColor(const QColor& pColor)
{
QPen pen = QPen(pColor);
pen.setStyle(style());
pen.setCapStyle(Qt::PenCapStyle::RoundCap);
pen.setWidth(mOriginalWidth);
QGraphicsLineItem::setPen(pen);
for (int i = 0; i < sublines.size(); ++i)
sublines[i]->setPen(pen);
mHasAlpha = (pColor.alphaF() < 1.0);
}
QColor UBGraphicsVectorItem::color() const
{
return QGraphicsLineItem::pen().color();
}
void UBGraphicsVectorItem::setStyle(const Qt::PenStyle& style)
{
QPen pen = QPen(color());
pen.setStyle(style);
pen.setCapStyle(Qt::PenCapStyle::RoundCap);
pen.setWidth(mOriginalWidth);
QGraphicsLineItem::setPen(pen);
for (int i = 0; i < sublines.size(); ++i)
sublines[i]->setPen(pen);
}
Qt::PenStyle UBGraphicsVectorItem::style() const
{
return QGraphicsLineItem::pen().style();
}
QList<QPointF> UBGraphicsVectorItem::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* UBGraphicsVectorItem::deepCopy() const
{
UBGraphicsVectorItem* copy = new UBGraphicsVectorItem(line());
copyItemParameters(copy);
return copy;
}
void UBGraphicsVectorItem::copyItemParameters(UBItem *copy) const
{
UBGraphicsVectorItem *cp = dynamic_cast<UBGraphicsVectorItem*>(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 UBGraphicsVectorItem::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);
for (int i = 0; i <sublines.size(); ++i)
{
sublines[i]->paint(painter, option, widget);
}
Delegate()->postpaint(painter, &styleOption, widget);
}
UBGraphicsScene* UBGraphicsVectorItem::scene()
{
return qobject_cast<UBGraphicsScene*>(QGraphicsLineItem::scene());
}
void UBGraphicsVectorItem::SetDelegate()
{
Delegate()->createControls();
}
QVariant UBGraphicsVectorItem::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,107 @@
#ifndef UBGRAPHICSVECTORITEM_H
#define UBGRAPHICSVECTORITEM_H
#include <QtGui>
#include "core/UB.h"
#include "UBItem.h"
class UBItem;
class UBGraphicsScene;
class UBGraphicsVectorItem: public QGraphicsLineItem, public UBItem, public UBGraphicsItem
{
public:
UBGraphicsVectorItem();
public:
UBGraphicsVectorItem(QGraphicsItem * parent = 0 );
UBGraphicsVectorItem(const QLineF& line, qreal pWidth);
UBGraphicsVectorItem(const QLineF& pLine, qreal pStartWidth, qreal pEndWidth);
UBGraphicsVectorItem(const QLineF & line, QGraphicsItem * parent = 0);
~UBGraphicsVectorItem();
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::VectorItemType };
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();
QList<QGraphicsLineItem*> SubLines()
{
return sublines;
}
protected:
void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
void setSublines();
private:
bool mHasAlpha;
QLineF mOriginalLine;
qreal mOriginalWidth;
bool mIsNominalLine;
QColor mColorOnDarkBackground;
QColor mColorOnLightBackground;
QList<QGraphicsLineItem *> sublines;
};
#endif // UBGRAPHICSVECTORITEM_H

@ -1,4 +1,5 @@
HEADERS += src/domain/UBGraphicsScene.h \ HEADERS += src/domain/UBGraphicsScene.h \
$$PWD/UBGraphicsVectorItem.h \
src/domain/UBGraphicsItemUndoCommand.h \ src/domain/UBGraphicsItemUndoCommand.h \
src/domain/UBGraphicsTextItemUndoCommand.h \ src/domain/UBGraphicsTextItemUndoCommand.h \
src/domain/UBGraphicsItemTransformUndoCommand.h \ src/domain/UBGraphicsItemTransformUndoCommand.h \
@ -28,6 +29,7 @@ HEADERS += src/domain/UBGraphicsScene.h \
src/domain/UBGraphicsItemZLevelUndoCommand.h src/domain/UBGraphicsItemZLevelUndoCommand.h
SOURCES += src/domain/UBGraphicsScene.cpp \ SOURCES += src/domain/UBGraphicsScene.cpp \
$$PWD/UBGraphicsVectorItem.cpp \
src/domain/UBGraphicsItemUndoCommand.cpp \ src/domain/UBGraphicsItemUndoCommand.cpp \
src/domain/UBGraphicsTextItemUndoCommand.cpp \ src/domain/UBGraphicsTextItemUndoCommand.cpp \
src/domain/UBGraphicsItemTransformUndoCommand.cpp \ src/domain/UBGraphicsItemTransformUndoCommand.cpp \

@ -61,6 +61,7 @@ UBStylusPalette::UBStylusPalette(QWidget *parent, Qt::Orientation orient)
actions << UBApplication::mainWindow->actionPointer; actions << UBApplication::mainWindow->actionPointer;
actions << UBApplication::mainWindow->actionLine; actions << UBApplication::mainWindow->actionLine;
actions << UBApplication::mainWindow->actionVector;
actions << UBApplication::mainWindow->actionText; actions << UBApplication::mainWindow->actionText;
actions << UBApplication::mainWindow->actionCapture; actions << UBApplication::mainWindow->actionCapture;

@ -210,6 +210,7 @@ void UBToolbarButtonGroup::colorPaletteChanged()
QList<QColor> colors; QList<QColor> colors;
if (UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Pen if (UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Pen
|| UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Vector
|| UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line) || UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line)
{ {
colors = UBSettings::settings()->penColors(isDarkBackground); colors = UBSettings::settings()->penColors(isDarkBackground);

Loading…
Cancel
Save