mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-25 10:20:54 +00:00
Changed: #1302 Improved selection model.
This commit is contained in:
parent
619fd9c997
commit
f614383200
3 changed files with 46 additions and 21 deletions
|
@ -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<QGraphicsItem *> &listItems)
|
||||
|
@ -317,15 +331,23 @@ void WorldEditorScene::updatePickSelection(const QPointF &point)
|
|||
|
||||
QList<QGraphicsItem *> listItems = items(point, Qt::ContainsItemShape,
|
||||
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
|
||||
m_lastPickedPrimitive++;
|
||||
m_lastPickedPrimitive %= listItems.size();
|
||||
QGraphicsItem *selectedItem = listItems.at(m_lastPickedPrimitive);
|
||||
if (qgraphicsitem_cast<AbstractWorldItem *>(selectedItem) != 0)
|
||||
m_selectedItems.push_back(selectedItem);
|
||||
m_lastPickedPrimitive %= worldItemsItems.size();
|
||||
|
||||
m_selectedItems.push_back(worldItemsItems.at(m_lastPickedPrimitive));
|
||||
updateSelectedItems(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<QGraphicsItem *> m_selectedItems;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue