Triangle Graphics tool - drawing possibility

preferencesAboutTextFull
Anatoly Mihalchenko 13 years ago
parent 99fd9a134b
commit 80f48f739d
  1. 81
      src/tools/UBGraphicsTriangle.cpp
  2. 7
      src/tools/UBGraphicsTriangle.h

@ -130,6 +130,7 @@ void UBGraphicsTriangle::calculatePoints(const QRectF& r)
{
switch(mOrientation)
{
case BottomLeft:
A1.setX(r.left()); A1.setY(r.top());
B1.setX(r.left()); B1.setY(r.bottom());
@ -267,6 +268,22 @@ void UBGraphicsTriangle::paint(QPainter *painter, const QStyleOptionGraphicsItem
}
}
QPainterPath UBGraphicsTriangle::shape() const
{
QPainterPath tShape;
QPolygonF tPolygon;
tPolygon << A1 << B1 << C1;
tShape.addPolygon(tPolygon);
tPolygon.clear();
tPolygon << A2 << B2 << C2;
tShape.addPolygon(tPolygon);
tPolygon.clear();
return tShape;
}
void UBGraphicsTriangle::paintGraduations(QPainter *painter)
{
const int centimeterGraduationHeight = 15;
@ -744,8 +761,7 @@ void UBGraphicsTriangle::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
if (currentTool == UBStylusTool::Selector)
{
if (currentTool == UBStylusTool::Selector) {
mCloseSvgItem->setParentItem(this);
mShowButtons = true;
@ -770,6 +786,11 @@ void UBGraphicsTriangle::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
event->accept();
update();
} else if (UBDrawingController::drawingController()->isDrawingTool()) {
setCursor(drawRulerLineCursor());
UBDrawingController::drawingController()->mActiveRuler = this;
event->accept();
}
}
@ -813,3 +834,59 @@ void UBGraphicsTriangle::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
event->accept();
}
}
void UBGraphicsTriangle::StartLine(const QPointF &scenePos, qreal width)
{
qDebug() << "morientation" << mOrientation;
//qDebug() << "triangle rect()" << rect();
QPointF itemPos = mapFromScene(scenePos);
qreal y;
if (mOrientation == 0 || mOrientation == 1) {
y = rect().y() + rect().height() + width / 2;
} else if (mOrientation == 2 || mOrientation == 3) {
y = rect().y() - width / 2;
}
if (itemPos.x() < rect().x() + sLeftEdgeMargin)
itemPos.setX(rect().x() + sLeftEdgeMargin);
if (itemPos.x() > rect().x() + rect().width() - sLeftEdgeMargin)
itemPos.setX(rect().x() + rect().width() - sLeftEdgeMargin);
itemPos.setY(y);
itemPos = mapToScene(itemPos);
scene()->moveTo(itemPos);
scene()->drawLineTo(itemPos, width, true);
}
void UBGraphicsTriangle::DrawLine(const QPointF &scenePos, qreal width)
{
QPointF itemPos = mapFromScene(scenePos);
qreal y;
if (mOrientation == 0 || mOrientation == 1) {
y = rect().y() + rect().height() + width / 2;
} else if (mOrientation == 2 || mOrientation == 3) {
y = rect().y() - width / 2;
}
if (itemPos.x() < rect().x() + sLeftEdgeMargin)
itemPos.setX(rect().x() + sLeftEdgeMargin);
if (itemPos.x() > rect().x() + rect().width() - sLeftEdgeMargin)
itemPos.setX(rect().x() + rect().width() - sLeftEdgeMargin);
itemPos.setY(y);
itemPos = mapToScene(itemPos);
// We have to use "pointed" line for marker tool
scene()->drawLineTo(itemPos, width,
UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Marker);
}
void UBGraphicsTriangle::EndLine()
{
}

@ -30,7 +30,7 @@ class UBItem;
class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonItem, public UBItem
{
Q_OBJECT;
Q_OBJECT
public:
UBGraphicsTriangle();
@ -46,6 +46,10 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
virtual UBItem* deepCopy(void) const;
virtual void StartLine(const QPointF& scenePos, qreal width);
virtual void DrawLine(const QPointF& position, qreal width);
virtual void EndLine();
enum UBGraphicsTriangleOrientation
{
BottomLeft = 0,
@ -77,6 +81,7 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
void updateResizeCursor();
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget);
virtual QPainterPath shape() const;
virtual void rotateAroundCenter(qreal angle);

Loading…
Cancel
Save