2019-01-11 14:52:35 +00:00
|
|
|
#ifndef CURSORTILERECT_H
|
|
|
|
#define CURSORTILERECT_H
|
|
|
|
|
|
|
|
#include <QGraphicsItem>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QRgb>
|
|
|
|
|
|
|
|
class CursorTileRect : public QGraphicsItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CursorTileRect(bool *enabled, QRgb color);
|
|
|
|
QRectF boundingRect() const override
|
|
|
|
{
|
|
|
|
int width = this->width;
|
|
|
|
int height = this->height;
|
|
|
|
if (this->singleTileMode) {
|
|
|
|
width = 16;
|
|
|
|
height = 16;
|
|
|
|
} else if (!this->rightClickSelectionAnchored && this->smartPathMode && this->selectionHeight == 3 && this->selectionWidth == 3) {
|
|
|
|
width = 32;
|
|
|
|
height = 32;
|
|
|
|
}
|
|
|
|
qreal penWidth = 4;
|
|
|
|
return QRectF(-penWidth,
|
|
|
|
-penWidth,
|
|
|
|
width + penWidth * 2,
|
|
|
|
height + penWidth * 2);
|
|
|
|
}
|
|
|
|
|
2019-08-07 04:35:02 +01:00
|
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
|
2019-01-11 14:52:35 +00:00
|
|
|
{
|
2019-01-16 05:06:25 +00:00
|
|
|
if (!(*enabled)) return;
|
2019-01-11 14:52:35 +00:00
|
|
|
int width = this->width;
|
|
|
|
int height = this->height;
|
|
|
|
if (this->singleTileMode) {
|
|
|
|
width = 16;
|
|
|
|
height = 16;
|
|
|
|
} else if (this->smartPathInEffect()) {
|
|
|
|
width = 32;
|
|
|
|
height = 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
painter->setPen(this->color);
|
|
|
|
painter->drawRect(-1, -1, width + 2, height + 2);
|
|
|
|
painter->setPen(QColor(0, 0, 0));
|
|
|
|
painter->drawRect(-2, -2, width + 4, height + 4);
|
|
|
|
painter->drawRect(0, 0, width, height);
|
|
|
|
}
|
|
|
|
void initAnchor(int coordX, int coordY);
|
|
|
|
void stopAnchor();
|
|
|
|
void initRightClickSelectionAnchor(int coordX, int coordY);
|
|
|
|
void stopRightClickSelectionAnchor();
|
2020-08-25 21:32:40 +01:00
|
|
|
void setSmartPathMode(bool enable);
|
2019-01-11 14:52:35 +00:00
|
|
|
bool getSmartPathMode() { return this->smartPathMode; }
|
2020-08-25 21:32:40 +01:00
|
|
|
void setStraightPathMode(bool enable);
|
2020-08-21 17:02:48 +01:00
|
|
|
bool getStraightPathMode() { return this->straightPathMode; }
|
2019-01-11 14:52:35 +00:00
|
|
|
void setSingleTileMode();
|
|
|
|
void stopSingleTileMode();
|
|
|
|
void updateLocation(int x, int y);
|
|
|
|
void updateSelectionSize(int width, int height);
|
2019-01-11 14:52:44 +00:00
|
|
|
void setVisibility(bool visible);
|
2019-01-11 14:52:35 +00:00
|
|
|
bool *enabled;
|
|
|
|
private:
|
2019-01-11 14:52:44 +00:00
|
|
|
bool visible;
|
2019-01-11 14:52:35 +00:00
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
bool anchored;
|
|
|
|
bool rightClickSelectionAnchored;
|
|
|
|
bool smartPathMode;
|
2020-08-21 17:02:48 +01:00
|
|
|
bool straightPathMode;
|
2019-01-11 14:52:35 +00:00
|
|
|
bool singleTileMode;
|
|
|
|
int anchorCoordX;
|
|
|
|
int anchorCoordY;
|
|
|
|
int selectionWidth;
|
|
|
|
int selectionHeight;
|
|
|
|
QRgb color;
|
|
|
|
bool smartPathInEffect();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // CURSORTILERECT_H
|