diff --git a/src/capture/widget/buttonhandler.cpp b/src/capture/widget/buttonhandler.cpp index 8f7cd87f..9502b25d 100644 --- a/src/capture/widget/buttonhandler.cpp +++ b/src/capture/widget/buttonhandler.cpp @@ -32,11 +32,13 @@ ButtonHandler::ButtonHandler(const QVector &v, QObject(parent), m_limits(limits) { setButtons(v); + updateScreenRegions(); } ButtonHandler::ButtonHandler(const QRect &limits, QObject *parent) : QObject(parent), m_limits(limits) { + updateScreenRegions(); } void ButtonHandler::hide() { @@ -224,14 +226,32 @@ void ButtonHandler::resetRegionTrack() { } void ButtonHandler::updateBlockedSides() { - m_blockedRight = - (m_limits.right() - m_selection.right() < SEPARATION*2 + m_buttonBaseSize); - m_blockedLeft = - (m_selection.x() < m_buttonBaseSize + SEPARATION*2); - m_blockedBotton = - (m_limits.bottom() - m_selection.bottom() < SEPARATION*2 + m_buttonBaseSize); - m_blockedTop = - (m_selection.y() < m_buttonBaseSize + SEPARATION*2); + const int EXTENSION = SEPARATION * 2 + m_buttonBaseSize; + // Right + QPoint pointA(m_selection.right() + EXTENSION, + m_selection.bottom()); + QPoint pointB(pointA.x(), + m_selection.top()); + m_blockedRight = !(m_screenRegions.contains(pointA) && + m_screenRegions.contains(pointB)); + // Left + pointA.setX(m_selection.left() - EXTENSION); + pointB.setX(pointA.x()); + m_blockedLeft = !(m_screenRegions.contains(pointA) && + m_screenRegions.contains(pointB)); + // Botton + pointA = QPoint(m_selection.left(), + m_selection.bottom() + EXTENSION); + pointB = QPoint(m_selection.right(), + pointA.y()); + m_blockedBotton = !(m_screenRegions.contains(pointA) && + m_screenRegions.contains(pointB)); + // Top + pointA.setY(m_selection.top() - EXTENSION); + pointB.setY(pointA.y()); + m_blockedTop = !(m_screenRegions.contains(pointA) && + m_screenRegions.contains(pointB)); + // Auxiliar m_oneHorizontalBlocked = (!m_blockedRight && m_blockedLeft) || (m_blockedRight && !m_blockedLeft); m_horizontalyBlocked = (m_blockedRight && m_blockedLeft); @@ -345,3 +365,10 @@ bool ButtonHandler::contains(const QPoint &p) const { QRegion r(QRect(topLeft, bottonRight).normalized()); return r.contains(p); } + +void ButtonHandler::updateScreenRegions() { + m_screenRegions = QRegion(); + for (QScreen *const screen : QGuiApplication::screens()) { + m_screenRegions += screen->geometry(); + } +} diff --git a/src/capture/widget/buttonhandler.h b/src/capture/widget/buttonhandler.h index 964609c7..b04bc813 100644 --- a/src/capture/widget/buttonhandler.h +++ b/src/capture/widget/buttonhandler.h @@ -21,6 +21,7 @@ #include "capturebutton.h" #include #include +#include class CaptureButton; class QRect; @@ -41,6 +42,7 @@ public: void updatePosition(const QRect &selection); void setButtons(const QVector); bool contains(const QPoint &p) const; + void updateScreenRegions(); public slots: void hide(); @@ -54,6 +56,8 @@ private: QVector m_vectorButtons; + QRegion m_screenRegions; + int m_buttonExtendedSize; int m_buttonBaseSize;