8 #include <QDragEnterEvent>
14 #include <QProgressDialog>
18 #define QOI_IMPLEMENTATION
37 QWidget::paintEvent(event);
44 QPainter painter(
this);
45 painter.setRenderHint(QPainter::Antialiasing);
47 QSize rect_size =
event->rect().size();
48 QSize pix_size =
pix.size();
49 pix_size.scale(event->rect().size(), Qt::KeepAspectRatio);
51 QPoint corner((rect_size.width() - pix_size.width()) / 2,
52 (rect_size.height() - pix_size.height()) / 2);
55 pix.scaled(pix_size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
56 painter.drawPixmap(corner, scaled_pix);
70 QMessageBox::warning(
this, QString::fromLatin1(
"QtAV error"),
71 tr(
"Can not create video renderer"));
79 ui->lineEditReference->installEventFilter(
this);
82 QString theme = settings.value(
"Preferences::theme",
"light").toString();
83 ui->clearButton->setIcon(
LoadSvg(
":/resources/svg/trash.svg", theme));
86 ui->verticalLayoutMain->addWidget(
_label, 1.0);
97 if (!filename.isEmpty() && QFileInfo::exists(filename))
101 ui->lineFilename->setText(filename);
106 ui->decodeButton->setEnabled(
true);
119 return ui->lineEditReference->text();
136 QString directory_path =
137 settings.value(
"VideoDialog.loadDirectory", QDir::currentPath()).toString();
140 QFileDialog::getOpenFileName(
this, tr(
"Load Video"), directory_path, tr(
"(*.*)"));
145 directory_path = QFileInfo(filename).absolutePath();
146 settings.setValue(
"VideoDialog.loadDirectory", directory_path);
151 const auto& fps =
_media_player->statistics().video.frame_rate;
153 int num_frames =
static_cast<int>(qreal(duration_ms) * fps / 1000.0);
154 ui->timeSlider->setRange(0, num_frames);
155 _media_player->setNotifyInterval(
static_cast<int>(1000 / fps));
158 ui->timeSlider->setEnabled(
true);
160 if (
_media_player->isSeekable() ==
false || duration_ms == 0)
162 QMessageBox msgBox(
this);
163 msgBox.setWindowTitle(
"Video is not seekable");
164 msgBox.setText(tr(
"Video is not seekable. You will need to decode the video into "
165 "individual frames.\n"));
166 msgBox.addButton(QMessageBox::Cancel);
167 QPushButton* button = msgBox.addButton(tr(
"Decode!"), QMessageBox::YesRole);
168 msgBox.setDefaultButton(button);
170 int res = msgBox.exec();
172 if (res < 0 || res == QMessageBox::Cancel)
174 ui->timeSlider->setEnabled(
false);
186 double period = 1000 / fps;
187 qint64 frame_pos =
static_cast<qint64
>(qreal(num) * period);
191 num = std::max(0, num);
195 void*
data =
qoi_decode(frame.data, frame.length, &frame.info, 3);
196 QImage image(
static_cast<uchar*
>(
data), frame.info.width, frame.info.height,
197 QImage::Format_RGB888);
215 if (
ui->radioButtonFrame->isChecked())
217 ui->timeSlider->setValue(
static_cast<int>(value));
219 else if (
ui->radioButtonTime->isChecked())
221 const auto& fps =
_media_player->statistics().video.frame_rate;
222 ui->timeSlider->setValue(
static_cast<int>(value * 1000 / fps));
228 if (obj !=
ui->lineEditReference)
232 if (ev->type() == QEvent::DragEnter)
234 auto event =
static_cast<QDragEnterEvent*
>(ev);
235 const QMimeData* mimeData =
event->mimeData();
236 QStringList mimeFormats = mimeData->formats();
238 QString&
format = mimeFormats.front();
240 QByteArray encoded = mimeData->data(
format);
241 QDataStream stream(&encoded, QIODevice::ReadOnly);
243 if (
format !=
"curveslist/add_curve")
249 while (!stream.atEnd())
252 stream >> curve_name;
253 if (!curve_name.isEmpty())
255 curves.push_back(curve_name);
258 if (curves.size() != 1)
264 event->acceptProposedAction();
267 else if (ev->type() == QEvent::Drop)
269 auto lineEdit = qobject_cast<QLineEdit*>(obj);
278 ui->lineFilename->setText(
"");
279 ui->lineEditReference->setText(
"");
280 ui->timeSlider->setEnabled(
false);
281 ui->timeSlider->setValue(0);
282 ui->decodeButton->setEnabled(
false);
298 QProgressDialog progress_dialog;
299 progress_dialog.setWindowTitle(
"PlotJuggler Video");
300 progress_dialog.setLabelText(
"Decoding file");
301 progress_dialog.setWindowModality(Qt::ApplicationModal);
302 progress_dialog.setRange(0,
_media_player->duration() * fps / 1000);
303 progress_dialog.setAutoClose(
true);
304 progress_dialog.setAutoReset(
true);
305 progress_dialog.show();
312 const QtAV::VideoFrame frame =
_frame_reader->getVideoFrame();
318 QImage image = frame.toImage(QImage::Format_RGB888);
321 compressed_frame.
info.
width = frame.width();
322 compressed_frame.
info.
height = frame.height();
325 compressed_frame.
data =
331 if (++
count % 10 == 0)
333 progress_dialog.setValue(
count);
334 QApplication::processEvents();
335 if (progress_dialog.wasCanceled())
347 ui->decodeButton->setEnabled(
false);