File indexing completed on 2025-02-02 05:02:39

0001 /*
0002     SPDX-FileCopyrightText: 2018-2021 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef UTIL_H
0008 #define UTIL_H
0009 
0010 #include <qobjectdefs.h>
0011 
0012 class QColor;
0013 class QDateTime;
0014 class QImage;
0015 class QVariant;
0016 
0017 /** Misc utilities. */
0018 class Util
0019 {
0020     Q_GADGET
0021 public:
0022     // workarounds for JS not preserving timezones
0023     /** Read a QDateTime property with the timezone stripped off. */
0024     Q_INVOKABLE static QDateTime dateTimeStripTimezone(const QVariant &obj, const QString &propertyName);
0025     /** Set a QDateTime property preserving the timezone of the current value. */
0026     Q_INVOKABLE static QVariant setDateTimePreserveTimezone(const QVariant &obj, const QString &propertyName, QDateTime value);
0027     /** Check whether a QDateTime property is the start of of day (ie. 00:00) in its given timezone. */
0028     Q_INVOKABLE static bool isStartOfDay(const QVariant &obj, const QString &propertyName);
0029 
0030     /** Checks whether @p text is rich-text. */
0031     Q_INVOKABLE static bool isRichText(const QString &text);
0032 
0033     /** Convert links, email address and phone numbers in the given text to HTML links. */
0034     Q_INVOKABLE static QString textToHtml(const QString &text);
0035     /** Convert a phone number into a tel: link. */
0036     Q_INVOKABLE static QString telephoneUrl(const QString &phoneNumber);
0037     /** Convert an email address into a mailto: link. */
0038     Q_INVOKABLE static QString emailUrl(const QString &emailAddress);
0039 
0040     /** Execute the non-exported sort() method on a QAbstractItemModel. */
0041     Q_INVOKABLE static void sortModel(QObject *model, int column, Qt::SortOrder sortOrder);
0042 
0043     /** QColor::isValid for QML. */
0044     Q_INVOKABLE static bool isValidColor(const QColor &color);
0045 
0046     /** Expose LocationUtil::isLocationCahnge to QML. */
0047     Q_INVOKABLE static bool isLocationChange(const QVariant &res);
0048 
0049     /** Simple heuristic on whether @p is primarily dark (and thus needs a light text
0050      *  color to be readable on top).
0051      */
0052     Q_INVOKABLE static bool isDarkImage(const QImage &img);
0053 };
0054 
0055 #endif // UTIL_H