Rotation transformations

preferencesAboutTextFull
Ilia Ryabokon 11 years ago
parent 004a13660b
commit f47733ee1a
  1. 4
      src/board/UBFeaturesController.cpp
  2. 1
      src/domain/UBGraphicsItemDelegate.cpp
  3. 10
      src/domain/UBGraphicsScene.cpp
  4. 54
      src/domain/UBSelectionFrame.cpp
  5. 3
      src/domain/UBSelectionFrame.h

@ -59,8 +59,8 @@ const QString UBFeaturesController::webSearchPath = rootPath + "/Web search";
void UBFeaturesComputingThread::scanFS(const QUrl & currentPath, const QString & currVirtualPath, const QSet<QUrl> &pFavoriteSet)
{
// Q_ASSERT(QFileInfo(currentPath.toLocalFile()).exists());
if(QFileInfo(currentPath.toLocalFile()).exists())
return;
// if(QFileInfo(currentPath.toLocalFile()).exists())
// return;
QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(currentPath.toLocalFile());

@ -316,6 +316,7 @@ void UBGraphicsItemDelegate::postpaint(QPainter *painter, const QStyleOptionGrap
painter->setPen(Qt::NoPen);
painter->setBrush(QColor(0x88, 0x88, 0x88, 0x77));
painter->drawRect(option->rect);
painter->restore();
}
}

@ -249,9 +249,15 @@ qreal UBZLayerController::changeZLevelTo(QGraphicsItem *item, moveDestination de
item->scene()->clearSelection();
item->setSelected(true);
foreach (QGraphicsItem *iitem, sortedItems.values()) {
if (iitem)
iitem != item
? qDebug() << "current value" << iitem->zValue()
: qDebug() << "marked value" << QString::number(iitem->zValue(), 'f');
}
//Return new z value assigned to item
return item->data(UBGraphicsItemData::ItemOwnZValue).toReal();
}
itemLayerType::Enum UBZLayerController::typeForData(QGraphicsItem *item) const
@ -317,7 +323,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoSta
}
// Just for debug. Do not delete please
// connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing()));
connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing()));
connect(this, SIGNAL(selectionChanged()), this, SLOT(updateGroupButtonState()));
connect(UBApplication::undoStack.data(), SIGNAL(indexChanged(int)), this, SLOT(updateSelectionFrameWrapper(int)));
}

@ -9,6 +9,7 @@
#include "gui/UBResources.h"
#include "core/UBApplication.h"
#include "domain/UBGraphicsScene.h"
#include "board/UBBoardView.h"
UBSelectionFrame::UBSelectionFrame()
: mThickness(UBSettings::settings()->objectFrameWidth)
@ -125,6 +126,7 @@ void UBSelectionFrame::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
mPressedPos = mLastMovedPos = event->pos();
mLastTranslateOffset = QPointF();
mRotationAngle = 0;
if (scene()->itemAt(event->scenePos()) == mRotateButton) {
mOperationMode = om_rotating;
@ -142,6 +144,7 @@ void UBSelectionFrame::mousePressEvent(QGraphicsSceneMouseEvent *event)
void UBSelectionFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
QPointF dp = event->pos() - mPressedPos;
QPointF rotCenter = mapToScene(rect().center());
foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) {
@ -174,17 +177,24 @@ void UBSelectionFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
QGraphicsItem *item = curDelegate->delegated();
QTransform ownTransform = item->transform();
qreal cntrX = item->boundingRect().center().x();
qreal cntrY = item->boundingRect().center().y();
QPointF nextRotCenter = item->mapFromScene(rotCenter);
qreal cntrX = nextRotCenter.x();
qreal cntrY = nextRotCenter.y();
ownTransform.translate(cntrX, cntrY);
mRotationAngle -= dAngle;
ownTransform.rotate(mRotationAngle);
ownTransform.rotate(-dAngle);
ownTransform.translate(-cntrX, -cntrY);
item->setTransform(ownTransform);
item->update();
item->setTransform(ownTransform, false);
int resultAngle = (int)mRotationAngle % 360;
// setCursorFromAngle(QString::number(resultAngle));
qDebug() << "curAngle" << dAngle;
qDebug() << "curAngle" << mRotationAngle;
} break;
}
@ -356,6 +366,38 @@ inline UBGraphicsScene *UBSelectionFrame::ubscene()
return qobject_cast<UBGraphicsScene*>(scene());
}
void UBSelectionFrame::setCursorFromAngle(QString angle)
{
QWidget *controlViewport = UBApplication::boardController->controlView()->viewport();
QSize cursorSize(45,30);
QImage mask_img(cursorSize, QImage::Format_Mono);
mask_img.fill(0xff);
QPainter mask_ptr(&mask_img);
mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) );
mask_ptr.drawRoundedRect(0,0, cursorSize.width()-1, cursorSize.height()-1, 6, 6);
QBitmap bmpMask = QBitmap::fromImage(mask_img);
QPixmap pixCursor(cursorSize);
pixCursor.fill(QColor(Qt::white));
QPainter painter(&pixCursor);
painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
painter.setBrush(QBrush(Qt::white));
painter.setPen(QPen(QColor(Qt::black)));
painter.drawRoundedRect(1,1,cursorSize.width()-2,cursorSize.height()-2,6,6);
painter.setFont(QFont("Arial", 10));
painter.drawText(1,1,cursorSize.width(),cursorSize.height(), Qt::AlignCenter, angle.append(QChar(176)));
painter.end();
pixCursor.setMask(bmpMask);
controlViewport->setCursor(pixCursor);
}
QList<QGraphicsItem*> UBSelectionFrame::sortedByZ(const QList<QGraphicsItem *> &pItems)
{
//select only items wiht the same z-level as item's one and push it to sortedItems QMultiMap
@ -394,7 +436,7 @@ QList<DelegateButton*> UBSelectionFrame::buttonsForFlags(UBGraphicsFlags fls) {
if (!mZOrderUpButton) {
mZOrderUpButton = new DelegateButton(":/images/z_layer_up.svg", this, 0, Qt::BottomLeftSection);
mZOrderUpButton->setShowProgressIndicator(true);
connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZlrfevelUp()));
connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZlevelUp()));
connect(mZOrderUpButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelTop()));
}

@ -15,7 +15,7 @@ class UBSelectionFrame : public QObject, public QGraphicsRectItem
public:
enum {om_idle, om_moving, om_rotating} mOperationMode;
enum { Type = UBGraphicsItemType::PixmapItemType };
enum { Type = UBGraphicsItemType::SelectionFrameType };
UBSelectionFrame();
@ -54,6 +54,7 @@ private:
void clearButtons();
inline int adjThickness() const {return mThickness * mAntiscaleRatio;}
inline UBGraphicsScene* ubscene();
void setCursorFromAngle(QString angle);
QList<QGraphicsItem*> sortedByZ(const QList<QGraphicsItem*> &pItems);
QList<DelegateButton*> buttonsForFlags(UBGraphicsFlags fls);

Loading…
Cancel
Save