|
|
@ -2,46 +2,29 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include <QtGui> |
|
|
|
#include <QtGui> |
|
|
|
|
|
|
|
|
|
|
|
#include "core/UB.h" |
|
|
|
|
|
|
|
#include "domain/UBItem.h" |
|
|
|
#include "domain/UBItem.h" |
|
|
|
#include "board/UBBoardController.h" |
|
|
|
#include "board/UBBoardController.h" |
|
|
|
#include "core/UBSettings.h" |
|
|
|
#include "core/UBSettings.h" |
|
|
|
#include "core/UBApplication.h" |
|
|
|
#include "core/UBApplication.h" |
|
|
|
|
|
|
|
#include "gui/UBResources.h" |
|
|
|
|
|
|
|
#include "core/UBApplication.h" |
|
|
|
|
|
|
|
#include "domain/UBGraphicsScene.h" |
|
|
|
|
|
|
|
|
|
|
|
UBSelectionFrame::UBSelectionFrame() |
|
|
|
UBSelectionFrame::UBSelectionFrame() |
|
|
|
: mThickness(UBSettings::settings()->objectFrameWidth) |
|
|
|
: mThickness(UBSettings::settings()->objectFrameWidth) |
|
|
|
, mAntiscaleRatio(1.0) |
|
|
|
, mAntiscaleRatio(1.0) |
|
|
|
|
|
|
|
, mRotationAngle(0) |
|
|
|
, mDeleteButton(0) |
|
|
|
, mDeleteButton(0) |
|
|
|
, mDuplicateButton(0) |
|
|
|
, mDuplicateButton(0) |
|
|
|
, mZOrderUpButton(0) |
|
|
|
, mZOrderUpButton(0) |
|
|
|
, mZOrderDownButton(0) |
|
|
|
, mZOrderDownButton(0) |
|
|
|
|
|
|
|
, mRotateButton(0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
setLocalBrush(QBrush(UBSettings::paletteColor)); |
|
|
|
setLocalBrush(QBrush(UBSettings::paletteColor)); |
|
|
|
setPen(Qt::NoPen); |
|
|
|
setPen(Qt::NoPen); |
|
|
|
setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); |
|
|
|
setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); |
|
|
|
setFlags(QGraphicsItem::ItemSendsGeometryChanges | QGraphicsItem::ItemIsSelectable | ItemIsMovable); |
|
|
|
setFlags(QGraphicsItem::ItemSendsGeometryChanges | QGraphicsItem::ItemIsSelectable | ItemIsMovable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mDeleteButton = new DelegateButton(":/images/close.svg", this, 0, Qt::TopLeftSection); |
|
|
|
|
|
|
|
mButtons << mDeleteButton; |
|
|
|
|
|
|
|
connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(remove())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mDuplicateButton = new DelegateButton(":/images/duplicate.svg", this, 0, Qt::TopLeftSection); |
|
|
|
|
|
|
|
// connect(mDuplicateButton, SIGNAL(clicked(bool)), this, SLOT(duplicate()));
|
|
|
|
|
|
|
|
mButtons << mDuplicateButton; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mZOrderUpButton = new DelegateButton(":/images/z_layer_up.svg", this, 0, Qt::BottomLeftSection); |
|
|
|
|
|
|
|
mZOrderUpButton->setShowProgressIndicator(true); |
|
|
|
|
|
|
|
// connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevelUp()));
|
|
|
|
|
|
|
|
// connect(mZOrderUpButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelTop()));
|
|
|
|
|
|
|
|
mButtons << mZOrderUpButton; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mZOrderDownButton = new DelegateButton(":/images/z_layer_down.svg", this, 0, Qt::BottomLeftSection); |
|
|
|
|
|
|
|
mZOrderDownButton->setShowProgressIndicator(true); |
|
|
|
|
|
|
|
// connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(increaseZLevelDown()));
|
|
|
|
|
|
|
|
// connect(mZOrderDownButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelBottom()));
|
|
|
|
|
|
|
|
mButtons << mZOrderDownButton; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect(UBApplication::boardController, SIGNAL(zoomChanged(qreal)), this, SLOT(onZoomChanged(qreal))); |
|
|
|
connect(UBApplication::boardController, SIGNAL(zoomChanged(qreal)), this, SLOT(onZoomChanged(qreal))); |
|
|
|
|
|
|
|
|
|
|
|
onZoomChanged(UBApplication::boardController->currentZoom()); |
|
|
|
onZoomChanged(UBApplication::boardController->currentZoom()); |
|
|
@ -90,25 +73,26 @@ void UBSelectionFrame::setEnclosedItems(const QList<QGraphicsItem*> pGraphicsIte |
|
|
|
{ |
|
|
|
{ |
|
|
|
mButtons.clear(); |
|
|
|
mButtons.clear(); |
|
|
|
mButtons.append(mDeleteButton); |
|
|
|
mButtons.append(mDeleteButton); |
|
|
|
mButtons.append(mZOrderUpButton); |
|
|
|
mRotationAngle = 0; |
|
|
|
mButtons.append(mZOrderDownButton); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QRegion resultRegion; |
|
|
|
QRegion resultRegion; |
|
|
|
|
|
|
|
UBGraphicsFlags resultFlags; |
|
|
|
mEnclosedtems.clear(); |
|
|
|
mEnclosedtems.clear(); |
|
|
|
foreach (QGraphicsItem *nextItem, pGraphicsItems) { |
|
|
|
foreach (QGraphicsItem *nextItem, pGraphicsItems) { |
|
|
|
UBGraphicsItemDelegate *nextDelegate = UBGraphicsItem::Delegate(nextItem); |
|
|
|
UBGraphicsItemDelegate *nextDelegate = UBGraphicsItem::Delegate(nextItem); |
|
|
|
if (nextDelegate) { |
|
|
|
if (nextDelegate) { |
|
|
|
mEnclosedtems.append(nextDelegate); |
|
|
|
mEnclosedtems.append(nextDelegate); |
|
|
|
resultRegion |= nextItem->boundingRegion(nextItem->sceneTransform()); |
|
|
|
resultRegion |= nextItem->boundingRegion(nextItem->sceneTransform()); |
|
|
|
|
|
|
|
resultFlags |= nextDelegate->ubflags(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QRectF resultRect = resultRegion.boundingRect(); |
|
|
|
QRectF resultRect = resultRegion.boundingRect(); |
|
|
|
setRect(resultRect); |
|
|
|
setRect(resultRect); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mButtons = buttonsForFlags(resultFlags); |
|
|
|
placeButtons(); |
|
|
|
placeButtons(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (resultRect.isEmpty()) { |
|
|
|
if (resultRect.isEmpty()) { |
|
|
|
hide(); |
|
|
|
hide(); |
|
|
|
} |
|
|
|
} |
|
|
@ -141,6 +125,12 @@ void UBSelectionFrame::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
|
|
mPressedPos = mLastMovedPos = event->pos(); |
|
|
|
mPressedPos = mLastMovedPos = event->pos(); |
|
|
|
mLastTranslateOffset = QPointF(); |
|
|
|
mLastTranslateOffset = QPointF(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (scene()->itemAt(event->scenePos()) == mRotateButton) { |
|
|
|
|
|
|
|
mOperationMode = om_rotating; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
mOperationMode = om_moving; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) {
|
|
|
|
// foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) {
|
|
|
|
// qDebug() << "TransformBefore" << curDelegate->delegated()->transform();
|
|
|
|
// qDebug() << "TransformBefore" << curDelegate->delegated()->transform();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
@ -154,23 +144,50 @@ void UBSelectionFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
|
|
|
|
|
|
|
|
|
|
foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) { |
|
|
|
foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) { |
|
|
|
|
|
|
|
|
|
|
|
QGraphicsItem *item = curDelegate->delegated(); |
|
|
|
switch (static_cast<int>(mOperationMode)) { |
|
|
|
QTransform ownTransform = item->transform(); |
|
|
|
case om_moving : { |
|
|
|
QTransform dTransform( |
|
|
|
QGraphicsItem *item = curDelegate->delegated(); |
|
|
|
ownTransform.m11() |
|
|
|
QTransform ownTransform = item->transform(); |
|
|
|
, ownTransform.m12() |
|
|
|
QTransform dTransform( |
|
|
|
, ownTransform.m13() |
|
|
|
ownTransform.m11() |
|
|
|
|
|
|
|
, ownTransform.m12() |
|
|
|
|
|
|
|
, ownTransform.m13() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
, ownTransform.m21() |
|
|
|
|
|
|
|
, ownTransform.m22() |
|
|
|
|
|
|
|
, ownTransform.m23() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
, ownTransform.m31() + (dp - mLastTranslateOffset).x() |
|
|
|
|
|
|
|
, ownTransform.m32() + (dp - mLastTranslateOffset).y() |
|
|
|
|
|
|
|
, ownTransform.m33() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
item->setTransform(dTransform); |
|
|
|
|
|
|
|
} break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case om_rotating : { |
|
|
|
|
|
|
|
QLineF startLine(sceneBoundingRect().center(), event->lastScenePos()); |
|
|
|
|
|
|
|
QLineF currentLine(sceneBoundingRect().center(), event->scenePos()); |
|
|
|
|
|
|
|
qreal dAngle = startLine.angleTo(currentLine); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QGraphicsItem *item = curDelegate->delegated(); |
|
|
|
|
|
|
|
QTransform ownTransform = item->transform(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qreal cntrX = item->boundingRect().center().x(); |
|
|
|
|
|
|
|
qreal cntrY = item->boundingRect().center().y(); |
|
|
|
|
|
|
|
|
|
|
|
, ownTransform.m21() |
|
|
|
ownTransform.translate(cntrX, cntrY); |
|
|
|
, ownTransform.m22() |
|
|
|
mRotationAngle -= dAngle; |
|
|
|
, ownTransform.m23() |
|
|
|
ownTransform.rotate(mRotationAngle); |
|
|
|
|
|
|
|
ownTransform.translate(-cntrX, -cntrY); |
|
|
|
|
|
|
|
|
|
|
|
, ownTransform.m31() + (dp - mLastTranslateOffset).x() |
|
|
|
item->setTransform(ownTransform); |
|
|
|
, ownTransform.m32() + (dp - mLastTranslateOffset).y() |
|
|
|
|
|
|
|
, ownTransform.m33() |
|
|
|
qDebug() << "curAngle" << dAngle; |
|
|
|
); |
|
|
|
} break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
item->setTransform(dTransform); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
updateRect(); |
|
|
|
updateRect(); |
|
|
@ -181,6 +198,17 @@ void UBSelectionFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
|
|
void UBSelectionFrame::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/) |
|
|
|
void UBSelectionFrame::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/) |
|
|
|
{ |
|
|
|
{ |
|
|
|
mPressedPos = mLastMovedPos = mLastTranslateOffset = QPointF(); |
|
|
|
mPressedPos = mLastMovedPos = mLastTranslateOffset = QPointF(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mOperationMode == om_moving || mOperationMode == om_rotating) { |
|
|
|
|
|
|
|
UBApplication::undoStack->beginMacro("TransformationMacro"); |
|
|
|
|
|
|
|
foreach (UBGraphicsItemDelegate *d, mEnclosedtems) { |
|
|
|
|
|
|
|
d->commitUndoStep(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
UBApplication::undoStack->endMacro(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
mOperationMode = om_idle; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) {
|
|
|
|
// foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) {
|
|
|
|
// qDebug() << "TransformBefore" << curDelegate->delegated()->transform();
|
|
|
|
// qDebug() << "TransformBefore" << curDelegate->delegated()->transform();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
@ -202,9 +230,22 @@ void UBSelectionFrame::onZoomChanged(qreal pZoom) |
|
|
|
|
|
|
|
|
|
|
|
void UBSelectionFrame::remove() |
|
|
|
void UBSelectionFrame::remove() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
UBApplication::undoStack->beginMacro("RemovingSelected"); |
|
|
|
foreach (UBGraphicsItemDelegate *d, mEnclosedtems) { |
|
|
|
foreach (UBGraphicsItemDelegate *d, mEnclosedtems) { |
|
|
|
d->remove(true); |
|
|
|
d->remove(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
UBApplication::undoStack->endMacro(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateRect(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBSelectionFrame::duplicate() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
UBApplication::undoStack->beginMacro("RemovingSelected"); |
|
|
|
|
|
|
|
foreach (UBGraphicsItemDelegate *d, mEnclosedtems) { |
|
|
|
|
|
|
|
d->duplicate(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
UBApplication::undoStack->endMacro(); |
|
|
|
|
|
|
|
|
|
|
|
updateRect(); |
|
|
|
updateRect(); |
|
|
|
} |
|
|
|
} |
|
|
@ -215,6 +256,10 @@ void UBSelectionFrame::translateItem(QGraphicsItem */*item*/, const QPointF &/*t |
|
|
|
|
|
|
|
|
|
|
|
void UBSelectionFrame::placeButtons() |
|
|
|
void UBSelectionFrame::placeButtons() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (!mButtons.count()) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QTransform tr; |
|
|
|
QTransform tr; |
|
|
|
tr.scale(mAntiscaleRatio, mAntiscaleRatio); |
|
|
|
tr.scale(mAntiscaleRatio, mAntiscaleRatio); |
|
|
|
mDeleteButton->setParentItem(this); |
|
|
|
mDeleteButton->setParentItem(this); |
|
|
@ -243,6 +288,10 @@ void UBSelectionFrame::placeButtons() |
|
|
|
button->setParentItem(this); |
|
|
|
button->setParentItem(this); |
|
|
|
button->setPos(bottomX + (++j * 1.6 * adjThickness()), bottomY); |
|
|
|
button->setPos(bottomX + (++j * 1.6 * adjThickness()), bottomY); |
|
|
|
button->setTransform(tr); |
|
|
|
button->setTransform(tr); |
|
|
|
|
|
|
|
} else if (button->getSection() == Qt::NoSection) { |
|
|
|
|
|
|
|
button->setParentItem(this); |
|
|
|
|
|
|
|
placeExceptionButton(button, tr); |
|
|
|
|
|
|
|
k++; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
++k; |
|
|
|
++k; |
|
|
|
} |
|
|
|
} |
|
|
@ -250,6 +299,18 @@ void UBSelectionFrame::placeButtons() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBSelectionFrame::placeExceptionButton(DelegateButton *pButton, QTransform pTransform) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QRectF frRect = boundingRect(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (pButton == mRotateButton) { |
|
|
|
|
|
|
|
qreal topX = frRect.right() - (mRotateButton->renderer()->viewBox().width()) * mAntiscaleRatio - 5; |
|
|
|
|
|
|
|
qreal topY = frRect.top() + 5; |
|
|
|
|
|
|
|
mRotateButton->setPos(topX, topY); |
|
|
|
|
|
|
|
mRotateButton->setTransform(pTransform); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBSelectionFrame::clearButtons() |
|
|
|
void UBSelectionFrame::clearButtons() |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach (DelegateButton *b, mButtons) |
|
|
|
foreach (DelegateButton *b, mButtons) |
|
|
@ -261,4 +322,61 @@ void UBSelectionFrame::clearButtons() |
|
|
|
mButtons.clear(); |
|
|
|
mButtons.clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline UBGraphicsScene *UBSelectionFrame::ubscene() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return qobject_cast<UBGraphicsScene*>(scene()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QList<DelegateButton*> UBSelectionFrame::buttonsForFlags(UBGraphicsFlags fls) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qDebug() << "buttons for flags" << QString::number((int)fls, 2); |
|
|
|
|
|
|
|
QList<DelegateButton*> result; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!mDeleteButton) { |
|
|
|
|
|
|
|
mDeleteButton = new DelegateButton(":/images/close.svg", this, 0, Qt::TopLeftSection); |
|
|
|
|
|
|
|
mButtons << mDeleteButton; |
|
|
|
|
|
|
|
connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(remove())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
result << mDeleteButton; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fls | GF_DUPLICATION_ENABLED) { |
|
|
|
|
|
|
|
if (!mDuplicateButton) { |
|
|
|
|
|
|
|
mDuplicateButton = new DelegateButton(":/images/duplicate.svg", this, 0, Qt::TopLeftSection); |
|
|
|
|
|
|
|
connect(mDuplicateButton, SIGNAL(clicked(bool)), this, SLOT(duplicate())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
result << mDuplicateButton; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fls | GF_ZORDER_MANIPULATIONS_ALLOWED) { |
|
|
|
|
|
|
|
if (!mZOrderUpButton) { |
|
|
|
|
|
|
|
mZOrderUpButton = new DelegateButton(":/images/z_layer_up.svg", this, 0, Qt::BottomLeftSection); |
|
|
|
|
|
|
|
mZOrderUpButton->setShowProgressIndicator(true); |
|
|
|
|
|
|
|
// connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevelUp()));
|
|
|
|
|
|
|
|
// connect(mZOrderUpButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelTop()));
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!mZOrderDownButton) { |
|
|
|
|
|
|
|
mZOrderDownButton = new DelegateButton(":/images/z_layer_down.svg", this, 0, Qt::BottomLeftSection); |
|
|
|
|
|
|
|
mZOrderDownButton->setShowProgressIndicator(true); |
|
|
|
|
|
|
|
// connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(increaseZLevelDown()));
|
|
|
|
|
|
|
|
// connect(mZOrderDownButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelBottom()));
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result << mZOrderUpButton; |
|
|
|
|
|
|
|
result << mZOrderDownButton; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fls | GF_REVOLVABLE) { |
|
|
|
|
|
|
|
if (!mRotateButton) { |
|
|
|
|
|
|
|
mRotateButton = new DelegateButton(":/images/rotate.svg", this, 0, Qt::NoSection); |
|
|
|
|
|
|
|
mRotateButton->setCursor(UBResources::resources()->rotateCursor); |
|
|
|
|
|
|
|
mRotateButton->setShowProgressIndicator(false); |
|
|
|
|
|
|
|
mRotateButton->setTransparentToMouseEvent(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
result << mRotateButton; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|