ImageHolder.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  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. update();
  425. }
  426. void
  427. ImageHolder::clearLast()
  428. {
  429. switch (tool_) {
  430. case BoundingBoxTool:
  431. bounding_box_.rect.setRect(-1, -1, 0, 0);
  432. break;
  433. case PolygonTool:
  434. polygon_.poly.clear();
  435. break;
  436. case TaggingTool:
  437. break;
  438. default:
  439. break;
  440. }
  441. bounding_box_.rect.setRect(-1, -1, 0, 0);
  442. state_ = StandBy;
  443. update();
  444. }
  445. void
  446. ImageHolder::confirmSelection()
  447. {
  448. if (NewSelection != state_ || NoTool == tool_) {
  449. return;
  450. /* NOTREACHED */
  451. }
  452. if (BoundingBoxTool == tool_) {
  453. BoundingBox *bbox = new BoundingBox;
  454. bounding_box_.rect = bounding_box_.rect.normalized();
  455. *bbox = bounding_box_;
  456. list_bounding_box_->append(bbox);
  457. bounding_box_.rect.setRect(-1, -1, 0, 0);
  458. }
  459. else if (PolygonTool == tool_) {
  460. Polygon *poly = new Polygon;
  461. *poly = polygon_;
  462. list_polygon_->append(poly);
  463. polygon_.poly.clear();
  464. }
  465. list_poly_history_.clear();
  466. state_ = StandBy;
  467. update();
  468. }
  469. ImageHolder::State
  470. ImageHolder::state()
  471. {
  472. return state_;
  473. }
  474. ImageHolder::Tool
  475. ImageHolder::tool()
  476. {
  477. return tool_;
  478. }
  479. int
  480. ImageHolder::focusedSelection()
  481. {
  482. return focused_selection_;
  483. }
  484. Figure
  485. ImageHolder::focusedSelectionType()
  486. {
  487. return focused_selection_type_;
  488. }
  489. void
  490. ImageHolder::undo()
  491. {
  492. if (PolygonTool == tool_ &&
  493. NewSelection == state_ &&
  494. !polygon_.poly.isEmpty())
  495. {
  496. list_poly_history_.append(polygon_.poly.last());
  497. polygon_.poly.pop_back();
  498. repaint_needed_ = 1;
  499. }
  500. if (repaint_needed_) {
  501. update();
  502. repaint_needed_ = 0;
  503. }
  504. }
  505. void
  506. ImageHolder::redo()
  507. {
  508. if (PolygonTool == tool_ &&
  509. NewSelection == state_ &&
  510. !list_poly_history_.isEmpty())
  511. {
  512. polygon_.poly.append(list_poly_history_.last());
  513. list_poly_history_.pop_back();
  514. repaint_needed_ = 1;
  515. }
  516. if (repaint_needed_) {
  517. update();
  518. repaint_needed_ = 0;
  519. }
  520. }
  521. void
  522. ImageHolder::checkForPoints(QPoint *aPos)
  523. {
  524. if ((!list_polygon_->count() &&
  525. !list_bounding_box_->count()) ||
  526. !aPos) {
  527. return;
  528. /* NOTREACHED */
  529. }
  530. int newRadius = 0;
  531. int x = aPos->x();
  532. int y = aPos->y();
  533. /* center coordinates */
  534. int xc = 0;
  535. int yc = 0;
  536. for (int i = 0; i < list_polygon_->count(); i++) {
  537. QPolygon poly = list_polygon_->at(i)->poly;
  538. for (int j = 0; j < poly.count(); j++) {
  539. xc = poly.at(j).x();
  540. yc = poly.at(j).y();
  541. newRadius = qSqrt(qPow(x - xc, 2) + qPow(y - yc, 2));
  542. if (newRadius <= point_radius_) {
  543. hovered_point_.figure = PolyFigure;
  544. hovered_point_.figureID = i;
  545. hovered_point_.pointID = j;
  546. repaint_needed_ = 1;
  547. return;
  548. /* NOTREACHED */
  549. }
  550. }
  551. }
  552. for (int i = 0; i < list_bounding_box_->count(); i++) {
  553. QRect rect = list_bounding_box_->at(i)->rect;
  554. for (int j = 0; j < 4; j++) {
  555. if (!j) {
  556. xc = rect.left();
  557. yc = rect.top();
  558. }
  559. else if (1 == j)
  560. {
  561. xc = rect.right();
  562. yc = rect.top();
  563. }
  564. else if (2 == j)
  565. {
  566. xc = rect.right();
  567. yc = rect.bottom();
  568. }
  569. else if (3 == j)
  570. {
  571. xc = rect.left();
  572. yc = rect.bottom();
  573. }
  574. newRadius = qSqrt(qPow(x - xc, 2) + qPow(y - yc, 2));
  575. if (newRadius <= point_radius_) {
  576. hovered_point_.figure = RectFigure;
  577. hovered_point_.figureID = i;
  578. hovered_point_.pointID = j;
  579. repaint_needed_ = 1;
  580. return;
  581. /* NOTREACHED */
  582. }
  583. }
  584. }
  585. hovered_point_.figure = NoFigure;
  586. hovered_point_.figureID = -1;
  587. hovered_point_.pointID = -1;
  588. repaint_needed_ = 1;
  589. }
  590. void
  591. ImageHolder::keyPressEvent(QKeyEvent *anEvent)
  592. {
  593. QLabel::keyPressEvent(anEvent);
  594. //keyboard_modifier_ = anEvent->modifiers();
  595. if (repaint_needed_) {
  596. update();
  597. repaint_needed_ = 0;
  598. }
  599. }
  600. void
  601. ImageHolder::mouseMoveEvent(QMouseEvent *anEvent)
  602. {
  603. QPoint pos = anEvent->pos() / scale_;
  604. if (anEvent->pos().x() < 0)
  605. pos.setX(0);
  606. if (width() < anEvent->pos().x())
  607. pos.setX(width() - 1);
  608. if (anEvent->pos().y() < 0)
  609. pos.setY(0);
  610. if (height() < anEvent->pos().y())
  611. pos.setY(height() - 1);
  612. if ((anEvent->buttons() & Qt::LeftButton) &&
  613. BoundingBoxTool == tool_ &&
  614. NewSelection == state_ &&
  615. Qt::NoModifier == keyboard_modifier_)
  616. {
  617. triggerBoundBox(pos, prev_cursor_pos_, &(bounding_box_.rect));
  618. }
  619. if (PolygonTool == tool_ &&
  620. NewSelection == state_ &&
  621. (anEvent->buttons() & Qt::LeftButton))
  622. {
  623. polygon_.poly.setPoint(polygon_.poly.count() - 1, pos);
  624. //triggerPolygon(pos, &(polygon_.poly));
  625. repaint_needed_ = 1;
  626. }
  627. if (-1 != focused_selection_ &&
  628. !(anEvent->buttons() & Qt::LeftButton)) {
  629. checkForPoints(&pos);
  630. }
  631. /* editing polygons */
  632. if (-1 != hovered_point_.figureID &&
  633. !list_polygon_->isEmpty() &&
  634. PolyFigure == hovered_point_.figure &&
  635. (anEvent->buttons() & Qt::LeftButton))
  636. {
  637. Polygon *poly = list_polygon_->at(hovered_point_.figureID);
  638. poly->poly.setPoint(hovered_point_.pointID, pos);
  639. repaint_needed_ = 1;
  640. }
  641. /* editing bounding boxes */
  642. if (-1 != hovered_point_.figureID &&
  643. !list_bounding_box_->isEmpty() &&
  644. RectFigure == hovered_point_.figure &&
  645. (anEvent->buttons() & Qt::LeftButton))
  646. {
  647. BoundingBox *rect = list_bounding_box_->at(hovered_point_.figureID);
  648. if (0 == hovered_point_.pointID)
  649. rect->rect.setTopLeft(pos);
  650. else if (1 == hovered_point_.pointID)
  651. rect->rect.setTopRight(pos);
  652. else if (2 == hovered_point_.pointID)
  653. rect->rect.setBottomRight(pos);
  654. else if (3 == hovered_point_.pointID)
  655. rect->rect.setBottomLeft(pos);
  656. repaint_needed_ = 1;
  657. }
  658. if (repaint_needed_) {
  659. update();
  660. repaint_needed_ = 0;
  661. }
  662. }
  663. void
  664. ImageHolder::mousePressEvent(QMouseEvent *anEvent)
  665. {
  666. /* remembering coordinates of the click */
  667. if ((anEvent->buttons() & Qt::LeftButton) ||
  668. (anEvent->buttons() & Qt::RightButton))
  669. {
  670. prev_cursor_pos_ = anEvent->pos() / scale_;
  671. }
  672. QPoint pos = anEvent->pos() / scale_;
  673. if (anEvent->buttons() & Qt::LeftButton) {
  674. /* clearing the selected area if it is not confirmed */
  675. if (NewSelection == state_ && BoundingBoxTool == tool_) {
  676. bounding_box_.rect.setRect(-1, -1, 0, 0);
  677. state_ = StandBy;
  678. }
  679. /* making new points for poly */
  680. if (PolygonTool == tool_ &&
  681. NewSelection == state_ &&
  682. Qt::NoModifier == keyboard_modifier_)
  683. {
  684. triggerPolygon(pos, &(polygon_.poly));
  685. }
  686. /* starting new selection by click */
  687. if (StandBy == state_ && NoTool != tool_ &&
  688. -1 == focused_selection_) {
  689. state_ = NewSelection;
  690. emit selectionStarted();
  691. polygon_.poly.clear();
  692. if (PolygonTool == tool_) {
  693. polygon_.poly << prev_cursor_pos_;
  694. }
  695. }
  696. }
  697. if (repaint_needed_) {
  698. update();
  699. repaint_needed_ = 0;
  700. }
  701. }
  702. void
  703. ImageHolder::mouseReleaseEvent(QMouseEvent *anEvent)
  704. {
  705. Q_UNUSED(anEvent)
  706. if (-1 != hovered_point_.figureID)
  707. emit areaEdited();
  708. if (RectFigure == hovered_point_.figure &&
  709. -1 != hovered_point_.figureID &&
  710. !list_bounding_box_->
  711. at(hovered_point_.figureID)->
  712. rect.isValid()
  713. )
  714. {
  715. BoundingBox *rect = list_bounding_box_->at(hovered_point_.figureID);
  716. rect->rect = rect->rect.normalized();
  717. }
  718. }
  719. /*
  720. *
  721. */