File indexing completed on 2024-05-19 04:29:26

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 #include <boost/operators.hpp>
0012 
0013 #include "kritawidgets_export.h"
0014 
0015 class KRITAWIDGETS_EXPORT KisColorSelectorConfiguration
0016         : public boost::equality_comparable<KisColorSelectorConfiguration> {
0017 
0018 public:
0019 
0020     enum Type {Ring, Square, Wheel, Triangle, Slider};
0021     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};
0022 
0023     Type mainType;
0024     Type subType;
0025     Parameters mainTypeParameter;
0026     Parameters subTypeParameter;
0027 
0028     KisColorSelectorConfiguration(Type mainT = Triangle, Type subT = Ring, Parameters mainTP = SL, Parameters subTP = H)
0029         : mainType(mainT)
0030         , subType(subT)
0031         , mainTypeParameter(mainTP)
0032         , subTypeParameter(subTP)
0033     {
0034     }
0035 
0036     KisColorSelectorConfiguration(QString string)
0037     {
0038         readString(string);
0039     }
0040 
0041     QString toString() const
0042     {
0043         return QString("%1|%2|%3|%4").arg(mainType).arg(subType).arg(mainTypeParameter).arg(subTypeParameter);
0044     }
0045     void readString(QString string)
0046     {
0047         QStringList strili = string.split('|');
0048         if(strili.length()!=4) return;
0049 
0050         int imt=strili.at(0).toInt();
0051         int ist=strili.at(1).toInt();
0052         int imtp=strili.at(2).toInt();
0053         int istp=strili.at(3).toInt();
0054 
0055         // Makes sure that Type and Parameters are within bounds.
0056         if(imt>Slider || ist>Slider || imtp>Hluma || istp>Hluma)
0057             return;
0058 
0059         mainType = Type(imt);
0060         subType = Type(ist);
0061         mainTypeParameter = Parameters(imtp);
0062         subTypeParameter = Parameters(istp);
0063     }
0064 
0065     static KisColorSelectorConfiguration fromString(QString string)
0066     {
0067         KisColorSelectorConfiguration ret;
0068         ret.readString(string);
0069         return ret;
0070     }
0071 
0072     bool operator==(const KisColorSelectorConfiguration &rhs) const
0073     {
0074         return (mainType == rhs.mainType &&
0075                 subType == rhs.subType &&
0076                 mainTypeParameter == rhs.mainTypeParameter &&
0077                 subTypeParameter == rhs.subTypeParameter);
0078     }
0079 };
0080 
0081 #endif