Browse Source

Add checkbox to toggle grid lines

Marcus Huderle 6 years ago
parent
commit
eeaa347f17
5 changed files with 123 additions and 97 deletions
  1. 5
    0
      editor.cpp
  2. 2
    0
      editor.h
  3. 1
    0
      mainwindow.cpp
  4. 2
    0
      mainwindow.h
  5. 113
    97
      mainwindow.ui

+ 5
- 0
editor.cpp View File

1
 #include "editor.h"
1
 #include "editor.h"
2
+#include <QCheckBox>
2
 #include <QPainter>
3
 #include <QPainter>
3
 #include <QMouseEvent>
4
 #include <QMouseEvent>
4
 
5
 
251
     for (int i = 0; i <= map->getWidth(); i++) {
252
     for (int i = 0; i <= map->getWidth(); i++) {
252
         int x = i * 16;
253
         int x = i * 16;
253
         QGraphicsLineItem *line = scene->addLine(x, 0, x, pixelHeight);
254
         QGraphicsLineItem *line = scene->addLine(x, 0, x, pixelHeight);
255
+        line->setVisible(gridToggleCheckbox->isChecked());
256
+        connect(gridToggleCheckbox, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
254
     }
257
     }
255
     for (int j = 0; j <= map->getHeight(); j++) {
258
     for (int j = 0; j <= map->getHeight(); j++) {
256
         int y = j * 16;
259
         int y = j * 16;
257
         QGraphicsLineItem *line = scene->addLine(0, y, pixelWidth, y);
260
         QGraphicsLineItem *line = scene->addLine(0, y, pixelWidth, y);
261
+        line->setVisible(gridToggleCheckbox->isChecked());
262
+        connect(gridToggleCheckbox, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
258
     }
263
     }
259
 }
264
 }
260
 
265
 

+ 2
- 0
editor.h View File

6
 #include <QGraphicsSceneMouseEvent>
6
 #include <QGraphicsSceneMouseEvent>
7
 #include <QGraphicsItemAnimation>
7
 #include <QGraphicsItemAnimation>
8
 #include <QComboBox>
8
 #include <QComboBox>
9
+#include <QCheckBox>
9
 
10
 
10
 #include "project.h"
11
 #include "project.h"
11
 
12
 
25
     QObject *parent = NULL;
26
     QObject *parent = NULL;
26
     Project *project = NULL;
27
     Project *project = NULL;
27
     Map *map = NULL;
28
     Map *map = NULL;
29
+    QCheckBox *gridToggleCheckbox = NULL;
28
     void saveProject();
30
     void saveProject();
29
     void save();
31
     void save();
30
     void undo();
32
     void undo();

+ 1
- 0
mainwindow.cpp View File

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

+ 2
- 0
mainwindow.h View File

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

+ 113
- 97
mainwindow.ui View File

126
              <item row="0" column="0">
126
              <item row="0" column="0">
127
               <widget class="QFrame" name="frame_6">
127
               <widget class="QFrame" name="frame_6">
128
                <property name="sizePolicy">
128
                <property name="sizePolicy">
129
-                <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
129
+                <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
130
                  <horstretch>0</horstretch>
130
                  <horstretch>0</horstretch>
131
                  <verstretch>0</verstretch>
131
                  <verstretch>0</verstretch>
132
                 </sizepolicy>
132
                 </sizepolicy>
143
                <property name="frameShadow">
143
                <property name="frameShadow">
144
                 <enum>QFrame::Raised</enum>
144
                 <enum>QFrame::Raised</enum>
145
                </property>
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
                 </property>
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
                 </property>
152
                 </property>
227
-                <property name="text">
228
-                 <string>Dropper</string>
153
+                <property name="topMargin">
154
+                 <number>4</number>
229
                 </property>
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
                 </property>
158
                 </property>
234
-                <property name="checkable">
235
-                 <bool>true</bool>
159
+                <property name="bottomMargin">
160
+                 <number>4</number>
236
                 </property>
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
               </widget>
254
               </widget>
239
              </item>
255
              </item>
240
              <item row="1" column="0">
256
              <item row="1" column="0">
274
                     <rect>
290
                     <rect>
275
                      <x>0</x>
291
                      <x>0</x>
276
                      <y>0</y>
292
                      <y>0</y>
277
-                     <width>617</width>
278
-                     <height>602</height>
293
+                     <width>614</width>
294
+                     <height>621</height>
279
                     </rect>
295
                     </rect>
280
                    </property>
296
                    </property>
281
                    <layout class="QGridLayout" name="gridLayout_8">
297
                    <layout class="QGridLayout" name="gridLayout_8">
462
                      <rect>
478
                      <rect>
463
                       <x>0</x>
479
                       <x>0</x>
464
                       <y>0</y>
480
                       <y>0</y>
465
-                      <width>186</width>
466
-                      <height>609</height>
481
+                      <width>180</width>
482
+                      <height>629</height>
467
                      </rect>
483
                      </rect>
468
                     </property>
484
                     </property>
469
                     <property name="sizePolicy">
485
                     <property name="sizePolicy">
675
               <rect>
691
               <rect>
676
                <x>0</x>
692
                <x>0</x>
677
                <y>0</y>
693
                <y>0</y>
678
-               <width>385</width>
679
-               <height>638</height>
694
+               <width>381</width>
695
+               <height>657</height>
680
               </rect>
696
               </rect>
681
              </property>
697
              </property>
682
              <layout class="QGridLayout" name="gridLayout_7">
698
              <layout class="QGridLayout" name="gridLayout_7">
841
                        <rect>
857
                        <rect>
842
                         <x>0</x>
858
                         <x>0</x>
843
                         <y>0</y>
859
                         <y>0</y>
844
-                        <width>416</width>
845
-                        <height>557</height>
860
+                        <width>420</width>
861
+                        <height>584</height>
846
                        </rect>
862
                        </rect>
847
                       </property>
863
                       </property>
848
                       <property name="sizePolicy">
864
                       <property name="sizePolicy">
1194
      <x>0</x>
1210
      <x>0</x>
1195
      <y>0</y>
1211
      <y>0</y>
1196
      <width>1117</width>
1212
      <width>1117</width>
1197
-     <height>20</height>
1213
+     <height>21</height>
1198
     </rect>
1214
     </rect>
1199
    </property>
1215
    </property>
1200
    <widget class="QMenu" name="menuFile">
1216
    <widget class="QMenu" name="menuFile">