| 76 | } |
| 77 | |
| 78 | void ThumbnailStrip::refreshLayout() |
| 79 | { |
| 80 | if(updatesEnabled()) |
| 81 | setUpdatesEnabled(false); |
| 82 | |
| 83 | QRect avail = geometry(); |
| 84 | avail.adjust(6, 6, -6, -6); |
| 85 | |
| 86 | int numActive = 0; |
| 87 | for(ResourcePreview *c : m_Thumbnails) |
| 88 | if(c->isActive()) |
| 89 | numActive++; |
| 90 | |
| 91 | // depending on overall aspect ratio, we either lay out the strip horizontally or |
| 92 | // vertically. This tries to account for whether the strip is docked along one side |
| 93 | // or another of the texture viewer |
| 94 | if(avail.width() > avail.height()) |
| 95 | { |
| 96 | avail.setWidth(avail.width() + 6); // controls implicitly have a 6 margin on the right |
| 97 | |
| 98 | int aspectWidth = (int)((float)avail.height() * 1.3f); |
| 99 | |
| 100 | ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
| 101 | |
| 102 | delete layout; |
| 103 | layout = new QHBoxLayout(); |
| 104 | layout->setSpacing(6); |
| 105 | layout->setContentsMargins(6, 6, 6, 6); |
| 106 | layout->setAlignment(Qt::AlignTop); |
| 107 | |
| 108 | int noscrollWidth = numActive * (aspectWidth + 20); |
| 109 | |
| 110 | if(noscrollWidth <= avail.width()) |
| 111 | { |
| 112 | ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
| 113 | |
| 114 | for(ResourcePreview *c : m_Thumbnails) |
| 115 | c->setSize(QSize(aspectWidth, avail.height())); |
| 116 | } |
| 117 | else |
| 118 | { |
| 119 | ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); |
| 120 | |
| 121 | QScrollBar *hs = ui->scrollArea->horizontalScrollBar(); |
| 122 | |
| 123 | avail.setHeight(qMax(1, avail.height() - hs->geometry().height())); |
| 124 | |
| 125 | aspectWidth = qMax(1, (int)((float)avail.height() * 1.3f)); |
| 126 | |
| 127 | int totalWidth = numActive * (aspectWidth + 20); |
| 128 | hs->setEnabled(totalWidth > avail.width()); |
| 129 | |
| 130 | for(ResourcePreview *c : m_Thumbnails) |
| 131 | c->setSize(QSize(aspectWidth, avail.height())); |
| 132 | } |
| 133 | } |
| 134 | else |
| 135 | { |
no test coverage detected