Add checkbox to toggle grid lines

This commit is contained in:
Marcus Huderle 2018-03-04 16:20:18 -08:00
parent 47ce60cbe1
commit eeaa347f17
5 changed files with 123 additions and 97 deletions

View file

@ -1,4 +1,5 @@
#include "editor.h" #include "editor.h"
#include <QCheckBox>
#include <QPainter> #include <QPainter>
#include <QMouseEvent> #include <QMouseEvent>
@ -251,10 +252,14 @@ void Editor::displayMapGrid() {
for (int i = 0; i <= map->getWidth(); i++) { for (int i = 0; i <= map->getWidth(); i++) {
int x = i * 16; int x = i * 16;
QGraphicsLineItem *line = scene->addLine(x, 0, x, pixelHeight); QGraphicsLineItem *line = scene->addLine(x, 0, x, pixelHeight);
line->setVisible(gridToggleCheckbox->isChecked());
connect(gridToggleCheckbox, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
} }
for (int j = 0; j <= map->getHeight(); j++) { for (int j = 0; j <= map->getHeight(); j++) {
int y = j * 16; int y = j * 16;
QGraphicsLineItem *line = scene->addLine(0, y, pixelWidth, y); QGraphicsLineItem *line = scene->addLine(0, y, pixelWidth, y);
line->setVisible(gridToggleCheckbox->isChecked());
connect(gridToggleCheckbox, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
} }
} }

View file

@ -6,6 +6,7 @@
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include <QGraphicsItemAnimation> #include <QGraphicsItemAnimation>
#include <QComboBox> #include <QComboBox>
#include <QCheckBox>
#include "project.h" #include "project.h"
@ -25,6 +26,7 @@ public:
QObject *parent = NULL; QObject *parent = NULL;
Project *project = NULL; Project *project = NULL;
Map *map = NULL; Map *map = NULL;
QCheckBox *gridToggleCheckbox = NULL;
void saveProject(); void saveProject();
void save(); void save();
void undo(); void undo();

View file

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

View file

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

View file

@ -126,7 +126,7 @@
<item row="0" column="0"> <item row="0" column="0">
<widget class="QFrame" name="frame_6"> <widget class="QFrame" name="frame_6">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -143,98 +143,114 @@
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<widget class="QToolButton" name="toolButton_Paint"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="enabled"> <property name="spacing">
<bool>true</bool> <number>4</number>
</property> </property>
<property name="geometry"> <property name="leftMargin">
<rect> <number>4</number>
<x>0</x>
<y>0</y>
<width>31</width>
<height>31</height>
</rect>
</property> </property>
<property name="text"> <property name="topMargin">
<string>Paint</string> <number>4</number>
</property> </property>
<property name="icon"> <property name="rightMargin">
<iconset resource="resources/images.qrc"> <number>4</number>
<normaloff>:/icons/pencil.ico</normaloff>:/icons/pencil.ico</iconset>
</property> </property>
<property name="checkable"> <property name="bottomMargin">
<bool>true</bool> <number>4</number>
</property> </property>
<property name="checked"> <item>
<bool>true</bool> <widget class="QToolButton" name="toolButton_Paint">
</property> <property name="enabled">
<property name="autoRaise"> <bool>true</bool>
<bool>false</bool> </property>
</property> <property name="text">
</widget> <string>Paint</string>
<widget class="QToolButton" name="toolButton_Select"> </property>
<property name="enabled"> <property name="icon">
<bool>true</bool> <iconset resource="resources/images.qrc">
</property> <normaloff>:/icons/pencil.ico</normaloff>:/icons/pencil.ico</iconset>
<property name="geometry"> </property>
<rect> <property name="checkable">
<x>30</x> <bool>true</bool>
<y>0</y> </property>
<width>31</width> <property name="checked">
<height>31</height> <bool>true</bool>
</rect> </property>
</property> <property name="autoRaise">
<property name="text"> <bool>false</bool>
<string>Select</string> </property>
</property> </widget>
<property name="icon"> </item>
<iconset resource="resources/images.qrc"> <item>
<normaloff>:/icons/cursor.ico</normaloff>:/icons/cursor.ico</iconset> <widget class="QToolButton" name="toolButton_Select">
</property> <property name="enabled">
<property name="checkable"> <bool>true</bool>
<bool>true</bool> </property>
</property> <property name="text">
</widget> <string>Select</string>
<widget class="QToolButton" name="toolButton_Fill"> </property>
<property name="geometry"> <property name="icon">
<rect> <iconset resource="resources/images.qrc">
<x>60</x> <normaloff>:/icons/cursor.ico</normaloff>:/icons/cursor.ico</iconset>
<y>0</y> </property>
<width>31</width> <property name="checkable">
<height>31</height> <bool>true</bool>
</rect> </property>
</property> </widget>
<property name="text"> </item>
<string>Fill</string> <item>
</property> <widget class="QToolButton" name="toolButton_Fill">
<property name="icon"> <property name="text">
<iconset resource="resources/images.qrc"> <string>Fill</string>
<normaloff>:/icons/fill_color.ico</normaloff>:/icons/fill_color.ico</iconset> </property>
</property> <property name="icon">
<property name="checkable"> <iconset resource="resources/images.qrc">
<bool>true</bool> <normaloff>:/icons/fill_color.ico</normaloff>:/icons/fill_color.ico</iconset>
</property> </property>
</widget> <property name="checkable">
<widget class="QToolButton" name="toolButton_Dropper"> <bool>true</bool>
<property name="geometry"> </property>
<rect> </widget>
<x>90</x> </item>
<y>0</y> <item>
<width>31</width> <widget class="QToolButton" name="toolButton_Dropper">
<height>31</height> <property name="text">
</rect> <string>Dropper</string>
</property> </property>
<property name="text"> <property name="icon">
<string>Dropper</string> <iconset resource="resources/images.qrc">
</property> <normaloff>:/icons/pipette.ico</normaloff>:/icons/pipette.ico</iconset>
<property name="icon"> </property>
<iconset resource="resources/images.qrc"> <property name="checkable">
<normaloff>:/icons/pipette.ico</normaloff>:/icons/pipette.ico</iconset> <bool>true</bool>
</property> </property>
<property name="checkable"> </widget>
<bool>true</bool> </item>
</property> <item>
</widget> <widget class="QCheckBox" name="checkBox_ToggleGrid">
<property name="styleSheet">
<string notr="true">margin-left: 10px</string>
</property>
<property name="text">
<string>Show Grid</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
@ -274,8 +290,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>617</width> <width>614</width>
<height>602</height> <height>621</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_8"> <layout class="QGridLayout" name="gridLayout_8">
@ -462,8 +478,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>186</width> <width>180</width>
<height>609</height> <height>629</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -675,8 +691,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>385</width> <width>381</width>
<height>638</height> <height>657</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_7"> <layout class="QGridLayout" name="gridLayout_7">
@ -841,8 +857,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>416</width> <width>420</width>
<height>557</height> <height>584</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -1194,7 +1210,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1117</width> <width>1117</width>
<height>20</height> <height>21</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">