Add linking buttons to grid settings

This commit is contained in:
GriffinR 2024-09-28 19:28:07 -04:00
parent 274d95eef5
commit a277e19334
6 changed files with 147 additions and 43 deletions

View file

@ -86,30 +86,60 @@
<property name="title">
<string>Dimensions (in pixels)</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_Width">
<layout class="QGridLayout" name="gridLayout_2" columnstretch="1,1,5">
<item row="0" column="0" rowspan="2">
<widget class="QToolButton" name="button_LinkDimensions">
<property name="text">
<string>Width</string>
<string>...</string>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/link_broken.ico</normaloff>
<normalon>:/icons/link.ico</normalon>:/icons/link_broken.ico</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="popupMode">
<enum>QToolButton::ToolButtonPopupMode::InstantPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_Height">
<property name="text">
<string>Height</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="NoScrollSpinBox" name="spinBox_Width">
<item row="1" column="2">
<widget class="NoScrollSpinBox" name="spinBox_Height">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="NoScrollSpinBox" name="spinBox_Height">
<widget class="QLabel" name="label_Height">
<property name="text">
<string>Height</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_Width">
<property name="text">
<string>Width</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="NoScrollSpinBox" name="spinBox_Width">
<property name="minimum">
<number>1</number>
</property>
@ -123,26 +153,56 @@
<property name="title">
<string>Offset (in pixels)</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_X">
<property name="text">
<string>X</string>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_3" columnstretch="1,1,5">
<item row="1" column="1">
<widget class="QLabel" name="label_Y">
<property name="text">
<string>Y</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_X">
<property name="text">
<string>X</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="NoScrollSpinBox" name="spinBox_Y"/>
</item>
<item row="0" column="2">
<widget class="NoScrollSpinBox" name="spinBox_X"/>
</item>
<item row="1" column="1">
<widget class="NoScrollSpinBox" name="spinBox_Y"/>
<item row="0" column="0" rowspan="2">
<widget class="QToolButton" name="button_LinkOffsets">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/link_broken.ico</normaloff>
<normalon>:/icons/link.ico</normalon>:/icons/link_broken.ico</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="popupMode">
<enum>QToolButton::ToolButtonPopupMode::InstantPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
@ -188,6 +248,8 @@
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<resources>
<include location="../resources/images.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -24,8 +24,14 @@ private:
Ui::GridSettingsDialog *ui;
GridSettings *settings;
GridSettings originalSettings;
bool dimensionsLinked = true;
bool offsetsLinked = true;
void reset(bool force = false);
void setWidth(int value);
void setHeight(int value);
void setOffsetX(int value);
void setOffsetY(int value);
private slots:
void dialogButtonClicked(QAbstractButton *button);

BIN
resources/icons/link.ico Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
resources/icons/link_broken.ico Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

View file

@ -17,6 +17,8 @@
<file>icons/folder_map.ico</file>
<file>icons/folder.ico</file>
<file>icons/help.ico</file>
<file>icons/link_broken.ico</file>
<file>icons/link.ico</file>
<file>icons/map_edited.ico</file>
<file>icons/map_opened.ico</file>
<file>icons/map.ico</file>

View file

@ -1,8 +1,6 @@
#include "ui_gridsettingsdialog.h"
#include "gridsettingsdialog.h"
// 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
@ -31,6 +29,9 @@ GridSettingsDialog::GridSettingsDialog(GridSettings *settings, QWidget *parent)
ui->spinBox_X->setMaximum(INT_MAX);
ui->spinBox_Y->setMaximum(INT_MAX);
ui->button_LinkDimensions->setChecked(this->dimensionsLinked);
ui->button_LinkOffsets->setChecked(this->offsetsLinked);
// Initialize the settings
if (!this->settings)
this->settings = new GridSettings; // TODO: Don't leak this
@ -38,6 +39,8 @@ GridSettingsDialog::GridSettingsDialog(GridSettings *settings, QWidget *parent)
reset(true);
connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &GridSettingsDialog::dialogButtonClicked);
connect(ui->button_LinkDimensions, &QAbstractButton::toggled, [this](bool on) { this->dimensionsLinked = on; });
connect(ui->button_LinkOffsets, &QAbstractButton::toggled, [this](bool on) { this->offsetsLinked = on; });
connect(ui->colorInput, &ColorInputWidget::colorChanged, this, &GridSettingsDialog::onColorChanged);
}
@ -50,20 +53,15 @@ void GridSettingsDialog::reset(bool force) {
return;
*this->settings = this->originalSettings;
// Avoid sending changedGridSettings multiple times
const QSignalBlocker b_Width(ui->spinBox_Width);
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);
const QSignalBlocker b_Color(ui->colorInput);
setWidth(this->settings->width);
setHeight(this->settings->height);
setOffsetX(this->settings->offsetX);
setOffsetY(this->settings->offsetY);
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);
const QSignalBlocker b_Color(ui->colorInput);
ui->colorInput->setColor(this->settings->color.rgb());
const QSignalBlocker b_Style(ui->comboBox_Style);
// TODO: Debug
//ui->comboBox_Style->setCurrentIndex(ui->comboBox_Style->findData(static_cast<int>(this->settings->style)));
for (const auto &pair : penStyleMap) {
@ -76,23 +74,59 @@ void GridSettingsDialog::reset(bool force) {
emit changedGridSettings();
}
void GridSettingsDialog::on_spinBox_Width_valueChanged(int value) {
void GridSettingsDialog::setWidth(int value) {
const QSignalBlocker b(ui->spinBox_Width);
ui->spinBox_Width->setValue(value);
this->settings->width = value;
}
void GridSettingsDialog::setHeight(int value) {
const QSignalBlocker b(ui->spinBox_Height);
ui->spinBox_Height->setValue(value);
this->settings->height = value;
}
void GridSettingsDialog::setOffsetX(int value) {
const QSignalBlocker b(ui->spinBox_X);
ui->spinBox_X->setValue(value);
this->settings->offsetX = value;
}
void GridSettingsDialog::setOffsetY(int value) {
const QSignalBlocker b(ui->spinBox_Y);
ui->spinBox_Y->setValue(value);
this->settings->offsetY = value;
}
void GridSettingsDialog::on_spinBox_Width_valueChanged(int value) {
setWidth(value);
if (this->dimensionsLinked)
setHeight(value);
emit changedGridSettings();
}
void GridSettingsDialog::on_spinBox_Height_valueChanged(int value) {
this->settings->height = value;
setHeight(value);
if (this->dimensionsLinked)
setWidth(value);
emit changedGridSettings();
}
void GridSettingsDialog::on_spinBox_X_valueChanged(int value) {
this->settings->offsetX = value;
setOffsetX(value);
if (this->offsetsLinked)
setOffsetY(value);
emit changedGridSettings();
}
void GridSettingsDialog::on_spinBox_Y_valueChanged(int value) {
this->settings->offsetY = value;
setOffsetY(value);
if (this->offsetsLinked)
setOffsetX(value);
emit changedGridSettings();
}