Commit 1da6ddb3 authored by Yang Wang's avatar Yang Wang Committed by Andreas Traczyk

videowidget: add corner-snap/rounded corners for preview

- remove resize
- re-implement paint event
- the preview now stays when the user set it in the whole session

Change-Id: I7d57f8de01d8db171c380109bfbe8295cd1378a0
Gitlab: #495
parent d9dadde7
......@@ -377,14 +377,9 @@ VideoView::mousePressEvent(QMouseEvent* event)
QPoint clickPosition = event->pos();
if (ui->videoWidget->getPreviewRect().contains(clickPosition)) {
QLine distance = QLine(clickPosition, ui->videoWidget->getPreviewRect().bottomRight());
if (distance.dy() < resizeGrip_ and distance.dx() < resizeGrip_) {
QApplication::setOverrideCursor(Qt::SizeFDiagCursor);
resizingPreview_ = true;
} else {
originMouseDisplacement_ = event->pos() - ui->videoWidget->getPreviewRect().topLeft();
QApplication::setOverrideCursor(Qt::SizeAllCursor);
draggingPreview_ = true;
}
}
}
......@@ -392,9 +387,32 @@ void
VideoView::mouseReleaseEvent(QMouseEvent* event)
{
Q_UNUSED(event)
if (draggingPreview_) {
//Check preview's current central position
QRect& previewRect = ui->videoWidget->getPreviewRect();
auto previewCentral = previewRect.center();
auto videoViewRect = ui->videoWidget->rect();
auto videoWidgetCentral = videoViewRect.center();
if (previewCentral.x() >= videoWidgetCentral.x()) {
if (previewCentral.y() >= videoWidgetCentral.y()) {
//Move preview to bottom right
ui->videoWidget->movePreview(VideoWidget::TargetPointPreview::bottomRight);
} else {
//Move preview to top right
ui->videoWidget->movePreview(VideoWidget::TargetPointPreview::topRight);
}
} else {
if (previewCentral.y() >= videoWidgetCentral.y()) {
//Move preview to bottom left
ui->videoWidget->movePreview(VideoWidget::TargetPointPreview::bottomLeft);
} else {
//Move preview to top left
ui->videoWidget->movePreview(VideoWidget::TargetPointPreview::topLeft);
}
}
}
draggingPreview_ = false;
resizingPreview_ = false;
QApplication::setOverrideCursor(Qt::ArrowCursor);
}
......@@ -431,12 +449,6 @@ VideoView::mouseMoveEvent(QMouseEvent* event)
}
QLine distance = QLine(previewRect.topLeft(), event->pos());
if (resizingPreview_
and distance.dx() > minimalSize_
and distance.dy() > minimalSize_
and geometry().contains(event->pos()))
previewRect.setBottomRight(event->pos());
}
void
......
......@@ -83,7 +83,6 @@ private:
QPoint origin_;
QPoint originMouseDisplacement_;
bool draggingPreview_ = false;
bool resizingPreview_ = false;
bool sharingEntireScreen_ = false;
std::string currentCallId_;
int keyPressed_;
......
......@@ -31,6 +31,8 @@ VideoWidget::VideoWidget(QWidget* parent) :
pal.setColor(QPalette::Background, Qt::black);
this->setAutoFillBackground(true);
this->setPalette(pal);
previewPlace_ = bottomRight;
}
VideoWidget::~VideoWidget()
......@@ -149,7 +151,14 @@ VideoWidget::paintEvent(QPaintEvent* e)
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);
updatePreviewPos();
if (!fullPreview_) {
QBrush brush(scaledPreview);
brush.setTransform(QTransform::fromTranslate(previewGeometry_.x(), previewGeometry_.y()));
QPainterPath previewPath;
previewPath.addRoundRect(previewGeometry_, 25);
painter.fillPath(previewPath, brush);
}
resetPreview_ = false;
}
......@@ -163,7 +172,15 @@ VideoWidget::paintEvent(QPaintEvent* e)
}
previewGeometry_.setWidth(scaledPreview.width());
previewGeometry_.setHeight(scaledPreview.height());
painter.drawImage(previewGeometry_, scaledPreview);
if (!fullPreview_){
QBrush brush(scaledPreview);
brush.setTransform(QTransform::fromTranslate(previewGeometry_.x(), previewGeometry_.y()));
QPainterPath previewPath;
previewPath.addRoundRect(previewGeometry_, 25);
painter.fillPath(previewPath, brush);
} else {
painter.drawImage(previewGeometry_, scaledPreview);
}
}
} else if (photoMode_) {
paintBackgroundColor(&painter, Qt::black);
......@@ -182,6 +199,79 @@ VideoWidget::paintBackgroundColor(QPainter* painter, QColor color)
painter->drawImage(previewGeometry_, scaledPreview);
}
void
VideoWidget::updatePreviewPos()
{
if (fullPreview_)
return;
switch (previewPlace_) {
case topRight:
previewGeometry_.moveTopRight(QPoint(width() - previewMargin_, previewMargin_));
break;
case topLeft:
previewGeometry_.moveTopLeft(QPoint(previewMargin_, previewMargin_));
break;
case bottomRight:
previewGeometry_.moveBottomRight(QPoint(width() - previewMargin_, height() - previewMargin_));
break;
case bottomLeft:
previewGeometry_.moveBottomLeft(QPoint(previewMargin_, height() - previewMargin_));
break;
case top:
previewGeometry_.moveTop(previewMargin_);
break;
case right:
previewGeometry_.moveRight(previewMargin_);
break;
case bottom:
previewGeometry_.moveBottom(previewMargin_);
break;
case left:
previewGeometry_.moveLeft(previewMargin_);
break;
default:
break;
}
}
void
VideoWidget::movePreview(TargetPointPreview typeOfMove)
{
resetPreview();
switch (typeOfMove)
{
case topRight:
previewPlace_ = topRight;
break;
case topLeft:
previewPlace_ = topLeft;
break;
case bottomRight:
previewPlace_ = bottomRight;
break;
case bottomLeft:
previewPlace_ = bottomLeft;
break;
case top:
previewPlace_ = top;
break;
case right:
previewPlace_ = right;
break;
case bottom:
previewPlace_ = bottom;
break;
case left:
previewPlace_ = left;
break;
default:
break;
}
}
void
VideoWidget::connectRendering()
{
......
......@@ -61,6 +61,19 @@ public slots:
void renderFrame(const std::string& id);
inline QRect& getPreviewRect(){ return previewGeometry_; }
public:
enum TargetPointPreview {
topRight,
topLeft,
bottomRight,
bottomLeft,
left,
right,
top,
bottom
};
void movePreview(TargetPointPreview typeOfMove);
private:
struct rendererConnections {
QMetaObject::Connection started, stopped, updated;
......@@ -86,6 +99,13 @@ private:
bool resetPreview_ = false;
bool photoMode_ = false;
bool hasFrame_ = false;
TargetPointPreview previewPlace_;
constexpr static int previewMargin_ = 15;
private:
void updatePreviewPos();
};
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