2021-09-11 20:43:03 +02:00
|
|
|
# Qt ForkAwesome
|
2021-11-02 18:03:33 +01:00
|
|
|
Library that bundles [ForkAwesome](https://forkaweso.me) for use within Qt
|
|
|
|
applications
|
2021-09-08 19:53:14 +02:00
|
|
|
|
|
|
|
## Build instructions
|
2021-09-16 22:27:48 +02:00
|
|
|
|
|
|
|
### Dependencies
|
2021-09-08 19:53:14 +02:00
|
|
|
The library depends on the following Qt modules (version 5.6 or higher):
|
|
|
|
`core`, `gui`
|
|
|
|
|
2021-10-25 18:44:18 +02:00
|
|
|
The additional library for Qt Quick integration (currently only providing a
|
|
|
|
`QQuickImageProvider`) depends on the following further Qt modules: `quick`
|
|
|
|
|
2021-09-08 19:53:14 +02:00
|
|
|
At build time `qtutilities` and `c++utilities` are required. This library is
|
|
|
|
built in the same way as these libraries so checkout the `c++utilities`
|
|
|
|
repository for detailed instructions.
|
|
|
|
|
|
|
|
To generate the header with icon definitions, Perl and the module `YAML::XS` (or
|
2021-09-11 20:43:03 +02:00
|
|
|
`YAML`) are required. To use a specific Perl binary, one can set the CMake
|
2023-02-26 19:25:28 +01:00
|
|
|
variable `PERL_BIN`. Under Windows, one can simply install `perl-YAML` via MSYS2
|
|
|
|
and set `PERL_BIN` to the path of `perl.exe` from the MSYS2 installation.
|
2021-09-08 19:53:14 +02:00
|
|
|
|
2021-09-16 22:27:48 +02:00
|
|
|
### Providing the font file
|
2021-09-11 20:43:03 +02:00
|
|
|
Of course the font file and icon definitions for ForkAwesome need to be
|
2023-11-23 18:53:13 +01:00
|
|
|
supplied as well. If none of the variables mentioned in the next paragraph are
|
|
|
|
specified, the build system will attempt to download the files from GitHub
|
|
|
|
automatically.
|
|
|
|
|
|
|
|
To supply the files manually, just download the `ttf`, `woff` or `woff2`
|
|
|
|
file from
|
|
|
|
[ForkAwesome's fonts directory](https://github.com/ForkAwesome/Fork-Awesome/tree/master/fonts)
|
|
|
|
and the
|
|
|
|
[icon definitions file](https://github.com/ForkAwesome/Fork-Awesome/blob/master/src/icons/icons.yml).
|
|
|
|
Then specify the path of the downloaded files via the CMake variables
|
|
|
|
`FORK_AWESOME_FONT_FILE` and `FORK_AWESOME_ICON_DEFINITIONS`, e.g. add
|
|
|
|
`-DFORK_AWESOME_FONT_FILE=/path/to/Fork-Awesome/fonts/forkawesome-webfont.woff2`
|
2021-09-08 19:53:14 +02:00
|
|
|
and
|
2023-11-23 18:53:13 +01:00
|
|
|
`-DFORK_AWESOME_ICON_DEFINITIONS=/path/to/Fork-Awesome/src/icons/icons.yml`
|
2021-09-08 19:53:14 +02:00
|
|
|
to the CMake invocation. The font file will be built into the library and
|
2023-11-23 18:53:13 +01:00
|
|
|
is hence only required at build time.
|
2021-09-08 19:53:14 +02:00
|
|
|
|
2021-09-16 22:27:48 +02:00
|
|
|
The Web Open Font Format (the `.woff`/`.woff2` file) might not be supported by
|
|
|
|
the font renderer. Notably, Window's native font rendering which Qt uses by
|
|
|
|
default does *not* support it. Then it makes sense to use the True Type Font
|
|
|
|
instead. Alternatively, one can force the platform plugin to use FreeType2 (e.g.
|
|
|
|
by setting `QT_QPA_PLATFORM=windows:fontengine=freetype`). Recent versions of
|
|
|
|
FreeType2 even support Web Open Font Format 2 (the `.woff2` file) but this
|
|
|
|
requires FreeType2 to be configured with Brotli support.
|
|
|
|
|
|
|
|
### Examples
|
|
|
|
Checkout https://github.com/Martchus/PKGBUILDs/tree/master/qtforkawesome for
|
|
|
|
examples to build for GNU/Linux and Windows against Qt 5 and Qt 6.
|
2021-09-11 20:43:03 +02:00
|
|
|
|
2021-09-16 22:27:48 +02:00
|
|
|
### Further remarks
|
2021-09-11 20:43:03 +02:00
|
|
|
As usual with CMake projects, it is possible to control whether to build as
|
|
|
|
static or shared library via the `BUILD_SHARED_LIBS` variable. If you build
|
|
|
|
qtforkawesome as part of another project and only want to affect qtforkawesome,
|
|
|
|
you can also use the variable `QT_FORK_AWESOME_BUILD_SHARED_LIBS`.
|
2021-09-08 19:53:14 +02:00
|
|
|
|
|
|
|
## Usage
|
2021-09-16 22:27:48 +02:00
|
|
|
The installation provides a CMake find module called `qtforkawesome` which
|
|
|
|
provides the imported target `qtforkawesome`. A pkg-config file is provided as
|
|
|
|
well. Once configured, the library is fairly simple to use:
|
2021-09-08 19:53:14 +02:00
|
|
|
|
|
|
|
```
|
2021-09-11 14:42:11 +02:00
|
|
|
#include <qtforkawesome/icon.h>
|
|
|
|
#include <qtforkawesome/renderer.h>
|
2021-09-08 19:53:14 +02:00
|
|
|
|
|
|
|
auto renderer = QtForkAwesome::Renderer();
|
|
|
|
renderer.pixmap(QtForkAwesome::Icon::Globe, QSize(64, 64), Qt::black);
|
|
|
|
```
|
|
|
|
|
|
|
|
There's also `renderer.render(…)` which takes a `QPainter` directly.
|
2021-09-13 20:49:52 +02:00
|
|
|
|
2021-09-16 22:27:48 +02:00
|
|
|
### Icon engine
|
2021-09-13 20:49:52 +02:00
|
|
|
A `QIconEnginePlugin` is provided as well. When it is loaded one can
|
|
|
|
create a `QIcon` using a file name with `.fa` extension, e.g.:
|
|
|
|
|
|
|
|
```
|
|
|
|
const auto icon = QIcon(QStringLiteral("qrcode:blue.fa"));
|
|
|
|
```
|
2021-09-16 22:27:48 +02:00
|
|
|
|
|
|
|
The color will be deduced from the applications default color palette unless it
|
|
|
|
is specified explicitly like in the example above.
|
|
|
|
|
|
|
|
To link against the plugin statically, find the CMake module
|
|
|
|
`qtforkawesomeiconengine`, link against the imported target
|
|
|
|
`qtforkawesomeiconengine` and add `Q_IMPORT_PLUGIN(ForkAwesomeIconEnginePlugin)`
|
|
|
|
to one of your source files.
|
|
|
|
|
2021-10-10 23:13:40 +02:00
|
|
|
### QQuickImageProvider
|
|
|
|
A `QQuickImageProvider` is provided as well in form of the additional library
|
2021-10-15 22:13:59 +02:00
|
|
|
`qtquickforkawesome`.
|
2021-10-10 23:13:40 +02:00
|
|
|
|
|
|
|
Then just include the header:
|
|
|
|
|
|
|
|
```
|
2021-10-15 19:58:06 +02:00
|
|
|
#include <qtquickforkawesome/imageprovider.h>
|
2021-10-10 23:13:40 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
Create an instance and add it to your `QQmlEngine`:
|
|
|
|
|
|
|
|
```
|
|
|
|
engine->addImageProvider(QStringLiteral("fa"), new QtForkAwesome::QuickImageProvider(renderer));
|
|
|
|
```
|
|
|
|
|
|
|
|
And use it like this:
|
|
|
|
```
|
|
|
|
Image {
|
|
|
|
source: "image://fa/syncthing"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2021-09-16 22:27:48 +02:00
|
|
|
### Bundling
|
|
|
|
It is also possible to build the library as part of your project. Simply add
|
|
|
|
it via `add_subdirectory`. Checkout the
|
|
|
|
[Syncthing Tray's project file](https://github.com/Martchus/syncthingtray/blob/master/CMakeLists.txt)
|
|
|
|
for an example.
|
2022-03-15 21:30:27 +01:00
|
|
|
|
2022-04-05 20:11:47 +02:00
|
|
|
## Copyright notice and license
|
2023-09-09 00:03:32 +02:00
|
|
|
Copyright © 2021-2023 Marius Kittler
|
2022-04-05 20:11:47 +02:00
|
|
|
|
2022-03-15 21:30:27 +01:00
|
|
|
All code is licensed under [GPL-2-or-later](LICENSE).
|