1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright (c) 2012-2017 VideoStitch SAS
// Copyright (c) 2018 stitchEm
#include "cropinputtab.hpp"
#include "ui_cropinputtab.h"
#include "libvideostitch-gui/utils/inputlensenum.hpp"
#include "libvideostitch-gui/videostitcher/globalcontroller.hpp"
#include "libvideostitch-gui/widgets/crop/croprectangleeditor.hpp"
#include "libvideostitch-gui/widgets/crop/cropcircleeditor.hpp"
CropInputTab::CropInputTab(const int id, const QSize videoSize, const int availableHaight, const Crop& crop,
const InputLensClass::LensType t, QWidget* parent)
: QFrame(parent),
ui(new Ui::CropInputTab),
inputIndex(id),
maxHeight(availableHaight),
videoSize(videoSize),
videoWidget(nullptr),
editor(nullptr) {
ui->setupUi(this);
ui->buttonRestore->setProperty("vs-button-medium", true);
videoWidget = std::shared_ptr<SingleVideoWidget>(new SingleVideoWidget(id, ui->frameBackground));
videoWidget->setObjectName(QStringLiteral("videoWidget"));
videoWidget->setMinimumSize(QSize(0, 0));
ui->layoutMain->addWidget(videoWidget.get());
videoWidget->setName(getReaderName().toStdString());
connect(ui->spinLeft, &QSpinBox::editingFinished, this, &CropInputTab::onLeftCropValueChanged);
connect(ui->spinTop, &QSpinBox::editingFinished, this, &CropInputTab::onTopCropValueChanged);
connect(ui->spinRight, &QSpinBox::editingFinished, this, &CropInputTab::onRightCropValueChanged);
connect(ui->spinBottom, &QSpinBox::editingFinished, this, &CropInputTab::onBottomCropValueChanged);
createCropEditor(calculateThumbnailSize(), crop, t);
videoWidget->setFixedSize(calculateThumbnailSize());
}
CropInputTab::~CropInputTab() { delete ui; }
QString CropInputTab::getReaderName() const { return QStringLiteral("cropInputTab") + QString::number(inputIndex); }
Crop CropInputTab::getCrop() const { return editor->getCrop(); }
void CropInputTab::disableCropActions(const bool block) {
ui->topFrame->setDisabled(block);
editor->disableEdition(block);
}
std::shared_ptr<SingleVideoWidget> CropInputTab::getVideoWidget() const { return videoWidget; }
void CropInputTab::setDefaultCrop() {
if (editor != nullptr) {
editor->setDefaultCrop();
}
}
void CropInputTab::updateEditorFromSpinBoxes() {
editor->setCrop(Crop(ui->spinLeft->value(), ui->spinRight->value(), ui->spinTop->value(), ui->spinBottom->value()));
}
void CropInputTab::onCropShapeChanged(const Crop& crop) {
ui->spinLeft->setValue(crop.crop_left);
ui->spinTop->setValue(crop.crop_top);
ui->spinRight->setValue(crop.crop_right);
ui->spinBottom->setValue(crop.crop_bottom);
emit cropChanged(crop);
}
void CropInputTab::setCrop(const Crop& crop) { editor->setCrop(crop); }
void CropInputTab::createCropEditor(const QSize thumbnailSize, const Crop& crop, InputLensClass::LensType lensType) {
if (lensType == InputLensClass::LensType::CircularFisheye) {
editor.reset(new CropCircleEditor(thumbnailSize, videoSize, crop, videoWidget.get()));
} else {
editor.reset(new CropRectangleEditor(thumbnailSize, videoSize, crop, videoWidget.get()));
}
connect(editor.data(), &CropShapeEditor::notifyCropSet, this, &CropInputTab::onCropShapeChanged);
connect(ui->buttonRestore, &QPushButton::clicked, editor.data(), &CropShapeEditor::onResetToDefault);
onCropShapeChanged(editor->getCrop());
}
QSize CropInputTab::calculateThumbnailSize() const {
if (maxHeight < (videoSize.height())) {
// If it doesn't fit in the available space, reduce it
const float factor = floor(float(maxHeight) / float(videoSize.height()) * 10 + .5) / 10;
return QSize(videoSize.width() * factor, videoSize.height() * factor);
} else {
// Otherwise, use the original frame size
return videoSize;
}
}
void CropInputTab::onLeftCropValueChanged() {
if (ui->spinLeft->value() > ui->spinRight->value()) {
ui->spinLeft->blockSignals(true);
ui->spinLeft->setValue(ui->spinRight->value());
ui->spinLeft->blockSignals(false);
}
updateEditorFromSpinBoxes();
}
void CropInputTab::onRightCropValueChanged() {
if (ui->spinLeft->value() > ui->spinRight->value()) {
ui->spinRight->blockSignals(true);
ui->spinRight->setValue(ui->spinLeft->value());
ui->spinRight->blockSignals(false);
}
updateEditorFromSpinBoxes();
}
void CropInputTab::onTopCropValueChanged() {
if (ui->spinTop->value() > ui->spinBottom->value()) {
ui->spinTop->blockSignals(true);
ui->spinTop->setValue(ui->spinBottom->value());
ui->spinTop->blockSignals(false);
}
updateEditorFromSpinBoxes();
}
void CropInputTab::onBottomCropValueChanged() {
if (ui->spinTop->value() > ui->spinBottom->value()) {
ui->spinBottom->blockSignals(true);
ui->spinBottom->setValue(ui->spinTop->value());
ui->spinBottom->blockSignals(false);
}
updateEditorFromSpinBoxes();
}