mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-05 23:09:04 +00:00
Changed: #1302 Added drawing of circle for point primitive
--HG-- branch : gsoc2011-worldeditorqt
This commit is contained in:
parent
8116d76d1e
commit
14964373fb
7 changed files with 125 additions and 72 deletions
|
@ -59,7 +59,18 @@ void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode
|
|||
{
|
||||
vec = primitive->getPrimVector();
|
||||
NLLIGO::CPrimPoint *primPoint = static_cast<NLLIGO::CPrimPoint *>(primitive);
|
||||
item = scene->addWorldItemPoint(QPointF(vec->x, -vec->y + cellSize), primPoint->Angle);
|
||||
|
||||
// Draw arrow ?
|
||||
bool showArrow = node->primitiveClass()->ShowArrow;
|
||||
|
||||
// Have a radius ?
|
||||
std::string strRadius;
|
||||
qreal radius = 0;
|
||||
if (primitive->getPropertyByName ("radius", strRadius))
|
||||
radius = atof(strRadius.c_str());
|
||||
|
||||
item = scene->addWorldItemPoint(QPointF(vec->x, -vec->y + cellSize),
|
||||
primPoint->Angle, radius, showArrow);
|
||||
break;
|
||||
}
|
||||
case NLLIGO::CPrimitiveClass::Path:
|
||||
|
@ -397,7 +408,7 @@ void MoveWorldItemsCommand::undo()
|
|||
{
|
||||
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
||||
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
||||
item->moveOn(-m_offset);
|
||||
item->moveBy(-m_offset.x(), -m_offset.y());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -409,7 +420,7 @@ void MoveWorldItemsCommand::redo()
|
|||
{
|
||||
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
||||
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
||||
item->moveOn(m_offset);
|
||||
item->moveBy(m_offset.x(), m_offset.y());
|
||||
}
|
||||
}
|
||||
m_firstRun = false;
|
||||
|
|
|
@ -59,9 +59,10 @@ WorldEditorScene::~WorldEditorScene()
|
|||
{
|
||||
}
|
||||
|
||||
AbstractWorldItem *WorldEditorScene::addWorldItemPoint(const QPointF &point, const float angle)
|
||||
AbstractWorldItem *WorldEditorScene::addWorldItemPoint(const QPointF &point, const qreal angle,
|
||||
const qreal radius, bool showArrow)
|
||||
{
|
||||
WorldItemPoint *item = new WorldItemPoint(point, angle);
|
||||
WorldItemPoint *item = new WorldItemPoint(point, angle, radius, showArrow);
|
||||
addItem(item);
|
||||
return item;
|
||||
}
|
||||
|
@ -203,7 +204,7 @@ void WorldEditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
|||
{
|
||||
Q_FOREACH(QGraphicsItem *item, m_selectedItems)
|
||||
{
|
||||
qgraphicsitem_cast<AbstractWorldItem *>(item)->moveOn(offset);
|
||||
item->moveBy(offset.x(), offset.y());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -56,7 +56,8 @@ public:
|
|||
QUndoStack *undoStack, QObject *parent = 0);
|
||||
virtual ~WorldEditorScene();
|
||||
|
||||
AbstractWorldItem *addWorldItemPoint(const QPointF &point, const float angle);
|
||||
AbstractWorldItem *addWorldItemPoint(const QPointF &point, const qreal angle,
|
||||
const qreal radius, bool showArrow);
|
||||
AbstractWorldItem *addWorldItemPath(const QPolygonF &polyline);
|
||||
AbstractWorldItem *addWorldItemZone(const QPolygonF &polygon);
|
||||
|
||||
|
|
|
@ -322,9 +322,12 @@ int AbstractWorldItem::type() const
|
|||
return Type;
|
||||
}
|
||||
|
||||
WorldItemPoint::WorldItemPoint(const QPointF &point, const qreal angle, QGraphicsItem *parent)
|
||||
WorldItemPoint::WorldItemPoint(const QPointF &point, const qreal angle, const qreal radius,
|
||||
bool showArrow, QGraphicsItem *parent)
|
||||
: AbstractWorldItem(parent),
|
||||
m_angle((2 * NLMISC::Pi - angle) * 180 / NLMISC::Pi)
|
||||
m_angle((2 * NLMISC::Pi - angle) * 180 / NLMISC::Pi),
|
||||
m_radius(radius),
|
||||
m_showArrow(showArrow)
|
||||
{
|
||||
setZValue(WORLD_POINT_LAYER);
|
||||
|
||||
|
@ -335,17 +338,41 @@ WorldItemPoint::WorldItemPoint(const QPointF &point, const qreal angle, QGraphic
|
|||
m_rect.setCoords(-SIZE_POINT, -SIZE_POINT, SIZE_POINT, SIZE_POINT);
|
||||
|
||||
m_pen.setColor(QColor(255, 100, 10));
|
||||
m_pen.setWidth(5);
|
||||
//m_pen.setWidth(0);
|
||||
|
||||
m_selectedPen.setColor(QColor(0, 255, 0));
|
||||
m_selectedPen.setWidth(5);
|
||||
m_selectedPen.setColor(Qt::white);
|
||||
//m_selectedPen.setWidth(0);
|
||||
|
||||
m_brush.setColor(QColor(255, 100, 10));
|
||||
m_brush.setStyle(Qt::SolidPattern);
|
||||
|
||||
m_selectedBrush.setColor(Qt::NoPen);
|
||||
m_selectedBrush.setColor(Qt::white);
|
||||
m_selectedBrush.setStyle(Qt::SolidPattern);
|
||||
|
||||
|
||||
if (m_radius != 0)
|
||||
{
|
||||
// Create circle
|
||||
int segmentCount = 30;
|
||||
QPointF circlePoint(m_radius, 0);
|
||||
m_circle << circlePoint;
|
||||
for (int i = 1; i < segmentCount + 1; ++i)
|
||||
{
|
||||
qreal angle = i * (2 * NLMISC::Pi / segmentCount);
|
||||
circlePoint.setX(cos(angle) * m_radius);
|
||||
circlePoint.setY(sin(angle) * m_radius);
|
||||
m_circle << circlePoint;
|
||||
}
|
||||
}
|
||||
|
||||
// Create arrow
|
||||
if (showArrow)
|
||||
{
|
||||
m_arrow.push_back(QLine(0, 0, SIZE_ARROW, 0));
|
||||
m_arrow.push_back(QLine(SIZE_ARROW - 2, -2, SIZE_ARROW, 0));
|
||||
m_arrow.push_back(QLine(SIZE_ARROW - 2, 2, SIZE_ARROW, 0));
|
||||
}
|
||||
|
||||
//setFlag(ItemIsSelectable);
|
||||
}
|
||||
|
||||
|
@ -353,13 +380,6 @@ WorldItemPoint::~WorldItemPoint()
|
|||
{
|
||||
}
|
||||
|
||||
void WorldItemPoint::moveOn(const QPointF &offset)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
|
||||
setPos(pos() + offset);
|
||||
}
|
||||
|
||||
void WorldItemPoint::rotateOn(const QPointF &pivot, const qreal deltaAngle)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
|
@ -367,8 +387,8 @@ void WorldItemPoint::rotateOn(const QPointF &pivot, const qreal deltaAngle)
|
|||
QPolygonF rotatedPolygon(m_rect);
|
||||
|
||||
// TODO
|
||||
rotatedPolygon.translate(pos());
|
||||
rotatedPolygon.translate(-pivot);
|
||||
rotatedPolygon.translate(pos() - pivot);
|
||||
//rotatedPolygon.translate(-pivot);
|
||||
|
||||
QTransform trans;
|
||||
trans = trans.rotate(deltaAngle);
|
||||
|
@ -385,8 +405,8 @@ void WorldItemPoint::scaleOn(const QPointF &pivot, const QPointF &factor)
|
|||
QPolygonF scaledPolygon(m_rect);
|
||||
|
||||
// TODO
|
||||
scaledPolygon.translate(pos());
|
||||
scaledPolygon.translate(-pivot);
|
||||
scaledPolygon.translate(pos() - pivot);
|
||||
//scaledPolygon.translate(-pivot);
|
||||
|
||||
QTransform trans;
|
||||
trans = trans.scale(factor.x(), factor.y());
|
||||
|
@ -408,6 +428,7 @@ void WorldItemPoint::radiusOn(const qreal radius)
|
|||
|
||||
void WorldItemPoint::setColor(const QColor &color)
|
||||
{
|
||||
m_pen.setColor(color);
|
||||
m_brush.setColor(color);
|
||||
}
|
||||
|
||||
|
@ -430,26 +451,26 @@ void WorldItemPoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
|
|||
// Here comes the magic:
|
||||
//painter->setClipRect(option->exposedRect);
|
||||
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setPen(m_pen);
|
||||
|
||||
if (option->state & QStyle::State_Selected)
|
||||
{
|
||||
painter->setBrush(m_selectedBrush);
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->setBrush(m_brush);
|
||||
}
|
||||
|
||||
painter->drawRect(m_rect);
|
||||
|
||||
painter->setPen(Qt::red);
|
||||
// Draw circle
|
||||
// Draws artefacts with using opengl painter
|
||||
// painter->drawEllipse(-m_radius / 2, -m_radius / 2, m_radius, m_radius);
|
||||
painter->drawPolygon(m_circle);
|
||||
|
||||
painter->rotate(m_angle);
|
||||
|
||||
painter->drawLine(0, 0, SIZE_ARROW, 0);
|
||||
painter->drawLine(SIZE_ARROW - 2, -2, SIZE_ARROW, 0);
|
||||
painter->drawLine(SIZE_ARROW - 2, 2, SIZE_ARROW, 0);
|
||||
// Draw arrow
|
||||
painter->drawLines(m_arrow);
|
||||
|
||||
painter->setPen(Qt::NoPen);
|
||||
if (option->state & QStyle::State_Selected)
|
||||
painter->setBrush(m_selectedBrush);
|
||||
else
|
||||
painter->setBrush(m_brush);
|
||||
|
||||
// Draw point
|
||||
painter->drawRect(m_rect);
|
||||
}
|
||||
|
||||
QVariant WorldItemPoint::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
|
@ -469,35 +490,34 @@ WorldItemPath::WorldItemPath(const QPolygonF &polygon, QGraphicsItem *parent)
|
|||
setZValue(WORLD_PATH_LAYER);
|
||||
|
||||
m_pen.setColor(Qt::black);
|
||||
m_pen.setWidth(5);
|
||||
m_pen.setWidth(3);
|
||||
m_pen.setJoinStyle(Qt::MiterJoin);
|
||||
|
||||
m_selectedPen.setColor(Qt::white);
|
||||
m_selectedPen.setWidth(5);
|
||||
m_selectedPen.setWidth(3);
|
||||
m_selectedPen.setJoinStyle(Qt::MiterJoin);
|
||||
|
||||
QPointF center = m_polygon.boundingRect().center();
|
||||
m_polygon.translate(-center);
|
||||
setPos(center);
|
||||
}
|
||||
|
||||
WorldItemPath::~WorldItemPath()
|
||||
{
|
||||
}
|
||||
|
||||
void WorldItemPath::moveOn(const QPointF &offset)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
|
||||
m_polygon.translate(offset);
|
||||
}
|
||||
|
||||
void WorldItemPath::rotateOn(const QPointF &pivot, const qreal deltaAngle)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
|
||||
QPolygonF rotatedPolygon(m_polygon);
|
||||
rotatedPolygon.translate(-pivot);
|
||||
rotatedPolygon.translate(pos() - pivot);
|
||||
|
||||
QTransform trans;
|
||||
trans = trans.rotate(deltaAngle);
|
||||
m_polygon = trans.map(rotatedPolygon);
|
||||
|
||||
m_polygon.translate(pivot);
|
||||
m_polygon.translate(pivot - pos());
|
||||
}
|
||||
|
||||
void WorldItemPath::scaleOn(const QPointF &pivot, const QPointF &factor)
|
||||
|
@ -505,13 +525,13 @@ void WorldItemPath::scaleOn(const QPointF &pivot, const QPointF &factor)
|
|||
prepareGeometryChange();
|
||||
|
||||
QPolygonF scaledPolygon(m_polygon);
|
||||
scaledPolygon.translate(-pivot);
|
||||
scaledPolygon.translate(pos() - pivot);
|
||||
|
||||
QTransform trans;
|
||||
trans = trans.scale(factor.x(), factor.y());
|
||||
m_polygon = trans.map(scaledPolygon);
|
||||
|
||||
m_polygon.translate(pivot);
|
||||
m_polygon.translate(pivot - pos());
|
||||
}
|
||||
|
||||
void WorldItemPath::turnOn(const qreal angle)
|
||||
|
@ -583,31 +603,28 @@ WorldItemZone::WorldItemZone(const QPolygonF &polygon, QGraphicsItem *parent)
|
|||
|
||||
m_selectedBrush.setColor(QColor(255, 255, 255, 100));
|
||||
m_selectedBrush.setStyle(Qt::SolidPattern);
|
||||
|
||||
QPointF center = m_polygon.boundingRect().center();
|
||||
m_polygon.translate(-center);
|
||||
setPos(center);
|
||||
}
|
||||
|
||||
WorldItemZone::~WorldItemZone()
|
||||
{
|
||||
}
|
||||
|
||||
void WorldItemZone::moveOn(const QPointF &offset)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
|
||||
m_polygon.translate(offset);
|
||||
}
|
||||
|
||||
void WorldItemZone::rotateOn(const QPointF &pivot, const qreal deltaAngle)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
|
||||
QPolygonF rotatedPolygon(m_polygon);
|
||||
rotatedPolygon.translate(-pivot);
|
||||
rotatedPolygon.translate(pos() - pivot);
|
||||
|
||||
QTransform trans;
|
||||
trans = trans.rotate(deltaAngle);
|
||||
m_polygon = trans.map(rotatedPolygon);
|
||||
|
||||
m_polygon.translate(pivot);
|
||||
m_polygon.translate(pivot - pos());
|
||||
}
|
||||
|
||||
void WorldItemZone::scaleOn(const QPointF &pivot, const QPointF &factor)
|
||||
|
@ -615,13 +632,14 @@ void WorldItemZone::scaleOn(const QPointF &pivot, const QPointF &factor)
|
|||
prepareGeometryChange();
|
||||
|
||||
QPolygonF scaledPolygon(m_polygon);
|
||||
scaledPolygon.translate(-pivot);
|
||||
|
||||
scaledPolygon.translate(pos() - pivot);
|
||||
|
||||
QTransform trans;
|
||||
trans = trans.scale(factor.x(), factor.y());
|
||||
m_polygon = trans.map(scaledPolygon);
|
||||
|
||||
m_polygon.translate(pivot);
|
||||
m_polygon.translate(pivot - pos());
|
||||
}
|
||||
|
||||
void WorldItemZone::turnOn(const qreal angle)
|
||||
|
|
|
@ -129,7 +129,6 @@ public:
|
|||
|
||||
enum { Type = QGraphicsItem::UserType + 1 };
|
||||
|
||||
virtual void moveOn(const QPointF &offset) = 0;
|
||||
virtual void rotateOn(const QPointF &pivot, const qreal deltaAngle) = 0;
|
||||
// TODO: add modes: IgnoreAspectRatio, KeepAspectRatio
|
||||
virtual void scaleOn(const QPointF &pivot, const QPointF &factor) = 0;
|
||||
|
@ -150,10 +149,10 @@ public:
|
|||
class WorldItemPoint: public AbstractWorldItem
|
||||
{
|
||||
public:
|
||||
WorldItemPoint(const QPointF &point, const qreal angle, QGraphicsItem *parent = 0);
|
||||
WorldItemPoint(const QPointF &point, const qreal angle, const qreal radius,
|
||||
bool showArrow, QGraphicsItem *parent = 0);
|
||||
virtual ~WorldItemPoint();
|
||||
|
||||
virtual void moveOn(const QPointF &offset);
|
||||
virtual void rotateOn(const QPointF &pivot, const qreal deltaAngle);
|
||||
virtual void scaleOn(const QPointF &pivot, const QPointF &factor);
|
||||
virtual void turnOn(const qreal angle);
|
||||
|
@ -171,13 +170,16 @@ protected:
|
|||
private:
|
||||
|
||||
// TODO
|
||||
static const int SIZE_POINT = 4;
|
||||
static const int SIZE_POINT = 3;
|
||||
|
||||
QPen m_pen, m_selectedPen;
|
||||
QBrush m_brush, m_selectedBrush;
|
||||
|
||||
QPolygonF m_circle;
|
||||
QVector<QLine> m_arrow;
|
||||
QRectF m_rect;
|
||||
qreal m_angle;
|
||||
qreal m_angle, m_radius;
|
||||
bool m_showArrow;
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -191,7 +193,6 @@ public:
|
|||
WorldItemPath(const QPolygonF &polygon, QGraphicsItem *parent = 0);
|
||||
virtual ~WorldItemPath();
|
||||
|
||||
virtual void moveOn(const QPointF &offset);
|
||||
virtual void rotateOn(const QPointF &pivot, const qreal deltaAngle);
|
||||
virtual void scaleOn(const QPointF &pivot, const QPointF &factor);
|
||||
virtual void turnOn(const qreal angle);
|
||||
|
@ -221,7 +222,6 @@ public:
|
|||
WorldItemZone(const QPolygonF &polygon, QGraphicsItem *parent = 0);
|
||||
virtual ~WorldItemZone();
|
||||
|
||||
virtual void moveOn(const QPointF &offset);
|
||||
virtual void rotateOn(const QPointF &pivot, const qreal deltaAngle);
|
||||
virtual void scaleOn(const QPointF &pivot, const QPointF &factor);
|
||||
virtual void turnOn(const qreal angle);
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include <QtCore/QSettings>
|
||||
#include <QtGui/QFileDialog>
|
||||
#include <QtGui/QStatusBar>
|
||||
#include <QtGui/QMessageBox>
|
||||
|
||||
namespace WorldEditor
|
||||
{
|
||||
|
@ -45,7 +46,8 @@ namespace WorldEditor
|
|||
WorldEditorWindow::WorldEditorWindow(QWidget *parent)
|
||||
: QMainWindow(parent),
|
||||
m_primitivesModel(0),
|
||||
m_undoStack(0)
|
||||
m_undoStack(0),
|
||||
m_oglWidget(0)
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
m_undoStack = new QUndoStack(this);
|
||||
|
@ -123,6 +125,25 @@ QUndoStack *WorldEditorWindow::undoStack() const
|
|||
return m_undoStack;
|
||||
}
|
||||
|
||||
void WorldEditorWindow::maybeSave()
|
||||
{
|
||||
QMessageBox *messageBox = new QMessageBox(tr("SDI"),
|
||||
tr("The data has been modified.\n"
|
||||
"Do you want to save your changes?"),
|
||||
QMessageBox::Warning,
|
||||
QMessageBox::Yes | QMessageBox::Default,
|
||||
QMessageBox::No,
|
||||
QMessageBox::Cancel | QMessageBox::Escape,
|
||||
this, Qt::Sheet);
|
||||
|
||||
messageBox->setButtonText(QMessageBox::Yes,
|
||||
tr("Save"));
|
||||
|
||||
messageBox->setButtonText(QMessageBox::No, tr("Don’t Save"));
|
||||
|
||||
messageBox->show();
|
||||
}
|
||||
|
||||
void WorldEditorWindow::open()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this,
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
~WorldEditorWindow();
|
||||
|
||||
QUndoStack *undoStack() const;
|
||||
void maybeSave();
|
||||
|
||||
Q_SIGNALS:
|
||||
public Q_SLOTS:
|
||||
|
|
Loading…
Reference in a new issue