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>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>416</width>
|
||||
<height>350</height>
|
||||
<width>423</width>
|
||||
<height>375</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -24,15 +24,15 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>390</width>
|
||||
<height>284</height>
|
||||
<width>397</width>
|
||||
<height>309</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="groupBox_Offset">
|
||||
<property name="title">
|
||||
<string>Offset (in metatiles)</string>
|
||||
<string>Offset (in pixels)</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout_2">
|
||||
<item row="0" column="0">
|
||||
|
@ -50,14 +50,27 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="spinBox_X"/>
|
||||
<widget class="NoScrollSpinBox" name="spinBox_X"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="spinBox_Y"/>
|
||||
<widget class="NoScrollSpinBox" name="spinBox_Y"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</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">
|
||||
<widget class="QLabel" name="label_Style">
|
||||
<property name="sizePolicy">
|
||||
|
@ -74,7 +87,7 @@
|
|||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="groupBox_Dimensions">
|
||||
<property name="title">
|
||||
<string>Dimensions (in metatiles)</string>
|
||||
<string>Dimensions (in pixels)</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
|
@ -92,14 +105,14 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="spinBox_Width">
|
||||
<widget class="NoScrollSpinBox" name="spinBox_Width">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="spinBox_Height">
|
||||
<widget class="NoScrollSpinBox" name="spinBox_Height">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
|
@ -109,21 +122,31 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="comboBox_Style"/>
|
||||
</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>
|
||||
<widget class="NoScrollComboBox" name="comboBox_Style">
|
||||
<property name="editable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Color</string>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QComboBox::SizeAdjustPolicy::AdjustToContentsOnFirstShow</enum>
|
||||
</property>
|
||||
<property name="minimumContentsLength">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</widget>
|
||||
</widget>
|
||||
|
@ -140,5 +163,18 @@
|
|||
</item>
|
||||
</layout>
|
||||
</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/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "collisionpixmapitem.h"
|
||||
#include "mappixmapitem.h"
|
||||
#include "settings.h"
|
||||
#include "gridsettingsdialog.h"
|
||||
#include "movablerect.h"
|
||||
#include "cursortilerect.h"
|
||||
#include "mapruler.h"
|
||||
|
|
|
@ -4,6 +4,15 @@
|
|||
|
||||
#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
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -4,20 +4,12 @@
|
|||
#include <QDialog>
|
||||
#include <QAbstractButton>
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
namespace Ui {
|
||||
class GridSettingsDialog;
|
||||
}
|
||||
|
||||
struct GridSettings {
|
||||
uint width = 16;
|
||||
uint height = 16;
|
||||
int offsetX = 0;
|
||||
int offsetY = 0;
|
||||
QString style;
|
||||
QColor color;
|
||||
};
|
||||
|
||||
|
||||
class GridSettingsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -41,7 +33,7 @@ private slots:
|
|||
void on_spinBox_Height_valueChanged(int value);
|
||||
void on_spinBox_X_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) {
|
||||
|
|
|
@ -1878,15 +1878,25 @@ void Editor::displayMapGrid() {
|
|||
const uint pixelMapWidth = map->getWidth() * 16;
|
||||
const uint pixelMapHeight = map->getHeight() * 16;
|
||||
|
||||
QPen pen;
|
||||
pen.setStyle(this->gridSettings.style);
|
||||
pen.setColor(this->gridSettings.color);
|
||||
|
||||
// Create vertical lines
|
||||
int offset = this->gridSettings.offsetX % this->gridSettings.width;
|
||||
for (uint i = offset; i <= pixelMapWidth; i += this->gridSettings.width)
|
||||
this->mapGrid->addToGroup(new QGraphicsLineItem(i, 0, i, pixelMapHeight));
|
||||
for (uint i = offset; i <= pixelMapWidth; i += this->gridSettings.width) {
|
||||
auto line = new QGraphicsLineItem(i, 0, i, pixelMapHeight);
|
||||
line->setPen(pen);
|
||||
this->mapGrid->addToGroup(line);
|
||||
}
|
||||
|
||||
// Create horizontal lines
|
||||
offset = this->gridSettings.offsetY % this->gridSettings.height;
|
||||
for (uint i = offset; i <= pixelMapHeight; i += this->gridSettings.height)
|
||||
this->mapGrid->addToGroup(new QGraphicsLineItem(0, i, pixelMapWidth, i));
|
||||
for (uint i = offset; i <= pixelMapHeight; i += this->gridSettings.height) {
|
||||
auto line = new QGraphicsLineItem(0, i, pixelMapWidth, i);
|
||||
line->setPen(pen);
|
||||
this->mapGrid->addToGroup(line);
|
||||
}
|
||||
|
||||
this->mapGrid->setVisible(porymapConfig.showGrid);
|
||||
}
|
||||
|
|
|
@ -2,14 +2,19 @@
|
|||
#include "gridsettingsdialog.h"
|
||||
|
||||
// TODO: Add color picker
|
||||
// TODO: Add styles
|
||||
// TODO: Update units in UI
|
||||
// TODO: Add linking chain button to width/height
|
||||
// TODO: Add "snap to metatile" check box?
|
||||
// TODO: Save settings in config
|
||||
// TODO: Look into custom painting to improve performance
|
||||
// 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) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::GridSettingsDialog),
|
||||
|
@ -18,14 +23,16 @@ GridSettingsDialog::GridSettingsDialog(GridSettings *settings, QWidget *parent)
|
|||
ui->setupUi(this);
|
||||
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_Height->setMaximum(INT_MAX);
|
||||
ui->spinBox_X->setMaximum(INT_MAX);
|
||||
ui->spinBox_Y->setMaximum(INT_MAX);
|
||||
|
||||
// Initialize UI values
|
||||
// Initialize the settings
|
||||
if (!this->settings)
|
||||
this->settings = new GridSettings; // TODO: Don't leak this
|
||||
this->originalSettings = *this->settings;
|
||||
|
@ -37,6 +44,10 @@ GridSettingsDialog::GridSettingsDialog(GridSettings *settings, QWidget *parent)
|
|||
// connect(ui->, &, this, &GridSettingsDialog::changedGridSettings);
|
||||
}
|
||||
|
||||
GridSettingsDialog::~GridSettingsDialog() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void GridSettingsDialog::reset(bool force) {
|
||||
if (!force && *this->settings == this->originalSettings)
|
||||
return;
|
||||
|
@ -47,12 +58,21 @@ void GridSettingsDialog::reset(bool force) {
|
|||
const QSignalBlocker b_Height(ui->spinBox_Height);
|
||||
const QSignalBlocker b_X(ui->spinBox_X);
|
||||
const QSignalBlocker b_Y(ui->spinBox_Y);
|
||||
const QSignalBlocker b_Style(ui->comboBox_Style);
|
||||
|
||||
ui->spinBox_Width->setValue(this->settings->width);
|
||||
ui->spinBox_Height->setValue(this->settings->height);
|
||||
ui->spinBox_X->setValue(this->settings->offsetX);
|
||||
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
|
||||
|
||||
emit changedGridSettings();
|
||||
|
@ -78,8 +98,11 @@ void GridSettingsDialog::on_spinBox_Y_valueChanged(int value) {
|
|||
emit changedGridSettings();
|
||||
}
|
||||
|
||||
void GridSettingsDialog::on_comboBox_Style_currentTextChanged(QString text) {
|
||||
this->settings->style = text;
|
||||
void GridSettingsDialog::on_comboBox_Style_currentIndexChanged(int index) {
|
||||
if (index < 0 || index >= penStyleMap.length())
|
||||
return;
|
||||
|
||||
this->settings->style = penStyleMap.at(index).second;
|
||||
emit changedGridSettings();
|
||||
}
|
||||
|
||||
|
@ -94,7 +117,3 @@ void GridSettingsDialog::dialogButtonClicked(QAbstractButton *button) {
|
|||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
GridSettingsDialog::~GridSettingsDialog() {
|
||||
delete ui;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue