Display hovered tile coords and block in status bar
This commit is contained in:
parent
470fc92fba
commit
f81ab6994a
7 changed files with 52 additions and 8 deletions
19
editor.cpp
19
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) {
|
void MapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
emit mouseEvent(event, this);
|
emit mouseEvent(event, this);
|
||||||
}
|
}
|
||||||
void MapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
void MapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
updateCurHoveredTile(event->pos());
|
||||||
emit mouseEvent(event, this);
|
emit mouseEvent(event, this);
|
||||||
}
|
}
|
||||||
void MapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
void MapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
|
6
editor.h
6
editor.h
|
@ -185,6 +185,7 @@ public:
|
||||||
Map *map = NULL;
|
Map *map = NULL;
|
||||||
MapPixmapItem(Map *map_) {
|
MapPixmapItem(Map *map_) {
|
||||||
map = map_;
|
map = map_;
|
||||||
|
setAcceptHoverEvents(true);
|
||||||
}
|
}
|
||||||
bool active;
|
bool active;
|
||||||
bool right_click;
|
bool right_click;
|
||||||
|
@ -198,10 +199,15 @@ public:
|
||||||
virtual void redo();
|
virtual void redo();
|
||||||
virtual void draw();
|
virtual void draw();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateCurHoveredTile(QPointF pos);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void mouseEvent(QGraphicsSceneMouseEvent *, MapPixmapItem *);
|
void mouseEvent(QGraphicsSceneMouseEvent *, MapPixmapItem *);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
|
||||||
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
|
|
@ -48,10 +48,17 @@ MainWindow::~MainWindow()
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::setStatusBarMessage(QString message, int timeout/* = 0*/) {
|
||||||
|
statusBar()->showMessage(message, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::openProject(QString dir) {
|
void MainWindow::openProject(QString dir) {
|
||||||
if (dir.isNull()) {
|
if (dir.isNull()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setStatusBarMessage(QString("Opening project %1").arg(dir));
|
||||||
|
|
||||||
bool already_open = (
|
bool already_open = (
|
||||||
(editor != NULL && editor != nullptr)
|
(editor != NULL && editor != nullptr)
|
||||||
&& (editor->project != NULL && editor->project != nullptr)
|
&& (editor->project != NULL && editor->project != nullptr)
|
||||||
|
@ -69,6 +76,8 @@ void MainWindow::openProject(QString dir) {
|
||||||
loadDataStructures();
|
loadDataStructures();
|
||||||
populateMapList();
|
populateMapList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setStatusBarMessage(QString("Opened project %1").arg(dir));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MainWindow::getDefaultMap() {
|
QString MainWindow::getDefaultMap() {
|
||||||
|
@ -169,6 +178,7 @@ void MainWindow::setMap(QString map_name) {
|
||||||
setWindowTitle(map_name + " - " + editor->project->getProjectTitle() + " - pretmap");
|
setWindowTitle(map_name + " - " + editor->project->getProjectTitle() + " - pretmap");
|
||||||
|
|
||||||
connect(editor->map, SIGNAL(mapChanged(Map*)), this, SLOT(onMapChanged(Map *)));
|
connect(editor->map, SIGNAL(mapChanged(Map*)), this, SLOT(onMapChanged(Map *)));
|
||||||
|
connect(editor->map, SIGNAL(statusBarMessage(QString)), this, SLOT(setStatusBarMessage(QString)));
|
||||||
|
|
||||||
setRecentMap(map_name);
|
setRecentMap(map_name);
|
||||||
updateMapList();
|
updateMapList();
|
||||||
|
|
|
@ -25,6 +25,9 @@ public:
|
||||||
explicit MainWindow(QWidget *parent = 0);
|
explicit MainWindow(QWidget *parent = 0);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setStatusBarMessage(QString message, int timeout = 0);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_action_Open_Project_triggered();
|
void on_action_Open_Project_triggered();
|
||||||
void on_mapList_activated(const QModelIndex &index);
|
void on_mapList_activated(const QModelIndex &index);
|
||||||
|
|
|
@ -1217,14 +1217,6 @@
|
||||||
<addaction name="menuFile"/>
|
<addaction name="menuFile"/>
|
||||||
<addaction name="menuEdit"/>
|
<addaction name="menuEdit"/>
|
||||||
</widget>
|
</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"/>
|
<widget class="QStatusBar" name="statusBar"/>
|
||||||
<action name="action_Save_Project">
|
<action name="action_Save_Project">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
11
map.cpp
11
map.cpp
|
@ -734,3 +734,14 @@ void Map::addEvent(Event *event) {
|
||||||
bool Map::hasUnsavedChanges() {
|
bool Map::hasUnsavedChanges() {
|
||||||
return !history.isSaved() || !isPersistedToFile;
|
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
3
map.h
|
@ -182,6 +182,8 @@ public:
|
||||||
void cacheBorder();
|
void cacheBorder();
|
||||||
|
|
||||||
bool hasUnsavedChanges();
|
bool hasUnsavedChanges();
|
||||||
|
void hoveredTileChanged(int x, int y, int block);
|
||||||
|
void clearHoveredTile();
|
||||||
|
|
||||||
QList<QList<QRgb> > getBlockPalettes(int metatile_index);
|
QList<QList<QRgb> > getBlockPalettes(int metatile_index);
|
||||||
|
|
||||||
|
@ -189,6 +191,7 @@ signals:
|
||||||
void paintTileChanged(Map *map);
|
void paintTileChanged(Map *map);
|
||||||
void paintCollisionChanged(Map *map);
|
void paintCollisionChanged(Map *map);
|
||||||
void mapChanged(Map *map);
|
void mapChanged(Map *map);
|
||||||
|
void statusBarMessage(QString);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue