8 QString qpointToString (const QPoint &p)
10 return "(" + QString("%1").arg(p.x()) +","+ QString ("%1").arg (p.y()) +")";
13 ostream &operator<< (ostream &stream, QPoint const &p)
15 return (stream << qpointToString(p) );
18 float getAngle(const QPoint &p)
20 // Calculate angle of vector to y-axis
30 return (float)(M_PI - atan ( (double)(p.x()) / (double)(p.y()) ) );
33 return (float)( 2*M_PI - atan ( (double)(p.x()) / (double)(p.y()) ) );
35 return (float)( - atan ( (double)(p.x()) / (double)(p.y()) ) );
39 QPoint normalise(const QPoint &p)
41 // Calculate normalised position (fixed length)
69 return QPoint ((int) (x),(int) (y));
72 QString maskPath(QString p)
74 // Change " " to "\ " to enable blanks in filenames
75 p=p.replace(QChar('&'),"\\&");
76 return p.replace(QChar(' '),"\\ ");
79 QString convertToRel (const QString &src, const QString &dst)
84 // Find relative path from src to dst
86 // Remove the first "/"
87 if (s.section ("/",0,0).isEmpty())
89 s=s.right (s.length()-1);
90 d=d.right (d.length()-1);
93 // remove identical left parts
94 while (s.section("/",0,0) == d.section("/",0,0) )
97 s=s.right (s.length()-i-1);
98 d=d.right (d.length()-i-1);
101 int srcsep=s.contains("/");
102 int dstsep=d.contains("/");
103 if (srcsep >= dstsep )
105 // find path to go up first and then back to dst
116 // returns masked "<" ">" "&"
117 QString quotemeta(const QString &s)
120 QRegExp rx("&(?!amp;)");
121 r.replace ( rx,"&");
123 r.replace ( rx,">");
125 r.replace ( rx,"<");
126 rx.setPattern( "\"");
127 r.replace ( rx,""");
131 int max(int a, int b)
138 int xmlObj::actindent=0; // make instance of actindent
147 QString xmlObj::singleElement(QString s, QString at)
149 return indent() + "<" + s +" " + at +" " + "/>\n";
153 QString xmlObj::beginElement(QString s)
155 return indent() + "<" + s + ">\n";
159 QString xmlObj::beginElement(QString s, QString at)
161 return indent() + "<" + s + " " + at + ">\n";
165 QString xmlObj::endElement(QString s)
167 return indent() + "</" + s + ">\n";
171 QString xmlObj::attribut(QString at, QString val)
173 return " " + at + "=\"" + quotemeta (val) + "\"";
176 // returns <s> val </s>
177 QString xmlObj::valueElement(QString el, QString val)
179 return indent() + "<" + el + ">" + quotemeta(val) + "</" +el + ">\n";
182 // returns <s at> val </s>
183 QString xmlObj::valueElement(QString el, QString val, QString at)
185 return indent() + "<" + el + " " + at + ">" + quotemeta(val) + "</" +el + ">\n";
188 void xmlObj::incIndent()
193 void xmlObj::decIndent()
196 if (actindent<0) actindent=0;
199 QString xmlObj::indent()
203 for (i=0; i<actindent*indentwidth; i++)
212 ImagePreview::ImagePreview (QWidget *parent=0): QLabel (parent)
216 void ImagePreview::previewUrl( const QUrl &u )
218 QString path = u.path();
221 setText( QObject::tr("This is not an image.") );
227 if (pix.width()>max_w)
229 r=max_w / pix.width();
230 pix.resize(qRound(pix.width()*r), qRound(pix.height()*r));
231 // TODO not a resize, but a shrink/enlarge is needed here...
233 if (pix.height()>max_h)
235 r=max_h / pix.height();
236 pix.resize(qRound(pix.width()*r), qRound(pix.height()*r));
237 // TODO not a resize, but a shrink/enlarge is needed here...