diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2009-03-23 09:18:55 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-03-23 09:18:55 (GMT) |
commit | e5fcad302d86d316390c6b0f62759a067313e8a9 (patch) | |
tree | c2afbf6f1066b6ce261f14341cf6d310e5595bc1 /tests/auto/qtextscriptengine/generate | |
download | Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.zip Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.gz Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.bz2 |
Long live Qt 4.5!
Diffstat (limited to 'tests/auto/qtextscriptengine/generate')
-rw-r--r-- | tests/auto/qtextscriptengine/generate/generate.pro | 13 | ||||
-rw-r--r-- | tests/auto/qtextscriptengine/generate/main.cpp | 129 |
2 files changed, 142 insertions, 0 deletions
diff --git a/tests/auto/qtextscriptengine/generate/generate.pro b/tests/auto/qtextscriptengine/generate/generate.pro new file mode 100644 index 0000000..355633d --- /dev/null +++ b/tests/auto/qtextscriptengine/generate/generate.pro @@ -0,0 +1,13 @@ +###################################################################### +# Automatically generated by qmake (1.07a) Fri Sep 30 15:20:45 2005 +###################################################################### + +TEMPLATE = app +CONFIG -= moc +INCLUDEPATH += . /usr/include/freetype2 + +# Input +SOURCES += main.cpp +CONFIG += qt warn_on debug thread create_prl link_prl + + diff --git a/tests/auto/qtextscriptengine/generate/main.cpp b/tests/auto/qtextscriptengine/generate/main.cpp new file mode 100644 index 0000000..d3ef67b --- /dev/null +++ b/tests/auto/qtextscriptengine/generate/main.cpp @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtTest/QtTest> +#include <QTextEdit> +#include <QLineEdit> +#include <QVBoxLayout> +#include <QFontDialog> +#include <QPushButton> + +#define private public +#include <qfont.h> +#include <private/qtextengine_p.h> +#include <private/qfontengine_p.h> +#include <qtextlayout.h> +#undef private + + +class MyEdit : public QTextEdit { + Q_OBJECT +public: + MyEdit(QWidget *p) : QTextEdit(p) { setReadOnly(true); } +public slots: + void setText(const QString &str); + void changeFont(); +public: + QLineEdit *lineEdit; +}; + +void MyEdit::setText(const QString &str) +{ + if (str.isEmpty()) { + clear(); + return; + } + QTextLayout layout(str, lineEdit->font()); + QTextEngine *e = layout.d; + e->itemize(); + e->shape(0); + + QString result; + result = "Using font '" + e->fontEngine(e->layoutData->items[0])->fontDef.family + "'\n\n"; + + result += "{ { "; + for (int i = 0; i < str.length(); ++i) + result += "0x" + QString::number(str.at(i).unicode(), 16) + ", "; + result += "0x0 },\n { "; + for (int i = 0; i < e->layoutData->items[0].num_glyphs; ++i) + result += "0x" + QString::number(e->layoutData->glyphPtr[i].glyph, 16) + ", "; + result += "0x0 } }"; + + setPlainText(result); +} + +void MyEdit::changeFont() +{ + bool ok; + QFont f = QFontDialog::getFont(&ok, lineEdit->font(), topLevelWidget()); + if (ok) + lineEdit->setFont(f); +} + +int main(int argc, char **argv) +{ + QApplication a(argc, argv); + + QWidget *mw = new QWidget(0); + QVBoxLayout *l = new QVBoxLayout(mw); + + QLineEdit *le = new QLineEdit(mw); + l->addWidget(le); + + MyEdit *view = new MyEdit(mw); + view->lineEdit = le; + l->addWidget(view); + + QPushButton *button = new QPushButton("Change Font", mw); + l->addWidget(button); + + QObject::connect(le, SIGNAL(textChanged(QString)), view, SLOT(setText(QString))); + QObject::connect(button, SIGNAL(clicked()), view, SLOT(changeFont())); + + mw->resize(500, 300); + mw->show(); + + return a.exec(); +} + + +#include <main.moc> |