소스 검색

Display hovered tile coords and block in status bar

Marcus Huderle 6 년 전
부모
커밋
f81ab6994a
7개의 변경된 파일52개의 추가작업 그리고 8개의 파일을 삭제
  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 파일 보기

@@ -368,10 +368,29 @@ void MapPixmapItem::redo() {
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 389
 void MapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
372 390
     emit mouseEvent(event, this);
373 391
 }
374 392
 void MapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
393
+    updateCurHoveredTile(event->pos());
375 394
     emit mouseEvent(event, this);
376 395
 }
377 396
 void MapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {

+ 6
- 0
editor.h 파일 보기

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

+ 10
- 0
mainwindow.cpp 파일 보기

@@ -48,10 +48,17 @@ MainWindow::~MainWindow()
48 48
     delete ui;
49 49
 }
50 50
 
51
+void MainWindow::setStatusBarMessage(QString message, int timeout/* = 0*/) {
52
+    statusBar()->showMessage(message, timeout);
53
+}
54
+
51 55
 void MainWindow::openProject(QString dir) {
52 56
     if (dir.isNull()) {
53 57
         return;
54 58
     }
59
+
60
+    setStatusBarMessage(QString("Opening project %1").arg(dir));
61
+
55 62
     bool already_open = (
56 63
         (editor != NULL && editor != nullptr)
57 64
         && (editor->project != NULL && editor->project != nullptr)
@@ -69,6 +76,8 @@ void MainWindow::openProject(QString dir) {
69 76
         loadDataStructures();
70 77
         populateMapList();
71 78
     }
79
+
80
+    setStatusBarMessage(QString("Opened project %1").arg(dir));
72 81
 }
73 82
 
74 83
 QString MainWindow::getDefaultMap() {
@@ -169,6 +178,7 @@ void MainWindow::setMap(QString map_name) {
169 178
     setWindowTitle(map_name + " - " + editor->project->getProjectTitle() + " - pretmap");
170 179
 
171 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 183
     setRecentMap(map_name);
174 184
     updateMapList();

+ 3
- 0
mainwindow.h 파일 보기

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

+ 0
- 8
mainwindow.ui 파일 보기

@@ -1217,14 +1217,6 @@
1217 1217
    <addaction name="menuFile"/>
1218 1218
    <addaction name="menuEdit"/>
1219 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 1220
   <widget class="QStatusBar" name="statusBar"/>
1229 1221
   <action name="action_Save_Project">
1230 1222
    <property name="text">

+ 11
- 0
map.cpp 파일 보기

@@ -734,3 +734,14 @@ void Map::addEvent(Event *event) {
734 734
 bool Map::hasUnsavedChanges() {
735 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 파일 보기

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