diff --git a/QtFonts/README b/QtFonts/README new file mode 100644 index 0000000..3a421b3 --- /dev/null +++ b/QtFonts/README @@ -0,0 +1,45 @@ +QtFonts - browsing Fonts Database currently available on your device. + +======================================================================== +Sample Description: + + This simple Qt application just shows you all available to Qt fonts + in the system. It's nice to have it when you develop your application + that uses many fonts as it gives you exact fontFamily and fontStyle + names, also it lists all available sizesi showing how it looks on the + screen. + + Feature summary + - Basic Qt application initialization + - Retrieving information about fonts database + - Handling events of changing selection in QTreeWidget component + +======================================================================== +Requirements: + + - BlackBerry Native SDK for BlackBerry 10 version 10.0.9 or later + - BlackBerry BB10 Alpha device running BB10.0.9 or later + +======================================================================== +Importing a project into the Native SDK: + + 1. File->New->Blackberry Tablet OS C/C++ Project + 2. In 'Project name' field type in 'QtFonts'. Press Next. + 3. Select 'Language:' C, 'Build Style:' Managed, 'Project Type:' Empty Application. + Press 'Finish'. + 4. Right click on this Project's src folder in Project Explorer and choose Import... + 5. Choose 'File system' and navigate to files from this repository, select all of them. Hit Finish. + 6. Right click on this Project in Project Explorer and choose Properties. + 7. In 'Configuration:' choose preferable configuration Device-Release. + 8. Under C/C++ Build->Settings->QCC Compiler->Preprocessro add following folders in + 'Include Directories (-I)': + ${QNX_TARGET}/usr/include/qt4 + ${QNX_TARGET}/usr/include/qt4/Qt + ${QNX_TARGET}/usr/include/qt4/QtCore + ${QNX_TARGET}/usr/include/qt4/QtGui + 9. Under C/C++ Build->Settings->QCC Linker->Libraries add following folders in + 'Library Paths (-L)' section: ${QNX_TARGET}/${CPUVARDIR}/usr/lib/qt4/lib. + 10. Under C/C++ Build->Settings->QCC Linker->Libraries add following libraries in + 'Libraries (-l)' section: cpp, QtCore, QtGui. Click OK. + 11. Build and deploy. + diff --git a/QtFonts/bar-descriptor.xml b/QtFonts/bar-descriptor.xml new file mode 100644 index 0000000..dd65629 --- /dev/null +++ b/QtFonts/bar-descriptor.xml @@ -0,0 +1,105 @@ + + + + + + + com.BGmot.AvailableFonts + + + AvailableFonts + + + 0.0.0 + + + 101 + + + The AvailableFonts application + + + BGmot Inc. + 10.0.9.386 + + + + + + portrait + false + none + false + + + + core.games + qtfonts.png + + armle-v7 + QtFonts + + + armle-v7 + QtFonts + + + armle-v7 + QtFonts + + + armle-v7 + QtFonts + + + x86 + QtFonts + + + x86 + QtFonts + + + x86 + QtFonts + + + + + + qtfonts.png + + + + + + + run_native + + + + + + + + + + + + + + + + + + + diff --git a/QtFonts/qtfonts.png b/QtFonts/qtfonts.png new file mode 100644 index 0000000..d5e270e Binary files /dev/null and b/QtFonts/qtfonts.png differ diff --git a/QtFonts/src/main.cpp b/QtFonts/src/main.cpp new file mode 100644 index 0000000..4561edb --- /dev/null +++ b/QtFonts/src/main.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2012 by BGmot + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include +#include +#include "myedit.h" + +QMyEdit::QMyEdit(QWidget *w) : +QTextEdit(w) +{ + +} +void QMyEdit::setNewFont( QTreeWidgetItem * current, QTreeWidgetItem * previous){ + // User has changed selection in our font tree + // We want to show font sample only if a line with Font Size selected + QString fontSize = current->text(0); + QTreeWidgetItem *styleItem = current->parent(); + if (styleItem != NULL){ + QString fontStyle = styleItem->text(0); + QTreeWidgetItem *familyItem = styleItem->parent(); + + if (familyItem != NULL){ + QString fontFamily = familyItem->text(0); + bool ok; + QFont font((fontFamily), fontSize.toInt(&ok, 10)); + setText(fontFamily + QString(" ") + fontStyle + QString(" Size:") + fontSize); + + // Apply appropriate style to our text sample + if (fontStyle.contains("Italic",Qt::CaseInsensitive)) {font.setStyle(QFont::StyleItalic);} + if (fontStyle.contains("Normal",Qt::CaseInsensitive)) {font.setStyle(QFont::StyleNormal);} + if (fontStyle.contains("Oblique",Qt::CaseInsensitive)) {font.setStyle(QFont::StyleOblique);} + + if (fontStyle.contains("Bold",Qt::CaseInsensitive)) {font.setWeight(QFont::Bold);} + if (fontStyle.contains("Normal",Qt::CaseInsensitive)) {font.setWeight(QFont::Normal);} + if (fontStyle.contains("Light",Qt::CaseInsensitive)) {font.setWeight(QFont::Light);} + if (fontStyle.contains("DemiBold",Qt::CaseInsensitive)) {font.setWeight(QFont::DemiBold);} + if (fontStyle.contains("Black",Qt::CaseInsensitive)) {font.setWeight(QFont::Black);} + + setFont(font); + } + } +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QFontDatabase database; + + QMainWindow *mainWindow = new QMainWindow(); + QRect r = QApplication::desktop()->screenGeometry(0); + mainWindow->resize(r.width()+1, r.height()+1); + + QWidget centralWidget; + mainWindow->setCentralWidget(¢ralWidget); + + // Create Fonts Tree Widget + QTreeWidget fontTree(¢ralWidget); + fontTree.setColumnCount(1); + fontTree.setHeaderLabels(QStringList() << "Font"); + + QStringList families = database.families(); // Acquire all available font families + QString family; + QString style; + QString size; + for (int i=0; i < families.size();i++ ) { + family = families.at(i); + QTreeWidgetItem *familyItem = new QTreeWidgetItem(&fontTree); + familyItem->setText(0, family); + familyItem->setExpanded(true); + + QStringList styles = database.styles(family); // Acquire all available styles for given families + for (int j=0; j < styles.size(); j++){ + style = styles.at(j); + QTreeWidgetItem *styleItem = new QTreeWidgetItem(familyItem); + styleItem->setText(0, style); + styleItem->setExpanded(false); + + QList sizes = database.smoothSizes(family, style); // Acquire all available sizes for given family/style + for (int k=0; k < sizes.size(); k++ ){ + size =QString::number(sizes.at(k)); + QTreeWidgetItem *sizeItem = new QTreeWidgetItem(styleItem); + sizeItem->setText(0, size); + } + } + } + fontTree.setGeometry(10, 10, r.width()-20, r.height()-150); + + // Create a window where Font's samples will be shown + QMyEdit textEdit(¢ralWidget); + textEdit.setGeometry(10, r.height()-140, r.width()-20, 130); + textEdit.setText(QString("Select font")); + textEdit.setReadOnly(true); + + // React if selection changes + QObject::connect(&fontTree, SIGNAL(currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)), &textEdit, SLOT(setNewFont(QTreeWidgetItem*, QTreeWidgetItem*))); + + mainWindow->show(); + return app.exec(); + + return 0; +} diff --git a/QtFonts/src/moc_myedit.cpp b/QtFonts/src/moc_myedit.cpp new file mode 100644 index 0000000..ed0ae7e --- /dev/null +++ b/QtFonts/src/moc_myedit.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** Meta object code from reading C++ file 'myedit.h' +** +** Created: Sun Oct 7 21:44:21 2012 +** by: The Qt Meta Object Compiler version 63 (Qt 4.8.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "myedit.h" +#if !defined(Q_MOC_OUTPUT_REVISION) +#error "The header file 'myedit.h' doesn't include ." +#elif Q_MOC_OUTPUT_REVISION != 63 +#error "This file was generated using the moc from 4.8.3. It" +#error "cannot be used with the include files from this version of Qt." +#error "(The moc has changed too much.)" +#endif + +QT_BEGIN_MOC_NAMESPACE +static const uint qt_meta_data_QMyEdit[] = { + + // content: + 6, // revision + 0, // classname + 0, 0, // classinfo + 1, 14, // methods + 0, 0, // properties + 0, 0, // enums/sets + 0, 0, // constructors + 0, // flags + 0, // signalCount + + // slots: signature, parameters, type, tag, flags + 11, 9, 8, 8, 0x0a, + + 0 // eod +}; + +static const char qt_meta_stringdata_QMyEdit[] = { + "QMyEdit\0\0,\0setNewFont(QTreeWidgetItem*,QTreeWidgetItem*)\0" +}; + +void QMyEdit::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) +{ + if (_c == QMetaObject::InvokeMetaMethod) { + Q_ASSERT(staticMetaObject.cast(_o)); + QMyEdit *_t = static_cast(_o); + switch (_id) { + case 0: _t->setNewFont((*reinterpret_cast< QTreeWidgetItem*(*)>(_a[1])),(*reinterpret_cast< QTreeWidgetItem*(*)>(_a[2]))); break; + default: ; + } + } +} + +const QMetaObjectExtraData QMyEdit::staticMetaObjectExtraData = { + 0, qt_static_metacall +}; + +const QMetaObject QMyEdit::staticMetaObject = { + { &QTextEdit::staticMetaObject, qt_meta_stringdata_QMyEdit, + qt_meta_data_QMyEdit, &staticMetaObjectExtraData } +}; + +#ifdef Q_NO_DATA_RELOCATION +const QMetaObject &QMyEdit::getStaticMetaObject() { return staticMetaObject; } +#endif //Q_NO_DATA_RELOCATION + +const QMetaObject *QMyEdit::metaObject() const +{ + return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; +} + +void *QMyEdit::qt_metacast(const char *_clname) +{ + if (!_clname) return 0; + if (!strcmp(_clname, qt_meta_stringdata_QMyEdit)) + return static_cast(const_cast< QMyEdit*>(this)); + return QTextEdit::qt_metacast(_clname); +} + +int QMyEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a) +{ + _id = QTextEdit::qt_metacall(_c, _id, _a); + if (_id < 0) + return _id; + if (_c == QMetaObject::InvokeMetaMethod) { + if (_id < 1) + qt_static_metacall(this, _c, _id, _a); + _id -= 1; + } + return _id; +} +QT_END_MOC_NAMESPACE diff --git a/QtFonts/src/myedit.h b/QtFonts/src/myedit.h new file mode 100644 index 0000000..d62db24 --- /dev/null +++ b/QtFonts/src/myedit.h @@ -0,0 +1,14 @@ +#ifndef MYEDIT_H +#define MYEDIT_H +#include +#include +class QMyEdit : public QTextEdit{ + Q_OBJECT + +public: + QMyEdit(QWidget *w); + +public slots: + void setNewFont(QTreeWidgetItem*, QTreeWidgetItem*); +}; +#endif