File indexing completed on 2024-05-05 12:13:16
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 #include "kcolorchoosermode_p.h" 0021 0022 #include <QColor> 0023 0024 namespace KDEPrivate 0025 { 0026 0027 qreal getComponentValue(const QColor &color, KColorChooserMode chooserMode) 0028 { 0029 switch (chooserMode) { 0030 case ChooserRed: 0031 return color.redF(); 0032 case ChooserGreen: 0033 return color.greenF(); 0034 case ChooserBlue: 0035 return color.blueF(); 0036 case ChooserHue: 0037 return color.hueF(); 0038 case ChooserSaturation: 0039 return color.saturationF(); 0040 default: 0041 return color.valueF(); 0042 } 0043 } 0044 0045 void setComponentValue(QColor &color, KColorChooserMode chooserMode, qreal value) 0046 { 0047 if (chooserMode >= ChooserRed) { 0048 if (chooserMode == ChooserRed) { 0049 color.setRedF(value); 0050 } else if (chooserMode == ChooserGreen) { 0051 color.setGreenF(value); 0052 } else { // chooserMode == ChooserBlue 0053 color.setBlueF(value); 0054 } 0055 } else { 0056 qreal h, s, v, a; 0057 color.getHsvF(&h, &s, &v, &a); 0058 if (chooserMode == ChooserHue) { 0059 h = value; 0060 } else if (chooserMode == ChooserSaturation) { 0061 s = value; 0062 } else { // chooserMode == ChooserValue 0063 v = value; 0064 } 0065 color.setHsvF(h, s, v, a); 0066 } 0067 } 0068 0069 } // namespace KDEPrivate