ImageHolder.cpp 16 KB

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