Stable selection frame. Transformation fixes

preferencesAboutTextFull
Ilia Ryabokon 12 years ago
parent a672c9bf1c
commit 625c239e34
  1. 3
      src/board/UBBoardController.cpp
  2. 51
      src/board/UBBoardView.cpp
  3. 3
      src/board/UBBoardView.h
  4. 11
      src/domain/UBGraphicsDelegateFrame.cpp
  5. 16
      src/domain/UBGraphicsItemDelegate.cpp
  6. 3
      src/domain/UBGraphicsItemDelegate.h
  7. 2
      src/domain/UBGraphicsPolygonItem.h
  8. 41
      src/domain/UBGraphicsScene.cpp
  9. 8
      src/domain/UBGraphicsScene.h
  10. 3
      src/domain/UBGraphicsStrokesGroup.cpp
  11. 68
      src/domain/UBSelectionFrame.cpp
  12. 12
      src/domain/UBSelectionFrame.h

@ -179,6 +179,7 @@ void UBBoardController::setupViews()
mControlLayout->setContentsMargins(0, 0, 0, 0);
mControlView = new UBBoardView(this, mControlContainer, true, false);
mControlView->setObjectName(CONTROLVIEW_OBJ_NAME);
mControlView->setInteractive(true);
mControlView->setMouseTracking(true);
@ -1514,6 +1515,8 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy,
updateSystemScaleFactor();
mControlView->setScene(mActiveScene);
disconnect(mControlView, SIGNAL(mouseReleased()), mActiveScene, SLOT(updateSelectionFrame()));
connect(mControlView, SIGNAL(mouseReleased()), mActiveScene, SLOT(updateSelectionFrame()));
mDisplayView->setScene(mActiveScene);
mActiveScene->setBackgroundZoomFactor(mControlView->transform().m11());
pDocumentProxy->setDefaultDocumentSize(mActiveScene->nominalSize());

@ -1023,13 +1023,10 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
// mUBRubberBand->setGeometry (QRect (mMouseDownPos, QSize ()));
// mUBRubberBand->show();
// scene()->updateMultipleSelectionFrame();
scene()->clearSelectionFrame();
}
if(mUBRubberBand) {
mUBRubberBand->hide();
scene()->setMultipleSelectionProcess(false);
}
handleItemMousePress(event);
@ -1077,7 +1074,6 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
mRubberBand->setGeometry (QRect (mMouseDownPos, QSize ()));
mRubberBand->show ();
mIsCreatingSceneGrabZone = true;
scene()->setMultipleSelectionProcess(true);
event->accept ();
break;
@ -1102,12 +1098,12 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
void
UBBoardView::mouseMoveEvent (QMouseEvent *event)
{
static QTime lastCallTime;
if (!lastCallTime.isNull()) {
qDebug() << "time interval is " << lastCallTime.msecsTo(QTime::currentTime());
}
// static QTime lastCallTime;
// if (!lastCallTime.isNull()) {
// qDebug() << "time interval is " << lastCallTime.msecsTo(QTime::currentTime());
// }
QTime mouseMoveTime = QTime::currentTime();
// QTime mouseMoveTime = QTime::currentTime();
if(!mIsDragInProgress
&& ((mapToScene(event->pos()) - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance())) {
qDebug() << "mouse move event canceled";
@ -1165,23 +1161,21 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
// mUBRubberBand->setGeometry (QRect (mMouseDownPos, QSize ()));
mUBRubberBand->setGeometry(bandRect);
mUBRubberBand->show();
scene()->setMultipleSelectionProcess(true);
QTime startTime = QTime::currentTime();
QTime testTime = QTime::currentTime();
// QTime startTime = QTime::currentTime();
// QTime testTime = QTime::currentTime();
QList<QGraphicsItem *> rubberItems = items(bandRect);
qDebug() << "==================";
qDebug() << "| ====rubber items" << testTime.msecsTo(QTime::currentTime());
testTime = QTime::currentTime();
// qDebug() << "==================";
// qDebug() << "| ====rubber items" << testTime.msecsTo(QTime::currentTime());
// testTime = QTime::currentTime();
foreach (QGraphicsItem *item, mJustSelectedItems) {
if (!rubberItems.contains(item)) {
item->setSelected(false);
mJustSelectedItems.remove(item);
}
}
qDebug() << "| ===foreach length" << testTime.msecsTo(QTime::currentTime());
testTime = QTime::currentTime();
// qDebug() << "| ===foreach length" << testTime.msecsTo(QTime::currentTime());
// testTime = QTime::currentTime();
int counter = 0;
if (currentTool == UBStylusTool::Selector) {
@ -1201,15 +1195,15 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
item->setSelected(true);
mJustSelectedItems.insert(item);
}
item->setSelected(true);
}
}
}
qDebug() << "| ==selected items count" << counter << endl
<< "| ==selection time" << testTime.msecsTo(QTime::currentTime()) << endl
<< "| =elapsed time " << startTime.msecsTo(QTime::currentTime()) << endl
<< "==================";
// qDebug() << "| ==selected items count" << counter << endl
// << "| ==selection time" << testTime.msecsTo(QTime::currentTime()) << endl
// << "| =elapsed time " << startTime.msecsTo(QTime::currentTime()) << endl
// << "==================";
// QCoreApplication::removePostedEvents(scene(), 0);
}
handleItemMouseMove(event);
} break;
@ -1233,8 +1227,8 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
event->accept ();
}
qDebug() << "mouse move time" << mouseMoveTime.msecsTo(QTime::currentTime());
lastCallTime = QTime::currentTime();
// qDebug() << "mouse move time" << mouseMoveTime.msecsTo(QTime::currentTime());
// lastCallTime = QTime::currentTime();
}
void
@ -1312,8 +1306,6 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
if (mUBRubberBand && mUBRubberBand->isVisible()) {
mUBRubberBand->hide();
scene()->setMultipleSelectionProcess(false);
scene()->updateMultipleSelectionFrame();
}
if (bReleaseIsNeed)
@ -1349,8 +1341,6 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
{
if (mRubberBand) {
mRubberBand->hide ();
scene()->setMultipleSelectionProcess(false);
scene()->updateMultipleSelectionFrame();
}
@ -1377,7 +1367,6 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
{
if (mRubberBand) {
mRubberBand->hide ();
scene()->setMultipleSelectionProcess(false);
}
if (scene () && mRubberBand && mIsCreatingSceneGrabZone && mRubberBand->geometry ().width () > 16)
@ -1412,6 +1401,8 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
movingItem = NULL;
mLongPressTimer.stop();
emit mouseReleased();
}
void

@ -23,6 +23,8 @@
#ifndef UBBOARDVIEW_H_
#define UBBOARDVIEW_H_
#define CONTROLVIEW_OBJ_NAME "ControlView"
#include <QtGui>
#include "core/UB.h"
#include "domain/UBGraphicsDelegateFrame.h"
@ -64,6 +66,7 @@ class UBBoardView : public QGraphicsView
void hidden();
void shown();
void clickOnBoard();
void mouseReleased();
protected:

@ -238,9 +238,8 @@ void UBGraphicsDelegateFrame::mousePressEvent(QGraphicsSceneMouseEvent *event)
setCursorFromAngle(QString::number((int)mAngle % 360));
event->accept();
if (moving())
prepareFramesToMove(getLinkedFrames());
// if (moving())
// prepareFramesToMove(getLinkedFrames());
}
void UBGraphicsDelegateFrame::setCursorFromAngle(QString angle)
@ -395,8 +394,10 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
return;
QLineF move = QLineF(mStartingPoint, event->scenePos());
qreal moveX = move.length() * cos((move.angle() - mAngle) * PI / 180);
qreal moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180);
// qreal moveX = move.length() * cos((move.angle() - mAngle) * PI / 180);
// qreal moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180);
qreal moveX = (event->pos() - mStartingPoint).x();
qreal moveY = (event->pos() - mStartingPoint).y();
qreal width = delegated()->boundingRect().width() * mTotalScaleX;
qreal height = delegated()->boundingRect().height() * mTotalScaleY;

@ -252,6 +252,12 @@ void UBGraphicsItemDelegate::freeControls()
freeButtons();
}
void UBGraphicsItemDelegate::showControls()
{
mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom());
positionHandles();
}
bool UBGraphicsItemDelegate::controlsExist() const
{
return mFrame
@ -278,14 +284,9 @@ QVariant UBGraphicsItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange ch
switch (static_cast<int>(change)) {
case QGraphicsItem::ItemSelectedHasChanged : {
if (ubScene && !ubScene->multipleSelectionProcess()) {
if (ubScene) {
if (value.toBool()) { //selected(true)
if (!controlsExist()) {
createControls();
mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom());
positionHandles();
ubScene->setSelectedZLevel(delegated());
}
} else {
ubScene->setOwnZlevel(delegated());
freeControls();
@ -297,6 +298,9 @@ QVariant UBGraphicsItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange ch
case QGraphicsItem::ItemPositionHasChanged :
case QGraphicsItem::ItemTransformHasChanged :
case QGraphicsItem::ItemZValueHasChanged :
if (!controlsExist()) {
break;
}
mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom());
positionHandles();
if (ubScene) {

@ -29,7 +29,7 @@
if (Scene) { \
Scene->removeItem(Object); \
} \
delete Object; \
Object->deleteLater(); \
Object = 0; \
} \
@ -231,6 +231,7 @@ class UBGraphicsItemDelegate : public QObject
void init();
virtual void createControls();
virtual void freeControls();
virtual void showControls();
virtual bool controlsExist() const;
virtual bool mousePressEvent(QGraphicsSceneMouseEvent *event);

@ -19,8 +19,6 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBGRAPHICSPOLYGONITEM_H
#define UBGRAPHICSPOLYGONITEM_H

@ -288,7 +288,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoSta
, mZLayerController(new UBZLayerController(this))
, mpLastPolygon(NULL)
, mCurrentPolygon(0)
, mMultipleSelectionProcess(false)
, mSelectionFrame(0)
{
UBCoreGraphicsScene::setObjectName("BoardScene");
@ -1041,20 +1040,50 @@ void UBGraphicsScene::clearSelectionFrame()
}
}
void UBGraphicsScene::updateMultipleSelectionFrame()
UBBoardView *UBGraphicsScene::controlView()
{
UBBoardView *result = 0;
foreach (QGraphicsView *view, views()) {
if (view->objectName() == CONTROLVIEW_OBJ_NAME) {
result = static_cast<UBBoardView*>(view);
}
}
return result;
}
void UBGraphicsScene::updateSelectionFrame()
{
qDebug() << "selected item count" << selectedItems().count();
QList<QGraphicsItem*> selItems = selectedItems();
// if (!mMultipleSelectionProcess) {
// return;
// }
if (!mSelectionFrame) {
mSelectionFrame = new UBSelectionFrame();
addItem(mSelectionFrame);
}
QList<QGraphicsItem*> selItems = selectedItems();
switch (selItems.count()) {
case 0 : {
mSelectionFrame->setVisible(false);
mSelectionFrame->setEnclosedItems(selItems);
if (!mSelectionFrame->isEmpty()) {
mSelectionFrame->setVisible(true);
} else {
} break;
case 1: {
mSelectionFrame->setVisible(false);
mSelectionFrame->setEnclosedItems(QList<QGraphicsItem*>());
UBGraphicsItemDelegate *itemDelegate = UBGraphicsItem::Delegate(selItems.first());
itemDelegate->createControls();
selItems.first()->setVisible(true);
itemDelegate->showControls();
} break;
default: {
mSelectionFrame->setVisible(true);
mSelectionFrame->setEnclosedItems(selItems);
} break;
}
}

@ -55,6 +55,7 @@ class UBMagnifier;
class UBGraphicsCache;
class UBGraphicsGroupContainerItem;
class UBSelectionFrame;
class UBBoardView;
const double PI = 4.0 * atan(1.0);
@ -309,12 +310,12 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
static QUuid getPersonalUuid(QGraphicsItem *item);
UBGraphicsPolygonItem* polygonToPolygonItem(const QPolygonF pPolygon);
void setMultipleSelectionProcess(bool pEnabled) {mMultipleSelectionProcess = pEnabled;}
bool multipleSelectionProcess() const {return mMultipleSelectionProcess;}
void clearSelectionFrame();
void updateMultipleSelectionFrame();
UBBoardView *controlView();
public slots:
void updateSelectionFrame();
void initStroke();
void hideEraser();
@ -430,7 +431,6 @@ public slots:
bool mDrawWithCompass;
UBGraphicsPolygonItem *mCurrentPolygon;
bool mMultipleSelectionProcess;
UBSelectionFrame *mSelectionFrame;
};

@ -187,8 +187,9 @@ void UBGraphicsStrokesGroup::paint(QPainter *painter, const QStyleOptionGraphics
}
styleOption.state &= ~QStyle::State_Selected;
QGraphicsItemGroup::paint(painter, &styleOption, widget);
if (selectedState) {
if (selectedState && !Delegate()->controlsExist()) {
painter->save();
painter->setPen(Qt::NoPen);
painter->setBrush(QColor(0x88, 0x88, 0x88, 0x77));
painter->drawRect(boundingRect());
painter->restore();

@ -15,7 +15,7 @@ UBSelectionFrame::UBSelectionFrame()
setLocalBrush(QBrush(UBSettings::paletteColor));
setPen(Qt::NoPen);
setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
setFlags(QGraphicsItem::ItemIsMovable);
setFlags(QGraphicsItem::ItemSendsGeometryChanges /*| QGraphicsItem::ItemIsSelectable*/ | ItemIsMovable);
connect(UBApplication::boardController, SIGNAL(zoomChanged(qreal)), this, SLOT(onZoomChanged(qreal)));
}
@ -61,16 +61,17 @@ QPainterPath UBSelectionFrame::shape() const
void UBSelectionFrame::setEnclosedItems(const QList<QGraphicsItem*> pGraphicsItems)
{
QRectF resultRect;
QRegion resultRegion;
mEnclosedtems.clear();
foreach (QGraphicsItem *nextItem, pGraphicsItems) {
UBGraphicsItemDelegate *nextDelegate = UBGraphicsItem::Delegate(nextItem);
if (nextDelegate) {
mEnclosedtems.append(nextDelegate);
resultRect |= nextItem->boundingRect();
resultRegion |= nextItem->boundingRegion(nextItem->sceneTransform());
}
}
QRectF resultRect = resultRegion.boundingRect();
setRect(resultRect);
if (resultRect.isEmpty()) {
@ -80,11 +81,12 @@ void UBSelectionFrame::setEnclosedItems(const QList<QGraphicsItem*> pGraphicsIte
void UBSelectionFrame::updateRect()
{
QRectF result;
QRegion resultRegion;
foreach (UBGraphicsItemDelegate *curDelegateItem, mEnclosedtems) {
result |= curDelegateItem->delegated()->boundingRect();
resultRegion |= curDelegateItem->delegated()->boundingRegion(curDelegateItem->delegated()->sceneTransform());
}
QRectF result = resultRegion.boundingRect();
setRect(result);
if (result.isEmpty()) {
@ -97,9 +99,65 @@ void UBSelectionFrame::updateScale()
setScale(-UBApplication::boardController->currentZoom());
}
void UBSelectionFrame::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
mPressedPos = mLastMovedPos = event->pos();
mLastTranslateOffset = QPointF();
// foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) {
// qDebug() << "TransformBefore" << curDelegate->delegated()->transform();
// }
// QGraphicsRectItem::mousePressEvent(event);
}
void UBSelectionFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
QPointF dp = event->pos() - mPressedPos;
foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) {
QGraphicsItem *item = curDelegate->delegated();
QTransform ownTransform = item->transform();
QTransform dTransform(
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);
}
updateRect();
mLastMovedPos = event->pos();
mLastTranslateOffset = dp;
}
void UBSelectionFrame::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/)
{
mPressedPos = mLastMovedPos = QPointF();
// foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) {
// qDebug() << "TransformBefore" << curDelegate->delegated()->transform();
// }
// QGraphicsRectItem::mouseReleaseEvent(event);
}
void UBSelectionFrame::onZoomChanged(qreal pZoom)
{
mAntiscaleRatio = pZoom;
updateScale();
}
void UBSelectionFrame::translateItem(QGraphicsItem */*item*/, const QPointF &/*translatePoint*/)
{
}

@ -25,15 +25,27 @@ public:
void updateScale();
bool isEmpty() const {return this->rect().isEmpty();}
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
private slots:
void setAntiScaleRatio(qreal pAntiscaleRatio) {mAntiscaleRatio = pAntiscaleRatio;}
void onZoomChanged(qreal pZoom);
private:
void translateItem(QGraphicsItem *item, const QPointF &translatePoint);
private:
int mThickness;
qreal mAntiscaleRatio;
QList<UBGraphicsItemDelegate*> mEnclosedtems;
QBrush mLocalBrush;
QPointF mPressedPos;
QPointF mLastMovedPos;
QPointF mLastTranslateOffset;
};
#endif // UBSELECTIONFRAME_H

Loading…
Cancel
Save