From caa024e76818ae543897c2f2890cd70212bae23a Mon Sep 17 00:00:00 2001 From: Benjamin Poulain Date: Tue, 25 Aug 2009 14:16:31 +0200 Subject: Fix subControlRect of the Mac style for the QComboBox The subControlRect of the arrow and the listBoxPopup where assuming the widget rect is at the origin. Reviewed-by: Richard Moe Gustavsen Reviewed-by: Pierre Rossi --- tests/auto/qcombobox/tst_qcombobox.cpp | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'tests/auto/qcombobox/tst_qcombobox.cpp') diff --git a/tests/auto/qcombobox/tst_qcombobox.cpp b/tests/auto/qcombobox/tst_qcombobox.cpp index 204a2fa956..52c6c02708 100644 --- a/tests/auto/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/qcombobox/tst_qcombobox.cpp @@ -145,6 +145,8 @@ private slots: void setItemDelegate(); void task253944_itemDelegateIsReset(); void paintingWithOffset(); + void subControlRectsWithOffset_data(); + void subControlRectsWithOffset(); protected slots: void onEditTextChanged( const QString &newString ); @@ -2276,5 +2278,53 @@ void tst_QComboBox::paintingWithOffset() QCOMPARE(noOffsetImage, translatedOffsetImage); } +void tst_QComboBox::subControlRectsWithOffset_data() +{ + QTest::addColumn("editable"); + + QTest::newRow("editable = true") << true; + QTest::newRow("editable = false") << false; +} + +void tst_QComboBox::subControlRectsWithOffset() +{ + // The sub control rect relative position should not depends + // on the position of the combobox + + class FriendlyCombo : public QComboBox { + public: + void styleOption(QStyleOptionComboBox *optCombo) { + initStyleOption(optCombo); + } + } combo; + QStyleOptionComboBox optCombo; + combo.styleOption(&optCombo); + + + const QRect rectAtOrigin(0, 0, 80, 30); + const QPoint offset(25, 50); + const QRect rectWithOffset = rectAtOrigin.translated(offset); + + QStyle *style = combo.style(); + + QFETCH(bool, editable); + optCombo.editable = editable; + + optCombo.rect = rectAtOrigin; + QRect editFieldRect = style->subControlRect(QStyle::CC_ComboBox, &optCombo, QStyle::SC_ComboBoxEditField, 0); + QRect arrowRect = style->subControlRect(QStyle::CC_ComboBox, &optCombo, QStyle::SC_ComboBoxArrow, 0); + QRect listboxRect = style->subControlRect(QStyle::CC_ComboBox, &optCombo, QStyle::SC_ComboBoxListBoxPopup, 0); + + optCombo.rect = rectWithOffset; + QRect editFieldRectWithOffset = style->subControlRect(QStyle::CC_ComboBox, &optCombo, QStyle::SC_ComboBoxEditField, 0); + QRect arrowRectWithOffset = style->subControlRect(QStyle::CC_ComboBox, &optCombo, QStyle::SC_ComboBoxArrow, 0); + QRect listboxRectWithOffset = style->subControlRect(QStyle::CC_ComboBox, &optCombo, QStyle::SC_ComboBoxListBoxPopup, 0); + + QCOMPARE(editFieldRect, editFieldRectWithOffset.translated(-offset)); + QCOMPARE(arrowRect, arrowRectWithOffset.translated(-offset)); + QCOMPARE(listboxRect, listboxRectWithOffset.translated(-offset)); + +} + QTEST_MAIN(tst_QComboBox) #include "tst_qcombobox.moc" -- cgit v1.2.1