ImageHolder.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  1. /*
  2. * ImageHolder.cpp
  3. *
  4. * Created on: Oct 5, 2011
  5. * Author: gapchich
  6. */
  7. #include "ImageHolder.h"
  8. #include "functions.h"
  9. #include <QKeyEvent>
  10. #include <QMouseEvent>
  11. #include <QPainter>
  12. #include <QListWidgetItem>
  13. #include <qmath.h>
  14. #include <QDebug>
  15. ImageHolder::ImageHolder(QWidget *aParent)
  16. : QLabel(aParent)
  17. {
  18. repaint_needed_ = 0;
  19. tool_ = NoTool;
  20. state_ = StandBy;
  21. keyboard_modifier_ = Qt::NoModifier;
  22. focused_selection_ = -1;
  23. focused_selection_type_ = NoFigure;
  24. hovered_point_.figure = NoFigure;
  25. hovered_point_.figureID = -1;
  26. hovered_point_.pointID = -1;
  27. list_bounding_box_ = 0;
  28. main_label_ = 0;
  29. //list_bounding_box_ = new QList< QRect >;
  30. scale_ = 1;
  31. point_radius_ = 6;
  32. setScaledContents(true);
  33. setMouseTracking(true);
  34. }
  35. ImageHolder::~ImageHolder()
  36. {
  37. //list_bounding_box_->clear();
  38. //delete list_bounding_box_;
  39. }
  40. void
  41. ImageHolder::paintEvent(QPaintEvent *anEvent)
  42. {
  43. QLabel::paintEvent(anEvent);
  44. QPainter painter(this);
  45. painter.setRenderHint(QPainter::Antialiasing);
  46. //painter.setRenderHint(QPainter::SmoothPixmapTransform);
  47. QPen pen;
  48. if (NoTool != tool_) {
  49. pen.setWidth(1);
  50. pen.setColor(QColor(Qt::black));
  51. pen.setStyle(Qt::DashLine);
  52. painter.setPen(pen);
  53. if (BoundingBoxTool == tool_) {
  54. /* scaling */
  55. QRect bbox = bounding_box_.rect;
  56. QPoint bboxTopLeft = bbox.topLeft() * scale_;
  57. QPoint bboxBottomRight = bbox.bottomRight() * scale_;
  58. bbox.setTopLeft(bboxTopLeft);
  59. bbox.setBottomRight(bboxBottomRight);
  60. painter.drawRect(bbox);
  61. }
  62. else if (PolygonTool == tool_) {
  63. /* scaling */
  64. QPoint point;
  65. QPolygon poly = polygon_.poly;
  66. for (int i = 0; i < poly.size(); i++) {
  67. point.setX(poly.at(i).x());
  68. point.setY(poly.at(i).y());
  69. point *= scale_;
  70. poly.remove(i);
  71. poly.insert(i, point);
  72. }
  73. painter.drawPolygon(poly);
  74. }
  75. // switch(tool_) {
  76. // case BoundingBoxTool:
  77. // painter.drawRect();
  78. // break;
  79. // case PolygonTool:
  80. // painter.drawPolygon(polygon_.poly);
  81. // break;
  82. // default:
  83. // break;
  84. // }
  85. }
  86. /* drawing bounding boxes */
  87. drawBoundingBoxes(&painter, &pen);
  88. drawPolygons(&painter, &pen);
  89. }
  90. void
  91. ImageHolder::drawBoundingBoxes(
  92. QPainter *aPainter,
  93. QPen *aPen
  94. )
  95. {
  96. /* FIXME: hardcoded colors */
  97. if (0 == list_bounding_box_)
  98. {
  99. return;
  100. /* NOTREACHED */
  101. }
  102. Qt::PenStyle penStyle = Qt::SolidLine;
  103. int width = 1;
  104. /* confirmed boxes */
  105. for (int i = 0; i < list_bounding_box_->size(); i++) {
  106. int labelID = list_bounding_box_->at(i)->label_ID_;
  107. if (labelID < list_label_color_->count())
  108. aPen->setColor(QColor(list_label_color_->at(labelID)));
  109. else
  110. aPen->setColor(QColor(Qt::white));
  111. /* checking whether labeled area is of main object or not */
  112. if (labelID == *main_label_)
  113. width = 3;
  114. else
  115. width = 1;
  116. if (RectFigure == focused_selection_type_ &&
  117. focused_selection_ == i) {
  118. penStyle = Qt::DotLine;
  119. width = 2;
  120. }
  121. /* scaling */
  122. QRect rect = list_bounding_box_->at(i)->rect.normalized();
  123. QPoint topLeft = rect.topLeft() * scale_;
  124. QPoint bottomRight = rect.bottomRight() * scale_;
  125. rect.setTopLeft(topLeft);
  126. rect.setBottomRight(bottomRight);
  127. if (focused_selection_ == i &&
  128. focused_selection_type_ == RectFigure) {
  129. QPen circPen;
  130. circPen.setWidth(2);
  131. circPen.setStyle(Qt::SolidLine);
  132. circPen.setColor(aPen->color());
  133. aPainter->setPen(circPen);
  134. for (int j = 0; j < 4; j++) {
  135. QPoint point;
  136. if (!j) {
  137. point = rect.topLeft();
  138. }
  139. else if (1 == j)
  140. {
  141. point = rect.topRight();
  142. }
  143. else if (2 == j)
  144. {
  145. point = rect.bottomRight();
  146. }
  147. else if (3 == j)
  148. {
  149. point = rect.bottomLeft();
  150. }
  151. if (i == hovered_point_.figureID &&
  152. j == hovered_point_.pointID &&
  153. RectFigure == hovered_point_.figure) {
  154. QBrush brush;
  155. brush.setColor(aPen->color());
  156. brush.setStyle(Qt::SolidPattern);
  157. aPainter->setBrush(brush);
  158. }
  159. aPainter->drawEllipse(point, point_radius_, point_radius_);
  160. aPainter->setBrush(Qt::NoBrush);
  161. }
  162. }
  163. aPen->setWidth(width);
  164. aPen->setStyle(penStyle);
  165. aPainter->setPen(*aPen);
  166. aPainter->drawRect(rect);
  167. /* drawing label ids of these boxes */
  168. QString labelIDText =
  169. QString("%1").arg(labelID);
  170. aPainter->drawText(
  171. rect.left() + 5,
  172. rect.top() + 5,
  173. 20,
  174. 20,
  175. Qt::AlignLeft,
  176. labelIDText
  177. );
  178. }
  179. }
  180. void
  181. ImageHolder::drawPolygons(
  182. QPainter *aPainter,
  183. QPen *aPen
  184. )
  185. {
  186. /* FIXME: hardcoded colors */
  187. if (0 == list_polygon_)
  188. {
  189. return;
  190. /* NOTREACHED */
  191. }
  192. Qt::PenStyle penStyle = Qt::SolidLine;
  193. int width = 1;
  194. /* confirmed polygons */
  195. for (int i = 0; i < list_polygon_->size(); i++) {
  196. penStyle = Qt::SolidLine;
  197. int labelID = list_polygon_->at(i)->label_ID_;
  198. if (labelID < list_label_color_->count())
  199. aPen->setColor(QColor(list_label_color_->at(labelID)));
  200. else
  201. aPen->setColor(QColor(Qt::white));
  202. /* checking whether labeled area is of main object or not */
  203. if (labelID == *main_label_)
  204. width = 3;
  205. else
  206. width = 1;
  207. if (PolyFigure == focused_selection_type_ &&
  208. focused_selection_ == i) {
  209. penStyle = Qt::DotLine;
  210. width = 2;
  211. }
  212. QPoint point;
  213. QPolygon poly = list_polygon_->at(i)->poly;
  214. for (int j = 0; j < poly.size(); j++) {
  215. point.setX(poly.at(j).x());
  216. point.setY(poly.at(j).y());
  217. point *= scale_;
  218. poly.remove(j);
  219. poly.insert(j, point);
  220. if (focused_selection_ == i &&
  221. focused_selection_type_ == PolyFigure) {
  222. QPen circPen;
  223. circPen.setWidth(2);
  224. circPen.setStyle(Qt::SolidLine);
  225. circPen.setColor(aPen->color());
  226. aPainter->setPen(circPen);
  227. if (j == hovered_point_.pointID &&
  228. i == hovered_point_.figureID &&
  229. PolyFigure == hovered_point_.figure) {
  230. QBrush brush;
  231. brush.setColor(aPen->color());
  232. brush.setStyle(Qt::SolidPattern);
  233. aPainter->setBrush(brush);
  234. }
  235. aPainter->drawEllipse(point, point_radius_, point_radius_);
  236. aPainter->setBrush(Qt::NoBrush);
  237. }
  238. }
  239. aPen->setWidth(width);
  240. aPen->setStyle(penStyle);
  241. aPainter->setPen(*aPen);
  242. aPainter->drawPolygon(poly);
  243. /* drawing label ids of these polys */
  244. QString labelIDText =
  245. QString("%1").arg(labelID);
  246. QRect rect = poly.boundingRect();
  247. int x = rect.center().x();
  248. int y = rect.center().y();
  249. aPainter->drawText(
  250. x,
  251. y,
  252. 20,
  253. 20,
  254. Qt::AlignHCenter,
  255. labelIDText
  256. );
  257. }
  258. }
  259. void
  260. ImageHolder::triggerBoundBox(
  261. const QPoint &aNewPos,
  262. const QPoint &anOldPos,
  263. QRect *aNewRect
  264. )
  265. {
  266. aNewRect->setCoords(
  267. anOldPos.x(),
  268. anOldPos.y(),
  269. aNewPos.x(),
  270. aNewPos.y()
  271. );
  272. state_ = NewSelection;
  273. repaint_needed_ = 1;
  274. }
  275. void
  276. ImageHolder::triggerPolygon(
  277. const QPoint &aPoint,
  278. QPolygon *aNewPoly
  279. )
  280. {
  281. *aNewPoly << aPoint;
  282. repaint_needed_ = 1;
  283. }
  284. void
  285. ImageHolder::focusOnArea(QListWidgetItem *anItem)
  286. {
  287. QString text = anItem->text();
  288. Tool tool = NoTool;
  289. if (-1 != text.indexOf("BBox"))
  290. tool = BoundingBoxTool;
  291. else if (-1 != text.indexOf("Poly"))
  292. tool = PolygonTool;
  293. /* looking for a number of selected area */
  294. if (NoTool != tool) {
  295. bool ok = 0;
  296. focused_selection_ = getNumFromString(&text, "#", ";", &ok);
  297. if (!ok) {
  298. focused_selection_ = -1;
  299. focused_selection_type_ = NoFigure;
  300. return;
  301. /* NOTREACHED */
  302. }
  303. switch (tool) {
  304. case BoundingBoxTool:
  305. focused_selection_type_ = RectFigure;
  306. break;
  307. case PolygonTool:
  308. focused_selection_type_ = PolyFigure;
  309. break;
  310. default:
  311. focused_selection_type_ = NoFigure;
  312. break;
  313. }
  314. }
  315. update();
  316. }
  317. void
  318. ImageHolder::scaleImage(
  319. ZoomDirection aDirection,
  320. double scaleFactor
  321. )
  322. {
  323. //QSize size = pixmap()->size();
  324. QSize size = this->size();
  325. /* zoomin */
  326. if (ZoomIn == aDirection) {
  327. size *= scaleFactor;
  328. scale_ *= scaleFactor;
  329. }
  330. /* zoomout */
  331. else if (ZoomOut == aDirection) {
  332. size /= scaleFactor;
  333. scale_ /= scaleFactor;
  334. }
  335. // setScaledContents(true);
  336. this->resize(size);
  337. // setPixmap(
  338. // image_->scaled(
  339. // size,
  340. // Qt::IgnoreAspectRatio,
  341. // Qt::SmoothTransformation
  342. // )
  343. // );
  344. // setScaledContents(false);
  345. //resize(scaleFactor * pixmap()->size());
  346. //emit imageScaled();
  347. }
  348. void
  349. ImageHolder::clearFocusOnArea()
  350. {
  351. focused_selection_ = -1;
  352. focused_selection_type_ = NoFigure;
  353. update();
  354. }
  355. void
  356. ImageHolder::setTool(Tool aTool)
  357. {
  358. switch(aTool) {
  359. case BoundingBoxTool:
  360. tool_ = BoundingBoxTool;
  361. break;
  362. case PolygonTool:
  363. tool_ = PolygonTool;
  364. break;
  365. case TaggingTool:
  366. tool_ = TaggingTool;
  367. break;
  368. default:
  369. tool_ = NoTool;
  370. break;
  371. }
  372. }
  373. void
  374. ImageHolder::setBoundingBoxList(QList< BoundingBox * > *aBBoxList)
  375. {
  376. if (0 == aBBoxList) {
  377. return;
  378. /* NOTREACHED */
  379. }
  380. list_bounding_box_ = aBBoxList;
  381. }
  382. void
  383. ImageHolder::setPolygonList(QList< Polygon * > *aPolygonList)
  384. {
  385. if (0 == aPolygonList) {
  386. return;
  387. /* NOTREACHED */
  388. }
  389. list_polygon_ = aPolygonList;
  390. }
  391. void
  392. ImageHolder::setLabelColorList(QList< uint > *aLabelColorList)
  393. {
  394. if (0 == aLabelColorList) {
  395. return;
  396. /* NOTREACHED */
  397. }
  398. list_label_color_ = aLabelColorList;
  399. }
  400. void
  401. ImageHolder::setMainLabelNum(int *aNum)
  402. {
  403. if (0 == aNum) {
  404. return;
  405. /* NOTREACHED */
  406. }
  407. main_label_ = aNum;
  408. }
  409. void
  410. ImageHolder::setImage(QPixmap *anImage)
  411. {
  412. if (0 == anImage) {
  413. return;
  414. /* NOTREACHED */
  415. }
  416. image_ = anImage;
  417. }
  418. void
  419. ImageHolder::clearAll()
  420. {
  421. //list_bounding_box_->clear();
  422. bounding_box_.rect.setRect(-1, -1, 0, 0);
  423. //list_polygon_->clear();
  424. polygon_.poly.clear();
  425. clearFocusOnArea();
  426. state_ = StandBy;
  427. update();
  428. }
  429. void
  430. ImageHolder::clearLast()
  431. {
  432. switch (tool_) {
  433. case BoundingBoxTool:
  434. bounding_box_.rect.setRect(-1, -1, 0, 0);
  435. break;
  436. case PolygonTool:
  437. polygon_.poly.clear();
  438. break;
  439. case TaggingTool:
  440. break;
  441. default:
  442. break;
  443. }
  444. bounding_box_.rect.setRect(-1, -1, 0, 0);
  445. state_ = StandBy;
  446. update();
  447. }
  448. void
  449. ImageHolder::confirmSelection()
  450. {
  451. if (NewSelection != state_ || NoTool == tool_) {
  452. return;
  453. /* NOTREACHED */
  454. }
  455. if (BoundingBoxTool == tool_) {
  456. BoundingBox *bbox = new BoundingBox;
  457. *bbox = bounding_box_;
  458. list_bounding_box_->append(bbox);
  459. bounding_box_.rect.setRect(-1, -1, 0, 0);
  460. }
  461. else if (PolygonTool == tool_) {
  462. Polygon *poly = new Polygon;
  463. *poly = polygon_;
  464. list_polygon_->append(poly);
  465. polygon_.poly.clear();
  466. }
  467. list_poly_history_.clear();
  468. state_ = StandBy;
  469. update();
  470. }
  471. ImageHolder::State
  472. ImageHolder::state()
  473. {
  474. return state_;
  475. }
  476. ImageHolder::Tool
  477. ImageHolder::tool()
  478. {
  479. return tool_;
  480. }
  481. int
  482. ImageHolder::focusedSelection()
  483. {
  484. return focused_selection_;
  485. }
  486. Figure
  487. ImageHolder::focusedSelectionType()
  488. {
  489. return focused_selection_type_;
  490. }
  491. void
  492. ImageHolder::undo()
  493. {
  494. if (PolygonTool == tool_ &&
  495. NewSelection == state_ &&
  496. !polygon_.poly.isEmpty())
  497. {
  498. list_poly_history_.append(polygon_.poly.last());
  499. polygon_.poly.pop_back();
  500. repaint_needed_ = 1;
  501. }
  502. if (repaint_needed_) {
  503. update();
  504. repaint_needed_ = 0;
  505. }
  506. }
  507. void
  508. ImageHolder::redo()
  509. {
  510. if (PolygonTool == tool_ &&
  511. NewSelection == state_ &&
  512. !list_poly_history_.isEmpty())
  513. {
  514. polygon_.poly.append(list_poly_history_.last());
  515. list_poly_history_.pop_back();
  516. repaint_needed_ = 1;
  517. }
  518. if (repaint_needed_) {
  519. update();
  520. repaint_needed_ = 0;
  521. }
  522. }
  523. void
  524. ImageHolder::checkForPoints(QPoint *aPos)
  525. {
  526. if ((!list_polygon_->count() &&
  527. !list_bounding_box_->count()) ||
  528. !aPos) {
  529. return;
  530. /* NOTREACHED */
  531. }
  532. int newRadius = 0;
  533. int x = aPos->x();
  534. int y = aPos->y();
  535. /* center coordinates */
  536. int xc = 0;
  537. int yc = 0;
  538. for (int i = 0; i < list_polygon_->count(); i++) {
  539. QPolygon poly = list_polygon_->at(i)->poly;
  540. for (int j = 0; j < poly.count(); j++) {
  541. xc = poly.at(j).x();
  542. yc = poly.at(j).y();
  543. newRadius = qSqrt(qPow(x - xc, 2) + qPow(y - yc, 2));
  544. if (newRadius <= point_radius_) {
  545. hovered_point_.figure = PolyFigure;
  546. hovered_point_.figureID = i;
  547. hovered_point_.pointID = j;
  548. repaint_needed_ = 1;
  549. return;
  550. /* NOTREACHED */
  551. }
  552. }
  553. }
  554. for (int i = 0; i < list_bounding_box_->count(); i++) {
  555. QRect rect = list_bounding_box_->at(i)->rect;
  556. for (int j = 0; j < 4; j++) {
  557. if (!j) {
  558. xc = rect.left();
  559. yc = rect.top();
  560. }
  561. else if (1 == j)
  562. {
  563. xc = rect.right();
  564. yc = rect.top();
  565. }
  566. else if (2 == j)
  567. {
  568. xc = rect.right();
  569. yc = rect.bottom();
  570. }
  571. else if (3 == j)
  572. {
  573. xc = rect.left();
  574. yc = rect.bottom();
  575. }
  576. newRadius = qSqrt(qPow(x - xc, 2) + qPow(y - yc, 2));
  577. if (newRadius <= point_radius_) {
  578. hovered_point_.figure = RectFigure;
  579. hovered_point_.figureID = i;
  580. hovered_point_.pointID = j;
  581. repaint_needed_ = 1;
  582. return;
  583. /* NOTREACHED */
  584. }
  585. }
  586. }
  587. hovered_point_.figure = NoFigure;
  588. hovered_point_.figureID = -1;
  589. hovered_point_.pointID = -1;
  590. repaint_needed_ = 1;
  591. }
  592. void
  593. ImageHolder::keyPressEvent(QKeyEvent *anEvent)
  594. {
  595. QLabel::keyPressEvent(anEvent);
  596. //keyboard_modifier_ = anEvent->modifiers();
  597. if (repaint_needed_) {
  598. update();
  599. repaint_needed_ = 0;
  600. }
  601. }
  602. void
  603. ImageHolder::mouseMoveEvent(QMouseEvent *anEvent)
  604. {
  605. QPoint pos = anEvent->pos() / scale_;
  606. if (anEvent->pos().x() < 0)
  607. pos.setX(0);
  608. if (width() < anEvent->pos().x())
  609. pos.setX(width() - 1);
  610. if (anEvent->pos().y() < 0)
  611. pos.setY(0);
  612. if (height() < anEvent->pos().y())
  613. pos.setY(height() - 1);
  614. if ((anEvent->buttons() & Qt::LeftButton) &&
  615. BoundingBoxTool == tool_ &&
  616. NewSelection == state_ &&
  617. Qt::NoModifier == keyboard_modifier_)
  618. {
  619. triggerBoundBox(pos, prev_cursor_pos_, &(bounding_box_.rect));
  620. }
  621. if (PolygonTool == tool_ &&
  622. NewSelection == state_ &&
  623. (anEvent->buttons() & Qt::LeftButton))
  624. {
  625. polygon_.poly.setPoint(polygon_.poly.count() - 1, pos);
  626. //triggerPolygon(pos, &(polygon_.poly));
  627. repaint_needed_ = 1;
  628. }
  629. if (-1 != focused_selection_ &&
  630. !(anEvent->buttons() & Qt::LeftButton)) {
  631. checkForPoints(&pos);
  632. }
  633. /* editing polygons */
  634. if (-1 != hovered_point_.figureID &&
  635. !list_polygon_->isEmpty() &&
  636. PolyFigure == hovered_point_.figure &&
  637. (anEvent->buttons() & Qt::LeftButton))
  638. {
  639. Polygon *poly = list_polygon_->at(hovered_point_.figureID);
  640. poly->poly.setPoint(hovered_point_.pointID, pos);
  641. repaint_needed_ = 1;
  642. }
  643. /* editing bounding boxes */
  644. if (-1 != hovered_point_.figureID &&
  645. !list_bounding_box_->isEmpty() &&
  646. RectFigure == hovered_point_.figure &&
  647. (anEvent->buttons() & Qt::LeftButton))
  648. {
  649. BoundingBox *rect = list_bounding_box_->at(hovered_point_.figureID);
  650. if (0 == hovered_point_.pointID)
  651. rect->rect.setTopLeft(pos);
  652. else if (1 == hovered_point_.pointID)
  653. rect->rect.setTopRight(pos);
  654. else if (2 == hovered_point_.pointID)
  655. rect->rect.setBottomRight(pos);
  656. else if (3 == hovered_point_.pointID)
  657. rect->rect.setBottomLeft(pos);
  658. repaint_needed_ = 1;
  659. }
  660. if (repaint_needed_) {
  661. update();
  662. repaint_needed_ = 0;
  663. }
  664. }
  665. void
  666. ImageHolder::mousePressEvent(QMouseEvent *anEvent)
  667. {
  668. /* remembering coordinates of the click */
  669. if ((anEvent->buttons() & Qt::LeftButton) ||
  670. (anEvent->buttons() & Qt::RightButton))
  671. {
  672. prev_cursor_pos_ = anEvent->pos() / scale_;
  673. }
  674. QPoint pos = anEvent->pos() / scale_;
  675. if (anEvent->buttons() & Qt::LeftButton) {
  676. /* clearing the selected area if it is not confirmed */
  677. if (NewSelection == state_ && BoundingBoxTool == tool_) {
  678. bounding_box_.rect.setRect(-1, -1, 0, 0);
  679. state_ = StandBy;
  680. }
  681. /* making new points for poly */
  682. if (PolygonTool == tool_ &&
  683. NewSelection == state_ &&
  684. Qt::NoModifier == keyboard_modifier_)
  685. {
  686. triggerPolygon(pos, &(polygon_.poly));
  687. }
  688. /* starting new selection by click */
  689. if (StandBy == state_ && NoTool != tool_ &&
  690. -1 == focused_selection_) {
  691. state_ = NewSelection;
  692. emit selectionStarted();
  693. polygon_.poly.clear();
  694. if (PolygonTool == tool_) {
  695. polygon_.poly << prev_cursor_pos_;
  696. }
  697. }
  698. }
  699. if (repaint_needed_) {
  700. update();
  701. repaint_needed_ = 0;
  702. }
  703. }
  704. void
  705. ImageHolder::mouseReleaseEvent(QMouseEvent *anEvent)
  706. {
  707. Q_UNUSED(anEvent)
  708. if (-1 != hovered_point_.figureID)
  709. emit areaEdited();
  710. if (RectFigure == hovered_point_.figure &&
  711. -1 != hovered_point_.figureID &&
  712. !list_bounding_box_->
  713. at(hovered_point_.figureID)->
  714. rect.isValid()
  715. )
  716. {
  717. BoundingBox *rect = list_bounding_box_->at(hovered_point_.figureID);
  718. rect->rect = rect->rect.normalized();
  719. }
  720. }
  721. /*
  722. *
  723. */