|
17 | 17 | #include <QFontDatabase> |
18 | 18 | #include <QFontMetrics> |
19 | 19 | #include <QString> |
| 20 | +#include <QUrlQuery> |
20 | 21 |
|
21 | 22 |
|
22 | 23 | #if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)) |
@@ -113,7 +114,7 @@ class QtAwesomeCharIconPainter: public QtAwesomeIconPainter |
113 | 114 | painter->setRenderHint(QPainter::HighQualityAntialiasing); |
114 | 115 | #endif |
115 | 116 |
|
116 | | - QVariant var =options.value("anim"); |
| 117 | + QVariant var = options.value("anim"); |
117 | 118 | QtAwesomeAnimation* anim = var.value<QtAwesomeAnimation*>(); |
118 | 119 | if (anim) { |
119 | 120 | anim->setup(*painter, rect); |
@@ -587,6 +588,59 @@ QString QtAwesome::fontName(int style) const |
587 | 588 | return _fontDetails[style].fontFamily(); |
588 | 589 | } |
589 | 590 |
|
| 591 | +/// \brief Requests a pixmap which can drictly be used by QQuickImageProvider |
| 592 | +/// |
| 593 | +/// \param An identifier in the format "regular/name?option1=x&option2=y |
| 594 | +QPixmap QtAwesome::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) |
| 595 | +{ |
| 596 | + QString baseId = id; |
| 597 | + QVariantMap options; |
| 598 | + |
| 599 | + int queryStart = id.indexOf('?'); |
| 600 | + if (queryStart != -1) { |
| 601 | + baseId = id.left(queryStart); |
| 602 | + QString queryString = id.mid(queryStart + 1); |
| 603 | + |
| 604 | + QUrlQuery query(queryString); |
| 605 | + for (const auto &item : query.queryItems()) { |
| 606 | + options.insert(item.first, item.second); |
| 607 | + } |
| 608 | + transformStringVariantOptions(options); |
| 609 | + } |
| 610 | + |
| 611 | + int nameStart = baseId.indexOf("/"); |
| 612 | + if (nameStart != -1) { |
| 613 | + baseId = "fa-" + baseId.left(nameStart) + " fa-" + baseId.mid(nameStart + 1); |
| 614 | + } else { |
| 615 | + baseId = "fa-solid fa-" + baseId; |
| 616 | + } |
| 617 | + |
| 618 | + QIcon icn = icon(baseId, options); |
| 619 | + QSize actualSize = requestedSize.isValid() ? requestedSize : QSize(128, 128); |
| 620 | + if (size) { |
| 621 | + *size = actualSize; |
| 622 | + } |
| 623 | + |
| 624 | + return icn.pixmap(actualSize); |
| 625 | +} |
| 626 | + |
| 627 | + |
| 628 | +/// \Brief Transforms a String based hash map to the correct objec types. |
| 629 | +/// All color types which aren't colors are converted to QColor objects and Interpreted |
| 630 | +/// as HEX codes (# is optional) |
| 631 | +void QtAwesome::transformStringVariantOptions(QVariantMap& options) |
| 632 | +{ |
| 633 | + for (auto i = options.cbegin(), end = options.cend(); i != end; ++i) { |
| 634 | + QString key = i.key(); |
| 635 | + if (key.contains("color") && i.value().userType() == QMetaType::QString) { |
| 636 | + QString value = i.value().value<QString>(); |
| 637 | + QColor colorValue = QColor(value[0] == '#' ? QColor(value) : QColor(QString("#%1").arg(value))); |
| 638 | + options[key] = colorValue; |
| 639 | + } |
| 640 | + } |
| 641 | +} |
| 642 | + |
| 643 | + |
590 | 644 | int QtAwesome::stringToStyleEnum(const QString style) const |
591 | 645 | { |
592 | 646 | if (style == "fa-solid") return fa::fa_solid; |
|
0 commit comments