Ingen beskrivning

editor.cpp 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. #include "editor.h"
  2. #include <QPainter>
  3. #include <QMouseEvent>
  4. Editor::Editor()
  5. {
  6. selected_events = new QList<DraggablePixmapItem*>;
  7. }
  8. void Editor::saveProject() {
  9. if (project) {
  10. project->saveAllMaps();
  11. project->saveAllDataStructures();
  12. }
  13. }
  14. void Editor::save() {
  15. if (project && map) {
  16. project->saveMap(map);
  17. project->saveAllDataStructures();
  18. }
  19. }
  20. void Editor::undo() {
  21. if (current_view) {
  22. ((MapPixmapItem*)current_view)->undo();
  23. }
  24. }
  25. void Editor::redo() {
  26. if (current_view) {
  27. ((MapPixmapItem*)current_view)->redo();
  28. }
  29. }
  30. void Editor::setEditingMap() {
  31. current_view = map_item;
  32. if (map_item) {
  33. map_item->draw();
  34. map_item->setVisible(true);
  35. map_item->setEnabled(true);
  36. }
  37. if (collision_item) {
  38. collision_item->setVisible(false);
  39. }
  40. if (objects_group) {
  41. objects_group->setVisible(false);
  42. }
  43. }
  44. void Editor::setEditingCollision() {
  45. current_view = collision_item;
  46. if (collision_item) {
  47. collision_item->draw();
  48. collision_item->setVisible(true);
  49. }
  50. if (map_item) {
  51. map_item->setVisible(false);
  52. }
  53. if (objects_group) {
  54. objects_group->setVisible(false);
  55. }
  56. }
  57. void Editor::setEditingObjects() {
  58. current_view = map_item;
  59. if (objects_group) {
  60. objects_group->setVisible(true);
  61. }
  62. if (map_item) {
  63. map_item->setVisible(true);
  64. map_item->setEnabled(false);
  65. }
  66. if (collision_item) {
  67. collision_item->setVisible(false);
  68. }
  69. }
  70. void Editor::setMap(QString map_name) {
  71. if (map_name.isNull()) {
  72. return;
  73. }
  74. if (project) {
  75. map = project->loadMap(map_name);
  76. displayMap();
  77. selected_events->clear();
  78. updateSelectedObjects();
  79. }
  80. }
  81. void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item) {
  82. if (map_edit_mode == "paint") {
  83. item->paint(event);
  84. } else if (map_edit_mode == "fill") {
  85. item->floodFill(event);
  86. } else if (map_edit_mode == "pick") {
  87. item->pick(event);
  88. } else if (map_edit_mode == "select") {
  89. item->select(event);
  90. }
  91. }
  92. void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item) {
  93. if (map_edit_mode == "paint") {
  94. item->paint(event);
  95. } else if (map_edit_mode == "fill") {
  96. item->floodFill(event);
  97. } else if (map_edit_mode == "pick") {
  98. item->pick(event);
  99. } else if (map_edit_mode == "select") {
  100. item->select(event);
  101. }
  102. }
  103. void Editor::displayMap() {
  104. scene = new QGraphicsScene;
  105. map_item = new MapPixmapItem(map);
  106. connect(map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,MapPixmapItem*)),
  107. this, SLOT(mouseEvent_map(QGraphicsSceneMouseEvent*,MapPixmapItem*)));
  108. map_item->draw();
  109. scene->addItem(map_item);
  110. collision_item = new CollisionPixmapItem(map);
  111. connect(collision_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)),
  112. this, SLOT(mouseEvent_collision(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)));
  113. collision_item->draw();
  114. scene->addItem(collision_item);
  115. objects_group = new EventGroup;
  116. scene->addItem(objects_group);
  117. if (map_item) {
  118. map_item->setVisible(false);
  119. }
  120. if (collision_item) {
  121. collision_item->setVisible(false);
  122. }
  123. if (objects_group) {
  124. objects_group->setVisible(false);
  125. }
  126. int tw = 16;
  127. int th = 16;
  128. scene->setSceneRect(
  129. -6 * tw,
  130. -6 * th,
  131. map_item->pixmap().width() + 12 * tw,
  132. map_item->pixmap().height() + 12 * th
  133. );
  134. displayMetatiles();
  135. displayCollisionMetatiles();
  136. displayElevationMetatiles();
  137. displayMapObjects();
  138. displayMapConnections();
  139. displayMapBorder();
  140. }
  141. void Editor::displayMetatiles() {
  142. scene_metatiles = new QGraphicsScene;
  143. metatiles_item = new MetatilesPixmapItem(map);
  144. metatiles_item->draw();
  145. scene_metatiles->addItem(metatiles_item);
  146. }
  147. void Editor::displayCollisionMetatiles() {
  148. scene_collision_metatiles = new QGraphicsScene;
  149. collision_metatiles_item = new CollisionMetatilesPixmapItem(map);
  150. collision_metatiles_item->draw();
  151. scene_collision_metatiles->addItem(collision_metatiles_item);
  152. }
  153. void Editor::displayElevationMetatiles() {
  154. scene_elevation_metatiles = new QGraphicsScene;
  155. elevation_metatiles_item = new ElevationMetatilesPixmapItem(map);
  156. elevation_metatiles_item->draw();
  157. scene_elevation_metatiles->addItem(elevation_metatiles_item);
  158. }
  159. void Editor::displayMapObjects() {
  160. for (QGraphicsItem *child : objects_group->childItems()) {
  161. objects_group->removeFromGroup(child);
  162. }
  163. QList<Event *> events = map->getAllEvents();
  164. project->loadObjectPixmaps(events);
  165. for (Event *event : events) {
  166. addMapObject(event);
  167. }
  168. //objects_group->setFiltersChildEvents(false);
  169. objects_group->setHandlesChildEvents(false);
  170. emit objectsChanged();
  171. }
  172. DraggablePixmapItem *Editor::addMapObject(Event *event) {
  173. DraggablePixmapItem *object = new DraggablePixmapItem(event);
  174. object->editor = this;
  175. objects_group->addToGroup(object);
  176. return object;
  177. }
  178. void Editor::displayMapConnections() {
  179. for (Connection *connection : map->connections) {
  180. if (connection->direction == "dive" || connection->direction == "emerge") {
  181. continue;
  182. }
  183. Map *connected_map = project->getMap(connection->map_name);
  184. QPixmap pixmap = connected_map->renderConnection(*connection);
  185. int offset = connection->offset.toInt(nullptr, 0);
  186. int x = 0, y = 0;
  187. if (connection->direction == "up") {
  188. x = offset * 16;
  189. y = -pixmap.height();
  190. } else if (connection->direction == "down") {
  191. x = offset * 16;
  192. y = map->getHeight() * 16;
  193. } else if (connection->direction == "left") {
  194. x = -pixmap.width();
  195. y = offset * 16;
  196. } else if (connection->direction == "right") {
  197. x = map->getWidth() * 16;
  198. y = offset * 16;
  199. }
  200. QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
  201. item->setZValue(-1);
  202. item->setX(x);
  203. item->setY(y);
  204. scene->addItem(item);
  205. }
  206. }
  207. void Editor::displayMapBorder() {
  208. QPixmap pixmap = map->renderBorder();
  209. for (int y = -6; y < map->getHeight() + 6; y += 2)
  210. for (int x = -6; x < map->getWidth() + 6; x += 2) {
  211. QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
  212. item->setX(x * 16);
  213. item->setY(y * 16);
  214. item->setZValue(-2);
  215. scene->addItem(item);
  216. }
  217. }
  218. void MetatilesPixmapItem::paintTileChanged(Map *map) {
  219. draw();
  220. }
  221. void MetatilesPixmapItem::draw() {
  222. setPixmap(map->renderMetatiles());
  223. }
  224. void MetatilesPixmapItem::pick(uint tile) {
  225. map->paint_tile = tile;
  226. emit map->paintTileChanged(map);
  227. }
  228. void MetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
  229. int x = ((int)pos.x()) / 16;
  230. int y = ((int)pos.y()) / 16;
  231. int width = pixmap().width() / 16;
  232. int height = pixmap().height() / 16;
  233. if (x < 0 || x >= width || y < 0 || y >= height) {
  234. map->clearHoveredMetatile();
  235. } else {
  236. int block = y * width + x;
  237. map->hoveredMetatileChanged(block);
  238. }
  239. }
  240. void MetatilesPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
  241. updateCurHoveredMetatile(event->pos());
  242. }
  243. void MetatilesPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
  244. map->clearHoveredMetatile();
  245. }
  246. void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
  247. QPointF pos = event->pos();
  248. int x = ((int)pos.x()) / 16;
  249. int y = ((int)pos.y()) / 16;
  250. //qDebug() << QString("(%1, %2)").arg(x).arg(y);
  251. int width = pixmap().width() / 16;
  252. int height = pixmap().height() / 16;
  253. if ((x >= 0 && x < width) && (y >=0 && y < height)) {
  254. pick(y * width + x);
  255. }
  256. }
  257. void MetatilesPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
  258. updateCurHoveredMetatile(event->pos());
  259. mousePressEvent(event);
  260. }
  261. void MetatilesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
  262. mousePressEvent(event);
  263. }
  264. void CollisionMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
  265. int x = ((int)pos.x()) / 16;
  266. int y = ((int)pos.y()) / 16;
  267. int width = pixmap().width() / 16;
  268. int height = pixmap().height() / 16;
  269. if (x < 0 || x >= width || y < 0 || y >= height) {
  270. map->clearHoveredCollisionTile();
  271. } else {
  272. int collision = y * width + x;
  273. map->hoveredCollisionTileChanged(collision);
  274. }
  275. }
  276. void ElevationMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
  277. int x = ((int)pos.x()) / 16;
  278. int y = ((int)pos.y()) / 16;
  279. int width = pixmap().width() / 16;
  280. int height = pixmap().height() / 16;
  281. if (x < 0 || x >= width || y < 0 || y >= height) {
  282. map->clearHoveredElevationTile();
  283. } else {
  284. int elevation = y * width + x;
  285. map->hoveredElevationTileChanged(elevation);
  286. }
  287. }
  288. void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
  289. if (map) {
  290. QPointF pos = event->pos();
  291. int x = (int)(pos.x()) / 16;
  292. int y = (int)(pos.y()) / 16;
  293. Block *block = map->getBlock(x, y);
  294. if (block) {
  295. block->tile = map->paint_tile;
  296. map->_setBlock(x, y, *block);
  297. }
  298. if (event->type() == QEvent::GraphicsSceneMouseRelease) {
  299. map->commit();
  300. }
  301. draw();
  302. }
  303. }
  304. void MapPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
  305. if (map) {
  306. QPointF pos = event->pos();
  307. int x = (int)(pos.x()) / 16;
  308. int y = (int)(pos.y()) / 16;
  309. map->floodFill(x, y, map->paint_tile);
  310. draw();
  311. }
  312. }
  313. void MapPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
  314. QPointF pos = event->pos();
  315. int x = (int)(pos.x()) / 16;
  316. int y = (int)(pos.y()) / 16;
  317. Block *block = map->getBlock(x, y);
  318. if (block) {
  319. map->paint_tile = block->tile;
  320. emit map->paintTileChanged(map);
  321. }
  322. }
  323. #define SWAP(a, b) do { if (a != b) { a ^= b; b ^= a; a ^= b; } } while (0)
  324. void MapPixmapItem::select(QGraphicsSceneMouseEvent *event) {
  325. QPointF pos = event->pos();
  326. int x = (int)(pos.x()) / 16;
  327. int y = (int)(pos.y()) / 16;
  328. if (event->type() == QEvent::GraphicsSceneMousePress) {
  329. selection_origin = QPoint(x, y);
  330. selection.clear();
  331. } else if (event->type() == QEvent::GraphicsSceneMouseMove) {
  332. if (event->buttons() & Qt::LeftButton) {
  333. selection.clear();
  334. selection.append(QPoint(x, y));
  335. }
  336. } else if (event->type() == QEvent::GraphicsSceneMouseRelease) {
  337. if (!selection.isEmpty()) {
  338. QPoint pos = selection.last();
  339. int x1 = selection_origin.x();
  340. int y1 = selection_origin.y();
  341. int x2 = pos.x();
  342. int y2 = pos.y();
  343. if (x1 > x2) SWAP(x1, x2);
  344. if (y1 > y2) SWAP(y1, y2);
  345. selection.clear();
  346. for (int y = y1; y <= y2; y++) {
  347. for (int x = x1; x <= x2; x++) {
  348. selection.append(QPoint(x, y));
  349. }
  350. }
  351. qDebug() << QString("selected (%1, %2) -> (%3, %4)").arg(x1).arg(y1).arg(x2).arg(y2);
  352. }
  353. }
  354. }
  355. void MapPixmapItem::draw() {
  356. if (map) {
  357. setPixmap(map->render());
  358. }
  359. }
  360. void MapPixmapItem::undo() {
  361. if (map) {
  362. map->undo();
  363. draw();
  364. }
  365. }
  366. void MapPixmapItem::redo() {
  367. if (map) {
  368. map->redo();
  369. draw();
  370. }
  371. }
  372. void MapPixmapItem::updateCurHoveredTile(QPointF pos) {
  373. int x = ((int)pos.x()) / 16;
  374. int y = ((int)pos.y()) / 16;
  375. int blockIndex = y * map->getWidth() + x;
  376. if (x < 0 || x >= map->getWidth() || y < 0 || y >= map->getHeight()) {
  377. map->clearHoveredTile();
  378. } else {
  379. int tile = map->blockdata->blocks->at(blockIndex).tile;
  380. map->hoveredTileChanged(x, y, tile);
  381. }
  382. }
  383. void MapPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
  384. updateCurHoveredTile(event->pos());
  385. }
  386. void MapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
  387. map->clearHoveredTile();
  388. }
  389. void MapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
  390. emit mouseEvent(event, this);
  391. }
  392. void MapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
  393. updateCurHoveredTile(event->pos());
  394. emit mouseEvent(event, this);
  395. }
  396. void MapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
  397. emit mouseEvent(event, this);
  398. }
  399. void CollisionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
  400. emit mouseEvent(event, this);
  401. }
  402. void CollisionPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
  403. emit mouseEvent(event, this);
  404. }
  405. void CollisionPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
  406. emit mouseEvent(event, this);
  407. }
  408. void CollisionPixmapItem::draw() {
  409. if (map) {
  410. setPixmap(map->renderCollision());
  411. }
  412. }
  413. void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
  414. if (map) {
  415. QPointF pos = event->pos();
  416. int x = (int)(pos.x()) / 16;
  417. int y = (int)(pos.y()) / 16;
  418. Block *block = map->getBlock(x, y);
  419. if (block) {
  420. if (map->paint_collision >= 0) {
  421. block->collision = map->paint_collision;
  422. }
  423. if (map->paint_elevation >= 0) {
  424. block->elevation = map->paint_elevation;
  425. }
  426. map->_setBlock(x, y, *block);
  427. }
  428. if (event->type() == QEvent::GraphicsSceneMouseRelease) {
  429. map->commit();
  430. }
  431. draw();
  432. }
  433. }
  434. void CollisionPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
  435. if (map) {
  436. QPointF pos = event->pos();
  437. int x = (int)(pos.x()) / 16;
  438. int y = (int)(pos.y()) / 16;
  439. bool collision = map->paint_collision >= 0;
  440. bool elevation = map->paint_elevation >= 0;
  441. if (collision && elevation) {
  442. map->floodFillCollisionElevation(x, y, map->paint_collision, map->paint_elevation);
  443. } else if (collision) {
  444. map->floodFillCollision(x, y, map->paint_collision);
  445. } else if (elevation) {
  446. map->floodFillElevation(x, y, map->paint_elevation);
  447. }
  448. draw();
  449. }
  450. }
  451. void CollisionPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
  452. QPointF pos = event->pos();
  453. int x = (int)(pos.x()) / 16;
  454. int y = (int)(pos.y()) / 16;
  455. Block *block = map->getBlock(x, y);
  456. if (block) {
  457. map->paint_collision = block->collision;
  458. map->paint_elevation = block->elevation;
  459. emit map->paintCollisionChanged(map);
  460. }
  461. }
  462. void DraggablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *mouse) {
  463. active = true;
  464. clicking = true;
  465. last_x = (mouse->pos().x() + this->pos().x()) / 16;
  466. last_y = (mouse->pos().y() + this->pos().y()) / 16;
  467. //qDebug() << QString("(%1, %2)").arg(event->get("x")).arg(event->get("y"));
  468. }
  469. void DraggablePixmapItem::move(int x, int y) {
  470. event->setX(event->x() + x);
  471. event->setY(event->y() + y);
  472. updatePosition();
  473. emitPositionChanged();
  474. }
  475. void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
  476. if (active) {
  477. int x = (mouse->pos().x() + this->pos().x()) / 16;
  478. int y = (mouse->pos().y() + this->pos().y()) / 16;
  479. if (x != last_x || y != last_y) {
  480. clicking = false;
  481. if (editor->selected_events->contains(this)) {
  482. for (DraggablePixmapItem *item : *editor->selected_events) {
  483. item->move(x - last_x, y - last_y);
  484. }
  485. } else {
  486. move(x - last_x, y - last_y);
  487. }
  488. last_x = x;
  489. last_y = y;
  490. //qDebug() << QString("(%1, %2)").arg(event->get("x")).arg(event->get("x"));
  491. }
  492. }
  493. }
  494. void DraggablePixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouse) {
  495. if (clicking) {
  496. this->editor->selectMapObject(this, mouse->modifiers() & Qt::ControlModifier);
  497. this->editor->updateSelectedObjects();
  498. }
  499. active = false;
  500. }
  501. QList<DraggablePixmapItem *> *Editor::getObjects() {
  502. QList<DraggablePixmapItem *> *list = new QList<DraggablePixmapItem *>;
  503. for (Event *event : map->getAllEvents()) {
  504. for (QGraphicsItem *child : objects_group->childItems()) {
  505. DraggablePixmapItem *item = (DraggablePixmapItem *)child;
  506. if (item->event == event) {
  507. list->append(item);
  508. break;
  509. }
  510. }
  511. }
  512. return list;
  513. }
  514. void Editor::redrawObject(DraggablePixmapItem *item) {
  515. if (item) {
  516. item->setPixmap(item->event->pixmap);
  517. if (selected_events && selected_events->contains(item)) {
  518. QImage image = item->pixmap().toImage();
  519. QPainter painter(&image);
  520. painter.setPen(QColor(250, 100, 25));
  521. painter.drawRect(0, 0, image.width() - 1, image.height() - 1);
  522. painter.end();
  523. item->setPixmap(QPixmap::fromImage(image));
  524. }
  525. }
  526. }
  527. void Editor::updateSelectedObjects() {
  528. for (DraggablePixmapItem *item : *(getObjects())) {
  529. redrawObject(item);
  530. }
  531. emit selectedObjectsChanged();
  532. }
  533. void Editor::selectMapObject(DraggablePixmapItem *object) {
  534. selectMapObject(object, false);
  535. }
  536. void Editor::selectMapObject(DraggablePixmapItem *object, bool toggle) {
  537. if (selected_events && object) {
  538. if (selected_events->contains(object)) {
  539. if (toggle) {
  540. selected_events->removeOne(object);
  541. }
  542. } else {
  543. if (!toggle) {
  544. selected_events->clear();
  545. }
  546. selected_events->append(object);
  547. }
  548. updateSelectedObjects();
  549. }
  550. }
  551. DraggablePixmapItem* Editor::addNewEvent() {
  552. return addNewEvent("object");
  553. }
  554. DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
  555. if (project && map) {
  556. Event *event = new Event;
  557. event->put("map_name", map->name);
  558. event->put("event_type", event_type);
  559. map->addEvent(event);
  560. project->loadObjectPixmaps(map->getAllEvents());
  561. DraggablePixmapItem *object = addMapObject(event);
  562. return object;
  563. }
  564. return NULL;
  565. }
  566. void Editor::deleteEvent(Event *event) {
  567. Map *map = project->getMap(event->get("map_name"));
  568. if (map) {
  569. map->removeEvent(event);
  570. }
  571. //selected_events->removeAll(event);
  572. //updateSelectedObjects();
  573. }
  574. // dunno how to detect bubbling. QMouseEvent::isAccepted seems to always be true
  575. // check if selected_events changed instead. this has the side effect of deselecting
  576. // when you click on a selected event, since selected_events doesn't change.
  577. QList<DraggablePixmapItem *> selected_events_test;
  578. bool clicking = false;
  579. void Editor::objectsView_onMousePress(QMouseEvent *event) {
  580. clicking = true;
  581. selected_events_test = *selected_events;
  582. }
  583. void Editor::objectsView_onMouseMove(QMouseEvent *event) {
  584. clicking = false;
  585. }
  586. void Editor::objectsView_onMouseRelease(QMouseEvent *event) {
  587. if (clicking) {
  588. if (selected_events_test.length()) {
  589. if (selected_events_test.length() == selected_events->length()) {
  590. bool deselect = true;
  591. for (int i = 0; i < selected_events_test.length(); i++) {
  592. if (selected_events_test.at(i) != selected_events->at(i)) {
  593. deselect = false;
  594. break;
  595. }
  596. }
  597. if (deselect) {
  598. selected_events->clear();
  599. updateSelectedObjects();
  600. }
  601. }
  602. }
  603. clicking = false;
  604. }
  605. }