Commit d92b3286 authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas

first prototype of video player

parent 28d2e5ff
......@@ -18,6 +18,7 @@
#include <dtkVisualization/dtkVisualizationPlot3D>
#include <dtkVisualization/dtkVisualizationView2D>
#include <dtkVisualization/dtkVisualizationView3D>
#include <dtkVisualization/dtkVisualizationViewVideoPlayer>
#include <dtkWidgets/dtkWidgetsLayout>
#include <dtkWidgets/dtkWidgetsLayoutItem>
......@@ -66,6 +67,8 @@ dtkWidgetsWidget *dtkVisualizationViewerStack::create(const QString& type)
view = new dtkVisualizationView3D;
else if (type == "View3D")
view = new dtkVisualizationView3D;
else if (type == "ViewVideoPlayer")
view = new dtkVisualizationViewVideoPlayer;
return view;
}
......
......@@ -45,6 +45,7 @@ int main(int argc, char **argv)
actions.insert("Plot3D", "Plot 3D");
actions.insert("View2D", "View 2D");
actions.insert("View3D", "View 3D");
actions.insert("ViewVideoPlayer", "Video player");
dtkWidgetsLayoutItem::setActions(actions);
......
......@@ -38,8 +38,11 @@ set(${PROJECT_NAME}_HEADERS
dtkVisualizationViewVideo.h
dtkVisualizationViewVideoGL
dtkVisualizationViewVideoGL.h
dtkVisualizationViewVideoPlayer
dtkVisualizationViewVideoPlayer.h
dtkVisualizationViewVideoRaster
dtkVisualizationViewVideoRaster.h)
dtkVisualizationViewVideoRaster.h
)
set(${PROJECT_NAME}_SOURCES
dtkVisualizationActor.cpp
......@@ -51,7 +54,9 @@ set(${PROJECT_NAME}_SOURCES
dtkVisualizationView3D.cpp
dtkVisualizationViewVideo.cpp
dtkVisualizationViewVideoGL.cpp
dtkVisualizationViewVideoRaster.cpp)
dtkVisualizationViewVideoPlayer.cpp
dtkVisualizationViewVideoRaster.cpp
)
set(${PROJECT_NAME}_SOURCES_QRC dtkVisualization.qrc)
......@@ -69,8 +74,10 @@ add_library(${PROJECT_NAME} SHARED
${${PROJECT_NAME}_HEADERS})
target_link_libraries(${PROJECT_NAME} Qt5::Core)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} Qt5::Multimedia)
target_link_libraries(${PROJECT_NAME} Qt5::MultimediaWidgets)
target_link_libraries(${PROJECT_NAME} Qt5::OpenGL)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} dtkFonts)
target_link_libraries(${PROJECT_NAME} dtkWidgets)
......
#include "dtkVisualizationViewVideoPlayer.h"
#include "dtkVisualizationViewVideoPlayer.h"
#include <dtkVisualizationWidgets/dtkVisualizationWidgetsVideoControls>
#include <dtkWidgets/dtkWidgetsHUD>
#include <dtkWidgets/dtkWidgetsHUDItem>
#include <dtkWidgets/dtkWidgetsOverlayPane>
#include <dtkWidgets/dtkWidgetsOverlayPaneItem>
#include <dtkFonts>
#include <QVideoWidget>
class dtkVisualizationViewVideoPlayerPrivate: public QVideoWidget
{
Q_OBJECT
public:
dtkVisualizationViewVideoPlayerPrivate(QWidget *parent = nullptr);
~dtkVisualizationViewVideoPlayerPrivate(void);
public:
dtkVisualizationWidgetsVideoControls *controls = nullptr;
QMediaPlayer * player = nullptr;
public:
dtkWidgetsOverlayPane *overlay = nullptr;
dtkWidgetsHUD *hud = nullptr;
public:
dtkVisualizationViewVideoPlayer *q = nullptr;
protected:
void mousePressEvent(QMouseEvent *event);
void resizeEvent(QResizeEvent *event);
};
dtkVisualizationViewVideoPlayerPrivate::dtkVisualizationViewVideoPlayerPrivate(QWidget *parent) : QVideoWidget(parent)
{
this->hud = new dtkWidgetsHUD(this);
this->player = new QMediaPlayer(this);
this->player->setAudioRole(QAudio::VideoRole); // FIXME
this->player->setVideoOutput(this);
QLineEdit *text_edit = new QLineEdit("TODO Settings");
dtkWidgetsOverlayPaneItem *display_settings_item = new dtkWidgetsOverlayPaneItem(this);
display_settings_item->setTitle("Display Settings");
display_settings_item->layout()->setContentsMargins(0, 0, 0, 0);
display_settings_item->addWidget(text_edit);
this->overlay = new dtkWidgetsOverlayPane(this);
this->controls = new dtkVisualizationWidgetsVideoControls(this);
this->overlay->addWidget(display_settings_item);
this->overlay->toggle();
this->controls->setVisible(false);
setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
QPalette p = palette();
p.setColor(QPalette::Window, Qt::black);
setPalette(p);
setAttribute(Qt::WA_OpaquePaintEvent);
connect(this->controls, &dtkVisualizationWidgetsVideoControls::pause, this->player, &QMediaPlayer::pause);
connect(this->controls, &dtkVisualizationWidgetsVideoControls::play, this->player, &QMediaPlayer::play);
connect(this->controls, &dtkVisualizationWidgetsVideoControls::seekTo, [=] (int frame_index) {
// double duration = 1000.0 * frame_index / (this->fps);
// this->current_frame_number = frame_index;
this->player->setPosition(frame_index);
});
connect(this->controls, &dtkVisualizationWidgetsVideoControls::restart,[=] () {
this->player->setPosition(0);
this->player->play();
});
}
dtkVisualizationViewVideoPlayerPrivate::~dtkVisualizationViewVideoPlayerPrivate(void)
{
}
void dtkVisualizationViewVideoPlayerPrivate::mousePressEvent(QMouseEvent *event)
{
q->emit focused();
if(this->overlay->rect().contains(event->pos())) {
event->accept();
return;
}
QVideoWidget::mousePressEvent(event);
}
void dtkVisualizationViewVideoPlayerPrivate::resizeEvent(QResizeEvent *event)
{
QVideoWidget::resizeEvent(event);
this->hud->resize(event->size());
this->overlay->setFixedHeight(event->size().height());
this->controls->move(event->size().width() / 2 - 32, event->size().height() - 32);
}
dtkVisualizationViewVideoPlayer::dtkVisualizationViewVideoPlayer(QWidget *parent): dtkWidgetsWidget(parent)
{
d = new dtkVisualizationViewVideoPlayerPrivate(this);
d->q = this;
static int count = 1;
this->setObjectName(QString("ViewVideoPlayer - %1").arg(count++));
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(d);
dtkWidgetsHUDItem *settings = d->hud->addItem(fa::sliders);
dtkWidgetsHUDItem *open = d->hud->addItem(fa::folderopen);
open->setToolTip("Open File");
settings->setToolTip("Settings");
connect(settings, SIGNAL(clicked()), d->overlay, SLOT(toggle()));
connect(open, SIGNAL(clicked()), this, SLOT(open()));
this->setAcceptDrops(true);
}
dtkVisualizationViewVideoPlayer::~dtkVisualizationViewVideoPlayer(void)
{
delete d;
}
QWidget *dtkVisualizationViewVideoPlayer::widget(void)
{
return d;
}
void dtkVisualizationViewVideoPlayer::update(void)
{
//FIXME
}
void dtkVisualizationViewVideoPlayer::open(void)
{
QFileDialog fileDialog(this);
fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
fileDialog.setWindowTitle(tr("Open Files"));
QStringList supportedMimeTypes = d->player->supportedMimeTypes();
if (!supportedMimeTypes.isEmpty()) {
supportedMimeTypes.append("video/x-mp4"); //FIXME ?
fileDialog.setMimeTypeFilters(supportedMimeTypes);
}
fileDialog.setDirectory(QStandardPaths::standardLocations(QStandardPaths::MoviesLocation).value(0, QDir::homePath()));
if (fileDialog.exec() == QDialog::Accepted) {
// QMediaContent *content = new QMediaContent(fileDialog.selectedUrls().first());
qDebug() << "try to open " << fileDialog.selectedUrls().first();
d->player->setMedia(fileDialog.selectedUrls().first());
d->controls->setVisible(true);
}
}
dtkWidgetsOverlayPane *dtkVisualizationViewVideoPlayer::overlay(void)
{
return d->overlay;
}
dtkWidgetsHUD *dtkVisualizationViewVideoPlayer::hud(void)
{
return d->hud;
}
void dtkVisualizationViewVideoPlayer::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasText())
event->accept();
else
event->ignore();
}
void dtkVisualizationViewVideoPlayer::dragLeaveEvent(QDragLeaveEvent *event)
{
event->accept();
}
void dtkVisualizationViewVideoPlayer::dragMoveEvent(QDragMoveEvent *event)
{
if (event->mimeData()->hasText())
event->accept();
else
event->ignore();
}
void dtkVisualizationViewVideoPlayer::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasText()) {
QString path = event->mimeData()->text();
if(!path.startsWith("file://"))
return;
path.remove("file://");
// if (path.endsWith(".vti"))
// this->importVTI(path);
// if (path.endsWith(".vtp"))
// this->importVTP(path);
// if (path.endsWith(".vtr"))
// this->importVTR(path);
// if (path.endsWith(".vts"))
// this->importVTS(path);
// if (path.endsWith(".vtu"))
// this->importVTU(path);
event->accept();
}
}
void dtkVisualizationViewVideoPlayer::keyPressEvent(QKeyEvent *event)
{
event->ignore();
// dtkWidgetsWidget::keyPressEvent(event);
}
#include "dtkVisualizationViewVideoPlayer.moc"
#pragma once
#include <QtCore>
#include <QtWidgets>
#include <dtkVisualizationExport>
#include <dtkWidgets/dtkWidgetsWidget>
class dtkWidgetsHUD;
class dtkWidgetsOverlayPane;
class DTKVISUALIZATION_EXPORT dtkVisualizationViewVideoPlayer: public dtkWidgetsWidget
{
Q_OBJECT
public:
dtkVisualizationViewVideoPlayer(QWidget *parent = nullptr);
virtual ~dtkVisualizationViewVideoPlayer();
public:
QWidget *widget(void);
public slots:
void update(void);
void open(void);
public:
dtkWidgetsOverlayPane *overlay(void);
dtkWidgetsHUD *hud(void);
protected:
void dragEnterEvent(QDragEnterEvent *);
void dragLeaveEvent(QDragLeaveEvent *);
void dragMoveEvent(QDragMoveEvent *);
void dropEvent(QDropEvent *);
void keyPressEvent(QKeyEvent *);
// void mousePressEvent(QMouseEvent *);
// void resizeEvent(QResizeEvent *);
private:
class dtkVisualizationViewVideoPlayerPrivate *d;
};
......@@ -24,12 +24,17 @@ set(${PROJECT_NAME}_HEADERS
dtkVisualizationWidgetsClutEditor
dtkVisualizationWidgetsClutEditor.h
dtkVisualizationWidgetsFieldScalar
dtkVisualizationWidgetsFieldScalar.h)
dtkVisualizationWidgetsFieldScalar.h
dtkVisualizationWidgetsVideoControls
dtkVisualizationWidgetsVideoControls.h
)
set(${PROJECT_NAME}_SOURCES
dtkVisualizationWidgetsActorList.cpp
dtkVisualizationWidgetsClutEditor.cpp
dtkVisualizationWidgetsFieldScalar.cpp)
dtkVisualizationWidgetsFieldScalar.cpp
dtkVisualizationWidgetsVideoControls.cpp
)
## #################################################################
## Build rules
......@@ -40,8 +45,9 @@ add_library(${PROJECT_NAME} SHARED
${${PROJECT_NAME}_HEADERS})
target_link_libraries(${PROJECT_NAME} Qt5::Core)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} Qt5::OpenGL)
target_link_libraries(${PROJECT_NAME} Qt5::Multimedia)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} Qt5::Xml)
target_link_libraries(${PROJECT_NAME} dtkFonts)
......
#include "dtkVisualizationWidgetsVideoControls.h"
#include "dtkVisualizationWidgetsVideoControls.h"
#include <dtkFonts>
#include <dtkWidgets/dtkWidgetsHUD>
#include <dtkWidgets/dtkWidgetsHUDItem>
class dtkVisualizationWidgetsVideoControlsItem: public QFrame
{
Q_OBJECT
public:
dtkVisualizationWidgetsVideoControlsItem(fa::icon icon, int icon_size, QWidget *parent = nullptr): QFrame(parent) {
m_icon_size = icon_size;
label = new QLabel(this);
label->setFixedSize(QSize(icon_size,icon_size));
label->setPixmap(dtkFontAwesome::instance()->icon(icon).pixmap(icon_size, icon_size));
label->setAttribute(Qt::WA_TranslucentBackground);
label->setAttribute(Qt::WA_NoSystemBackground);
label->setVisible(true);
QHBoxLayout *layout = new QHBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
layout->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
layout->addWidget(label);
this->setLayout(layout);
this->setMouseTracking(true);
};
virtual ~dtkVisualizationWidgetsVideoControlsItem(void) { };
void setIcon(fa::icon icon) {
label->setPixmap(dtkFontAwesome::instance()->icon(icon).pixmap(m_icon_size, m_icon_size));
};
signals:
void clicked(void);
protected:
QLabel *label = nullptr;
int m_icon_size = 0;
protected:
void mousePressEvent(QMouseEvent *event) { emit clicked(); } ;
};
class dtkVisualizationWidgetsVideoControlsPrivate {
public:
dtkVisualizationWidgetsVideoControlsItem *status_item = nullptr;
dtkVisualizationWidgetsVideoControlsItem *rewind = nullptr;
QMediaPlayer::State state = QMediaPlayer::State::StoppedState;
public:
QProgressBar *progress_bar = nullptr;
};
dtkVisualizationWidgetsVideoControls::dtkVisualizationWidgetsVideoControls(QWidget *parent): QFrame(parent), d(new dtkVisualizationWidgetsVideoControlsPrivate)
{
dtkFontAwesome::instance()->initFontAwesome();
dtkFontAwesome::instance()->setDefaultOption("color", QColor(Qt::gray));
d->status_item = new dtkVisualizationWidgetsVideoControlsItem(fa::play, 30, parent);
d->rewind = new dtkVisualizationWidgetsVideoControlsItem(fa::stepbackward, 24, parent);
connect(d->status_item, &dtkVisualizationWidgetsVideoControlsItem::clicked, [=] () {
if (d->state == QMediaPlayer::State::StoppedState || QMediaPlayer::State::PausedState) {
d->state = QMediaPlayer::State::PlayingState;
dtkFontAwesome::instance()->setDefaultOption("color", QColor(Qt::gray));
d->status_item->setIcon(fa::pause);
qDebug() << "emitting play";
emit play();
} else {
d->state = QMediaPlayer::State::PausedState;
dtkFontAwesome::instance()->setDefaultOption("color", QColor(Qt::gray));
d->status_item->setIcon(fa::play);
qDebug() << "emitting pause";
emit pause();
}
});
connect(d->rewind, &dtkVisualizationWidgetsVideoControlsItem::clicked, [=]() {
d->status_item->setIcon(fa::play);
d->progress_bar->reset();
emit restart();
});
d->progress_bar = new QProgressBar(parent);
d->progress_bar->setOrientation(Qt::Horizontal);
d->progress_bar->setTextVisible(true);
QString style_bar = "QProgressBar{ border: 1px solid transparent; text-align: center; color:rgba(0,0,0,100); border-radius: 5px; background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(182, 182, 182, 100), stop:1 rgba(209, 209, 209, 100)); } QProgressBar::chunk{ background-color: rgba(0,255,0,100); }";
d->progress_bar->setStyleSheet(style_bar);
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(d->rewind);
layout->addWidget(d->status_item);
layout->addWidget(d->progress_bar);
this->setMouseTracking(true);
}
void dtkVisualizationWidgetsVideoControls::reset(void)
{
d->state = QMediaPlayer::State::StoppedState;
dtkFontAwesome::instance()->setDefaultOption("color", QColor(Qt::gray));
d->status_item->setIcon(fa::play);
}
QMediaPlayer::State dtkVisualizationWidgetsVideoControls::state(void) const
{
return d->state;
}
void dtkVisualizationWidgetsVideoControls::setFrameNumber(qlonglong count)
{
d->progress_bar->setRange(1, count);
d->progress_bar->setValue(1);
d->progress_bar->reset();
}
void dtkVisualizationWidgetsVideoControls::setCurrentFrame(qlonglong count)
{
d->progress_bar->setValue(count);
}
void dtkVisualizationWidgetsVideoControls::mouseMoveEvent(QMouseEvent *event)
{
event->ignore();
QFrame::mouseMoveEvent(event);
}
void dtkVisualizationWidgetsVideoControls::mousePressEvent(QMouseEvent *event)
{
int size = d->progress_bar->width();
double percent = (event->pos().x() - d->progress_bar->x())/ (double)size ;
int frame_index = percent * d->progress_bar->maximum();
emit seekTo(frame_index);
event->ignore();
QFrame::mousePressEvent(event);
}
#include "dtkVisualizationWidgetsVideoControls.moc"
#pragma once
#include <QFrame>
#include <QMediaPlayer>
#include <dtkVisualizationWidgetsExport.h>
class dtkWidgetsHUD;
class dtkWidgetsHUDItem;
class DTKVISUALIZATIONWIDGETS_EXPORT dtkVisualizationWidgetsVideoControls: public QFrame
{
Q_OBJECT
public:
dtkVisualizationWidgetsVideoControls(QWidget *parent);
virtual ~dtkVisualizationWidgetsVideoControls() {};
public:
QMediaPlayer::State state(void) const;
public:
void reset(void);
signals:
void pause(void);
void play(void);
void restart(void);
void seekTo(int);
public:
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
public slots:
void setCurrentFrame(qlonglong frame_id);
void setFrameNumber(qlonglong frame_count);
private:
class dtkVisualizationWidgetsVideoControlsPrivate *d;
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment