File indexing completed on 2024-05-12 16:02:02

0001 /*
0002  * SPDX-FileCopyrightText: 2016 Wolthera van Hovell tot Westerflier <griffinvalley@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 #ifndef KIS_COLOR_SELECTOR_CONFIGURATION_H
0007 #define KIS_COLOR_SELECTOR_CONFIGURATION_H
0008 
0009 #include <QString>
0010 #include <QStringList>
0011 
0012 #include "kritawidgets_export.h"
0013 
0014 class KRITAWIDGETS_EXPORT KisColorSelectorConfiguration {
0015 
0016 public:
0017 
0018     enum Type {Ring, Square, Wheel, Triangle, Slider};
0019     enum Parameters {H, hsvS, V, hslS, L, SL, SV, SV2, hsvSH, hslSH, VH, LH, SI, SY, hsiSH, hsySH, I, Y, IH, YH, hsiS, hsyS, Hluma};
0020 
0021     Type mainType;
0022     Type subType;
0023     Parameters mainTypeParameter;
0024     Parameters subTypeParameter;
0025 
0026     KisColorSelectorConfiguration(Type mainT = Triangle, Type subT = Ring, Parameters mainTP = SL, Parameters subTP = H)
0027         : mainType(mainT)
0028         , subType(subT)
0029         , mainTypeParameter(mainTP)
0030         , subTypeParameter(subTP)
0031     {
0032     }
0033 
0034     KisColorSelectorConfiguration(QString string)
0035     {
0036         readString(string);
0037     }
0038 
0039     QString toString() const
0040     {
0041         return QString("%1|%2|%3|%4").arg(mainType).arg(subType).arg(mainTypeParameter).arg(subTypeParameter);
0042     }
0043     void readString(QString string)
0044     {
0045         QStringList strili = string.split('|');
0046         if(strili.length()!=4) return;
0047 
0048         int imt=strili.at(0).toInt();
0049         int ist=strili.at(1).toInt();
0050         int imtp=strili.at(2).toInt();
0051         int istp=strili.at(3).toInt();
0052 
0053         // Makes sure that Type and Parameters are within bounds.
0054         if(imt>Slider || ist>Slider || imtp>Hluma || istp>Hluma)
0055             return;
0056 
0057         mainType = Type(imt);
0058         subType = Type(ist);
0059         mainTypeParameter = Parameters(imtp);
0060         subTypeParameter = Parameters(istp);
0061     }
0062 
0063     static KisColorSelectorConfiguration fromString(QString string)
0064     {
0065         KisColorSelectorConfiguration ret;
0066         ret.readString(string);
0067         return ret;
0068     }
0069 };
0070 
0071 #endif