Commit e52278b6 authored by Yang Wang's avatar Yang Wang Committed by Andreas Traczyk

videoview: fix the preview reposition problems

Gitlab: #495
Change-Id: I29cd215147b673e82b692b194ef79099f58cc01a
parent 6019918a
...@@ -67,6 +67,7 @@ VideoView::VideoView(QWidget* parent) : ...@@ -67,6 +67,7 @@ VideoView::VideoView(QWidget* parent) :
this, SLOT(showContextMenu(const QPoint&))); this, SLOT(showContextMenu(const QPoint&)));
connect(overlay_, &VideoOverlay::setChatVisibility, [=](bool visible) { connect(overlay_, &VideoOverlay::setChatVisibility, [=](bool visible) {
emit this->setChatVisibility(visible); emit this->setChatVisibility(visible);
connect(this, SIGNAL(toggleFullScreenClicked()), ui->videoWidget, SLOT(slotToggleFullScreenClicked()));
}); });
} }
...@@ -81,6 +82,7 @@ VideoView::~VideoView() ...@@ -81,6 +82,7 @@ VideoView::~VideoView()
void void
VideoView::resizeEvent(QResizeEvent* event) VideoView::resizeEvent(QResizeEvent* event)
{ {
int marginWidth = ui->videoWidget->getPreviewMargin();
QRect& previewRect = ui->videoWidget->getPreviewRect(); QRect& previewRect = ui->videoWidget->getPreviewRect();
int deltaW = event->size().width() - event->oldSize().width(); int deltaW = event->size().width() - event->oldSize().width();
int deltaH = event->size().height() - event->oldSize().height(); int deltaH = event->size().height() - event->oldSize().height();
...@@ -102,16 +104,20 @@ VideoView::resizeEvent(QResizeEvent* event) ...@@ -102,16 +104,20 @@ VideoView::resizeEvent(QResizeEvent* event)
} }
if (previewRect.left() <= 0) if (previewRect.left() <= 0)
previewRect.moveLeft(1); previewRect.moveLeft(marginWidth);
previewRect.moveRight(width() - marginWidth);
if (previewRect.right() >= width()) if (previewRect.right() >= width())
previewRect.moveRight(width() - 1); previewRect.moveRight(width() - marginWidth);
if (previewRect.top() <= 0) if (previewRect.top() <= 0)
previewRect.moveTop(1); previewRect.moveTop(marginWidth);
previewRect.moveBottom(height() - marginWidth);
if (previewRect.bottom() >= height()) if (previewRect.bottom() >= height())
previewRect.moveBottom(height() - 1); previewRect.moveBottom(height() - marginWidth);
ui->videoWidget->resetPreview();
overlay_->resize(this->size()); overlay_->resize(this->size());
overlay_->show(); overlay_->show();
...@@ -164,8 +170,10 @@ VideoView::slotCallStatusChanged(const std::string& callId) ...@@ -164,8 +170,10 @@ VideoView::slotCallStatusChanged(const std::string& callId)
} }
return; return;
} }
default: case Status::ENDED:
emit closing(call.id); emit closing(call.id);
default:
//emit closing(call.id);
break; break;
} }
QObject::disconnect(timerConnection_); QObject::disconnect(timerConnection_);
......
...@@ -109,6 +109,12 @@ VideoWidget::renderFrame(const std::string& id) ...@@ -109,6 +109,12 @@ VideoWidget::renderFrame(const std::string& id)
} }
} }
void
VideoWidget::slotToggleFullScreenClicked()
{
this->update();
}
void void
VideoWidget::paintEvent(QPaintEvent* e) VideoWidget::paintEvent(QPaintEvent* e)
{ {
...@@ -154,9 +160,9 @@ VideoWidget::paintEvent(QPaintEvent* e) ...@@ -154,9 +160,9 @@ VideoWidget::paintEvent(QPaintEvent* e)
hasFrame_ = true; hasFrame_ = true;
} }
if (previewImage_) { if (previewImage_) {
if(resetPreview_) { if (resetPreview_) {
auto previewHeight = fullPreview_ ? height() : height() / 4; auto previewHeight = fullPreview_ ? height() : height() / 6;
auto previewWidth = fullPreview_ ? width() : width() / 4; auto previewWidth = fullPreview_ ? width() : width() / 6;
QImage scaledPreview; QImage scaledPreview;
if (photoMode_) if (photoMode_)
scaledPreview = Utils::getCirclePhoto(*previewImage_, previewHeight); scaledPreview = Utils::getCirclePhoto(*previewImage_, previewHeight);
...@@ -164,8 +170,8 @@ VideoWidget::paintEvent(QPaintEvent* e) ...@@ -164,8 +170,8 @@ VideoWidget::paintEvent(QPaintEvent* e)
scaledPreview = previewImage_->scaled(previewWidth, previewHeight, Qt::KeepAspectRatio); scaledPreview = previewImage_->scaled(previewWidth, previewHeight, Qt::KeepAspectRatio);
auto xDiff = (previewWidth - scaledPreview.width()) / 2; auto xDiff = (previewWidth - scaledPreview.width()) / 2;
auto yDiff = (previewHeight - scaledPreview.height()) / 2; auto yDiff = (previewHeight - scaledPreview.height()) / 2;
auto yPos = fullPreview_ ? yDiff : height() - previewHeight - previewMargin_;
auto xPos = fullPreview_ ? xDiff : width() - scaledPreview.width() - previewMargin_; auto xPos = fullPreview_ ? xDiff : width() - scaledPreview.width() - previewMargin_;
auto yPos = fullPreview_ ? yDiff : height() - scaledPreview.height() - previewMargin_;
previewGeometry_.setRect(xPos, yPos, scaledPreview.width(), scaledPreview.height()); previewGeometry_.setRect(xPos, yPos, scaledPreview.width(), scaledPreview.height());
painter.drawImage(previewGeometry_, scaledPreview); painter.drawImage(previewGeometry_, scaledPreview);
resetPreview_ = false; resetPreview_ = false;
......
...@@ -43,11 +43,14 @@ public: ...@@ -43,11 +43,14 @@ public:
inline void setResetPreview(bool reset) { resetPreview_ = reset; hasFrame_=false; } inline void setResetPreview(bool reset) { resetPreview_ = reset; hasFrame_=false; }
void setPhotoMode(bool isPhotoMode); void setPhotoMode(bool isPhotoMode);
QImage takePhoto(); QImage takePhoto();
int getPreviewMargin(){ return previewMargin_; }
void resetPreview() { resetPreview_ = true; }
protected: protected:
void paintEvent(QPaintEvent* e); void paintEvent(QPaintEvent* e);
public slots: public slots:
void slotToggleFullScreenClicked();
void slotRendererStarted(const std::string& id); void slotRendererStarted(const std::string& id);
void renderFrame(const std::string& id); void renderFrame(const std::string& id);
inline QRect& getPreviewRect(){ return previewGeometry_; } inline QRect& getPreviewRect(){ return previewGeometry_; }
...@@ -57,6 +60,8 @@ private: ...@@ -57,6 +60,8 @@ private:
QMetaObject::Connection started, stopped, updated; QMetaObject::Connection started, stopped, updated;
} rendererConnections_; } rendererConnections_;
void paintBackgroundColor(QPainter* painter, QColor color);
video::Renderer* previewRenderer_; video::Renderer* previewRenderer_;
video::Frame previewFrame_; video::Frame previewFrame_;
std::unique_ptr<QImage> previewImage_; std::unique_ptr<QImage> previewImage_;
...@@ -77,7 +82,4 @@ private: ...@@ -77,7 +82,4 @@ private:
bool hasFrame_ = false; bool hasFrame_ = false;
constexpr static int previewMargin_ = 15; constexpr static int previewMargin_ = 15;
private:
void paintBackgroundColor(QPainter* painter, QColor color);
}; };
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