Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New properties framework #4045

Draft
wants to merge 36 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ef5f794
WIP: Rewrite of the property editor
bjorn Aug 15, 2024
141e933
Progress on new property editor
bjorn Aug 18, 2024
82be477
Progress on new property editor 2
bjorn Aug 20, 2024
3c6ab56
Introduced a responsive editor for QSize
bjorn Aug 21, 2024
854f0f2
First fully functional "Map Orientation" property
bjorn Aug 26, 2024
6e2aa36
Implemented "Map Size" and "Tile Size" properties
bjorn Aug 30, 2024
faff00d
Implemented "Infinite" and "Hex Side Length" properties
bjorn Sep 2, 2024
bfc5688
Implemented "Stagger Axis/Index" properties
bjorn Sep 2, 2024
f13fd5c
Implemented remaining Map properties
bjorn Sep 3, 2024
aa9fd8c
Fixed compile against Qt 5
bjorn Sep 4, 2024
993ca5b
Implemented custom widget for Class property
bjorn Sep 4, 2024
7be4d4c
Made most Tileset properties functional
bjorn Sep 4, 2024
47d8244
Implemented Layer properties
bjorn Sep 4, 2024
09643e8
Added Image Layer and Group Layer properties
bjorn Sep 4, 2024
1ce8d98
Added properties for map objects
bjorn Sep 5, 2024
8153799
Implemented Tile, WangSet and WangColor properties
bjorn Sep 6, 2024
fee9eec
Fixed compile
bjorn Sep 6, 2024
aaf487f
Refactor that gets rid of most editor factories
bjorn Sep 6, 2024
f5ef40f
Renamed ValueTypeEditorFactory to PropertyFactory
bjorn Sep 6, 2024
2b0cb35
Simplifying or over-complicating things
bjorn Sep 9, 2024
091bc14
Addressed various property todo items
bjorn Sep 9, 2024
a8f2e31
Use tool buttons for text styling in FontProperty
bjorn Sep 9, 2024
fa195b2
Progress on various property editor features
bjorn Sep 12, 2024
5a4a7e9
Made a special case for the image layer repeat setting
bjorn Sep 16, 2024
6cee32b
Added support for "no label" properties, used for bool values
bjorn Sep 16, 2024
b84553d
Used Slider for opacity property, replacing the one in Layers view
bjorn Sep 16, 2024
e3b2ee1
Make slider an IntProperty option rather than a separate property type
bjorn Sep 16, 2024
5dc9211
Made the property label indentation shrink when there is very little …
bjorn Sep 16, 2024
5137671
Implemented custom widget for allowed transformations
bjorn Sep 17, 2024
b81836d
Fixed an issue with VariantEditor::clear
bjorn Sep 17, 2024
db138cc
Added suffixes, support for custom enums and other progress
bjorn Sep 17, 2024
f77fb26
Added support for custom enum types that are used as flags
bjorn Sep 18, 2024
68d84af
Allow expanding the child properties for any GroupProperty
bjorn Sep 18, 2024
2d18a43
Added support for custom class properties
bjorn Sep 24, 2024
b9ca537
Show inherited class name as placeholder text
bjorn Sep 26, 2024
2339f35
Implemented Remove and Reset buttons for custom properties
bjorn Sep 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,12 @@ Icons from the Elementary icon theme (GPLv3)
* src/tiled/images/32/dialog-error.png
* src/tiled/images/32/dialog-warning.png

Icons from the GNOME project (CC0 1.0 Universal)
* src/tiled/resources/images/scalable/text-bold-symbolic.svg
* src/tiled/resources/images/scalable/text-italic-symbolic.svg
* src/tiled/resources/images/scalable/text-underline-symbolic.svg
* src/tiled/resources/images/scalable/text-strikethrough-symbolic.svg


Tilesets:

Expand Down
3 changes: 1 addition & 2 deletions src/libtiled/imagelayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ ImageLayer *ImageLayer::initializeClone(ImageLayer *clone) const
clone->mImageSource = mImageSource;
clone->mTransparentColor = mTransparentColor;
clone->mImage = mImage;
clone->mRepeatX = mRepeatX;
clone->mRepeatY = mRepeatY;
clone->mRepetition = mRepetition;

return clone;
}
43 changes: 23 additions & 20 deletions src/libtiled/imagelayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ namespace Tiled {
class TILEDSHARED_EXPORT ImageLayer : public Layer
{
public:
enum Repetition {
/**
* Makes the image repeat along the X axis.
*/
RepeatX = 0x1,

/**
* Makes the image repeat along the Y axis.
*/
RepeatY = 0x2,
};
Q_DECLARE_FLAGS(RepetitionFlags, Repetition)

ImageLayer(const QString &name, int x, int y);
~ImageLayer() override;

Expand Down Expand Up @@ -114,25 +127,13 @@ class TILEDSHARED_EXPORT ImageLayer : public Layer
*/
bool isEmpty() const override;

/**
* Returns true if the image of this layer repeats along the X axis.
*/
bool repeatX() const { return mRepeatX; }

/**
* Returns true if the image of this layer repeats along the Y axis.
*/
bool repeatY() const { return mRepeatY; }

/**
* Sets whether the image of this layer repeats along the X axis.
*/
void setRepeatX(bool repeatX) { mRepeatX = repeatX; }
bool repeatX() const { return mRepetition & RepeatX; }
bool repeatY() const { return mRepetition & RepeatY; }
RepetitionFlags repetition() const { return mRepetition; }

/**
* Sets whether the image of this layer repeats along the Y axis.
*/
void setRepeatY(bool repeatY) { mRepeatY = repeatY; }
void setRepeatX(bool repeatX) { mRepetition.setFlag(RepeatX, repeatX); }
void setRepeatY(bool repeatY) { mRepetition.setFlag(RepeatY, repeatY); }
void setRepetition(RepetitionFlags repetition) { mRepetition = repetition; }

ImageLayer *clone() const override;

Expand All @@ -143,8 +144,10 @@ class TILEDSHARED_EXPORT ImageLayer : public Layer
QUrl mImageSource;
QColor mTransparentColor;
QPixmap mImage;
bool mRepeatX = false;
bool mRepeatY = false;
RepetitionFlags mRepetition;
};

} // namespace Tiled

Q_DECLARE_METATYPE(Tiled::ImageLayer::RepetitionFlags)
Q_DECLARE_OPERATORS_FOR_FLAGS(Tiled::ImageLayer::RepetitionFlags)
2 changes: 2 additions & 0 deletions src/libtiled/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -791,3 +791,5 @@ Q_DECLARE_METATYPE(Tiled::Map*)
Q_DECLARE_METATYPE(Tiled::Map::Orientation)
Q_DECLARE_METATYPE(Tiled::Map::LayerDataFormat)
Q_DECLARE_METATYPE(Tiled::Map::RenderOrder)
Q_DECLARE_METATYPE(Tiled::Map::StaggerAxis)
Q_DECLARE_METATYPE(Tiled::Map::StaggerIndex)
1 change: 1 addition & 0 deletions src/libtiled/objectgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,4 @@ TILEDSHARED_EXPORT ObjectGroup::DrawOrder drawOrderFromString(const QString &);
} // namespace Tiled

Q_DECLARE_METATYPE(Tiled::ObjectGroup*)
Q_DECLARE_METATYPE(Tiled::ObjectGroup::DrawOrder)
4 changes: 4 additions & 0 deletions src/libtiled/tileset.h
Original file line number Diff line number Diff line change
Expand Up @@ -739,5 +739,9 @@ inline void Tileset::setTransformationFlags(TransformationFlags flags)

Q_DECLARE_METATYPE(Tiled::Tileset*)
Q_DECLARE_METATYPE(Tiled::SharedTileset)
Q_DECLARE_METATYPE(Tiled::Tileset::Orientation)
Q_DECLARE_METATYPE(Tiled::Tileset::TileRenderSize)
Q_DECLARE_METATYPE(Tiled::Tileset::FillMode)
Q_DECLARE_METATYPE(Tiled::Tileset::TransformationFlags)

Q_DECLARE_OPERATORS_FOR_FLAGS(Tiled::Tileset::TransformationFlags)
3 changes: 2 additions & 1 deletion src/libtiled/wangset.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,5 +424,6 @@ TILEDSHARED_EXPORT WangSet::Type wangSetTypeFromString(const QString &);

} // namespace Tiled

Q_DECLARE_METATYPE(Tiled::WangSet*)
Q_DECLARE_METATYPE(Tiled::WangId)
Q_DECLARE_METATYPE(Tiled::WangSet*)
Q_DECLARE_METATYPE(Tiled::WangSet::Type)
34 changes: 29 additions & 5 deletions src/tiled/changeevents.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class ChangeEvent
WangSetRemoved,
WangSetChanged,
WangColorAboutToBeRemoved,
WangColorChanged,
} type;

protected:
Expand Down Expand Up @@ -164,7 +165,7 @@ class TileLayerChangeEvent : public LayerChangeEvent
class ImageLayerChangeEvent : public LayerChangeEvent
{
public:
enum TileLayerProperty {
enum ImageLayerProperty {
TransparentColorProperty = 1 << 7,
ImageSourceProperty = 1 << 8,
RepeatProperty = 1 << 9,
Expand Down Expand Up @@ -277,17 +278,20 @@ class WangSetChangeEvent : public ChangeEvent
{
public:
enum WangSetProperty {
TypeProperty = 1 << 0,
NameProperty,
TypeProperty,
ImageProperty,
ColorCountProperty,
};

WangSetChangeEvent(WangSet *wangSet, int properties)
WangSetChangeEvent(WangSet *wangSet, WangSetProperty property)
: ChangeEvent(WangSetChanged)
, wangSet(wangSet)
, properties(properties)
, property(property)
{}

WangSet *wangSet;
int properties;
WangSetProperty property;
};

class WangColorEvent : public ChangeEvent
Expand All @@ -303,4 +307,24 @@ class WangColorEvent : public ChangeEvent
int color;
};

class WangColorChangeEvent : public ChangeEvent
{
public:
enum WangColorProperty {
NameProperty,
ColorProperty,
ImageProperty,
ProbabilityProperty,
};

WangColorChangeEvent(WangColor *wangColor, WangColorProperty property)
: ChangeEvent(WangColorChanged)
, wangColor(wangColor)
, property(property)
{}

WangColor *wangColor;
WangColorProperty property;
};

} // namespace Tiled
2 changes: 1 addition & 1 deletion src/tiled/changeproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ChangeClassName::ChangeClassName(Document *document,
QUndoCommand *parent)
: ChangeValue(document, objects, className, parent)
{
setText(QCoreApplication::translate("Undo Commands", "Change Type"));
setText(QCoreApplication::translate("Undo Commands", "Change Class"));
}

void ChangeClassName::undo()
Expand Down
4 changes: 3 additions & 1 deletion src/tiled/colorbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ColorButton::ColorButton(QWidget *parent)

void ColorButton::setColor(const QColor &color)
{
if (mColor == color || !color.isValid())
if (mColor == color)
return;

mColor = color;
Expand Down Expand Up @@ -75,7 +75,9 @@ void ColorButton::pickColor()

void ColorButton::updateIcon()
{
// todo: fix gray icon in disabled state (consider using opacity, and not using an icon at all)
setIcon(Utils::colorIcon(mColor, iconSize()));
setText(mColor.isValid() ? QString() : tr("Unset"));
}

#include "moc_colorbutton.cpp"
1 change: 1 addition & 0 deletions src/tiled/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ void Document::setCurrentObject(Object *object, Document *owningDocument)

emit currentObjectSet(object);
emit currentObjectChanged(object);
emit currentObjectsChanged();
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/tiled/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class Document : public QObject,

void currentObjectSet(Object *object);
void currentObjectChanged(Object *object);
void currentObjectsChanged();

/**
* Makes the Properties window visible and take focus.
Expand Down
2 changes: 1 addition & 1 deletion src/tiled/fileedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ FileEdit::FileEdit(QWidget *parent)
mOkTextColor = mLineEdit->palette().color(QPalette::Active, QPalette::Text);

QToolButton *button = new QToolButton(this);
button->setText(QLatin1String("..."));
button->setText(QStringLiteral(""));
button->setAutoRaise(true);
button->setToolTip(tr("Choose"));
layout->addWidget(mLineEdit);
Expand Down
90 changes: 3 additions & 87 deletions src/tiled/layerdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "map.h"
#include "mapdocument.h"
#include "mapdocumentactionhandler.h"
#include "objectgroup.h"
#include "reversingproxymodel.h"
#include "utils.h"
#include "iconcheckdelegate.h"
Expand All @@ -39,10 +38,8 @@
#include <QBoxLayout>
#include <QContextMenuEvent>
#include <QHeaderView>
#include <QLabel>
#include <QMenu>
#include <QScopedValueRollback>
#include <QSlider>
#include <QStyledItemDelegate>
#include <QToolBar>
#include <QUndoStack>
Expand All @@ -54,8 +51,6 @@ using namespace Tiled;

LayerDock::LayerDock(QWidget *parent):
QDockWidget(parent),
mOpacityLabel(new QLabel),
mOpacitySlider(new QSlider(Qt::Horizontal)),
mLayerView(new LayerView)
{
setObjectName(QLatin1String("layerDock"));
Expand All @@ -64,13 +59,6 @@ LayerDock::LayerDock(QWidget *parent):
QVBoxLayout *layout = new QVBoxLayout(widget);
layout->setContentsMargins(0, 0, 0, 0);

QHBoxLayout *opacityLayout = new QHBoxLayout;
mOpacitySlider->setRange(0, 100);
mOpacitySlider->setEnabled(false);
opacityLayout->addWidget(mOpacityLabel);
opacityLayout->addWidget(mOpacitySlider);
mOpacityLabel->setBuddy(mOpacitySlider);

MapDocumentActionHandler *handler = MapDocumentActionHandler::instance();

QMenu *newLayerMenu = handler->createNewLayerMenu(this);
Expand Down Expand Up @@ -99,20 +87,12 @@ LayerDock::LayerDock(QWidget *parent):
buttonContainer->addWidget(spacerWidget);
buttonContainer->addAction(ActionManager::action("HighlightCurrentLayer"));

QVBoxLayout *listAndToolBar = new QVBoxLayout;
listAndToolBar->setSpacing(0);
listAndToolBar->addWidget(mLayerView);
listAndToolBar->addWidget(buttonContainer);

layout->addLayout(opacityLayout);
layout->addLayout(listAndToolBar);
layout->setSpacing(0);
layout->addWidget(mLayerView);
layout->addWidget(buttonContainer);

setWidget(widget);
retranslateUi();

connect(mOpacitySlider, &QAbstractSlider::valueChanged,
this, &LayerDock::sliderValueChanged);
updateOpacitySlider();
}

void LayerDock::setMapDocument(MapDocument *mapDocument)
Expand All @@ -126,10 +106,6 @@ void LayerDock::setMapDocument(MapDocument *mapDocument)
mMapDocument = mapDocument;

if (mMapDocument) {
connect(mMapDocument, &MapDocument::changed,
this, &LayerDock::documentChanged);
connect(mMapDocument, &MapDocument::currentLayerChanged,
this, &LayerDock::updateOpacitySlider);
connect(mMapDocument, &MapDocument::editLayerNameRequested,
this, &LayerDock::editLayerName);
}
Expand All @@ -145,8 +121,6 @@ void LayerDock::setMapDocument(MapDocument *mapDocument)
mLayerView->header()->resizeSection(1, iconSectionWidth);
mLayerView->header()->resizeSection(2, iconSectionWidth);
}

updateOpacitySlider();
}

void LayerDock::changeEvent(QEvent *e)
Expand All @@ -162,40 +136,6 @@ void LayerDock::changeEvent(QEvent *e)
}
}

void LayerDock::updateOpacitySlider()
{
const bool enabled = mMapDocument &&
mMapDocument->currentLayer() != nullptr;

mOpacitySlider->setEnabled(enabled);
mOpacityLabel->setEnabled(enabled);

QScopedValueRollback<bool> updating(mUpdatingSlider, true);
if (enabled) {
qreal opacity = mMapDocument->currentLayer()->opacity();
mOpacitySlider->setValue(qRound(opacity * 100));
} else {
mOpacitySlider->setValue(100);
}
}

void LayerDock::documentChanged(const ChangeEvent &change)
{
switch (change.type) {
case ChangeEvent::LayerChanged: {
auto &layerChange = static_cast<const LayerChangeEvent&>(change);

// Don't update the slider when we're the ones changing the layer opacity
if ((layerChange.properties & LayerChangeEvent::OpacityProperty) && !mChangingLayerOpacity)
if (layerChange.layer == mMapDocument->currentLayer())
updateOpacitySlider();
break;
}
default:
break;
}
}

void LayerDock::editLayerName()
{
if (!isVisible())
Expand All @@ -208,33 +148,9 @@ void LayerDock::editLayerName()
mLayerView->editLayerModelIndex(layerModel->index(currentLayer));
}

void LayerDock::sliderValueChanged(int opacity)
{
if (!mMapDocument)
return;

// When the slider changes value just because we're updating it, it
// shouldn't try to set the layer opacity.
if (mUpdatingSlider)
return;

const auto layer = mMapDocument->currentLayer();
if (!layer)
return;

if (static_cast<int>(layer->opacity() * 100) != opacity) {
LayerModel *layerModel = mMapDocument->layerModel();
QScopedValueRollback<bool> updating(mChangingLayerOpacity, true);
layerModel->setData(layerModel->index(layer),
qreal(opacity) / 100,
LayerModel::OpacityRole);
}
}

void LayerDock::retranslateUi()
{
setWindowTitle(tr("Layers"));
mOpacityLabel->setText(tr("Opacity:"));
mNewLayerButton->setToolTip(tr("New Layer"));
}

Expand Down
Loading