|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 |
|
43 #include <QtTest/QtTest> |
|
44 #include <QSizeGrip> |
|
45 #include <QEvent> |
|
46 #include <QLineEdit> |
|
47 #include <QVBoxLayout> |
|
48 #include <QLabel> |
|
49 |
|
50 static inline Qt::Corner sizeGripCorner(QWidget *parent, QSizeGrip *sizeGrip) |
|
51 { |
|
52 if (!parent || !sizeGrip) |
|
53 return Qt::TopLeftCorner; |
|
54 |
|
55 const QPoint sizeGripPos = sizeGrip->mapTo(parent, QPoint(0, 0)); |
|
56 bool isAtBottom = sizeGripPos.y() >= parent->height() / 2; |
|
57 bool isAtLeft = sizeGripPos.x() <= parent->width() / 2; |
|
58 if (isAtLeft) |
|
59 return isAtBottom ? Qt::BottomLeftCorner : Qt::TopLeftCorner; |
|
60 else |
|
61 return isAtBottom ? Qt::BottomRightCorner : Qt::TopRightCorner; |
|
62 |
|
63 } |
|
64 |
|
65 //TESTED_CLASS= |
|
66 //TESTED_FILES= |
|
67 |
|
68 Q_DECLARE_METATYPE(Qt::WindowType); |
|
69 |
|
70 class tst_QSizeGrip : public QObject |
|
71 { |
|
72 Q_OBJECT |
|
73 public slots: |
|
74 void initTestCase(); |
|
75 void cleanupTestCase(); |
|
76 |
|
77 private slots: |
|
78 void hideAndShowOnWindowStateChange_data(); |
|
79 void hideAndShowOnWindowStateChange(); |
|
80 void orientation(); |
|
81 |
|
82 private: |
|
83 QLineEdit *dummyWidget; |
|
84 }; |
|
85 |
|
86 class TestWidget : public QWidget |
|
87 { |
|
88 public: |
|
89 TestWidget(QWidget *parent = 0, Qt::WindowFlags flags = 0) : QWidget(parent, flags) {} |
|
90 QSize sizeHint() const { return QSize(300, 200); } |
|
91 void changeEvent(QEvent *event) |
|
92 { |
|
93 QWidget::changeEvent(event); |
|
94 if (isWindow() && event->type() == QEvent::WindowStateChange) { |
|
95 #ifdef Q_WS_X11 |
|
96 qt_x11_wait_for_window_manager(this); |
|
97 #endif |
|
98 } |
|
99 } |
|
100 }; |
|
101 |
|
102 void tst_QSizeGrip::initTestCase() |
|
103 { |
|
104 dummyWidget = new QLineEdit; |
|
105 dummyWidget->show(); |
|
106 } |
|
107 |
|
108 void tst_QSizeGrip::cleanupTestCase() |
|
109 { |
|
110 delete dummyWidget; |
|
111 dummyWidget = 0; |
|
112 } |
|
113 |
|
114 void tst_QSizeGrip::hideAndShowOnWindowStateChange_data() |
|
115 { |
|
116 QTest::addColumn<Qt::WindowType>("windowType"); |
|
117 QTest::newRow("Qt::Window") << Qt::Window; |
|
118 QTest::newRow("Qt::SubWindow") << Qt::SubWindow; |
|
119 } |
|
120 |
|
121 void tst_QSizeGrip::hideAndShowOnWindowStateChange() |
|
122 { |
|
123 QFETCH(Qt::WindowType, windowType); |
|
124 |
|
125 QWidget *parentWidget = windowType == Qt::Window ? 0 : new QWidget; |
|
126 TestWidget *widget = new TestWidget(parentWidget, Qt::WindowFlags(windowType)); |
|
127 QSizeGrip *sizeGrip = new QSizeGrip(widget); |
|
128 |
|
129 // Normal. |
|
130 if (parentWidget) |
|
131 parentWidget->show(); |
|
132 else |
|
133 widget->show(); |
|
134 QVERIFY(sizeGrip->isVisible()); |
|
135 |
|
136 widget->showFullScreen(); |
|
137 QVERIFY(!sizeGrip->isVisible()); |
|
138 |
|
139 widget->showNormal(); |
|
140 QVERIFY(sizeGrip->isVisible()); |
|
141 |
|
142 widget->showMaximized(); |
|
143 #ifndef Q_WS_MAC |
|
144 QVERIFY(!sizeGrip->isVisible()); |
|
145 #else |
|
146 QVERIFY(sizeGrip->isVisible()); |
|
147 #endif |
|
148 |
|
149 widget->showNormal(); |
|
150 QVERIFY(sizeGrip->isVisible()); |
|
151 |
|
152 sizeGrip->hide(); |
|
153 QVERIFY(!sizeGrip->isVisible()); |
|
154 |
|
155 widget->showFullScreen(); |
|
156 widget->showNormal(); |
|
157 QVERIFY(!sizeGrip->isVisible()); |
|
158 widget->showMaximized(); |
|
159 widget->showNormal(); |
|
160 QVERIFY(!sizeGrip->isVisible()); |
|
161 |
|
162 delete widget; |
|
163 delete parentWidget; |
|
164 } |
|
165 |
|
166 void tst_QSizeGrip::orientation() |
|
167 { |
|
168 TestWidget widget; |
|
169 widget.setLayout(new QVBoxLayout); |
|
170 QSizeGrip *sizeGrip = new QSizeGrip(&widget); |
|
171 sizeGrip->setFixedSize(sizeGrip->sizeHint()); |
|
172 widget.layout()->addWidget(sizeGrip); |
|
173 widget.layout()->setAlignment(sizeGrip, Qt::AlignBottom | Qt::AlignRight); |
|
174 |
|
175 widget.show(); |
|
176 QCOMPARE(sizeGripCorner(&widget, sizeGrip), Qt::BottomRightCorner); |
|
177 |
|
178 widget.setLayoutDirection(Qt::RightToLeft); |
|
179 qApp->processEvents(); |
|
180 QCOMPARE(sizeGripCorner(&widget, sizeGrip), Qt::BottomLeftCorner); |
|
181 |
|
182 widget.unsetLayoutDirection(); |
|
183 qApp->processEvents(); |
|
184 QCOMPARE(sizeGripCorner(&widget, sizeGrip), Qt::BottomRightCorner); |
|
185 |
|
186 widget.layout()->setAlignment(sizeGrip, Qt::AlignTop | Qt::AlignRight); |
|
187 qApp->processEvents(); |
|
188 QCOMPARE(sizeGripCorner(&widget, sizeGrip), Qt::TopRightCorner); |
|
189 |
|
190 widget.setLayoutDirection(Qt::RightToLeft); |
|
191 qApp->processEvents(); |
|
192 QCOMPARE(sizeGripCorner(&widget, sizeGrip), Qt::TopLeftCorner); |
|
193 |
|
194 widget.unsetLayoutDirection(); |
|
195 qApp->processEvents(); |
|
196 QCOMPARE(sizeGripCorner(&widget, sizeGrip), Qt::TopRightCorner); |
|
197 } |
|
198 |
|
199 QTEST_MAIN(tst_QSizeGrip) |
|
200 #include "tst_qsizegrip.moc" |
|
201 |