add limits for resizing layouts
This commit is contained in:
parent
c83474b6bc
commit
1163969d61
4 changed files with 25 additions and 15 deletions
|
@ -204,11 +204,6 @@ private:
|
||||||
/// Implements a command to commit a map or border resize action.
|
/// Implements a command to commit a map or border resize action.
|
||||||
class ResizeLayout : public QUndoCommand {
|
class ResizeLayout : public QUndoCommand {
|
||||||
public:
|
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,
|
ResizeLayout(Layout *layout, QSize oldLayoutDimensions, QMargins newLayoutMargins,
|
||||||
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
|
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
|
||||||
QSize oldBorderDimensions, QSize newBorderDimensions,
|
QSize oldBorderDimensions, QSize newBorderDimensions,
|
||||||
|
|
|
@ -55,6 +55,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void updatePosFromRect(QRect newPos);
|
void updatePosFromRect(QRect newPos);
|
||||||
|
void setLimit(QRect limit) { this->limit = limit; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
|
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
|
||||||
|
@ -71,6 +72,8 @@ private:
|
||||||
QPointF clickedPos = QPointF();
|
QPointF clickedPos = QPointF();
|
||||||
QRect clickedRect;
|
QRect clickedRect;
|
||||||
|
|
||||||
|
QRect limit = QRect();
|
||||||
|
|
||||||
int lineWidth = 8;
|
int lineWidth = 8;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
|
@ -151,13 +151,24 @@ void ResizableRect::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// lower bounds limits
|
// lower bounds limits, smallest possible size is 16x16 square
|
||||||
if (resizedRect.width() < 16)
|
if (resizedRect.width() < 16) {
|
||||||
|
if (dx < 0) { // right sided adjustment made
|
||||||
resizedRect.setWidth(16);
|
resizedRect.setWidth(16);
|
||||||
if (resizedRect.height() < 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);
|
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
|
// Upper bounds: clip resized to limit rect
|
||||||
|
this->updatePosFromRect(resizedRect & this->limit);
|
||||||
this->updatePosFromRect(resizedRect);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 x = xMin, xTile = 0; x <= xMax; x += this->gridSize, xTile++) {
|
||||||
for (int y = yMin, yTile = 0; y <= yMax; y += this->gridSize, yTile++) {
|
for (int y = yMin, yTile = 0; y <= yMax; y += this->gridSize, yTile++) {
|
||||||
if (!((xTile ^ yTile) & 1)) { // tile numbers have same parity (evenness)
|
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
|
paintColor = QColor(132, 217, 165); // green light color
|
||||||
else
|
else
|
||||||
paintColor = 0xbcbcbc; // normal light color
|
paintColor = 0xbcbcbc; // normal light color
|
||||||
}
|
}
|
||||||
else {
|
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
|
paintColor = QColor(76, 178, 121); // green dark color
|
||||||
else
|
else
|
||||||
paintColor = 0x969696; // normal dark color
|
paintColor = 0x969696; // normal dark color
|
||||||
|
@ -142,6 +142,7 @@ void ResizeLayoutPopup::setupLayoutView() {
|
||||||
static bool layoutSizeRectVisible = true;
|
static bool layoutSizeRectVisible = true;
|
||||||
|
|
||||||
this->outline = new ResizableRect(this, &layoutSizeRectVisible, this->editor->layout->getWidth(), this->editor->layout->getHeight(), qRgb(255, 0, 255));
|
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){
|
connect(outline, &ResizableRect::rectUpdated, [=](QRect rect){
|
||||||
this->scene->setValidRect(rect);
|
this->scene->setValidRect(rect);
|
||||||
this->ui->spinBox_width->setValue(rect.width() / 16);
|
this->ui->spinBox_width->setValue(rect.width() / 16);
|
||||||
|
|
Loading…
Reference in a new issue