Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

utils.cpp

Go to the documentation of this file.
00001 #include "utils.hpp"
00002 
00003 QColor trust2rgb(float trust)
00004 {
00005         int r,g,b;
00006         if (trust < 0)
00007         {
00008                 r = 255;
00009                 g = 255;
00010                 b = 255;
00011         } 
00012         // Interpolate between red(255,0,0) and yellow (255,255,0)
00013         else if (trust < 0.5)
00014         {
00015                 r = 255;
00016                 g = (int)(510 * trust);
00017                 b = 0;
00018         //interpolate between yellow(255,255,0) and blue(0,0,255)
00019         } else {
00020                 r = (int) (510 * (1 - trust));
00021                 g = (int) (510 * (1 - trust));
00022                 b = (int) (510 * (trust - 0.5));
00023         }
00024         return QColor(r,g,b);
00025 }
00026 
00027 float trustItem2float (int item)
00028 {
00029         if (item == 0) return -1; else 
00030         return (float)(item - 1)/5;
00031 }
00032 
00033 int float2TrustItem (float trust)
00034 {
00035         if (trust < 0) return 0; else
00036         return (trust * 5) + 1;
00037 }
00038 
00039 QString escapeXml(const QString &str)
00040 {
00041         QString xml = str;
00042         xml.replace("&", "&amp;");
00043         xml.replace("<", "&lt;");
00044         xml.replace(">", "&gt;");
00045         xml.replace("'", "&apos;");
00046         xml.replace("\"", "&quot;");
00047         xml.replace("", "&AElig;");
00048         xml.replace("", "&Aacute;");
00049         xml.replace("", "&Acirc;");
00050         xml.replace("", "&Agrave;");
00051         xml.replace("", "&Atilde;");
00052         xml.replace("", "&Aring;");
00053         xml.replace("", "&Auml;");
00054         xml.replace("", "&Ccedil;");
00055         xml.replace("", "&ETH;");
00056         xml.replace("", "&Eacute;");
00057         xml.replace("", "&Ecirc;");
00058         xml.replace("", "&Egrave;");
00059         xml.replace("", "&Euml;");
00060         xml.replace("", "&Iacute;");
00061         xml.replace("", "&Icirc;");
00062         xml.replace("", "&Igrave;");
00063         xml.replace("", "&Iuml;");
00064         xml.replace("", "&Ntilde;");
00065         xml.replace("", "&Ocirc;");
00066         xml.replace("", "&Ocute;");
00067         xml.replace("", "&Ograve;");
00068         xml.replace("", "&Oslash;");
00069         xml.replace("", "&Ouml;");
00070         xml.replace("", "&Otilde;");
00071         xml.replace("", "&Uacute;");
00072         xml.replace("", "&Ucirc;");
00073         xml.replace("", "&Ugrave;");
00074         xml.replace("", "&Uuml;");
00075         xml.replace("", "&THORN;");
00076         xml.replace("", "&Yacute;");
00077         xml.replace("", "&aelig;");
00078         xml.replace("", "&aacute;");
00079         xml.replace("", "&acirc;");
00080         xml.replace("", "&agrave;");
00081         xml.replace("", "&atilde;");
00082         xml.replace("", "&aring;");
00083         xml.replace("", "&auml;");
00084         xml.replace("", "&ccedil;");
00085         xml.replace("", "&eth;");
00086         xml.replace("", "&eacute;");
00087         xml.replace("", "&ecirc;");
00088         xml.replace("", "&egrave;");
00089         xml.replace("", "&euml;");
00090         xml.replace("", "&iacute;");
00091         xml.replace("", "&icirc;");
00092         xml.replace("", "&igrave;");
00093         xml.replace("", "&iuml;");
00094         xml.replace("", "&ntilde;");
00095         xml.replace("", "&ocirc;");
00096         xml.replace("", "&ocute;");
00097         xml.replace("", "&ograve;");
00098         xml.replace("", "&oslash;");
00099         xml.replace("", "&ouml;");
00100         xml.replace("", "&otilde;");
00101         xml.replace("", "&uacute;");
00102         xml.replace("", "&ucirc;");
00103         xml.replace("", "&ugrave;");
00104         xml.replace("", "&uuml;");
00105         xml.replace("", "&szlig;");
00106         xml.replace("", "&thorn;");
00107         xml.replace("", "&yacute;");
00108         return xml;
00109  
00110 
00111 }
00112 
Untitled Document Pesquisa Psi SourceForge.net Logo