Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
lupoDharkael committed May 16, 2018
1 parent 7814dd9 commit 54c5f97
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/widgets/capture/rectgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,26 @@ RectGroup::RectGroup(const QVector<QRect> &v) : m_rects(v) {

void RectGroup::setRects(const QVector<QRect> &v) {
m_rects = v;
// Sort by x coord from higher to lower.
std::sort(m_rects.begin(), m_rects.end(),
[](const QRect &r1, const QRect &r2) {
return r1.x() < r2.x();
return r1.x() > r2.x();
});
}

QRect RectGroup::getRectContainingPoint(const QPoint &p) const {
QRect res;
// Get the iterator to the QRect with x() lower than p's x().
auto it = std::upper_bound(m_rects.begin(), m_rects.end(), QRect(p, p),
[](const QRect &r1, const QRect &r2) {
return r1.x() < r2.x();
return r1.x() > r2.x();
});

for (auto i = m_rects.begin(); i != it; i++) {
if (i->contains(p)) {
res = (*i);
// Find the rect containing the mouse in the rects with x() lower
// than p's x()
for (; it != m_rects.end(); it++) {
if (it->contains(p)) {
res = (*it);
break;
}
}
Expand Down

0 comments on commit 54c5f97

Please sign in to comment.