diff --git a/include/core/editcommands.h b/include/core/editcommands.h index 83e33d41..eabfacc0 100644 --- a/include/core/editcommands.h +++ b/include/core/editcommands.h @@ -204,11 +204,6 @@ private: /// Implements a command to commit a map or border resize action. class ResizeLayout : public QUndoCommand { public: - // ResizeLayout(Layout *layout, QSize oldLayoutDimensions, QSize newLayoutDimensions, - // const Blockdata &oldMetatiles, const Blockdata &newMetatiles, - // QSize oldBorderDimensions, QSize newBorderDimensions, - // const Blockdata &oldBorder, const Blockdata &newBorder, - // QUndoCommand *parent = nullptr); ResizeLayout(Layout *layout, QSize oldLayoutDimensions, QMargins newLayoutMargins, const Blockdata &oldMetatiles, const Blockdata &newMetatiles, QSize oldBorderDimensions, QSize newBorderDimensions, diff --git a/include/ui/movablerect.h b/include/ui/movablerect.h index c5ca00ab..6f53e729 100644 --- a/include/ui/movablerect.h +++ b/include/ui/movablerect.h @@ -55,6 +55,7 @@ public: } void updatePosFromRect(QRect newPos); + void setLimit(QRect limit) { this->limit = limit; } protected: void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override; @@ -71,6 +72,8 @@ private: QPointF clickedPos = QPointF(); QRect clickedRect; + QRect limit = QRect(); + int lineWidth = 8; signals: diff --git a/src/ui/movablerect.cpp b/src/ui/movablerect.cpp index e9e373e0..6cb3c7e0 100644 --- a/src/ui/movablerect.cpp +++ b/src/ui/movablerect.cpp @@ -151,13 +151,24 @@ void ResizableRect::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { break; } - // lower bounds limits - if (resizedRect.width() < 16) - resizedRect.setWidth(16); - if (resizedRect.height() < 16) - resizedRect.setHeight(16); + // lower bounds limits, smallest possible size is 16x16 square + if (resizedRect.width() < 16) { + if (dx < 0) { // right sided adjustment made + resizedRect.setWidth(16); + } else { // left sided adjustment slightly more complicated + int dxMax = this->clickedRect.right() - this->clickedRect.left() - 16; + resizedRect.adjust(dxMax - dx, 0, 0, 0); + } + } + if (resizedRect.height() < 16) { + if (dy < 0) { // bottom + resizedRect.setHeight(16); + } else { // top + int dyMax = this->clickedRect.bottom() - this->clickedRect.top() - 16; + resizedRect.adjust(0, dyMax - dy, 0, 0); + } + } - // TODO: upper bound limits - - this->updatePosFromRect(resizedRect); + // Upper bounds: clip resized to limit rect + this->updatePosFromRect(resizedRect & this->limit); } diff --git a/src/ui/resizelayoutpopup.cpp b/src/ui/resizelayoutpopup.cpp index c6c48db7..2ed540bc 100644 --- a/src/ui/resizelayoutpopup.cpp +++ b/src/ui/resizelayoutpopup.cpp @@ -22,13 +22,13 @@ void CheckeredBgScene::drawBackground(QPainter *painter, const QRectF &rect) { for (int x = xMin, xTile = 0; x <= xMax; x += this->gridSize, xTile++) { for (int y = yMin, yTile = 0; y <= yMax; y += this->gridSize, yTile++) { if (!((xTile ^ yTile) & 1)) { // tile numbers have same parity (evenness) - if (this->validRect.contains(x, y)) // check if inside validRect + if (this->validRect.contains(x, y)) paintColor = QColor(132, 217, 165); // green light color else paintColor = 0xbcbcbc; // normal light color } else { - if (this->validRect.contains(x, y)) // check if inside validRect + if (this->validRect.contains(x, y)) paintColor = QColor(76, 178, 121); // green dark color else paintColor = 0x969696; // normal dark color @@ -142,6 +142,7 @@ void ResizeLayoutPopup::setupLayoutView() { static bool layoutSizeRectVisible = true; this->outline = new ResizableRect(this, &layoutSizeRectVisible, this->editor->layout->getWidth(), this->editor->layout->getHeight(), qRgb(255, 0, 255)); + this->outline->setLimit(cover->rect().toAlignedRect()); connect(outline, &ResizableRect::rectUpdated, [=](QRect rect){ this->scene->setValidRect(rect); this->ui->spinBox_width->setValue(rect.width() / 16);