12 extern QString vymVersion;
14 QString richTextToPlain(QString r, const QString &indent, const int &width)
18 // Avoid failing assert with mingw
25 // Remove all <style...> ...</style>
26 rx.setPattern("<style.*>.*</style>");
29 // convert all "<br*>" to "\n"
30 rx.setPattern("<br.*>");
33 // convert all "</p>" to "\n"
34 rx.setPattern("</p>");
37 // remove all remaining tags
38 rx.setPattern("<.*>");
41 // If string starts with \n now, remove it.
42 // It would be wrong in an OOo export for example
43 while (r.length() > 0 && r.at(0) == '\n')
46 // convert "&", "<" and ">"
47 rx.setPattern(">");
49 rx.setPattern("<");
51 rx.setPattern("&");
53 rx.setPattern(""");
58 r.replace(rx, indent);
59 r = indent + r; // Don't forget first line
64 QString qpointToString(const QPoint &p)
66 return "(" + QString("%1").arg(p.x()) + "," + QString("%1").arg(p.y()) +
70 QString qpointFToString(const QPointF &p)
72 return "(" + QString("%1").arg(p.x()) + "," + QString("%1").arg(p.y()) +
76 QString qrectFToString(const QRectF &r, int d)
78 return QString("(%1, %2 %3x%4)")
79 .arg(QString::number(r.x(),'f', d))
80 .arg(QString::number(r.y(),'f', d))
81 .arg(QString::number(r.width(),'f', d))
82 .arg(QString::number(r.height(),'f', d));
85 QString VectorToString(const Vector &p)
87 return "(" + QString("%1").arg(p.x()) + "," + QString("%1").arg(p.y()) +
91 ostream &operator<<(ostream &stream, QPoint const &p)
93 stream << "(" << p.x() << "," << p.y() << ")";
97 ostream &operator<<(ostream &stream, QPointF const &p)
99 stream << "(" << p.x() << "," << p.y() << ")";
103 ostream &operator<<(ostream &stream, QRectF const &r)
105 stream << "tL=" << r.topLeft() << " - (w,h)=" << r.width() << ","
106 << r.height() << " bR=" << r.bottomRight();
110 ostream &operator<<(ostream &stream, Vector const &p)
112 stream << "(" << p.x() << "," << p.y() << ")";
116 qreal getAngle(const QPointF &p)
118 // Calculate angle of vector to x-axis
128 return (qreal)(-atan((qreal)(p.y()) / (qreal)(p.x())));
130 return (qreal)(2 * M_PI -
131 atan((qreal)(p.y()) / (qreal)(p.x())));
134 return (qreal)(M_PI - atan((qreal)(p.y()) / (qreal)(p.x())));
137 // Calculate angle of vector to y-axis
147 return (qreal)(M_PI - atan ( (qreal)(p.x()) / (qreal)(p.y()) ) );
150 return (qreal)( 2*M_PI - atan ( (qreal)(p.x()) / (qreal)(p.y()) ) );
152 return (qreal)( - atan ( (qreal)(p.x()) / (qreal)(p.y()) ) );
157 qreal min(qreal a, qreal b)
164 qreal max(qreal a, qreal b)
179 int round_int(qreal x) { return (x > 0.0) ? (x + 0.5) : (x - 0.5); }
181 Qt::PenStyle penStyle(const QString &s, bool &ok)
184 Qt::PenStyle p(Qt::NoPen);
185 if (s == "Qt::NoPen")
187 if (s == "Qt::SolidLine")
189 else if (s == "Qt::DashLine")
191 else if (s == "Qt::DotLine")
193 else if (s == "Qt::DashDotLine")
195 else if (s == "Qt::DashDotDotLine")
196 p = Qt::DashDotDotLine;
198 qWarning() << "misc.cpp penStyle - Unknown style s=" << s;
204 QString penStyleToString(Qt::PenStyle p)
210 return "Qt::SolidLine";
212 return "Qt::DashLine";
214 return "Qt::DotLine";
215 case Qt::DashDotLine:
216 return "Qt::DashDotLine";
217 case Qt::DashDotDotLine:
218 return "Qt::DashDotDotLine";
224 QPointF point(const QString &s, bool &ok)
228 qreal x = s.section(',', 0, 0).toFloat(&okx);
229 qreal y = s.section(',', 1, 1).toFloat(&oky);
231 return QPointF(x, y);
233 qWarning() << "misc.cpp Couldn't create QPointF from " << s
234 << " ok=" << okx << "," << oky;
239 QString pointToString(const QPointF &p)
241 return QString("%1,%2").arg(p.x()).arg(p.y());
244 void centerDialog(QDialog *dia)
246 dia->move(QCursor::pos() -
247 0.5 * QPoint(dia->rect().width(), dia->rect().height()));
250 // #include "version.h"
253 // #include <QRegExp>
255 bool versionLowerThanVym(const QString &v)
257 // returns true, if Version v < VYM_VERSION
261 return versionLowerOrEqualThanVym(v);
264 bool versionLowerOrEqualThanVym(const QString &v)
266 // returns true, if Version v <= VYM_VERSION
267 return versionLowerOrEqual(v, vymVersion);
270 bool versionLowerOrEqual(const QString &v, const QString &vstatic)
272 // returns true, if version v <= vstatic
281 QRegExp rx("(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})");
282 int pos = rx.indexIn(v);
284 v1 = rx.cap(1).toInt(&ok);
286 v2 = rx.cap(2).toInt(&ok);
288 v3 = rx.cap(3).toInt(&ok);
291 pos = rx.indexIn(vstatic);
292 if (ok && pos > -1) {
293 vs1 = rx.cap(1).toInt(&ok);
295 vs2 = rx.cap(2).toInt(&ok);
297 vs3 = rx.cap(3).toInt(&ok);
301 qWarning() << QString(
302 "Warning: Checking version failed: v=%1 vstatic=%2")