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 |
|
|
45 |
|
|
46 |
#include <qapplication.h>
|
|
47 |
#include <qfontinfo.h>
|
|
48 |
#include <qtimer.h>
|
|
49 |
#include <qmainwindow.h>
|
|
50 |
#include <qlistview.h>
|
|
51 |
#include "qfontdialog.h"
|
|
52 |
#include <private/qfontdialog_p.h>
|
|
53 |
|
|
54 |
//TESTED_CLASS=
|
|
55 |
//TESTED_FILES=
|
|
56 |
|
|
57 |
QT_FORWARD_DECLARE_CLASS(QtTestEventThread)
|
|
58 |
|
|
59 |
class tst_QFontDialog : public QObject
|
|
60 |
{
|
|
61 |
Q_OBJECT
|
|
62 |
|
|
63 |
public:
|
|
64 |
tst_QFontDialog();
|
|
65 |
virtual ~tst_QFontDialog();
|
|
66 |
|
|
67 |
|
|
68 |
public slots:
|
|
69 |
void postKeyReturn();
|
|
70 |
|
|
71 |
public slots:
|
|
72 |
void initTestCase();
|
|
73 |
void cleanupTestCase();
|
|
74 |
void init();
|
|
75 |
void cleanup();
|
|
76 |
private slots:
|
|
77 |
void defaultOkButton();
|
|
78 |
void setFont();
|
|
79 |
void task256466_wrongStyle();
|
|
80 |
};
|
|
81 |
|
|
82 |
tst_QFontDialog::tst_QFontDialog()
|
|
83 |
{
|
|
84 |
}
|
|
85 |
|
|
86 |
tst_QFontDialog::~tst_QFontDialog()
|
|
87 |
{
|
|
88 |
}
|
|
89 |
|
|
90 |
void tst_QFontDialog::initTestCase()
|
|
91 |
{
|
|
92 |
}
|
|
93 |
|
|
94 |
void tst_QFontDialog::cleanupTestCase()
|
|
95 |
{
|
|
96 |
}
|
|
97 |
|
|
98 |
void tst_QFontDialog::init()
|
|
99 |
{
|
|
100 |
}
|
|
101 |
|
|
102 |
void tst_QFontDialog::cleanup()
|
|
103 |
{
|
|
104 |
}
|
|
105 |
|
|
106 |
|
|
107 |
void tst_QFontDialog::postKeyReturn() {
|
|
108 |
#ifndef Q_WS_MAC
|
|
109 |
QWidgetList list = QApplication::topLevelWidgets();
|
|
110 |
for (int i=0; i<list.count(); ++i) {
|
|
111 |
QFontDialog *dialog = qobject_cast<QFontDialog*>(list[i]);
|
|
112 |
if (dialog) {
|
|
113 |
QTest::keyClick( list[i], Qt::Key_Return, Qt::NoModifier );
|
|
114 |
return;
|
|
115 |
}
|
|
116 |
}
|
|
117 |
#else
|
|
118 |
extern void click_cocoa_button();
|
|
119 |
click_cocoa_button();
|
|
120 |
#endif
|
|
121 |
}
|
|
122 |
|
|
123 |
void tst_QFontDialog::defaultOkButton()
|
|
124 |
{
|
|
125 |
bool ok = FALSE;
|
|
126 |
QTimer::singleShot(2000, this, SLOT(postKeyReturn()));
|
|
127 |
QFontDialog::getFont(&ok);
|
|
128 |
QVERIFY(ok == TRUE);
|
|
129 |
}
|
|
130 |
|
|
131 |
|
|
132 |
void tst_QFontDialog::setFont()
|
|
133 |
{
|
|
134 |
/* The font should be the same before as it is after if nothing changed
|
|
135 |
while the font dialog was open.
|
|
136 |
Task #27662
|
|
137 |
*/
|
|
138 |
bool ok = FALSE;
|
|
139 |
#if defined Q_OS_HPUX
|
|
140 |
QString fontName = "Courier";
|
|
141 |
int fontSize = 25;
|
|
142 |
#elif defined Q_OS_AIX
|
|
143 |
QString fontName = "Charter";
|
|
144 |
int fontSize = 13;
|
|
145 |
#else
|
|
146 |
QString fontName = "Arial";
|
|
147 |
int fontSize = 24;
|
|
148 |
#endif
|
|
149 |
QFont f1(fontName, fontSize);
|
|
150 |
f1.setPixelSize(QFontInfo(f1).pixelSize());
|
|
151 |
QTimer::singleShot(2000, this, SLOT(postKeyReturn()));
|
|
152 |
QFont f2 = QFontDialog::getFont(&ok, f1);
|
|
153 |
QCOMPARE(QFontInfo(f2).pointSize(), QFontInfo(f1).pointSize());
|
|
154 |
}
|
|
155 |
|
|
156 |
|
|
157 |
class FriendlyFontDialog : public QFontDialog
|
|
158 |
{
|
|
159 |
friend class tst_QFontDialog;
|
|
160 |
Q_DECLARE_PRIVATE(QFontDialog);
|
|
161 |
};
|
|
162 |
|
|
163 |
void tst_QFontDialog::task256466_wrongStyle()
|
|
164 |
{
|
|
165 |
QFontDatabase fdb;
|
|
166 |
FriendlyFontDialog dialog;
|
|
167 |
QListView *familyList = reinterpret_cast<QListView*>(dialog.d_func()->familyList);
|
|
168 |
QListView *styleList = reinterpret_cast<QListView*>(dialog.d_func()->styleList);
|
|
169 |
QListView *sizeList = reinterpret_cast<QListView*>(dialog.d_func()->sizeList);
|
|
170 |
for (int i = 0; i < familyList->model()->rowCount(); ++i) {
|
|
171 |
QModelIndex currentFamily = familyList->model()->index(i, 0);
|
|
172 |
familyList->setCurrentIndex(currentFamily);
|
|
173 |
const QFont current = dialog.currentFont(),
|
|
174 |
expected = fdb.font(currentFamily.data().toString(),
|
|
175 |
styleList->currentIndex().data().toString(), sizeList->currentIndex().data().toInt());
|
|
176 |
QCOMPARE(current.family(), expected.family());
|
|
177 |
QCOMPARE(current.style(), expected.style());
|
|
178 |
QCOMPARE(current.pointSizeF(), expected.pointSizeF());
|
|
179 |
}
|
|
180 |
}
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
QTEST_MAIN(tst_QFontDialog)
|
|
186 |
#include "tst_qfontdialog.moc"
|