Skip to content

Commit

Permalink
Addressed various property todo items
Browse files Browse the repository at this point in the history
* Apply various minimum and maximum values
* Set custom step size where needed
* Set file filters where appropriate
* Support constraint on RectProperty
  • Loading branch information
bjorn committed Sep 9, 2024
1 parent 2b0cb35 commit 091bc14
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 67 deletions.
51 changes: 28 additions & 23 deletions src/tiled/propertieswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ class MapProperties : public ObjectProperties
}
},
this);
mTileSizeProperty->setMinimum(1);

mInfiniteProperty = new BoolProperty(
tr("Infinite"),
Expand Down Expand Up @@ -539,6 +540,7 @@ class MapProperties : public ObjectProperties
[this](const QSize &value) {
push(new ChangeMapProperty(mapDocument(), value));
});
mChunkSizeProperty->setMinimum(CHUNK_SIZE_MIN);

mRenderOrderProperty = new EnumProperty<Map::RenderOrder>(
tr("Tile Render Order"),
Expand Down Expand Up @@ -682,14 +684,14 @@ class MapProperties : public ObjectProperties

Property *mOrientationProperty;
Property *mSizeProperty;
Property *mTileSizeProperty;
SizeProperty *mTileSizeProperty;
Property *mInfiniteProperty;
Property *mHexSideLengthProperty;
Property *mStaggerAxisProperty;
Property *mStaggerIndexProperty;
Property *mParallaxOriginProperty;
Property *mLayerDataFormatProperty;
Property *mChunkSizeProperty;
SizeProperty *mChunkSizeProperty;
Property *mRenderOrderProperty;
Property *mCompressionLevelProperty;
Property *mBackgroundColorProperty;
Expand Down Expand Up @@ -733,14 +735,15 @@ class LayerProperties : public ObjectProperties
push(new SetLayerLocked(mapDocument(), { layer() }, value));
});

// todo: value should be between 0 and 1, and would be nice to use a slider (replacing the one in Layers view)
// todo: singleStep should be 0.1
// todo: would be nice to use a slider (replacing the one in Layers view)
mOpacityProperty = new FloatProperty(
tr("Opacity"),
[this] { return layer()->opacity(); },
[this](const double &value) {
push(new SetLayerOpacity(mapDocument(), { layer() }, value));
});
mOpacityProperty->setRange(0.0, 1.0);
mOpacityProperty->setSingleStep(0.1);

mTintColorProperty = new ColorProperty(
tr("Tint Color"),
Expand All @@ -756,13 +759,13 @@ class LayerProperties : public ObjectProperties
push(new SetLayerOffset(mapDocument(), { layer() }, value));
});

// todo: singleStep should be 0.1
mParallaxFactorProperty = new PointFProperty(
tr("Parallax Factor"),
[this] { return layer()->parallaxFactor(); },
[this](const QPointF &value) {
push(new SetLayerParallaxFactor(mapDocument(), { layer() }, value));
});
mParallaxFactorProperty->setSingleStep(0.1);

connect(document, &Document::changed,
this, &LayerProperties::onChanged);
Expand Down Expand Up @@ -821,10 +824,10 @@ class LayerProperties : public ObjectProperties
Property *mNameProperty;
Property *mVisibleProperty;
Property *mLockedProperty;
Property *mOpacityProperty;
FloatProperty *mOpacityProperty;
Property *mTintColorProperty;
Property *mOffsetProperty;
Property *mParallaxFactorProperty;
PointFProperty *mParallaxFactorProperty;
};

class ImageLayerProperties : public LayerProperties
Expand All @@ -835,13 +838,13 @@ class ImageLayerProperties : public LayerProperties
ImageLayerProperties(MapDocument *document, ImageLayer *object, QObject *parent = nullptr)
: LayerProperties(document, object, parent)
{
// todo: set a file filter for selecting images (or map files?)
mImageProperty = new UrlProperty(
tr("Image Source"),
[this] { return imageLayer()->imageSource(); },
[this](const QUrl &value) {
push(new ChangeImageLayerImageSource(mapDocument(), { imageLayer() }, value));
});
mImageProperty->setFilter(Utils::readableImageFormatsFilter());

mTransparentColorProperty = new ColorProperty(
tr("Transparent Color"),
Expand Down Expand Up @@ -904,7 +907,7 @@ class ImageLayerProperties : public LayerProperties
return static_cast<ImageLayer*>(mObject);
}

Property *mImageProperty;
UrlProperty *mImageProperty;
Property *mTransparentColorProperty;
Property *mRepeatXProperty;
Property *mRepeatYProperty;
Expand Down Expand Up @@ -1047,8 +1050,8 @@ class TilesetProperties : public ObjectProperties
[this](const QSize &value) {
push(new ChangeTilesetGridSize(tilesetDocument(), value));
});
mGridSizeProperty->setMinimum(1);

// todo: needs 1 as minimum value
mColumnCountProperty = new IntProperty(
tr("Columns"),
[this] {
Expand All @@ -1057,6 +1060,7 @@ class TilesetProperties : public ObjectProperties
[this](const int &value) {
push(new ChangeTilesetColumnCount(tilesetDocument(), value));
});
mColumnCountProperty->setMinimum(1);

// todo: this needs a custom widget
mAllowedTransformationsProperty = new IntProperty(
Expand Down Expand Up @@ -1163,8 +1167,8 @@ class TilesetProperties : public ObjectProperties
Property *mFillModeProperty;
Property *mBackgroundColorProperty;
Property *mOrientationProperty;
Property *mGridSizeProperty;
Property *mColumnCountProperty;
SizeProperty *mGridSizeProperty;
IntProperty *mColumnCountProperty;
Property *mAllowedTransformationsProperty;
Property *mImageProperty;
};
Expand Down Expand Up @@ -1262,8 +1266,7 @@ class MapObjectProperties : public ObjectProperties
push(command);
});

// todo: allow opening the multi-line text dialog
mTextProperty = new StringProperty(
mTextProperty = new MultilineStringProperty(
tr("Text"),
[this] {
return mapObject()->textData().text;
Expand Down Expand Up @@ -1446,7 +1449,6 @@ class TileProperties : public ObjectProperties
[this] { return tile()->id(); });
mIdProperty->setEnabled(false);

// todo: apply readableImageFormatsFilter
mImageProperty = new UrlProperty(
tr("Image"),
[this] { return tile()->imageSource(); },
Expand All @@ -1455,6 +1457,7 @@ class TileProperties : public ObjectProperties
tile(),
value));
});
mImageProperty->setFilter(Utils::readableImageFormatsFilter());

mRectangleProperty = new RectProperty(
tr("Rectangle"),
Expand All @@ -1464,8 +1467,8 @@ class TileProperties : public ObjectProperties
{ tile() },
{ value }));
});
mRectangleProperty->setConstraint(object->image().rect());

// todo: minimum value should be 0
mProbabilityProperty = new FloatProperty(
tr("Probability"),
[this] { return tile()->probability(); },
Expand All @@ -1475,6 +1478,7 @@ class TileProperties : public ObjectProperties
value));
});
mProbabilityProperty->setToolTip(tr("Relative chance this tile will be picked"));
mProbabilityProperty->setMinimum(0.0);

// annoying... maybe we should somehow always have the relevant TilesetDocument
if (auto tilesetDocument = qobject_cast<TilesetDocument*>(document)) {
Expand Down Expand Up @@ -1513,6 +1517,7 @@ class TileProperties : public ObjectProperties
{
if (tile != this->tile())
return;
mRectangleProperty->setConstraint(tile->image().rect());
emit mImageProperty->valueChanged();
emit mRectangleProperty->valueChanged();
}
Expand Down Expand Up @@ -1545,9 +1550,9 @@ class TileProperties : public ObjectProperties
}

Property *mIdProperty;
Property *mImageProperty;
Property *mRectangleProperty;
Property *mProbabilityProperty;
UrlProperty *mImageProperty;
RectProperty *mRectangleProperty;
FloatProperty *mProbabilityProperty;
};

class WangSetProperties : public ObjectProperties
Expand All @@ -1573,7 +1578,6 @@ class WangSetProperties : public ObjectProperties
push(new ChangeWangSetType(tilesetDocument(), wangSet(), value));
});

// todo: keep between 0 and WangId::MAX_COLOR_COUNT
mColorCountProperty = new IntProperty(
tr("Color Count"),
[this] { return wangSet()->colorCount(); },
Expand All @@ -1582,6 +1586,7 @@ class WangSetProperties : public ObjectProperties
wangSet(),
value));
});
mColorCountProperty->setRange(0, WangId::MAX_COLOR_COUNT);

connect(document, &Document::changed,
this, &WangSetProperties::onChanged);
Expand Down Expand Up @@ -1644,7 +1649,7 @@ class WangSetProperties : public ObjectProperties

Property *mNameProperty;
Property *mTypeProperty;
Property *mColorCountProperty;
IntProperty *mColorCountProperty;
};

class WangColorProperties : public ObjectProperties
Expand All @@ -1670,13 +1675,13 @@ class WangColorProperties : public ObjectProperties
push(new ChangeWangColorColor(tilesetDocument(), wangColor(), value));
});

// todo: set 0.01 as minimum
mProbabilityProperty = new FloatProperty(
tr("Probability"),
[this] { return wangColor()->probability(); },
[this](const double &value) {
push(new ChangeWangColorProbability(tilesetDocument(), wangColor(), value));
});
mProbabilityProperty->setMinimum(0.01);

connect(document, &Document::changed,
this, &WangColorProperties::onChanged);
Expand Down Expand Up @@ -1740,7 +1745,7 @@ class WangColorProperties : public ObjectProperties

Property *mNameProperty;
Property *mColorProperty;
Property *mProbabilityProperty;
FloatProperty *mProbabilityProperty;
};


Expand Down
32 changes: 32 additions & 0 deletions src/tiled/propertyeditorwidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ QSize SizeEdit::value() const
m_heightSpinBox->value());
}

void SizeEdit::setMinimum(int minimum)
{
m_widthSpinBox->setMinimum(minimum);
m_heightSpinBox->setMinimum(minimum);
}


SizeFEdit::SizeFEdit(QWidget *parent)
: ResponsivePairswiseWidget(parent)
Expand Down Expand Up @@ -301,6 +307,12 @@ QPointF PointFEdit::value() const
m_ySpinBox->value());
}

void PointFEdit::setSingleStep(double step)
{
m_xSpinBox->setSingleStep(step);
m_ySpinBox->setSingleStep(step);
}


RectEdit::RectEdit(QWidget *parent)
: ResponsivePairswiseWidget(parent)
Expand All @@ -320,6 +332,9 @@ RectEdit::RectEdit(QWidget *parent)
{ m_heightLabel, m_heightSpinBox },
});

m_widthSpinBox->setMinimum(0);
m_heightSpinBox->setMinimum(0);

connect(m_xSpinBox, qOverload<int>(&QSpinBox::valueChanged), this, &RectEdit::valueChanged);
connect(m_ySpinBox, qOverload<int>(&QSpinBox::valueChanged), this, &RectEdit::valueChanged);
connect(m_widthSpinBox, qOverload<int>(&QSpinBox::valueChanged), this, &RectEdit::valueChanged);
Expand All @@ -342,6 +357,23 @@ QRect RectEdit::value() const
m_heightSpinBox->value());
}

void RectEdit::setConstraint(const QRect &constraint)
{
if (constraint.isNull()) {
m_xSpinBox->setRange(std::numeric_limits<int>::lowest(),
std::numeric_limits<int>::max());
m_ySpinBox->setRange(std::numeric_limits<int>::lowest(),
std::numeric_limits<int>::max());
m_widthSpinBox->setRange(0, std::numeric_limits<int>::max());
m_heightSpinBox->setRange(0, std::numeric_limits<int>::max());
} else {
m_xSpinBox->setRange(constraint.left(), constraint.right() + 1);
m_ySpinBox->setRange(constraint.top(), constraint.bottom() + 1);
m_widthSpinBox->setRange(0, constraint.width());
m_heightSpinBox->setRange(0, constraint.height());
}
}


RectFEdit::RectFEdit(QWidget *parent)
: ResponsivePairswiseWidget(parent)
Expand Down
6 changes: 6 additions & 0 deletions src/tiled/propertyeditorwidgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class SizeEdit : public ResponsivePairswiseWidget
void setValue(const QSize &size);
QSize value() const;

void setMinimum(int minimum);

signals:
void valueChanged();

Expand Down Expand Up @@ -156,6 +158,8 @@ class PointFEdit : public ResponsivePairswiseWidget
void setValue(const QPointF &size);
QPointF value() const;

void setSingleStep(double step);

signals:
void valueChanged();

Expand All @@ -180,6 +184,8 @@ class RectEdit : public ResponsivePairswiseWidget
void setValue(const QRect &size);
QRect value() const;

void setConstraint(const QRect &constraint);

signals:
void valueChanged();

Expand Down
1 change: 1 addition & 0 deletions src/tiled/textpropertyedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ QString escapeNewlines(const QString &string);
class TextPropertyEdit : public QWidget
{
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL)

public:
explicit TextPropertyEdit(QWidget *parent = nullptr);
Expand Down
Loading

0 comments on commit 091bc14

Please sign in to comment.