| 1555 | } |
| 1556 | |
| 1557 | void ImageViewer::insertImage(shared_ptr<Image> image, size_t index, bool shallSelect) { |
| 1558 | if (!image) { |
| 1559 | throw invalid_argument{"Image may not be null."}; |
| 1560 | } |
| 1561 | |
| 1562 | if (mDragType == EMouseDragType::ImageButtonDrag && index <= mDraggedImageButtonId) { |
| 1563 | ++mDraggedImageButtonId; |
| 1564 | } |
| 1565 | |
| 1566 | auto button = new ImageButton{nullptr, image->name(), true}; |
| 1567 | button->set_font_size(15); |
| 1568 | button->setId(index + 1); |
| 1569 | button->set_tooltip(image->toString()); |
| 1570 | |
| 1571 | button->setSelectedCallback([this, image]() { selectImage(image); }); |
| 1572 | |
| 1573 | button->setReferenceCallback([this, image](bool isReference) { |
| 1574 | if (!isReference) { |
| 1575 | selectReference(nullptr); |
| 1576 | } else { |
| 1577 | selectReference(image); |
| 1578 | } |
| 1579 | }); |
| 1580 | |
| 1581 | button->setCaptionChangeCallback([this]() { mRequiresFilterUpdate = true; }); |
| 1582 | |
| 1583 | mImageButtonContainer->add_child((int)index, button); |
| 1584 | mImages.insert(begin(mImages) + index, image); |
| 1585 | |
| 1586 | mShouldFooterBeVisible |= image->channelGroups().size() > 1; |
| 1587 | // The following call will make sure the footer becomes visible if the previous line enabled it. |
| 1588 | setUiVisible(isUiVisible()); |
| 1589 | |
| 1590 | // Ensure the new image button will have the correct visibility state. |
| 1591 | setFilter(mFilter->value()); |
| 1592 | |
| 1593 | requestLayoutUpdate(); |
| 1594 | |
| 1595 | // First image got added, let's select it. |
| 1596 | if ((index == 0 && mImages.size() == 1) || shallSelect) { |
| 1597 | selectImage(image); |
| 1598 | if (!isMaximized() && resizeWindowToFitImageOnLoad()) { |
| 1599 | resizeToFit(sizeToFitImage(image)); |
| 1600 | } |
| 1601 | } |
| 1602 | } |
| 1603 | |
| 1604 | void ImageViewer::moveImageInList(size_t oldIndex, size_t newIndex) { |
| 1605 | if (oldIndex == newIndex) { |
nothing calls this directly
no test coverage detected