Clean up rotation functions

This commit is contained in:
GriffinR 2022-10-13 15:14:53 -04:00 committed by Marcus Huderle
parent ad5eea2293
commit 47f6723bd2
4 changed files with 33 additions and 26 deletions

View file

@ -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);

View file

@ -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<int> xCoords, QList<int> yCoords, QString borderColorStr, QString fillColorStr);
private:
void clampAngle();
QColor getColor(QString colorStr);
QList<OverlayItem*> items;
int x;
int y;
int rotation;
int angle;
qreal hScale;
qreal vScale;
bool hidden;

View file

@ -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();
}

View file

@ -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) {