Display hovered tile coords and block in status bar

This commit is contained in:
Marcus Huderle 2018-03-04 00:09:34 -08:00
parent 470fc92fba
commit f81ab6994a
7 changed files with 52 additions and 8 deletions

View file

@ -368,10 +368,29 @@ void MapPixmapItem::redo() {
}
}
void MapPixmapItem::updateCurHoveredTile(QPointF pos) {
int x = ((int)pos.x()) / 16;
int y = ((int)pos.y()) / 16;
int blockIndex = y * map->getWidth() + x;
if (x < 0 || x >= map->getWidth() || y < 0 || y >= map->getHeight()) {
map->clearHoveredTile();
} else {
int tile = map->blockdata->blocks->at(blockIndex).tile;
map->hoveredTileChanged(x, y, tile);
}
}
void MapPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
updateCurHoveredTile(event->pos());
}
void MapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
map->clearHoveredTile();
}
void MapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
emit mouseEvent(event, this);
}
void MapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
updateCurHoveredTile(event->pos());
emit mouseEvent(event, this);
}
void MapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {

View file

@ -185,6 +185,7 @@ public:
Map *map = NULL;
MapPixmapItem(Map *map_) {
map = map_;
setAcceptHoverEvents(true);
}
bool active;
bool right_click;
@ -198,10 +199,15 @@ public:
virtual void redo();
virtual void draw();
private:
void updateCurHoveredTile(QPointF pos);
signals:
void mouseEvent(QGraphicsSceneMouseEvent *, MapPixmapItem *);
protected:
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
void mousePressEvent(QGraphicsSceneMouseEvent*);
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);

View file

@ -48,10 +48,17 @@ MainWindow::~MainWindow()
delete ui;
}
void MainWindow::setStatusBarMessage(QString message, int timeout/* = 0*/) {
statusBar()->showMessage(message, timeout);
}
void MainWindow::openProject(QString dir) {
if (dir.isNull()) {
return;
}
setStatusBarMessage(QString("Opening project %1").arg(dir));
bool already_open = (
(editor != NULL && editor != nullptr)
&& (editor->project != NULL && editor->project != nullptr)
@ -69,6 +76,8 @@ void MainWindow::openProject(QString dir) {
loadDataStructures();
populateMapList();
}
setStatusBarMessage(QString("Opened project %1").arg(dir));
}
QString MainWindow::getDefaultMap() {
@ -169,6 +178,7 @@ void MainWindow::setMap(QString map_name) {
setWindowTitle(map_name + " - " + editor->project->getProjectTitle() + " - pretmap");
connect(editor->map, SIGNAL(mapChanged(Map*)), this, SLOT(onMapChanged(Map *)));
connect(editor->map, SIGNAL(statusBarMessage(QString)), this, SLOT(setStatusBarMessage(QString)));
setRecentMap(map_name);
updateMapList();

View file

@ -25,6 +25,9 @@ public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void setStatusBarMessage(QString message, int timeout = 0);
private slots:
void on_action_Open_Project_triggered();
void on_mapList_activated(const QModelIndex &index);

View file

@ -1217,14 +1217,6 @@
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="action_Save_Project">
<property name="text">

11
map.cpp
View file

@ -734,3 +734,14 @@ void Map::addEvent(Event *event) {
bool Map::hasUnsavedChanges() {
return !history.isSaved() || !isPersistedToFile;
}
void Map::hoveredTileChanged(int x, int y, int block) {
emit statusBarMessage(QString("X: %1, Y: %2, Block: 0x%3")
.arg(x)
.arg(y)
.arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper()));
}
void Map::clearHoveredTile() {
emit statusBarMessage(QString(""));
}

3
map.h
View file

@ -182,6 +182,8 @@ public:
void cacheBorder();
bool hasUnsavedChanges();
void hoveredTileChanged(int x, int y, int block);
void clearHoveredTile();
QList<QList<QRgb> > getBlockPalettes(int metatile_index);
@ -189,6 +191,7 @@ signals:
void paintTileChanged(Map *map);
void paintCollisionChanged(Map *map);
void mapChanged(Map *map);
void statusBarMessage(QString);
public slots:
};