|
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 <QTextEdit> |
|
45 #include <QLineEdit> |
|
46 #include <QVBoxLayout> |
|
47 #include <QFontDialog> |
|
48 #include <QPushButton> |
|
49 |
|
50 #define private public |
|
51 #include <qfont.h> |
|
52 #include <private/qtextengine_p.h> |
|
53 #include <private/qfontengine_p.h> |
|
54 #include <qtextlayout.h> |
|
55 #undef private |
|
56 |
|
57 |
|
58 class MyEdit : public QTextEdit { |
|
59 Q_OBJECT |
|
60 public: |
|
61 MyEdit(QWidget *p) : QTextEdit(p) { setReadOnly(true); } |
|
62 public slots: |
|
63 void setText(const QString &str); |
|
64 void changeFont(); |
|
65 public: |
|
66 QLineEdit *lineEdit; |
|
67 }; |
|
68 |
|
69 void MyEdit::setText(const QString &str) |
|
70 { |
|
71 if (str.isEmpty()) { |
|
72 clear(); |
|
73 return; |
|
74 } |
|
75 QTextLayout layout(str, lineEdit->font()); |
|
76 QTextEngine *e = layout.d; |
|
77 e->itemize(); |
|
78 e->shape(0); |
|
79 |
|
80 QString result; |
|
81 result = "Using font '" + e->fontEngine(e->layoutData->items[0])->fontDef.family + "'\n\n"; |
|
82 |
|
83 result += "{ { "; |
|
84 for (int i = 0; i < str.length(); ++i) |
|
85 result += "0x" + QString::number(str.at(i).unicode(), 16) + ", "; |
|
86 result += "0x0 },\n { "; |
|
87 for (int i = 0; i < e->layoutData->items[0].num_glyphs; ++i) |
|
88 result += "0x" + QString::number(e->layoutData->glyphPtr[i].glyph, 16) + ", "; |
|
89 result += "0x0 } }"; |
|
90 |
|
91 setPlainText(result); |
|
92 } |
|
93 |
|
94 void MyEdit::changeFont() |
|
95 { |
|
96 bool ok; |
|
97 QFont f = QFontDialog::getFont(&ok, lineEdit->font(), topLevelWidget()); |
|
98 if (ok) |
|
99 lineEdit->setFont(f); |
|
100 } |
|
101 |
|
102 int main(int argc, char **argv) |
|
103 { |
|
104 QApplication a(argc, argv); |
|
105 |
|
106 QWidget *mw = new QWidget(0); |
|
107 QVBoxLayout *l = new QVBoxLayout(mw); |
|
108 |
|
109 QLineEdit *le = new QLineEdit(mw); |
|
110 l->addWidget(le); |
|
111 |
|
112 MyEdit *view = new MyEdit(mw); |
|
113 view->lineEdit = le; |
|
114 l->addWidget(view); |
|
115 |
|
116 QPushButton *button = new QPushButton("Change Font", mw); |
|
117 l->addWidget(button); |
|
118 |
|
119 QObject::connect(le, SIGNAL(textChanged(QString)), view, SLOT(setText(QString))); |
|
120 QObject::connect(button, SIGNAL(clicked()), view, SLOT(changeFont())); |
|
121 |
|
122 mw->resize(500, 300); |
|
123 mw->show(); |
|
124 |
|
125 return a.exec(); |
|
126 } |
|
127 |
|
128 |
|
129 #include <main.moc> |