mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-17 13:01:41 +00:00
Changed: #1302 When selecting primitives in the primitives dialog will be selected the appropriate graphics items in scene.
This commit is contained in:
parent
63a755f83e
commit
353847a489
11 changed files with 193 additions and 60 deletions
|
@ -173,6 +173,8 @@ private:
|
||||||
NLLIGO::CPrimitives *m_primitives;
|
NLLIGO::CPrimitives *m_primitives;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef QList<Node *> NodeList;
|
||||||
|
|
||||||
} /* namespace WorldEditor */
|
} /* namespace WorldEditor */
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(WorldEditor::Node *)
|
Q_DECLARE_METATYPE(WorldEditor::Node *)
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
// Project includes
|
// Project includes
|
||||||
#include "primitives_view.h"
|
#include "primitives_view.h"
|
||||||
#include "primitive_item.h"
|
|
||||||
#include "primitives_model.h"
|
#include "primitives_model.h"
|
||||||
#include "world_editor_actions.h"
|
#include "world_editor_actions.h"
|
||||||
|
|
||||||
|
@ -208,7 +207,7 @@ void PrimitivesView::addNewPrimitiveByClass(int value)
|
||||||
QString className = node->primitiveClass()->DynamicChildren[value].ClassName.c_str();
|
QString className = node->primitiveClass()->DynamicChildren[value].ClassName.c_str();
|
||||||
|
|
||||||
m_undoStack->push(new AddPrimitiveByClassCommand(className, m_primitivesTreeModel->pathFromIndex(indexList.first()),
|
m_undoStack->push(new AddPrimitiveByClassCommand(className, m_primitivesTreeModel->pathFromIndex(indexList.first()),
|
||||||
m_primitivesTreeModel));
|
m_worldEditorScene, m_primitivesTreeModel));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrimitivesView::generatePrimitives(int value)
|
void PrimitivesView::generatePrimitives(int value)
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
#ifndef PRIMITIVES_VIEW_H
|
#ifndef PRIMITIVES_VIEW_H
|
||||||
#define PRIMITIVES_VIEW_H
|
#define PRIMITIVES_VIEW_H
|
||||||
|
|
||||||
|
// Project includes
|
||||||
|
#include "primitive_item.h"
|
||||||
|
|
||||||
// NeL includes
|
// NeL includes
|
||||||
#include <nel/ligo/primitive.h>
|
#include <nel/ligo/primitive.h>
|
||||||
|
|
||||||
|
@ -28,6 +31,7 @@
|
||||||
#include <QtCore/QVariant>
|
#include <QtCore/QVariant>
|
||||||
#include <QtCore/QSignalMapper>
|
#include <QtCore/QSignalMapper>
|
||||||
#include <QtGui/QUndoStack>
|
#include <QtGui/QUndoStack>
|
||||||
|
#include <QtGui/QItemSelection>
|
||||||
|
|
||||||
namespace LandscapeEditor
|
namespace LandscapeEditor
|
||||||
{
|
{
|
||||||
|
@ -57,6 +61,9 @@ public:
|
||||||
void setWorldScene(WorldEditorScene *worldEditorScene);
|
void setWorldScene(WorldEditorScene *worldEditorScene);
|
||||||
virtual void setModel(PrimitivesTreeModel *model);
|
virtual void setModel(PrimitivesTreeModel *model);
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
//void selectPrimitives();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void loadLandscape();
|
void loadLandscape();
|
||||||
void loadRootPrimitive();
|
void loadRootPrimitive();
|
||||||
|
|
|
@ -43,6 +43,29 @@
|
||||||
namespace WorldEditor
|
namespace WorldEditor
|
||||||
{
|
{
|
||||||
|
|
||||||
|
QGraphicsItem *getGraphicsItem(Node *node)
|
||||||
|
{
|
||||||
|
QGraphicsItem *result = 0;
|
||||||
|
if (node->type() == Node::PrimitiveNodeType)
|
||||||
|
{
|
||||||
|
PrimitiveNode *primitiveNode = static_cast<PrimitiveNode *>(node);
|
||||||
|
if (primitiveNode != 0)
|
||||||
|
{
|
||||||
|
switch (primitiveNode->primitiveClass()->Type)
|
||||||
|
{
|
||||||
|
case NLLIGO::CPrimitiveClass::Point:
|
||||||
|
case NLLIGO::CPrimitiveClass::Path:
|
||||||
|
case NLLIGO::CPrimitiveClass::Zone:
|
||||||
|
{
|
||||||
|
result = qvariant_cast<AbstractWorldItem *>(primitiveNode->data(Constants::GRAPHICS_DATA_QT4_2D));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *model, WorldEditorScene *scene)
|
void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *model, WorldEditorScene *scene)
|
||||||
{
|
{
|
||||||
PrimitiveNode *node = static_cast<PrimitiveNode *>(primIndex.internalPointer());
|
PrimitiveNode *node = static_cast<PrimitiveNode *>(primIndex.internalPointer());
|
||||||
|
@ -53,6 +76,10 @@ 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;
|
||||||
AbstractWorldItem *item = 0;
|
AbstractWorldItem *item = 0;
|
||||||
|
|
||||||
|
// Draw arrow ?
|
||||||
|
bool showArrow = node->primitiveClass()->ShowArrow;
|
||||||
|
|
||||||
switch (node->primitiveClass()->Type)
|
switch (node->primitiveClass()->Type)
|
||||||
{
|
{
|
||||||
case NLLIGO::CPrimitiveClass::Point:
|
case NLLIGO::CPrimitiveClass::Point:
|
||||||
|
@ -60,9 +87,6 @@ void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode
|
||||||
vec = primitive->getPrimVector();
|
vec = primitive->getPrimVector();
|
||||||
NLLIGO::CPrimPoint *primPoint = static_cast<NLLIGO::CPrimPoint *>(primitive);
|
NLLIGO::CPrimPoint *primPoint = static_cast<NLLIGO::CPrimPoint *>(primitive);
|
||||||
|
|
||||||
// Draw arrow ?
|
|
||||||
bool showArrow = node->primitiveClass()->ShowArrow;
|
|
||||||
|
|
||||||
// Have a radius ?
|
// Have a radius ?
|
||||||
std::string strRadius;
|
std::string strRadius;
|
||||||
qreal radius = 0;
|
qreal radius = 0;
|
||||||
|
@ -85,7 +109,7 @@ void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode
|
||||||
++vec;
|
++vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
item = scene->addWorldItemPath(polygon);
|
item = scene->addWorldItemPath(polygon, showArrow);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NLLIGO::CPrimitiveClass::Zone:
|
case NLLIGO::CPrimitiveClass::Zone:
|
||||||
|
@ -153,22 +177,13 @@ void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode
|
||||||
|
|
||||||
void removeGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *model, WorldEditorScene *scene)
|
void removeGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *model, WorldEditorScene *scene)
|
||||||
{
|
{
|
||||||
PrimitiveNode *node = static_cast<PrimitiveNode *>(primIndex.internalPointer());
|
Node *node = static_cast<Node *>(primIndex.internalPointer());
|
||||||
|
|
||||||
if (node != 0)
|
if (node != 0)
|
||||||
{
|
{
|
||||||
switch (node->primitiveClass()->Type)
|
QGraphicsItem *item = getGraphicsItem(node);
|
||||||
{
|
if (item != 0)
|
||||||
case NLLIGO::CPrimitiveClass::Point:
|
scene->removeWorldItem(item);
|
||||||
case NLLIGO::CPrimitiveClass::Path:
|
|
||||||
case NLLIGO::CPrimitiveClass::Zone:
|
|
||||||
{
|
|
||||||
QGraphicsItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
||||||
if (item != 0)
|
|
||||||
scene->removeWorldItem(item);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int count = model->rowCount(primIndex);
|
int count = model->rowCount(primIndex);
|
||||||
|
@ -334,10 +349,11 @@ void LoadRootPrimitiveCommand::redo()
|
||||||
}
|
}
|
||||||
|
|
||||||
AddPrimitiveByClassCommand::AddPrimitiveByClassCommand(const QString &className, const Path &parentIndex,
|
AddPrimitiveByClassCommand::AddPrimitiveByClassCommand(const QString &className, const Path &parentIndex,
|
||||||
PrimitivesTreeModel *model, QUndoCommand *parent)
|
WorldEditorScene *scene, PrimitivesTreeModel *model, QUndoCommand *parent)
|
||||||
: QUndoCommand(parent),
|
: QUndoCommand(parent),
|
||||||
m_className(className),
|
m_className(className),
|
||||||
m_parentIndex(parentIndex),
|
m_parentIndex(parentIndex),
|
||||||
|
m_scene(scene),
|
||||||
m_model(model)
|
m_model(model)
|
||||||
{
|
{
|
||||||
setText(QString("Add %1").arg(m_className));
|
setText(QString("Add %1").arg(m_className));
|
||||||
|
|
|
@ -36,7 +36,15 @@ namespace WorldEditor
|
||||||
{
|
{
|
||||||
class WorldEditorScene;
|
class WorldEditorScene;
|
||||||
|
|
||||||
|
// Auxiliary operations
|
||||||
|
|
||||||
|
// Return QGraphicsItem if node contains it
|
||||||
|
QGraphicsItem *getGraphicsItem(Node *node);
|
||||||
|
|
||||||
|
// Scan primitives model for create/add necessary QGraphicsItems
|
||||||
void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *model, WorldEditorScene *scene);
|
void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *model, WorldEditorScene *scene);
|
||||||
|
|
||||||
|
// Recursive scan primitives model for delete Graphics Items
|
||||||
void removeGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *model, WorldEditorScene *scene);
|
void removeGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *model, WorldEditorScene *scene);
|
||||||
QList<Path> graphicsItemsToPaths(const QList<QGraphicsItem *> &items, PrimitivesTreeModel *model);
|
QList<Path> graphicsItemsToPaths(const QList<QGraphicsItem *> &items, PrimitivesTreeModel *model);
|
||||||
//QList<GraphicsItem *> pathsToGraphicsItems(const QList<Path> &items, PrimitivesTreeModel *model);
|
//QList<GraphicsItem *> pathsToGraphicsItems(const QList<Path> &items, PrimitivesTreeModel *model);
|
||||||
|
@ -130,7 +138,8 @@ class AddPrimitiveByClassCommand: public QUndoCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AddPrimitiveByClassCommand(const QString &className, const Path &parentIndex,
|
AddPrimitiveByClassCommand(const QString &className, const Path &parentIndex,
|
||||||
PrimitivesTreeModel *model, QUndoCommand *parent = 0);
|
WorldEditorScene *scene, PrimitivesTreeModel *model,
|
||||||
|
QUndoCommand *parent = 0);
|
||||||
virtual ~AddPrimitiveByClassCommand();
|
virtual ~AddPrimitiveByClassCommand();
|
||||||
|
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
|
@ -139,6 +148,7 @@ private:
|
||||||
|
|
||||||
const QString m_className;
|
const QString m_className;
|
||||||
Path m_parentIndex, m_newPrimIndex;
|
Path m_parentIndex, m_newPrimIndex;
|
||||||
|
WorldEditorScene *m_scene;
|
||||||
PrimitivesTreeModel *m_model;
|
PrimitivesTreeModel *m_model;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,9 @@ WorldEditorScene::WorldEditorScene(int sizeCell, PrimitivesTreeModel *model, QUn
|
||||||
{
|
{
|
||||||
setItemIndexMethod(NoIndex);
|
setItemIndexMethod(NoIndex);
|
||||||
|
|
||||||
|
// TODO: get params from settings
|
||||||
|
setSceneRect(QRectF(-20 * 160, -20 * 160, 256 * 160, 256 * 160));
|
||||||
|
|
||||||
m_pen1.setColor(QColor(50, 255, 155));
|
m_pen1.setColor(QColor(50, 255, 155));
|
||||||
m_pen1.setWidth(0);
|
m_pen1.setWidth(0);
|
||||||
|
|
||||||
|
@ -67,7 +70,7 @@ AbstractWorldItem *WorldEditorScene::addWorldItemPoint(const QPointF &point, con
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractWorldItem *WorldEditorScene::addWorldItemPath(const QPolygonF &polyline)
|
AbstractWorldItem *WorldEditorScene::addWorldItemPath(const QPolygonF &polyline, bool showArrow)
|
||||||
{
|
{
|
||||||
WorldItemPath *item = new WorldItemPath(polyline);
|
WorldItemPath *item = new WorldItemPath(polyline);
|
||||||
addItem(item);
|
addItem(item);
|
||||||
|
@ -113,6 +116,31 @@ void WorldEditorScene::setEnabledEditPoint(bool enabled)
|
||||||
m_editMode = enabled;
|
m_editMode = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldEditorScene::updateSelection(const QList<QGraphicsItem *> &selected, const QList<QGraphicsItem *> &deselected)
|
||||||
|
{
|
||||||
|
// Deselect and remove from list graphics items.
|
||||||
|
Q_FOREACH(QGraphicsItem *item, deselected)
|
||||||
|
{
|
||||||
|
// Item is selected?
|
||||||
|
int i = m_selectedItems.indexOf(item);
|
||||||
|
if (i != -1)
|
||||||
|
{
|
||||||
|
updateSelectedItem(item, false);
|
||||||
|
m_selectedItems.takeAt(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select and add from list graphics items.
|
||||||
|
Q_FOREACH(QGraphicsItem *item, selected)
|
||||||
|
{
|
||||||
|
updateSelectedItem(item, true);
|
||||||
|
m_selectedItems.push_back(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
update();
|
||||||
|
m_editedSelectedItems = true;
|
||||||
|
}
|
||||||
|
|
||||||
void WorldEditorScene::drawForeground(QPainter *painter, const QRectF &rect)
|
void WorldEditorScene::drawForeground(QPainter *painter, const QRectF &rect)
|
||||||
{
|
{
|
||||||
QGraphicsScene::drawForeground(painter, rect);
|
QGraphicsScene::drawForeground(painter, rect);
|
||||||
|
@ -138,15 +166,11 @@ void WorldEditorScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
{
|
{
|
||||||
LandscapeEditor::LandscapeSceneBase::mousePressEvent(mouseEvent);
|
LandscapeEditor::LandscapeSceneBase::mousePressEvent(mouseEvent);
|
||||||
|
|
||||||
qreal x = mouseEvent->scenePos().x();
|
|
||||||
qreal y = mouseEvent->scenePos().y();
|
|
||||||
|
|
||||||
if (mouseEvent->button() != Qt::LeftButton)
|
if (mouseEvent->button() != Qt::LeftButton)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_firstPick = mouseEvent->scenePos();
|
m_firstPick = mouseEvent->scenePos();
|
||||||
|
|
||||||
// if ((!m_editedSelectedItems) && (m_mode != WorldEditorScene::SelectMode))
|
|
||||||
if ((!m_editedSelectedItems && m_selectedItems.isEmpty()) ||
|
if ((!m_editedSelectedItems && m_selectedItems.isEmpty()) ||
|
||||||
(!calcBoundingRect(m_selectedItems).contains(mouseEvent->scenePos())))
|
(!calcBoundingRect(m_selectedItems).contains(mouseEvent->scenePos())))
|
||||||
{
|
{
|
||||||
|
@ -183,12 +207,19 @@ void WorldEditorScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
m_selectHack = true;
|
||||||
// if (m_selectedItems.isEmpty())
|
// if (m_selectedItems.isEmpty())
|
||||||
// m_selectionArea.setTopLeft(mouseEvent->scenePos());
|
// m_selectionArea.setTopLeft(mouseEvent->scenePos());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldEditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
void WorldEditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
{
|
{
|
||||||
|
if (m_selectHack)
|
||||||
|
{
|
||||||
|
m_selectHack = false;
|
||||||
|
updateSelectedItems(true);
|
||||||
|
}
|
||||||
|
|
||||||
if (QApplication::mouseButtons() == Qt::LeftButton)
|
if (QApplication::mouseButtons() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -379,20 +410,25 @@ void WorldEditorScene::updateSelectedItems(bool value)
|
||||||
{
|
{
|
||||||
Q_FOREACH(QGraphicsItem *item, m_selectedItems)
|
Q_FOREACH(QGraphicsItem *item, m_selectedItems)
|
||||||
{
|
{
|
||||||
if (value)
|
updateSelectedItem(item, value);
|
||||||
{
|
|
||||||
item->setFlag(QGraphicsItem::ItemIsSelectable);
|
|
||||||
//item->setZValue(SELECTED_LAYER);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
item->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
|
||||||
//item->setZValue(UNSELECTED_LAYER);
|
|
||||||
}
|
|
||||||
item->setSelected(value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldEditorScene::updateSelectedItem(QGraphicsItem *item, bool value)
|
||||||
|
{
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
|
item->setFlag(QGraphicsItem::ItemIsSelectable);
|
||||||
|
//item->setZValue(SELECTED_LAYER);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
item->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
||||||
|
//item->setZValue(UNSELECTED_LAYER);
|
||||||
|
}
|
||||||
|
item->setSelected(value);
|
||||||
|
}
|
||||||
|
|
||||||
void WorldEditorScene::updatePickSelection(const QPointF &point)
|
void WorldEditorScene::updatePickSelection(const QPointF &point)
|
||||||
{
|
{
|
||||||
//clearSelection();
|
//clearSelection();
|
||||||
|
|
|
@ -58,9 +58,8 @@ public:
|
||||||
|
|
||||||
AbstractWorldItem *addWorldItemPoint(const QPointF &point, const qreal angle,
|
AbstractWorldItem *addWorldItemPoint(const QPointF &point, const qreal angle,
|
||||||
const qreal radius, bool showArrow);
|
const qreal radius, bool showArrow);
|
||||||
AbstractWorldItem *addWorldItemPath(const QPolygonF &polyline);
|
AbstractWorldItem *addWorldItemPath(const QPolygonF &polyline, bool showArrow);
|
||||||
AbstractWorldItem *addWorldItemZone(const QPolygonF &polygon);
|
AbstractWorldItem *addWorldItemZone(const QPolygonF &polygon);
|
||||||
|
|
||||||
void removeWorldItem(QGraphicsItem *item);
|
void removeWorldItem(QGraphicsItem *item);
|
||||||
|
|
||||||
void setModeEdit(WorldEditorScene::ModeEdit mode);
|
void setModeEdit(WorldEditorScene::ModeEdit mode);
|
||||||
|
@ -70,6 +69,7 @@ public:
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void setEnabledEditPoint(bool enabled);
|
void setEnabledEditPoint(bool enabled);
|
||||||
|
void updateSelection(const QList<QGraphicsItem *> &selected, const QList<QGraphicsItem *> &deselected);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void drawForeground(QPainter *painter, const QRectF &rect);
|
virtual void drawForeground(QPainter *painter, const QRectF &rect);
|
||||||
|
@ -83,12 +83,13 @@ private:
|
||||||
QRectF calcBoundingRect(const QList<QGraphicsItem *> &listItems);
|
QRectF calcBoundingRect(const QList<QGraphicsItem *> &listItems);
|
||||||
QPainterPath calcBoundingShape(const QList<QGraphicsItem *> &listItems);
|
QPainterPath calcBoundingShape(const QList<QGraphicsItem *> &listItems);
|
||||||
void updateSelectedItems(bool value);
|
void updateSelectedItems(bool value);
|
||||||
|
void updateSelectedItem(QGraphicsItem *item, bool value);
|
||||||
void updatePickSelection(const QPointF &point);
|
void updatePickSelection(const QPointF &point);
|
||||||
|
|
||||||
QPen m_pen1, m_pen2;
|
QPen m_pen1, m_pen2;
|
||||||
QBrush m_brush1, m_brush2;
|
QBrush m_brush1, m_brush2;
|
||||||
|
|
||||||
|
bool m_selectHack;
|
||||||
QPointF m_firstPick, m_scaleFactor, m_pivot;
|
QPointF m_firstPick, m_scaleFactor, m_pivot;
|
||||||
QRectF m_selectionArea;
|
QRectF m_selectionArea;
|
||||||
qreal m_firstPickX, m_firstPickY, m_angle;
|
qreal m_firstPickX, m_firstPickY, m_angle;
|
||||||
|
|
|
@ -349,21 +349,7 @@ WorldItemPoint::WorldItemPoint(const QPointF &point, const qreal angle, const qr
|
||||||
m_selectedBrush.setColor(Qt::white);
|
m_selectedBrush.setColor(Qt::white);
|
||||||
m_selectedBrush.setStyle(Qt::SolidPattern);
|
m_selectedBrush.setStyle(Qt::SolidPattern);
|
||||||
|
|
||||||
|
createCircle();
|
||||||
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
|
// Create arrow
|
||||||
if (showArrow)
|
if (showArrow)
|
||||||
|
@ -373,6 +359,7 @@ WorldItemPoint::WorldItemPoint(const QPointF &point, const qreal angle, const qr
|
||||||
m_arrow.push_back(QLine(SIZE_ARROW - 2, 2, SIZE_ARROW, 0));
|
m_arrow.push_back(QLine(SIZE_ARROW - 2, 2, SIZE_ARROW, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateBoundingRect();
|
||||||
//setFlag(ItemIsSelectable);
|
//setFlag(ItemIsSelectable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,6 +411,8 @@ void WorldItemPoint::turnOn(const qreal angle)
|
||||||
|
|
||||||
void WorldItemPoint::radiusOn(const qreal radius)
|
void WorldItemPoint::radiusOn(const qreal radius)
|
||||||
{
|
{
|
||||||
|
if (m_radius == 0)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldItemPoint::setColor(const QColor &color)
|
void WorldItemPoint::setColor(const QColor &color)
|
||||||
|
@ -432,18 +421,43 @@ void WorldItemPoint::setColor(const QColor &color)
|
||||||
m_brush.setColor(color);
|
m_brush.setColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldItemPoint::createCircle()
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldItemPoint::updateBoundingRect()
|
||||||
|
{
|
||||||
|
m_boundingRect.setCoords(-SIZE_POINT, -SIZE_POINT, SIZE_POINT, SIZE_POINT);
|
||||||
|
QRectF circleBoundingRect;
|
||||||
|
circleBoundingRect.setCoords(-m_radius, -m_radius, m_radius, m_radius);
|
||||||
|
m_boundingRect = m_boundingRect.united(circleBoundingRect);
|
||||||
|
}
|
||||||
|
|
||||||
QPainterPath WorldItemPoint::shape() const
|
QPainterPath WorldItemPoint::shape() const
|
||||||
{
|
{
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
|
|
||||||
path.addRect(m_rect);
|
path.addRect(m_boundingRect);
|
||||||
|
|
||||||
return qt_graphicsItem_shapeFromPath(path, m_pen);
|
return qt_graphicsItem_shapeFromPath(path, m_pen);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF WorldItemPoint::boundingRect() const
|
QRectF WorldItemPoint::boundingRect() const
|
||||||
{
|
{
|
||||||
return m_rect;
|
return m_boundingRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldItemPoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
|
void WorldItemPoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
|
||||||
|
|
|
@ -168,6 +168,8 @@ protected:
|
||||||
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void createCircle();
|
||||||
|
void updateBoundingRect();
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
static const int SIZE_POINT = 3;
|
static const int SIZE_POINT = 3;
|
||||||
|
@ -177,7 +179,7 @@ private:
|
||||||
|
|
||||||
QPolygonF m_circle;
|
QPolygonF m_circle;
|
||||||
QVector<QLine> m_arrow;
|
QVector<QLine> m_arrow;
|
||||||
QRectF m_rect;
|
QRectF m_rect, m_boundingRect;
|
||||||
qreal m_angle, m_radius;
|
qreal m_angle, m_radius;
|
||||||
bool m_showArrow;
|
bool m_showArrow;
|
||||||
};
|
};
|
||||||
|
@ -236,7 +238,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||||
|
|
||||||
static const int TRANSPARENCY = 28;
|
static const int TRANSPARENCY = 38;
|
||||||
|
|
||||||
QPen m_pen, m_selectedPen;
|
QPen m_pen, m_selectedPen;
|
||||||
QBrush m_brush, m_selectedBrush;
|
QBrush m_brush, m_selectedBrush;
|
||||||
|
|
|
@ -105,6 +105,9 @@ WorldEditorWindow::WorldEditorWindow(QWidget *parent)
|
||||||
connect(m_ui.saveWorldEditAction, SIGNAL(triggered()), this, SLOT(saveWorldEditFile()));
|
connect(m_ui.saveWorldEditAction, SIGNAL(triggered()), this, SLOT(saveWorldEditFile()));
|
||||||
connect(m_ui.visibleGridAction, SIGNAL(toggled(bool)), m_ui.graphicsView, SLOT(setVisibleGrid(bool)));
|
connect(m_ui.visibleGridAction, SIGNAL(toggled(bool)), m_ui.graphicsView, SLOT(setVisibleGrid(bool)));
|
||||||
|
|
||||||
|
connect(m_ui.treePrimitivesView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
|
||||||
|
this, SLOT(updateSelection(QItemSelection, QItemSelection)));
|
||||||
|
|
||||||
m_statusBarTimer = new QTimer(this);
|
m_statusBarTimer = new QTimer(this);
|
||||||
connect(m_statusBarTimer, SIGNAL(timeout()), this, SLOT(updateStatusBar()));
|
connect(m_statusBarTimer, SIGNAL(timeout()), this, SLOT(updateStatusBar()));
|
||||||
|
|
||||||
|
@ -250,6 +253,47 @@ void WorldEditorWindow::updateStatusBar()
|
||||||
m_statusInfo->setText(m_worldEditorScene->zoneNameFromMousePos());
|
m_statusInfo->setText(m_worldEditorScene->zoneNameFromMousePos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldEditorWindow::updateSelection(const QItemSelection &selected, const QItemSelection &deselected)
|
||||||
|
{
|
||||||
|
m_ui.pointsAction->setChecked(false);
|
||||||
|
|
||||||
|
NodeList nodesSelected;
|
||||||
|
Q_FOREACH(QModelIndex modelIndex, selected.indexes())
|
||||||
|
{
|
||||||
|
Node *node = static_cast<Node *>(modelIndex.internalPointer());
|
||||||
|
nodesSelected.push_back(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeList nodesDeselected;
|
||||||
|
Q_FOREACH(QModelIndex modelIndex, deselected.indexes())
|
||||||
|
{
|
||||||
|
Node *node = static_cast<Node *>(modelIndex.internalPointer());
|
||||||
|
nodesDeselected.push_back(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: update property editor
|
||||||
|
// ...
|
||||||
|
|
||||||
|
QList<QGraphicsItem *> itemSelected;
|
||||||
|
Q_FOREACH(Node *node, nodesSelected)
|
||||||
|
{
|
||||||
|
QGraphicsItem *item = getGraphicsItem(node);
|
||||||
|
if (item != 0)
|
||||||
|
itemSelected.push_back(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QGraphicsItem *> itemDeselected;
|
||||||
|
Q_FOREACH(Node *node, nodesDeselected)
|
||||||
|
{
|
||||||
|
QGraphicsItem *item = getGraphicsItem(node);
|
||||||
|
if (item != 0)
|
||||||
|
itemDeselected.push_back(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update world editor scene
|
||||||
|
m_worldEditorScene->updateSelection(itemSelected, itemDeselected);
|
||||||
|
}
|
||||||
|
|
||||||
void WorldEditorWindow::showEvent(QShowEvent *showEvent)
|
void WorldEditorWindow::showEvent(QShowEvent *showEvent)
|
||||||
{
|
{
|
||||||
QMainWindow::showEvent(showEvent);
|
QMainWindow::showEvent(showEvent);
|
||||||
|
|
|
@ -60,6 +60,8 @@ private Q_SLOTS:
|
||||||
void setMode(int value);
|
void setMode(int value);
|
||||||
void updateStatusBar();
|
void updateStatusBar();
|
||||||
|
|
||||||
|
void updateSelection(const QItemSelection &selected, const QItemSelection &deselected);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void showEvent(QShowEvent *showEvent);
|
virtual void showEvent(QShowEvent *showEvent);
|
||||||
virtual void hideEvent(QHideEvent *hideEvent);
|
virtual void hideEvent(QHideEvent *hideEvent);
|
||||||
|
|
Loading…
Reference in a new issue