6 QString qpointToString (const QPoint &p)
8 return "(" + QString("%1").arg(p.x()) +","+ QString ("%1").arg (p.y()) +")";
11 ostream &operator<< (ostream &stream, QPoint const &p)
13 return (stream << qpointToString(p) );
16 float getAngle(const QPoint &p)
18 // Calculate angle of vector to y-axis
28 return (float)(M_PI - atan ( (double)(p.x()) / (double)(p.y()) ) );
31 return (float)( 2*M_PI - atan ( (double)(p.x()) / (double)(p.y()) ) );
33 return (float)( - atan ( (double)(p.x()) / (double)(p.y()) ) );
37 QPoint normalise(const QPoint &p)
39 // Calculate normalised position (fixed length)
67 return QPoint ((int) (x),(int) (y));
70 QString maskPath(QString p)
72 // Change " " to "\ " to enable blanks in filenames
73 p=p.replace(QChar('&'),"\\&");
74 return p.replace(QChar(' '),"\\ ");
77 QString convertToRel (const QString &src, const QString &dst)
82 // Find relative path from src to dst
84 // Remove the first "/"
85 if (s.section ("/",0,0).isEmpty())
87 s=s.right (s.length()-1);
88 d=d.right (d.length()-1);
91 // remove identical left parts
92 while (s.section("/",0,0) == d.section("/",0,0) )
95 s=s.right (s.length()-i-1);
96 d=d.right (d.length()-i-1);
99 int srcsep=s.contains("/");
100 int dstsep=d.contains("/");
101 if (srcsep >= dstsep )
103 // find path to go up first and then back to dst
114 // returns masked "<" ">" "&"
115 QString quotemeta(const QString &s)
118 QRegExp rx("&(?!amp;)");
119 r.replace ( rx,"&");
121 r.replace ( rx,">");
123 r.replace ( rx,"<");
124 rx.setPattern( "\"");
125 r.replace ( rx,""");
129 int max(int a, int b)
136 int xmlObj::actindent=0; // make instance of actindent
145 QString xmlObj::singleElement(QString s, QString at)
147 return indent() + "<" + s +" " + at +" " + "/>\n";
151 QString xmlObj::beginElement(QString s)
153 return indent() + "<" + s + ">\n";
157 QString xmlObj::beginElement(QString s, QString at)
159 return indent() + "<" + s + " " + at + ">\n";
163 QString xmlObj::endElement(QString s)
165 return indent() + "</" + s + ">\n";
169 QString xmlObj::attribut(QString at, QString val)
171 return " " + at + "=\"" + quotemeta (val) + "\"";
174 // returns <s> val </s>
175 QString xmlObj::valueElement(QString el, QString val)
177 return indent() + "<" + el + ">" + quotemeta(val) + "</" +el + ">\n";
180 // returns <s at> val </s>
181 QString xmlObj::valueElement(QString el, QString val, QString at)
183 return indent() + "<" + el + " " + at + ">" + quotemeta(val) + "</" +el + ">\n";
186 void xmlObj::incIndent()
191 void xmlObj::decIndent()
194 if (actindent<0) actindent=0;
197 QString xmlObj::indent()
201 for (i=0; i<actindent*indentwidth; i++)
210 ImagePreview::ImagePreview (QWidget *parent=0): QLabel (parent)
214 void ImagePreview::previewUrl( const QUrl &u )
216 QString path = u.path();
219 setText( QObject::tr("This is not an image.") );
225 if (pix.width()>max_w)
227 r=max_w / pix.width();
228 pix.resize(qRound(pix.width()*r), qRound(pix.height()*r));
229 // TODO not a resize, but a shrink/enlarge is needed here...
231 if (pix.height()>max_h)
233 r=max_h / pix.height();
234 pix.resize(qRound(pix.width()*r), qRound(pix.height()*r));
235 // TODO not a resize, but a shrink/enlarge is needed here...