mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-11 17:59:03 +00:00
Changed: #1302 Improved selection model.
This commit is contained in:
parent
eb92bf6ef3
commit
b1e2ef90a3
3 changed files with 46 additions and 21 deletions
|
@ -38,11 +38,17 @@ WorldEditorScene::WorldEditorScene(int sizeCell, QObject *parent)
|
||||||
{
|
{
|
||||||
setItemIndexMethod(NoIndex);
|
setItemIndexMethod(NoIndex);
|
||||||
|
|
||||||
m_pen.setColor(QColor(50, 255, 155));
|
m_pen1.setColor(QColor(50, 255, 155));
|
||||||
m_pen.setWidth(0);
|
m_pen1.setWidth(0);
|
||||||
|
|
||||||
m_brush.setColor(QColor(50, 255, 155, 80));
|
m_brush1.setColor(QColor(50, 255, 155, 80));
|
||||||
m_brush.setStyle(Qt::SolidPattern);
|
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()
|
WorldEditorScene::~WorldEditorScene()
|
||||||
|
@ -75,8 +81,6 @@ void WorldEditorScene::setModeEdit(WorldEditorScene::ModeEdit mode)
|
||||||
if (mode == WorldEditorScene::SelectMode)
|
if (mode == WorldEditorScene::SelectMode)
|
||||||
m_editedSelectedItems = false;
|
m_editedSelectedItems = false;
|
||||||
|
|
||||||
m_selectionArea = QRectF();
|
|
||||||
|
|
||||||
m_mode = mode;
|
m_mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,9 +105,18 @@ void WorldEditorScene::drawForeground(QPainter *painter, const QRectF &rect)
|
||||||
|
|
||||||
if ((m_selectionArea.left() != 0) && (m_selectionArea.right() != 0))
|
if ((m_selectionArea.left() != 0) && (m_selectionArea.right() != 0))
|
||||||
{
|
{
|
||||||
painter->setPen(m_pen);
|
if (m_selectionArea.left() < m_selectionArea.right())
|
||||||
painter->setBrush(m_brush);
|
{
|
||||||
|
painter->setPen(m_pen1);
|
||||||
|
painter->setBrush(m_brush1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
painter->setPen(m_pen2);
|
||||||
|
painter->setBrush(m_brush2);
|
||||||
|
}
|
||||||
painter->drawRect(m_selectionArea);
|
painter->drawRect(m_selectionArea);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,6 +130,8 @@ void WorldEditorScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
if (mouseEvent->button() != Qt::LeftButton)
|
if (mouseEvent->button() != Qt::LeftButton)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
m_firstPick = mouseEvent->scenePos();
|
||||||
|
|
||||||
// if ((!m_editedSelectedItems) && (m_mode != WorldEditorScene::SelectMode))
|
// if ((!m_editedSelectedItems) && (m_mode != WorldEditorScene::SelectMode))
|
||||||
if ((!m_editedSelectedItems && m_selectedItems.isEmpty()) ||
|
if ((!m_editedSelectedItems && m_selectedItems.isEmpty()) ||
|
||||||
(!calcBoundingShape(m_selectedItems).contains(mouseEvent->scenePos())))
|
(!calcBoundingShape(m_selectedItems).contains(mouseEvent->scenePos())))
|
||||||
|
@ -217,7 +232,7 @@ void WorldEditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
/*m_mouseX = mouseEvent->scenePos().x();
|
/*m_mouseX = mouseEvent->scenePos().x();
|
||||||
m_mouseY = mouseEvent->scenePos().y() - m_cellSize;
|
m_mouseY = mouseEvent->scenePos().y() - m_cellSize;
|
||||||
*/
|
*/
|
||||||
QGraphicsScene::mouseMoveEvent(mouseEvent);
|
LandscapeEditor::LandscapeSceneBase::mouseMoveEvent(mouseEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldEditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
void WorldEditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
@ -261,12 +276,11 @@ void WorldEditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
updatePickSelection(mouseEvent->scenePos());
|
updatePickSelection(mouseEvent->scenePos());
|
||||||
else
|
else
|
||||||
m_firstSelection = false;
|
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<QGraphicsItem *> &listItems)
|
QRectF WorldEditorScene::calcBoundingRect(const QList<QGraphicsItem *> &listItems)
|
||||||
|
@ -317,15 +331,23 @@ void WorldEditorScene::updatePickSelection(const QPointF &point)
|
||||||
|
|
||||||
QList<QGraphicsItem *> listItems = items(point, Qt::ContainsItemShape,
|
QList<QGraphicsItem *> listItems = items(point, Qt::ContainsItemShape,
|
||||||
Qt::AscendingOrder);
|
Qt::AscendingOrder);
|
||||||
if (!listItems.isEmpty())
|
|
||||||
|
QList<AbstractWorldItem *> worldItemsItems;
|
||||||
|
|
||||||
|
Q_FOREACH(QGraphicsItem *item, listItems)
|
||||||
|
{
|
||||||
|
AbstractWorldItem *worldItem = qgraphicsitem_cast<AbstractWorldItem *>(item);
|
||||||
|
if (worldItem != 0)
|
||||||
|
worldItemsItems.push_back(worldItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!worldItemsItems.isEmpty())
|
||||||
{
|
{
|
||||||
// Next primitives
|
// Next primitives
|
||||||
m_lastPickedPrimitive++;
|
m_lastPickedPrimitive++;
|
||||||
m_lastPickedPrimitive %= listItems.size();
|
m_lastPickedPrimitive %= worldItemsItems.size();
|
||||||
QGraphicsItem *selectedItem = listItems.at(m_lastPickedPrimitive);
|
|
||||||
if (qgraphicsitem_cast<AbstractWorldItem *>(selectedItem) != 0)
|
|
||||||
m_selectedItems.push_back(selectedItem);
|
|
||||||
|
|
||||||
|
m_selectedItems.push_back(worldItemsItems.at(m_lastPickedPrimitive));
|
||||||
updateSelectedItems(true);
|
updateSelectedItems(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,9 +80,10 @@ private:
|
||||||
|
|
||||||
void updatePickSelection(const QPointF &point);
|
void updatePickSelection(const QPointF &point);
|
||||||
|
|
||||||
QPen m_pen;
|
QPen m_pen1, m_pen2;
|
||||||
QBrush m_brush;
|
QBrush m_brush1, m_brush2;
|
||||||
|
|
||||||
|
QPointF m_firstPick;
|
||||||
QRectF m_selectionArea;
|
QRectF m_selectionArea;
|
||||||
qreal m_firstPickX, m_firstPickY;
|
qreal m_firstPickX, m_firstPickY;
|
||||||
QList<QGraphicsItem *> m_selectedItems;
|
QList<QGraphicsItem *> m_selectedItems;
|
||||||
|
|
|
@ -328,6 +328,8 @@ WorldItemPoint::WorldItemPoint(const QPointF &point, const float angle, QGraphic
|
||||||
{
|
{
|
||||||
setZValue(WORLD_POINT_LAYER);
|
setZValue(WORLD_POINT_LAYER);
|
||||||
|
|
||||||
|
//setFlag(ItemIgnoresTransformations);
|
||||||
|
|
||||||
setPos(point);
|
setPos(point);
|
||||||
|
|
||||||
m_rect.setCoords(-SIZE_POINT, -SIZE_POINT, SIZE_POINT, SIZE_POINT);
|
m_rect.setCoords(-SIZE_POINT, -SIZE_POINT, SIZE_POINT, SIZE_POINT);
|
||||||
|
|
Loading…
Reference in a new issue