|
@@ -4,6 +4,8 @@
|
4
|
4
|
#include <QPainter>
|
5
|
5
|
#include <QMouseEvent>
|
6
|
6
|
|
|
7
|
+bool selectingEvent = false;
|
|
8
|
+
|
7
|
9
|
Editor::Editor(Ui::MainWindow* ui)
|
8
|
10
|
{
|
9
|
11
|
this->ui = ui;
|
|
@@ -469,6 +471,8 @@ void Editor::displayMapEvents() {
|
469
|
471
|
delete events_group;
|
470
|
472
|
}
|
471
|
473
|
|
|
474
|
+ selected_events->clear();
|
|
475
|
+
|
472
|
476
|
events_group = new EventGroup;
|
473
|
477
|
scene->addItem(events_group);
|
474
|
478
|
|
|
@@ -484,8 +488,7 @@ void Editor::displayMapEvents() {
|
484
|
488
|
}
|
485
|
489
|
|
486
|
490
|
DraggablePixmapItem *Editor::addMapEvent(Event *event) {
|
487
|
|
- DraggablePixmapItem *object = new DraggablePixmapItem(event);
|
488
|
|
- object->editor = this;
|
|
491
|
+ DraggablePixmapItem *object = new DraggablePixmapItem(event, this);
|
489
|
492
|
events_group->addToGroup(object);
|
490
|
493
|
return object;
|
491
|
494
|
}
|
|
@@ -808,16 +811,22 @@ void Editor::updateDiveEmergeMap(QString mapName, QString direction) {
|
808
|
811
|
|
809
|
812
|
void Editor::updatePrimaryTileset(QString tilesetLabel)
|
810
|
813
|
{
|
811
|
|
- map->layout->tileset_primary_label = tilesetLabel;
|
812
|
|
- map->layout->tileset_primary = project->getTileset(tilesetLabel);
|
813
|
|
- emit tilesetChanged(map->name);
|
|
814
|
+ if (map->layout->tileset_primary_label != tilesetLabel)
|
|
815
|
+ {
|
|
816
|
+ map->layout->tileset_primary_label = tilesetLabel;
|
|
817
|
+ map->layout->tileset_primary = project->getTileset(tilesetLabel);
|
|
818
|
+ emit tilesetChanged(map->name);
|
|
819
|
+ }
|
814
|
820
|
}
|
815
|
821
|
|
816
|
822
|
void Editor::updateSecondaryTileset(QString tilesetLabel)
|
817
|
823
|
{
|
818
|
|
- map->layout->tileset_secondary_label = tilesetLabel;
|
819
|
|
- map->layout->tileset_secondary = project->getTileset(tilesetLabel);
|
820
|
|
- emit tilesetChanged(map->name);
|
|
824
|
+ if (map->layout->tileset_secondary_label != tilesetLabel)
|
|
825
|
+ {
|
|
826
|
+ map->layout->tileset_secondary_label = tilesetLabel;
|
|
827
|
+ map->layout->tileset_secondary = project->getTileset(tilesetLabel);
|
|
828
|
+ emit tilesetChanged(map->name);
|
|
829
|
+ }
|
821
|
830
|
}
|
822
|
831
|
|
823
|
832
|
void MetatilesPixmapItem::paintTileChanged(Map *map) {
|
|
@@ -1471,9 +1480,11 @@ void CollisionPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
|
1471
|
1480
|
|
1472
|
1481
|
void DraggablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *mouse) {
|
1473
|
1482
|
active = true;
|
1474
|
|
- clicking = true;
|
1475
|
1483
|
last_x = (mouse->pos().x() + this->pos().x()) / 16;
|
1476
|
1484
|
last_y = (mouse->pos().y() + this->pos().y()) / 16;
|
|
1485
|
+ this->editor->selectMapEvent(this, mouse->modifiers() & Qt::ControlModifier);
|
|
1486
|
+ this->editor->updateSelectedEvents();
|
|
1487
|
+ selectingEvent = true;
|
1477
|
1488
|
//qDebug() << QString("(%1, %2)").arg(event->get("x")).arg(event->get("y"));
|
1478
|
1489
|
}
|
1479
|
1490
|
|
|
@@ -1489,7 +1500,6 @@ void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
|
1489
|
1500
|
int x = (mouse->pos().x() + this->pos().x()) / 16;
|
1490
|
1501
|
int y = (mouse->pos().y() + this->pos().y()) / 16;
|
1491
|
1502
|
if (x != last_x || y != last_y) {
|
1492
|
|
- clicking = false;
|
1493
|
1503
|
if (editor->selected_events->contains(this)) {
|
1494
|
1504
|
for (DraggablePixmapItem *item : *editor->selected_events) {
|
1495
|
1505
|
item->move(x - last_x, y - last_y);
|
|
@@ -1532,7 +1542,7 @@ void Editor::redrawObject(DraggablePixmapItem *item) {
|
1532
|
1542
|
if (selected_events && selected_events->contains(item)) {
|
1533
|
1543
|
QImage image = item->pixmap().toImage();
|
1534
|
1544
|
QPainter painter(&image);
|
1535
|
|
- painter.setPen(QColor(250, 100, 25));
|
|
1545
|
+ painter.setPen(QColor(250, 0, 255));
|
1536
|
1546
|
painter.drawRect(0, 0, image.width() - 1, image.height() - 1);
|
1537
|
1547
|
painter.end();
|
1538
|
1548
|
item->setPixmap(QPixmap::fromImage(image));
|
|
@@ -1589,39 +1599,19 @@ void Editor::deleteEvent(Event *event) {
|
1589
|
1599
|
//updateSelectedObjects();
|
1590
|
1600
|
}
|
1591
|
1601
|
|
1592
|
|
-// dunno how to detect bubbling. QMouseEvent::isAccepted seems to always be true
|
1593
|
|
-// check if selected_events changed instead. this has the side effect of deselecting
|
1594
|
|
-// when you click on a selected event, since selected_events doesn't change.
|
1595
|
|
-
|
1596
|
|
-QList<DraggablePixmapItem *> selected_events_test;
|
1597
|
|
-bool clicking = false;
|
1598
|
|
-
|
|
1602
|
+// It doesn't seem to be possible to prevent the mousePress event
|
|
1603
|
+// from triggering both event's DraggablePixmapItem and the background mousePress.
|
|
1604
|
+// Since the DraggablePixmapItem's event fires first, we can set a temp
|
|
1605
|
+// variable "selectingEvent" so that we can detect whether or not the user
|
|
1606
|
+// is clicking on the background instead of an event.
|
1599
|
1607
|
void Editor::objectsView_onMousePress(QMouseEvent *event) {
|
1600
|
|
- clicking = true;
|
1601
|
|
- selected_events_test = *selected_events;
|
1602
|
|
-}
|
1603
|
|
-
|
1604
|
|
-void Editor::objectsView_onMouseMove(QMouseEvent *event) {
|
1605
|
|
- clicking = false;
|
1606
|
|
-}
|
1607
|
|
-
|
1608
|
|
-void Editor::objectsView_onMouseRelease(QMouseEvent *event) {
|
1609
|
|
- if (clicking) {
|
1610
|
|
- if (selected_events_test.length()) {
|
1611
|
|
- if (selected_events_test.length() == selected_events->length()) {
|
1612
|
|
- bool deselect = true;
|
1613
|
|
- for (int i = 0; i < selected_events_test.length(); i++) {
|
1614
|
|
- if (selected_events_test.at(i) != selected_events->at(i)) {
|
1615
|
|
- deselect = false;
|
1616
|
|
- break;
|
1617
|
|
- }
|
1618
|
|
- }
|
1619
|
|
- if (deselect) {
|
1620
|
|
- selected_events->clear();
|
1621
|
|
- updateSelectedEvents();
|
1622
|
|
- }
|
1623
|
|
- }
|
1624
|
|
- }
|
1625
|
|
- clicking = false;
|
|
1608
|
+ bool multiSelect = event->modifiers() & Qt::ControlModifier;
|
|
1609
|
+ if (!selectingEvent && !multiSelect && selected_events->length() > 1) {
|
|
1610
|
+ DraggablePixmapItem *first = selected_events->first();
|
|
1611
|
+ selected_events->clear();
|
|
1612
|
+ selected_events->append(first);
|
|
1613
|
+ updateSelectedEvents();
|
1626
|
1614
|
}
|
|
1615
|
+
|
|
1616
|
+ selectingEvent = false;
|
1627
|
1617
|
}
|