X-Git-Url: https://git.sven.stormbind.net/?a=blobdiff_plain;f=src%2Fmapobj.cpp;fp=src%2Fmapobj.cpp;h=8ade8ede74dd44a6b7d3396bfcac35efd0b2daab;hb=d483bd8e6523c23c6f1d8908a2e0611c2bc9ff4f;hp=0000000000000000000000000000000000000000;hpb=7dfa3fe589d1722d49681f42cdb0bf1e6efb5223;p=sven%2Fvym.git diff --git a/src/mapobj.cpp b/src/mapobj.cpp new file mode 100644 index 0000000..8ade8ed --- /dev/null +++ b/src/mapobj.cpp @@ -0,0 +1,117 @@ +#include + +#include "geometry.h" +#include "mapobj.h" +#include "misc.h" + +///////////////////////////////////////////////////////////////// +// MapObj +///////////////////////////////////////////////////////////////// +MapObj::MapObj(QGraphicsItem *parent, TreeItem *ti) : QGraphicsItem(parent) +{ + // qDebug() << "Const MapObj (this,ti)=("<setParentItem(NULL); +} + +void MapObj::init() +{ + absPos = QPointF(0, 0); + visible = true; +} + +void MapObj::copy(MapObj *other) +{ + absPos = other->absPos; + bbox.setX(other->bbox.x()); + bbox.setY(other->bbox.y()); + bbox.setSize(QSizeF(other->bbox.width(), other->bbox.height())); +} + +void MapObj::setTreeItem(TreeItem *ti) { treeItem = ti; } + +TreeItem *MapObj::getTreeItem() const { return treeItem; } + +qreal MapObj::x() { return getAbsPos().x(); } + +qreal MapObj::y() { return getAbsPos().y(); } + +qreal MapObj::width() { return bbox.width(); } + +qreal MapObj::height() { return bbox.height(); } + +QPointF MapObj::getAbsPos() { return absPos; } + +QString MapObj::getPos() { return qpointFToString(absPos); } + +void MapObj::move(double x, double y) { MapObj::move(QPointF(x, y)); } + +void MapObj::move(QPointF p) +{ + absPos = p; + bbox.moveTo(p); + clickPoly = QPolygonF(bbox); +} + +void MapObj::moveBy(double x, double y) +{ + QPointF v(x, y); + MapObj::move(absPos + v); + bbox.moveTo(bbox.topLeft() + v); + clickPoly.translate(v); +} + +QRectF MapObj::boundingRect() const { return QRectF(); } + +void MapObj::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {} + +QRectF MapObj::getBBox() { return bbox; } + +ConvexPolygon MapObj::getBoundingPolygon() +{ + QPolygonF p; + p << bbox.topLeft() << bbox.topRight() << bbox.bottomRight() + << bbox.bottomLeft(); + return p; +} + +QPolygonF MapObj::getClickPoly() { return clickPoly; } + +QPainterPath MapObj::getSelectionPath() +{ + qreal d = 3; // Thickness of selection "border" + QPainterPath p; + QRectF br = clickPoly.boundingRect(); + p.moveTo(br.topLeft() + QPointF(-d, -d)); + p.lineTo(br.topRight() + QPointF(d, -d)); + p.lineTo(br.bottomRight() + QPointF(d, d)); + p.lineTo(br.bottomLeft() + QPointF(-d, d)); + p.lineTo(br.topLeft() + QPointF(-d, -d)); + return p; +} + +bool MapObj::isInClickBox(const QPointF &p) +{ + return clickPoly.containsPoint(p, Qt::OddEvenFill); +} + +QSizeF MapObj::getSize() { return bbox.size(); } + +void MapObj::setRotation(const qreal &a) { angle = a; } + +qreal MapObj::getRotation() { return angle; } + +bool MapObj::isVisibleObj() { return visible; } + +void MapObj::setVisibility(bool v) { visible = v; } + +void MapObj::positionBBox() {} +void MapObj::calcBBoxSize() {}