add limits for resizing layouts

This commit is contained in:
garak 2024-11-12 12:30:56 -05:00
parent c83474b6bc
commit 1163969d61
4 changed files with 25 additions and 15 deletions

View file

@ -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,

View file

@ -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:

View file

@ -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);
}

View file

@ -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);