Add styles to grid settings
This commit is contained in:
parent
16536eb940
commit
2cd4cb9334
6 changed files with 113 additions and 48 deletions
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>416</width>
|
<width>423</width>
|
||||||
<height>350</height>
|
<height>375</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -24,15 +24,15 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>390</width>
|
<width>397</width>
|
||||||
<height>284</height>
|
<height>309</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="1" column="0" colspan="2">
|
<item row="1" column="0" colspan="2">
|
||||||
<widget class="QGroupBox" name="groupBox_Offset">
|
<widget class="QGroupBox" name="groupBox_Offset">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Offset (in metatiles)</string>
|
<string>Offset (in pixels)</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QFormLayout" name="formLayout_2">
|
<layout class="QFormLayout" name="formLayout_2">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
|
@ -50,14 +50,27 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QSpinBox" name="spinBox_X"/>
|
<widget class="NoScrollSpinBox" name="spinBox_X"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QSpinBox" name="spinBox_Y"/>
|
<widget class="NoScrollSpinBox" name="spinBox_Y"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QLabel" name="label_Color">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Color</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="label_Style">
|
<widget class="QLabel" name="label_Style">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -74,7 +87,7 @@
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="0" column="0" colspan="2">
|
||||||
<widget class="QGroupBox" name="groupBox_Dimensions">
|
<widget class="QGroupBox" name="groupBox_Dimensions">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Dimensions (in metatiles)</string>
|
<string>Dimensions (in pixels)</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
|
@ -92,14 +105,14 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QSpinBox" name="spinBox_Width">
|
<widget class="NoScrollSpinBox" name="spinBox_Width">
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QSpinBox" name="spinBox_Height">
|
<widget class="NoScrollSpinBox" name="spinBox_Height">
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
|
@ -109,21 +122,31 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QComboBox" name="comboBox_Style"/>
|
<widget class="NoScrollComboBox" name="comboBox_Style">
|
||||||
</item>
|
<property name="editable">
|
||||||
<item row="3" column="0">
|
<bool>false</bool>
|
||||||
<widget class="QLabel" name="label_Color">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="sizeAdjustPolicy">
|
||||||
<string>Color</string>
|
<enum>QComboBox::SizeAdjustPolicy::AdjustToContentsOnFirstShow</enum>
|
||||||
|
</property>
|
||||||
|
<property name="minimumContentsLength">
|
||||||
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="4" column="0" colspan="2">
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Orientation::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -140,5 +163,18 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>NoScrollSpinBox</class>
|
||||||
|
<extends>QSpinBox</extends>
|
||||||
|
<header>noscrollspinbox.h</header>
|
||||||
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>NoScrollComboBox</class>
|
||||||
|
<extends>QComboBox</extends>
|
||||||
|
<header>noscrollcombobox.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#include "collisionpixmapitem.h"
|
#include "collisionpixmapitem.h"
|
||||||
#include "mappixmapitem.h"
|
#include "mappixmapitem.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "gridsettingsdialog.h"
|
|
||||||
#include "movablerect.h"
|
#include "movablerect.h"
|
||||||
#include "cursortilerect.h"
|
#include "cursortilerect.h"
|
||||||
#include "mapruler.h"
|
#include "mapruler.h"
|
||||||
|
|
|
@ -4,6 +4,15 @@
|
||||||
|
|
||||||
#include <QCursor>
|
#include <QCursor>
|
||||||
|
|
||||||
|
struct GridSettings {
|
||||||
|
uint width = 16;
|
||||||
|
uint height = 16;
|
||||||
|
int offsetX = 0;
|
||||||
|
int offsetY = 0;
|
||||||
|
Qt::PenStyle style = Qt::SolidLine;
|
||||||
|
QColor color = Qt::black;
|
||||||
|
};
|
||||||
|
|
||||||
class Settings
|
class Settings
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -4,20 +4,12 @@
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QAbstractButton>
|
#include <QAbstractButton>
|
||||||
|
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class GridSettingsDialog;
|
class GridSettingsDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GridSettings {
|
|
||||||
uint width = 16;
|
|
||||||
uint height = 16;
|
|
||||||
int offsetX = 0;
|
|
||||||
int offsetY = 0;
|
|
||||||
QString style;
|
|
||||||
QColor color;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class GridSettingsDialog : public QDialog
|
class GridSettingsDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -41,7 +33,7 @@ private slots:
|
||||||
void on_spinBox_Height_valueChanged(int value);
|
void on_spinBox_Height_valueChanged(int value);
|
||||||
void on_spinBox_X_valueChanged(int value);
|
void on_spinBox_X_valueChanged(int value);
|
||||||
void on_spinBox_Y_valueChanged(int value);
|
void on_spinBox_Y_valueChanged(int value);
|
||||||
void on_comboBox_Style_currentTextChanged(QString style);
|
void on_comboBox_Style_currentIndexChanged(int index);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator==(const struct GridSettings &a, const struct GridSettings &b) {
|
inline bool operator==(const struct GridSettings &a, const struct GridSettings &b) {
|
||||||
|
|
|
@ -1878,15 +1878,25 @@ void Editor::displayMapGrid() {
|
||||||
const uint pixelMapWidth = map->getWidth() * 16;
|
const uint pixelMapWidth = map->getWidth() * 16;
|
||||||
const uint pixelMapHeight = map->getHeight() * 16;
|
const uint pixelMapHeight = map->getHeight() * 16;
|
||||||
|
|
||||||
|
QPen pen;
|
||||||
|
pen.setStyle(this->gridSettings.style);
|
||||||
|
pen.setColor(this->gridSettings.color);
|
||||||
|
|
||||||
// Create vertical lines
|
// Create vertical lines
|
||||||
int offset = this->gridSettings.offsetX % this->gridSettings.width;
|
int offset = this->gridSettings.offsetX % this->gridSettings.width;
|
||||||
for (uint i = offset; i <= pixelMapWidth; i += this->gridSettings.width)
|
for (uint i = offset; i <= pixelMapWidth; i += this->gridSettings.width) {
|
||||||
this->mapGrid->addToGroup(new QGraphicsLineItem(i, 0, i, pixelMapHeight));
|
auto line = new QGraphicsLineItem(i, 0, i, pixelMapHeight);
|
||||||
|
line->setPen(pen);
|
||||||
|
this->mapGrid->addToGroup(line);
|
||||||
|
}
|
||||||
|
|
||||||
// Create horizontal lines
|
// Create horizontal lines
|
||||||
offset = this->gridSettings.offsetY % this->gridSettings.height;
|
offset = this->gridSettings.offsetY % this->gridSettings.height;
|
||||||
for (uint i = offset; i <= pixelMapHeight; i += this->gridSettings.height)
|
for (uint i = offset; i <= pixelMapHeight; i += this->gridSettings.height) {
|
||||||
this->mapGrid->addToGroup(new QGraphicsLineItem(0, i, pixelMapWidth, i));
|
auto line = new QGraphicsLineItem(0, i, pixelMapWidth, i);
|
||||||
|
line->setPen(pen);
|
||||||
|
this->mapGrid->addToGroup(line);
|
||||||
|
}
|
||||||
|
|
||||||
this->mapGrid->setVisible(porymapConfig.showGrid);
|
this->mapGrid->setVisible(porymapConfig.showGrid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,19 @@
|
||||||
#include "gridsettingsdialog.h"
|
#include "gridsettingsdialog.h"
|
||||||
|
|
||||||
// TODO: Add color picker
|
// TODO: Add color picker
|
||||||
// TODO: Add styles
|
|
||||||
// TODO: Update units in UI
|
|
||||||
// TODO: Add linking chain button to width/height
|
// TODO: Add linking chain button to width/height
|
||||||
// TODO: Add "snap to metatile" check box?
|
// TODO: Add "snap to metatile" check box?
|
||||||
// TODO: Save settings in config
|
// TODO: Save settings in config
|
||||||
// TODO: Look into custom painting to improve performance
|
// TODO: Look into custom painting to improve performance
|
||||||
// TODO: Add tooltips
|
// TODO: Add tooltips
|
||||||
|
|
||||||
|
const QList<QPair<QString, Qt::PenStyle>> penStyleMap = {
|
||||||
|
{"Solid", Qt::SolidLine},
|
||||||
|
{"Large Dashes", Qt::DashLine},
|
||||||
|
{"Small Dashes", Qt::DotLine},
|
||||||
|
{"Dots", Qt::CustomDashLine}, // TODO: Implement a custom pattern for this
|
||||||
|
};
|
||||||
|
|
||||||
GridSettingsDialog::GridSettingsDialog(GridSettings *settings, QWidget *parent) :
|
GridSettingsDialog::GridSettingsDialog(GridSettings *settings, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::GridSettingsDialog),
|
ui(new Ui::GridSettingsDialog),
|
||||||
|
@ -18,14 +23,16 @@ GridSettingsDialog::GridSettingsDialog(GridSettings *settings, QWidget *parent)
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
// TODO: Populate comboBox_Style
|
// Populate the styles combo box
|
||||||
|
for (const auto &pair : penStyleMap)
|
||||||
|
ui->comboBox_Style->addItem(pair.first, static_cast<int>(pair.second));
|
||||||
|
|
||||||
ui->spinBox_Width->setMaximum(INT_MAX);
|
ui->spinBox_Width->setMaximum(INT_MAX);
|
||||||
ui->spinBox_Height->setMaximum(INT_MAX);
|
ui->spinBox_Height->setMaximum(INT_MAX);
|
||||||
ui->spinBox_X->setMaximum(INT_MAX);
|
ui->spinBox_X->setMaximum(INT_MAX);
|
||||||
ui->spinBox_Y->setMaximum(INT_MAX);
|
ui->spinBox_Y->setMaximum(INT_MAX);
|
||||||
|
|
||||||
// Initialize UI values
|
// Initialize the settings
|
||||||
if (!this->settings)
|
if (!this->settings)
|
||||||
this->settings = new GridSettings; // TODO: Don't leak this
|
this->settings = new GridSettings; // TODO: Don't leak this
|
||||||
this->originalSettings = *this->settings;
|
this->originalSettings = *this->settings;
|
||||||
|
@ -37,6 +44,10 @@ GridSettingsDialog::GridSettingsDialog(GridSettings *settings, QWidget *parent)
|
||||||
// connect(ui->, &, this, &GridSettingsDialog::changedGridSettings);
|
// connect(ui->, &, this, &GridSettingsDialog::changedGridSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GridSettingsDialog::~GridSettingsDialog() {
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
void GridSettingsDialog::reset(bool force) {
|
void GridSettingsDialog::reset(bool force) {
|
||||||
if (!force && *this->settings == this->originalSettings)
|
if (!force && *this->settings == this->originalSettings)
|
||||||
return;
|
return;
|
||||||
|
@ -47,12 +58,21 @@ void GridSettingsDialog::reset(bool force) {
|
||||||
const QSignalBlocker b_Height(ui->spinBox_Height);
|
const QSignalBlocker b_Height(ui->spinBox_Height);
|
||||||
const QSignalBlocker b_X(ui->spinBox_X);
|
const QSignalBlocker b_X(ui->spinBox_X);
|
||||||
const QSignalBlocker b_Y(ui->spinBox_Y);
|
const QSignalBlocker b_Y(ui->spinBox_Y);
|
||||||
|
const QSignalBlocker b_Style(ui->comboBox_Style);
|
||||||
|
|
||||||
ui->spinBox_Width->setValue(this->settings->width);
|
ui->spinBox_Width->setValue(this->settings->width);
|
||||||
ui->spinBox_Height->setValue(this->settings->height);
|
ui->spinBox_Height->setValue(this->settings->height);
|
||||||
ui->spinBox_X->setValue(this->settings->offsetX);
|
ui->spinBox_X->setValue(this->settings->offsetX);
|
||||||
ui->spinBox_Y->setValue(this->settings->offsetY);
|
ui->spinBox_Y->setValue(this->settings->offsetY);
|
||||||
// TODO: Initialize comboBox_Style with settings->style
|
|
||||||
|
// TODO: Debug
|
||||||
|
//ui->comboBox_Style->setCurrentIndex(ui->comboBox_Style->findData(static_cast<int>(this->settings->style)));
|
||||||
|
for (const auto &pair : penStyleMap) {
|
||||||
|
if (pair.second == this->settings->style) {
|
||||||
|
ui->comboBox_Style->setCurrentText(pair.first);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
// TODO: Initialize color with settings-color
|
// TODO: Initialize color with settings-color
|
||||||
|
|
||||||
emit changedGridSettings();
|
emit changedGridSettings();
|
||||||
|
@ -78,8 +98,11 @@ void GridSettingsDialog::on_spinBox_Y_valueChanged(int value) {
|
||||||
emit changedGridSettings();
|
emit changedGridSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridSettingsDialog::on_comboBox_Style_currentTextChanged(QString text) {
|
void GridSettingsDialog::on_comboBox_Style_currentIndexChanged(int index) {
|
||||||
this->settings->style = text;
|
if (index < 0 || index >= penStyleMap.length())
|
||||||
|
return;
|
||||||
|
|
||||||
|
this->settings->style = penStyleMap.at(index).second;
|
||||||
emit changedGridSettings();
|
emit changedGridSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +117,3 @@ void GridSettingsDialog::dialogButtonClicked(QAbstractButton *button) {
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GridSettingsDialog::~GridSettingsDialog() {
|
|
||||||
delete ui;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue