Browse Source

Display hovered tile coords and block in status bar

Marcus Huderle 6 years ago
parent
commit
f81ab6994a
7 changed files with 52 additions and 8 deletions
  1. 19
    0
      editor.cpp
  2. 6
    0
      editor.h
  3. 10
    0
      mainwindow.cpp
  4. 3
    0
      mainwindow.h
  5. 0
    8
      mainwindow.ui
  6. 11
    0
      map.cpp
  7. 3
    0
      map.h

+ 19
- 0
editor.cpp View File

368
     }
368
     }
369
 }
369
 }
370
 
370
 
371
+void MapPixmapItem::updateCurHoveredTile(QPointF pos) {
372
+    int x = ((int)pos.x()) / 16;
373
+    int y = ((int)pos.y()) / 16;
374
+    int blockIndex = y * map->getWidth() + x;
375
+    if (x < 0 || x >= map->getWidth() || y < 0 || y >= map->getHeight()) {
376
+        map->clearHoveredTile();
377
+    } else {
378
+        int tile = map->blockdata->blocks->at(blockIndex).tile;
379
+        map->hoveredTileChanged(x, y, tile);
380
+    }
381
+}
382
+
383
+void MapPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
384
+    updateCurHoveredTile(event->pos());
385
+}
386
+void MapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
387
+    map->clearHoveredTile();
388
+}
371
 void MapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
389
 void MapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
372
     emit mouseEvent(event, this);
390
     emit mouseEvent(event, this);
373
 }
391
 }
374
 void MapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
392
 void MapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
393
+    updateCurHoveredTile(event->pos());
375
     emit mouseEvent(event, this);
394
     emit mouseEvent(event, this);
376
 }
395
 }
377
 void MapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
396
 void MapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {

+ 6
- 0
editor.h View File

185
     Map *map = NULL;
185
     Map *map = NULL;
186
     MapPixmapItem(Map *map_) {
186
     MapPixmapItem(Map *map_) {
187
         map = map_;
187
         map = map_;
188
+        setAcceptHoverEvents(true);
188
     }
189
     }
189
     bool active;
190
     bool active;
190
     bool right_click;
191
     bool right_click;
198
     virtual void redo();
199
     virtual void redo();
199
     virtual void draw();
200
     virtual void draw();
200
 
201
 
202
+private:
203
+    void updateCurHoveredTile(QPointF pos);
204
+
201
 signals:
205
 signals:
202
     void mouseEvent(QGraphicsSceneMouseEvent *, MapPixmapItem *);
206
     void mouseEvent(QGraphicsSceneMouseEvent *, MapPixmapItem *);
203
 
207
 
204
 protected:
208
 protected:
209
+    void hoverMoveEvent(QGraphicsSceneHoverEvent*);
210
+    void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
205
     void mousePressEvent(QGraphicsSceneMouseEvent*);
211
     void mousePressEvent(QGraphicsSceneMouseEvent*);
206
     void mouseMoveEvent(QGraphicsSceneMouseEvent*);
212
     void mouseMoveEvent(QGraphicsSceneMouseEvent*);
207
     void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
213
     void mouseReleaseEvent(QGraphicsSceneMouseEvent*);

+ 10
- 0
mainwindow.cpp View File

48
     delete ui;
48
     delete ui;
49
 }
49
 }
50
 
50
 
51
+void MainWindow::setStatusBarMessage(QString message, int timeout/* = 0*/) {
52
+    statusBar()->showMessage(message, timeout);
53
+}
54
+
51
 void MainWindow::openProject(QString dir) {
55
 void MainWindow::openProject(QString dir) {
52
     if (dir.isNull()) {
56
     if (dir.isNull()) {
53
         return;
57
         return;
54
     }
58
     }
59
+
60
+    setStatusBarMessage(QString("Opening project %1").arg(dir));
61
+
55
     bool already_open = (
62
     bool already_open = (
56
         (editor != NULL && editor != nullptr)
63
         (editor != NULL && editor != nullptr)
57
         && (editor->project != NULL && editor->project != nullptr)
64
         && (editor->project != NULL && editor->project != nullptr)
69
         loadDataStructures();
76
         loadDataStructures();
70
         populateMapList();
77
         populateMapList();
71
     }
78
     }
79
+
80
+    setStatusBarMessage(QString("Opened project %1").arg(dir));
72
 }
81
 }
73
 
82
 
74
 QString MainWindow::getDefaultMap() {
83
 QString MainWindow::getDefaultMap() {
169
     setWindowTitle(map_name + " - " + editor->project->getProjectTitle() + " - pretmap");
178
     setWindowTitle(map_name + " - " + editor->project->getProjectTitle() + " - pretmap");
170
 
179
 
171
     connect(editor->map, SIGNAL(mapChanged(Map*)), this, SLOT(onMapChanged(Map *)));
180
     connect(editor->map, SIGNAL(mapChanged(Map*)), this, SLOT(onMapChanged(Map *)));
181
+    connect(editor->map, SIGNAL(statusBarMessage(QString)), this, SLOT(setStatusBarMessage(QString)));
172
 
182
 
173
     setRecentMap(map_name);
183
     setRecentMap(map_name);
174
     updateMapList();
184
     updateMapList();

+ 3
- 0
mainwindow.h View File

25
     explicit MainWindow(QWidget *parent = 0);
25
     explicit MainWindow(QWidget *parent = 0);
26
     ~MainWindow();
26
     ~MainWindow();
27
 
27
 
28
+public slots:
29
+    void setStatusBarMessage(QString message, int timeout = 0);
30
+
28
 private slots:
31
 private slots:
29
     void on_action_Open_Project_triggered();
32
     void on_action_Open_Project_triggered();
30
     void on_mapList_activated(const QModelIndex &index);
33
     void on_mapList_activated(const QModelIndex &index);

+ 0
- 8
mainwindow.ui View File

1217
    <addaction name="menuFile"/>
1217
    <addaction name="menuFile"/>
1218
    <addaction name="menuEdit"/>
1218
    <addaction name="menuEdit"/>
1219
   </widget>
1219
   </widget>
1220
-  <widget class="QToolBar" name="mainToolBar">
1221
-   <attribute name="toolBarArea">
1222
-    <enum>TopToolBarArea</enum>
1223
-   </attribute>
1224
-   <attribute name="toolBarBreak">
1225
-    <bool>false</bool>
1226
-   </attribute>
1227
-  </widget>
1228
   <widget class="QStatusBar" name="statusBar"/>
1220
   <widget class="QStatusBar" name="statusBar"/>
1229
   <action name="action_Save_Project">
1221
   <action name="action_Save_Project">
1230
    <property name="text">
1222
    <property name="text">

+ 11
- 0
map.cpp View File

734
 bool Map::hasUnsavedChanges() {
734
 bool Map::hasUnsavedChanges() {
735
     return !history.isSaved() || !isPersistedToFile;
735
     return !history.isSaved() || !isPersistedToFile;
736
 }
736
 }
737
+
738
+void Map::hoveredTileChanged(int x, int y, int block) {
739
+    emit statusBarMessage(QString("X: %1, Y: %2, Block: 0x%3")
740
+                          .arg(x)
741
+                          .arg(y)
742
+                          .arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper()));
743
+}
744
+
745
+void Map::clearHoveredTile() {
746
+    emit statusBarMessage(QString(""));
747
+}

+ 3
- 0
map.h View File

182
     void cacheBorder();
182
     void cacheBorder();
183
 
183
 
184
     bool hasUnsavedChanges();
184
     bool hasUnsavedChanges();
185
+    void hoveredTileChanged(int x, int y, int block);
186
+    void clearHoveredTile();
185
 
187
 
186
     QList<QList<QRgb> > getBlockPalettes(int metatile_index);
188
     QList<QList<QRgb> > getBlockPalettes(int metatile_index);
187
 
189
 
189
     void paintTileChanged(Map *map);
191
     void paintTileChanged(Map *map);
190
     void paintCollisionChanged(Map *map);
192
     void paintCollisionChanged(Map *map);
191
     void mapChanged(Map *map);
193
     void mapChanged(Map *map);
194
+    void statusBarMessage(QString);
192
 
195
 
193
 public slots:
196
 public slots:
194
 };
197
 };