Skip to content

Commit

Permalink
Introducing QtFonts sample application.
Browse files Browse the repository at this point in the history
  • Loading branch information
BGmot committed Nov 20, 2012
1 parent 08d376b commit 8d73a18
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 0 deletions.
45 changes: 45 additions & 0 deletions 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.

105 changes: 105 additions & 0 deletions QtFonts/bar-descriptor.xml
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<qnx xmlns="http://www.qnx.com/schemas/application/1.0">

<!-- BlackBerry® 10 application descriptor file.
Specifies parameters for identifying, installing, and launching native applications on BlackBerry® 10 OS.
-->

<!-- A universally unique application identifier. Must be unique across all BlackBerry applications.
Using a reverse DNS-style name as the id is recommended. (Eg. com.example.ExampleApplication.) Required. -->
<id>com.BGmot.AvailableFonts</id>

<!-- The name that is displayed in the BlackBerry application installer.
May have multiple values for each language. See samples or xsd schema file. Optional. -->
<name>AvailableFonts</name>

<!-- A string value of the format <0-999>.<0-999>.<0-999> that represents application version which can be used to check for application upgrade.
Values can also be 1-part or 2-part. It is not necessary to have a 3-part value.
An updated version of application must have a versionNumber value higher than the previous version. Required. -->
<versionNumber>0.0.0</versionNumber>

<!-- Fourth digit segment of the package version. First three segments are taken from the
<versionNumber> element. Must be an integer from 0 to 2^16-1 -->
<buildId>101</buildId>

<!-- Description, displayed in the BlackBerry application installer.
May have multiple values for each language. See samples or xsd schema file. Optional. -->
<description>The AvailableFonts application</description>

<!-- Name of author which is used for signing. Must match the developer name of your development certificate. -->
<author>BGmot Inc.</author>
<platformVersion>10.0.9.386</platformVersion>

<!-- Unique author ID assigned by signing authority. Required if using debug tokens. -->
<!-- <authorId>ABC1234YjsnUk235h</authorId> -->

<initialWindow>
<aspectRatio>portrait</aspectRatio>
<autoOrients>false</autoOrients>
<systemChrome>none</systemChrome>
<transparent>false</transparent>
</initialWindow>

<!-- The category where the application appears. Either core.games or core.media. -->
<category>core.games</category>
<asset path="qtfonts.png">qtfonts.png</asset>
<configuration id="com.qnx.qcc.configuration.exe.debug.1407455284" name="Device-Debug">
<platformArchitecture>armle-v7</platformArchitecture>
<asset path="Device-Debug/QtFonts" entry="true" type="Qnx/Elf">QtFonts</asset>
</configuration>
<configuration id="com.qnx.qcc.configuration.exe.release.835361476" name="Device-Release">
<platformArchitecture>armle-v7</platformArchitecture>
<asset path="Device-Release/QtFonts" entry="true" type="Qnx/Elf">QtFonts</asset>
</configuration>
<configuration id="com.qnx.qcc.configuration.exe.profile.687864542" name="Device-Profile">
<platformArchitecture>armle-v7</platformArchitecture>
<asset path="Device-Profile/QtFonts" entry="true" type="Qnx/Elf">QtFonts</asset>
</configuration>
<configuration id="com.qnx.qcc.configuration.exe.profile.coverage.1812228769" name="Device-Coverage">
<platformArchitecture>armle-v7</platformArchitecture>
<asset path="Device-Coverage/QtFonts" entry="true" type="Qnx/Elf">QtFonts</asset>
</configuration>
<configuration id="com.qnx.qcc.configuration.exe.debug.1574122806" name="Simulator-Debug">
<platformArchitecture>x86</platformArchitecture>
<asset path="Simulator-Debug/QtFonts" entry="true" type="Qnx/Elf">QtFonts</asset>
</configuration>
<configuration id="com.qnx.qcc.configuration.exe.profile.423749433" name="Simulator-Profile">
<platformArchitecture>x86</platformArchitecture>
<asset path="Simulator-Profile/QtFonts" entry="true" type="Qnx/Elf">QtFonts</asset>
</configuration>
<configuration id="com.qnx.qcc.configuration.exe.profile.coverage.1654983009" name="Simulator-Coverage">
<platformArchitecture>x86</platformArchitecture>
<asset path="Simulator-Coverage/QtFonts" entry="true" type="Qnx/Elf">QtFonts</asset>
</configuration>

<!-- The icon for the application, which should be 86x86. -->
<icon>
<image></image>
<image>qtfonts.png</image>
</icon>

<!-- The splash screen that will appear when your application is launching. Should be 1024x600. -->
<!-- <splashscreen></splashscreen> -->

<!-- Request permission to execute native code. Required for native applications. -->
<permission system="true">run_native</permission>

<!-- The permissions requested by your application. -->
<!-- <permission>access_shared</permission> -->
<!-- <permission>record_audio</permission> -->
<!-- <permission>read_geolocation</permission> -->
<!-- <permission>use_camera</permission> -->
<!-- <permission>access_internet</permission> -->
<!-- <permission>play_audio</permission> -->
<!-- <permission>post_notification</permission> -->
<!-- <permission>set_audio_volume</permission> -->
<!-- <permission>read_device_identifying_information</permission> -->
<!-- <permission>access_led_control</permission> -->
<!-- <action>run_when_backgrounded</action> -->


<!-- Ensure that shared libraries in the package are found at run-time. -->
<env var="LD_LIBRARY_PATH" value="/usr/lib/qt4/lib"/>

</qnx>
Binary file added QtFonts/qtfonts.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 changes: 118 additions & 0 deletions QtFonts/src/main.cpp
@@ -0,0 +1,118 @@
/*
* Copyright (c) 2012 by BGmot <ey@tm-k.com>
*
* 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 <QtCore>
#include <QtGui>
#include <QtGui/QApplication>
#include <QFontDatabase>
#include <QTreeWidget>
#include <QPushButton>
#include <QFont>
#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(&centralWidget);

// Create Fonts Tree Widget
QTreeWidget fontTree(&centralWidget);
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<int> 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(&centralWidget);
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;
}
93 changes: 93 additions & 0 deletions 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 <QObject>."
#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<QMyEdit *>(_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<void*>(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
14 changes: 14 additions & 0 deletions QtFonts/src/myedit.h
@@ -0,0 +1,14 @@
#ifndef MYEDIT_H
#define MYEDIT_H
#include <QtGui>
#include <QObject>
class QMyEdit : public QTextEdit{
Q_OBJECT

public:
QMyEdit(QWidget *w);

public slots:
void setNewFont(QTreeWidgetItem*, QTreeWidgetItem*);
};
#endif

0 comments on commit 8d73a18

Please sign in to comment.