QuantitySpinBox: Fixed placement of expression editor pop-up.

This commit is contained in:
Eivind Kvedalen 2015-09-22 22:46:58 +02:00
parent 90ccc1cee4
commit 28fe9b481d
3 changed files with 19 additions and 4 deletions

View File

@ -35,7 +35,6 @@ using namespace App;
using namespace Gui::Dialog; using namespace Gui::Dialog;
const int DlgExpressionInput::h = 15; const int DlgExpressionInput::h = 15;
const int DlgExpressionInput::l = 30;
const int DlgExpressionInput::r = 30; const int DlgExpressionInput::r = 30;
const int DlgExpressionInput::d = 7; const int DlgExpressionInput::d = 7;
@ -45,7 +44,8 @@ DlgExpressionInput::DlgExpressionInput(const App::ObjectIdentifier & _path, boos
expression(_expression ? _expression->copy() : 0), expression(_expression ? _expression->copy() : 0),
path(_path), path(_path),
discarded(false), discarded(false),
impliedUnit(_impliedUnit) impliedUnit(_impliedUnit),
l(30)
{ {
assert(path.getDocumentObject() != 0); assert(path.getDocumentObject() != 0);
@ -91,6 +91,19 @@ QPoint DlgExpressionInput::tip() const
return QPoint(l - d, 0); return QPoint(l - d, 0);
} }
void DlgExpressionInput::setGeometry(int x, int y, int w, int h)
{
QDesktopWidget widget;
int screenWidth = widget.availableGeometry(widget.primaryScreen()).width();
if (x + w > screenWidth) {
l = l + (x + w - screenWidth);
x = screenWidth - w - 10;
}
QWidget::setGeometry(x, y, w, h);
}
void DlgExpressionInput::paintEvent(QPaintEvent * event) { void DlgExpressionInput::paintEvent(QPaintEvent * event) {
QPainter painter(this); QPainter painter(this);
QPainterPath path; QPainterPath path;

View File

@ -62,6 +62,8 @@ public:
QPoint tip() const; QPoint tip() const;
void setGeometry(int x, int y, int w, int h);
private Q_SLOTS: private Q_SLOTS:
void textChanged(const QString & text); void textChanged(const QString & text);
void setDiscarded(); void setDiscarded();
@ -74,7 +76,7 @@ private:
const Base::Unit impliedUnit; const Base::Unit impliedUnit;
static const int h; static const int h;
static const int l; int l;
static const int r; static const int r;
static const int d; static const int d;
}; };

View File

@ -497,7 +497,7 @@ void QuantitySpinBox::openFormulaDialog()
Gui::Dialog::DlgExpressionInput box(getPath(), getExpression(), d->unit, this); Gui::Dialog::DlgExpressionInput box(getPath(), getExpression(), d->unit, this);
QPoint pos = mapToGlobal(QPoint(width() / 2, height() / 2)); QPoint pos = mapToGlobal(QPoint(width() / 2, height() / 2));
box.setGeometry(pos.x() - box.tip().x(), pos.y() - box.tip().y(), width(), height()); box.setGeometry(pos.x() - box.tip().x(), pos.y() - box.tip().y(), box.width(), box.height());
if (box.exec() == QDialog::Accepted) if (box.exec() == QDialog::Accepted)
setExpression(box.getExpression()); setExpression(box.getExpression());
else if (box.discardedFormula()) else if (box.discardedFormula())