@@ -55,28 +55,6 @@ using namespace Tiled;
5555
5656namespace {
5757
58- static void setupTilesetGridTransform (const Tileset &tileset, QTransform &transform, QRect &targetRect)
59- {
60- if (tileset.orientation () == Tileset::Isometric) {
61- const QPoint tileCenter = targetRect.center ();
62- targetRect.setHeight (targetRect.width ());
63- targetRect.moveCenter (tileCenter);
64-
65- const QSize gridSize = tileset.gridSize ();
66-
67- transform.translate (tileCenter.x (), tileCenter.y ());
68-
69- const auto ratio = (qreal) gridSize.height () / gridSize.width ();
70- const auto scaleX = 1.0 / sqrt (2.0 );
71- const auto scaleY = scaleX * ratio;
72- transform.scale (scaleX, scaleY);
73-
74- transform.rotate (45.0 );
75-
76- transform.translate (-tileCenter.x (), -tileCenter.y ());
77- }
78- }
79-
8058/* *
8159 * The delegate for drawing tile items in the tileset view.
8260 */
@@ -105,11 +83,13 @@ class TileDelegate : public QAbstractItemDelegate
10583 TilesetView *mTilesetView ;
10684};
10785
86+ } // anonymous namespace
87+
10888void TileDelegate::paint (QPainter *painter,
10989 const QStyleOptionViewItem &option,
11090 const QModelIndex &index) const
11191{
112- const TilesetModel *model = static_cast <const TilesetModel*>(index.model ());
92+ const auto *model = static_cast <const TilesetModel*>(index.model ());
11393 const Tile *tile = model->tileAt (index);
11494 if (!tile)
11595 return ;
@@ -245,6 +225,28 @@ void TileDelegate::drawFilmStrip(QPainter *painter, QRect targetRect)
245225 painter->restore ();
246226}
247227
228+ static void setupTilesetGridTransform (const Tileset &tileset, QTransform &transform, QRect &targetRect)
229+ {
230+ if (tileset.orientation () == Tileset::Isometric) {
231+ const QPoint tileCenter = targetRect.center ();
232+ targetRect.setHeight (targetRect.width ());
233+ targetRect.moveCenter (tileCenter);
234+
235+ const QSize gridSize = tileset.gridSize ();
236+
237+ transform.translate (tileCenter.x (), tileCenter.y ());
238+
239+ const auto ratio = (qreal) gridSize.height () / gridSize.width ();
240+ const auto scaleX = 1.0 / sqrt (2.0 );
241+ const auto scaleY = scaleX * ratio;
242+ transform.scale (scaleX, scaleY);
243+
244+ transform.rotate (45.0 );
245+
246+ transform.translate (-tileCenter.x (), -tileCenter.y ());
247+ }
248+ }
249+
248250void TileDelegate::drawWangOverlay (QPainter *painter,
249251 const Tile *tile,
250252 QRect targetRect,
@@ -278,7 +280,6 @@ void TileDelegate::drawWangOverlay(QPainter *painter,
278280 painter->restore ();
279281}
280282
281- } // anonymous namespace
282283
283284TilesetView::TilesetView (QWidget *parent)
284285 : QTableView(parent)
@@ -585,34 +586,38 @@ void TilesetView::mousePressEvent(QMouseEvent *event)
585586
586587void TilesetView::mouseMoveEvent (QMouseEvent *event)
587588{
588- if (mEditWangSet ) {
589- if (!mWangSet )
590- return ;
589+ if (!mEditWangSet ) {
590+ QTableView::mouseMoveEvent (event);
591+ return ;
592+ }
591593
592- const QPoint pos = event->pos ();
593- const QModelIndex hoveredIndex = indexAt (pos);
594- const QModelIndex previousHoveredIndex = mHoveredIndex ;
595- mHoveredIndex = hoveredIndex;
594+ if (!mWangSet )
595+ return ;
596596
597- WangId wangId;
597+ const QPoint pos = event->pos ();
598+ const QModelIndex hoveredIndex = indexAt (pos);
599+ const QModelIndex previousHoveredIndex = mHoveredIndex ;
600+ mHoveredIndex = hoveredIndex;
598601
599- if (mWangBehavior == AssignWholeId) {
600- wangId = mWangId ;
601- } else {
602- QRect tileRect = visualRect (mHoveredIndex );
603- QTransform transform;
604- setupTilesetGridTransform (*tilesetDocument ()->tileset (), transform, tileRect);
602+ WangId wangId;
605603
604+ if (mWangBehavior == AssignWholeId) {
605+ wangId = mWangId ;
606+ } else {
607+ QRect tileRect = visualRect (mHoveredIndex );
608+ QTransform transform;
609+ setupTilesetGridTransform (*tilesetDocument ()->tileset (), transform, tileRect);
610+
611+ if (!tileRect.isEmpty ()) {
606612 const auto mappedPos = transform.inverted ().map (pos);
607- QPoint tileLocalPos = mappedPos - tileRect.topLeft ();
608- QPointF tileLocalPosF ((qreal) tileLocalPos.x () / tileRect.width (),
609- (qreal) tileLocalPos.y () / tileRect.height ());
613+ QPointF tileLocalPosF (qreal (mappedPos.x () - tileRect.x ()) / tileRect.width (),
614+ qreal (mappedPos.y () - tileRect.y ()) / tileRect.height ());
610615
611616 const int x = qBound (0 , qFloor (tileLocalPosF.x () * 3 ), 2 );
612617 const int y = qBound (0 , qFloor (tileLocalPosF.y () * 3 ), 2 );
613618 WangId::Index index = WangId::indexByGrid (x, y);
614619
615- if (index != WangId::NumIndexes) { // center is dead zone
620+ if (index != WangId::NumIndexes) { // center is dead zone for all WangSet types
616621 switch (mWangSet ->type ()) {
617622 case WangSet::Edge:
618623 tileLocalPosF -= QPointF (0.5 , 0.5 );
@@ -650,23 +655,19 @@ void TilesetView::mouseMoveEvent(QMouseEvent *event)
650655 : WangId::INDEX_MASK);
651656 }
652657 }
658+ }
653659
654- if (previousHoveredIndex != mHoveredIndex || wangId != mWangId ) {
655- mWangId = wangId;
656-
657- if (previousHoveredIndex.isValid ())
658- update (previousHoveredIndex);
659- if (mHoveredIndex .isValid ())
660- update (mHoveredIndex );
661- }
662-
663- if (event->buttons () & Qt::LeftButton)
664- applyWangId ();
660+ if (previousHoveredIndex != mHoveredIndex || wangId != mWangId ) {
661+ mWangId = wangId;
665662
666- return ;
663+ if (previousHoveredIndex.isValid ())
664+ update (previousHoveredIndex);
665+ if (mHoveredIndex .isValid ())
666+ update (mHoveredIndex );
667667 }
668668
669- QTableView::mouseMoveEvent (event);
669+ if (event->buttons () & Qt::LeftButton)
670+ applyWangId ();
670671}
671672
672673void TilesetView::mouseReleaseEvent (QMouseEvent *event)
@@ -931,7 +932,7 @@ void TilesetView::applyWangId()
931932 WangId newWangId = previousWangId;
932933
933934 if (mWangBehavior == AssignWholeId) {
934- newWangId = mWangId ;
935+ newWangId = mWangId & ~ mWangId . mask (WangId::INDEX_MASK) ;
935936 } else {
936937 for (int i = 0 ; i < WangId::NumIndexes; ++i) {
937938 if (mWangId .indexColor (i))
0 commit comments