Skip to content
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0b03c73
Created new mapItem instance for rendering the tool brush on mapview.…
UltraDagon Jun 16, 2026
6760a51
Fixed tool brush mapitem to no longer cause errors when the map is un…
UltraDagon Jun 19, 2026
f530985
mapview.qml updates upon old editor tool usage
UltraDagon Jun 19, 2026
0005b76
Added sizeChanged and tileSizeChanged notify signals to editablemap
UltraDagon Jun 20, 2026
451055f
Changed libtiledquick/mapitem::repaintRegion to only update the affec…
UltraDagon Jun 20, 2026
d703b13
Updated new ToolBrush to work with mouse movement and fill tool
UltraDagon Jun 23, 2026
85dcc28
Moved quick brush changes to onQuickBrushChanged and set up emits in …
UltraDagon Jun 24, 2026
833bbf0
Don't link to the tiledquickplugin
bjorn Jun 24, 2026
b07fc43
Changed editablemap's size signals to be sent properly; MapItem now r…
UltraDagon Jun 24, 2026
9ca0d81
Added disconnects for libtiledquick/mapitem's setmap connections
UltraDagon Jun 24, 2026
40055c8
Small fixes for review comments
UltraDagon Jun 24, 2026
2e3f22b
Renamed quickBrushChanged signal to brushMapChanged; Javascript owner…
UltraDagon Jun 25, 2026
8632491
Partially implemented requested brushItem->map() and toolBrushMap cha…
UltraDagon Jun 26, 2026
e096b8d
Moved brushChanged logic to a Q_PROPERTY and quickMouseCoordsChanged …
UltraDagon Jun 27, 2026
8c3e48f
Fixed ifdefs for TILEDQUICK_LIB
UltraDagon Jun 27, 2026
4cbb046
Created template classes and setup for regionOverlay
UltraDagon Jun 28, 2026
e6ac0b9
Fixed crash that happened upon QML's garbage collection for tileEditP…
UltraDagon Jun 29, 2026
5775da4
Fixed small typo in mapview.qml
UltraDagon Jun 29, 2026
26b461f
Fixed memory leak with setTileEditPreview; brushMapChanged now takes …
UltraDagon Jun 30, 2026
fc5b3ec
Removed AbstractTileTool::toolBrush(); Fixed crash caused by closing …
UltraDagon Jun 30, 2026
b8afceb
Added RegionOverlay for selected tiles to mapview.qml
UltraDagon Jul 1, 2026
163e803
Linked quick mouse onPress and onRelease events to selectedTool
UltraDagon Jul 2, 2026
40b1776
Moved tileEditRegionChanged code from brushItem to abstractTileTool &…
UltraDagon Jul 3, 2026
5d21d77
Changed brushRegionOverlay to indicate if brush is in or out of map b…
UltraDagon Jul 5, 2026
d4a3f4a
Added selectedRegionOverlay; RegionOverlay tweaks
UltraDagon Jul 7, 2026
a75bf94
Added EditableMap constructor for using SharedMaps
UltraDagon Jul 7, 2026
4dfaad9
Added safeguard for new EditableMap constructor usage; Small RegionOv…
UltraDagon Jul 7, 2026
eee95ff
Fixed crash by only forwarding Quick mouse events to an active tool
bjorn Jul 8, 2026
8dd9411
Added requested changes
UltraDagon Jul 9, 2026
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
4 changes: 4 additions & 0 deletions src/libtiledquick/libtiledquick.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ DynamicLibrary {
"mapitem.h",
"maploader.cpp",
"maploader.h",
"regionoverlay.cpp",
"regionoverlay.h",
"tiledquick_global.h",
"tilelayeritem.cpp",
"tilelayeritem.h",
Expand Down Expand Up @@ -71,6 +73,8 @@ DynamicLibrary {
cpp.includePaths: exportingProduct.sourceDirectory
}

Depends { name: "Qt.core" }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this added here? I think that should be already covered by this line above:

Depends { name: "Qt"; submodules: ["quick","shadertools"]; versionAtLeast: "6.5" }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that, Qt Creator auto adds it whenever I add new files and I must have forgot to remove it.


install: !qbs.targetOS.contains("darwin")
installDir: {
if (qbs.targetOS.contains("windows"))
Expand Down
33 changes: 18 additions & 15 deletions src/libtiledquick/mapgriditem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ QSGNode *MapGridItem::updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNode

void MapGridItem::setTileSize(const QPointF &tileSize)
{
if (mTileSize != tileSize) {
mTileSize = tileSize;
emit tileSizeChanged();
update();
}
if (mTileSize == tileSize)
return;

mTileSize = tileSize;
emit tileSizeChanged();
update();
}

QPointF MapGridItem::tileSize() const
Expand All @@ -82,11 +83,12 @@ QPointF MapGridItem::tileSize() const

void MapGridItem::setScale(const qreal &scale)
{
if (mScale != scale) {
mScale = scale;
emit scaleChanged();
update();
}
if (mScale == scale)
return;

mScale = scale;
emit scaleChanged();
update();
}

qreal MapGridItem::scale() const
Expand All @@ -96,11 +98,12 @@ qreal MapGridItem::scale() const

void MapGridItem::setColor(const QColor &color)
{
if(mColor != color) {
mColor = color;
emit colorChanged();
update();
}
if (mColor == color)
return;

mColor = color;
emit colorChanged();
update();
}

QColor MapGridItem::color() const
Expand Down
26 changes: 26 additions & 0 deletions src/libtiledquick/mapitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ using namespace TiledQuick;

MapItem::MapItem(QQuickItem *parent)
: QQuickItem(parent)
, mMap(nullptr)
, mEditableMap(nullptr)
{
}

Expand All @@ -40,8 +42,21 @@ void MapItem::setMap(Tiled::EditableMap *editableMap)
if (mEditableMap == editableMap)
return;

if (mEditableMap && mEditableMap->mapDocument()) {
Tiled::MapDocument *oldMapDocument = mEditableMap->mapDocument();
disconnect(oldMapDocument, &Tiled::MapDocument::regionChanged, this, &MapItem::repaintRegion);
disconnect(oldMapDocument, &Tiled::MapDocument::mapResized, this, &MapItem::refresh);
}

if (editableMap && editableMap->mapDocument()) {
Tiled::MapDocument *mapDocument = editableMap->mapDocument();
connect(mapDocument, &Tiled::MapDocument::regionChanged, this, &MapItem::repaintRegion);
Comment thread
bjorn marked this conversation as resolved.
connect(mapDocument, &Tiled::MapDocument::mapResized, this, &MapItem::refresh);
}

mEditableMap = editableMap;
mMap = editableMap ? editableMap->map() : nullptr;

refresh();
emit mapChanged();
}
Expand Down Expand Up @@ -170,3 +185,14 @@ void MapItem::refresh()
const QRect rect = mRenderer->mapBoundingRect();
setImplicitSize(rect.width(), rect.height());
}

void MapItem::repaintRegion(const QRegion &, Tiled::TileLayer *tileLayer)
{
for (TileLayerItem *tileLayerItem : std::as_const(mTileLayerItems)) {
if (tileLayer == tileLayerItem->layer()) {
// TODO: Update only the region edited
tileLayerItem->update();
continue;
}
}
}
2 changes: 2 additions & 0 deletions src/libtiledquick/mapitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class TILEDQUICK_SHARED_EXPORT MapItem : public QQuickItem
private:
void refresh();

void repaintRegion(const QRegion &region, Tiled::TileLayer *tileLayer);

Tiled::Map *mMap;
Tiled::EditableMap *mEditableMap;
QRectF mVisibleArea;
Expand Down
95 changes: 95 additions & 0 deletions src/libtiledquick/regionoverlay.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* regionoverlay.cpp
* Copyright 2026, UltraDagon
*
* This file is part of Tiled Quick.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "regionoverlay.h"

#include <QPainterPath>
#include <QApplication>
#include <QPalette>

using namespace TiledQuick;

RegionOverlay::RegionOverlay(QQuickItem *parent)
: QQuickItem(parent)
, mTileSize(0, 0)
, mRegion(QRegion())
, mColor(QApplication::palette().highlight().color())
{
}

RegionOverlay::~RegionOverlay() = default;

QList<QPolygonF> RegionOverlay::polygons() const
{
QPainterPath path;

for (const QRect &r : mRegion.rects())
path.addRect(r);

QList<QPolygonF> polygons = path.simplified().toFillPolygons();

QTransform transform;
transform.scale(mTileSize.x(), mTileSize.y());

for (QPolygonF &polygon : polygons)
polygon = polygon * transform;

return polygons;
}

QColor RegionOverlay::strokeColor() const
{
return mColor;
}

QColor RegionOverlay::fillColor() const
{
QColor fillColor = mColor;
fillColor.setAlpha(64);
return fillColor;
}

QPointF RegionOverlay::tileSize() const
{
return mTileSize;
}

void RegionOverlay::setTileSize(const QPointF &tileSize)
{
if (mTileSize == tileSize)
return;

mTileSize = tileSize;
emit tileSizeChanged();
}

QRegion RegionOverlay::region() const
{
return mRegion;
}

void RegionOverlay::setRegion(const QRegion &region)
{
if (mRegion == region)
return;

mRegion = region;
emit regionChanged();
}
60 changes: 60 additions & 0 deletions src/libtiledquick/regionoverlay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* regionoverlay.h
* Copyright 2026, UltraDagon
*
* This file is part of Tiled Quick.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <QQuickItem>

#include "tiledquick_global.h"

namespace TiledQuick {

class TILEDQUICK_SHARED_EXPORT RegionOverlay : public QQuickItem
{
Q_OBJECT

Q_PROPERTY(QPointF tileSize READ tileSize WRITE setTileSize NOTIFY tileSizeChanged)
Q_PROPERTY(QRegion region READ region WRITE setRegion NOTIFY regionChanged)

public:
explicit RegionOverlay(QQuickItem *parent = nullptr);
~RegionOverlay() override;

Q_INVOKABLE QList<QPolygonF> polygons() const;
Q_INVOKABLE QColor strokeColor() const;
Q_INVOKABLE QColor fillColor() const;

QPointF tileSize() const;
void setTileSize(const QPointF &tileSize);

QRegion region() const;
void setRegion(const QRegion &region);

signals:
void tileSizeChanged();
void regionChanged();

private:
QPointF mTileSize;
QRegion mRegion;
QColor mColor;
};

} // namespace TiledQuick
6 changes: 4 additions & 2 deletions src/libtiledquick/tilelayeritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ void TileLayerItem::syncWithTileLayer()
setSize(boundingRect.size());
}



QSGNode *TileLayerItem::updatePaintNode(QSGNode *node,
QQuickItem::UpdatePaintNodeData *)
{
Expand Down Expand Up @@ -201,6 +199,10 @@ QSGNode *TileLayerItem::updatePaintNode(QSGNode *node,
return node;
}

Tiled::TileLayer *TileLayerItem::layer() {
return mLayer;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good candidate for inlining. :-)

}

void TileLayerItem::updateVisibleTiles()
{
const MapItem *mapItem = static_cast<MapItem*>(parentItem());
Expand Down
2 changes: 2 additions & 0 deletions src/libtiledquick/tilelayeritem.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class TILEDQUICK_SHARED_EXPORT TileLayerItem : public QQuickItem

QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *) override;

Tiled::TileLayer *layer();

public slots:
void updateVisibleTiles();

Expand Down
5 changes: 5 additions & 0 deletions src/tiled/abstracttilefilltool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ void AbstractTileFillTool::updatePreview(const QRegion &fillRegion)

preview->addTilesets(preview->usedTilesets());

emit brushMapChanged(preview.get());
emit brushRegionChanged(fillRegion);

brushItem()->setMap(preview);
mPreviewMap = preview;
}
Expand All @@ -248,6 +251,8 @@ bool AbstractTileFillTool::applyPreview(const QString &text)

void AbstractTileFillTool::clearOverlay()
{
emit brushMapChanged(nullptr);

brushItem()->clear();
static_cast<WangBrushItem*>(brushItem())->setInvalidTiles(QRegion());

Expand Down
7 changes: 6 additions & 1 deletion src/tiled/abstracttiletool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ AbstractTileTool::~AbstractTileTool()
delete mBrushItem;
}

QRegion AbstractTileTool::validRegion() const
{
return mBrushItem->tileRegion();
}

void AbstractTileTool::activate(MapScene *scene)
{
scene->addItem(mBrushItem);
Expand Down Expand Up @@ -243,7 +248,7 @@ void AbstractTileTool::updateBrushVisibility()
}
}

mBrushItem->setVisible(showBrush);
mBrushItem->setVisible(showBrush || Preferences::instance()->useNewHardwareRenderer());
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/tiled/abstracttiletool.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class AbstractTileTool : public AbstractTool

~AbstractTileTool() override;

QRegion validRegion() const;

void activate(MapScene *scene) override;
void deactivate(MapScene *scene) override;

Expand All @@ -62,6 +64,10 @@ class AbstractTileTool : public AbstractTool

void keyPressed(QKeyEvent *event) override;

signals:
void brushMapChanged(Tiled::Map *map);
void brushRegionChanged(const QRegion &region);

protected:
void mapDocumentChanged(MapDocument *oldDocument,
MapDocument *newDocument) override;
Expand Down
Loading
Loading