Fix QGraphicsWidget window frame section logic

CppCat detected duplicate sub-expressions in the code that checked for
BottomLeftSection and BottomRightSection. It was fairly obvious to
see what the values should be.

Change-Id: Id45ca5bbd26c92b800c60867fef5170578216eee
Reviewed-by: Andreas Aardal Hanssen <andreas@hanssen.name>
This commit is contained in:
Dyami Caliri 2015-01-26 14:45:09 -08:00
parent 2b99491692
commit 2a27fc41a4
2 changed files with 31 additions and 2 deletions

View File

@ -1311,7 +1311,7 @@ Qt::WindowFrameSection QGraphicsWidget::windowFrameSectionAt(const QPointF &pos)
if (x <= left + cornerMargin) {
if (y <= top + windowFrameWidth || (x <= left + windowFrameWidth && y <= top + cornerMargin)) {
s = Qt::TopLeftSection;
} else if (y >= bottom - windowFrameWidth || (x <= left + windowFrameWidth && y >= bottom - windowFrameWidth)) {
} else if (y >= bottom - windowFrameWidth || (x <= left + windowFrameWidth && y >= bottom - cornerMargin)) {
s = Qt::BottomLeftSection;
} else if (x <= left + windowFrameWidth) {
s = Qt::LeftSection;
@ -1319,7 +1319,7 @@ Qt::WindowFrameSection QGraphicsWidget::windowFrameSectionAt(const QPointF &pos)
} else if (x >= right - cornerMargin) {
if (y <= top + windowFrameWidth || (x >= right - windowFrameWidth && y <= top + cornerMargin)) {
s = Qt::TopRightSection;
} else if (y >= bottom - windowFrameWidth || (x >= right - windowFrameWidth && y >= bottom - windowFrameWidth)) {
} else if (y >= bottom - windowFrameWidth || (x >= right - windowFrameWidth && y >= bottom - cornerMargin)) {
s = Qt::BottomRightSection;
} else if (x >= right - windowFrameWidth) {
s = Qt::RightSection;

View File

@ -171,6 +171,7 @@ private slots:
void fontPropagatesResolveViaNonWidget();
void fontPropagatesResolveFromScene();
void tabFocus();
void windowFrameSectionAt();
// Task fixes
void task236127_bspTreeIndexFails();
@ -243,6 +244,9 @@ public:
void call_updateGeometry()
{ return QGraphicsWidget::updateGeometry(); }
Qt::WindowFrameSection call_windowFrameSectionAt(const QPointF &pos) const
{ return QGraphicsWidget::windowFrameSectionAt(pos); }
int eventCount;
Qt::LayoutDirection m_painterLayoutDirection;
@ -3411,6 +3415,31 @@ void tst_QGraphicsWidget::tabFocus()
delete widget6;
}
void tst_QGraphicsWidget::windowFrameSectionAt()
{
SubQGraphicsWidget widget;
widget.setWindowFrameMargins(5, 5, 5, 5);
widget.setGeometry(0, 0, 200, 200);
QCOMPARE(widget.call_windowFrameSectionAt(QPointF(50, 50)), Qt::NoSection);
QCOMPARE(widget.call_windowFrameSectionAt(QPointF(-2, -2)), Qt::TopLeftSection);
QCOMPARE(widget.call_windowFrameSectionAt(QPointF(-2, 10)), Qt::TopLeftSection);
QCOMPARE(widget.call_windowFrameSectionAt(QPointF(-2, 30)), Qt::LeftSection);
QCOMPARE(widget.call_windowFrameSectionAt(QPointF(-2, 170)), Qt::LeftSection);
QCOMPARE(widget.call_windowFrameSectionAt(QPointF(-2, 198)), Qt::BottomLeftSection);
QCOMPARE(widget.call_windowFrameSectionAt(QPointF(-2, 202)), Qt::BottomLeftSection);
QCOMPARE(widget.call_windowFrameSectionAt(QPointF(202, -2)), Qt::TopRightSection);
QCOMPARE(widget.call_windowFrameSectionAt(QPointF(202, 10)), Qt::TopRightSection);
QCOMPARE(widget.call_windowFrameSectionAt(QPointF(202, 30)), Qt::RightSection);
QCOMPARE(widget.call_windowFrameSectionAt(QPointF(202, 170)), Qt::RightSection);
QCOMPARE(widget.call_windowFrameSectionAt(QPointF(202, 198)), Qt::BottomRightSection);
QCOMPARE(widget.call_windowFrameSectionAt(QPointF(202, 202)), Qt::BottomRightSection);
QCOMPARE(widget.call_windowFrameSectionAt(QPointF(50, -2)), Qt::TopSection);
QCOMPARE(widget.call_windowFrameSectionAt(QPointF(50, 202)), Qt::BottomSection);
}
void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems()
{
QGraphicsScene scene;