Changed: #1302 When create zone or path initially has minimal 3 points and path 2 points resp.

--HG--
branch : gsoc2011-worldeditorqt
This commit is contained in:
dnk-88 2011-08-16 01:10:22 +03:00
parent 434ce9d6a9
commit 054e5c521c
6 changed files with 64 additions and 15 deletions

View file

@ -38,6 +38,7 @@
// Qt includes
#include <QModelIndex>
#include <QGraphicsView>
#include <QPersistentModelIndex>
namespace WorldEditor
@ -365,6 +366,13 @@ AddPrimitiveByClassCommand::AddPrimitiveByClassCommand(const QString &className,
m_model(model)
{
setText(QString("Add %1").arg(m_className));
QGraphicsView *view = m_scene->views().first();
// TODO: returns incorrect position when zoom in
QRectF visibleArea = view->mapToScene(view->rect()).boundingRect();
m_delta = visibleArea.height() / 10.0;
m_initPos = visibleArea.center();
}
AddPrimitiveByClassCommand::~AddPrimitiveByClassCommand()
@ -381,6 +389,8 @@ void AddPrimitiveByClassCommand::undo()
// set the primitive context
NLLIGO::CPrimitiveContext::instance().CurrentPrimitive = node->rootPrimitiveNode()->primitives();
removeGraphicsItems(index, m_model, m_scene);
Utils::deletePrimitive(node->primitive());
// unset the context
@ -397,7 +407,6 @@ void AddPrimitiveByClassCommand::redo()
PrimitiveNode *parentNode = static_cast<PrimitiveNode *>(parentIndex.internalPointer());
const NLLIGO::CPrimitiveClass *primClass = parentNode->primitiveClass();
float delta = 10;
int id = 0;
while (primClass->DynamicChildren[id].ClassName != m_className.toStdString())
++id;
@ -407,12 +416,14 @@ void AddPrimitiveByClassCommand::redo()
QString namePrimititve = QString("%1_%2").arg(m_className).arg(parentNode->childCount());
NLLIGO::IPrimitive *newPrimitive = Utils::createPrimitive(m_className.toStdString().c_str(), namePrimititve.toStdString().c_str(),
NLMISC::CVector(), delta, primClass->DynamicChildren[id].Parameters, parentNode->primitive());
NLMISC::CVector(m_initPos.x(), -m_initPos.y(), 0.0), m_delta, primClass->DynamicChildren[id].Parameters, parentNode->primitive());
// unset the context
NLLIGO::CPrimitiveContext::instance().CurrentPrimitive = NULL;
m_newPrimIndex = m_model->createPrimitiveNode(newPrimitive, m_parentIndex);
addNewGraphicsItems(m_model->pathToIndex(m_newPrimIndex), m_model, m_scene);
}
MoveWorldItemsCommand::MoveWorldItemsCommand(const QList<QGraphicsItem *> &items, const QPointF &offset,
@ -471,7 +482,7 @@ RotateWorldItemsCommand::RotateWorldItemsCommand(const QList<QGraphicsItem *> &i
m_scene(scene),
m_firstRun(true)
{
setText(QString("Rotate item(s) %1").arg(m_angle));
setText("Rotate item(s)");
}
RotateWorldItemsCommand::~RotateWorldItemsCommand()
@ -565,7 +576,7 @@ TurnWorldItemsCommand::TurnWorldItemsCommand(const QList<QGraphicsItem *> &items
m_scene(scene),
m_firstRun(true)
{
setText(QString("Turn item(s) %1").arg(m_angle));
setText("Turn item(s)");
}
TurnWorldItemsCommand::~TurnWorldItemsCommand()

View file

@ -147,6 +147,8 @@ public:
virtual void redo();
private:
QPointF m_initPos;
float m_delta;
const QString m_className;
Path m_parentIndex, m_newPrimIndex;
WorldEditorScene *m_scene;

View file

@ -365,11 +365,25 @@ NLLIGO::IPrimitive *createPrimitive(const char *className, const char *primName,
}
break;
case NLLIGO::CPrimitiveClass::Path:
primitive = new NLLIGO::CPrimPath;
{
NLLIGO::CPrimPath *path = new NLLIGO::CPrimPath;
primitive = path;
path->VPoints.push_back(NLLIGO::CPrimVector(initPos));
NLMISC::CVector secondPos = NLMISC::CVector(initPos.x + deltaPos, initPos.y, 0.0);
path->VPoints.push_back(NLLIGO::CPrimVector(secondPos));
break;
}
case NLLIGO::CPrimitiveClass::Zone:
primitive = new NLLIGO::CPrimZone;
{
NLLIGO::CPrimZone *zone = new NLLIGO::CPrimZone;
primitive = zone;
zone->VPoints.push_back(NLLIGO::CPrimVector(initPos));
NLMISC::CVector secondPos = NLMISC::CVector(initPos.x + deltaPos, initPos.y, 0.0);
zone->VPoints.push_back(NLLIGO::CPrimVector(secondPos));
secondPos.y = initPos.y + deltaPos;
zone->VPoints.push_back(NLLIGO::CPrimVector(secondPos));
break;
}
case NLLIGO::CPrimitiveClass::Alias:
primitive = new NLLIGO::CPrimAlias;
break;

View file

@ -187,7 +187,7 @@ void WorldItemPoint::createCircle()
if (m_radius != 0)
{
// Create circle
int segmentCount = 30;
int segmentCount = 20;
QPointF circlePoint(m_radius, 0);
m_circle << circlePoint;
for (int i = 1; i < segmentCount + 1; ++i)
@ -241,9 +241,13 @@ void WorldItemPoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
painter->setPen(Qt::NoPen);
// if (option->state & QStyle::State_Selected)
if (isActived())
{
painter->setBrush(m_selectedBrush);
}
else
{
painter->setBrush(m_brush);
}
// Draw point
painter->drawRect(m_rect);

View file

@ -129,7 +129,7 @@ private:
void createCircle();
void updateBoundingRect();
static const int SIZE_POINT = 3;
static const int SIZE_POINT = 2;
QPen m_pen, m_selectedPen;
QBrush m_brush, m_selectedBrush;

View file

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<width>819</width>
<height>600</height>
</rect>
</property>
@ -121,8 +121,9 @@
<bool>false</bool>
</attribute>
<addaction name="visibleLandAction"/>
<addaction name="visiblePrimitivesAction"/>
<addaction name="visibleLayersAction"/>
<addaction name="visibleZonePrimitivesAction"/>
<addaction name="visiblePathPrimitivesAction"/>
<addaction name="vidiblePointPrimitives"/>
<addaction name="visibleDetailsAction"/>
<addaction name="visibleGridAction"/>
<addaction name="visibleGridPointsAction"/>
@ -177,7 +178,7 @@
<string>S/H Land</string>
</property>
</action>
<action name="visiblePrimitivesAction">
<action name="visibleZonePrimitivesAction">
<property name="checkable">
<bool>true</bool>
</property>
@ -185,10 +186,13 @@
<bool>false</bool>
</property>
<property name="text">
<string>S/H Primitives</string>
<string>S/H Zone primitives</string>
</property>
<property name="toolTip">
<string>S/H Zone Primitives</string>
</property>
</action>
<action name="visibleLayersAction">
<action name="visiblePathPrimitivesAction">
<property name="checkable">
<bool>true</bool>
</property>
@ -196,7 +200,7 @@
<bool>false</bool>
</property>
<property name="text">
<string>S/H Layers</string>
<string>S/H Path primitives</string>
</property>
</action>
<action name="visibleDetailsAction">
@ -343,6 +347,20 @@
<string>Project settings</string>
</property>
</action>
<action name="vidiblePointPrimitives">
<property name="checkable">
<bool>true</bool>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>S/H Points primitives</string>
</property>
<property name="toolTip">
<string>S/H Points primitives</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>