File indexing completed on 2024-03-24 15:27:37
0001 /* 0002 * This file is part of the KDE project. 0003 * Copyright © 2010 Christoph Feck <christoph@maxiom.de> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License version 2 as published by the Free Software Foundation. 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 KDEUI_COLORS_KCOLORCHOOSERMODE_PRIVATE_H 0021 #define KDEUI_COLORS_KCOLORCHOOSERMODE_PRIVATE_H 0022 0023 #include "kcolorchoosermode.h" 0024 0025 #include <QtGlobal> 0026 0027 class QColor; 0028 0029 namespace KDEPrivate 0030 { 0031 0032 // get/set color component 0033 extern qreal getComponentValue(const QColor &color, KColorChooserMode chooserMode); 0034 extern void setComponentValue(QColor &color, KColorChooserMode chooserMode, qreal value); 0035 0036 // number of linear gradient ranges needed for color component 0037 static inline int componentValueSteps(KColorChooserMode chooserMode) 0038 { 0039 if (chooserMode == ChooserHue) { 0040 return 6; 0041 } else { 0042 return 1; 0043 } 0044 } 0045 0046 // color component that is used for X in the XY selector 0047 static inline KColorChooserMode chooserXMode(KColorChooserMode chooserMode) 0048 { 0049 if (chooserMode >= ChooserRed) { 0050 return chooserMode == ChooserRed ? ChooserGreen : ChooserRed; 0051 } else { 0052 return chooserMode == ChooserHue ? ChooserSaturation : ChooserHue; 0053 } 0054 } 0055 0056 // color component that is used for Y in the XY selector 0057 static inline KColorChooserMode chooserYMode(KColorChooserMode chooserMode) 0058 { 0059 if (chooserMode >= ChooserRed) { 0060 return chooserMode == ChooserBlue ? ChooserGreen : ChooserBlue; 0061 } else { 0062 return chooserMode == ChooserValue ? ChooserSaturation : ChooserValue; 0063 } 0064 } 0065 0066 static inline int componentXSteps(KColorChooserMode chooserMode) 0067 { 0068 return componentValueSteps(chooserXMode(chooserMode)); 0069 } 0070 0071 static inline int componentYSteps(KColorChooserMode chooserMode) 0072 { 0073 return componentValueSteps(chooserYMode(chooserMode)); 0074 } 0075 0076 static inline qreal getComponentX(const QColor &color, KColorChooserMode chooserMode) 0077 { 0078 return getComponentValue(color, chooserXMode(chooserMode)); 0079 } 0080 0081 static inline qreal getComponentY(const QColor &color, KColorChooserMode chooserMode) 0082 { 0083 return getComponentValue(color, chooserYMode(chooserMode)); 0084 } 0085 0086 static inline void setComponentX(QColor &color, KColorChooserMode chooserMode, qreal x) 0087 { 0088 setComponentValue(color, chooserXMode(chooserMode), x); 0089 } 0090 0091 static inline void setComponentY(QColor &color, KColorChooserMode chooserMode, qreal y) 0092 { 0093 setComponentValue(color, chooserYMode(chooserMode), y); 0094 } 0095 0096 } // namespace KDEPrivate 0097 0098 #endif /* KDEUI_COLORS_KCOLORCHOOSERMODE_PRIVATE_H */