0
|
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 <qtooltip.h>
|
|
45 |
#include "../../shared/util.h"
|
|
46 |
|
|
47 |
//TESTED_CLASS=
|
|
48 |
//TESTED_FILES=
|
|
49 |
|
|
50 |
class tst_QToolTip : public QObject
|
|
51 |
{
|
|
52 |
Q_OBJECT
|
|
53 |
|
|
54 |
public:
|
|
55 |
tst_QToolTip() {}
|
|
56 |
virtual ~tst_QToolTip() {}
|
|
57 |
|
|
58 |
public slots:
|
|
59 |
void initTestCase() {}
|
|
60 |
void cleanupTestCase() {}
|
|
61 |
void init() {}
|
|
62 |
void cleanup() {}
|
|
63 |
|
|
64 |
private slots:
|
|
65 |
|
|
66 |
// task-specific tests below me
|
|
67 |
void task183679_data();
|
|
68 |
void task183679();
|
|
69 |
void whatsThis();
|
|
70 |
void setPalette();
|
|
71 |
};
|
|
72 |
|
|
73 |
class Widget_task183679 : public QWidget
|
|
74 |
{
|
|
75 |
Q_OBJECT
|
|
76 |
public:
|
|
77 |
Widget_task183679(QWidget *parent = 0) : QWidget(parent) {}
|
|
78 |
|
|
79 |
void showDelayedToolTip(int msecs)
|
|
80 |
{
|
|
81 |
QTimer::singleShot(msecs, this, SLOT(showToolTip()));
|
|
82 |
}
|
|
83 |
|
|
84 |
private slots:
|
|
85 |
void showToolTip()
|
|
86 |
{
|
|
87 |
QToolTip::showText(mapToGlobal(QPoint(0, 0)), "tool tip text", this);
|
|
88 |
}
|
|
89 |
};
|
|
90 |
|
|
91 |
Q_DECLARE_METATYPE(Qt::Key)
|
|
92 |
|
|
93 |
void tst_QToolTip::task183679_data()
|
|
94 |
{
|
|
95 |
QTest::addColumn<Qt::Key>("key");
|
|
96 |
QTest::addColumn<bool>("visible");
|
|
97 |
#ifdef Q_WS_MAC
|
|
98 |
const bool visibleAfterNonModifier = false;
|
|
99 |
#else
|
|
100 |
const bool visibleAfterNonModifier = true;
|
|
101 |
#endif
|
|
102 |
QTest::newRow("non-modifier") << Qt::Key_A << visibleAfterNonModifier;
|
|
103 |
QTest::newRow("Shift") << Qt::Key_Shift << true;
|
|
104 |
QTest::newRow("Control") << Qt::Key_Control << true;
|
|
105 |
QTest::newRow("Alt") << Qt::Key_Alt << true;
|
|
106 |
QTest::newRow("Meta") << Qt::Key_Meta << true;
|
|
107 |
}
|
|
108 |
|
|
109 |
void tst_QToolTip::task183679()
|
|
110 |
{
|
|
111 |
QFETCH(Qt::Key, key);
|
|
112 |
QFETCH(bool, visible);
|
|
113 |
|
|
114 |
Widget_task183679 widget;
|
|
115 |
widget.show();
|
|
116 |
QApplication::setActiveWindow(&widget);
|
|
117 |
QTest::qWaitForWindowShown(&widget);
|
|
118 |
QTest::qWait(30);
|
|
119 |
|
|
120 |
|
|
121 |
widget.showDelayedToolTip(100);
|
|
122 |
QTest::qWait(300);
|
|
123 |
QTRY_VERIFY(QToolTip::isVisible());
|
|
124 |
|
|
125 |
QTest::keyPress(&widget, key);
|
|
126 |
|
|
127 |
// Important: the following delay must be larger than the duration of the timer potentially
|
|
128 |
// initiated by the key press (currently 300 msecs), but smaller than the minimum
|
|
129 |
// auto-close timeout (currently 10000 msecs)
|
|
130 |
QTest::qWait(1500);
|
|
131 |
|
|
132 |
QCOMPARE(QToolTip::isVisible(), visible);
|
|
133 |
}
|
|
134 |
|
|
135 |
#include <QWhatsThis>
|
|
136 |
|
|
137 |
void tst_QToolTip::whatsThis()
|
|
138 |
{
|
|
139 |
qApp->setStyleSheet( "QWidget { font-size: 72px; }" );
|
|
140 |
QWhatsThis::showText(QPoint(0,0), "THis is text");
|
|
141 |
QTest::qWait(400);
|
|
142 |
QWidget *whatsthis = 0;
|
|
143 |
foreach (QWidget *widget, QApplication::topLevelWidgets()) {
|
|
144 |
if (widget->inherits("QWhatsThat")) {
|
|
145 |
whatsthis = widget;
|
|
146 |
break;
|
|
147 |
}
|
|
148 |
}
|
|
149 |
QVERIFY(whatsthis);
|
|
150 |
QVERIFY(whatsthis->isVisible());
|
|
151 |
QVERIFY(whatsthis->height() > 100); // Test QTBUG-2416
|
|
152 |
qApp->setStyleSheet("");
|
|
153 |
}
|
|
154 |
|
|
155 |
|
|
156 |
void tst_QToolTip::setPalette()
|
|
157 |
{
|
|
158 |
//the previous test may still have a tooltip pending for deletion
|
|
159 |
QVERIFY(!QToolTip::isVisible());
|
|
160 |
|
|
161 |
QToolTip::showText(QPoint(), "tool tip text", 0);
|
|
162 |
|
|
163 |
QTRY_VERIFY(QToolTip::isVisible());
|
|
164 |
|
|
165 |
QWidget *toolTip = 0;
|
|
166 |
foreach (QWidget *widget, QApplication::topLevelWidgets()) {
|
|
167 |
if (widget->windowType() == Qt::ToolTip
|
|
168 |
&& widget->objectName() == QLatin1String("qtooltip_label"))
|
|
169 |
{
|
|
170 |
toolTip = widget;
|
|
171 |
break;
|
|
172 |
}
|
|
173 |
}
|
|
174 |
|
|
175 |
QVERIFY(toolTip);
|
|
176 |
QTRY_VERIFY(toolTip->isVisible());
|
|
177 |
|
|
178 |
const QPalette oldPalette = toolTip->palette();
|
|
179 |
QPalette newPalette = oldPalette;
|
|
180 |
newPalette.setColor(QPalette::ToolTipBase, Qt::red);
|
|
181 |
newPalette.setColor(QPalette::ToolTipText, Qt::blue);
|
|
182 |
QToolTip::setPalette(newPalette);
|
|
183 |
QCOMPARE(toolTip->palette(), newPalette);
|
|
184 |
}
|
|
185 |
|
|
186 |
QTEST_MAIN(tst_QToolTip)
|
|
187 |
#include "tst_qtooltip.moc"
|