![]() |
Mixxx
|
00001 00002 #include "skin/colorschemeparser.h" 00003 00004 #include "widget/wpixmapstore.h" 00005 #include "widget/wskincolor.h" 00006 #include "widget/wwidget.h" 00007 00008 #include "skin/imgsource.h" 00009 #include "skin/imgloader.h" 00010 #include "skin/imgcolor.h" 00011 #include "skin/imginvert.h" 00012 00013 void ColorSchemeParser::setupLegacyColorSchemes(QDomElement docElem, 00014 ConfigObject<ConfigValue>* pConfig) { 00015 QDomNode colsch = docElem.namedItem("Schemes"); 00016 00017 if (!colsch.isNull() && colsch.isElement()) { 00018 QString schname = pConfig->getValueString(ConfigKey("[Config]","Scheme")); 00019 QDomNode sch = colsch.firstChild(); 00020 00021 bool found = false; 00022 00023 if (schname.isEmpty()) { 00024 // If no scheme stored, accept the first one in the file 00025 found = true; 00026 } 00027 00028 while (!sch.isNull() && !found) { 00029 QString thisname = WWidget::selectNodeQString(sch, "Name"); 00030 if (thisname == schname) { 00031 found = true; 00032 } else { 00033 sch = sch.nextSibling(); 00034 } 00035 } 00036 00037 if (found) { 00038 QSharedPointer<ImgSource> imsrc = 00039 QSharedPointer<ImgSource>(parseFilters(sch.namedItem("Filters"))); 00040 WPixmapStore::setLoader(imsrc); 00041 WSkinColor::setLoader(imsrc); 00042 } else { 00043 WPixmapStore::setLoader(QSharedPointer<ImgSource>()); 00044 WSkinColor::setLoader(QSharedPointer<ImgSource>()); 00045 } 00046 } else { 00047 WPixmapStore::setLoader(QSharedPointer<ImgSource>()); 00048 WSkinColor::setLoader(QSharedPointer<ImgSource>()); 00049 } 00050 } 00051 00052 ImgSource* ColorSchemeParser::parseFilters(QDomNode filt) { 00053 00054 // TODO: Move this code into ImgSource 00055 if (!filt.hasChildNodes()) { 00056 return 0; 00057 } 00058 00059 ImgSource * ret = new ImgLoader(); 00060 00061 QDomNode f = filt.firstChild(); 00062 00063 while (!f.isNull()) { 00064 QString name = f.nodeName().toLower(); 00065 if (name == "invert") { 00066 ret = new ImgInvert(ret); 00067 } else if (name == "hueinv") { 00068 ret = new ImgHueInv(ret); 00069 } else if (name == "add") { 00070 ret = new ImgAdd(ret, WWidget::selectNodeInt(f, "Amount")); 00071 } else if (name == "scalewhite") { 00072 ret = new ImgScaleWhite(ret, WWidget::selectNodeFloat(f, "Amount")); 00073 } else if (name == "hsvtweak") { 00074 int hmin = 0; 00075 int hmax = 359; 00076 int smin = 0; 00077 int smax = 255; 00078 int vmin = 0; 00079 int vmax = 255; 00080 float hfact = 1.0f; 00081 float sfact = 1.0f; 00082 float vfact = 1.0f; 00083 int hconst = 0; 00084 int sconst = 0; 00085 int vconst = 0; 00086 00087 if (!f.namedItem("HMin").isNull()) { hmin = WWidget::selectNodeInt(f, "HMin"); } 00088 if (!f.namedItem("HMax").isNull()) { hmax = WWidget::selectNodeInt(f, "HMax"); } 00089 if (!f.namedItem("SMin").isNull()) { smin = WWidget::selectNodeInt(f, "SMin"); } 00090 if (!f.namedItem("SMax").isNull()) { smax = WWidget::selectNodeInt(f, "SMax"); } 00091 if (!f.namedItem("VMin").isNull()) { vmin = WWidget::selectNodeInt(f, "VMin"); } 00092 if (!f.namedItem("VMax").isNull()) { vmax = WWidget::selectNodeInt(f, "VMax"); } 00093 00094 if (!f.namedItem("HConst").isNull()) { hconst = WWidget::selectNodeInt(f, "HConst"); } 00095 if (!f.namedItem("SConst").isNull()) { sconst = WWidget::selectNodeInt(f, "SConst"); } 00096 if (!f.namedItem("VConst").isNull()) { vconst = WWidget::selectNodeInt(f, "VConst"); } 00097 00098 if (!f.namedItem("HFact").isNull()) { hfact = WWidget::selectNodeFloat(f, "HFact"); } 00099 if (!f.namedItem("SFact").isNull()) { sfact = WWidget::selectNodeFloat(f, "SFact"); } 00100 if (!f.namedItem("VFact").isNull()) { vfact = WWidget::selectNodeFloat(f, "VFact"); } 00101 00102 ret = new ImgHSVTweak(ret, hmin, hmax, smin, smax, vmin, vmax, hfact, hconst, 00103 sfact, sconst, vfact, vconst); 00104 } else { 00105 qDebug() << "Unkown image filter:" << name; 00106 } 00107 f = f.nextSibling(); 00108 } 00109 00110 return ret; 00111 }