Preview task-group selections until Meta is released
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "previewplacement.h"
|
||||
|
||||
#include <plasma/plasma.h>
|
||||
#include <algorithm>
|
||||
|
||||
QPoint previewPosition(const QRect &button, const QRect &screen, const QSize &preview, int panelLocation)
|
||||
{
|
||||
const QRect anchor = button.isValid() ? button : screen;
|
||||
const int centerX = anchor.x() + (anchor.width() - preview.width()) / 2;
|
||||
const int centerY = anchor.y() + (anchor.height() - preview.height()) / 2;
|
||||
QPoint result;
|
||||
switch (panelLocation) {
|
||||
case Plasma::Types::TopEdge:
|
||||
result = {centerX, button.isValid() ? button.bottom() + 1 : screen.top()};
|
||||
break;
|
||||
case Plasma::Types::LeftEdge:
|
||||
result = {button.isValid() ? button.right() + 1 : screen.left(), centerY};
|
||||
break;
|
||||
case Plasma::Types::RightEdge:
|
||||
result = {button.isValid() ? button.left() - preview.width() : screen.right() + 1 - preview.width(), centerY};
|
||||
break;
|
||||
default:
|
||||
result = {centerX, button.isValid() ? button.top() - preview.height() : screen.bottom() + 1 - preview.height()};
|
||||
break;
|
||||
}
|
||||
result.setX(std::clamp(result.x(), screen.left(), std::max(screen.left(), screen.right() + 1 - preview.width())));
|
||||
result.setY(std::clamp(result.y(), screen.top(), std::max(screen.top(), screen.bottom() + 1 - preview.height())));
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user