From b1e2ef90a3ff19705634a3a440286116b9cb7f03 Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Wed, 10 Aug 2011 15:00:47 +0300 Subject: [PATCH] Changed: #1302 Improved selection model. --- .../world_editor/world_editor_scene.cpp | 60 +++++++++++++------ .../plugins/world_editor/world_editor_scene.h | 5 +- .../world_editor/world_editor_scene_item.cpp | 2 + 3 files changed, 46 insertions(+), 21 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.cpp index fd2d85a24..1e21ee0ec 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.cpp @@ -38,11 +38,17 @@ WorldEditorScene::WorldEditorScene(int sizeCell, QObject *parent) { setItemIndexMethod(NoIndex); - m_pen.setColor(QColor(50, 255, 155)); - m_pen.setWidth(0); + m_pen1.setColor(QColor(50, 255, 155)); + m_pen1.setWidth(0); - m_brush.setColor(QColor(50, 255, 155, 80)); - m_brush.setStyle(Qt::SolidPattern); + m_brush1.setColor(QColor(50, 255, 155, 80)); + m_brush1.setStyle(Qt::SolidPattern); + + m_pen2.setColor(QColor(100, 0, 255)); + m_pen2.setWidth(0); + + m_brush2.setColor(QColor(100, 0, 255, 80)); + m_brush2.setStyle(Qt::SolidPattern); } WorldEditorScene::~WorldEditorScene() @@ -75,8 +81,6 @@ void WorldEditorScene::setModeEdit(WorldEditorScene::ModeEdit mode) if (mode == WorldEditorScene::SelectMode) m_editedSelectedItems = false; - m_selectionArea = QRectF(); - m_mode = mode; } @@ -101,9 +105,18 @@ void WorldEditorScene::drawForeground(QPainter *painter, const QRectF &rect) if ((m_selectionArea.left() != 0) && (m_selectionArea.right() != 0)) { - painter->setPen(m_pen); - painter->setBrush(m_brush); + if (m_selectionArea.left() < m_selectionArea.right()) + { + painter->setPen(m_pen1); + painter->setBrush(m_brush1); + } + else + { + painter->setPen(m_pen2); + painter->setBrush(m_brush2); + } painter->drawRect(m_selectionArea); + } } @@ -117,6 +130,8 @@ void WorldEditorScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) if (mouseEvent->button() != Qt::LeftButton) return; + m_firstPick = mouseEvent->scenePos(); + // if ((!m_editedSelectedItems) && (m_mode != WorldEditorScene::SelectMode)) if ((!m_editedSelectedItems && m_selectedItems.isEmpty()) || (!calcBoundingShape(m_selectedItems).contains(mouseEvent->scenePos()))) @@ -217,7 +232,7 @@ void WorldEditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) /*m_mouseX = mouseEvent->scenePos().x(); m_mouseY = mouseEvent->scenePos().y() - m_cellSize; */ - QGraphicsScene::mouseMoveEvent(mouseEvent); + LandscapeEditor::LandscapeSceneBase::mouseMoveEvent(mouseEvent); } void WorldEditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) @@ -261,12 +276,11 @@ void WorldEditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) updatePickSelection(mouseEvent->scenePos()); else m_firstSelection = false; - } -// Huck for standart selection model -// clearSelection(); -// updateSelectedItems(true); - QGraphicsScene::mouseReleaseEvent(mouseEvent); + m_selectionArea = QRectF(); + } + + LandscapeEditor::LandscapeSceneBase::mouseReleaseEvent(mouseEvent); } QRectF WorldEditorScene::calcBoundingRect(const QList &listItems) @@ -317,15 +331,23 @@ void WorldEditorScene::updatePickSelection(const QPointF &point) QList listItems = items(point, Qt::ContainsItemShape, Qt::AscendingOrder); - if (!listItems.isEmpty()) + + QList worldItemsItems; + + Q_FOREACH(QGraphicsItem *item, listItems) + { + AbstractWorldItem *worldItem = qgraphicsitem_cast(item); + if (worldItem != 0) + worldItemsItems.push_back(worldItem); + } + + if (!worldItemsItems.isEmpty()) { // Next primitives m_lastPickedPrimitive++; - m_lastPickedPrimitive %= listItems.size(); - QGraphicsItem *selectedItem = listItems.at(m_lastPickedPrimitive); - if (qgraphicsitem_cast(selectedItem) != 0) - m_selectedItems.push_back(selectedItem); + m_lastPickedPrimitive %= worldItemsItems.size(); + m_selectedItems.push_back(worldItemsItems.at(m_lastPickedPrimitive)); updateSelectedItems(true); } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.h index 36f27b9b4..b97b9672c 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.h @@ -80,9 +80,10 @@ private: void updatePickSelection(const QPointF &point); - QPen m_pen; - QBrush m_brush; + QPen m_pen1, m_pen2; + QBrush m_brush1, m_brush2; + QPointF m_firstPick; QRectF m_selectionArea; qreal m_firstPickX, m_firstPickY; QList m_selectedItems; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene_item.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene_item.cpp index f88c95b9a..d428aed51 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene_item.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene_item.cpp @@ -328,6 +328,8 @@ WorldItemPoint::WorldItemPoint(const QPointF &point, const float angle, QGraphic { setZValue(WORLD_POINT_LAYER); + //setFlag(ItemIgnoresTransformations); + setPos(point); m_rect.setCoords(-SIZE_POINT, -SIZE_POINT, SIZE_POINT, SIZE_POINT);