Commit 8e82cca4 authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas

enhance control widget + handle fullscreen button

parent 0869a354
......@@ -53,12 +53,12 @@ QSplitter::handle {
}
QToolTip {
color: #bebfbf;
color: yellow;
border: 1px solid #242728;
border-radius: 4px;
background-color: #242728;
padding: 5px;
font: 14px;
padding: 2px;
font: bold 14px;
}
QScrollArea {
......
......@@ -72,8 +72,8 @@ dtkVisualizationCanvasPrivate::dtkVisualizationCanvasPrivate(QWidget *parent) :
this->setEnableHiDPI(true);
this->hud = new dtkWidgetsHUD(parent);
this->overlay = new dtkWidgetsOverlayPane(parent, true);
this->overlay->setToggleToolTip("Settings");
this->overlay = new dtkWidgetsOverlayPane(parent);
// this->overlay->setToggleToolTip("Settings");
this->overlay->setBound(300);
this->overlay->toggle();
......
......@@ -124,8 +124,8 @@ dtkVisualizationPlot2DPrivate::dtkVisualizationPlot2DPrivate(QWidget *parent) :
this->setEnableHiDPI(true);
this->hud = new dtkWidgetsHUD(parent);
this->overlay = new dtkWidgetsOverlayPane(parent, true);
this->overlay->setToggleToolTip("Plot settings");
this->overlay = new dtkWidgetsOverlayPane(parent);
// this->overlay->setToggleToolTip("Plot settings");
this->fields_table = vtkSmartPointer<vtkTable>::New();
......
......@@ -87,13 +87,13 @@ void dtkVisualizationViewVideoPrivate::paintGL(void)
const int offset = 50;
const int margin = 20;
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(0, 0, 0, 128));
painter.drawRect(0, this->size().height() - offset - margin, this->size().width(), margin * 7/4);
painter.setPen(Qt::white);
painter.drawText(this->size().width()/2 - metrics.width(this->title)/2, this->size().height() - offset, this->title);
// QPainter painter(this);
// painter.setRenderHint(QPainter::Antialiasing, true);
// painter.setPen(Qt::NoPen);
// painter.setBrush(QColor(0, 0, 0, 128));
// painter.drawRect(0, this->size().height() - offset - margin, this->size().width(), margin * 7/4);
// painter.setPen(Qt::white);
// painter.drawText(this->size().width()/2 - metrics.width(this->title)/2, this->size().height() - offset, this->title);
}
void dtkVisualizationViewVideoPrivate::resizeGL(int width, int height)
......
......@@ -47,12 +47,12 @@ protected:
const int offset = 50;
const int margin = 20;
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(0, 0, 0, 128));
painter.drawRect(0, this->size().height() - offset - margin, this->size().width(), margin * 7/4);
painter.setPen(Qt::white);
painter.drawText(this->size().width()/2 - metrics.width(this->title)/2, this->size().height() - offset, this->title);
// painter.setRenderHint(QPainter::Antialiasing, true);
// painter.setPen(Qt::NoPen);
// painter.setBrush(QColor(0, 0, 0, 128));
// painter.drawRect(0, this->size().height() - offset - margin, this->size().width(), margin * 7/4);
// painter.setPen(Qt::white);
// painter.drawText(this->size().width()/2 - metrics.width(this->title)/2, this->size().height() - offset, this->title);
}
public:
......
......@@ -244,8 +244,15 @@ dtkVisualizationViewVideoPlayer::dtkVisualizationViewVideoPlayer(QWidget *parent
connect(d->controls, &dtkVisualizationWidgetsVideoControls::pause, d->player, &QMediaPlayer::pause);
connect(d->controls, &dtkVisualizationWidgetsVideoControls::play, d->player, &QMediaPlayer::play);
connect(d->controls, &dtkVisualizationWidgetsVideoControls::seekTo, d->player, &QMediaPlayer::setPosition);
connect(d->controls, &dtkVisualizationWidgetsVideoControls::fullscreen, [=](bool is_full){
if (is_full) {
this->widget()->window()->showFullScreen();
} else {
this->widget()->window()->showNormal();
}
}
);
connect(d->controls, &dtkVisualizationWidgetsVideoControls::restart,[=] () {
qDebug() << "restart";
d->player->setPosition(0);
d->player->play();
d->controls->toggle();
......@@ -341,7 +348,8 @@ void dtkVisualizationViewVideoPlayer::resizeEvent(QResizeEvent *event)
d->hud->resize(event->size());
d->overlay->resize(event->size());
d->controls->move(event->size().width() / 2 - 32, event->size().height() - 32);
d->controls->setFixedWidth(event->size().width());
d->controls->move(0, event->size().height() - 64);
}
#include "dtkVisualizationViewVideoPlayer.moc"
......@@ -35,12 +35,12 @@ public:
dtkWidgetsHUD *hud(void) ;
protected:
void dragEnterEvent(QDragEnterEvent *);
void dragLeaveEvent(QDragLeaveEvent *);
void dragMoveEvent(QDragMoveEvent *);
void dropEvent(QDropEvent *);
void keyPressEvent(QKeyEvent *);
void resizeEvent(QResizeEvent *);
void dragEnterEvent(QDragEnterEvent *) override;
void dragLeaveEvent(QDragLeaveEvent *) override;
void dragMoveEvent(QDragMoveEvent *) override;
void dropEvent(QDropEvent *) override;
void keyPressEvent(QKeyEvent *) override;
void resizeEvent(QResizeEvent *) override;
private:
class dtkVisualizationViewVideoPlayerPrivate *d;
......
......@@ -46,30 +46,65 @@ protected:
};
class dtkVisualizationWidgetsVideoControlsPrivate {
class dtkVisualizationWidgetsVideoControlsPrivate: public QObject
{
Q_OBJECT
public:
dtkVisualizationWidgetsVideoControlsItem *status_item = nullptr;
dtkVisualizationWidgetsVideoControlsItem *rewind = nullptr;
dtkVisualizationWidgetsVideoControlsItem *fullscreen = nullptr;
QMediaPlayer::State state = QMediaPlayer::State::StoppedState;
public slots:
void updateDurationInfo(qint64 currentInfo);
public:
QProgressBar *progress_bar = nullptr;
QLabel *label_duration = nullptr;
bool is_fullscreen = false;
};
void dtkVisualizationWidgetsVideoControlsPrivate::updateDurationInfo(qint64 currentInfo)
{
QString tStr;
int duration = this->progress_bar->maximum() / 1000;
if (currentInfo || duration) {
QTime currentTime((currentInfo / 3600) % 60, (currentInfo / 60) % 60,
currentInfo % 60, (currentInfo * 1000) % 1000);
QTime totalTime((duration / 3600) % 60, (duration / 60) % 60,
duration % 60, (duration * 1000) % 1000);
QString format = "mm:ss";
if (duration > 3600)
format = "hh:mm:ss";
tStr = currentTime.toString(format) + " / " + totalTime.toString(format);
}
this->label_duration->setText(tStr);
this->label_duration->setStyleSheet("font: 14pt;");
}
dtkVisualizationWidgetsVideoControls::dtkVisualizationWidgetsVideoControls(QWidget *parent): QFrame(parent), d(new dtkVisualizationWidgetsVideoControlsPrivate)
{
this->setAttribute(Qt::WA_NoSystemBackground);
this->setAttribute(Qt::WA_TranslucentBackground);
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);
dtkFontAwesome::instance()->setDefaultOption("color", QColor(Qt::white));
d->status_item = new dtkVisualizationWidgetsVideoControlsItem(fa::play, 24, parent);
d->rewind = new dtkVisualizationWidgetsVideoControlsItem(fa::stepbackward, 24, parent);
d->fullscreen = new dtkVisualizationWidgetsVideoControlsItem(fa::arrowsalt, 24, parent);
connect(d->status_item, &dtkVisualizationWidgetsVideoControlsItem::clicked, this, &dtkVisualizationWidgetsVideoControls::toggle);
connect(d->fullscreen, &dtkVisualizationWidgetsVideoControlsItem::clicked, [=]() {
if (d->is_fullscreen) // was fullscreen
d->fullscreen->setIcon(fa::arrowsalt);
else
d->fullscreen->setIcon(fa::compress);
d->is_fullscreen = !d->is_fullscreen;
emit fullscreen(d->is_fullscreen);
});
connect(d->rewind, &dtkVisualizationWidgetsVideoControlsItem::clicked, [=]() {
d->state = QMediaPlayer::State::StoppedState;
d->status_item->setIcon(fa::play);
......@@ -80,23 +115,39 @@ dtkVisualizationWidgetsVideoControls::dtkVisualizationWidgetsVideoControls(QWidg
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->setFixedHeight(10);
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(253,26,30,100); }";
d->progress_bar->setStyleSheet(style_bar);
QHBoxLayout *layout = new QHBoxLayout(this);
d->label_duration = new QLabel(this);
d->label_duration->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QVBoxLayout *vlayout = new QVBoxLayout(this);
vlayout->setContentsMargins(32, 0, 32, 0);
vlayout->setAlignment(Qt::AlignLeft);
QHBoxLayout *layout = new QHBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(d->rewind);
layout->addWidget(d->status_item);
layout->addWidget(d->progress_bar);
layout->addWidget(d->rewind);
layout->addWidget(d->label_duration);
layout->addWidget(d->fullscreen);
this->setMouseTracking(true);
vlayout->addWidget(d->progress_bar);
vlayout->addLayout(layout);
this->setLayout(vlayout);
}
void dtkVisualizationWidgetsVideoControls::reset(void)
{
d->state = QMediaPlayer::State::StoppedState;
dtkFontAwesome::instance()->setDefaultOption("color", QColor(Qt::gray));
dtkFontAwesome::instance()->setDefaultOption("color", QColor(Qt::white));
d->status_item->setIcon(fa::play);
}
......@@ -120,18 +171,19 @@ void dtkVisualizationWidgetsVideoControls::setDuration(qlonglong duration)
void dtkVisualizationWidgetsVideoControls::setPosition(qlonglong pos)
{
d->progress_bar->setValue(pos);
d->updateDurationInfo(pos / 1000);
}
void dtkVisualizationWidgetsVideoControls::toggle(void)
{
if (d->state == QMediaPlayer::State::StoppedState || d->state == QMediaPlayer::State::PausedState) {
d->state = QMediaPlayer::State::PlayingState;
dtkFontAwesome::instance()->setDefaultOption("color", QColor(Qt::gray));
dtkFontAwesome::instance()->setDefaultOption("color", QColor(Qt::white));
d->status_item->setIcon(fa::pause);
emit play();
} else {
d->state = QMediaPlayer::State::PausedState;
dtkFontAwesome::instance()->setDefaultOption("color", QColor(Qt::gray));
dtkFontAwesome::instance()->setDefaultOption("color", QColor(Qt::white));
d->status_item->setIcon(fa::play);
emit pause();
}
......@@ -144,6 +196,18 @@ void dtkVisualizationWidgetsVideoControls::setCurrentFrame(qlonglong count)
void dtkVisualizationWidgetsVideoControls::mouseMoveEvent(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() / 1000.0 ;
QTime currentTime((frame_index / 3600) % 60, (frame_index / 60) % 60,
frame_index % 60, (frame_index * 1000) % 1000);
QString format = "mm:ss";
if (frame_index > 3600)
format = "hh:mm:ss";
d->progress_bar->setToolTip(currentTime.toString(format));
event->ignore();
QFrame::mouseMoveEvent(event);
......
......@@ -28,10 +28,11 @@ signals:
void play(void);
void restart(void);
void seekTo(int);
void fullscreen(bool);
public:
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
public slots:
void setCurrentFrame(qlonglong frame_id);
......
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