Kaynağa Gözat

Merge pull request #25 from huderlem/grid

Add map grid toggling
yenatch 6 yıl önce
ebeveyn
işleme
d667a0caad
No account linked to committer's email address
5 değiştirilmiş dosya ile 138 ekleme ve 97 silme
  1. 19
    0
      editor.cpp
  2. 3
    0
      editor.h
  3. 1
    0
      mainwindow.cpp
  4. 2
    0
      mainwindow.h
  5. 113
    97
      mainwindow.ui

+ 19
- 0
editor.cpp Dosyayı Görüntüle

@@ -1,4 +1,5 @@
1 1
 #include "editor.h"
2
+#include <QCheckBox>
2 3
 #include <QPainter>
3 4
 #include <QMouseEvent>
4 5
 
@@ -156,6 +157,7 @@ void Editor::displayMap() {
156 157
     displayMapObjects();
157 158
     displayMapConnections();
158 159
     displayMapBorder();
160
+    displayMapGrid();
159 161
 }
160 162
 
161 163
 void Editor::displayMetatiles() {
@@ -244,6 +246,23 @@ void Editor::displayMapBorder() {
244 246
     }
245 247
 }
246 248
 
249
+void Editor::displayMapGrid() {
250
+    int pixelWidth = map->getWidth() * 16;
251
+    int pixelHeight = map->getHeight() * 16;
252
+    for (int i = 0; i <= map->getWidth(); i++) {
253
+        int x = i * 16;
254
+        QGraphicsLineItem *line = scene->addLine(x, 0, x, pixelHeight);
255
+        line->setVisible(gridToggleCheckbox->isChecked());
256
+        connect(gridToggleCheckbox, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
257
+    }
258
+    for (int j = 0; j <= map->getHeight(); j++) {
259
+        int y = j * 16;
260
+        QGraphicsLineItem *line = scene->addLine(0, y, pixelWidth, y);
261
+        line->setVisible(gridToggleCheckbox->isChecked());
262
+        connect(gridToggleCheckbox, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
263
+    }
264
+}
265
+
247 266
 void MetatilesPixmapItem::paintTileChanged(Map *map) {
248 267
     draw();
249 268
 }

+ 3
- 0
editor.h Dosyayı Görüntüle

@@ -6,6 +6,7 @@
6 6
 #include <QGraphicsSceneMouseEvent>
7 7
 #include <QGraphicsItemAnimation>
8 8
 #include <QComboBox>
9
+#include <QCheckBox>
9 10
 
10 11
 #include "project.h"
11 12
 
@@ -25,6 +26,7 @@ public:
25 26
     QObject *parent = NULL;
26 27
     Project *project = NULL;
27 28
     Map *map = NULL;
29
+    QCheckBox *gridToggleCheckbox = NULL;
28 30
     void saveProject();
29 31
     void save();
30 32
     void undo();
@@ -37,6 +39,7 @@ public:
37 39
     void displayMapObjects();
38 40
     void displayMapConnections();
39 41
     void displayMapBorder();
42
+    void displayMapGrid();
40 43
 
41 44
     void setEditingMap();
42 45
     void setEditingCollision();

+ 1
- 0
mainwindow.cpp Dosyayı Görüntüle

@@ -27,6 +27,7 @@ MainWindow::MainWindow(QWidget *parent) :
27 27
     new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this, SLOT(redo()));
28 28
 
29 29
     editor = new Editor;
30
+    editor->gridToggleCheckbox = ui->checkBox_ToggleGrid;
30 31
     connect(editor, SIGNAL(objectsChanged()), this, SLOT(updateSelectedObjects()));
31 32
     connect(editor, SIGNAL(selectedObjectsChanged()), this, SLOT(updateSelectedObjects()));
32 33
 

+ 2
- 0
mainwindow.h Dosyayı Görüntüle

@@ -72,6 +72,8 @@ private slots:
72 72
     void onOpenMapListContextMenu(const QPoint &point);
73 73
     void onAddNewMapToGroupClick(QAction* triggeredAction);
74 74
 
75
+    void on_checkBox_ToggleGrid_toggled(bool checked);
76
+
75 77
 private:
76 78
     Ui::MainWindow *ui;
77 79
     QStandardItemModel *mapListModel;

+ 113
- 97
mainwindow.ui Dosyayı Görüntüle

@@ -126,7 +126,7 @@
126 126
              <item row="0" column="0">
127 127
               <widget class="QFrame" name="frame_6">
128 128
                <property name="sizePolicy">
129
-                <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
129
+                <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
130 130
                  <horstretch>0</horstretch>
131 131
                  <verstretch>0</verstretch>
132 132
                 </sizepolicy>
@@ -143,98 +143,114 @@
143 143
                <property name="frameShadow">
144 144
                 <enum>QFrame::Raised</enum>
145 145
                </property>
146
-               <widget class="QToolButton" name="toolButton_Paint">
147
-                <property name="enabled">
148
-                 <bool>true</bool>
149
-                </property>
150
-                <property name="geometry">
151
-                 <rect>
152
-                  <x>0</x>
153
-                  <y>0</y>
154
-                  <width>31</width>
155
-                  <height>31</height>
156
-                 </rect>
157
-                </property>
158
-                <property name="text">
159
-                 <string>Paint</string>
160
-                </property>
161
-                <property name="icon">
162
-                 <iconset resource="resources/images.qrc">
163
-                  <normaloff>:/icons/pencil.ico</normaloff>:/icons/pencil.ico</iconset>
164
-                </property>
165
-                <property name="checkable">
166
-                 <bool>true</bool>
167
-                </property>
168
-                <property name="checked">
169
-                 <bool>true</bool>
170
-                </property>
171
-                <property name="autoRaise">
172
-                 <bool>false</bool>
173
-                </property>
174
-               </widget>
175
-               <widget class="QToolButton" name="toolButton_Select">
176
-                <property name="enabled">
177
-                 <bool>true</bool>
178
-                </property>
179
-                <property name="geometry">
180
-                 <rect>
181
-                  <x>30</x>
182
-                  <y>0</y>
183
-                  <width>31</width>
184
-                  <height>31</height>
185
-                 </rect>
186
-                </property>
187
-                <property name="text">
188
-                 <string>Select</string>
189
-                </property>
190
-                <property name="icon">
191
-                 <iconset resource="resources/images.qrc">
192
-                  <normaloff>:/icons/cursor.ico</normaloff>:/icons/cursor.ico</iconset>
193
-                </property>
194
-                <property name="checkable">
195
-                 <bool>true</bool>
196
-                </property>
197
-               </widget>
198
-               <widget class="QToolButton" name="toolButton_Fill">
199
-                <property name="geometry">
200
-                 <rect>
201
-                  <x>60</x>
202
-                  <y>0</y>
203
-                  <width>31</width>
204
-                  <height>31</height>
205
-                 </rect>
206
-                </property>
207
-                <property name="text">
208
-                 <string>Fill</string>
209
-                </property>
210
-                <property name="icon">
211
-                 <iconset resource="resources/images.qrc">
212
-                  <normaloff>:/icons/fill_color.ico</normaloff>:/icons/fill_color.ico</iconset>
213
-                </property>
214
-                <property name="checkable">
215
-                 <bool>true</bool>
146
+               <layout class="QHBoxLayout" name="horizontalLayout_2">
147
+                <property name="spacing">
148
+                 <number>4</number>
216 149
                 </property>
217
-               </widget>
218
-               <widget class="QToolButton" name="toolButton_Dropper">
219
-                <property name="geometry">
220
-                 <rect>
221
-                  <x>90</x>
222
-                  <y>0</y>
223
-                  <width>31</width>
224
-                  <height>31</height>
225
-                 </rect>
150
+                <property name="leftMargin">
151
+                 <number>4</number>
226 152
                 </property>
227
-                <property name="text">
228
-                 <string>Dropper</string>
153
+                <property name="topMargin">
154
+                 <number>4</number>
229 155
                 </property>
230
-                <property name="icon">
231
-                 <iconset resource="resources/images.qrc">
232
-                  <normaloff>:/icons/pipette.ico</normaloff>:/icons/pipette.ico</iconset>
156
+                <property name="rightMargin">
157
+                 <number>4</number>
233 158
                 </property>
234
-                <property name="checkable">
235
-                 <bool>true</bool>
159
+                <property name="bottomMargin">
160
+                 <number>4</number>
236 161
                 </property>
237
-               </widget>
162
+                <item>
163
+                 <widget class="QToolButton" name="toolButton_Paint">
164
+                  <property name="enabled">
165
+                   <bool>true</bool>
166
+                  </property>
167
+                  <property name="text">
168
+                   <string>Paint</string>
169
+                  </property>
170
+                  <property name="icon">
171
+                   <iconset resource="resources/images.qrc">
172
+                    <normaloff>:/icons/pencil.ico</normaloff>:/icons/pencil.ico</iconset>
173
+                  </property>
174
+                  <property name="checkable">
175
+                   <bool>true</bool>
176
+                  </property>
177
+                  <property name="checked">
178
+                   <bool>true</bool>
179
+                  </property>
180
+                  <property name="autoRaise">
181
+                   <bool>false</bool>
182
+                  </property>
183
+                 </widget>
184
+                </item>
185
+                <item>
186
+                 <widget class="QToolButton" name="toolButton_Select">
187
+                  <property name="enabled">
188
+                   <bool>true</bool>
189
+                  </property>
190
+                  <property name="text">
191
+                   <string>Select</string>
192
+                  </property>
193
+                  <property name="icon">
194
+                   <iconset resource="resources/images.qrc">
195
+                    <normaloff>:/icons/cursor.ico</normaloff>:/icons/cursor.ico</iconset>
196
+                  </property>
197
+                  <property name="checkable">
198
+                   <bool>true</bool>
199
+                  </property>
200
+                 </widget>
201
+                </item>
202
+                <item>
203
+                 <widget class="QToolButton" name="toolButton_Fill">
204
+                  <property name="text">
205
+                   <string>Fill</string>
206
+                  </property>
207
+                  <property name="icon">
208
+                   <iconset resource="resources/images.qrc">
209
+                    <normaloff>:/icons/fill_color.ico</normaloff>:/icons/fill_color.ico</iconset>
210
+                  </property>
211
+                  <property name="checkable">
212
+                   <bool>true</bool>
213
+                  </property>
214
+                 </widget>
215
+                </item>
216
+                <item>
217
+                 <widget class="QToolButton" name="toolButton_Dropper">
218
+                  <property name="text">
219
+                   <string>Dropper</string>
220
+                  </property>
221
+                  <property name="icon">
222
+                   <iconset resource="resources/images.qrc">
223
+                    <normaloff>:/icons/pipette.ico</normaloff>:/icons/pipette.ico</iconset>
224
+                  </property>
225
+                  <property name="checkable">
226
+                   <bool>true</bool>
227
+                  </property>
228
+                 </widget>
229
+                </item>
230
+                <item>
231
+                 <widget class="QCheckBox" name="checkBox_ToggleGrid">
232
+                  <property name="styleSheet">
233
+                   <string notr="true">margin-left: 10px</string>
234
+                  </property>
235
+                  <property name="text">
236
+                   <string>Show Grid</string>
237
+                  </property>
238
+                 </widget>
239
+                </item>
240
+                <item>
241
+                 <spacer name="horizontalSpacer">
242
+                  <property name="orientation">
243
+                   <enum>Qt::Horizontal</enum>
244
+                  </property>
245
+                  <property name="sizeHint" stdset="0">
246
+                   <size>
247
+                    <width>40</width>
248
+                    <height>20</height>
249
+                   </size>
250
+                  </property>
251
+                 </spacer>
252
+                </item>
253
+               </layout>
238 254
               </widget>
239 255
              </item>
240 256
              <item row="1" column="0">
@@ -274,8 +290,8 @@
274 290
                     <rect>
275 291
                      <x>0</x>
276 292
                      <y>0</y>
277
-                     <width>617</width>
278
-                     <height>602</height>
293
+                     <width>614</width>
294
+                     <height>621</height>
279 295
                     </rect>
280 296
                    </property>
281 297
                    <layout class="QGridLayout" name="gridLayout_8">
@@ -462,8 +478,8 @@
462 478
                      <rect>
463 479
                       <x>0</x>
464 480
                       <y>0</y>
465
-                      <width>186</width>
466
-                      <height>609</height>
481
+                      <width>180</width>
482
+                      <height>629</height>
467 483
                      </rect>
468 484
                     </property>
469 485
                     <property name="sizePolicy">
@@ -675,8 +691,8 @@
675 691
               <rect>
676 692
                <x>0</x>
677 693
                <y>0</y>
678
-               <width>385</width>
679
-               <height>638</height>
694
+               <width>381</width>
695
+               <height>657</height>
680 696
               </rect>
681 697
              </property>
682 698
              <layout class="QGridLayout" name="gridLayout_7">
@@ -841,8 +857,8 @@
841 857
                        <rect>
842 858
                         <x>0</x>
843 859
                         <y>0</y>
844
-                        <width>416</width>
845
-                        <height>557</height>
860
+                        <width>420</width>
861
+                        <height>584</height>
846 862
                        </rect>
847 863
                       </property>
848 864
                       <property name="sizePolicy">
@@ -1194,7 +1210,7 @@
1194 1210
      <x>0</x>
1195 1211
      <y>0</y>
1196 1212
      <width>1117</width>
1197
-     <height>20</height>
1213
+     <height>21</height>
1198 1214
     </rect>
1199 1215
    </property>
1200 1216
    <widget class="QMenu" name="menuFile">