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)
87 // Special case, we just need the name of the file,
88 // not the complete path
90 d=d.right (d.length()-i-1);
93 // Find relative path from src to dst
95 // Remove the first "/"
96 if (s.section ("/",0,0).isEmpty())
98 s=s.right (s.length()-1);
99 d=d.right (d.length()-1);
102 // remove identical left parts
103 while (s.section("/",0,0) == d.section("/",0,0) )
106 s=s.right (s.length()-i-1);
107 d=d.right (d.length()-i-1);
110 int srcsep=s.contains("/");
111 int dstsep=d.contains("/");
112 if (srcsep >= dstsep )
114 // find path to go up first and then back to dst
126 // returns masked "<" ">" "&"
127 QString quotemeta(const QString &s)
130 QRegExp rx("&(?!amp;)");
131 r.replace ( rx,"&");
133 r.replace ( rx,">");
135 r.replace ( rx,"<");
136 rx.setPattern( "\"");
137 r.replace ( rx,""");
141 int max(int a, int b)
148 int xmlObj::actindent=0; // make instance of actindent
157 QString xmlObj::singleElement(QString s, QString at)
159 return indent() + "<" + s +" " + at +" " + "/>\n";
163 QString xmlObj::beginElement(QString s)
165 return indent() + "<" + s + ">\n";
169 QString xmlObj::beginElement(QString s, QString at)
171 return indent() + "<" + s + " " + at + ">\n";
175 QString xmlObj::endElement(QString s)
177 return indent() + "</" + s + ">\n";
181 QString xmlObj::attribut(QString at, QString val)
183 return " " + at + "=\"" + quotemeta (val) + "\"";
186 // returns <s> val </s>
187 QString xmlObj::valueElement(QString el, QString val)
189 return indent() + "<" + el + ">" + quotemeta(val) + "</" +el + ">\n";
192 // returns <s at> val </s>
193 QString xmlObj::valueElement(QString el, QString val, QString at)
195 return indent() + "<" + el + " " + at + ">" + quotemeta(val) + "</" +el + ">\n";
198 void xmlObj::incIndent()
203 void xmlObj::decIndent()
206 if (actindent<0) actindent=0;
209 QString xmlObj::indent()
213 for (i=0; i<actindent*indentwidth; i++)
222 ImagePreview::ImagePreview (QWidget *parent=0): QLabel (parent)
226 void ImagePreview::previewUrl( const QUrl &u )
228 QString path = u.path();
231 setText( QObject::tr("This is not an image.") );
237 if (pix.width()>max_w)
239 r=max_w / pix.width();
240 pix.resize(qRound(pix.width()*r), qRound(pix.height()*r));
241 // TODO not a resize, but a shrink/enlarge is needed here...
243 if (pix.height()>max_h)
245 r=max_h / pix.height();
246 pix.resize(qRound(pix.width()*r), qRound(pix.height()*r));
247 // TODO not a resize, but a shrink/enlarge is needed here...