Brak opisu

editor.cpp 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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. displayMapGrid();
  141. }
  142. void Editor::displayMetatiles() {
  143. scene_metatiles = new QGraphicsScene;
  144. metatiles_item = new MetatilesPixmapItem(map);
  145. metatiles_item->draw();
  146. scene_metatiles->addItem(metatiles_item);
  147. }
  148. void Editor::displayCollisionMetatiles() {
  149. scene_collision_metatiles = new QGraphicsScene;
  150. collision_metatiles_item = new CollisionMetatilesPixmapItem(map);
  151. collision_metatiles_item->draw();
  152. scene_collision_metatiles->addItem(collision_metatiles_item);
  153. }
  154. void Editor::displayElevationMetatiles() {
  155. scene_elevation_metatiles = new QGraphicsScene;
  156. elevation_metatiles_item = new ElevationMetatilesPixmapItem(map);
  157. elevation_metatiles_item->draw();
  158. scene_elevation_metatiles->addItem(elevation_metatiles_item);
  159. }
  160. void Editor::displayMapObjects() {
  161. for (QGraphicsItem *child : objects_group->childItems()) {
  162. objects_group->removeFromGroup(child);
  163. }
  164. QList<Event *> events = map->getAllEvents();
  165. project->loadObjectPixmaps(events);
  166. for (Event *event : events) {
  167. addMapObject(event);
  168. }
  169. //objects_group->setFiltersChildEvents(false);
  170. objects_group->setHandlesChildEvents(false);
  171. emit objectsChanged();
  172. }
  173. DraggablePixmapItem *Editor::addMapObject(Event *event) {
  174. DraggablePixmapItem *object = new DraggablePixmapItem(event);
  175. object->editor = this;
  176. objects_group->addToGroup(object);
  177. return object;
  178. }
  179. void Editor::displayMapConnections() {
  180. for (Connection *connection : map->connections) {
  181. if (connection->direction == "dive" || connection->direction == "emerge") {
  182. continue;
  183. }
  184. Map *connected_map = project->getMap(connection->map_name);
  185. QPixmap pixmap = connected_map->renderConnection(*connection);
  186. int offset = connection->offset.toInt(nullptr, 0);
  187. int x = 0, y = 0;
  188. if (connection->direction == "up") {
  189. x = offset * 16;
  190. y = -pixmap.height();
  191. } else if (connection->direction == "down") {
  192. x = offset * 16;
  193. y = map->getHeight() * 16;
  194. } else if (connection->direction == "left") {
  195. x = -pixmap.width();
  196. y = offset * 16;
  197. } else if (connection->direction == "right") {
  198. x = map->getWidth() * 16;
  199. y = offset * 16;
  200. }
  201. QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
  202. item->setZValue(-1);
  203. item->setX(x);
  204. item->setY(y);
  205. scene->addItem(item);
  206. }
  207. }
  208. void Editor::displayMapBorder() {
  209. QPixmap pixmap = map->renderBorder();
  210. for (int y = -6; y < map->getHeight() + 6; y += 2)
  211. for (int x = -6; x < map->getWidth() + 6; x += 2) {
  212. QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
  213. item->setX(x * 16);
  214. item->setY(y * 16);
  215. item->setZValue(-2);
  216. scene->addItem(item);
  217. }
  218. }
  219. void Editor::displayMapGrid() {
  220. int pixelWidth = map->getWidth() * 16;
  221. int pixelHeight = map->getHeight() * 16;
  222. for (int i = 0; i <= map->getWidth(); i++) {
  223. int x = i * 16;
  224. QGraphicsLineItem *line = scene->addLine(x, 0, x, pixelHeight);
  225. }
  226. for (int j = 0; j <= map->getHeight(); j++) {
  227. int y = j * 16;
  228. QGraphicsLineItem *line = scene->addLine(0, y, pixelWidth, y);
  229. }
  230. }
  231. void MetatilesPixmapItem::paintTileChanged(Map *map) {
  232. draw();
  233. }
  234. void MetatilesPixmapItem::draw() {
  235. setPixmap(map->renderMetatiles());
  236. }
  237. void MetatilesPixmapItem::pick(uint tile) {
  238. map->paint_tile = tile;
  239. emit map->paintTileChanged(map);
  240. }
  241. void MetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
  242. int x = ((int)pos.x()) / 16;
  243. int y = ((int)pos.y()) / 16;
  244. int width = pixmap().width() / 16;
  245. int height = pixmap().height() / 16;
  246. if (x < 0 || x >= width || y < 0 || y >= height) {
  247. map->clearHoveredMetatile();
  248. } else {
  249. int block = y * width + x;
  250. map->hoveredMetatileChanged(block);
  251. }
  252. }
  253. void MetatilesPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
  254. updateCurHoveredMetatile(event->pos());
  255. }
  256. void MetatilesPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
  257. map->clearHoveredMetatile();
  258. }
  259. void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
  260. QPointF pos = event->pos();
  261. int x = ((int)pos.x()) / 16;
  262. int y = ((int)pos.y()) / 16;
  263. //qDebug() << QString("(%1, %2)").arg(x).arg(y);
  264. int width = pixmap().width() / 16;
  265. int height = pixmap().height() / 16;
  266. if ((x >= 0 && x < width) && (y >=0 && y < height)) {
  267. pick(y * width + x);
  268. }
  269. }
  270. void MetatilesPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
  271. updateCurHoveredMetatile(event->pos());
  272. mousePressEvent(event);
  273. }
  274. void MetatilesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
  275. mousePressEvent(event);
  276. }
  277. void CollisionMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
  278. int x = ((int)pos.x()) / 16;
  279. int y = ((int)pos.y()) / 16;
  280. int width = pixmap().width() / 16;
  281. int height = pixmap().height() / 16;
  282. if (x < 0 || x >= width || y < 0 || y >= height) {
  283. map->clearHoveredCollisionTile();
  284. } else {
  285. int collision = y * width + x;
  286. map->hoveredCollisionTileChanged(collision);
  287. }
  288. }
  289. void ElevationMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
  290. int x = ((int)pos.x()) / 16;
  291. int y = ((int)pos.y()) / 16;
  292. int width = pixmap().width() / 16;
  293. int height = pixmap().height() / 16;
  294. if (x < 0 || x >= width || y < 0 || y >= height) {
  295. map->clearHoveredElevationTile();
  296. } else {
  297. int elevation = y * width + x;
  298. map->hoveredElevationTileChanged(elevation);
  299. }
  300. }
  301. void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
  302. if (map) {
  303. QPointF pos = event->pos();
  304. int x = (int)(pos.x()) / 16;
  305. int y = (int)(pos.y()) / 16;
  306. Block *block = map->getBlock(x, y);
  307. if (block) {
  308. block->tile = map->paint_tile;
  309. map->_setBlock(x, y, *block);
  310. }
  311. if (event->type() == QEvent::GraphicsSceneMouseRelease) {
  312. map->commit();
  313. }
  314. draw();
  315. }
  316. }
  317. void MapPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
  318. if (map) {
  319. QPointF pos = event->pos();
  320. int x = (int)(pos.x()) / 16;
  321. int y = (int)(pos.y()) / 16;
  322. map->floodFill(x, y, map->paint_tile);
  323. draw();
  324. }
  325. }
  326. void MapPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
  327. QPointF pos = event->pos();
  328. int x = (int)(pos.x()) / 16;
  329. int y = (int)(pos.y()) / 16;
  330. Block *block = map->getBlock(x, y);
  331. if (block) {
  332. map->paint_tile = block->tile;
  333. emit map->paintTileChanged(map);
  334. }
  335. }
  336. #define SWAP(a, b) do { if (a != b) { a ^= b; b ^= a; a ^= b; } } while (0)
  337. void MapPixmapItem::select(QGraphicsSceneMouseEvent *event) {
  338. QPointF pos = event->pos();
  339. int x = (int)(pos.x()) / 16;
  340. int y = (int)(pos.y()) / 16;
  341. if (event->type() == QEvent::GraphicsSceneMousePress) {
  342. selection_origin = QPoint(x, y);
  343. selection.clear();
  344. } else if (event->type() == QEvent::GraphicsSceneMouseMove) {
  345. if (event->buttons() & Qt::LeftButton) {
  346. selection.clear();
  347. selection.append(QPoint(x, y));
  348. }
  349. } else if (event->type() == QEvent::GraphicsSceneMouseRelease) {
  350. if (!selection.isEmpty()) {
  351. QPoint pos = selection.last();
  352. int x1 = selection_origin.x();
  353. int y1 = selection_origin.y();
  354. int x2 = pos.x();
  355. int y2 = pos.y();
  356. if (x1 > x2) SWAP(x1, x2);
  357. if (y1 > y2) SWAP(y1, y2);
  358. selection.clear();
  359. for (int y = y1; y <= y2; y++) {
  360. for (int x = x1; x <= x2; x++) {
  361. selection.append(QPoint(x, y));
  362. }
  363. }
  364. qDebug() << QString("selected (%1, %2) -> (%3, %4)").arg(x1).arg(y1).arg(x2).arg(y2);
  365. }
  366. }
  367. }
  368. void MapPixmapItem::draw() {
  369. if (map) {
  370. setPixmap(map->render());
  371. }
  372. }
  373. void MapPixmapItem::undo() {
  374. if (map) {
  375. map->undo();
  376. draw();
  377. }
  378. }
  379. void MapPixmapItem::redo() {
  380. if (map) {
  381. map->redo();
  382. draw();
  383. }
  384. }
  385. void MapPixmapItem::updateCurHoveredTile(QPointF pos) {
  386. int x = ((int)pos.x()) / 16;
  387. int y = ((int)pos.y()) / 16;
  388. int blockIndex = y * map->getWidth() + x;
  389. if (x < 0 || x >= map->getWidth() || y < 0 || y >= map->getHeight()) {
  390. map->clearHoveredTile();
  391. } else {
  392. int tile = map->blockdata->blocks->at(blockIndex).tile;
  393. map->hoveredTileChanged(x, y, tile);
  394. }
  395. }
  396. void MapPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
  397. updateCurHoveredTile(event->pos());
  398. }
  399. void MapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
  400. map->clearHoveredTile();
  401. }
  402. void MapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
  403. emit mouseEvent(event, this);
  404. }
  405. void MapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
  406. updateCurHoveredTile(event->pos());
  407. emit mouseEvent(event, this);
  408. }
  409. void MapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
  410. emit mouseEvent(event, this);
  411. }
  412. void CollisionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
  413. emit mouseEvent(event, this);
  414. }
  415. void CollisionPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
  416. emit mouseEvent(event, this);
  417. }
  418. void CollisionPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
  419. emit mouseEvent(event, this);
  420. }
  421. void CollisionPixmapItem::draw() {
  422. if (map) {
  423. setPixmap(map->renderCollision());
  424. }
  425. }
  426. void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
  427. if (map) {
  428. QPointF pos = event->pos();
  429. int x = (int)(pos.x()) / 16;
  430. int y = (int)(pos.y()) / 16;
  431. Block *block = map->getBlock(x, y);
  432. if (block) {
  433. if (map->paint_collision >= 0) {
  434. block->collision = map->paint_collision;
  435. }
  436. if (map->paint_elevation >= 0) {
  437. block->elevation = map->paint_elevation;
  438. }
  439. map->_setBlock(x, y, *block);
  440. }
  441. if (event->type() == QEvent::GraphicsSceneMouseRelease) {
  442. map->commit();
  443. }
  444. draw();
  445. }
  446. }
  447. void CollisionPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
  448. if (map) {
  449. QPointF pos = event->pos();
  450. int x = (int)(pos.x()) / 16;
  451. int y = (int)(pos.y()) / 16;
  452. bool collision = map->paint_collision >= 0;
  453. bool elevation = map->paint_elevation >= 0;
  454. if (collision && elevation) {
  455. map->floodFillCollisionElevation(x, y, map->paint_collision, map->paint_elevation);
  456. } else if (collision) {
  457. map->floodFillCollision(x, y, map->paint_collision);
  458. } else if (elevation) {
  459. map->floodFillElevation(x, y, map->paint_elevation);
  460. }
  461. draw();
  462. }
  463. }
  464. void CollisionPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
  465. QPointF pos = event->pos();
  466. int x = (int)(pos.x()) / 16;
  467. int y = (int)(pos.y()) / 16;
  468. Block *block = map->getBlock(x, y);
  469. if (block) {
  470. map->paint_collision = block->collision;
  471. map->paint_elevation = block->elevation;
  472. emit map->paintCollisionChanged(map);
  473. }
  474. }
  475. void DraggablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *mouse) {
  476. active = true;
  477. clicking = true;
  478. last_x = (mouse->pos().x() + this->pos().x()) / 16;
  479. last_y = (mouse->pos().y() + this->pos().y()) / 16;
  480. //qDebug() << QString("(%1, %2)").arg(event->get("x")).arg(event->get("y"));
  481. }
  482. void DraggablePixmapItem::move(int x, int y) {
  483. event->setX(event->x() + x);
  484. event->setY(event->y() + y);
  485. updatePosition();
  486. emitPositionChanged();
  487. }
  488. void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
  489. if (active) {
  490. int x = (mouse->pos().x() + this->pos().x()) / 16;
  491. int y = (mouse->pos().y() + this->pos().y()) / 16;
  492. if (x != last_x || y != last_y) {
  493. clicking = false;
  494. if (editor->selected_events->contains(this)) {
  495. for (DraggablePixmapItem *item : *editor->selected_events) {
  496. item->move(x - last_x, y - last_y);
  497. }
  498. } else {
  499. move(x - last_x, y - last_y);
  500. }
  501. last_x = x;
  502. last_y = y;
  503. //qDebug() << QString("(%1, %2)").arg(event->get("x")).arg(event->get("x"));
  504. }
  505. }
  506. }
  507. void DraggablePixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouse) {
  508. if (clicking) {
  509. this->editor->selectMapObject(this, mouse->modifiers() & Qt::ControlModifier);
  510. this->editor->updateSelectedObjects();
  511. }
  512. active = false;
  513. }
  514. QList<DraggablePixmapItem *> *Editor::getObjects() {
  515. QList<DraggablePixmapItem *> *list = new QList<DraggablePixmapItem *>;
  516. for (Event *event : map->getAllEvents()) {
  517. for (QGraphicsItem *child : objects_group->childItems()) {
  518. DraggablePixmapItem *item = (DraggablePixmapItem *)child;
  519. if (item->event == event) {
  520. list->append(item);
  521. break;
  522. }
  523. }
  524. }
  525. return list;
  526. }
  527. void Editor::redrawObject(DraggablePixmapItem *item) {
  528. if (item) {
  529. item->setPixmap(item->event->pixmap);
  530. if (selected_events && selected_events->contains(item)) {
  531. QImage image = item->pixmap().toImage();
  532. QPainter painter(&image);
  533. painter.setPen(QColor(250, 100, 25));
  534. painter.drawRect(0, 0, image.width() - 1, image.height() - 1);
  535. painter.end();
  536. item->setPixmap(QPixmap::fromImage(image));
  537. }
  538. }
  539. }
  540. void Editor::updateSelectedObjects() {
  541. for (DraggablePixmapItem *item : *(getObjects())) {
  542. redrawObject(item);
  543. }
  544. emit selectedObjectsChanged();
  545. }
  546. void Editor::selectMapObject(DraggablePixmapItem *object) {
  547. selectMapObject(object, false);
  548. }
  549. void Editor::selectMapObject(DraggablePixmapItem *object, bool toggle) {
  550. if (selected_events && object) {
  551. if (selected_events->contains(object)) {
  552. if (toggle) {
  553. selected_events->removeOne(object);
  554. }
  555. } else {
  556. if (!toggle) {
  557. selected_events->clear();
  558. }
  559. selected_events->append(object);
  560. }
  561. updateSelectedObjects();
  562. }
  563. }
  564. DraggablePixmapItem* Editor::addNewEvent() {
  565. return addNewEvent("object");
  566. }
  567. DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
  568. if (project && map) {
  569. Event *event = new Event;
  570. event->put("map_name", map->name);
  571. event->put("event_type", event_type);
  572. map->addEvent(event);
  573. project->loadObjectPixmaps(map->getAllEvents());
  574. DraggablePixmapItem *object = addMapObject(event);
  575. return object;
  576. }
  577. return NULL;
  578. }
  579. void Editor::deleteEvent(Event *event) {
  580. Map *map = project->getMap(event->get("map_name"));
  581. if (map) {
  582. map->removeEvent(event);
  583. }
  584. //selected_events->removeAll(event);
  585. //updateSelectedObjects();
  586. }
  587. // dunno how to detect bubbling. QMouseEvent::isAccepted seems to always be true
  588. // check if selected_events changed instead. this has the side effect of deselecting
  589. // when you click on a selected event, since selected_events doesn't change.
  590. QList<DraggablePixmapItem *> selected_events_test;
  591. bool clicking = false;
  592. void Editor::objectsView_onMousePress(QMouseEvent *event) {
  593. clicking = true;
  594. selected_events_test = *selected_events;
  595. }
  596. void Editor::objectsView_onMouseMove(QMouseEvent *event) {
  597. clicking = false;
  598. }
  599. void Editor::objectsView_onMouseRelease(QMouseEvent *event) {
  600. if (clicking) {
  601. if (selected_events_test.length()) {
  602. if (selected_events_test.length() == selected_events->length()) {
  603. bool deselect = true;
  604. for (int i = 0; i < selected_events_test.length(); i++) {
  605. if (selected_events_test.at(i) != selected_events->at(i)) {
  606. deselect = false;
  607. break;
  608. }
  609. }
  610. if (deselect) {
  611. selected_events->clear();
  612. updateSelectedObjects();
  613. }
  614. }
  615. }
  616. clicking = false;
  617. }
  618. }