/*************************************************************************** * Copyright (c) 2013 Luke Parry * * * * This file is part of the FreeCAD CAx development system. * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library 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 Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this library; see the file COPYING.LIB. If not, * * write to the Free Software Foundation, Inc., 59 Temple Place, * * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ #include #include #include #include #include #include #include #include #endif #include #include #include #include "Rez.h" #include "QGIArrow.h" using namespace TechDrawGui; QGIArrow::QGIArrow() : m_fill(Qt::SolidPattern), m_size(5.0), m_style(0) { isFlipped = false; m_brush.setStyle(m_fill); setCacheMode(QGraphicsItem::NoCache); setAcceptHoverEvents(false); setFlag(QGraphicsItem::ItemIsSelectable, false); setFlag(QGraphicsItem::ItemIsMovable, false); } void QGIArrow::flip(bool state) { isFlipped = state; } void QGIArrow::draw() { QPainterPath path; if (m_style == 0) { path = makeFilledTriangle(m_size,m_size/6.0,isFlipped); //"arrow l/w sb 3/1" ?? } else if (m_style == 1) { path = makeOpenArrow(m_size,m_size/3.0,isFlipped); //broad arrow? } else if (m_style == 2) { path = makeHashMark(m_size/2.0,m_size/2.0,isFlipped); //big enough? } else if (m_style == 3) { path = makeDot(m_size/2.0,m_size/2.0,isFlipped); } else if (m_style == 4) { path = makeOpenDot(m_size/2.0,m_size/2.0,isFlipped); } else { path = makeFilledTriangle(m_size,m_size/6.0,isFlipped); //sb a question mark or ??? } setPath(path); } void QGIArrow::setSize(double s) { m_size = s; } QPainterPath QGIArrow::makeFilledTriangle(double length, double width, bool flipped) { //(0,0) is tip of arrow if (!flipped) { length *= -1; } QPainterPath path; path.moveTo(QPointF(0.,0.)); path.lineTo(QPointF(Rez::guiX(length),Rez::guiX(-width))); path.lineTo(QPointF(Rez::guiX(length),Rez::guiX(width))); path.closeSubpath(); m_fill = Qt::SolidPattern; return path; } QPainterPath QGIArrow::makeOpenArrow(double length, double width, bool flipped) { //(0,0) is tip of arrow if (!flipped) { length *= -1; } QPainterPath path; path.moveTo(QPointF(Rez::guiX(length),Rez::guiX(-width))); path.lineTo(QPointF(0.,0.)); path.lineTo(QPointF(Rez::guiX(length),Rez::guiX(width))); m_fill = Qt::NoBrush; return path; } QPainterPath QGIArrow::makeHashMark(double length, double width, bool flipped) //Arch tick { double adjWidth = 1.0; //(0,0) is tip of arrow if (!flipped) { length *= -1; adjWidth *= -1; } QPainterPath path; path.moveTo(QPointF(Rez::guiX(length),Rez::guiX(adjWidth * (-width)))); path.lineTo(QPointF(Rez::guiX(-length),Rez::guiX(adjWidth * width))); m_fill = Qt::NoBrush; return path; } QPainterPath QGIArrow::makeDot(double length, double width, bool flipped) //closed dot { Q_UNUSED(flipped); QPainterPath path; path.moveTo(0.0,0.0); ////(0,0) is Center of dot path.addEllipse(Rez::guiX(-length/2.0), Rez::guiX(-width/2.0), Rez::guiX(length), Rez::guiX(width)); m_fill = Qt::SolidPattern; return path; } QPainterPath QGIArrow::makeOpenDot(double length, double width, bool flipped) { Q_UNUSED(flipped); QPainterPath path; path.moveTo(0.0,0.0); ////(0,0) is Center of dot path.addEllipse(Rez::guiX(-length/2.0), Rez::guiX(-width/2.0), Rez::guiX(length), Rez::guiX(width)); m_fill = Qt::NoBrush; return path; } int QGIArrow::getPrefArrowStyle() { Base::Reference hGrp = App::GetApplication().GetUserParameter(). GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); int style = hGrp->GetInt("ArrowStyle", 0); return style; } double QGIArrow::getPrefArrowSize() { Base::Reference hGrp = App::GetApplication().GetUserParameter(). GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); double style = hGrp->GetFloat("ArrowSize", 3.5); return style; } void QGIArrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { QStyleOptionGraphicsItem myOption(*option); myOption.state &= ~QStyle::State_Selected; setPen(m_pen); m_brush.setColor(m_colCurrent); m_brush.setStyle(m_fill); setBrush(m_brush); QGIPrimPath::paint (painter, &myOption, widget); }