| 982 | } |
| 983 | |
| 984 | void Select::resetBoxes(const size_type pageNum /* = -1 */) |
| 985 | { |
| 986 | _pageNum = pageNum; |
| 987 | _boxes.clear(); |
| 988 | #ifdef DEBUG |
| 989 | // In debug builds, remove any previously shown (selectable) boxes |
| 990 | foreach(QGraphicsRectItem * box, _displayBoxes) { |
| 991 | delete box; |
| 992 | } |
| 993 | _displayBoxes.clear(); |
| 994 | #endif |
| 995 | |
| 996 | Q_ASSERT(_parent != nullptr); |
| 997 | PDFDocumentScene * scene = dynamic_cast<PDFDocumentScene*>(_parent->scene()); |
| 998 | Q_ASSERT(scene != nullptr); |
| 999 | QSharedPointer<Backend::Document> doc(scene->document().toStrongRef()); |
| 1000 | if (!doc) |
| 1001 | return; |
| 1002 | |
| 1003 | QSharedPointer<Backend::Page> page(doc->page(pageNum).toStrongRef()); |
| 1004 | if (page.isNull()) |
| 1005 | return; |
| 1006 | |
| 1007 | _boxes = page->boxes(); |
| 1008 | #ifdef DEBUG |
| 1009 | // In debug builds, show all selectable boxes |
| 1010 | PDFPageGraphicsItem * pageGraphicsItem = dynamic_cast<PDFPageGraphicsItem*>(scene->pageAt(pageNum)); |
| 1011 | Q_ASSERT(pageGraphicsItem != nullptr); |
| 1012 | |
| 1013 | QTransform toView = pageGraphicsItem->pointScale(); |
| 1014 | for(const Backend::Page::Box & b : _boxes) { |
| 1015 | if (b.subBoxes.isEmpty()) { |
| 1016 | QGraphicsRectItem * rectItem = scene->addRect(toView.mapRect(b.boundingBox), QPen(_highlightColor)); |
| 1017 | rectItem->setParentItem(pageGraphicsItem); |
| 1018 | _displayBoxes << rectItem; |
| 1019 | } |
| 1020 | else { |
| 1021 | for (const Backend::Page::Box & sb : b.subBoxes) { |
| 1022 | QGraphicsRectItem * rectItem = scene->addRect(toView.mapRect(sb.boundingBox), QPen(_highlightColor)); |
| 1023 | rectItem->setParentItem(pageGraphicsItem); |
| 1024 | _displayBoxes << rectItem; |
| 1025 | } |
| 1026 | } |
| 1027 | } |
| 1028 | #endif // DEBUG |
| 1029 | } |
| 1030 | |
| 1031 | void Select::pageDestroyed() |
| 1032 | { |