diff --git a/include/ui/mapview.h b/include/ui/mapview.h index 2059e93c..62d5e461 100644 --- a/include/ui/mapview.h +++ b/include/ui/mapview.h @@ -44,15 +44,15 @@ public: Q_INVOKABLE int getOpacity(int layer = 0); Q_INVOKABLE void setOpacity(int opacity, int layer); Q_INVOKABLE void setOpacity(int opacity); - Q_INVOKABLE int getHorizontalScale(int layer); - Q_INVOKABLE int getVerticalScale(int layer); + Q_INVOKABLE int getHorizontalScale(int layer = 0); + Q_INVOKABLE int getVerticalScale(int layer = 0); Q_INVOKABLE void setHorizontalScale(int scale, int layer); Q_INVOKABLE void setHorizontalScale(int scale); Q_INVOKABLE void setVerticalScale(int scale, int layer); Q_INVOKABLE void setVerticalScale(int scale); - Q_INVOKABLE int getRotation(int layer); - Q_INVOKABLE void setRotation(int rotation, int layer); - Q_INVOKABLE void setRotation(int rotation); + Q_INVOKABLE int getAngle(int layer = 0); + Q_INVOKABLE void setAngle(int angle, int layer); + Q_INVOKABLE void setAngle(int angle); Q_INVOKABLE void rotate(int degrees, int layer); Q_INVOKABLE void rotate(int degrees); Q_INVOKABLE void addText(QString text, int x, int y, QString color = "#000000", int fontSize = 12, int layer = 0); diff --git a/include/ui/overlay.h b/include/ui/overlay.h index 4cfc513c..dfdfea16 100644 --- a/include/ui/overlay.h +++ b/include/ui/overlay.h @@ -70,7 +70,7 @@ public: Overlay() { this->x = 0; this->y = 0; - this->rotation = 0; + this->angle = 0; this->hScale = 1.0; this->vScale = 1.0; this->hidden = false; @@ -92,8 +92,8 @@ public: int getVScale(); void setHScale(int scale); void setVScale(int scale); - int getRotation(); - void setRotation(int rotation); + int getAngle(); + void setAngle(int angle); void rotate(int degrees); void setClippingRect(QRectF rect); void clearClippingRect(); @@ -108,11 +108,12 @@ public: bool addImage(int x, int y, QImage image); bool addPath(QList xCoords, QList yCoords, QString borderColorStr, QString fillColorStr); private: + void clampAngle(); QColor getColor(QString colorStr); QList items; int x; int y; - int rotation; + int angle; qreal hScale; qreal vScale; bool hidden; diff --git a/src/scriptapi/apioverlay.cpp b/src/scriptapi/apioverlay.cpp index 34b9f9a3..61178c33 100644 --- a/src/scriptapi/apioverlay.cpp +++ b/src/scriptapi/apioverlay.cpp @@ -179,19 +179,19 @@ void MapView::setVerticalScale(int scale) { this->scene()->update(); } -int MapView::getRotation(int layer) { - return this->getOverlay(layer)->getRotation(); +int MapView::getAngle(int layer) { + return this->getOverlay(layer)->getAngle(); } -void MapView::setRotation(int rotation, int layer) { - this->getOverlay(layer)->setRotation(rotation); +void MapView::setAngle(int angle, int layer) { + this->getOverlay(layer)->setAngle(angle); this->scene()->update(); } -// Overload. No layer provided, set rotation of all layers -void MapView::setRotation(int rotation) { +// Overload. No layer provided, set angle of all layers +void MapView::setAngle(int angle) { foreach (Overlay * layer, this->overlayMap) - layer->setRotation(rotation); + layer->setAngle(angle); this->scene()->update(); } diff --git a/src/ui/overlay.cpp b/src/ui/overlay.cpp index 7e3fdf16..374c09be 100644 --- a/src/ui/overlay.cpp +++ b/src/ui/overlay.cpp @@ -27,14 +27,10 @@ void Overlay::renderItems(QPainter *painter) { QTransform transform = painter->transform(); transform.translate(this->x, this->y); - transform.rotate(this->rotation); + transform.rotate(this->angle); transform.scale(this->hScale, this->vScale); painter->setTransform(transform); - /*painter->translate(this->x, this->y); - painter->rotate(this->rotation); - painter->scale(this->hScale, this->vScale);*/ - if (this->clippingRect) { painter->setClipping(true); painter->setClipRect(*this->clippingRect); @@ -110,16 +106,26 @@ void Overlay::setVScale(int scale) { this->vScale = scale; } -int Overlay::getRotation() { - return this->rotation; +int Overlay::getAngle() { + return this->angle; } -void Overlay::setRotation(int rotation) { - this->rotation = rotation; +void Overlay::setAngle(int angle) { + this->angle = angle; + this->clampAngle(); } void Overlay::rotate(int degrees) { - this->rotation += degrees; + this->angle += degrees; + this->clampAngle(); +} + +void Overlay::clampAngle() { + // transform.rotate would handle this already, but we only + // want to report angles 0-359 for Overlay::getAngle + this->angle %= 360; + if (this->angle < 0) + this->angle += 360; } void Overlay::setClippingRect(QRectF rect) {