12 QString richTextToPlain (QString r, const QString &indent, const int &width)
16 // Avoid failing assert with mingw
17 if (r.isEmpty()) return r;
22 // Remove all <style...> ...</style>
23 rx.setPattern("<style.*>.*</style>");
26 // convert all "<br*>" to "\n"
27 rx.setPattern ("<br.*>");
30 // convert all "</p>" to "\n"
31 rx.setPattern ("</p>");
34 // remove all remaining tags
35 rx.setPattern ("<.*>");
38 // If string starts with \n now, remove it.
39 // It would be wrong in an OOo export for example
40 while (r.length() > 0 && r.at(0)=='\n') r.remove (0,1);
42 // convert "&", "<" and ">"
43 rx.setPattern (">");
45 rx.setPattern ("<");
47 rx.setPattern ("&");
49 rx.setPattern (""");
53 rx.setPattern ("^\n");
54 r.replace (rx,indent);
55 r = indent + r; // Don't forget first line
60 QString qpointToString (const QPoint &p)
61 { return "(" + QString("%1").arg(p.x()) +","+ QString ("%1").arg (p.y()) +")"; }
63 QString qpointFToString (const QPointF &p)
64 { return "(" + QString("%1").arg(p.x()) +","+ QString ("%1").arg (p.y()) +")"; }
66 QString VectorToString (const Vector &p)
67 { return "(" + QString("%1").arg(p.x()) +","+ QString ("%1").arg (p.y()) +")"; }
69 ostream &operator<< (ostream &stream, QPoint const &p)
71 stream << "("<<p.x()<<","<<p.y()<<")";
75 ostream &operator<< (ostream &stream, QPointF const &p)
77 stream << "("<<p.x()<<","<<p.y()<<")";
81 ostream &operator<< (ostream &stream, QRectF const &r)
83 stream << "tL="<<r.topLeft()<<" - (w,h)="<<r.width()<<","<<r.height()<<" bR="<<r.bottomRight();
87 ostream &operator<< (ostream &stream, Vector const &p)
89 stream << "("<<p.x()<<","<<p.y()<<")";
93 qreal getAngle(const QPointF &p)
95 // Calculate angle of vector to x-axis
107 return (qreal)( - atan ( (qreal)(p.y()) / (qreal)(p.x()) ) );
109 return (qreal)( 2*M_PI - atan ( (qreal)(p.y()) / (qreal)(p.x()) ) );
112 return (qreal)(M_PI -atan ( (qreal)(p.y()) / (qreal)(p.x()) ) );
115 // Calculate angle of vector to y-axis
125 return (qreal)(M_PI - atan ( (qreal)(p.x()) / (qreal)(p.y()) ) );
128 return (qreal)( 2*M_PI - atan ( (qreal)(p.x()) / (qreal)(p.y()) ) );
130 return (qreal)( - atan ( (qreal)(p.x()) / (qreal)(p.y()) ) );
135 qreal min(qreal a, qreal b)
142 qreal max(qreal a, qreal b)
157 int round_int (qreal x)
159 return (x > 0.0) ? (x + 0.5) : (x - 0.5);
162 Qt::PenStyle penStyle (const QString &s, bool &ok)
165 Qt::PenStyle p(Qt::NoPen);
168 if (s=="Qt::SolidLine")
170 else if (s=="Qt::DashLine")
172 else if (s=="Qt::DotLine")
174 else if (s=="Qt::DashDotLine")
176 else if (s=="Qt::DashDotDotLine")
177 p=Qt::DashDotDotLine;
180 qWarning()<<"misc.cpp penStyle - Unknown style s="<<s;
186 QString penStyleToString (Qt::PenStyle p)
193 return "Qt::SolidLine";
195 return "Qt::DashLine";
197 return "Qt::DotLine";
198 case Qt::DashDotLine:
199 return "Qt::DashDotLine";
200 case Qt::DashDotDotLine:
201 return "Qt::DashDotDotLine";
207 QPointF point (const QString &s, bool &ok)
211 qreal x=s.section (',',0,0).toFloat (&okx);
212 qreal y=s.section (',',1,1).toFloat (&oky);
214 return QPointF (x,y);
216 qWarning()<<"misc.cpp Couldn't create QPointF from "<<s<<" ok="<<okx<<","<<oky;
221 QString pointToString (const QPointF &p)
223 return QString("%1,%2").arg(p.x()).arg(p.y());
226 void centerDialog (QDialog *dia)
228 dia->move(QCursor::pos() - 0.5 * QPoint(dia->rect().width(),dia->rect().height() ) );