Prevent the color popup from being shown across multiple monitors. Fixes #509.

This commit is contained in:
Leonardo Zide 2020-12-12 15:40:53 -08:00
parent ea99066465
commit 1bef9e001e

View file

@ -785,30 +785,36 @@ void lcQPropertiesTree::slotColorButtonClicked()
{ {
int ColorIndex = gDefaultColor; int ColorIndex = gDefaultColor;
lcObject* Focus = gMainWindow->GetActiveModel()->GetFocusObject(); lcObject* Focus = gMainWindow->GetActiveModel()->GetFocusObject();
if (Focus && Focus->IsPiece()) if (Focus && Focus->IsPiece())
ColorIndex = ((lcPiece*)Focus)->mColorIndex; ColorIndex = ((lcPiece*)Focus)->mColorIndex;
QWidget *parent = (QWidget*)sender(); QWidget* Button = (QWidget*)sender();
lcQColorPickerPopup *popup = new lcQColorPickerPopup(parent, ColorIndex);
connect(popup, SIGNAL(selected(int)), SLOT(slotSetValue(int)));
popup->setMinimumSize(300, 200);
const QRect desktop = QApplication::desktop()->geometry(); if (!Button)
return;
QPoint pos = parent->mapToGlobal(parent->rect().bottomLeft()); lcQColorPickerPopup* Popup = new lcQColorPickerPopup(Button, ColorIndex);
if (pos.x() < desktop.left()) connect(Popup, SIGNAL(selected(int)), SLOT(slotSetValue(int)));
pos.setX(desktop.left()); Popup->setMinimumSize(300, 200);
if (pos.y() < desktop.top())
pos.setY(desktop.top());
if ((pos.x() + popup->width()) > desktop.width()) QScreen* Screen = QGuiApplication::screenAt(Button->mapToGlobal(Button->rect().bottomLeft()));
pos.setX(desktop.width() - popup->width()); const QRect ScreenRect = Screen ? Screen->geometry() : QApplication::desktop()->geometry();
if ((pos.y() + popup->height()) > desktop.bottom())
pos.setY(desktop.bottom() - popup->height());
popup->move(pos);
popup->setFocus(); QPoint pos = Button->mapToGlobal(Button->rect().bottomLeft());
popup->show(); if (pos.x() < ScreenRect.left())
pos.setX(ScreenRect.left());
if (pos.y() < ScreenRect.top())
pos.setY(ScreenRect.top());
if ((pos.x() + Popup->width()) > ScreenRect.right())
pos.setX(ScreenRect.right() - Popup->width());
if ((pos.y() + Popup->height()) > ScreenRect.bottom())
pos.setY(ScreenRect.bottom() - Popup->height());
Popup->move(pos);
Popup->setFocus();
Popup->show();
} }
QTreeWidgetItem *lcQPropertiesTree::addProperty(QTreeWidgetItem *parent, const QString& label, PropertyType propertyType) QTreeWidgetItem *lcQPropertiesTree::addProperty(QTreeWidgetItem *parent, const QString& label, PropertyType propertyType)