7 ostream &operator<< (ostream &stream, QPoint const &p)
9 return (stream << "(" << p.x() << "," << p.y() << ")");
12 float getAngle(const QPoint &p)
14 // Calculate angle of vector to y-axis
24 return (float)(M_PI - atan ( (double)(p.x()) / (double)(p.y()) ) );
27 return (float)( 2*M_PI - atan ( (double)(p.x()) / (double)(p.y()) ) );
29 return (float)( - atan ( (double)(p.x()) / (double)(p.y()) ) );
33 QPoint normalise(const QPoint &p)
35 // Calculate normalised position (fixed length)
63 return QPoint ((int) (x),(int) (y));
66 QString maskPath(QString p)
68 // Change " " to "\ " to enable blanks in filenames
69 p=p.replace(QChar('&'),"\\&");
70 return p.replace(QChar(' '),"\\ ");
73 QString convertToRel (const QString &src, const QString &dst)
78 // Find relative path from src to dst
80 // Remove the first "/"
81 if (s.section ("/",0,0).isEmpty())
83 s=s.right (s.length()-1);
84 d=d.right (d.length()-1);
87 // remove identical left parts
88 while (s.section("/",0,0) == d.section("/",0,0) )
91 s=s.right (s.length()-i-1);
92 d=d.right (d.length()-i-1);
95 int srcsep=s.contains("/");
96 int dstsep=d.contains("/");
97 if (srcsep >= dstsep )
99 // find path to go up first and then back to dst
110 // returns masked "<" ">" "&"
111 QString quotemeta(const QString &s)
114 QRegExp rx("&(?!amp;)");
115 r.replace ( rx,"&");
117 r.replace ( rx,">");
119 r.replace ( rx,"<");
120 rx.setPattern( "\"");
121 r.replace ( rx,""");
125 int max(int a, int b)
132 int xmlObj::actindent=0; // make instance of actindent
141 QString xmlObj::singleElement(QString s, QString at)
143 return indent() + "<" + s +" " + at +" " + "/>\n";
147 QString xmlObj::beginElement(QString s)
149 return indent() + "<" + s + ">\n";
153 QString xmlObj::beginElement(QString s, QString at)
155 return indent() + "<" + s + " " + at + ">\n";
159 QString xmlObj::endElement(QString s)
161 return indent() + "</" + s + ">\n";
165 QString xmlObj::attribut(QString at, QString val)
167 return " " + at + "=\"" + quotemeta (val) + "\"";
170 // returns <s> val </s>
171 QString xmlObj::valueElement(QString el, QString val)
173 return indent() + "<" + el + ">" + quotemeta(val) + "</" +el + ">\n";
176 // returns <s at> val </s>
177 QString xmlObj::valueElement(QString el, QString val, QString at)
179 return indent() + "<" + el + " " + at + ">" + quotemeta(val) + "</" +el + ">\n";
182 void xmlObj::incIndent()
187 void xmlObj::decIndent()
190 if (actindent<0) actindent=0;
193 QString xmlObj::indent()
197 for (i=0; i<actindent*indentwidth; i++)
206 ImagePreview::ImagePreview (QWidget *parent=0): QLabel (parent)
210 void ImagePreview::previewUrl( const QUrl &u )
212 QString path = u.path();
215 setText( QObject::tr("This is not an image.") );
221 if (pix.width()>max_w)
223 r=max_w / pix.width();
224 pix.resize(qRound(pix.width()*r), qRound(pix.height()*r));
225 // TODO not a resize, but a shrink/enlarge is needed here...
227 if (pix.height()>max_h)
229 r=max_h / pix.height();
230 pix.resize(qRound(pix.width()*r), qRound(pix.height()*r));
231 // TODO not a resize, but a shrink/enlarge is needed here...