lineStyle
thomas_lucky13 2 years ago
parent 9194120bc8
commit a8a0c0b720
  1. 20
      src/adaptors/UBSvgSubsetAdaptor.cpp
  2. 43
      src/domain/UBGraphicsLineItem.cpp
  3. 37
      src/domain/UBGraphicsLineItem.h
  4. 118
      src/domain/UBGraphicsLineStroke.cpp
  5. 74
      src/domain/UBGraphicsLineStroke.h
  6. 17
      src/domain/UBGraphicsScene.cpp
  7. 2
      src/domain/domain.pri

@ -654,7 +654,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene(UBDocumentProx
lineItem->setTransform(group->transform());
group->addToGroup(lineItem);
lineItem->setStrokesGroup(group);
lineItem->show();
group->addToGroup(lineItem);
@ -1346,38 +1345,32 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(UBDocumentProxy* proxy,
UBGraphicsLineItem *lineItem = qgraphicsitem_cast<UBGraphicsLineItem*> (item);
if (lineItem && lineItem->isVisible())
{
UBGraphicsLineStroke* currentStroke = lineItem->stroke();
bool firstLineInStroke = currentStroke && !openStroke;
if (firstLineInStroke)
{
mXmlWriter.writeStartElement("g");
QColor colorOnDarkBackground = lineItem->colorOnDarkBackground();
QColor colorOnLightBackground = lineItem->colorOnLightBackground();
UBGraphicsStrokesGroup * sg = lineItem->strokesGroup();
if (colorOnDarkBackground.isValid() && colorOnLightBackground.isValid() && sg)
if (colorOnDarkBackground.isValid() && colorOnLightBackground.isValid() && lineItem)
{
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "z-value"
, QString("%1").arg(lineItem->strokesGroup()->zValue()));
, QString("%1").arg(lineItem->zValue()));
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri
, "fill-on-dark-background", colorOnDarkBackground.name());
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri
, "fill-on-light-background", colorOnLightBackground.name());
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "uuid", UBStringUtils::toCanonicalUuid(sg->uuid()));
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "uuid", UBStringUtils::toCanonicalUuid(lineItem->uuid()));
QVariant locked = sg->data(UBGraphicsItemData::ItemLocked);
QVariant locked = lineItem->data(UBGraphicsItemData::ItemLocked);
if (!locked.isNull() && locked.toBool())
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "locked", xmlTrue);
QVariant layer = sg->data(UBGraphicsItemData::ItemLayerType);
QVariant layer = lineItem->data(UBGraphicsItemData::ItemLayerType);
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "layer", QString("%1").arg(layer.toInt()));
QMatrix matrix = sg->sceneMatrix();
QMatrix matrix = lineItem->sceneMatrix();
if (!matrix.isIdentity())
mXmlWriter.writeAttribute("transform", toSvgTransform(matrix));
@ -1385,7 +1378,6 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(UBDocumentProxy* proxy,
groupHoldsInfo = true;
}
}
lineItemToSvgLine(lineItem, groupHoldsInfo);

@ -2,7 +2,6 @@
#include "frameworks/UBGeometryUtils.h"
#include "UBGraphicsScene.h"
#include "domain/UBGraphicsLineStroke.h"
#include "core/memcheck.h"
@ -11,8 +10,6 @@ UBGraphicsLineItem::UBGraphicsLineItem (QGraphicsItem * parent)
, mHasAlpha(false)
, mOriginalWidth(-1)
, mIsNominalLine(false)
, mStroke(0)
, mpGroup(NULL)
{
// NOOP
initialize();
@ -22,8 +19,6 @@ UBGraphicsLineItem::UBGraphicsLineItem (const QLineF & line, QGraphicsItem * par
: QGraphicsLineItem(line, parent)
, mOriginalWidth(-1)
, mIsNominalLine(false)
, mStroke(0)
, mpGroup(NULL)
{
// NOOP
initialize();
@ -35,8 +30,6 @@ UBGraphicsLineItem::UBGraphicsLineItem (const QLineF& pLine, qreal pWidth)
, mOriginalLine(pLine)
, mOriginalWidth(pWidth)
, mIsNominalLine(true)
, mStroke(0)
, mpGroup(NULL)
{
// NOOP
initialize();
@ -47,8 +40,6 @@ UBGraphicsLineItem::UBGraphicsLineItem (const QLineF& pLine, qreal pStartWidth,
, mOriginalLine(pLine)
, mOriginalWidth(pEndWidth)
, mIsNominalLine(true)
, mStroke(0)
, mpGroup(NULL)
{
// NOOP
initialize();
@ -57,7 +48,7 @@ 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
//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
@ -75,43 +66,11 @@ void UBGraphicsLineItem::setUuid(const QUuid &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->lines().empty())
delete mStroke;
mStroke = NULL;
}
}
UBGraphicsLineItem::~UBGraphicsLineItem()
{
clearStroke();
}
void UBGraphicsLineItem::setStrokesGroup(UBGraphicsStrokesGroup *group)
{
mpGroup = group;
}
void UBGraphicsLineItem::setStroke(UBGraphicsLineStroke* stroke)
{
if (stroke) {
clearStroke();
mStroke = stroke;
mStroke->addLine(this);
}
}
UBGraphicsLineStroke* UBGraphicsLineItem::stroke() const
{
return mStroke;
}
void UBGraphicsLineItem::setColor(const QColor& pColor)
{
QPen pen = QPen(pColor);

@ -4,12 +4,9 @@
#include <QtGui>
#include "core/UB.h"
#include "UBItem.h"
#include "UBGraphicsStrokesGroup.h"
#include "domain/UBGraphicsGroupContainerItem.h"
class UBItem;
class UBGraphicsScene;
class UBGraphicsLineStroke;
class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem, public UBGraphicsItem
{
@ -27,8 +24,6 @@ class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem, public UBGra
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);
@ -37,30 +32,6 @@ class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem, public UBGra
virtual UBGraphicsScene* scene();
inline void subtract(UBGraphicsLineItem *li)
{
/*if (boundingRect().intersects(li->boundingRect()))
{
QLineF subtractedLine = line().substracted(li->line());
if (line() != subtractedLine)
{
mIsNominalLine = false;
QGraphicsLineItem::setLine(subtractedLine);
}
}*/
}
inline void subtractIntersecting(UBGraphicsLineItem *li)
{
/*QLineF subtractedLine = line().substracted(li->line());
if (line() != subtractedLine)
{
mIsNominalLine = false;
QGraphicsLineItem::setLine(subtractedLine);
}*/
}
enum { Type = UBGraphicsItemType::LineItemType };
virtual int type() const
@ -106,9 +77,6 @@ class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem, public UBGra
mColorOnLightBackground = pColorOnLightBackground;
}
void setStroke(UBGraphicsLineStroke* stroke);
UBGraphicsLineStroke* stroke() const;
void SetDelegate();
protected:
@ -117,8 +85,6 @@ class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem, public UBGra
private:
void clearStroke();
bool mHasAlpha;
QLineF mOriginalLine;
@ -128,9 +94,6 @@ class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem, public UBGra
QColor mColorOnDarkBackground;
QColor mColorOnLightBackground;
UBGraphicsLineStroke* mStroke;
UBGraphicsStrokesGroup* mpGroup;
};
#endif // UBGRAPHICSLINEITEM_H

@ -1,118 +0,0 @@
/*
* Copyright (C) 2015-2022 Département de l'Instruction Publique (DIP-SEM)
*
* Copyright (C) 2013 Open Education Foundation
*
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour
* l'Education Numérique en Afrique (GIP ENA)
*
* This file is part of OpenBoard.
*
* OpenBoard is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* OpenBoard is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBGraphicsLineStroke.h"
#include "UBGraphicsLineItem.h"
#include "board/UBBoardController.h"
#include "core/UBApplication.h"
#include "core/memcheck.h"
#include "domain/UBGraphicsScene.h"
#include "frameworks/UBGeometryUtils.h"
UBGraphicsLineStroke::UBGraphicsLineStroke(UBGraphicsScene *scene)
:mScene(scene)
{
mAntiScaleRatio = 1./(UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom());
}
UBGraphicsLineStroke::~UBGraphicsLineStroke()
{
foreach(UBGraphicsLineItem* line, mLines)
line->setStroke(NULL);
mLines.clear();
}
void UBGraphicsLineStroke::addLine(UBGraphicsLineItem* line)
{
remove(line);
mLines << line;
}
void UBGraphicsLineStroke::remove(UBGraphicsLineItem* lineItem)
{
int n = mLines.indexOf(lineItem);
if (n>=0)
mLines.removeAt(n);
}
QList<UBGraphicsLineItem*> UBGraphicsLineStroke::lines() const
{
return mLines;
}
bool UBGraphicsLineStroke::hasPressure()
{
if (mLines.count() > 2)
{
qreal nominalWidth = mLines.at(0)->originalWidth();
foreach(UBGraphicsLineItem* line, mLines)
{
if (!line->isNominalLine() || line->originalWidth() != nominalWidth)
return true;
}
return false;
}
else
return true;
}
UBGraphicsLineStroke* UBGraphicsLineStroke::deepCopy()
{
UBGraphicsLineStroke* clone = new UBGraphicsLineStroke();
return clone;
}
bool UBGraphicsLineStroke::hasAlpha() const
{
if (mLines.length() > 0 && mLines.at(0)->color().alphaF() != 1.0)
{
return true;
}
else
{
return false;
}
}
void UBGraphicsLineStroke::clear()
{
if(!mLines.empty()){
mLines.clear();
}
}

@ -1,74 +0,0 @@
/*
* Copyright (C) 2015-2022 Département de l'Instruction Publique (DIP-SEM)
*
* Copyright (C) 2013 Open Education Foundation
*
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour
* l'Education Numérique en Afrique (GIP ENA)
*
* This file is part of OpenBoard.
*
* OpenBoard is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* OpenBoard is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBGRAPHICSSTROKE_H_
#define UBGRAPHICSSTROKE_H_
#include <QtGui>
#include "core/UB.h"
class UBGraphicsLineItem;
class UBGraphicsScene;
class UBGraphicsLineStroke
{
friend class UBGraphicsLineItem;
public:
UBGraphicsLineStroke(UBGraphicsScene* scene = NULL);
virtual ~UBGraphicsLineStroke();
bool hasPressure();
QList<UBGraphicsLineItem*> lines() const;
void remove(UBGraphicsLineItem* lineItem);
UBGraphicsLineStroke *deepCopy();
bool hasAlpha() const;
void clear();
protected:
void addLine(UBGraphicsLineItem* line);
private:
UBGraphicsScene * mScene;
QList<UBGraphicsLineItem*> mLines;
qreal mAntiScaleRatio;
};
#endif /* UBGRAPHICSSTROKE_H_ */

@ -542,23 +542,6 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
if (currentTool == UBStylusTool::Line || dc->mActiveRuler)
{
if (UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Marker)
if(NULL != mpLastPolygon && NULL != mCurrentStroke && mAddedItems.size() > 0){
UBCoreGraphicsScene::removeItemFromDeletion(mpLastPolygon);
mAddedItems.remove(mpLastPolygon);
mCurrentStroke->remove(mpLastPolygon);
if (mCurrentStroke->polygons().empty()){
delete mCurrentStroke;
mCurrentStroke = NULL;
}
removeItem(mpLastPolygon);
mPreviousPolygonItems.removeAll(mpLastPolygon);
}
// ------------------------------------------------------------------------
// Here we wanna make sure that the Line will 'grip' at i*45, i*90 degrees
// ------------------------------------------------------------------------
QLineF radius(mPreviousPoint, position);
qreal angle = radius.angle();
angle = qRound(angle / 45) * 45;

@ -14,7 +14,6 @@ HEADERS += src/domain/UBGraphicsScene.h \
src/domain/UBGraphicsTextItem.h \
src/domain/UBResizableGraphicsItem.h \
src/domain/UBGraphicsStroke.h \
src/domain/UBGraphicsLineStroke.h \
src/domain/UBGraphicsMediaItem.h \
src/domain/UBGraphicsGroupContainerItem.h \
src/domain/UBGraphicsGroupContainerItemDelegate.h \
@ -45,7 +44,6 @@ SOURCES += src/domain/UBGraphicsScene.cpp \
src/domain/UBGraphicsTextItem.cpp \
src/domain/UBResizableGraphicsItem.cpp \
src/domain/UBGraphicsStroke.cpp \
src/domain/UBGraphicsLineStroke.cpp \
src/domain/UBGraphicsMediaItem.cpp \
src/domain/UBGraphicsGroupContainerItem.cpp \
src/domain/UBGraphicsGroupContainerItemDelegate.cpp \

Loading…
Cancel
Save