From 8095c5b5b7394e3e78f8860d3b791b8370945f91 Mon Sep 17 00:00:00 2001 From: thomas_lucky13 Date: Thu, 23 Jun 2022 17:12:35 +0400 Subject: [PATCH] UBGraphicsLineStroke --- src/domain/UBGraphicsLineItem.cpp | 15 ++-- src/domain/UBGraphicsLineItem.h | 17 ++-- src/domain/UBGraphicsLineStroke.cpp | 118 ++++++++++++++++++++++++++++ src/domain/UBGraphicsLineStroke.h | 74 +++++++++++++++++ src/domain/domain.pri | 2 + 5 files changed, 209 insertions(+), 17 deletions(-) create mode 100644 src/domain/UBGraphicsLineStroke.cpp create mode 100644 src/domain/UBGraphicsLineStroke.h diff --git a/src/domain/UBGraphicsLineItem.cpp b/src/domain/UBGraphicsLineItem.cpp index 0db07259..e1d46cae 100644 --- a/src/domain/UBGraphicsLineItem.cpp +++ b/src/domain/UBGraphicsLineItem.cpp @@ -2,8 +2,7 @@ #include "frameworks/UBGeometryUtils.h" #include "UBGraphicsScene.h" -#include "domain/UBGraphicsPolygonItem.h" -#include "domain/UBGraphicsStroke.h" +#include "domain/UBGraphicsLineStroke.h" #include "core/memcheck.h" @@ -75,8 +74,8 @@ void UBGraphicsLineItem::clearStroke() { if (mStroke!=NULL) { - //mStroke->remove(this); - if (mStroke->polygons().empty()) + mStroke->remove(this); + if (mStroke->lines().empty()) delete mStroke; mStroke = NULL; } @@ -84,7 +83,7 @@ void UBGraphicsLineItem::clearStroke() UBGraphicsLineItem::~UBGraphicsLineItem() { - //clearStroke(); + clearStroke(); } void UBGraphicsLineItem::setStrokesGroup(UBGraphicsStrokesGroup *group) @@ -92,17 +91,17 @@ void UBGraphicsLineItem::setStrokesGroup(UBGraphicsStrokesGroup *group) mpGroup = group; } -void UBGraphicsLineItem::setStroke(UBGraphicsStroke* stroke) +void UBGraphicsLineItem::setStroke(UBGraphicsLineStroke* stroke) { if (stroke) { clearStroke(); mStroke = stroke; - //mStroke->addPolygon(this); + mStroke->addLine(this); } } -UBGraphicsStroke* UBGraphicsLineItem::stroke() const +UBGraphicsLineStroke* UBGraphicsLineItem::stroke() const { return mStroke; } diff --git a/src/domain/UBGraphicsLineItem.h b/src/domain/UBGraphicsLineItem.h index c5f88999..f21c1039 100644 --- a/src/domain/UBGraphicsLineItem.h +++ b/src/domain/UBGraphicsLineItem.h @@ -9,7 +9,7 @@ class UBItem; class UBGraphicsScene; -class UBGraphicsStroke; +class UBGraphicsLineStroke; class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem { @@ -39,8 +39,8 @@ class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem inline void subtract(UBGraphicsLineItem *pi) { - if (boundingRect().intersects(pi->boundingRect())) - { + //if (boundingRect().intersects(pi->boundingRect())) + //{ //QLineF subtractedLine = line().substracted(pi->line()); /*if (line() != subtractedLine) @@ -48,13 +48,12 @@ class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem mIsNominalLine = false; QGraphicsLineItem::setLine(subtractedLine); }*/ - } + //} } inline void subtractIntersecting(UBGraphicsLineItem *pi) { - /*QLineF subtractedLine = line().substracted(pi->line()) - + /*QLineF subtractedLine = line();.substracted(pi->line()) if (line() != subtractedLine) { mIsNominalLine = false; @@ -105,8 +104,8 @@ class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem mColorOnLightBackground = pColorOnLightBackground; } - void setStroke(UBGraphicsStroke* stroke); - UBGraphicsStroke* stroke() const; + void setStroke(UBGraphicsLineStroke* stroke); + UBGraphicsLineStroke* stroke() const; protected: void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget); @@ -125,7 +124,7 @@ class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem QColor mColorOnDarkBackground; QColor mColorOnLightBackground; - UBGraphicsStroke* mStroke; + UBGraphicsLineStroke* mStroke; UBGraphicsStrokesGroup* mpGroup; }; diff --git a/src/domain/UBGraphicsLineStroke.cpp b/src/domain/UBGraphicsLineStroke.cpp new file mode 100644 index 00000000..76deb012 --- /dev/null +++ b/src/domain/UBGraphicsLineStroke.cpp @@ -0,0 +1,118 @@ +/* + * 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 . + */ + + + + +#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 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(); + } +} diff --git a/src/domain/UBGraphicsLineStroke.h b/src/domain/UBGraphicsLineStroke.h new file mode 100644 index 00000000..5ddf4b8b --- /dev/null +++ b/src/domain/UBGraphicsLineStroke.h @@ -0,0 +1,74 @@ +/* + * 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 . + */ + + + + +#ifndef UBGRAPHICSSTROKE_H_ +#define UBGRAPHICSSTROKE_H_ + +#include + +#include "core/UB.h" + + + +class UBGraphicsLineItem; +class UBGraphicsScene; + +class UBGraphicsLineStroke +{ + friend class UBGraphicsLineItem; + + public: + UBGraphicsLineStroke(UBGraphicsScene* scene = NULL); + virtual ~UBGraphicsLineStroke(); + + bool hasPressure(); + + QList lines() const; + + void remove(UBGraphicsLineItem* lineItem); + + UBGraphicsLineStroke *deepCopy(); + + bool hasAlpha() const; + + void clear(); + + protected: + void addLine(UBGraphicsLineItem* line); + + private: + + UBGraphicsScene * mScene; + + QList mLines; + + qreal mAntiScaleRatio; +}; + +#endif /* UBGRAPHICSSTROKE_H_ */ diff --git a/src/domain/domain.pri b/src/domain/domain.pri index 91206704..35d42acf 100644 --- a/src/domain/domain.pri +++ b/src/domain/domain.pri @@ -14,6 +14,7 @@ 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 \ @@ -44,6 +45,7 @@ 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 \