File indexing completed on 2024-12-01 10:29:27

0001 /* This file is part of the KDE project
0002    Copyright (C) 2010-2017 Jarosław Staniek <staniek@kde.org>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KPROPERTY_UTILS_P_H
0021 #define KPROPERTY_UTILS_P_H
0022 
0023 #include <QPainter>
0024 #include <QString>
0025 #include <QVariant>
0026 
0027 class KProperty;
0028 
0029 namespace KPropertyUtilsPrivate
0030 {
0031 
0032 //! @return contrast color for @a c color.
0033 QColor contrastColor(const QColor& c);
0034 
0035 //! @return grid line color defined by a KPropertyEditorView widget contains @a widget
0036 //! Invalid  color is returned if no grid is defined or KPropertyEditorView was not found.
0037 QColor gridLineColor(const QWidget *widget);
0038 
0039 //! @return supported icon theme
0040 //! @todo Support other themes
0041 QString supportedIconTheme();
0042 
0043 /*! @brief Sets up a private icon resource file
0044  * Warns on failure and returns @c false.
0045  * @param privateName Name to be used instead of application name for resource lookup
0046  * @param path Relative path to the resource file
0047  * @param messageType Type of message to use on error, QtFatalMsg for fatal exit and any
0048  * other for warning
0049  * @param prefix Resource path prefix. The default is useful for library-global resource,
0050  * other values is useful for plugins.
0051  */
0052 bool setupPrivateIconsResourceWithMessage(const QString &privateName, const QString& path,
0053                                           QtMsgType messageType,
0054                                           const QString &prefix = QLatin1String(":/icons"));
0055 
0056 //! Sets up a global icon theme if it is different from supported.
0057 //! Warns on failure and returns @c false.
0058 bool setupGlobalIconTheme();
0059 
0060 //! Helper for handling minValueText, prefix and suffix property options
0061 class ValueOptionsHandler
0062 {
0063 public:
0064     explicit ValueOptionsHandler(const KProperty &property);
0065 
0066     //! @return @a valueString value with prefix and suffix, if present
0067     QString valueWithPrefixAndSuffix(const QString &valueString, const QLocale &locale) const;
0068 
0069     QVariant minValueText;
0070     QString prefix;
0071     QString suffix;
0072 };
0073 
0074 //! @short Manages the QPainter::save()/QPainter::restore() block using RAII
0075 /*! The PainterSaver class makes sure that restore() is called when exiting from the block of code.
0076 
0077    Instead of:
0078    @code
0079    painter.save();
0080    // (code)
0081    painter.restore();
0082    @endcode
0083 
0084    Use this:
0085    @code
0086    const PainterSaver saver(&painter);
0087    // (code)
0088    @endcode
0089 */
0090 class PainterSaver
0091 {
0092 public:
0093     explicit PainterSaver(QPainter *p);
0094 
0095     ~PainterSaver();
0096 
0097 private:
0098     QPainter* const m_painter;
0099 };
0100 
0101 /**
0102  * @brief Returns @c true if native dialog should be used
0103  *
0104  * If @c false Qt's standard dialog should be used instead of the operating system native dialog.
0105  * Can be used with QColorDialog, QFileDialog and QFontDialog.
0106  * Depends on the curent desktop in use:
0107  * - on Unix (other than macOS) returns @c true if the XDG_CURRENT_DESKTOP environment variable is
0108  *   empty or equal to "KDE", @c false for other values of XDG_CURRENT_DESKTOP (i.e. @c false for
0109  *   XFCE, GNOME and other desktops)
0110  * - @c true for all other operating systems, i.e. for MS Windows, macOS, etc.
0111  *
0112  * @todo Share this code with KReport and Kexi
0113  */
0114 bool shouldUseNativeDialogs();
0115 
0116 } // namespace KPropertyUtilsPrivate
0117 
0118 #endif