Commit 3096811a authored by Ming Rui Zhang's avatar Ming Rui Zhang

selectareadialog: set a minimum rect for the select area to display

- Also, the dialog now take rect reference so that, lrc api is
  called in videoview

Change-Id: I5fe63a67cbb68b144e113b96bc3d8b580ff60c60
parent 2da169af
/***************************************************************************
* Copyright (C) 2015-2017 by Savoir-faire Linux *
* Copyright (C) 2015-2017 by Savoir-faire Linux *
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
* *
* This program is free software; you can redistribute it and/or modify *
......@@ -31,8 +31,13 @@
#include "lrcinstance.h"
#include "utils.h"
SelectAreaDialog::SelectAreaDialog() :
rubberBand_(nullptr)
SelectAreaDialog::SelectAreaDialog(int& screenNumberRef,
QRect& rectArea,
QWidget* parent) :
rubberBand_(nullptr),
screenNumber_(screenNumberRef),
rectArea_(rectArea),
QDialog(parent)
{
setWindowFlags(Qt::Widget | Qt::FramelessWindowHint);
setWindowState(Qt::WindowFullScreen);
......@@ -41,12 +46,14 @@ SelectAreaDialog::SelectAreaDialog() :
setAttribute(Qt::WA_NoSystemBackground, false);
setAttribute(Qt::WA_TranslucentBackground, true);
setAttribute(Qt::WA_PaintOnScreen);
setWindowModality(Qt::ApplicationModal);
grabMouse();
rubberBand_ = new QRubberBand(QRubberBand::Rectangle, this);
QApplication::setOverrideCursor(Qt::CrossCursor);
auto screenNumber = qApp->desktop()->screenNumber(this);
if (auto screen = qApp->screens().at(screenNumber)) {
originalPixmap_ = screen->grabWindow(screenNumber);
screenNumber_ = qApp->desktop()->screenNumber(parent);
if (auto screen = qApp->screens().at(screenNumber_)) {
originalPixmap_ = screen->grabWindow(0);
originalPixmap_.setDevicePixelRatio(screen->devicePixelRatio());
}
}
......@@ -81,8 +88,7 @@ SelectAreaDialog::mouseReleaseEvent(QMouseEvent* event)
return;
}
auto screenNumber = qApp->desktop()->screenNumber(this);
QScreen* screen = qApp->screens().at(screenNumber);
QScreen* screen = qApp->screens().at(screenNumber_);
if (!screen) {
screen = qApp->primaryScreen();
}
......@@ -106,11 +112,14 @@ SelectAreaDialog::mouseReleaseEvent(QMouseEvent* event)
rect.setHeight(static_cast<int>(height));
}
# endif
LRCInstance::avModel().setDisplay(screenNumber,
rect.x(), rect.y(), rect.width(), rect.height()
);
// Minimun size
rect.setHeight(rect.height() < 128 ? 128 : rect.height());
rect.setWidth(rect.width() < 128 ? 128 : rect.width());
rectArea_ = rect;
rubberBand_->deleteLater();
reject();
done(0);
}
void
......
......@@ -28,16 +28,21 @@ class SelectAreaDialog : public QDialog
{
Q_OBJECT
public:
SelectAreaDialog();
explicit SelectAreaDialog(int& screenNumberRef,
QRect& rectArea,
QWidget* parent = nullptr);
protected:
void mousePressEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void paintEvent(QPaintEvent* event);
void mousePressEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void paintEvent(QPaintEvent* event);
private:
QPoint origin_;
QDialog transDialog_;
QRubberBand* rubberBand_;
QPixmap originalPixmap_;
QPoint origin_;
QDialog transDialog_;
QRubberBand* rubberBand_;
QPixmap originalPixmap_;
int& screenNumber_;
QRect& rectArea_;
};
......@@ -268,8 +268,15 @@ VideoView::showContextMenu(const QPoint& position)
connect(shareAreaAction, &QAction::triggered,
[this]() {
resetPreview();
SelectAreaDialog selectAreaDialog;
selectAreaDialog.exec();
QRect area;
int screenNumber = 0;
SelectAreaDialog selectAreaDialog(screenNumber, area, this);
int code = selectAreaDialog.exec();
if (code == 0) {
LRCInstance::avModel().setDisplay(screenNumber,
area.x(), area.y(), area.width(), area.height()
);
}
sharingEntireScreen_ = false;
});
......
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