- // Set the widths for the previews.
- double preview_width = preview_height * 16.0 / 9.0;
- for (unsigned i = 0; i < previews.size(); ++i) {
- ui->preview_displays->setStretch(i, lrintf(preview_width));
- }
+ if (current_audio_view == 0) { // Compact audio view.
+ // Set the widths for the previews.
+ double preview_width = preview_height * double(global_flags.width) / double(global_flags.height);
+ for (unsigned i = 0; i < previews.size(); ++i) {
+ ui->preview_displays->setStretch(i, lrintf(preview_width));
+ }
+
+ // The preview horizontal spacer.
+ double remaining_preview_width = preview_total_width - previews.size() * preview_width;
+ ui->preview_displays->setStretch(previews.size(), lrintf(remaining_preview_width));
+ } else if (current_audio_view == 2) { // Video grid view.
+ // QGridLayout doesn't do it for us, since we need to be able to remove rows
+ // or columns as the grid changes, and it won't do that. Thus, position everything
+ // by hand.
+ constexpr int spacing = 6;
+ int grid_width = ui->preview_displays_grid->geometry().width();
+ int grid_height = ui->preview_displays_grid->geometry().height();
+ int best_preview_width = 0;
+ unsigned best_num_rows = 1, best_num_cols = 1;
+ for (unsigned num_rows = 1; num_rows <= previews.size(); ++num_rows) {
+ int num_cols = (previews.size() + num_rows - 1) / num_rows;
+
+ int max_preview_height = (grid_height - spacing * (num_rows - 1)) / num_rows - preview_label_height;
+ int max_preview_width = (grid_width - spacing * (num_cols - 1)) / num_cols;
+ int preview_width = std::min<int>(max_preview_width, max_preview_height * double(global_flags.width) / double(global_flags.height));
+
+ if (preview_width > best_preview_width) {
+ best_preview_width = preview_width;
+ best_num_rows = num_rows;
+ best_num_cols = num_cols;
+ }
+ }