Changed: #1302 Added the turn undo command.

--HG--
branch : gsoc2011-worldeditorqt
This commit is contained in:
dnk-88 2011-08-11 22:58:45 +03:00
parent e39cc48a3a
commit 8116d76d1e
9 changed files with 213 additions and 117 deletions

View file

@ -1,44 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WorldEditorSettingsPage</class>
<widget class="QWidget" name="WorldEditorSettingsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>329</width>
<height>239</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Colors</string>
</property>
<layout class="QGridLayout" name="gridLayout_2"/>
</widget>
</item>
<item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources>
<include location="world_editor.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -52,13 +52,14 @@ void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode
{ {
NLLIGO::IPrimitive *primitive = node->primitive(); NLLIGO::IPrimitive *primitive = node->primitive();
NLLIGO::CPrimVector *vec = 0; NLLIGO::CPrimVector *vec = 0;
QGraphicsItem *item; AbstractWorldItem *item = 0;
switch (node->primitiveClass()->Type) switch (node->primitiveClass()->Type)
{ {
case NLLIGO::CPrimitiveClass::Point: case NLLIGO::CPrimitiveClass::Point:
{ {
vec = primitive->getPrimVector(); vec = primitive->getPrimVector();
item = scene->addWorldItemPoint(QPointF(vec->x, -vec->y + cellSize), 0); NLLIGO::CPrimPoint *primPoint = static_cast<NLLIGO::CPrimPoint *>(primitive);
item = scene->addWorldItemPoint(QPointF(vec->x, -vec->y + cellSize), primPoint->Angle);
break; break;
} }
case NLLIGO::CPrimitiveClass::Path: case NLLIGO::CPrimitiveClass::Path:
@ -91,12 +92,44 @@ void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode
break; break;
} }
} }
if (item != 0)
{
// Get color from world_editor_classes.xml
NLMISC::CRGBA color = Utils::ligoConfig()->getPrimitiveColor(*primitive);
/*
// Configurations (from world_editor_primitive_configuration.xml)
const std::vector<NLLIGO::CPrimitiveConfigurations> &configurations = Utils::ligoConfig()->getPrimitiveConfiguration();
// Look for the configuration
sint search = 0;
bool colorFound = false;
while ((search = theApp.getActiveConfiguration (*primitive, search)) != -1)
{
// Configuration activated ?
if (theApp.Configurations[search].Activated)
{
colorFound = true;
mainColor = configurations[search].Color;
break;
}
search++;
}
// try to get the primitive color ?
//if (!colorFound)*/
primitive->getPropertyByName ("Color", color);
item->setColor(QColor(color.R, color.G, color.B));
}
QVariant variantNode; QVariant variantNode;
variantNode.setValue<Node *>(node); variantNode.setValue<Node *>(node);
item->setData(Constants::WORLD_EDITOR_NODE, variantNode); item->setData(Constants::WORLD_EDITOR_NODE, variantNode);
QVariant graphicsData; QVariant graphicsData;
graphicsData.setValue<QGraphicsItem *>(item); graphicsData.setValue<AbstractWorldItem *>(item);
node->setData(Constants::GRAPHICS_DATA_QT4_2D, graphicsData); node->setData(Constants::GRAPHICS_DATA_QT4_2D, graphicsData);
} }
@ -119,7 +152,7 @@ void removeGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode
case NLLIGO::CPrimitiveClass::Path: case NLLIGO::CPrimitiveClass::Path:
case NLLIGO::CPrimitiveClass::Zone: case NLLIGO::CPrimitiveClass::Zone:
{ {
QGraphicsItem *item = qvariant_cast<QGraphicsItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D)); QGraphicsItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
if (item != 0) if (item != 0)
scene->removeWorldItem(item); scene->removeWorldItem(item);
break; break;
@ -363,8 +396,8 @@ void MoveWorldItemsCommand::undo()
for (int i = 0; i < m_listPaths.count(); ++i) for (int i = 0; i < m_listPaths.count(); ++i)
{ {
Node *node = m_model->pathToNode(m_listPaths.at(i)); Node *node = m_model->pathToNode(m_listPaths.at(i));
QGraphicsItem *item = qvariant_cast<QGraphicsItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D)); AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
qgraphicsitem_cast<AbstractWorldItem *>(item)->moveOn(-m_offset); item->moveOn(-m_offset);
} }
} }
@ -375,14 +408,14 @@ void MoveWorldItemsCommand::redo()
for (int i = 0; i < m_listPaths.count(); ++i) for (int i = 0; i < m_listPaths.count(); ++i)
{ {
Node *node = m_model->pathToNode(m_listPaths.at(i)); Node *node = m_model->pathToNode(m_listPaths.at(i));
QGraphicsItem *item = qvariant_cast<QGraphicsItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D)); AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
qgraphicsitem_cast<AbstractWorldItem *>(item)->moveOn(m_offset); item->moveOn(m_offset);
} }
} }
m_firstRun = false; m_firstRun = false;
} }
RotateWorldItemsCommand::RotateWorldItemsCommand(const QList<QGraphicsItem *> &items, const qreal &angle, RotateWorldItemsCommand::RotateWorldItemsCommand(const QList<QGraphicsItem *> &items, const qreal angle,
const QPointF &pivot, PrimitivesTreeModel *model, QUndoCommand *parent) const QPointF &pivot, PrimitivesTreeModel *model, QUndoCommand *parent)
: QUndoCommand(parent), : QUndoCommand(parent),
m_listPaths(graphicsItemsToPaths(items, model)), m_listPaths(graphicsItemsToPaths(items, model)),
@ -391,7 +424,7 @@ RotateWorldItemsCommand::RotateWorldItemsCommand(const QList<QGraphicsItem *> &i
m_model(model), m_model(model),
m_firstRun(true) m_firstRun(true)
{ {
setText("Rotate item(s)"); setText(QString("Rotate item(s) %1").arg(m_angle));
} }
RotateWorldItemsCommand::~RotateWorldItemsCommand() RotateWorldItemsCommand::~RotateWorldItemsCommand()
@ -403,8 +436,8 @@ void RotateWorldItemsCommand::undo()
for (int i = 0; i < m_listPaths.count(); ++i) for (int i = 0; i < m_listPaths.count(); ++i)
{ {
Node *node = m_model->pathToNode(m_listPaths.at(i)); Node *node = m_model->pathToNode(m_listPaths.at(i));
QGraphicsItem *item = qvariant_cast<QGraphicsItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D)); AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
qgraphicsitem_cast<AbstractWorldItem *>(item)->rotateOn(m_pivot, -m_angle); item->rotateOn(m_pivot, -m_angle);
} }
} }
@ -415,8 +448,8 @@ void RotateWorldItemsCommand::redo()
for (int i = 0; i < m_listPaths.count(); ++i) for (int i = 0; i < m_listPaths.count(); ++i)
{ {
Node *node = m_model->pathToNode(m_listPaths.at(i)); Node *node = m_model->pathToNode(m_listPaths.at(i));
QGraphicsItem *item = qvariant_cast<QGraphicsItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D)); AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
qgraphicsitem_cast<AbstractWorldItem *>(item)->rotateOn(m_pivot, m_angle); item->rotateOn(m_pivot, m_angle);
} }
} }
m_firstRun = false; m_firstRun = false;
@ -444,8 +477,8 @@ void ScaleWorldItemsCommand::undo()
for (int i = 0; i < m_listPaths.count(); ++i) for (int i = 0; i < m_listPaths.count(); ++i)
{ {
Node *node = m_model->pathToNode(m_listPaths.at(i)); Node *node = m_model->pathToNode(m_listPaths.at(i));
QGraphicsItem *item = qvariant_cast<QGraphicsItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D)); AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
qgraphicsitem_cast<AbstractWorldItem *>(item)->scaleOn(m_pivot, m_invertFactor); item->scaleOn(m_pivot, m_invertFactor);
} }
} }
@ -456,8 +489,47 @@ void ScaleWorldItemsCommand::redo()
for (int i = 0; i < m_listPaths.count(); ++i) for (int i = 0; i < m_listPaths.count(); ++i)
{ {
Node *node = m_model->pathToNode(m_listPaths.at(i)); Node *node = m_model->pathToNode(m_listPaths.at(i));
QGraphicsItem *item = qvariant_cast<QGraphicsItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D)); AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
qgraphicsitem_cast<AbstractWorldItem *>(item)->scaleOn(m_pivot, m_factor); item->scaleOn(m_pivot, m_factor);
}
}
m_firstRun = false;
}
TurnWorldItemsCommand::TurnWorldItemsCommand(const QList<QGraphicsItem *> &items, const qreal angle,
PrimitivesTreeModel *model, QUndoCommand *parent)
: QUndoCommand(parent),
m_listPaths(graphicsItemsToPaths(items, model)),
m_angle(angle),
m_model(model),
m_firstRun(true)
{
setText(QString("Turn item(s) %1").arg(m_angle));
}
TurnWorldItemsCommand::~TurnWorldItemsCommand()
{
}
void TurnWorldItemsCommand::undo()
{
for (int i = 0; i < m_listPaths.count(); ++i)
{
Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->turnOn(-m_angle);
}
}
void TurnWorldItemsCommand::redo()
{
if (!m_firstRun)
{
for (int i = 0; i < m_listPaths.count(); ++i)
{
Node *node = m_model->pathToNode(m_listPaths.at(i));
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
item->turnOn(m_angle);
} }
} }
m_firstRun = false; m_firstRun = false;

View file

@ -172,7 +172,7 @@ private:
class RotateWorldItemsCommand: public QUndoCommand class RotateWorldItemsCommand: public QUndoCommand
{ {
public: public:
RotateWorldItemsCommand(const QList<QGraphicsItem *> &items, const qreal &angle, RotateWorldItemsCommand(const QList<QGraphicsItem *> &items, const qreal angle,
const QPointF &pivot, PrimitivesTreeModel *model, QUndoCommand *parent = 0); const QPointF &pivot, PrimitivesTreeModel *model, QUndoCommand *parent = 0);
virtual ~RotateWorldItemsCommand(); virtual ~RotateWorldItemsCommand();
@ -210,6 +210,29 @@ private:
bool m_firstRun; bool m_firstRun;
}; };
/**
@class TurnWorldItemsCommand
@brief
@details
*/
class TurnWorldItemsCommand: public QUndoCommand
{
public:
TurnWorldItemsCommand(const QList<QGraphicsItem *> &items, const qreal angle,
PrimitivesTreeModel *model, QUndoCommand *parent = 0);
virtual ~TurnWorldItemsCommand();
virtual void undo();
virtual void redo();
private:
const QList<Path> m_listPaths;
const qreal m_angle;
PrimitivesTreeModel *const m_model;
bool m_firstRun;
};
} /* namespace WorldEditor */ } /* namespace WorldEditor */
#endif // WORLD_EDITOR_ACTIONS_H #endif // WORLD_EDITOR_ACTIONS_H

View file

@ -77,7 +77,7 @@ bool WorldEditorPlugin::initialize(ExtensionSystem::IPluginManager *pluginManage
// Reset // Reset
m_ligoConfig.resetPrimitiveConfiguration (); m_ligoConfig.resetPrimitiveConfiguration ();
// Load // TODO: get file names! from settings
m_ligoConfig.readPrimitiveClass("world_editor_primitive_configuration.xml", true); m_ligoConfig.readPrimitiveClass("world_editor_primitive_configuration.xml", true);

View file

@ -59,21 +59,21 @@ WorldEditorScene::~WorldEditorScene()
{ {
} }
QGraphicsItem *WorldEditorScene::addWorldItemPoint(const QPointF &point, const float angle) AbstractWorldItem *WorldEditorScene::addWorldItemPoint(const QPointF &point, const float angle)
{ {
WorldItemPoint *item = new WorldItemPoint(point, angle); WorldItemPoint *item = new WorldItemPoint(point, angle);
addItem(item); addItem(item);
return item; return item;
} }
QGraphicsItem *WorldEditorScene::addWorldItemPath(const QPolygonF &polyline) AbstractWorldItem *WorldEditorScene::addWorldItemPath(const QPolygonF &polyline)
{ {
WorldItemPath *item = new WorldItemPath(polyline); WorldItemPath *item = new WorldItemPath(polyline);
addItem(item); addItem(item);
return item; return item;
} }
QGraphicsItem *WorldEditorScene::addWorldItemZone(const QPolygonF &polygon) AbstractWorldItem *WorldEditorScene::addWorldItemZone(const QPolygonF &polygon)
{ {
WorldItemZone *item = new WorldItemZone(polygon); WorldItemZone *item = new WorldItemZone(polygon);
addItem(item); addItem(item);
@ -167,11 +167,16 @@ void WorldEditorScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
break; break;
} }
case WorldEditorScene::RotateMode: case WorldEditorScene::RotateMode:
m_angle = 0;
m_pivot = calcBoundingRect(m_selectedItems).center();
break; break;
case WorldEditorScene::ScaleMode: case WorldEditorScene::ScaleMode:
m_scaleFactor = QPointF(1.0, 1.0); m_scaleFactor = QPointF(1.0, 1.0);
m_pivot = calcBoundingRect(m_selectedItems).center();
break; break;
case WorldEditorScene::TurnMode: case WorldEditorScene::TurnMode:
m_angle = 0;
m_pivot = calcBoundingRect(m_selectedItems).center();
break; break;
case WorldEditorScene::RadiusMode: case WorldEditorScene::RadiusMode:
break; break;
@ -204,24 +209,21 @@ void WorldEditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
} }
case WorldEditorScene::RotateMode: case WorldEditorScene::RotateMode:
{ {
QPointF pivot = calcBoundingRect(m_selectedItems).center();
// Caluculate angle between two line // Caluculate angle between two line
QLineF firstLine(pivot, mouseEvent->lastScenePos()); QLineF firstLine(m_pivot, mouseEvent->lastScenePos());
QLineF secondLine(pivot, mouseEvent->scenePos()); QLineF secondLine(m_pivot, mouseEvent->scenePos());
qreal angle = secondLine.angleTo(firstLine); qreal angle = secondLine.angleTo(firstLine);
m_angle += angle;
Q_FOREACH(QGraphicsItem *item, m_selectedItems) Q_FOREACH(QGraphicsItem *item, m_selectedItems)
{ {
qgraphicsitem_cast<AbstractWorldItem *>(item)->rotateOn(pivot, angle); qgraphicsitem_cast<AbstractWorldItem *>(item)->rotateOn(m_pivot, angle);
} }
break; break;
} }
case WorldEditorScene::ScaleMode: case WorldEditorScene::ScaleMode:
{ {
// TODO: perfomance
QPointF pivot = calcBoundingRect(m_selectedItems).center();
// Calculate scale factor // Calculate scale factor
if (offset.x() > 0) if (offset.x() > 0)
offset.setX(1.0 + (offset.x() / 5000)); offset.setX(1.0 + (offset.x() / 5000));
@ -238,12 +240,26 @@ void WorldEditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
Q_FOREACH(QGraphicsItem *item, m_selectedItems) Q_FOREACH(QGraphicsItem *item, m_selectedItems)
{ {
qgraphicsitem_cast<AbstractWorldItem *>(item)->scaleOn(pivot, offset); qgraphicsitem_cast<AbstractWorldItem *>(item)->scaleOn(m_pivot, offset);
} }
break; break;
} }
case WorldEditorScene::TurnMode: case WorldEditorScene::TurnMode:
{
// Caluculate angle between two line
QLineF firstLine(m_pivot, mouseEvent->lastScenePos());
QLineF secondLine(m_pivot, mouseEvent->scenePos());
qreal angle = secondLine.angleTo(firstLine);
m_angle += angle;
Q_FOREACH(QGraphicsItem *item, m_selectedItems)
{
qgraphicsitem_cast<AbstractWorldItem *>(item)->turnOn(angle);
}
break; break;
}
case WorldEditorScene::RadiusMode: case WorldEditorScene::RadiusMode:
break; break;
}; };
@ -276,30 +292,17 @@ void WorldEditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
case WorldEditorScene::MoveMode: case WorldEditorScene::MoveMode:
{ {
QPointF offset = mouseEvent->scenePos() - m_firstPick; QPointF offset = mouseEvent->scenePos() - m_firstPick;
m_undoStack->push(new MoveWorldItemsCommand(m_selectedItems, offset, m_model)); m_undoStack->push(new MoveWorldItemsCommand(m_selectedItems, offset, m_model));
break; break;
} }
case WorldEditorScene::RotateMode: case WorldEditorScene::RotateMode:
{ m_undoStack->push(new RotateWorldItemsCommand(m_selectedItems, m_angle, m_pivot, m_model));
QPointF pivot = calcBoundingRect(m_selectedItems).center();
// Caluculate angle between two line
QLineF firstLine(pivot, m_firstPick);
QLineF secondLine(pivot, mouseEvent->scenePos());
qreal angle = secondLine.angleTo(firstLine);
m_undoStack->push(new RotateWorldItemsCommand(m_selectedItems, angle, pivot, m_model));
break; break;
}
case WorldEditorScene::ScaleMode: case WorldEditorScene::ScaleMode:
{ m_undoStack->push(new ScaleWorldItemsCommand(m_selectedItems, m_scaleFactor, m_pivot, m_model));
QPointF pivot = calcBoundingRect(m_selectedItems).center();
m_undoStack->push(new ScaleWorldItemsCommand(m_selectedItems, m_scaleFactor, pivot, m_model));
break; break;
}
case WorldEditorScene::TurnMode: case WorldEditorScene::TurnMode:
m_undoStack->push(new TurnWorldItemsCommand(m_selectedItems, m_angle, m_model));
break; break;
case WorldEditorScene::RadiusMode: case WorldEditorScene::RadiusMode:
break; break;

View file

@ -30,6 +30,7 @@
namespace WorldEditor namespace WorldEditor
{ {
class PrimitivesTreeModel; class PrimitivesTreeModel;
class AbstractWorldItem;
/* /*
@class WorldEditorScene @class WorldEditorScene
@ -55,9 +56,9 @@ public:
QUndoStack *undoStack, QObject *parent = 0); QUndoStack *undoStack, QObject *parent = 0);
virtual ~WorldEditorScene(); virtual ~WorldEditorScene();
QGraphicsItem *addWorldItemPoint(const QPointF &point, const float angle); AbstractWorldItem *addWorldItemPoint(const QPointF &point, const float angle);
QGraphicsItem *addWorldItemPath(const QPolygonF &polyline); AbstractWorldItem *addWorldItemPath(const QPolygonF &polyline);
QGraphicsItem *addWorldItemZone(const QPolygonF &polygon); AbstractWorldItem *addWorldItemZone(const QPolygonF &polygon);
void removeWorldItem(QGraphicsItem *item); void removeWorldItem(QGraphicsItem *item);
@ -87,9 +88,9 @@ private:
QPen m_pen1, m_pen2; QPen m_pen1, m_pen2;
QBrush m_brush1, m_brush2; QBrush m_brush1, m_brush2;
QPointF m_firstPick, m_scaleFactor; QPointF m_firstPick, m_scaleFactor, m_pivot;
QRectF m_selectionArea; QRectF m_selectionArea;
qreal m_firstPickX, m_firstPickY; qreal m_firstPickX, m_firstPickY, m_angle;
QList<QGraphicsItem *> m_selectedItems; QList<QGraphicsItem *> m_selectedItems;
bool m_editedSelectedItems, m_firstSelection; bool m_editedSelectedItems, m_firstSelection;
uint m_lastPickedPrimitive; uint m_lastPickedPrimitive;

View file

@ -322,9 +322,9 @@ int AbstractWorldItem::type() const
return Type; return Type;
} }
WorldItemPoint::WorldItemPoint(const QPointF &point, const float angle, QGraphicsItem *parent) WorldItemPoint::WorldItemPoint(const QPointF &point, const qreal angle, QGraphicsItem *parent)
: AbstractWorldItem(parent), : AbstractWorldItem(parent),
m_angle(angle) m_angle((2 * NLMISC::Pi - angle) * 180 / NLMISC::Pi)
{ {
setZValue(WORLD_POINT_LAYER); setZValue(WORLD_POINT_LAYER);
@ -343,7 +343,7 @@ WorldItemPoint::WorldItemPoint(const QPointF &point, const float angle, QGraphic
m_brush.setColor(QColor(255, 100, 10)); m_brush.setColor(QColor(255, 100, 10));
m_brush.setStyle(Qt::SolidPattern); m_brush.setStyle(Qt::SolidPattern);
m_selectedBrush.setColor(QColor(0, 255, 0)); m_selectedBrush.setColor(Qt::NoPen);
m_selectedBrush.setStyle(Qt::SolidPattern); m_selectedBrush.setStyle(Qt::SolidPattern);
//setFlag(ItemIsSelectable); //setFlag(ItemIsSelectable);
@ -396,14 +396,21 @@ void WorldItemPoint::scaleOn(const QPointF &pivot, const QPointF &factor)
setPos(scaledPolygon.boundingRect().center()); setPos(scaledPolygon.boundingRect().center());
} }
void WorldItemPoint::turnOn(const QPointF &offset) void WorldItemPoint::turnOn(const qreal angle)
{ {
m_angle += angle;
update();
} }
void WorldItemPoint::radiusOn(const qreal radius) void WorldItemPoint::radiusOn(const qreal radius)
{ {
} }
void WorldItemPoint::setColor(const QColor &color)
{
m_brush.setColor(color);
}
QPainterPath WorldItemPoint::shape() const QPainterPath WorldItemPoint::shape() const
{ {
QPainterPath path; QPainterPath path;
@ -435,6 +442,14 @@ void WorldItemPoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
} }
painter->drawRect(m_rect); painter->drawRect(m_rect);
painter->setPen(Qt::red);
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);
} }
QVariant WorldItemPoint::itemChange(GraphicsItemChange change, const QVariant &value) QVariant WorldItemPoint::itemChange(GraphicsItemChange change, const QVariant &value)
@ -453,10 +468,10 @@ WorldItemPath::WorldItemPath(const QPolygonF &polygon, QGraphicsItem *parent)
setZValue(WORLD_PATH_LAYER); setZValue(WORLD_PATH_LAYER);
m_pen.setColor(QColor(0, 0, 0)); m_pen.setColor(Qt::black);
m_pen.setWidth(5); m_pen.setWidth(5);
m_selectedPen.setColor(QColor(255, 0, 0)); m_selectedPen.setColor(Qt::white);
m_selectedPen.setWidth(5); m_selectedPen.setWidth(5);
} }
@ -499,7 +514,7 @@ void WorldItemPath::scaleOn(const QPointF &pivot, const QPointF &factor)
m_polygon.translate(pivot); m_polygon.translate(pivot);
} }
void WorldItemPath::turnOn(const QPointF &offset) void WorldItemPath::turnOn(const qreal angle)
{ {
} }
@ -507,6 +522,11 @@ void WorldItemPath::radiusOn(const qreal radius)
{ {
} }
void WorldItemPath::setColor(const QColor &color)
{
m_pen.setColor(color);
}
QPainterPath WorldItemPath::shape() const QPainterPath WorldItemPath::shape() const
{ {
QPainterPath path; QPainterPath path;
@ -555,13 +575,13 @@ WorldItemZone::WorldItemZone(const QPolygonF &polygon, QGraphicsItem *parent)
m_pen.setColor(QColor(20, 100, 255)); m_pen.setColor(QColor(20, 100, 255));
m_pen.setWidth(0); m_pen.setWidth(0);
m_selectedPen.setColor(QColor(255, 0, 0)); m_selectedPen.setColor(Qt::white);
m_selectedPen.setWidth(0); m_selectedPen.setWidth(0);
m_brush.setColor(QColor(20, 100, 255, 28)); m_brush.setColor(QColor(20, 100, 255, TRANSPARENCY));
m_brush.setStyle(Qt::SolidPattern); m_brush.setStyle(Qt::SolidPattern);
m_selectedBrush.setColor(QColor(255, 0, 0, 128)); m_selectedBrush.setColor(QColor(255, 255, 255, 100));
m_selectedBrush.setStyle(Qt::SolidPattern); m_selectedBrush.setStyle(Qt::SolidPattern);
} }
@ -604,7 +624,7 @@ void WorldItemZone::scaleOn(const QPointF &pivot, const QPointF &factor)
m_polygon.translate(pivot); m_polygon.translate(pivot);
} }
void WorldItemZone::turnOn(const QPointF &offset) void WorldItemZone::turnOn(const qreal angle)
{ {
} }
@ -612,6 +632,16 @@ void WorldItemZone::radiusOn(const qreal radius)
{ {
} }
void WorldItemZone::setColor(const QColor &color)
{
m_pen.setColor(color);
QColor brushColor(color);
brushColor.setAlpha(TRANSPARENCY);
m_brush.setColor(brushColor);
}
QRectF WorldItemZone::boundingRect() const QRectF WorldItemZone::boundingRect() const
{ {
return m_polygon.boundingRect(); return m_polygon.boundingRect();

View file

@ -45,6 +45,7 @@ const int WORLD_PATH_LAYER = 200;
const int MIDDLE_POINT_LAYER = 201; const int MIDDLE_POINT_LAYER = 201;
const int EDGE_POINT_LAYER = 201; const int EDGE_POINT_LAYER = 201;
const int SIZE_ARROW = 20;
/* /*
// Deprecated // Deprecated
class GraphicsItemNode: public QGraphicsObject class GraphicsItemNode: public QGraphicsObject
@ -132,9 +133,11 @@ public:
virtual void rotateOn(const QPointF &pivot, const qreal deltaAngle) = 0; virtual void rotateOn(const QPointF &pivot, const qreal deltaAngle) = 0;
// TODO: add modes: IgnoreAspectRatio, KeepAspectRatio // TODO: add modes: IgnoreAspectRatio, KeepAspectRatio
virtual void scaleOn(const QPointF &pivot, const QPointF &factor) = 0; virtual void scaleOn(const QPointF &pivot, const QPointF &factor) = 0;
virtual void turnOn(const QPointF &offset) = 0; virtual void turnOn(const qreal angle) = 0;
virtual void radiusOn(const qreal radius) = 0; virtual void radiusOn(const qreal radius) = 0;
virtual void setColor(const QColor &color) = 0;
// Enable the use of qgraphicsitem_cast with this item. // Enable the use of qgraphicsitem_cast with this item.
int type() const; int type() const;
}; };
@ -147,15 +150,17 @@ public:
class WorldItemPoint: public AbstractWorldItem class WorldItemPoint: public AbstractWorldItem
{ {
public: public:
WorldItemPoint(const QPointF &point, const float angle, QGraphicsItem *parent = 0); WorldItemPoint(const QPointF &point, const qreal angle, QGraphicsItem *parent = 0);
virtual ~WorldItemPoint(); virtual ~WorldItemPoint();
virtual void moveOn(const QPointF &offset); virtual void moveOn(const QPointF &offset);
virtual void rotateOn(const QPointF &pivot, const qreal deltaAngle); virtual void rotateOn(const QPointF &pivot, const qreal deltaAngle);
virtual void scaleOn(const QPointF &pivot, const QPointF &factor); virtual void scaleOn(const QPointF &pivot, const QPointF &factor);
virtual void turnOn(const QPointF &offset); virtual void turnOn(const qreal angle);
virtual void radiusOn(const qreal radius); virtual void radiusOn(const qreal radius);
virtual void setColor(const QColor &color);
virtual QRectF boundingRect() const; virtual QRectF boundingRect() const;
virtual QPainterPath shape() const; virtual QPainterPath shape() const;
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
@ -166,13 +171,13 @@ protected:
private: private:
// TODO // TODO
static const int SIZE_POINT = 7; static const int SIZE_POINT = 4;
QPen m_pen, m_selectedPen; QPen m_pen, m_selectedPen;
QBrush m_brush, m_selectedBrush; QBrush m_brush, m_selectedBrush;
QRectF m_rect; QRectF m_rect;
float m_angle; qreal m_angle;
}; };
/* /*
@ -189,9 +194,11 @@ public:
virtual void moveOn(const QPointF &offset); virtual void moveOn(const QPointF &offset);
virtual void rotateOn(const QPointF &pivot, const qreal deltaAngle); virtual void rotateOn(const QPointF &pivot, const qreal deltaAngle);
virtual void scaleOn(const QPointF &pivot, const QPointF &factor); virtual void scaleOn(const QPointF &pivot, const QPointF &factor);
virtual void turnOn(const QPointF &offset); virtual void turnOn(const qreal angle);
virtual void radiusOn(const qreal radius); virtual void radiusOn(const qreal radius);
virtual void setColor(const QColor &color);
virtual QRectF boundingRect() const; virtual QRectF boundingRect() const;
virtual QPainterPath shape() const; virtual QPainterPath shape() const;
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
@ -217,9 +224,11 @@ public:
virtual void moveOn(const QPointF &offset); virtual void moveOn(const QPointF &offset);
virtual void rotateOn(const QPointF &pivot, const qreal deltaAngle); virtual void rotateOn(const QPointF &pivot, const qreal deltaAngle);
virtual void scaleOn(const QPointF &pivot, const QPointF &factor); virtual void scaleOn(const QPointF &pivot, const QPointF &factor);
virtual void turnOn(const QPointF &offset); virtual void turnOn(const qreal angle);
virtual void radiusOn(const qreal radius); virtual void radiusOn(const qreal radius);
virtual void setColor(const QColor &color);
virtual QRectF boundingRect() const; virtual QRectF boundingRect() const;
virtual QPainterPath shape() const; virtual QPainterPath shape() const;
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
@ -227,6 +236,8 @@ public:
protected: protected:
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
static const int TRANSPARENCY = 28;
QPen m_pen, m_selectedPen; QPen m_pen, m_selectedPen;
QBrush m_brush, m_selectedBrush; QBrush m_brush, m_selectedBrush;
QPolygonF m_polygon; QPolygonF m_polygon;

View file

@ -293,7 +293,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>true</bool>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="world_editor.qrc"> <iconset resource="world_editor.qrc">