Skip to content

Commit 84abbb3

Browse files
committed
Draw resize corner indicators
Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
1 parent 7638cf4 commit 84abbb3

File tree

1 file changed

+44
-14
lines changed

1 file changed

+44
-14
lines changed

src/tiled/tilesetview.cpp

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,21 @@ void TilesetView::mouseMoveEvent(QMouseEvent *event)
668668
if (!model)
669669
return;
670670

671+
const QModelIndex hoveredIndex = indexAt(event->pos());
672+
if (hoveredIndex != mHoveredIndex) {
673+
const QModelIndex previousHoveredIndex = mHoveredIndex;
674+
mHoveredIndex = hoveredIndex;
675+
676+
if (model->tileset()->isAtlas()) {
677+
viewport()->update();
678+
} else {
679+
if (previousHoveredIndex.isValid())
680+
update(previousHoveredIndex);
681+
if (mHoveredIndex.isValid())
682+
update(mHoveredIndex);
683+
}
684+
}
685+
671686
if (mDraggedIndex.isValid()) {
672687
mSnapToGrid = !(event->modifiers() & Qt::ShiftModifier);
673688

@@ -739,10 +754,6 @@ void TilesetView::mouseMoveEvent(QMouseEvent *event)
739754
return;
740755

741756
const QPoint pos = event->pos();
742-
const QModelIndex hoveredIndex = indexAt(pos);
743-
const QModelIndex previousHoveredIndex = mHoveredIndex;
744-
mHoveredIndex = hoveredIndex;
745-
746757
WangId wangId;
747758

748759
if (mWangBehavior == AssignWholeId) {
@@ -800,17 +811,9 @@ void TilesetView::mouseMoveEvent(QMouseEvent *event)
800811
}
801812
}
802813

803-
if (previousHoveredIndex != mHoveredIndex || wangId != mWangId) {
814+
if (wangId != mWangId) {
804815
mWangId = wangId;
805-
806-
if (model->tileset()->isAtlas()) {
807-
viewport()->update();
808-
} else {
809-
if (previousHoveredIndex.isValid())
810-
update(previousHoveredIndex);
811-
if (mHoveredIndex.isValid())
812-
update(mHoveredIndex);
813-
}
816+
viewport()->update();
814817
}
815818

816819
if (event->buttons() & Qt::LeftButton)
@@ -901,14 +904,41 @@ void TilesetView::paintEvent(QPaintEvent *event)
901904
const bool selected = s->isSelected(index) || index == s->currentIndex();
902905
delegate->paintTile(&painter, model, tile, rect, palette().highlight(), selected, mHoveredIndex == index);
903906

907+
// Draw grid
904908
if (mDrawGrid) {
905909
if (mRelocateTiles) {
906910
painter.setPen(palette().highlight().color());
907911
} else {
908912
painter.setPen(palette().base().color());
909913
}
914+
painter.setBrush(Qt::NoBrush);
910915
painter.drawRect(rect);
911916
}
917+
918+
// Draw resize indicators
919+
if (mRelocateTiles && (mDraggedIndex == index || (!mDraggedIndex.isValid() && mHoveredIndex == index))) {
920+
const int indicatorSize = 4 * scale();
921+
QColor indicatorColor = palette().highlight().color().lighter(150);
922+
indicatorColor.setAlpha(180); // Make slightly transparent
923+
painter.setPen(Qt::NoPen);
924+
painter.setBrush(indicatorColor);
925+
926+
// Top-left corner
927+
painter.drawRect(QRect(rect.topLeft(), QSize(indicatorSize, indicatorSize)));
928+
929+
// Top-right corner
930+
painter.drawRect(QRect(rect.topRight() - QPoint(indicatorSize, 0), QSize(indicatorSize, indicatorSize)));
931+
932+
// Bottom-left corner
933+
painter.drawRect(QRect(rect.bottomLeft() - QPoint(0, indicatorSize), QSize(indicatorSize, indicatorSize)));
934+
935+
// Bottom-right corner
936+
painter.drawRect(QRect(rect.bottomRight() - QPoint(indicatorSize, indicatorSize), QSize(indicatorSize, indicatorSize)));
937+
938+
// Reset painter state
939+
painter.setPen(palette().base().color());
940+
painter.setBrush(Qt::NoBrush);
941+
}
912942
}
913943
}
914944

0 commit comments

Comments
 (0)