Compare commits

...

17 Commits

Author SHA1 Message Date
Martchus 43435a1b6a Avoid warning about implicit conversion when compiling with clang 2024-05-18 13:06:39 +02:00
Martchus 8f1a49610c Bump patch version 2024-05-18 13:06:17 +02:00
Martchus d363a5c9b0 Apply clang-format 2024-02-29 14:10:01 +01:00
Martchus ef08f63715 Apply change of `global.h` template 2024-02-22 19:42:43 +01:00
Martchus bb2030c964 Avoid too big icons in certain cases
When setting the scale factor of the primary screen to e.g. 100 % and the
scale factor of the second screen to something higher like 200 % the icons
appear too big on buttons and tabs. This is because icons are apparently
just rendered with the required size and the scale factor should therefore
not be applied.

This change adds overloads to specify a scale factor manually and uses a
scale factor of 1.0 for icons. The icons do not look blurry afterwards but
are also not too big anymore in the mentioned case. So this is probably how
it is supposed to be done.
2024-02-22 00:59:42 +01:00
Martchus 44776c210e Allow associating a paint device with the renderer for device-pixel-ratio 2024-02-22 00:59:42 +01:00
Martchus ce8e535d0e Update copyright date 2024-02-22 00:59:42 +01:00
Martchus 63ce4c79c6 Bump minor version 2024-02-22 00:59:42 +01:00
Martchus 3ec0824d3e Update outdated link in "Providing the font file" section
* Releases seem to be no longer present
* Link directly to the relevant directories/files
* Mention the automatic download before going into all the details of
  supplying the files manually
2023-11-23 18:53:13 +01:00
Martchus 6c5b63ec3b Update copyright date 2023-09-09 00:04:07 +02:00
Martchus 79f421c624 Avoid CMake deprecation warning by bumping version 2023-07-23 21:00:45 +02:00
Martchus 29fb3ca956 Apply cmake-format 2023-04-02 18:31:40 +02:00
Martchus fd14d3c502 Workaround CMake being unable to override symlink on Windows
The documentation says "If <linkname> already exists, it will
be overwritten.". This seems to be the case on GNU/Linux but
on Windows with CMake 3.24.2 (as provided by the official Qt
installer) I've nevertheless got an error.
2023-03-23 21:10:05 +01:00
Martchus e3d82ad643 Verify TLS cert when downloading font 2023-03-04 19:04:55 +01:00
Martchus 2cb41fd6ba Add note about using Perl from MSYS2 2023-02-26 19:28:03 +01:00
Martchus f725c3bee3 Fail at configuration time if Perl can not be found with obvious error 2023-02-26 19:28:03 +01:00
Martchus c77be09ca0 Bump patch version 2023-02-26 19:28:03 +01:00
9 changed files with 91 additions and 22 deletions

View File

@ -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)

View File

@ -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).

View File

@ -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

View File

@ -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) {

View File

@ -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")

View File

@ -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

View File

@ -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).
*/

View File

@ -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();

View File

@ -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