diff options
author | Benjamin Poulain <benjamin.poulain@nokia.com> | 2009-08-14 08:04:36 (GMT) |
---|---|---|
committer | Benjamin Poulain <benjamin.poulain@nokia.com> | 2009-08-14 08:04:36 (GMT) |
commit | 0fd4ecf10bf57d56cd50f3bd6aeff5af381cef26 (patch) | |
tree | 5946b6811fba5ab0939c1ffc59ba9897de7be9c3 /tests/auto | |
parent | e58f3d36fba82f69debe5a37ab8e25eac1dddbcf (diff) | |
download | Qt-0fd4ecf10bf57d56cd50f3bd6aeff5af381cef26.zip Qt-0fd4ecf10bf57d56cd50f3bd6aeff5af381cef26.tar.gz Qt-0fd4ecf10bf57d56cd50f3bd6aeff5af381cef26.tar.bz2 |
Fix the painting of QComboBox on Mac when the rect is not at the origin
The style was assuming that the combo box is painted at (0,0). This is
not the case when the painting is done in the delegate of an item view.
The offset of the rect is now taken into account to paint the style.
HIRect has been replaced by QRect when it make sense.
Task-number: 00026815
Reviewed-by: Richard Moe Gustavsen
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qcombobox/tst_qcombobox.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/qcombobox/tst_qcombobox.cpp b/tests/auto/qcombobox/tst_qcombobox.cpp index b7a66af..204a2fa 100644 --- a/tests/auto/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/qcombobox/tst_qcombobox.cpp @@ -144,6 +144,7 @@ private slots: void noScrollbar(); void setItemDelegate(); void task253944_itemDelegateIsReset(); + void paintingWithOffset(); protected slots: void onEditTextChanged( const QString &newString ); @@ -2232,5 +2233,48 @@ void tst_QComboBox::task253944_itemDelegateIsReset() QCOMPARE(comboBox.itemDelegate(), itemDelegate); } +static void paintCombo(QImage *image, const QRect &rect) +{ + class FriendlyCombo : public QComboBox { + public: + void styleOption(QStyleOptionComboBox *optCombo) { + initStyleOption(optCombo); + } + } combo; + combo.setEditable(true); + + QStyleOptionComboBox optCombo; + combo.styleOption(&optCombo); + optCombo.rect = rect; + optCombo.palette.setCurrentColorGroup(QPalette::Active); + optCombo.state = QStyle::State_None; + + QPainter painter(image); + painter.fillRect(image->rect(), Qt::white); + QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &optCombo, &painter, 0); +} + +void tst_QComboBox::paintingWithOffset() +{ + // The painting of the combobox should not depend on its position in + // the widget. Some style are making the assumuption that the combobox + // start at 0,0 + const QSize comboSize(80, 30); + QImage noOffsetImage(comboSize, QImage::Format_ARGB32); + const QRect noOffsetRect(QPoint(0, 0), comboSize); + paintCombo(&noOffsetImage, noOffsetRect); + + QImage offsetImage(105, 80, QImage::Format_ARGB32); + const QRect offsetRect(QPoint(25, 50), comboSize); + paintCombo(&offsetImage, offsetRect); + + QImage translatedOffsetImage(comboSize, QImage::Format_ARGB32); + { + QPainter painter(&translatedOffsetImage); + painter.drawImage(noOffsetRect, offsetImage, offsetRect); + } + QCOMPARE(noOffsetImage, translatedOffsetImage); +} + QTEST_MAIN(tst_QComboBox) #include "tst_qcombobox.moc" |