focused elements always on top

indicate connected walls
fixes int/float issues
refactoring
This commit is contained in:
2018-07-22 17:33:55 +02:00
parent c4fce6c90d
commit 423fbfc545
6 changed files with 121 additions and 69 deletions

View File

@@ -18,6 +18,12 @@ int Painter::width() {return w;}
int Painter::height() {return h;}
float Painter::radToDeg(const float rad) const {
return rad * 180 / M_PI;
}
bool Painter::isVisible(const Point2 p) {
const float x = s.xms(p.x);
const float y = s.yms(p.y);
@@ -36,69 +42,82 @@ void Painter::drawLine(const Point2 p1, const Point2 p2) {
//p->drawLine(s.xms(p1.x), s.yms(p1.y), s.xms(p2.x), s.yms(p2.y));
p->drawLine(QPointF(s.xms(p1.x), s.yms(p1.y)), QPointF(s.xms(p2.x), s.yms(p2.y)));
}
void Painter::drawLine(const Point3 p1, const Point3 p2) {
//p->drawLine(s.xms(p1.x), s.yms(p1.y), s.xms(p2.x), s.yms(p2.y));
p->drawLine(QPointF(s.xms(p1.x), s.yms(p1.y)), QPointF(s.xms(p2.x), s.yms(p2.y)));
}
float Painter::radToDeg(const float rad) const {
return rad * 180 / M_PI;
void Painter::drawLine(const float x1, const float y1, const float x2, const float y2) {
p->drawLine(QPointF(s.xms(x1), s.yms(y1)), QPointF(s.xms(x2), s.yms(y2)));
}
void Painter::drawArc(const Point2 center, const float radius, const float startAngleRad, const float spanAngleRad) {
const float wh = s.ms(radius) * 2;
const float x1 = s.xms(center.x) - wh/2;
const float y1 = s.yms(center.y) - wh/2;
p->drawArc(x1, y1, wh, wh, radToDeg(startAngleRad)*16, radToDeg(spanAngleRad)*16);
const QRectF rect(x1, y1, wh, wh);
p->drawArc(rect, radToDeg(startAngleRad)*16, radToDeg(spanAngleRad)*16);
//p->drawArc(x1, y1, wh, wh, radToDeg(startAngleRad)*16, radToDeg(spanAngleRad)*16);
}
/** draw a dot at the given map coordinates */
void Painter::drawDot(const Point2 center) {
//int r = 1;
//p->drawEllipse(QPointF(s.xms(center.x)-r, s.yms(center.y)-r), 2*r, 2*r);
p->drawPoint(QPointF(s.xms(center.x), s.yms(center.y)));
}
void Painter::drawCircle(const Point3 center) {
int r = 5;
p->drawEllipse(s.xms(center.x)-r, s.yms(center.y)-r, 2*r, 2*r);
p->drawEllipse(QPointF(s.xms(center.x), s.yms(center.y)), r, r);
}
void Painter::drawCircle(const Point2 center) {
int r = 5;
p->drawEllipse(s.xms(center.x)-r, s.yms(center.y)-r, 2*r, 2*r);
}
/** draw a dot at the given map coordinates */
void Painter::drawDot(const Point2 center) {
int r = 1;
p->drawEllipse(s.xms(center.x)-r, s.yms(center.y)-r, 2*r, 2*r);
p->drawEllipse(QPointF(s.xms(center.x), s.yms(center.y)), r, r);
}
void Painter::drawCircle(const Point2 center, const float size_m) {
int r = s.ms(size_m);
p->drawEllipse(s.xms(center.x)-r, s.yms(center.y)-r, 2*r, 2*r);
p->drawEllipse(QPointF(s.xms(center.x), s.yms(center.y)), r, r);
}
void Painter::drawCircle_px(const Point2 center, const float size_px) {
int r = size_px;
p->drawEllipse(s.xms(center.x)-r, s.yms(center.y)-r, 2*r, 2*r);
p->drawEllipse(QPointF(s.xms(center.x), s.yms(center.y)), r, r);
}
void Painter::drawNode(Point2 pt, bool focused, bool selected) {
float rs = 0.05;
if (selected) {setPenBrush(Qt::black, Qt::gray); rs = 0.08;}
else if (focused) {setPenBrush(Qt::black, Qt::white); rs = 0.08;}
else {setPenBrush(Qt::black, Qt::NoBrush); rs = 0.04;}
float rs = 4;
if (selected) {setPenBrush(Qt::black, Qt::gray); rs*=2;}
else if (focused) {setPenBrush(Qt::black, Qt::white); rs*=2;}
else {setPenBrush(Qt::black, Qt::NoBrush); rs*=1;}
const float s = this->s.getScale();
if (s > 10) {drawCircle(pt, rs);} // only at a certain zoom level
if (s > 25) {drawCircle_px(pt, rs);} // only at a certain zoom level
else if (s > 10) {drawCircle_px(pt, 1);} // only at a certain zoom level
}
void Painter::drawLine(const float x1, const float y1, const float x2, const float y2) {
p->drawLine(s.xms(x1), s.yms(y1), s.xms(x2), s.yms(y2));
}
void Painter::drawRect(const Point2 p1, const Point2 p2) {
drawRect(p1.x, p1.y, p2.x, p2.y);
}
void Painter::drawRect(const float x1, const float y1, const float x2, const float y2) {
float w = x2-x1;
float h = y1-y2;
p->drawRect(s.xms(x1), s.yms(y1), s.ms(w), s.ms(h));
const float w = x2-x1;
const float h = y1-y2;
const QRectF rect(s.xms(x1), s.yms(y1), s.ms(w), s.ms(h));
p->drawRect(rect);
//p->drawRect(s.xms(x1), s.yms(y1), s.ms(w), s.ms(h));
}
void Painter::drawRect(const Point2 center) {
@@ -107,7 +126,7 @@ void Painter::drawRect(const Point2 center) {
}
void Painter::drawText(const Point2 pos, const std::string& text) {
p->drawText(s.xms(pos.x), s.yms(pos.y), text.c_str());
p->drawText(QPointF(s.xms(pos.x), s.yms(pos.y)), text.c_str());
}
void Painter::drawPolygon(const std::vector<Point2>& points) {