src/declarative/util/qdeclarativefontloader.cpp
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
child 37 758a864f9613
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
    77 
    77 
    78 
    78 
    79 /*!
    79 /*!
    80     \qmlclass FontLoader QDeclarativeFontLoader
    80     \qmlclass FontLoader QDeclarativeFontLoader
    81     \since 4.7
    81     \since 4.7
    82     \brief This item allows using fonts by name or url.
    82     \brief The FontLoader element allows fonts to be loaded by name or URL.
    83 
    83 
    84     Example:
    84     The FontLoader element is used to load fonts by name or URL. 
       
    85     
       
    86     The \l status indicates when the font has been loaded, which is useful 
       
    87     for fonts loaded from remote sources.
       
    88 
       
    89     For example:
    85     \qml
    90     \qml
    86     FontLoader { id: fixedFont; name: "Courier" }
    91     import Qt 4.7
    87     FontLoader { id: webFont; source: "http://www.mysite.com/myfont.ttf" }
    92 
    88 
    93     Column { 
    89     Text { text: "Fixed-size font"; font.family: fixedFont.name }
    94         FontLoader { id: fixedFont; name: "Courier" }
    90     Text { text: "Fancy font"; font.family: webFont.name }
    95         FontLoader { id: webFont; source: "http://www.mysite.com/myfont.ttf" }
    91     \endqml
    96 
       
    97         Text { text: "Fixed-size font"; font.family: fixedFont.name }
       
    98         Text { text: "Fancy font"; font.family: webFont.name }
       
    99     }
       
   100     \endqml
       
   101 
       
   102     \sa {declarative/text/fonts}{Fonts example}
    92 */
   103 */
    93 QDeclarativeFontLoader::QDeclarativeFontLoader(QObject *parent)
   104 QDeclarativeFontLoader::QDeclarativeFontLoader(QObject *parent)
    94     : QObject(*(new QDeclarativeFontLoaderPrivate), parent)
   105     : QObject(*(new QDeclarativeFontLoaderPrivate), parent)
    95 {
   106 {
    96 }
   107 }
   181     \o FontLoader.Ready - the font has been loaded
   192     \o FontLoader.Ready - the font has been loaded
   182     \o FontLoader.Loading - the font is currently being loaded
   193     \o FontLoader.Loading - the font is currently being loaded
   183     \o FontLoader.Error - an error occurred while loading the font
   194     \o FontLoader.Error - an error occurred while loading the font
   184     \endlist
   195     \endlist
   185 
   196 
   186     Note that a change in the status property does not cause anything to happen
   197     Use this status to provide an update or respond to the status change in some way.
   187     (although it reflects what has happened to the font loader internally). If you wish
   198     For example, you could:
   188     to react to the change in status you need to do it yourself, for example in one
   199 
   189     of the following ways:
   200     \e {Trigger a state change:}
   190     \list
   201     \qml 
   191     \o Create a state, so that a state change occurs, e.g. State{name: 'loaded'; when: loader.status = FontLoader.Ready;}
   202         State { name: 'loaded'; when: loader.status = FontLoader.Ready }
   192     \o Do something inside the onStatusChanged signal handler, e.g. FontLoader{id: loader; onStatusChanged: if(loader.status == FontLoader.Ready) console.log('Loaded');}
   203     \endqml
   193     \o Bind to the status variable somewhere, e.g. Text{text: if(loader.status!=FontLoader.Ready){'Not Loaded';}else{'Loaded';}}
   204 
   194     \endlist
   205     \e {Implement an \c onStatusChanged signal handler:}
       
   206     \qml 
       
   207         FontLoader {
       
   208             id: loader
       
   209             onStatusChanged: if (loader.status == FontLoader.Ready) console.log('Loaded')
       
   210         }
       
   211     \endqml
       
   212 
       
   213     \e {Bind to the status value:}
       
   214     \qml
       
   215         Text { text: loader.status != FontLoader.Ready ? 'Not Loaded' : 'Loaded' }
       
   216     \endqml
   195 */
   217 */
   196 QDeclarativeFontLoader::Status QDeclarativeFontLoader::status() const
   218 QDeclarativeFontLoader::Status QDeclarativeFontLoader::status() const
   197 {
   219 {
   198     Q_D(const QDeclarativeFontLoader);
   220     Q_D(const QDeclarativeFontLoader);
   199     return d->status;
   221     return d->status;