Compare commits
35 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 | |
Martchus | 48827d29d5 | |
Martchus | cc5aa18a5f | |
Martchus | 5e614118d3 | |
Martchus | 34aacf236b | |
Martchus | 0add8e8f91 | |
Martchus | 855b3af38b | |
Martchus | 65b3838b81 | |
Martchus | 2fcc5debcd | |
Martchus | 45dc4c7291 | |
Martchus | 145fd5a8e1 | |
Martchus | 1c92ea5bce | |
Martchus | f4ad5fefc3 | |
Martchus | d6293b7084 | |
Martchus | a0b31d8ddd | |
Martchus | 78ccb5c870 | |
Martchus | 8be5b2be7d | |
Martchus | 2d2cf96eb9 | |
Martchus | 860209ce7d |
|
@ -0,0 +1,19 @@
|
|||
# Number of days of inactivity before an issue becomes stale
|
||||
daysUntilStale: 60
|
||||
# Number of days of inactivity before a stale issue is closed
|
||||
daysUntilClose: 7
|
||||
# Issues with these labels will never be considered stale
|
||||
exemptLabels:
|
||||
- pinned
|
||||
- security
|
||||
- feature request
|
||||
- enhancement
|
||||
# Label to use when marking an issue as stale
|
||||
staleLabel: stale
|
||||
# Comment to post when marking an issue as stale. Set to `false` to disable
|
||||
markComment: >
|
||||
This issue has been automatically marked as stale because it has not had
|
||||
recent activity. It will be closed if no further activity occurs. Thank you
|
||||
for your contributions.
|
||||
# Comment to post when closing a stale issue. Set to `false` to disable
|
||||
closeComment: false
|
|
@ -1,14 +1,14 @@
|
|||
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 0)
|
||||
set(META_VERSION_PATCH 2)
|
||||
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_VERSION_EXACT_SONAME ON) # while still on 0.x.x release
|
||||
set(META_SOVERSION 1)
|
||||
set(META_PUBLIC_QT_MODULES Core Gui)
|
||||
set(META_ADD_DEFAULT_CPP_UNIT_TEST_APPLICATION OFF)
|
||||
|
||||
|
|
30
README.md
30
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
|
||||
|
@ -109,3 +116,8 @@ 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.
|
||||
|
||||
## Copyright notice and license
|
||||
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) {
|
||||
|
|
|
@ -22,14 +22,11 @@ class QT_FORK_AWESOME_ICON_ENGINE_EXPORT ForkAwesomeIconEnginePlugin : public QI
|
|||
|
||||
public:
|
||||
QIconEngine *create(const QString &filename = QString()) override;
|
||||
|
||||
private:
|
||||
const Renderer m_renderer;
|
||||
};
|
||||
|
||||
QIconEngine *ForkAwesomeIconEnginePlugin::create(const QString &file)
|
||||
{
|
||||
auto *const engine = new IconEngine(m_renderer);
|
||||
auto *const engine = new IconEngine(Renderer::global());
|
||||
if (!file.isNull()) {
|
||||
engine->addFile(file, QSize(), QIcon::Normal, QIcon::Off);
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
@ -85,8 +95,9 @@ endif ()
|
|||
use_cpp_utilities(ONLY_HEADERS VISIBILITY PUBLIC)
|
||||
use_qt_utilities(ONLY_HEADERS VISIBILITY PRIVATE)
|
||||
|
||||
# use Qt Gui module
|
||||
# set required Qt modules and declare their use as public
|
||||
list(APPEND ADDITIONAL_QT_MODULES Gui)
|
||||
set(META_PUBLIC_QT_MODULES Core ${ADDITIONAL_QT_MODULES})
|
||||
|
||||
# include modules to apply configuration
|
||||
include(BasicConfig)
|
||||
|
@ -98,7 +109,7 @@ include(ConfigHeader)
|
|||
|
||||
# configure test target
|
||||
include(TestUtilities)
|
||||
set(QT_TEST_LIBRARIES ${CPP_UTILITIES_LIB} ${META_TARGET_NAME})
|
||||
list(APPEND QT_TEST_LIBRARIES ${CPP_UTILITIES_LIB} ${META_TARGET_NAME})
|
||||
use_qt_module(LIBRARIES_VARIABLE "QT_TEST_LIBRARIES" PREFIX "${QT_PACKAGE_PREFIX}" MODULE "Test")
|
||||
foreach (TEST ${QT_TESTS})
|
||||
configure_test_target(TEST_NAME "${TEST}_tests" SRC_FILES "tests/${TEST}.cpp" LIBRARIES "${QT_TEST_LIBRARIES}")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
#include <QFontDatabase>
|
||||
#include <QGuiApplication>
|
||||
#include <QHash>
|
||||
#include <QIcon>
|
||||
#include <QPaintDevice>
|
||||
#include <QPainter>
|
||||
|
||||
/// \brief Contains classes provided by the QtForkAwesome library.
|
||||
|
@ -11,17 +14,58 @@ namespace QtForkAwesome {
|
|||
|
||||
/// \cond
|
||||
|
||||
struct IconOverride {
|
||||
void setIcon(const QIcon &icon);
|
||||
void addIconName(const QString &iconName);
|
||||
const QIcon &locateIcon();
|
||||
|
||||
private:
|
||||
QStringList iconNames;
|
||||
QIcon cachedIcon;
|
||||
};
|
||||
|
||||
void IconOverride::setIcon(const QIcon &icon)
|
||||
{
|
||||
iconNames.clear();
|
||||
cachedIcon = icon;
|
||||
}
|
||||
|
||||
void IconOverride::addIconName(const QString &iconName)
|
||||
{
|
||||
iconNames.append(iconName);
|
||||
if (!cachedIcon.isNull()) {
|
||||
cachedIcon = QIcon();
|
||||
}
|
||||
}
|
||||
|
||||
const QIcon &IconOverride::locateIcon()
|
||||
{
|
||||
if (!cachedIcon.isNull()) {
|
||||
return cachedIcon;
|
||||
}
|
||||
for (const auto &iconName : iconNames) {
|
||||
cachedIcon = QIcon::fromTheme(iconName);
|
||||
if (!cachedIcon.isNull()) {
|
||||
return cachedIcon;
|
||||
}
|
||||
}
|
||||
return cachedIcon;
|
||||
}
|
||||
|
||||
struct Renderer::InternalData {
|
||||
explicit InternalData(int id);
|
||||
static constexpr int invalidId = -1;
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -69,15 +113,9 @@ Renderer::operator bool() const
|
|||
return !m_d->fontFamilies.empty();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Renders the specified \a icon using the specified \a painter.
|
||||
*/
|
||||
void QtForkAwesome::Renderer::render(QChar character, QPainter *painter, const QRect &rect, const QColor &color) const
|
||||
/// \cond
|
||||
static void renderInternally(QChar character, QPainter *painter, QFont &&font, const QRect &rect, const QColor &color)
|
||||
{
|
||||
if (!*this) {
|
||||
return;
|
||||
}
|
||||
auto font = QFont(m_d->fontFamilies.front());
|
||||
font.setPixelSize(rect.height());
|
||||
painter->save();
|
||||
painter->setFont(font);
|
||||
|
@ -85,22 +123,52 @@ void QtForkAwesome::Renderer::render(QChar character, QPainter *painter, const Q
|
|||
painter->drawText(rect, QString(character), QTextOption(Qt::AlignCenter));
|
||||
painter->restore();
|
||||
}
|
||||
/// \endcond
|
||||
|
||||
/*!
|
||||
* \brief Renders the specified \a icon using the specified \a painter.
|
||||
*/
|
||||
void QtForkAwesome::Renderer::render(QChar character, QPainter *painter, const QRect &rect, const QColor &color) const
|
||||
{
|
||||
if (auto override = m_d->overrides.find(character); override != m_d->overrides.end()) {
|
||||
if (const auto &overrideIcon = override->locateIcon(); !overrideIcon.isNull()) {
|
||||
painter->drawPixmap(rect, overrideIcon.pixmap(rect.size(), QIcon::Normal, QIcon::On));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (*this) {
|
||||
renderInternally(character, painter, QFont(m_d->fontFamilies.front()), rect, color);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \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
|
||||
{
|
||||
const auto scaleFactor =
|
||||
if (auto override = m_d->overrides.find(icon); override != m_d->overrides.end()) {
|
||||
if (const auto &overrideIcon = override->locateIcon(); !overrideIcon.isNull()) {
|
||||
return overrideIcon.pixmap(size, QIcon::Normal, QIcon::On);
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
auto painter = QPainter(&pm);
|
||||
render(icon, &painter, QRect(QPoint(), scaledSize), color);
|
||||
if (*this) {
|
||||
auto painter = QPainter(&pm);
|
||||
renderInternally(icon, &painter, QFont(m_d->fontFamilies.front()), QRect(QPoint(), scaledSize), color);
|
||||
}
|
||||
pm.setDevicePixelRatio(scaleFactor);
|
||||
return pm;
|
||||
}
|
||||
|
@ -108,9 +176,79 @@ 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);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Uses the icon from the current icon theme obtained via QIcon::fromTheme() for \a character if it exists.
|
||||
*/
|
||||
void Renderer::addThemeOverride(QChar character, const QString &iconNameInTheme)
|
||||
{
|
||||
m_d->overrides[character].addIconName(iconNameInTheme);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Uses the specified \a override icon for \a character if it is not null.
|
||||
*/
|
||||
void Renderer::addOverride(QChar character, const QIcon &override)
|
||||
{
|
||||
m_d->overrides[character].setIcon(override);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Clears all overrides added via addThemeOverride() or addOverride().
|
||||
*/
|
||||
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).
|
||||
*/
|
||||
Renderer &Renderer::global()
|
||||
{
|
||||
static auto globalRenderer = Renderer();
|
||||
return globalRenderer;
|
||||
}
|
||||
|
||||
} // namespace QtForkAwesome
|
||||
|
|
|
@ -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,9 +31,20 @@ 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;
|
||||
|
||||
void addThemeOverride(QChar character, const QString &iconNameInTheme);
|
||||
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();
|
||||
|
||||
private:
|
||||
std::unique_ptr<Renderer::InternalData> m_d;
|
||||
};
|
||||
|
@ -45,6 +57,22 @@ inline void Renderer::render(Icon icon, QPainter *painter, const QRect &rect, co
|
|||
render(QChar(static_cast<IconBaseType>(icon)), painter, rect, color);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Uses the icon from the current icon theme obtained via QIcon::fromTheme() for \a icon if it exists.
|
||||
*/
|
||||
inline void Renderer::addThemeOverride(Icon icon, const QString &iconNameInTheme)
|
||||
{
|
||||
addThemeOverride(QChar(static_cast<IconBaseType>(icon)), iconNameInTheme);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Uses the specified \a override icon for \a icon if it is not null.
|
||||
*/
|
||||
inline void Renderer::addOverride(Icon icon, const QIcon &override)
|
||||
{
|
||||
addOverride(QChar(static_cast<IconBaseType>(icon)), override);
|
||||
}
|
||||
|
||||
} // namespace QtForkAwesome
|
||||
|
||||
#endif // QT_FORK_AWESOME_RENDERER
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "../icon.h"
|
||||
#include "../renderer.h"
|
||||
#include "../icon.h"
|
||||
|
||||
#include <c++utilities/tests/testutils.h>
|
||||
|
||||
|
|
|
@ -21,8 +21,9 @@ endif ()
|
|||
find_package(${NAMESPACE_PREFIX}qtforkawesome${CONFIGURATION_PACKAGE_SUFFIX_QTFORKAWESOME} ${META_APP_VERSION} REQUIRED)
|
||||
use_qt_fork_awesome()
|
||||
|
||||
# use Qt Gui module
|
||||
# set required Qt modules and declare their use as public
|
||||
list(APPEND ADDITIONAL_QT_MODULES Gui Quick)
|
||||
set(META_PUBLIC_QT_MODULES Core ${ADDITIONAL_QT_MODULES})
|
||||
|
||||
# include modules to apply configuration
|
||||
include(BasicConfig)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -20,15 +20,8 @@ QuickImageProvider::QuickImageProvider(
|
|||
{
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
QPixmap QuickImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize, const QQuickImageProviderOptions &options)
|
||||
#else
|
||||
QPixmap QuickImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
|
||||
#endif
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
Q_UNUSED(options)
|
||||
#endif
|
||||
const auto parts = QtUtilities::splitRef(id, QChar(':'));
|
||||
if (parts.empty()) {
|
||||
return QPixmap();
|
||||
|
@ -48,16 +41,9 @@ QPixmap QuickImageProvider::requestPixmap(const QString &id, QSize *size, const
|
|||
return m_renderer.pixmap(icon, renderSize, color);
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
QImage QuickImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize, const QQuickImageProviderOptions &options)
|
||||
{
|
||||
return requestPixmap(id, size, requestedSize, options).toImage();
|
||||
}
|
||||
#else
|
||||
QImage QuickImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
|
||||
{
|
||||
return requestPixmap(id, size, requestedSize).toImage();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace QtForkAwesome
|
||||
|
|
|
@ -15,16 +15,21 @@ namespace QtForkAwesome {
|
|||
class Renderer;
|
||||
|
||||
class QT_QUICK_FORK_AWESOME_EXPORT QuickImageProvider : public QQuickImageProvider {
|
||||
Q_PROPERTY(QColor defaultColor defaultColor name WRITE setDefaultColor)
|
||||
Q_PROPERTY(QSize defaultColor defaultSize name WRITE setDefaultSize)
|
||||
|
||||
public:
|
||||
QuickImageProvider(const Renderer &renderer, const QColor &defaultColor = QColor(), const QSize &defaultSize = QSize(64, 64),
|
||||
QQuickImageProvider::ImageType type = QQuickImageProvider::Pixmap);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize, const QQuickImageProviderOptions &options);
|
||||
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize, const QQuickImageProviderOptions &options);
|
||||
#else
|
||||
QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override;
|
||||
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override;
|
||||
#endif
|
||||
|
||||
QColor defaultColor() const;
|
||||
QSize defaultSize() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setDefaultColor(const QColor &color);
|
||||
void setDefaultSize(const QSize &size);
|
||||
|
||||
private:
|
||||
const Renderer &m_renderer;
|
||||
|
@ -32,6 +37,26 @@ private:
|
|||
QSize m_defaultSize;
|
||||
};
|
||||
|
||||
inline QColor QuickImageProvider::defaultColor() const
|
||||
{
|
||||
return m_defaultColor;
|
||||
}
|
||||
|
||||
inline QSize QuickImageProvider::defaultSize() const
|
||||
{
|
||||
return m_defaultSize;
|
||||
}
|
||||
|
||||
inline void QuickImageProvider::setDefaultColor(const QColor &color)
|
||||
{
|
||||
m_defaultColor = color;
|
||||
}
|
||||
|
||||
inline void QuickImageProvider::setDefaultSize(const QSize &size)
|
||||
{
|
||||
m_defaultSize = size;
|
||||
}
|
||||
|
||||
} // namespace QtForkAwesome
|
||||
|
||||
#endif // QT_FORK_AWESOME_QUICK_IMAGE_PROVIDER
|
||||
|
|
Loading…
Reference in New Issue