Add color input to grid settings
This commit is contained in:
parent
2cd4cb9334
commit
274d95eef5
7 changed files with 652 additions and 58 deletions
313
forms/colorinputwidget.ui
Normal file
313
forms/colorinputwidget.ui
Normal file
|
@ -0,0 +1,313 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ColorInputWidget</class>
|
||||
<widget class="QGroupBox" name="ColorInputWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>221</width>
|
||||
<height>212</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Color</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QFrame" name="frame_InputMain">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_Labels">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_Red">
|
||||
<property name="text">
|
||||
<string>Red</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_Green">
|
||||
<property name="text">
|
||||
<string>Green</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_Blue">
|
||||
<property name="text">
|
||||
<string>Blue</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_Sliders">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QSlider" name="slider_Red">
|
||||
<property name="maximum">
|
||||
<number>31</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSlider" name="slider_Green">
|
||||
<property name="maximum">
|
||||
<number>31</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSlider" name="slider_Blue">
|
||||
<property name="maximum">
|
||||
<number>31</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_SpinBoxes">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_Red">
|
||||
<property name="maximum">
|
||||
<number>255</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>8</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_Green">
|
||||
<property name="maximum">
|
||||
<number>255</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>8</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_Blue">
|
||||
<property name="maximum">
|
||||
<number>255</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>8</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QFrame" name="frame_ColorDisplay">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<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>
|
||||
<item row="0" column="1">
|
||||
<widget class="QFrame" name="frame_InputTop">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QFrame" name="frame_Hex">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_Hex">
|
||||
<property name="text">
|
||||
<string>#</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="QLineEdit" name="lineEdit_Hex"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QToolButton" name="button_Eyedrop">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/images.qrc">
|
||||
<normaloff>:/icons/pipette.ico</normaloff>:/icons/pipette.ico</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../resources/images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>423</width>
|
||||
<height>375</height>
|
||||
<width>331</width>
|
||||
<height>467</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -24,39 +24,23 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>397</width>
|
||||
<height>309</height>
|
||||
<width>305</width>
|
||||
<height>401</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 pixels)</string>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</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">
|
||||
<widget class="QLabel" name="label_Y">
|
||||
<property name="text">
|
||||
<string>Y</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="NoScrollSpinBox" name="spinBox_X"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="NoScrollSpinBox" name="spinBox_Y"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_Color">
|
||||
|
@ -71,6 +55,19 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="NoScrollComboBox" name="comboBox_Style">
|
||||
<property name="editable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QComboBox::SizeAdjustPolicy::AdjustToContentsOnFirstShow</enum>
|
||||
</property>
|
||||
<property name="minimumContentsLength">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_Style">
|
||||
<property name="sizePolicy">
|
||||
|
@ -121,31 +118,41 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="NoScrollComboBox" name="comboBox_Style">
|
||||
<property name="editable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QComboBox::SizeAdjustPolicy::AdjustToContentsOnFirstShow</enum>
|
||||
</property>
|
||||
<property name="minimumContentsLength">
|
||||
<number>0</number>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="groupBox_Offset">
|
||||
<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">
|
||||
<widget class="QLabel" name="label_Y">
|
||||
<property name="text">
|
||||
<string>Y</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="NoScrollSpinBox" name="spinBox_X"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="NoScrollSpinBox" name="spinBox_Y"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
<item row="3" column="1">
|
||||
<widget class="ColorInputWidget" name="colorInput">
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
@ -174,6 +181,12 @@
|
|||
<extends>QComboBox</extends>
|
||||
<header>noscrollcombobox.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>ColorInputWidget</class>
|
||||
<extends>QGroupBox</extends>
|
||||
<header>colorinputwidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
45
include/ui/colorinputwidget.h
Normal file
45
include/ui/colorinputwidget.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
#ifndef COLORINPUTWIDGET_H
|
||||
#define COLORINPUTWIDGET_H
|
||||
|
||||
#include <QGroupBox>
|
||||
#include <QValidator>
|
||||
|
||||
namespace Ui {
|
||||
class ColorInputWidget;
|
||||
}
|
||||
|
||||
|
||||
class ColorInputWidget : public QGroupBox {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ColorInputWidget(QWidget *parent = nullptr);
|
||||
explicit ColorInputWidget(const QString &title, QWidget *parent = nullptr);
|
||||
~ColorInputWidget();
|
||||
|
||||
void setColor(QRgb color);
|
||||
QRgb color() const { return m_color; }
|
||||
|
||||
bool setBitDepth(int bits);
|
||||
int bitDepth() const { return m_bitDepth; }
|
||||
|
||||
signals:
|
||||
void colorChanged(QRgb color);
|
||||
void bitDepthChanged(int bits);
|
||||
|
||||
private:
|
||||
Ui::ColorInputWidget *ui;
|
||||
|
||||
QRgb m_color = 0;
|
||||
int m_bitDepth = 0;
|
||||
|
||||
void init();
|
||||
void updateColorUi();
|
||||
void pickColor();
|
||||
void blockEditSignals(bool block);
|
||||
|
||||
void setRgbFromSliders();
|
||||
void setRgbFromSpinners();
|
||||
void setRgbFromHexString(const QString &);
|
||||
};
|
||||
|
||||
#endif // COLORINPUTWIDGET_H
|
|
@ -34,6 +34,7 @@ private slots:
|
|||
void on_spinBox_X_valueChanged(int value);
|
||||
void on_spinBox_Y_valueChanged(int value);
|
||||
void on_comboBox_Style_currentIndexChanged(int index);
|
||||
void onColorChanged(QRgb color);
|
||||
};
|
||||
|
||||
inline bool operator==(const struct GridSettings &a, const struct GridSettings &b) {
|
||||
|
|
|
@ -51,6 +51,7 @@ SOURCES += src/core/block.cpp \
|
|||
src/scriptapi/apiutility.cpp \
|
||||
src/scriptapi/scripting.cpp \
|
||||
src/ui/aboutporymap.cpp \
|
||||
src/ui/colorinputwidget.cpp \
|
||||
src/ui/connectionslistitem.cpp \
|
||||
src/ui/customscriptseditor.cpp \
|
||||
src/ui/customscriptslistitem.cpp \
|
||||
|
@ -175,6 +176,7 @@ HEADERS += include/core/block.h \
|
|||
include/ui/prefabcreationdialog.h \
|
||||
include/ui/regionmappixmapitem.h \
|
||||
include/ui/citymappixmapitem.h \
|
||||
include/ui/colorinputwidget.h \
|
||||
include/ui/mapsceneeventfilter.h \
|
||||
include/ui/metatilelayersitem.h \
|
||||
include/ui/metatileselector.h \
|
||||
|
@ -220,6 +222,7 @@ HEADERS += include/core/block.h \
|
|||
include/ui/wildmonchart.h
|
||||
|
||||
FORMS += forms/mainwindow.ui \
|
||||
forms/colorinputwidget.ui \
|
||||
forms/connectionslistitem.ui \
|
||||
forms/gridsettingsdialog.ui \
|
||||
forms/newmapconnectiondialog.ui \
|
||||
|
|
216
src/ui/colorinputwidget.cpp
Normal file
216
src/ui/colorinputwidget.cpp
Normal file
|
@ -0,0 +1,216 @@
|
|||
#include "colorinputwidget.h"
|
||||
#include "ui_colorinputwidget.h"
|
||||
#include "colorpicker.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
// TODO: Refactor palette editor to make use of this class
|
||||
|
||||
class HexCodeValidator : public QValidator {
|
||||
virtual QValidator::State validate(QString &input, int &) const override {
|
||||
input = input.toUpper();
|
||||
return QValidator::Acceptable;
|
||||
}
|
||||
};
|
||||
|
||||
static inline int rgb5(int rgb) { return round(static_cast<double>(rgb * 31) / 255.0); }
|
||||
static inline int rgb8(int rgb) { return round(rgb * 255. / 31.); }
|
||||
static inline int gbaRed(int rgb) { return rgb & 0x1f; }
|
||||
static inline int gbaGreen(int rgb) { return (rgb >> 5) & 0x1f; }
|
||||
static inline int gbaBlue(int rgb) { return (rgb >> 10) & 0x1f; }
|
||||
|
||||
ColorInputWidget::ColorInputWidget(QWidget *parent) :
|
||||
QGroupBox(parent),
|
||||
ui(new Ui::ColorInputWidget)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
ColorInputWidget::ColorInputWidget(const QString &title, QWidget *parent) :
|
||||
QGroupBox(title, parent),
|
||||
ui(new Ui::ColorInputWidget)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
void ColorInputWidget::init() {
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->slider_Red, &QSlider::valueChanged, this, &ColorInputWidget::setRgbFromSliders);
|
||||
connect(ui->slider_Green, &QSlider::valueChanged, this, &ColorInputWidget::setRgbFromSliders);
|
||||
connect(ui->slider_Blue, &QSlider::valueChanged, this, &ColorInputWidget::setRgbFromSliders);
|
||||
|
||||
connect(ui->spinBox_Red, QOverload<int>::of(&QSpinBox::valueChanged), this, &ColorInputWidget::setRgbFromSpinners);
|
||||
connect(ui->spinBox_Green, QOverload<int>::of(&QSpinBox::valueChanged), this, &ColorInputWidget::setRgbFromSpinners);
|
||||
connect(ui->spinBox_Blue, QOverload<int>::of(&QSpinBox::valueChanged), this, &ColorInputWidget::setRgbFromSpinners);
|
||||
|
||||
static const HexCodeValidator hexValidator;
|
||||
ui->lineEdit_Hex->setValidator(&hexValidator);
|
||||
connect(ui->lineEdit_Hex, &QLineEdit::textEdited, this, &ColorInputWidget::setRgbFromHexString);
|
||||
|
||||
connect(ui->button_Eyedrop, &QToolButton::clicked, this, &ColorInputWidget::pickColor);
|
||||
|
||||
setBitDepth(24);
|
||||
}
|
||||
|
||||
ColorInputWidget::~ColorInputWidget() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ColorInputWidget::updateColorUi() {
|
||||
blockEditSignals(true);
|
||||
|
||||
int red = qRed(m_color);
|
||||
int green = qGreen(m_color);
|
||||
int blue = qBlue(m_color);
|
||||
|
||||
if (m_bitDepth == 15) {
|
||||
// Sliders
|
||||
ui->slider_Red->setValue(rgb5(red));
|
||||
ui->slider_Green->setValue(rgb5(green));
|
||||
ui->slider_Blue->setValue(rgb5(blue));
|
||||
|
||||
// Hex
|
||||
int hex15 = (rgb5(blue) << 10) | (rgb5(green) << 5) | rgb5(red);
|
||||
ui->lineEdit_Hex->setText(QString("%1").arg(hex15, 4, 16, QLatin1Char('0')).toUpper());
|
||||
|
||||
// Spinners
|
||||
ui->spinBox_Red->setValue(rgb5(red));
|
||||
ui->spinBox_Green->setValue(rgb5(green));
|
||||
ui->spinBox_Blue->setValue(rgb5(blue));
|
||||
} else {
|
||||
// Sliders
|
||||
ui->slider_Red->setValue(red);
|
||||
ui->slider_Green->setValue(green);
|
||||
ui->slider_Blue->setValue(blue);
|
||||
|
||||
// Hex
|
||||
QColor color(red, green, blue);
|
||||
ui->lineEdit_Hex->setText(color.name().remove(0, 1).toUpper());
|
||||
|
||||
// Spinners
|
||||
ui->spinBox_Red->setValue(red);
|
||||
ui->spinBox_Green->setValue(green);
|
||||
ui->spinBox_Blue->setValue(blue);
|
||||
}
|
||||
|
||||
ui->frame_ColorDisplay->setStyleSheet(QString("background-color: rgb(%1, %2, %3);").arg(red).arg(green).arg(blue));
|
||||
|
||||
blockEditSignals(false);
|
||||
}
|
||||
|
||||
void ColorInputWidget::blockEditSignals(bool block) {
|
||||
ui->slider_Red->blockSignals(block);
|
||||
ui->slider_Green->blockSignals(block);
|
||||
ui->slider_Blue->blockSignals(block);
|
||||
|
||||
ui->spinBox_Red->blockSignals(block);
|
||||
ui->spinBox_Green->blockSignals(block);
|
||||
ui->spinBox_Blue->blockSignals(block);
|
||||
|
||||
ui->lineEdit_Hex->blockSignals(block);
|
||||
}
|
||||
|
||||
bool ColorInputWidget::setBitDepth(int bits) {
|
||||
if (m_bitDepth == bits)
|
||||
return true;
|
||||
|
||||
int singleStep, pageStep, maximum;
|
||||
QString hexInputMask;
|
||||
if (bits == 15) {
|
||||
singleStep = 1;
|
||||
pageStep = 4;
|
||||
maximum = 31;
|
||||
hexInputMask = "HHHH";
|
||||
} else if (bits == 24) {
|
||||
singleStep = 8;
|
||||
pageStep = 24;
|
||||
maximum = 255;
|
||||
hexInputMask = "HHHHHH";
|
||||
} else {
|
||||
// Unsupported bit depth
|
||||
return false;
|
||||
}
|
||||
m_bitDepth = bits;
|
||||
|
||||
blockEditSignals(true);
|
||||
ui->slider_Red->setSingleStep(singleStep);
|
||||
ui->slider_Green->setSingleStep(singleStep);
|
||||
ui->slider_Blue->setSingleStep(singleStep);
|
||||
ui->slider_Red->setPageStep(pageStep);
|
||||
ui->slider_Green->setPageStep(pageStep);
|
||||
ui->slider_Blue->setPageStep(pageStep);
|
||||
ui->slider_Red->setMaximum(maximum);
|
||||
ui->slider_Green->setMaximum(maximum);
|
||||
ui->slider_Blue->setMaximum(maximum);
|
||||
|
||||
ui->spinBox_Red->setSingleStep(singleStep);
|
||||
ui->spinBox_Green->setSingleStep(singleStep);
|
||||
ui->spinBox_Blue->setSingleStep(singleStep);
|
||||
ui->spinBox_Red->setMaximum(maximum);
|
||||
ui->spinBox_Green->setMaximum(maximum);
|
||||
ui->spinBox_Blue->setMaximum(maximum);
|
||||
|
||||
ui->lineEdit_Hex->setInputMask(hexInputMask);
|
||||
ui->lineEdit_Hex->setMaxLength(hexInputMask.length());
|
||||
|
||||
updateColorUi();
|
||||
blockEditSignals(false);
|
||||
emit bitDepthChanged(m_bitDepth);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ColorInputWidget::setColor(QRgb rgb) {
|
||||
if (m_color == rgb)
|
||||
return;
|
||||
m_color = rgb;
|
||||
updateColorUi();
|
||||
emit colorChanged(m_color);
|
||||
}
|
||||
|
||||
void ColorInputWidget::setRgbFromSliders() {
|
||||
if (m_bitDepth == 15) {
|
||||
setColor(qRgb(rgb8(ui->slider_Red->value()),
|
||||
rgb8(ui->slider_Green->value()),
|
||||
rgb8(ui->slider_Blue->value())));
|
||||
} else {
|
||||
setColor(qRgb(ui->slider_Red->value(),
|
||||
ui->slider_Green->value(),
|
||||
ui->slider_Blue->value()));
|
||||
}
|
||||
}
|
||||
|
||||
void ColorInputWidget::setRgbFromSpinners() {
|
||||
if (m_bitDepth == 15) {
|
||||
setColor(qRgb(rgb8(ui->spinBox_Red->value()), rgb8(ui->spinBox_Green->value()), rgb8(ui->spinBox_Blue->value())));
|
||||
} else {
|
||||
setColor(qRgb(ui->spinBox_Red->value(), ui->spinBox_Green->value(), ui->spinBox_Blue->value()));
|
||||
}
|
||||
}
|
||||
|
||||
void ColorInputWidget::setRgbFromHexString(const QString &text) {
|
||||
if ((m_bitDepth == 24 && text.length() != 6)
|
||||
|| (m_bitDepth == 15 && text.length() != 4))
|
||||
return;
|
||||
|
||||
bool ok = false;
|
||||
int rgb = text.toInt(&ok, 16);
|
||||
if (!ok) rgb = 0xFFFFFFFF;
|
||||
|
||||
if (m_bitDepth == 15) {
|
||||
int rc = gbaRed(rgb);
|
||||
int gc = gbaGreen(rgb);
|
||||
int bc = gbaBlue(rgb);
|
||||
setColor(qRgb(rgb8(rc), rgb8(gc), rgb8(bc)));
|
||||
} else {
|
||||
setColor(qRgb(qRed(rgb), qGreen(rgb), qBlue(rgb)));
|
||||
}
|
||||
}
|
||||
|
||||
void ColorInputWidget::pickColor() {
|
||||
ColorPicker picker(this);
|
||||
if (picker.exec() == QDialog::Accepted) {
|
||||
QColor c = picker.getColor();
|
||||
setColor(c.rgb());
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
#include "ui_gridsettingsdialog.h"
|
||||
#include "gridsettingsdialog.h"
|
||||
|
||||
// TODO: Add color picker
|
||||
// TODO: Add linking chain button to width/height
|
||||
// TODO: Add "snap to metatile" check box?
|
||||
// TODO: Save settings in config
|
||||
|
@ -39,9 +38,7 @@ GridSettingsDialog::GridSettingsDialog(GridSettings *settings, QWidget *parent)
|
|||
reset(true);
|
||||
|
||||
connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &GridSettingsDialog::dialogButtonClicked);
|
||||
|
||||
// TODO: Connect color picker
|
||||
// connect(ui->, &, this, &GridSettingsDialog::changedGridSettings);
|
||||
connect(ui->colorInput, &ColorInputWidget::colorChanged, this, &GridSettingsDialog::onColorChanged);
|
||||
}
|
||||
|
||||
GridSettingsDialog::~GridSettingsDialog() {
|
||||
|
@ -59,11 +56,13 @@ void GridSettingsDialog::reset(bool force) {
|
|||
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);
|
||||
|
||||
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);
|
||||
ui->colorInput->setColor(this->settings->color.rgb());
|
||||
|
||||
// TODO: Debug
|
||||
//ui->comboBox_Style->setCurrentIndex(ui->comboBox_Style->findData(static_cast<int>(this->settings->style)));
|
||||
|
@ -73,7 +72,6 @@ void GridSettingsDialog::reset(bool force) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
// TODO: Initialize color with settings-color
|
||||
|
||||
emit changedGridSettings();
|
||||
}
|
||||
|
@ -106,6 +104,11 @@ void GridSettingsDialog::on_comboBox_Style_currentIndexChanged(int index) {
|
|||
emit changedGridSettings();
|
||||
}
|
||||
|
||||
void GridSettingsDialog::onColorChanged(QRgb color) {
|
||||
this->settings->color = QColor::fromRgb(color);
|
||||
emit changedGridSettings();
|
||||
}
|
||||
|
||||
void GridSettingsDialog::dialogButtonClicked(QAbstractButton *button) {
|
||||
auto role = ui->buttonBox->buttonRole(button);
|
||||
if (role == QDialogButtonBox::AcceptRole) {
|
||||
|
@ -114,6 +117,6 @@ void GridSettingsDialog::dialogButtonClicked(QAbstractButton *button) {
|
|||
reset();
|
||||
close();
|
||||
} else if (role == QDialogButtonBox::ResetRole) {
|
||||
reset();
|
||||
reset(); // TODO: We should restore to original defaults, not to the values when the window was opened.
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue