ImageHolder.cpp 16 KB

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