File indexing completed on 2024-05-05 04:38:47

0001 /*
0002     SPDX-FileCopyrightText: 2015 Kevin Funk <kfunk@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include <util/utilexport.h>
0010 
0011 #include <QtGlobal>
0012 
0013 class QColor;
0014 class QModelIndex;
0015 class QPainter;
0016 class QRect;
0017 class QPalette;
0018 class QTreeView;
0019 class QTextDocument;
0020 
0021 namespace KDevelop {
0022 
0023 namespace WidgetColorizer {
0024 /**
0025  * Generate a new color by blending the input @p color with the foreground.
0026  *
0027  * This function also works nicely on dark color schemes, in contrast to
0028  * simply setting an alpha channel value on the color.
0029  *
0030  * @p color Input color to blend.
0031  * @p ratio Ratio to decide how strong to do the blending.
0032  *          When set to 0 you get the foreground color as-is, when set to 1
0033  *          you get the input color as-is.
0034  */
0035 KDEVPLATFORMUTIL_EXPORT QColor blendForeground(QColor color, float ratio,
0036                                                const QColor& foreground, const QColor& background);
0037 
0038 /**
0039  * Generate a new color by blending the input @p color with the background.
0040  *
0041  * This function also works nicely on dark color schemes, in contrast to
0042  * simply setting an alpha channel value on the color.
0043  *
0044  * @p color Input color to blend.
0045  * @p ratio Ratio to decide how strong to do the blending.
0046  *          When set to 0 you get the background color as-is, when set to 1
0047  *          you get the input color as-is.
0048  */
0049 KDEVPLATFORMUTIL_EXPORT QColor blendBackground(const QColor& color, float ratio,
0050                                                const QColor& foreground, const QColor& background);
0051 
0052 KDEVPLATFORMUTIL_EXPORT void drawBranches(const QTreeView* treeView, QPainter* painter,
0053                                           const QRect& rect, const QModelIndex& index, const QColor& color);
0054 
0055 /**
0056  * Return a random color fit for the active palette.
0057  *
0058  * @p id An id which can be generated e.g. by qHash. Same ids will return
0059  *       the same color.
0060  * @p activePalette The palette to use for generating the color.
0061  * @p background If set to true, a background color will be returned,
0062  *               otherwise a foreground color will be returned by default.
0063  */
0064 KDEVPLATFORMUTIL_EXPORT QColor colorForId(uint id, const QPalette& activePalette,
0065                                           bool background = false);
0066 
0067 /**
0068  * Returns true when the setting is enabled to colorize widgets representing
0069  * files belonging to projects.
0070  */
0071 KDEVPLATFORMUTIL_EXPORT bool colorizeByProject();
0072 
0073 /**
0074  * Convert colors in the @p doc to make them readable if the current palette is using a dark theme
0075  */
0076 KDEVPLATFORMUTIL_EXPORT void convertDocumentToDarkTheme(QTextDocument* doc);
0077 }
0078 
0079 }