UBGraphicsLineStroke

lineStyle
thomas_lucky13 2 years ago
parent dbfe174730
commit 8095c5b5b7
  1. 15
      src/domain/UBGraphicsLineItem.cpp
  2. 17
      src/domain/UBGraphicsLineItem.h
  3. 118
      src/domain/UBGraphicsLineStroke.cpp
  4. 74
      src/domain/UBGraphicsLineStroke.h
  5. 2
      src/domain/domain.pri

@ -2,8 +2,7 @@
#include "frameworks/UBGeometryUtils.h" #include "frameworks/UBGeometryUtils.h"
#include "UBGraphicsScene.h" #include "UBGraphicsScene.h"
#include "domain/UBGraphicsPolygonItem.h" #include "domain/UBGraphicsLineStroke.h"
#include "domain/UBGraphicsStroke.h"
#include "core/memcheck.h" #include "core/memcheck.h"
@ -75,8 +74,8 @@ void UBGraphicsLineItem::clearStroke()
{ {
if (mStroke!=NULL) if (mStroke!=NULL)
{ {
//mStroke->remove(this); mStroke->remove(this);
if (mStroke->polygons().empty()) if (mStroke->lines().empty())
delete mStroke; delete mStroke;
mStroke = NULL; mStroke = NULL;
} }
@ -84,7 +83,7 @@ void UBGraphicsLineItem::clearStroke()
UBGraphicsLineItem::~UBGraphicsLineItem() UBGraphicsLineItem::~UBGraphicsLineItem()
{ {
//clearStroke(); clearStroke();
} }
void UBGraphicsLineItem::setStrokesGroup(UBGraphicsStrokesGroup *group) void UBGraphicsLineItem::setStrokesGroup(UBGraphicsStrokesGroup *group)
@ -92,17 +91,17 @@ void UBGraphicsLineItem::setStrokesGroup(UBGraphicsStrokesGroup *group)
mpGroup = group; mpGroup = group;
} }
void UBGraphicsLineItem::setStroke(UBGraphicsStroke* stroke) void UBGraphicsLineItem::setStroke(UBGraphicsLineStroke* stroke)
{ {
if (stroke) { if (stroke) {
clearStroke(); clearStroke();
mStroke = stroke; mStroke = stroke;
//mStroke->addPolygon(this); mStroke->addLine(this);
} }
} }
UBGraphicsStroke* UBGraphicsLineItem::stroke() const UBGraphicsLineStroke* UBGraphicsLineItem::stroke() const
{ {
return mStroke; return mStroke;
} }

@ -9,7 +9,7 @@
class UBItem; class UBItem;
class UBGraphicsScene; class UBGraphicsScene;
class UBGraphicsStroke; class UBGraphicsLineStroke;
class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem
{ {
@ -39,8 +39,8 @@ class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem
inline void subtract(UBGraphicsLineItem *pi) inline void subtract(UBGraphicsLineItem *pi)
{ {
if (boundingRect().intersects(pi->boundingRect())) //if (boundingRect().intersects(pi->boundingRect()))
{ //{
//QLineF subtractedLine = line().substracted(pi->line()); //QLineF subtractedLine = line().substracted(pi->line());
/*if (line() != subtractedLine) /*if (line() != subtractedLine)
@ -48,13 +48,12 @@ class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem
mIsNominalLine = false; mIsNominalLine = false;
QGraphicsLineItem::setLine(subtractedLine); QGraphicsLineItem::setLine(subtractedLine);
}*/ }*/
} //}
} }
inline void subtractIntersecting(UBGraphicsLineItem *pi) inline void subtractIntersecting(UBGraphicsLineItem *pi)
{ {
/*QLineF subtractedLine = line().substracted(pi->line()) /*QLineF subtractedLine = line();.substracted(pi->line())
if (line() != subtractedLine) if (line() != subtractedLine)
{ {
mIsNominalLine = false; mIsNominalLine = false;
@ -105,8 +104,8 @@ class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem
mColorOnLightBackground = pColorOnLightBackground; mColorOnLightBackground = pColorOnLightBackground;
} }
void setStroke(UBGraphicsStroke* stroke); void setStroke(UBGraphicsLineStroke* stroke);
UBGraphicsStroke* stroke() const; UBGraphicsLineStroke* stroke() const;
protected: protected:
void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget); void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
@ -125,7 +124,7 @@ class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem
QColor mColorOnDarkBackground; QColor mColorOnDarkBackground;
QColor mColorOnLightBackground; QColor mColorOnLightBackground;
UBGraphicsStroke* mStroke; UBGraphicsLineStroke* mStroke;
UBGraphicsStrokesGroup* mpGroup; UBGraphicsStrokesGroup* mpGroup;
}; };

@ -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 <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();
}
}

@ -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 <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_ */

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

Loading…
Cancel
Save