Commit ca320d87 authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Adrien Béraud

videoview: fade video overlay when mouse is not moving

Change-Id: I9095888304ba8290e6e9840b9b8bce4b2ba62028
parent 8d5e5495
......@@ -46,7 +46,7 @@ VideoView::VideoView(QWidget* parent) :
connect(&CallModel::instance(), SIGNAL(callStateChanged(Call*, Call::State)),
this, SLOT(callStateChanged(Call*, Call::State)));
overlay_ = new VideoOverlay(this);
auto effect = new QGraphicsOpacityEffect(overlay_);
effect->setOpacity(maxOverlayOpacity_);
......@@ -58,6 +58,12 @@ VideoView::VideoView(QWidget* parent) :
fadeAnim_->setStartValue(effect->opacity());
fadeAnim_->setEndValue(0);
fadeAnim_->setEasingCurve(QEasingCurve::OutQuad);
// Setup the timer to start the fade when the mouse stops moving
this->setMouseTracking(true);
overlay_->setMouseTracking(true);
fadeTimer_.setSingleShot(true);
connect(&fadeTimer_, SIGNAL(timeout()), this, SLOT(fadeOverlayOut()));
this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),
......@@ -119,15 +125,27 @@ void
VideoView::enterEvent(QEvent* event)
{
Q_UNUSED(event)
fadeAnim_->stop();
fadeAnim_->targetObject()->setProperty(fadeAnim_->propertyName(), fadeAnim_->startValue());
showOverlay();
}
void
VideoView::leaveEvent(QEvent* event)
{
Q_UNUSED(event)
if(not overlay_->isDialogVisible())
fadeOverlayOut();
}
void
VideoView::showOverlay()
{
fadeAnim_->stop();
fadeAnim_->targetObject()->setProperty(fadeAnim_->propertyName(), fadeAnim_->startValue());
}
void
VideoView::fadeOverlayOut()
{
if (not overlay_->isDialogVisible())
fadeAnim_->start(QAbstractAnimation::KeepWhenStopped);
}
......@@ -333,6 +351,13 @@ VideoView::mouseReleaseEvent(QMouseEvent* event)
void
VideoView::mouseMoveEvent(QMouseEvent* event)
{
// start/restart the timer after which the overlay will fade
if (fadeTimer_.isActive()) {
showOverlay();
} else {
fadeTimer_.start(startfadeOverlayTime_);
}
QRect& previewRect = ui->videoWidget->getPreviewRect();
if (draggingPreview_) {
if (previewRect.left() > 0
......
......@@ -54,11 +54,14 @@ private slots:
void updateCall();
void showContextMenu(const QPoint& pos);
void slotVideoStarted(Video::Renderer* renderer);
void fadeOverlayOut();
void showOverlay();
private:
Ui::VideoView* ui;
VideoOverlay* overlay_;
QPropertyAnimation* fadeAnim_;
QTimer fadeTimer_;
QWidget* oldParent_;
QSize oldSize_;
QMetaObject::Connection timerConnection_;
......@@ -72,6 +75,10 @@ private:
constexpr static int resizeGrip_ = 40;
constexpr static int minimalSize_ = 100;
// Time before the overlay starts fading out after the mouse stops
// moving within the videoview.
constexpr static int startfadeOverlayTime_ = 2000; //msec
// TODO: fix when changing Qt version
// Full(1.0) opacity bug affecting many Qt version (macOS + win10)
// causing the render to take a buggy code path which can be avoided
......
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