Turn MapRuler dimensions into a mouse-tracking tooltip, and show in status bar
This commit is contained in:
parent
84f920bb03
commit
39aa420265
8 changed files with 147 additions and 99 deletions
|
@ -195,7 +195,7 @@ private slots:
|
||||||
void onHoveredMovementPermissionCleared();
|
void onHoveredMovementPermissionCleared();
|
||||||
void onHoveredMetatileSelectionChanged(uint16_t);
|
void onHoveredMetatileSelectionChanged(uint16_t);
|
||||||
void onHoveredMetatileSelectionCleared();
|
void onHoveredMetatileSelectionCleared();
|
||||||
void onHoveredMapMetatileChanged(int, int);
|
void onHoveredMapMetatileChanged(const QPointF &scenePos, const QPoint &screenPos);
|
||||||
void onHoveredMapMetatileCleared();
|
void onHoveredMapMetatileCleared();
|
||||||
void onHoveredMapMovementPermissionChanged(int, int);
|
void onHoveredMapMovementPermissionChanged(int, int);
|
||||||
void onHoveredMapMovementPermissionCleared();
|
void onHoveredMapMovementPermissionCleared();
|
||||||
|
|
|
@ -89,7 +89,7 @@ signals:
|
||||||
void startPaint(QGraphicsSceneMouseEvent *, MapPixmapItem *);
|
void startPaint(QGraphicsSceneMouseEvent *, MapPixmapItem *);
|
||||||
void endPaint(QGraphicsSceneMouseEvent *, MapPixmapItem *);
|
void endPaint(QGraphicsSceneMouseEvent *, MapPixmapItem *);
|
||||||
void mouseEvent(QGraphicsSceneMouseEvent *, MapPixmapItem *);
|
void mouseEvent(QGraphicsSceneMouseEvent *, MapPixmapItem *);
|
||||||
void hoveredMapMetatileChanged(int x, int y);
|
void hoveredMapMetatileChanged(const QPointF &scenePos, const QPoint &screenPos);
|
||||||
void hoveredMapMetatileCleared();
|
void hoveredMapMetatileCleared();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -9,8 +9,9 @@
|
||||||
class MapRuler : public QGraphicsItem, private QLine
|
class MapRuler : public QGraphicsItem, private QLine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MapRuler(QColor interior = Qt::yellow, QColor exterior = Qt::black)
|
MapRuler(QColor innerColor = Qt::yellow, QColor borderColor = Qt::black) :
|
||||||
: interiorColor(interior), exteriorColor(exterior)
|
innerColor(innerColor),
|
||||||
|
borderColor(borderColor)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
setAcceptedMouseButtons(Qt::RightButton);
|
setAcceptedMouseButtons(Qt::RightButton);
|
||||||
|
@ -20,17 +21,13 @@ public:
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override;
|
||||||
QPainterPath shape() const override;
|
QPainterPath shape() const override;
|
||||||
|
|
||||||
// Anchor the ruler on metatile 'tilePos' and show the ruler
|
// Anchor the ruler and make it visible
|
||||||
void setAnchor(const QPoint &tilePos);
|
void setAnchor(const QPointF &scenePos, const QPoint &screenPos);
|
||||||
// Anchor the ruler on metatile (tileX,tileY) and show the ruler
|
// Release the anchor and hide the ruler
|
||||||
void setAnchor(int tileX, int tileY) { setAnchor(QPoint(tileX, tileY)); }
|
|
||||||
// Release the ruler anchor and hide the ruler
|
|
||||||
void endAnchor();
|
void endAnchor();
|
||||||
// Set the ruler end point to metatile 'tilePos' and repaint
|
// Set the end point and repaint
|
||||||
void setEndPos(const QPoint &tilePos);
|
void setEndPos(const QPointF &scenePos, const QPoint &screenPos);
|
||||||
// Set the ruler end point to metatile (tileX, tileY) and repaint
|
|
||||||
void setEndPos(int tileX, int tileY) { setEndPos(QPoint(tileX, tileY)); }
|
|
||||||
|
|
||||||
// Ruler start point in metatiles
|
// Ruler start point in metatiles
|
||||||
QPoint anchor() const { return QLine::p1(); }
|
QPoint anchor() const { return QLine::p1(); }
|
||||||
// Ruler end point in metatiles
|
// Ruler end point in metatiles
|
||||||
|
@ -52,21 +49,25 @@ public:
|
||||||
// Ruler height in map pixels
|
// Ruler height in map pixels
|
||||||
int pixHeight() const { return height() * 16; }
|
int pixHeight() const { return height() * 16; }
|
||||||
|
|
||||||
bool mousePressed(Qt::MouseButtons buttons) { return buttons & acceptedMouseButtons(); }
|
bool isMousePressed(QGraphicsSceneMouseEvent *event) const;
|
||||||
|
bool isAnchored() const { return anchored; }
|
||||||
|
|
||||||
|
bool locked;
|
||||||
|
QString statusMessage;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QColor innerColor;
|
||||||
|
QColor borderColor;
|
||||||
QRect xRuler;
|
QRect xRuler;
|
||||||
QRect yRuler;
|
QRect yRuler;
|
||||||
QLineF cornerTick;
|
QLineF cornerTick;
|
||||||
QRect widthTextBox;
|
bool anchored;
|
||||||
QRect heightTextBox;
|
|
||||||
QColor interiorColor;
|
|
||||||
QColor exteriorColor;
|
|
||||||
|
|
||||||
static int padding;
|
|
||||||
static int thickness;
|
static int thickness;
|
||||||
|
|
||||||
void updateShape();
|
void showDimensions(const QPoint &screenPos);
|
||||||
|
void hideDimensions() const;
|
||||||
|
void updateGeometry();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAPRULER_H
|
#endif // MAPRULER_H
|
||||||
|
|
|
@ -889,23 +889,31 @@ void Editor::onSelectedMetatilesChanged() {
|
||||||
this->redrawCurrentMetatilesSelection();
|
this->redrawCurrentMetatilesSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::onHoveredMapMetatileChanged(int x, int y) {
|
void Editor::onHoveredMapMetatileChanged(const QPointF &scenePos, const QPoint &screenPos) {
|
||||||
this->playerViewRect->updateLocation(x, y);
|
QPoint pos = Metatile::coordFromPixmapCoord(scenePos);
|
||||||
this->cursorMapTileRect->updateLocation(x, y);
|
this->playerViewRect->updateLocation(pos.x(), pos.y());
|
||||||
|
this->cursorMapTileRect->updateLocation(pos.x(), pos.y());
|
||||||
|
|
||||||
if (map_item->paintingMode == MapPixmapItem::PaintMode::Metatiles
|
if (map_item->paintingMode == MapPixmapItem::PaintMode::Metatiles
|
||||||
&& x >= 0 && x < map->getWidth() && y >= 0 && y < map->getHeight()) {
|
&& pos.x() >= 0 && pos.x() < map->getWidth() && pos.y() >= 0 && pos.y() < map->getHeight()) {
|
||||||
int blockIndex = y * map->getWidth() + x;
|
int blockIndex = pos.y() * map->getWidth() + pos.x();
|
||||||
int metatileId = map->layout->blockdata->blocks->at(blockIndex).tile;
|
int metatileId = map->layout->blockdata->blocks->at(blockIndex).tile;
|
||||||
this->ui->statusBar->showMessage(QString("X: %1, Y: %2, %3, Scale = %4x")
|
this->ui->statusBar->showMessage(QString("X: %1, Y: %2, %3, Scale = %4x")
|
||||||
.arg(x)
|
.arg(pos.x())
|
||||||
.arg(y)
|
.arg(pos.y())
|
||||||
.arg(getMetatileDisplayMessage(metatileId))
|
.arg(getMetatileDisplayMessage(metatileId))
|
||||||
.arg(QString::number(pow(scale_base, scale_exp), 'g', 2)));
|
.arg(QString::number(pow(scale_base, scale_exp), 'g', 2)));
|
||||||
} else if (map_item->paintingMode == MapPixmapItem::PaintMode::EventObjects
|
} else if (map_item->paintingMode == MapPixmapItem::PaintMode::EventObjects
|
||||||
&& x >= 0 && x < map->getWidth() && y >= 0 && y < map->getHeight()) {
|
&& pos.x() >= 0 && pos.x() < map->getWidth() && pos.y() >= 0 && pos.y() < map->getHeight()) {
|
||||||
this->ui->statusBar->showMessage(QString("X: %1, Y: %2")
|
this->ui->statusBar->showMessage(QString("X: %1, Y: %2")
|
||||||
.arg(x)
|
.arg(pos.x())
|
||||||
.arg(y));
|
.arg(pos.y()));
|
||||||
|
if (this->map_ruler->isAnchored()) {
|
||||||
|
this->map_ruler->setEndPos(scenePos, screenPos);
|
||||||
|
this->ui->statusBar->showMessage(
|
||||||
|
this->ui->statusBar->currentMessage() + "; " + this->map_ruler->statusMessage
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -915,6 +923,9 @@ void Editor::onHoveredMapMetatileCleared() {
|
||||||
if (map_item->paintingMode == MapPixmapItem::PaintMode::Metatiles
|
if (map_item->paintingMode == MapPixmapItem::PaintMode::Metatiles
|
||||||
|| map_item->paintingMode == MapPixmapItem::PaintMode::EventObjects) {
|
|| map_item->paintingMode == MapPixmapItem::PaintMode::EventObjects) {
|
||||||
this->ui->statusBar->clearMessage();
|
this->ui->statusBar->clearMessage();
|
||||||
|
if (this->map_ruler->isAnchored()) {
|
||||||
|
this->ui->statusBar->showMessage(this->map_ruler->statusMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1121,13 +1132,15 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (obj_edit_mode == "select") {
|
} else if (obj_edit_mode == "select") {
|
||||||
if (!this->map_ruler->isEnabled() && this->map_ruler->mousePressed(event->buttons())) {
|
if (!this->map_ruler->isAnchored() && this->map_ruler->isMousePressed(event)) {
|
||||||
this->map_ruler->setAnchor(x, y);
|
this->map_ruler->setAnchor(event->scenePos(), event->screenPos());
|
||||||
} else if (event->type() == QEvent::GraphicsSceneMouseRelease
|
} else if (this->map_ruler->isAnchored()) {
|
||||||
&& !this->map_ruler->mousePressed(event->buttons())) {
|
if (event->buttons() & Qt::LeftButton)
|
||||||
this->map_ruler->endAnchor();
|
this->map_ruler->locked = !this->map_ruler->locked;
|
||||||
} else if (this->map_ruler->isEnabled()) {
|
if (this->map_ruler->isMousePressed(event))
|
||||||
this->map_ruler->setEndPos(x, y);
|
this->map_ruler->endAnchor();
|
||||||
|
else
|
||||||
|
this->map_ruler->setEndPos(event->scenePos(), event->screenPos());
|
||||||
}
|
}
|
||||||
} else if (obj_edit_mode == "shift" && item->map) {
|
} else if (obj_edit_mode == "shift" && item->map) {
|
||||||
static QPoint selection_origin;
|
static QPoint selection_origin;
|
||||||
|
@ -1292,8 +1305,8 @@ void Editor::displayMapMetatiles() {
|
||||||
this, SLOT(onMapStartPaint(QGraphicsSceneMouseEvent*,MapPixmapItem*)));
|
this, SLOT(onMapStartPaint(QGraphicsSceneMouseEvent*,MapPixmapItem*)));
|
||||||
connect(map_item, SIGNAL(endPaint(QGraphicsSceneMouseEvent*,MapPixmapItem*)),
|
connect(map_item, SIGNAL(endPaint(QGraphicsSceneMouseEvent*,MapPixmapItem*)),
|
||||||
this, SLOT(onMapEndPaint(QGraphicsSceneMouseEvent*,MapPixmapItem*)));
|
this, SLOT(onMapEndPaint(QGraphicsSceneMouseEvent*,MapPixmapItem*)));
|
||||||
connect(map_item, SIGNAL(hoveredMapMetatileChanged(int, int)),
|
connect(map_item, SIGNAL(hoveredMapMetatileChanged(const QPointF&, const QPoint&)),
|
||||||
this, SLOT(onHoveredMapMetatileChanged(int, int)));
|
this, SLOT(onHoveredMapMetatileChanged(const QPointF&, const QPoint&)));
|
||||||
connect(map_item, SIGNAL(hoveredMapMetatileCleared()),
|
connect(map_item, SIGNAL(hoveredMapMetatileCleared()),
|
||||||
this, SLOT(onHoveredMapMetatileCleared()));
|
this, SLOT(onHoveredMapMetatileCleared()));
|
||||||
|
|
||||||
|
|
|
@ -1346,6 +1346,9 @@ void MainWindow::on_mainTabBar_tabBarClicked(int index)
|
||||||
if (projectConfig.getEncounterJsonActive())
|
if (projectConfig.getEncounterJsonActive())
|
||||||
editor->saveEncounterTabData();
|
editor->saveEncounterTabData();
|
||||||
}
|
}
|
||||||
|
if (index != 1) {
|
||||||
|
editor->map_ruler->endAnchor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionZoom_In_triggered() {
|
void MainWindow::on_actionZoom_In_triggered() {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "editor.h"
|
#include "editor.h"
|
||||||
#include "editcommands.h"
|
#include "editcommands.h"
|
||||||
#include "mapruler.h"
|
#include "mapruler.h"
|
||||||
|
#include "metatile.h"
|
||||||
|
|
||||||
static unsigned currentActionId = 0;
|
static unsigned currentActionId = 0;
|
||||||
|
|
||||||
|
@ -56,17 +57,20 @@ void DraggablePixmapItem::bindToUserData(QComboBox *combo, QString key) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DraggablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *mouse) {
|
void DraggablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *mouse) {
|
||||||
int x = static_cast<int>(mouse->pos().x() + this->pos().x()) / 16;
|
|
||||||
int y = static_cast<int>(mouse->pos().y() + this->pos().y()) / 16;
|
|
||||||
if (mouse->buttons() & this->editor->map_ruler->acceptedMouseButtons()) {
|
|
||||||
this->editor->map_ruler->setAnchor(x, y);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
active = true;
|
active = true;
|
||||||
last_x = x;
|
QPoint pos = Metatile::coordFromPixmapCoord(mouse->scenePos());
|
||||||
last_y = y;
|
last_x = pos.x();
|
||||||
|
last_y = pos.y();
|
||||||
this->editor->selectMapEvent(this, mouse->modifiers() & Qt::ControlModifier);
|
this->editor->selectMapEvent(this, mouse->modifiers() & Qt::ControlModifier);
|
||||||
this->editor->selectingEvent = true;
|
this->editor->selectingEvent = true;
|
||||||
|
if (!this->editor->map_ruler->isAnchored() && this->editor->map_ruler->isMousePressed(mouse)) {
|
||||||
|
this->editor->map_ruler->setAnchor(mouse->scenePos(), mouse->screenPos());
|
||||||
|
} else if (this->editor->map_ruler->isAnchored()) {
|
||||||
|
if (mouse->buttons() & Qt::LeftButton)
|
||||||
|
this->editor->map_ruler->locked = !this->editor->map_ruler->locked;
|
||||||
|
if (this->editor->map_ruler->isMousePressed(mouse))
|
||||||
|
this->editor->map_ruler->endAnchor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DraggablePixmapItem::move(int x, int y) {
|
void DraggablePixmapItem::move(int x, int y) {
|
||||||
|
@ -78,12 +82,11 @@ void DraggablePixmapItem::move(int x, int y) {
|
||||||
|
|
||||||
void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
|
void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
|
||||||
if (active) {
|
if (active) {
|
||||||
int x = static_cast<int>(mouse->pos().x() + this->pos().x()) / 16;
|
QPoint pos = Metatile::coordFromPixmapCoord(mouse->scenePos());
|
||||||
int y = static_cast<int>(mouse->pos().y() + this->pos().y()) / 16;
|
emit this->editor->map_item->hoveredMapMetatileChanged(mouse->scenePos(), mouse->screenPos());
|
||||||
emit this->editor->map_item->hoveredMapMetatileChanged(x, y);
|
if (this->editor->map_ruler->isAnchored()) {
|
||||||
if (this->editor->map_ruler->isEnabled()) {
|
this->editor->map_ruler->setEndPos(mouse->scenePos(), mouse->screenPos());
|
||||||
this->editor->map_ruler->setEndPos(x, y);
|
} else if (pos.x() != last_x || pos.y() != last_y) {
|
||||||
} else if (x != last_x || y != last_y) {
|
|
||||||
QList <Event *> selectedEvents;
|
QList <Event *> selectedEvents;
|
||||||
if (editor->selected_events->contains(this)) {
|
if (editor->selected_events->contains(this)) {
|
||||||
for (DraggablePixmapItem *item : *editor->selected_events) {
|
for (DraggablePixmapItem *item : *editor->selected_events) {
|
||||||
|
@ -92,21 +95,16 @@ void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
|
||||||
} else {
|
} else {
|
||||||
selectedEvents.append(this->event);
|
selectedEvents.append(this->event);
|
||||||
}
|
}
|
||||||
editor->map->editHistory.push(new EventMove(selectedEvents, x - last_x, y - last_y, currentActionId));
|
editor->map->editHistory.push(new EventMove(selectedEvents, pos.x() - last_x, pos.y() - last_y, currentActionId));
|
||||||
last_x = x;
|
last_x = pos.x();
|
||||||
last_y = y;
|
last_y = pos.y();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DraggablePixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouse) {
|
void DraggablePixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *) {
|
||||||
if (!(mouse->buttons() & this->editor->map_ruler->acceptedMouseButtons())) {
|
active = false;
|
||||||
this->editor->map_ruler->endAnchor();
|
currentActionId++;
|
||||||
}
|
|
||||||
if (!this->editor->map_ruler->isEnabled()) {
|
|
||||||
active = false;
|
|
||||||
currentActionId++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DraggablePixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) {
|
void DraggablePixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) {
|
||||||
|
|
|
@ -742,7 +742,7 @@ void MapPixmapItem::draw(bool ignoreCache) {
|
||||||
void MapPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
void MapPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
||||||
int x = static_cast<int>(event->pos().x()) / 16;
|
int x = static_cast<int>(event->pos().x()) / 16;
|
||||||
int y = static_cast<int>(event->pos().y()) / 16;
|
int y = static_cast<int>(event->pos().y()) / 16;
|
||||||
emit this->hoveredMapMetatileChanged(x, y);
|
emit this->hoveredMapMetatileChanged(event->scenePos(), event->screenPos());
|
||||||
if (this->settings->betterCursors && this->paintingMode != MapPixmapItem::PaintMode::Disabled) {
|
if (this->settings->betterCursors && this->paintingMode != MapPixmapItem::PaintMode::Disabled) {
|
||||||
setCursor(this->settings->mapCursor);
|
setCursor(this->settings->mapCursor);
|
||||||
}
|
}
|
||||||
|
@ -769,7 +769,7 @@ void MapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
void MapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
void MapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
int x = static_cast<int>(event->pos().x()) / 16;
|
int x = static_cast<int>(event->pos().x()) / 16;
|
||||||
int y = static_cast<int>(event->pos().y()) / 16;
|
int y = static_cast<int>(event->pos().y()) / 16;
|
||||||
emit this->hoveredMapMetatileChanged(x, y);
|
emit this->hoveredMapMetatileChanged(event->scenePos(), event->screenPos());
|
||||||
emit mouseEvent(event, this);
|
emit mouseEvent(event, this);
|
||||||
}
|
}
|
||||||
void MapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
void MapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
|
|
@ -1,25 +1,28 @@
|
||||||
#include "mapruler.h"
|
#include "mapruler.h"
|
||||||
|
#include "metatile.h"
|
||||||
|
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include <QToolTip>
|
||||||
|
|
||||||
int MapRuler::padding = 24;
|
|
||||||
int MapRuler::thickness = 3;
|
int MapRuler::thickness = 3;
|
||||||
|
|
||||||
|
|
||||||
void MapRuler::init() {
|
void MapRuler::init() {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
setEnabled(false);
|
|
||||||
setPoints(QPoint(), QPoint());
|
setPoints(QPoint(), QPoint());
|
||||||
|
anchored = false;
|
||||||
|
locked = false;
|
||||||
|
statusMessage = QString("Ruler: 0");
|
||||||
xRuler = QRect();
|
xRuler = QRect();
|
||||||
yRuler = QRect();
|
yRuler = QRect();
|
||||||
widthTextBox = QRect();
|
cornerTick = QLine();
|
||||||
heightTextBox = QRect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF MapRuler::boundingRect() const {
|
QRectF MapRuler::boundingRect() const {
|
||||||
return QRectF(-padding, -padding, pixWidth() + padding * 2, pixHeight() + padding * 2);
|
return QRectF(-thickness, -thickness, pixWidth() + thickness * 2, pixHeight() + thickness * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPainterPath MapRuler::shape() const {
|
QPainterPath MapRuler::shape() const {
|
||||||
|
@ -36,69 +39,99 @@ QPainterPath MapRuler::shape() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapRuler::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) {
|
void MapRuler::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) {
|
||||||
painter->setPen(exteriorColor);
|
painter->setPen(QPen(borderColor));
|
||||||
painter->setBrush(QBrush(interiorColor));
|
painter->setBrush(QBrush(innerColor));
|
||||||
painter->drawPath(shape());
|
painter->drawPath(shape());
|
||||||
if (width() && height())
|
if (deltaX() && deltaY())
|
||||||
painter->drawLine(cornerTick);
|
painter->drawLine(cornerTick);
|
||||||
painter->drawText(widthTextBox, Qt::AlignCenter, QString("%1").arg(width()));
|
|
||||||
painter->drawText(heightTextBox, Qt::AlignCenter, QString("%1").arg(height()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapRuler::setAnchor(const QPoint &tilePos) {
|
void MapRuler::setAnchor(const QPointF &scenePos, const QPoint &screenPos) {
|
||||||
setEnabled(true);
|
anchored = true;
|
||||||
|
locked = false;
|
||||||
|
QPoint tilePos = Metatile::coordFromPixmapCoord(scenePos);
|
||||||
setPoints(tilePos, tilePos);
|
setPoints(tilePos, tilePos);
|
||||||
updateShape();
|
updateGeometry();
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
|
showDimensions(screenPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapRuler::endAnchor() {
|
void MapRuler::endAnchor() {
|
||||||
setVisible(false);
|
hideDimensions();
|
||||||
setEnabled(false);
|
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapRuler::setEndPos(const QPoint &tilePos) {
|
void MapRuler::setEndPos(const QPointF &scenePos, const QPoint &screenPos) {
|
||||||
if (!isEnabled() || (tilePos == endPos() && tilePos != anchor()))
|
if (locked)
|
||||||
return;
|
return;
|
||||||
prepareGeometryChange();
|
QPoint pos = Metatile::coordFromPixmapCoord(scenePos);
|
||||||
setP2(tilePos);
|
QPoint lastEndPos = endPos();
|
||||||
updateShape();
|
setP2(pos);
|
||||||
|
if (pos != lastEndPos)
|
||||||
|
updateGeometry();
|
||||||
|
showDimensions(screenPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapRuler::updateShape() {
|
bool MapRuler::isMousePressed(QGraphicsSceneMouseEvent *event) const {
|
||||||
|
return event->buttons() & acceptedMouseButtons() && event->type() == QEvent::GraphicsSceneMousePress;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapRuler::showDimensions(const QPoint &screenPos) {
|
||||||
|
// This is a hack to make the tool tip follow the cursor since it won't change position if the text is the same.
|
||||||
|
QToolTip::showText(screenPos + QPoint(16, -8), statusMessage + ' ');
|
||||||
|
QToolTip::showText(screenPos + QPoint(16, -8), statusMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapRuler::hideDimensions() const {
|
||||||
|
QToolTip::hideText();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapRuler::updateGeometry() {
|
||||||
|
prepareGeometryChange();
|
||||||
setPos(QPoint(left() * 16 + 7, top() * 16 + 7));
|
setPos(QPoint(left() * 16 + 7, top() * 16 + 7));
|
||||||
/* Determines what quadrant the ruler exists in, relative to the anchor point. The anchor point
|
/* Determine what quadrant the end point is in relative to the anchor point. The anchor
|
||||||
* is the top-left corner of the metatile the ruler starts in, so a zero-length(s) ruler is
|
* point is the top-left corner of the metatile the ruler starts in, so a zero-length(s)
|
||||||
* treated as being in the bottom-right quadrant from the anchor point. */
|
* ruler is considered to be in the bottom-right quadrant from the anchor point. */
|
||||||
if (deltaX() < 0 && deltaY() < 0) {
|
if (deltaX() < 0 && deltaY() < 0) {
|
||||||
// Top-left
|
// Top-left
|
||||||
xRuler = QRect(0, pixHeight(), pixWidth() + thickness, thickness);
|
xRuler = QRect(0, pixHeight(), pixWidth() + thickness, thickness);
|
||||||
yRuler = QRect(0, 0, thickness, pixHeight() + thickness);
|
yRuler = QRect(0, 0, thickness, pixHeight() + thickness);
|
||||||
cornerTick = QLineF(yRuler.x() + 0.5, xRuler.y() + thickness - 0.5, yRuler.x() + thickness, xRuler.y());
|
cornerTick = QLineF(yRuler.x() + 0.5, xRuler.y() + thickness - 0.5, yRuler.x() + thickness, xRuler.y());
|
||||||
widthTextBox = QRect(0, pixHeight(), pixWidth(), padding);
|
statusMessage = QString("Ruler: Left %1, Up %2").arg(width()).arg(height());
|
||||||
heightTextBox = QRect(-padding, 0, padding, pixHeight());
|
|
||||||
} else if (deltaX() < 0) {
|
} else if (deltaX() < 0) {
|
||||||
// Bottom-left
|
// Bottom-left
|
||||||
xRuler = QRect(0, 0, pixWidth() + thickness, thickness);
|
xRuler = QRect(0, 0, pixWidth() + thickness, thickness);
|
||||||
yRuler = QRect(0, 0, thickness, pixHeight() + thickness);
|
yRuler = QRect(0, 0, thickness, pixHeight() + thickness);
|
||||||
cornerTick = QLineF(xRuler.x() + 0.5, xRuler.y() + 0.5, xRuler.x() + thickness, xRuler.y() + thickness);
|
cornerTick = QLineF(xRuler.x() + 0.5, xRuler.y() + 0.5, xRuler.x() + thickness, xRuler.y() + thickness);
|
||||||
widthTextBox = QRect(0, -padding, pixWidth(), padding);
|
statusMessage = QString("Ruler: Left %1").arg(width());
|
||||||
heightTextBox = QRect(-padding, 0, padding, pixHeight());
|
if (deltaY())
|
||||||
|
statusMessage += QString(", Down %1").arg(height());
|
||||||
} else if (deltaY() < 0) {
|
} else if (deltaY() < 0) {
|
||||||
// Top-right
|
// Top-right
|
||||||
xRuler = QRect(0, pixHeight(), pixWidth() + thickness, thickness);
|
xRuler = QRect(0, pixHeight(), pixWidth() + thickness, thickness);
|
||||||
yRuler = QRect(pixWidth(), 0, thickness, pixHeight() + thickness);
|
yRuler = QRect(pixWidth(), 0, thickness, pixHeight() + thickness);
|
||||||
cornerTick = QLineF(yRuler.x(), xRuler.y(), yRuler.x() + thickness - 0.5, xRuler.y() + thickness - 0.5);
|
cornerTick = QLineF(yRuler.x(), xRuler.y(), yRuler.x() + thickness - 0.5, xRuler.y() + thickness - 0.5);
|
||||||
widthTextBox = QRect(0, pixHeight(), pixWidth(), padding);
|
statusMessage = QString("Ruler: ");
|
||||||
heightTextBox = QRect(pixWidth(), 0, padding, pixHeight());
|
if (deltaX())
|
||||||
|
statusMessage += QString("Right %1, ").arg(width());
|
||||||
|
statusMessage += QString("Up %1").arg(height());
|
||||||
} else {
|
} else {
|
||||||
// Bottom-right
|
// Bottom-right
|
||||||
xRuler = QRect(0, 0, pixWidth() + thickness, thickness);
|
xRuler = QRect(0, 0, pixWidth() + thickness, thickness);
|
||||||
yRuler = QRect(pixWidth(), 0, thickness, pixHeight() + thickness);
|
yRuler = QRect(pixWidth(), 0, thickness, pixHeight() + thickness);
|
||||||
cornerTick = QLineF(yRuler.x(), yRuler.y() + thickness, yRuler.x() + thickness - 0.5, yRuler.y() + 0.5);
|
cornerTick = QLineF(yRuler.x(), yRuler.y() + thickness, yRuler.x() + thickness - 0.5, yRuler.y() + 0.5);
|
||||||
widthTextBox = QRect(0, -padding, pixWidth(), padding);
|
statusMessage = QString("Ruler: ");
|
||||||
heightTextBox = QRect(pixWidth(), 0, padding, pixHeight());
|
if (deltaX() || deltaY()) {
|
||||||
|
if (deltaX())
|
||||||
|
statusMessage += QString("Right %1").arg(width());
|
||||||
|
if (deltaY()) {
|
||||||
|
if (deltaX())
|
||||||
|
statusMessage += ", ";
|
||||||
|
statusMessage += QString("Down: %1").arg(height());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
statusMessage += QString("0");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue