9 ostream &operator<< (ostream &stream, QPoint const &p)
11 return (stream << "(" << p.x() << "," << p.y() << ")");
14 float getAngle(const QPoint &p)
16 // Calculate angle of vector to y-axis
26 return (float)(M_PI - atan ( (double)(p.x()) / (double)(p.y()) ) );
29 return (float)( 2*M_PI - atan ( (double)(p.x()) / (double)(p.y()) ) );
31 return (float)( - atan ( (double)(p.x()) / (double)(p.y()) ) );
35 QPoint normalise(const QPoint &p)
37 // Calculate normalised position (fixed length)
65 return QPoint ((int) (x),(int) (y));
68 QString maskPath(QString p)
70 // Change " " to "\ " to enable blanks in filenames
71 p=p.replace(QChar('&'),"\\&");
72 return p.replace(QChar(' '),"\\ ");
75 QString convertToRel (const QString &src, const QString &dst)
80 // Find relative path from src to dst
82 // Remove the first "/"
83 if (s.section ("/",0,0).isEmpty())
85 s=s.right (s.length()-1);
86 d=d.right (d.length()-1);
89 // remove identical left parts
90 while (s.section("/",0,0) == d.section("/",0,0) )
93 s=s.right (s.length()-i-1);
94 d=d.right (d.length()-i-1);
97 int srcsep=s.contains("/");
98 int dstsep=d.contains("/");
99 if (srcsep >= dstsep )
101 // find path to go up first and then back to dst
112 // returns masked "<" ">" "&"
113 QString quotemeta(const QString &s)
116 QRegExp rx("&(?!amp;)");
117 r.replace ( rx,"&");
119 r.replace ( rx,">");
121 r.replace ( rx,"<");
122 rx.setPattern( "\"");
123 r.replace ( rx,""");
127 int max(int a, int b)
134 int xmlObj::actindent=0; // make instance of actindent
143 QString xmlObj::singleElement(QString s, QString at)
145 return indent() + "<" + s +" " + at +" " + "/>\n";
149 QString xmlObj::beginElement(QString s)
151 return indent() + "<" + s + ">\n";
155 QString xmlObj::beginElement(QString s, QString at)
157 return indent() + "<" + s + " " + at + ">\n";
161 QString xmlObj::endElement(QString s)
163 return indent() + "</" + s + ">\n";
167 QString xmlObj::attribut(QString at, QString val)
169 return " " + at + "=\"" + quotemeta (val) + "\"";
172 // returns <s> val </s>
173 QString xmlObj::valueElement(QString el, QString val)
175 return indent() + "<" + el + ">" + quotemeta(val) + "</" +el + ">\n";
178 // returns <s at> val </s>
179 QString xmlObj::valueElement(QString el, QString val, QString at)
181 return indent() + "<" + el + " " + at + ">" + quotemeta(val) + "</" +el + ">\n";
184 void xmlObj::incIndent()
189 void xmlObj::decIndent()
192 if (actindent<0) actindent=0;
195 QString xmlObj::indent()
199 for (i=0; i<actindent*indentwidth; i++)
208 ImagePreview::ImagePreview (QWidget *parent=0): QLabel (parent)
212 void ImagePreview::previewUrl( const QUrl &u )
214 QString path = u.path();
217 setText( QObject::tr("This is not an image.") );
223 if (pix.width()>max_w)
225 r=max_w / pix.width();
226 pix.resize(lrint(pix.width()*r), lrint(pix.height()*r));
227 // TODO not a resize, but a shrink/enlarge is needed here...
229 if (pix.height()>max_h)
231 r=max_h / pix.height();
232 pix.resize(lrint(pix.width()*r), lrint(pix.height()*r));
233 // TODO not a resize, but a shrink/enlarge is needed here...