Compare commits
17 Commits
Author | SHA1 | Date |
---|---|---|
Martchus | 43435a1b6a | |
Martchus | 8f1a49610c | |
Martchus | d363a5c9b0 | |
Martchus | ef08f63715 | |
Martchus | bb2030c964 | |
Martchus | 44776c210e | |
Martchus | ce8e535d0e | |
Martchus | 63ce4c79c6 | |
Martchus | 3ec0824d3e | |
Martchus | 6c5b63ec3b | |
Martchus | 79f421c624 | |
Martchus | 29fb3ca956 | |
Martchus | fd14d3c502 | |
Martchus | e3d82ad643 | |
Martchus | 2cb41fd6ba | |
Martchus | f725c3bee3 | |
Martchus | c77be09ca0 |
|
@ -1,12 +1,12 @@
|
|||
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
|
||||
cmake_minimum_required(VERSION 3.17.0 FATAL_ERROR)
|
||||
|
||||
# meta data
|
||||
set(META_PROJECT_NAME qtforkawesome)
|
||||
set(META_APP_AUTHOR "Martchus")
|
||||
set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
|
||||
set(META_VERSION_MAJOR 0)
|
||||
set(META_VERSION_MINOR 1)
|
||||
set(META_VERSION_PATCH 0)
|
||||
set(META_VERSION_MINOR 2)
|
||||
set(META_VERSION_PATCH 1)
|
||||
set(META_APP_VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH})
|
||||
set(META_SOVERSION 1)
|
||||
set(META_PUBLIC_QT_MODULES Core Gui)
|
||||
|
|
27
README.md
27
README.md
|
@ -17,20 +17,27 @@ repository for detailed instructions.
|
|||
|
||||
To generate the header with icon definitions, Perl and the module `YAML::XS` (or
|
||||
`YAML`) are required. To use a specific Perl binary, one can set the CMake
|
||||
variable `PERL`.
|
||||
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.
|
||||
|
||||
### Providing the font file
|
||||
Of course the font file and icon definitions for ForkAwesome need to be
|
||||
supplied as well.
|
||||
Just download an archive from https://github.com/ForkAwesome/Fork-Awesome/releases
|
||||
and specify its path via the CMake variables `FORK_AWESOME_FONT_FILE`
|
||||
and `FORK_AWESOME_ICON_DEFINITIONS`, e.g. add
|
||||
`-DFORK_AWESOME_FONT_FILE=/path/to/Fork-Awesome-1.2.0/fonts/forkawesome-webfont.woff2`
|
||||
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`
|
||||
and
|
||||
`-DFORK_AWESOME_ICON_DEFINITIONS=/path/to/Fork-Awesome-1.2.0/src/icons/icons.yml`
|
||||
`-DFORK_AWESOME_ICON_DEFINITIONS=/path/to/Fork-Awesome/src/icons/icons.yml`
|
||||
to the CMake invocation. The font file will be built into the library and
|
||||
is hence only required at build time. If none of the variables are specified,
|
||||
the build system will attempt to download the files from GitHub.
|
||||
is hence only required at build time.
|
||||
|
||||
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
|
||||
|
@ -111,6 +118,6 @@ it via `add_subdirectory`. Checkout the
|
|||
for an example.
|
||||
|
||||
## Copyright notice and license
|
||||
Copyright © 2021-2022 Marius Kittler
|
||||
Copyright © 2021-2024 Marius Kittler
|
||||
|
||||
All code is licensed under [GPL-2-or-later](LICENSE).
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#ifndef QT_FORK_AWESOME_ICON_ENGINE_GLOBAL
|
||||
#define QT_FORK_AWESOME_ICON_ENGINE_GLOBAL
|
||||
|
||||
#include "qtforkawesomeiconengine-definitions.h"
|
||||
#include <c++utilities/application/global.h>
|
||||
|
||||
#ifdef QT_FORK_AWESOME_ICON_ENGINE_STATIC
|
||||
|
|
|
@ -63,7 +63,7 @@ QPixmap IconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State sta
|
|||
color = QGuiApplication::palette().color(group, role);
|
||||
}
|
||||
|
||||
auto pixmap = m_renderer.pixmap(QChar(m_char), size, color);
|
||||
auto pixmap = m_renderer.pixmap(QChar(m_char), size, color, 1.0);
|
||||
#ifdef QT_FORK_AWESOME_ICON_ENGINE_ENABLE_STYLE_SUPPORT
|
||||
auto *const app = qobject_cast<QApplication *>(QApplication::instance());
|
||||
if (auto *const style = app ? app->style() : nullptr) {
|
||||
|
|
|
@ -32,7 +32,10 @@ function (checkout_file VARIABLE)
|
|||
get_filename_component(FILE_NAME "${${VARIABLE}}" NAME)
|
||||
if (NOT EXISTS "${DOWNLOAD_DIR}/${FILE_NAME}")
|
||||
message(STATUS "Downloading ${${VARIABLE}}")
|
||||
file(DOWNLOAD "${${VARIABLE}}" "${DOWNLOAD_DIR}/${FILE_NAME}" SHOW_PROGRESS)
|
||||
file(
|
||||
DOWNLOAD "${${VARIABLE}}" "${DOWNLOAD_DIR}/${FILE_NAME}"
|
||||
SHOW_PROGRESS
|
||||
TLS_VERIFY ON)
|
||||
endif ()
|
||||
set("${VARIABLE}"
|
||||
"${DOWNLOAD_DIR}/${FILE_NAME}"
|
||||
|
@ -52,6 +55,10 @@ set(META_CUSTOM_CONFIG
|
|||
set(RES_FILE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}_font.qrc")
|
||||
set(RES_FILE_DATA "<RCC><qresource prefix=\"/\"><file>${META_FONT_FILE_NAME}</file></qresource></RCC>")
|
||||
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.14")
|
||||
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" AND EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${META_FONT_FILE_NAME}")
|
||||
# avoid running into error when symlink already exists (should not be necassary according to docs)
|
||||
file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/${META_FONT_FILE_NAME}")
|
||||
endif ()
|
||||
file(CREATE_LINK "${FORK_AWESOME_FONT_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/${META_FONT_FILE_NAME}" SYMBOLIC)
|
||||
else ()
|
||||
file(COPY "${FORK_AWESOME_FONT_FILE}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
@ -60,7 +67,10 @@ file(WRITE "${RES_FILE_PATH}" "${RES_FILE_DATA}")
|
|||
list(APPEND RES_FILES "${RES_FILE_PATH}")
|
||||
|
||||
# create rule for generating header file
|
||||
find_program(PERL perl)
|
||||
find_program(PERL_BIN perl)
|
||||
if (NOT PERL_BIN)
|
||||
message(FATAL_ERROR "Unable to find Perl, set PERL_BIN to the path of Perl's executable.")
|
||||
endif ()
|
||||
set(GENERATED_HEADERS_PATH "${CMAKE_CURRENT_BINARY_DIR}/headers")
|
||||
set(ICONS_HEADER_FILE "${GENERATED_HEADERS_PATH}/private/icons.h")
|
||||
set(ID_MAPPING_HEADER_FILE "${GENERATED_HEADERS_PATH}/private/idmapping.h")
|
||||
|
@ -69,7 +79,7 @@ list(APPEND SRC_FILES "${ICONS_HEADER_FILE}" "${ID_MAPPING_HEADER_FILE}")
|
|||
set(META_TIDY_EXCLUDE_REGEX ".*/headers/private.*")
|
||||
add_custom_command(
|
||||
OUTPUT "${ICONS_HEADER_FILE}" "${ID_MAPPING_HEADER_FILE}"
|
||||
COMMAND "${PERL}" "${CMAKE_CURRENT_SOURCE_DIR}/scripts/yaml2enum.pl" "${FORK_AWESOME_ICON_DEFINITIONS}"
|
||||
COMMAND "${PERL_BIN}" "${CMAKE_CURRENT_SOURCE_DIR}/scripts/yaml2enum.pl" "${FORK_AWESOME_ICON_DEFINITIONS}"
|
||||
"${ICONS_HEADER_FILE}" "${ID_MAPPING_HEADER_FILE}"
|
||||
DEPENDS "${FORK_AWESOME_ICON_DEFINITIONS}"
|
||||
COMMENT "Icon header")
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#ifndef QT_FORK_AWESOME_GLOBAL
|
||||
#define QT_FORK_AWESOME_GLOBAL
|
||||
|
||||
#include "qtforkawesome-definitions.h"
|
||||
#include <c++utilities/application/global.h>
|
||||
|
||||
#ifdef QT_FORK_AWESOME_STATIC
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <QGuiApplication>
|
||||
#include <QHash>
|
||||
#include <QIcon>
|
||||
#include <QPaintDevice>
|
||||
#include <QPainter>
|
||||
|
||||
/// \brief Contains classes provided by the QtForkAwesome library.
|
||||
|
@ -58,11 +59,13 @@ struct Renderer::InternalData {
|
|||
int id;
|
||||
QStringList fontFamilies;
|
||||
QHash<QChar, IconOverride> overrides;
|
||||
QPaintDevice *paintDevice;
|
||||
};
|
||||
|
||||
Renderer::InternalData::InternalData(int id)
|
||||
: id(id)
|
||||
, fontFamilies(id != invalidId ? QFontDatabase::applicationFontFamilies(id) : QStringList())
|
||||
, paintDevice(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -141,7 +144,7 @@ void QtForkAwesome::Renderer::render(QChar character, QPainter *painter, const Q
|
|||
/*!
|
||||
* \brief Renders the specified \a character as pixmap of the specified \a size.
|
||||
*/
|
||||
QPixmap QtForkAwesome::Renderer::pixmap(QChar icon, const QSize &size, const QColor &color) const
|
||||
QPixmap Renderer::pixmap(QChar icon, const QSize &size, const QColor &color, qreal scaleFactor) const
|
||||
{
|
||||
if (auto override = m_d->overrides.find(icon); override != m_d->overrides.end()) {
|
||||
if (const auto &overrideIcon = override->locateIcon(); !overrideIcon.isNull()) {
|
||||
|
@ -149,11 +152,16 @@ QPixmap QtForkAwesome::Renderer::pixmap(QChar icon, const QSize &size, const QCo
|
|||
}
|
||||
}
|
||||
|
||||
const auto scaleFactor =
|
||||
if (!static_cast<bool>(scaleFactor)) {
|
||||
scaleFactor =
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
!QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? 1.0 :
|
||||
!QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps)
|
||||
? 1.0
|
||||
:
|
||||
#endif
|
||||
qGuiApp->devicePixelRatio();
|
||||
(m_d->paintDevice ? m_d->paintDevice->devicePixelRatioF() : qGuiApp->devicePixelRatio());
|
||||
}
|
||||
|
||||
const auto scaledSize = QSize(size * scaleFactor);
|
||||
auto pm = QPixmap(scaledSize);
|
||||
pm.fill(QColor(Qt::transparent));
|
||||
|
@ -168,9 +176,35 @@ QPixmap QtForkAwesome::Renderer::pixmap(QChar icon, const QSize &size, const QCo
|
|||
/*!
|
||||
* \brief Renders the specified \a icon as pixmap of the specified \a size.
|
||||
*/
|
||||
QPixmap Renderer::pixmap(Icon icon, const QSize &size, const QColor &color, qreal scaleFactor) const
|
||||
{
|
||||
return pixmap(QChar(static_cast<IconBaseType>(icon)), size, color, scaleFactor);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Renders the specified \a character as pixmap of the specified \a size.
|
||||
* \remarks
|
||||
* - The pixmap will be scaled for the associated paint device or use the global device-dixel-ratio if not paint
|
||||
* device has been associated.
|
||||
* - When rendering a QPixmap for a QIcon, better the other overloads with the actual size (and a scale factor of
|
||||
* one).
|
||||
*/
|
||||
QPixmap QtForkAwesome::Renderer::pixmap(QChar icon, const QSize &size, const QColor &color) const
|
||||
{
|
||||
return pixmap(icon, size, color, 0.0);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Renders the specified \a icon as pixmap of the specified \a size.
|
||||
* \remarks
|
||||
* - The pixmap will be scaled for the associated paint device or use the global device-dixel-ratio if not paint
|
||||
* device has been associated.
|
||||
* - When rendering a QPixmap for a QIcon, better the other overloads with the actual size (and a scale factor of
|
||||
* one).
|
||||
*/
|
||||
QPixmap Renderer::pixmap(Icon icon, const QSize &size, const QColor &color) const
|
||||
{
|
||||
return pixmap(QChar(static_cast<IconBaseType>(icon)), size, color);
|
||||
return pixmap(QChar(static_cast<IconBaseType>(icon)), size, color, 0.0);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -197,6 +231,17 @@ void Renderer::clearOverrides()
|
|||
m_d->overrides.clear();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the associated \a paintDevice.
|
||||
* \remarks
|
||||
* The device-pixel-ratio of the specified device will be used when rendering pixmaps using the overloads that
|
||||
* do *not* take a scale factor.
|
||||
*/
|
||||
void Renderer::setAssociatedPaintDevice(QPaintDevice *paintDevice)
|
||||
{
|
||||
m_d->paintDevice = paintDevice;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the global instance (which is so far only used by the icon engine plugin).
|
||||
*/
|
||||
|
|
|
@ -13,6 +13,7 @@ QT_FORWARD_DECLARE_CLASS(QColor)
|
|||
QT_FORWARD_DECLARE_CLASS(QPainter)
|
||||
QT_FORWARD_DECLARE_CLASS(QRect)
|
||||
QT_FORWARD_DECLARE_CLASS(QSize)
|
||||
QT_FORWARD_DECLARE_CLASS(QPaintDevice)
|
||||
QT_FORWARD_DECLARE_CLASS(QPixmap)
|
||||
QT_FORWARD_DECLARE_CLASS(QIcon)
|
||||
|
||||
|
@ -30,6 +31,8 @@ public:
|
|||
void render(QChar character, QPainter *painter, const QRect &rect, const QColor &color) const;
|
||||
void render(Icon icon, QPainter *painter, const QRect &rect, const QColor &color) const;
|
||||
|
||||
QPixmap pixmap(QChar icon, const QSize &size, const QColor &color, qreal scaleFactor) const;
|
||||
QPixmap pixmap(Icon icon, const QSize &size, const QColor &color, qreal scaleFactor) const;
|
||||
QPixmap pixmap(QChar icon, const QSize &size, const QColor &color) const;
|
||||
QPixmap pixmap(Icon icon, const QSize &size, const QColor &color) const;
|
||||
|
||||
|
@ -37,6 +40,7 @@ public:
|
|||
void addThemeOverride(Icon icon, const QString &iconNameInTheme);
|
||||
void addOverride(QChar character, const QIcon &override);
|
||||
void addOverride(Icon icon, const QIcon &override);
|
||||
void setAssociatedPaintDevice(QPaintDevice *paintDevice);
|
||||
void clearOverrides();
|
||||
|
||||
static Renderer &global();
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#ifndef QT_QUICK_FORK_AWESOME_GLOBAL
|
||||
#define QT_QUICK_FORK_AWESOME_GLOBAL
|
||||
|
||||
#include "qtquickforkawesome-definitions.h"
|
||||
#include <c++utilities/application/global.h>
|
||||
|
||||
#ifdef QT_QUICK_FORK_AWESOME_STATIC
|
||||
|
|
Loading…
Reference in New Issue