diff --git a/editor.cpp b/editor.cpp index 7ae693c5..93f2657e 100755 --- a/editor.cpp +++ b/editor.cpp @@ -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) { diff --git a/editor.h b/editor.h index e099809c..15101e49 100755 --- a/editor.h +++ b/editor.h @@ -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*); diff --git a/mainwindow.cpp b/mainwindow.cpp index fd5bebc5..79e1e13e 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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(); diff --git a/mainwindow.h b/mainwindow.h index 34c94d63..67d18aa9 100755 --- a/mainwindow.h +++ b/mainwindow.h @@ -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); diff --git a/mainwindow.ui b/mainwindow.ui index 67baef37..a3f7a857 100755 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -1217,14 +1217,6 @@ - - - TopToolBarArea - - - false - - diff --git a/map.cpp b/map.cpp index 03156002..4b33c182 100755 --- a/map.cpp +++ b/map.cpp @@ -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("")); +} diff --git a/map.h b/map.h index c49d833e..01af4910 100755 --- a/map.h +++ b/map.h @@ -182,6 +182,8 @@ public: void cacheBorder(); bool hasUnsavedChanges(); + void hoveredTileChanged(int x, int y, int block); + void clearHoveredTile(); QList > 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: };