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