| 1242 | } |
| 1243 | |
| 1244 | void splitViewWidget::zoomToFitInternal() |
| 1245 | { |
| 1246 | if (!this->playlist) |
| 1247 | // The playlist was not initialized yet. Nothing to draw (yet) |
| 1248 | return; |
| 1249 | |
| 1250 | this->setMoveOffset(QPoint(0, 0)); |
| 1251 | |
| 1252 | auto item = this->playlist->getSelectedItems(); |
| 1253 | |
| 1254 | if (item[0] == nullptr) |
| 1255 | // We cannot zoom to anything |
| 1256 | return; |
| 1257 | |
| 1258 | double fracZoom = 1.0; |
| 1259 | if (!isSplitting()) |
| 1260 | { |
| 1261 | // Get the size of item 0 and the size of the widget and set the zoom factor so that this fits |
| 1262 | QSize item0Size = item[0]->getSize(); |
| 1263 | if (item0Size.width() <= 0 || item0Size.height() <= 0) |
| 1264 | return; |
| 1265 | |
| 1266 | double zoomH = (double)size().width() / item0Size.width(); |
| 1267 | double zoomV = (double)size().height() / item0Size.height(); |
| 1268 | |
| 1269 | fracZoom = std::min(zoomH, zoomV); |
| 1270 | } |
| 1271 | else if (viewSplitMode == COMPARISON) |
| 1272 | { |
| 1273 | // We can just zoom to an item that is the size of the bigger of the two items |
| 1274 | QSize virtualItemSize = item[0]->getSize(); |
| 1275 | |
| 1276 | if (item[1]) |
| 1277 | { |
| 1278 | // Extend the size of the virtual item if a second item is available |
| 1279 | QSize item1Size = item[1]->getSize(); |
| 1280 | if (item1Size.width() > virtualItemSize.width()) |
| 1281 | virtualItemSize.setWidth(item1Size.width()); |
| 1282 | if (item1Size.height() > virtualItemSize.height()) |
| 1283 | virtualItemSize.setHeight(item1Size.height()); |
| 1284 | } |
| 1285 | |
| 1286 | double zoomH = (double)size().width() / virtualItemSize.width(); |
| 1287 | double zoomV = (double)size().height() / virtualItemSize.height(); |
| 1288 | |
| 1289 | fracZoom = std::min(zoomH, zoomV); |
| 1290 | } |
| 1291 | else if (viewSplitMode == SIDE_BY_SIDE) |
| 1292 | { |
| 1293 | // We have to know the size of the split parts and calculate a zoom factor for each part |
| 1294 | int xSplit = int(size().width() * splittingPoint); |
| 1295 | |
| 1296 | // Left item |
| 1297 | QSize item0Size = item[0]->getSize(); |
| 1298 | if (item0Size.width() <= 0 || item0Size.height() <= 0) |
| 1299 | return; |
| 1300 | |
| 1301 | double zoomH = (double)xSplit / item0Size.width(); |
nothing calls this directly
no test coverage detected