Commit 966c2133 authored by Thomas Baumgart's avatar Thomas Baumgart
Browse files

Make calculator widget a parentless popup

Using the AmountEdit widget as parent widget for the calculator caused
trouble in some circumstances (see bug report). Making the popup
parentless solves the issue.

BUG: 429436
FIXED-IN: 5.1.1

(cherry picked from commit 7767d4b4)
parent f0651a6a
......@@ -79,7 +79,7 @@ public:
m_allowEmpty(false)
{
Q_Q(AmountEdit);
m_calculatorFrame = new QFrame(q);
m_calculatorFrame = new QFrame;
m_calculatorFrame->setWindowFlags(Qt::Popup);
m_calculatorFrame->setFrameStyle(QFrame::Panel | QFrame::Raised);
......@@ -145,27 +145,33 @@ public:
Q_Q(AmountEdit);
m_calculator->setInitialValues(q->text(), k);
auto h = m_calculatorFrame->height();
auto w = m_calculatorFrame->width();
// do not open the calculator in read-only mode
if (q->isReadOnly())
return;
// usually, the calculator widget is shown underneath the MoneyEdit widget
// show calculator and update size
m_calculatorFrame->show();
m_calculatorFrame->setGeometry(m_calculator->geometry());
const auto h = m_calculatorFrame->height();
const auto w = m_calculatorFrame->width();
// usually, the calculator widget is shown underneath the AmountEdit widget
// if it does not fit on the screen, we show it above this widget
auto p = q->mapToGlobal(QPoint(0, 0));
if (p.y() + q->height() + h > QApplication::desktop()->height())
auto p = q->mapToGlobal(QPoint());
if (p.y() + q->height() + h > QApplication::desktop()->height()) {
p.setY(p.y() - h);
else
} else {
p.setY(p.y() + q->height());
}
// usually, it is shown left aligned. If it does not fit, we align it
// to the right edge of the widget
if (p.x() + w > QApplication::desktop()->width())
// to the right edge of the AmountEdit widget
if (p.x() + w > QApplication::desktop()->width()) {
p.setX(p.x() + q->width() - w);
}
m_calculatorFrame->show();
QRect r = m_calculator->geometry();
r.moveTopLeft(p);
m_calculatorFrame->setGeometry(r);
m_calculatorFrame->move(p);
m_calculator->setFocus();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment