|
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 <qapplication.h> |
|
45 #include <qfontinfo.h> |
|
46 |
|
47 |
|
48 #include <qpushbutton.h> |
|
49 #include <qscrollbar.h> |
|
50 #include <qtimer.h> |
|
51 |
|
52 #include <qdialog.h> |
|
53 |
|
54 |
|
55 //TESTED_CLASS= |
|
56 //TESTED_FILES=gui/widgets/qmenubar.h gui/widgets/qmenubar.cpp |
|
57 |
|
58 class TstWidget; |
|
59 class TstDialog; |
|
60 QT_FORWARD_DECLARE_CLASS(QPushButton) |
|
61 |
|
62 class tst_qmouseevent_modal : public QObject |
|
63 { |
|
64 Q_OBJECT |
|
65 |
|
66 public: |
|
67 tst_qmouseevent_modal(); |
|
68 virtual ~tst_qmouseevent_modal(); |
|
69 |
|
70 |
|
71 public slots: |
|
72 void initTestCase(); |
|
73 void cleanupTestCase(); |
|
74 void init(); |
|
75 void cleanup(); |
|
76 private slots: |
|
77 void mousePressRelease(); |
|
78 |
|
79 private: |
|
80 TstWidget *w; |
|
81 }; |
|
82 |
|
83 class TstWidget : public QWidget |
|
84 { |
|
85 Q_OBJECT |
|
86 public: |
|
87 TstWidget(); |
|
88 public slots: |
|
89 void buttonPressed(); |
|
90 public: |
|
91 QPushButton *pb; |
|
92 TstDialog *d; |
|
93 }; |
|
94 |
|
95 |
|
96 class TstDialog : public QDialog |
|
97 { |
|
98 Q_OBJECT |
|
99 public: |
|
100 TstDialog( QWidget *mouseWidget, QWidget *parent, const char *name ); |
|
101 int count() { return c; } |
|
102 protected: |
|
103 void showEvent ( QShowEvent * ); |
|
104 public slots: |
|
105 void releaseMouse(); |
|
106 void closeDialog(); |
|
107 private: |
|
108 QWidget *m; |
|
109 int c; |
|
110 }; |
|
111 |
|
112 tst_qmouseevent_modal::tst_qmouseevent_modal() |
|
113 { |
|
114 } |
|
115 |
|
116 tst_qmouseevent_modal::~tst_qmouseevent_modal() |
|
117 { |
|
118 } |
|
119 |
|
120 void tst_qmouseevent_modal::initTestCase() |
|
121 { |
|
122 w = new TstWidget; |
|
123 w->show(); |
|
124 } |
|
125 |
|
126 void tst_qmouseevent_modal::cleanupTestCase() |
|
127 { |
|
128 delete w; |
|
129 w = 0; |
|
130 } |
|
131 |
|
132 void tst_qmouseevent_modal::init() |
|
133 { |
|
134 } |
|
135 |
|
136 void tst_qmouseevent_modal::cleanup() |
|
137 { |
|
138 } |
|
139 |
|
140 /* |
|
141 Test for task 22500 |
|
142 */ |
|
143 void tst_qmouseevent_modal::mousePressRelease() |
|
144 { |
|
145 |
|
146 QVERIFY( !w->d->isVisible() ); |
|
147 QVERIFY( w->d->count() == 0 ); |
|
148 |
|
149 QTest::mousePress( w->pb, Qt::LeftButton ); |
|
150 |
|
151 QVERIFY( !w->d->isVisible() ); |
|
152 QVERIFY( w->d->count() == 1 ); |
|
153 QVERIFY( !w->pb->isDown() ); |
|
154 |
|
155 QTest::mousePress( w->pb, Qt::LeftButton ); |
|
156 |
|
157 QVERIFY( !w->d->isVisible() ); |
|
158 QVERIFY( w->d->count() == 2 ); |
|
159 QVERIFY( !w->pb->isDown() ); |
|
160 |
|
161 // With the current QWS mouse handling, the 3rd press would fail... |
|
162 |
|
163 QTest::mousePress( w->pb, Qt::LeftButton ); |
|
164 |
|
165 QVERIFY( !w->d->isVisible() ); |
|
166 QVERIFY( w->d->count() == 3 ); |
|
167 QVERIFY( !w->pb->isDown() ); |
|
168 |
|
169 QTest::mousePress( w->pb, Qt::LeftButton ); |
|
170 |
|
171 QVERIFY( !w->d->isVisible() ); |
|
172 QVERIFY( w->d->count() == 4 ); |
|
173 QVERIFY( !w->pb->isDown() ); |
|
174 } |
|
175 |
|
176 |
|
177 TstWidget::TstWidget() |
|
178 { |
|
179 pb = new QPushButton( "Press me", this ); |
|
180 pb->setObjectName("testbutton"); |
|
181 QSize s = pb->sizeHint(); |
|
182 pb->setGeometry( 5, 5, s.width(), s.height() ); |
|
183 |
|
184 connect( pb, SIGNAL(pressed()), this, SLOT(buttonPressed()) ); |
|
185 |
|
186 // QScrollBar *sb = new QScrollBar( Qt::Horizontal, this ); |
|
187 |
|
188 // sb->setGeometry( 5, pb->geometry().bottom() + 5, 100, sb->sizeHint().height() ); |
|
189 |
|
190 d = new TstDialog( pb, this , 0 ); |
|
191 } |
|
192 |
|
193 void TstWidget::buttonPressed() |
|
194 { |
|
195 d->exec(); |
|
196 } |
|
197 |
|
198 TstDialog::TstDialog( QWidget *mouseWidget, QWidget *parent, const char *name ) |
|
199 :QDialog( parent ) |
|
200 { |
|
201 setObjectName(name); |
|
202 setModal(true); |
|
203 m = mouseWidget; |
|
204 c = 0; |
|
205 } |
|
206 |
|
207 void TstDialog::showEvent ( QShowEvent * ) |
|
208 { |
|
209 QTimer::singleShot(1, this, SLOT(releaseMouse())); |
|
210 QTimer::singleShot(100, this, SLOT(closeDialog())); |
|
211 } |
|
212 |
|
213 void TstDialog::releaseMouse() |
|
214 { |
|
215 QTest::mouseRelease(m, Qt::LeftButton); |
|
216 } |
|
217 |
|
218 void TstDialog::closeDialog() |
|
219 { |
|
220 if ( isVisible() ) { |
|
221 c++; |
|
222 accept(); |
|
223 } |
|
224 } |
|
225 |
|
226 QTEST_MAIN(tst_qmouseevent_modal) |
|
227 #include "tst_qmouseevent_modal.moc" |