Permanent Z-layer order changes, click bugs with pictures

preferencesAboutTextFull
Ivan Ilin 13 years ago
parent e82d5d880d
commit da61ebad0c
  1. 4
      src/adaptors/UBSvgSubsetAdaptor.cpp
  2. 1
      src/core/UBSettings.cpp
  3. 1
      src/core/UBSettings.h
  4. 247
      src/domain/UBGraphicsItemDelegate.cpp
  5. 39
      src/domain/UBGraphicsItemDelegate.h
  6. 7
      src/domain/UBGraphicsPixmapItem.cpp
  7. 4
      src/domain/UBGraphicsPixmapItem.h
  8. 209
      src/domain/UBGraphicsScene.cpp
  9. 54
      src/domain/UBGraphicsScene.h
  10. 8
      src/domain/UBGraphicsVideoItem.cpp
  11. 2
      src/domain/UBGraphicsWidgetItem.cpp
  12. 2
      src/domain/UBItem.cpp
  13. 2
      src/domain/UBItem.h

@ -2559,7 +2559,6 @@ UBGraphicsRuler* UBSvgSubsetAdaptor::UBSvgSubsetReader::rulerFromSvg()
graphicsItemFromSvg(ruler); graphicsItemFromSvg(ruler);
UBGraphicsItem::assignZValue(ruler, UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetRuler);
ruler->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); ruler->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool));
QStringRef svgWidth = mXmlReader.attributes().value("width"); QStringRef svgWidth = mXmlReader.attributes().value("width");
@ -2617,7 +2616,6 @@ UBGraphicsCompass* UBSvgSubsetAdaptor::UBSvgSubsetReader::compassFromSvg()
graphicsItemFromSvg(compass); graphicsItemFromSvg(compass);
UBGraphicsItem::assignZValue(compass, UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetCompass);
compass->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); compass->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool));
QStringRef svgX = mXmlReader.attributes().value("x"); QStringRef svgX = mXmlReader.attributes().value("x");
@ -2681,7 +2679,6 @@ UBGraphicsProtractor* UBSvgSubsetAdaptor::UBSvgSubsetReader::protractorFromSvg()
{ {
UBGraphicsProtractor* protractor = new UBGraphicsProtractor(); UBGraphicsProtractor* protractor = new UBGraphicsProtractor();
UBGraphicsItem::assignZValue(protractor, UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetProtractor);
protractor->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); protractor->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool));
graphicsItemFromSvg(protractor); graphicsItemFromSvg(protractor);
@ -2751,7 +2748,6 @@ UBGraphicsTriangle* UBSvgSubsetAdaptor::UBSvgSubsetReader::triangleFromSvg()
{ {
UBGraphicsTriangle* triangle = new UBGraphicsTriangle(); UBGraphicsTriangle* triangle = new UBGraphicsTriangle();
UBGraphicsItem::assignZValue(triangle, UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetTriangle);
triangle->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); triangle->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool));
graphicsItemFromSvg(triangle); graphicsItemFromSvg(triangle);

@ -86,6 +86,7 @@ const int UBSettings::defaultWidgetIconWidth = 110;
const int UBSettings::defaultVideoWidth = 80; const int UBSettings::defaultVideoWidth = 80;
const int UBSettings::thumbnailSpacing = 20; const int UBSettings::thumbnailSpacing = 20;
const int UBSettings::longClickInterval = 2000;
const qreal UBSettings::minScreenRatio = 1.33; // 800/600 or 1024/768 const qreal UBSettings::minScreenRatio = 1.33; // 800/600 or 1024/768

@ -179,6 +179,7 @@ class UBSettings : public QObject
static const int defaultSoundWidth; static const int defaultSoundWidth;
static const int thumbnailSpacing; static const int thumbnailSpacing;
static const int longClickInterval;
static const qreal minScreenRatio; static const qreal minScreenRatio;

@ -47,6 +47,28 @@
class UBGraphicsParaschoolEditorWidgetItem; class UBGraphicsParaschoolEditorWidgetItem;
void DelegateButton::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
// make sure delegate is selected, to avoid control being hidden
mPressedTime = QTime::currentTime();
// mDelegated->setSelected(true);
event->setAccepted(!mIsTransparentToMouseEvent);
}
void DelegateButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
int timeto = qAbs(QTime::currentTime().msecsTo(mPressedTime));
if (timeto < UBSettings::longClickInterval) {
emit clicked();
} else {
emit longClicked();
}
event->setAccepted(!mIsTransparentToMouseEvent);
}
UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObject * parent, bool respectRatio, bool canRotate) UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObject * parent, bool respectRatio, bool canRotate)
: QObject(parent) : QObject(parent)
, mDelegated(pDelegated) , mDelegated(pDelegated)
@ -88,11 +110,13 @@ void UBGraphicsItemDelegate::init()
mButtons << mMenuButton; mButtons << mMenuButton;
mZOrderUpButton = new DelegateButton(":/images/plus.svg", mDelegated, mFrame, Qt::BottomLeftSection); mZOrderUpButton = new DelegateButton(":/images/plus.svg", mDelegated, mFrame, Qt::BottomLeftSection);
connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevel())); connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevelUp()));
connect(mZOrderUpButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelTop()));
mButtons << mZOrderUpButton; mButtons << mZOrderUpButton;
mZOrderDownButton = new DelegateButton(":/images/minus.svg", mDelegated, mFrame, Qt::BottomLeftSection); mZOrderDownButton = new DelegateButton(":/images/minus.svg", mDelegated, mFrame, Qt::BottomLeftSection);
connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(decreaseZLevel())); connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(increaseZLevelDown()));
connect(mZOrderDownButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelBottom()));
mButtons << mZOrderDownButton; mButtons << mZOrderDownButton;
buildButtons(); buildButtons();
@ -149,23 +173,22 @@ QVariant UBGraphicsItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange ch
return value; return value;
} }
UBGraphicsScene *UBGraphicsItemDelegate::castUBGraphicsScene()
{
UBGraphicsScene *castScene = dynamic_cast<UBGraphicsScene*>(delegated()->scene());
return castScene;
}
bool UBGraphicsItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event) bool UBGraphicsItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
if(NULL != mMimeData) mDragStartPosition = event->pos();
{
QDrag* mDrag = new QDrag(event->widget());
mDrag->setMimeData(mMimeData);
mDrag->start();
}
startUndoStep(); startUndoStep();
if (!mDelegated->isSelected()) if (!mDelegated->isSelected())
{ {
mDelegated->setSelected(true); mDelegated->setSelected(true);
qDebug() << mDelegated->zValue();
positionHandles(); positionHandles();
return true; return true;
} }
@ -182,13 +205,27 @@ void UBGraphicsItemDelegate::setMimeData(QMimeData *mimeData)
bool UBGraphicsItemDelegate::mouseMoveEvent(QGraphicsSceneMouseEvent *event) bool UBGraphicsItemDelegate::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
if((NULL != mMimeData) && ((event->pos() - mDragStartPosition).manhattanLength() < QApplication::startDragDistance()))
{
QDrag* mDrag = new QDrag(event->widget());
mDrag->setMimeData(mMimeData);
if (!mDragPixmap.isNull()) {
mDrag->setPixmap(mDragPixmap);
mDrag->setHotSpot(mDragPixmap.rect().center());
}
mDrag->exec();
mDragPixmap = QPixmap();
return true;
}
if(isLocked()) if(isLocked())
{ {
event->accept(); event->accept();
return true; return true;
} }
else else
return false; return true;
} }
bool UBGraphicsItemDelegate::weelEvent(QGraphicsSceneWheelEvent *event) bool UBGraphicsItemDelegate::weelEvent(QGraphicsSceneWheelEvent *event)
@ -215,68 +252,34 @@ bool UBGraphicsItemDelegate::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
return true; return true;
} }
void UBGraphicsItemDelegate::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
void UBGraphicsItemDelegate::positionHandles()
{
if (mDelegated->isSelected())
{
if (mFrame && !mFrame->scene() && mDelegated->scene())
{ {
mDelegated->scene()->addItem(mFrame); Q_UNUSED(event)
// if (!mDelegated->isSelected()) {
// setZOrderButtonsVisible(true);
// }
} }
mFrame->setAntiScale(mAntiScaleRatio); void UBGraphicsItemDelegate::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
mFrame->positionHandles();
mFrame->show();
QTransform tr;
tr.scale(mAntiScaleRatio, mAntiScaleRatio);
mDeleteButton->setTransform(tr);
qreal topX = mFrame->rect().left()- mDeleteButton->renderer()->viewBox().width() * mAntiScaleRatio / 2;
qreal topY = mFrame->rect().top() - mDeleteButton->renderer()->viewBox().height() * mAntiScaleRatio / 2;
qreal bottomX = mFrame->rect().left()- mDeleteButton->renderer()->viewBox().width() * mAntiScaleRatio / 2;
qreal bottomY = mFrame->rect().bottom() - mDeleteButton->renderer()->viewBox().height() * mAntiScaleRatio / 2;
mDeleteButton->setPos(topX, topY);
if (!mDeleteButton->scene())
{ {
mDeleteButton->setParentItem(mFrame);//update parent for the case the item has been previously removed from scene Q_UNUSED(event)
if (mDelegated->scene()) // if (!mDelegated->isSelected()) {
mDelegated->scene()->addItem(mDeleteButton); // setZOrderButtonsVisible(false);
// }
} }
mDeleteButton->show();
void UBGraphicsItemDelegate::positionHandles()
{
if (mDelegated->isSelected()) {
bool shownOnDisplay = mDelegated->data(UBGraphicsItemData::ItemLayerType).toInt() != UBItemLayerType::Control; bool shownOnDisplay = mDelegated->data(UBGraphicsItemData::ItemLayerType).toInt() != UBItemLayerType::Control;
showHide(shownOnDisplay); showHide(shownOnDisplay);
lock(isLocked()); lock(isLocked());
updateFrame();
mFrame->show();
int i = 1, j = 0, k = 0; updateButtons(true);
while ((i + j) < mButtons.size()) {
DelegateButton* button = mButtons[i + j];
button->setTransform(tr);
if (button->getSection() == Qt::TopLeftSection) {
button->setPos(topX + (i++ * 1.6 * mFrameWidth * mAntiScaleRatio), topY);
} else if (button->getSection() == Qt::BottomLeftSection) {
button->setPos(bottomX + (++j * 1.6 * mFrameWidth * mAntiScaleRatio), bottomY);
} else if (button->getSection() == Qt::NoSection) {
++k;
}
if (!button->scene())
{
button->setParentItem(mFrame);//update parent for the case the item has been previously removed from scene
if (mDelegated->scene())
mDelegated->scene()->addItem(button);
}
button->show();
button->setZValue(delegated()->zValue());
}
} else { } else {
foreach(DelegateButton* button, mButtons) foreach(DelegateButton* button, mButtons)
button->hide(); button->hide();
@ -284,7 +287,30 @@ void UBGraphicsItemDelegate::positionHandles()
mFrame->hide(); mFrame->hide();
} }
} }
void UBGraphicsItemDelegate::setZOrderButtonsVisible(bool visible)
{
if (visible) {
updateFrame();
updateButtons();
QPointF newUpPoint = mFrame->mapToItem(mDelegated, mZOrderUpButton->pos());
QPointF newDownPoint = mFrame->mapToItem(mDelegated, mZOrderDownButton->pos());
mZOrderUpButton->setParentItem(mDelegated);
mZOrderDownButton->setParentItem(mDelegated);
mZOrderUpButton->setPos(newUpPoint + QPointF(0,0));
mZOrderDownButton->setPos(newDownPoint + QPointF(0,0));
mZOrderUpButton->show();
mZOrderDownButton->show();
} else {
mZOrderUpButton->hide();
mZOrderDownButton->hide();
}
}
void UBGraphicsItemDelegate::remove(bool canUndo) void UBGraphicsItemDelegate::remove(bool canUndo)
{ {
@ -320,18 +346,34 @@ void UBGraphicsItemDelegate::duplicate()
UBApplication::boardController->copy(); UBApplication::boardController->copy();
UBApplication::boardController->paste(); UBApplication::boardController->paste();
} }
void UBGraphicsItemDelegate::increaseZLevel(int delta)
{
qDebug() << delegated()->scene()->items().count();
// UBGraphicsItem::assignZValue(delegated(), )
// int valueCandidate = delegated()->data(UBGraphicsItemData::ItemOwnZValue).toInt();
// if (delta < 0) {
// } else if (delta > 0) { void UBGraphicsItemDelegate::increaseZLevelUp()
{
// } UBGraphicsScene *curScene = castUBGraphicsScene();
if (curScene) {
curScene->changeZLevelTo(delegated(), UBZLayerController::up);
}
}
void UBGraphicsItemDelegate::increaseZlevelTop()
{
UBGraphicsScene *curScene = castUBGraphicsScene();
if (curScene) {
curScene->changeZLevelTo(delegated(), UBZLayerController::top);
}
}
void UBGraphicsItemDelegate::increaseZLevelDown()
{
UBGraphicsScene *curScene = castUBGraphicsScene();
if (curScene) {
curScene->changeZLevelTo(delegated(), UBZLayerController::down);
}
}
void UBGraphicsItemDelegate::increaseZlevelBottom()
{
UBGraphicsScene *curScene = castUBGraphicsScene();
if (curScene) {
curScene->changeZLevelTo(delegated(), UBZLayerController::bottom);
}
} }
void UBGraphicsItemDelegate::lock(bool locked) void UBGraphicsItemDelegate::lock(bool locked)
@ -484,3 +526,64 @@ bool UBGraphicsItemDelegate::isFlippable()
{ {
return mFlippable; return mFlippable;
} }
void UBGraphicsItemDelegate::updateFrame()
{
if (mFrame && !mFrame->scene() && mDelegated->scene())
{
mDelegated->scene()->addItem(mFrame);
}
mFrame->setAntiScale(mAntiScaleRatio);
mFrame->positionHandles();
}
void UBGraphicsItemDelegate::updateButtons(bool showUpdated)
{
QTransform tr;
tr.scale(mAntiScaleRatio, mAntiScaleRatio);
mDeleteButton->setParentItem(mFrame);
mDeleteButton->setTransform(tr);
qreal topX = mFrame->rect().left() - mDeleteButton->renderer()->viewBox().width() * mAntiScaleRatio / 2;
qreal topY = mFrame->rect().top() - mDeleteButton->renderer()->viewBox().height() * mAntiScaleRatio / 2;
qreal bottomX = mFrame->rect().left() - mDeleteButton->renderer()->viewBox().width() * mAntiScaleRatio / 2;
qreal bottomY = mFrame->rect().bottom() - mDeleteButton->renderer()->viewBox().height() * mAntiScaleRatio / 2;
mDeleteButton->setPos(topX, topY);
if (!mDeleteButton->scene())
{
if (mDelegated->scene())
mDelegated->scene()->addItem(mDeleteButton);
}
if (showUpdated)
mDeleteButton->show();
int i = 1, j = 0, k = 0;
while ((i + j + k) < mButtons.size()) {
DelegateButton* button = mButtons[i + j];
button->setParentItem(mFrame);
button->setTransform(tr);
if (button->getSection() == Qt::TopLeftSection) {
button->setPos(topX + (i++ * 1.6 * mFrameWidth * mAntiScaleRatio), topY);
} else if (button->getSection() == Qt::BottomLeftSection) {
button->setPos(bottomX + (++j * 1.6 * mFrameWidth * mAntiScaleRatio), bottomY);
} else if (button->getSection() == Qt::NoSection) {
++k;
}
if (!button->scene())
{
if (mDelegated->scene())
mDelegated->scene()->addItem(button);
}
if (showUpdated) {
button->show();
button->setZValue(delegated()->zValue());
}
}
}

@ -21,9 +21,11 @@
#include <QMimeData> #include <QMimeData>
#include "core/UB.h" #include "core/UB.h"
#include "core/UBSettings.h"
class QGraphicsSceneMouseEvent; class QGraphicsSceneMouseEvent;
class QGraphicsItem; class QGraphicsItem;
class UBGraphicsScene;
class UBGraphicsProxyWidget; class UBGraphicsProxyWidget;
class UBGraphicsDelegateFrame; class UBGraphicsDelegateFrame;
class UBGraphicsWidgetItem; class UBGraphicsWidgetItem;
@ -63,20 +65,8 @@ class DelegateButton: public QGraphicsSvgItem
protected: protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
{ virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
// make sure delegate is selected, to avoid control being hidden
mDelegated->setSelected(true);
event->setAccepted(!mIsTransparentToMouseEvent);
}
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
emit clicked();
event->setAccepted(!mIsTransparentToMouseEvent);
}
void modified(); void modified();
@ -84,12 +74,13 @@ class DelegateButton: public QGraphicsSvgItem
QGraphicsItem* mDelegated; QGraphicsItem* mDelegated;
QTime mPressedTime;
bool mIsTransparentToMouseEvent; bool mIsTransparentToMouseEvent;
Qt::WindowFrameSection mButtonAlignmentSection; Qt::WindowFrameSection mButtonAlignmentSection;
signals: signals:
void clicked (bool checked = false); void clicked (bool checked = false);
void longClicked();
}; };
@ -110,8 +101,12 @@ class UBGraphicsItemDelegate : public QObject
virtual bool mouseReleaseEvent(QGraphicsSceneMouseEvent *event); virtual bool mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual bool weelEvent(QGraphicsSceneWheelEvent *event); virtual bool weelEvent(QGraphicsSceneWheelEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change, virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change,
const QVariant &value); const QVariant &value);
virtual UBGraphicsScene *castUBGraphicsScene();
void printMessage(const QString &mess) {qDebug() << mess;} void printMessage(const QString &mess) {qDebug() << mess;}
@ -123,6 +118,7 @@ class UBGraphicsItemDelegate : public QObject
void setCanDuplicate(bool allow){ mCanDuplicate = allow; } void setCanDuplicate(bool allow){ mCanDuplicate = allow; }
virtual void positionHandles(); virtual void positionHandles();
void setZOrderButtonsVisible(bool visible);
void startUndoStep(); void startUndoStep();
void commitUndoStep(); void commitUndoStep();
@ -135,6 +131,7 @@ class UBGraphicsItemDelegate : public QObject
QMimeData* mimeData(){ return mMimeData; } QMimeData* mimeData(){ return mMimeData; }
void setMimeData(QMimeData* mimeData); void setMimeData(QMimeData* mimeData);
void setDragPixmap(const QPixmap &pix) {mDragPixmap = pix;}
void setFlippable(bool flippable); void setFlippable(bool flippable);
bool isFlippable(); bool isFlippable();
@ -151,8 +148,10 @@ class UBGraphicsItemDelegate : public QObject
virtual void lock(bool lock); virtual void lock(bool lock);
virtual void duplicate(); virtual void duplicate();
virtual void increaseZLevel() {increaseZLevel(1);} void increaseZLevelUp();
virtual void decreaseZLevel() {increaseZLevel(-1);} void increaseZLevelDown();
void increaseZlevelTop();
void increaseZlevelBottom();
protected: protected:
virtual void buildButtons() {;} virtual void buildButtons() {;}
@ -187,18 +186,22 @@ protected slots:
virtual void gotoContentSource(bool checked); virtual void gotoContentSource(bool checked);
private: private:
void updateFrame();
void updateButtons(bool showUpdated = false);
virtual void increaseZLevel(int delta);
QPointF mOffset; QPointF mOffset;
QTransform mPreviousTransform; QTransform mPreviousTransform;
QPointF mPreviousPosition; QPointF mPreviousPosition;
QPointF mDragStartPosition;
qreal mPreviousZValue; qreal mPreviousZValue;
QSizeF mPreviousSize; QSizeF mPreviousSize;
bool mCanRotate; bool mCanRotate;
bool mCanDuplicate; bool mCanDuplicate;
bool mRespectRatio; bool mRespectRatio;
QMimeData* mMimeData; QMimeData* mMimeData;
QPixmap mDragPixmap;
/** A boolean saying that this object can be flippable (mirror effect) */ /** A boolean saying that this object can be flippable (mirror effect) */
bool mFlippable; bool mFlippable;

@ -58,13 +58,18 @@ void UBGraphicsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
QMimeData* pMime = new QMimeData(); QMimeData* pMime = new QMimeData();
pMime->setImageData(pixmap().toImage()); pMime->setImageData(pixmap().toImage());
mDelegate->setMimeData(pMime); mDelegate->setMimeData(pMime);
int k = pixmap().width() / 100;
QSize newSize(pixmap().width() / k, pixmap().height() / k);
mDelegate->setDragPixmap(pixmap().scaled(newSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
if (mDelegate->mousePressEvent(event)) if (mDelegate->mousePressEvent(event))
{ {
//NOOP //NOOP
} }
else else
{ {
QGraphicsPixmapItem::mousePressEvent(event); // QGraphicsPixmapItem::mousePressEvent(event);
} }
} }

@ -61,10 +61,6 @@ protected:
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
// UBGraphicsItemDelegate* mDelegate;
}; };
#endif /* UBGRAPHICSPIXMAPITEM_H_ */ #endif /* UBGRAPHICSPIXMAPITEM_H_ */

@ -61,24 +61,11 @@
#include "core/memcheck.h" #include "core/memcheck.h"
qreal UBGraphicsScene::drawingLayerStart = 0.0;
qreal UBGraphicsScene::toolLayerStart = 10000000.0;
qreal UBGraphicsScene::toolOffsetRuler = 100;
qreal UBGraphicsScene::toolOffsetProtractor = 100;
qreal UBGraphicsScene::toolOffsetTriangle = 100;
qreal UBGraphicsScene::toolOffsetCompass = 100;
qreal UBGraphicsScene::toolOffsetEraser = 200;
qreal UBGraphicsScene::toolOffsetCurtain = 1000;
qreal UBGraphicsScene::toolOffsetPointer = 1100;
qreal UBGraphicsScene::toolOffsetCache = 1000;//Didier please define offset you want
qreal UBZLayerController::errorNumber = -20000001.0; qreal UBZLayerController::errorNumber = -20000001.0;
UBZLayerController::UBZLayerController(QGraphicsScene *scene) :
mScene(scene)
UBZLayerController::UBZLayerController()
{ {
scopeMap.insert(itemLayerType::NoLayer, ItemLayerTypeData( errorNumber, errorNumber)); scopeMap.insert(itemLayerType::NoLayer, ItemLayerTypeData( errorNumber, errorNumber));
scopeMap.insert(itemLayerType::BackgroundItem, ItemLayerTypeData(-10000000.0, -10000000.0 )); scopeMap.insert(itemLayerType::BackgroundItem, ItemLayerTypeData(-10000000.0, -10000000.0 ));
@ -104,17 +91,162 @@ qreal UBZLayerController::generateZLevel(itemLayerType::Enum key)
qreal result = scopeMap.value(key).curValue; qreal result = scopeMap.value(key).curValue;
qreal top = scopeMap.value(key).topLimit; qreal top = scopeMap.value(key).topLimit;
qreal incrementalStep = scopeMap.value(key).incStep;
result++; result += incrementalStep;
if (result >= top) { if (result >= top) {
// If not only one variable presents in the scope, notify that values for scope are over
if (scopeMap.value(key).topLimit != scopeMap.value(key).bottomLimit) {
qDebug() << "new values are over for the scope" << key; qDebug() << "new values are over for the scope" << key;
result = top - 1; }
result = top - incrementalStep;
} }
scopeMap[key].curValue = result; scopeMap[key].curValue = result;
return result; return result;
} }
qreal UBZLayerController::generateZLevel(QGraphicsItem *item)
{
qreal result = errorNumber;
itemLayerType::Enum type = static_cast<itemLayerType::Enum>(item->data(UBGraphicsItemData::itemLayerType).toInt());
if (validLayerType(type)) {
result = generateZLevel(type);
}
return result;
}
qreal UBZLayerController::changeZLevelTo(QGraphicsItem *item, moveDestination dest)
{
itemLayerType::Enum curItemLayerType = typeForData(item);
if (curItemLayerType == itemLayerType::NoLayer) {
qDebug() << "item's layer is out of the scope. Can't implement z-layer changing operation";
return errorNum();
}
//select only items wiht the same z-level as item's one and push it to sortedItems QMultiMap
QMultiMap<qreal, QGraphicsItem*> sortedItems;
if (mScene->items().count()) {
foreach (QGraphicsItem *tmpItem, mScene->items()) {
if (typeForData(tmpItem) == curItemLayerType) {
sortedItems.insert(tmpItem->data(UBGraphicsItemData::ItemOwnZValue).toReal(), tmpItem);
}
}
}
//If only one item itself - do nothing, return it's z-value
if (sortedItems.count() == 1 && sortedItems.values().first() == item) {
qDebug() << "only one item exists in layer. Have nothing to change";
return item->data(UBGraphicsItemData::ItemOwnZValue).toReal();
}
QMapIterator<qreal, QGraphicsItem*>iCurElement(sortedItems);
if (dest == up) {
if (iCurElement.findNext(item)) {
if (iCurElement.hasNext()) {
qreal nextZ = iCurElement.peekNext().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal();
UBGraphicsItem::assignZValue(iCurElement.peekNext().value(), item->data(UBGraphicsItemData::ItemOwnZValue).toReal());
UBGraphicsItem::assignZValue(item, nextZ);
iCurElement.next();
while (iCurElement.hasNext() && iCurElement.peekNext().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal() == nextZ) {
UBGraphicsItem::assignZValue(iCurElement.next().value(), nextZ);
}
item->scene()->clearSelection();
item->setSelected(true);
}
}
} else if (dest == top) {
if (iCurElement.findNext(item)) {
if (iCurElement.hasNext()) {
UBGraphicsItem::assignZValue(item, generateZLevel(item));
}
}
} else if (dest == down) {
iCurElement.toBack();
if (iCurElement.findPrevious(item)) {
if (iCurElement.hasPrevious()) {
qreal nextZ = iCurElement.peekPrevious().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal();
UBGraphicsItem::assignZValue(iCurElement.peekPrevious().value(), item->data(UBGraphicsItemData::ItemOwnZValue).toReal());
UBGraphicsItem::assignZValue(item, nextZ);
while (iCurElement.hasNext() && iCurElement.peekNext().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal() == nextZ) {
UBGraphicsItem::assignZValue(iCurElement.next().value(), nextZ);
}
}
}
} else if (dest == bottom) {
iCurElement.toBack();
if (iCurElement.findPrevious(item)) {
if (iCurElement.hasPrevious()) {
// qreal oldz = iCurElement.peekPrevious().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal();
qreal oldz = item->data(UBGraphicsItemData::ItemOwnZValue).toReal();
iCurElement.toFront();
qreal nextZ = iCurElement.next().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal();
ItemLayerTypeData curItemLayerTypeData = scopeMap.value(curItemLayerType);
//
//if we have some free space between lowest graphics item and layer's bottom bound,
//insert element close to first element in layer
if (nextZ >= curItemLayerTypeData.bottomLimit + curItemLayerTypeData.incStep) {
qreal result = nextZ - curItemLayerTypeData.incStep;
UBGraphicsItem::assignZValue(item, result);
} else {
UBGraphicsItem::assignZValue(item, nextZ);
bool doubleGap = false; //to detect if we can finish rundown since we can insert item to the free space
while (iCurElement.peekNext().value() != item) {
qreal curZ = iCurElement.value()->data(UBGraphicsItemData::ItemOwnZValue).toReal();
qreal curNextZ = iCurElement.peekNext().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal();
if (curNextZ - curZ >= 2 * curItemLayerTypeData.incStep) {
UBGraphicsItem::assignZValue(iCurElement.value(), curZ + curItemLayerTypeData.incStep);
doubleGap = true;
break;
} else {
UBGraphicsItem::assignZValue(iCurElement.value(), iCurElement.next().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal());
}
}
if (!doubleGap) {
UBGraphicsItem::assignZValue(iCurElement.value(), oldz);
while (iCurElement.hasNext() && (iCurElement.peekNext().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal() == oldz)) {
UBGraphicsItem::assignZValue(iCurElement.next().value(), oldz);
}
}
}
}
}
}
//clear selection of the item and then select it again to activate selectionChangeProcessing()
item->scene()->clearSelection();
item->setSelected(true);
//Return new z value assigned to item
return item->data(UBGraphicsItemData::ItemOwnZValue).toReal();
}
itemLayerType::Enum UBZLayerController::typeForData(QGraphicsItem *item) const
{
itemLayerType::Enum result = static_cast<itemLayerType::Enum>(item->data(UBGraphicsItemData::itemLayerType).toInt());
if (!scopeMap.contains(result)) {
result = itemLayerType::NoLayer;
}
return result;
}
UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
: UBCoreGraphicsScene(parent) : UBCoreGraphicsScene(parent)
@ -135,7 +267,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
, enableUndoRedoStack(true) , enableUndoRedoStack(true)
, magniferControlViewWidget(0) , magniferControlViewWidget(0)
, magniferDisplayViewWidget(0) , magniferDisplayViewWidget(0)
, mZLayerController(new UBZLayerController(this))
{ {
#ifdef __ppc__ #ifdef __ppc__
@ -165,6 +297,9 @@ UBGraphicsScene::~UBGraphicsScene()
if (mCurrentStroke) if (mCurrentStroke)
if (mCurrentStroke->polygons().empty()) if (mCurrentStroke->polygons().empty())
delete mCurrentStroke; delete mCurrentStroke;
if (mZLayerController)
delete mZLayerController;
} }
void UBGraphicsScene::selectionChangedProcessing() void UBGraphicsScene::selectionChangedProcessing()
@ -178,7 +313,7 @@ void UBGraphicsScene::selectionChangedProcessing()
QGraphicsItem *nextItem = allItemsList.at(i); QGraphicsItem *nextItem = allItemsList.at(i);
if (nextItem->isSelected()) { if (nextItem->isSelected()) {
nextItem->setZValue(mZLayerController.generateZLevel(itemLayerType::SelectedItem)); nextItem->setZValue(mZLayerController->generateZLevel(itemLayerType::SelectedItem));
} else { } else {
nextItem->setZValue(nextItem->data(UBGraphicsItemData::ItemOwnZValue).toReal()); nextItem->setZValue(nextItem->data(UBGraphicsItemData::ItemOwnZValue).toReal());
} }
@ -823,7 +958,6 @@ void UBGraphicsScene::leaveEvent(QEvent * event)
hideEraser(); hideEraser();
} }
UBGraphicsScene* UBGraphicsScene::sceneDeepCopy() const UBGraphicsScene* UBGraphicsScene::sceneDeepCopy() const
{ {
UBGraphicsScene* copy = new UBGraphicsScene(this->document()); UBGraphicsScene* copy = new UBGraphicsScene(this->document());
@ -1330,7 +1464,7 @@ void UBGraphicsScene::addItem(QGraphicsItem* item)
setModified(true); setModified(true);
UBCoreGraphicsScene::addItem(item); UBCoreGraphicsScene::addItem(item);
UBGraphicsItem::assignZValue(item, generateZLevel(item)); UBGraphicsItem::assignZValue(item, mZLayerController->generateZLevel(item));
if (!mTools.contains(item)) if (!mTools.contains(item))
++mItemCount; ++mItemCount;
@ -1344,7 +1478,7 @@ void UBGraphicsScene::addItems(const QSet<QGraphicsItem*>& items)
foreach(QGraphicsItem* item, items) { foreach(QGraphicsItem* item, items) {
UBCoreGraphicsScene::addItem(item); UBCoreGraphicsScene::addItem(item);
UBGraphicsItem::assignZValue(item, generateZLevel(item)); UBGraphicsItem::assignZValue(item, mZLayerController->generateZLevel(item));
} }
mItemCount += items.size(); mItemCount += items.size();
@ -1406,7 +1540,7 @@ QGraphicsItem* UBGraphicsScene::setAsBackgroundObject(QGraphicsItem* item, bool
item->setAcceptedMouseButtons(Qt::NoButton); item->setAcceptedMouseButtons(Qt::NoButton);
item->setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::FixedBackground); item->setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::FixedBackground);
UBGraphicsItem::assignZValue(item, mZLayerController.generateZLevel(itemLayerType::BackgroundItem)); UBGraphicsItem::assignZValue(item, mZLayerController->generateZLevel(itemLayerType::BackgroundItem));
if (pAdaptTransformation) if (pAdaptTransformation)
{ {
@ -1779,6 +1913,23 @@ void UBGraphicsScene::setNominalSize(int pWidth, int pHeight)
setNominalSize(QSize(pWidth, pHeight)); setNominalSize(QSize(pWidth, pHeight));
} }
void UBGraphicsScene::setSelectedZLevel(QList<QGraphicsItem *> itemList)
{
foreach (QGraphicsItem *item, itemList) {
item->setZValue(mZLayerController->generateZLevel(itemLayerType::SelectedItem));
}
}
void UBGraphicsScene::setOwnZlevel(QList<QGraphicsItem *> itemList)
{
foreach (QGraphicsItem *item, itemList) {
item->setZValue(item->data(UBGraphicsItemData::ItemOwnZValue).toReal());
}
}
qreal UBGraphicsScene::changeZLevelTo(QGraphicsItem *item, UBZLayerController::moveDestination dest)
{
return mZLayerController->changeZLevelTo(item, dest);
}
QGraphicsItem* UBGraphicsScene::rootItem(QGraphicsItem* item) const QGraphicsItem* UBGraphicsScene::rootItem(QGraphicsItem* item) const
{ {
@ -1951,18 +2102,6 @@ void UBGraphicsScene::createPointer()
addItem(mPointer); addItem(mPointer);
} }
qreal UBGraphicsScene::generateZLevel(QGraphicsItem *item)
{
qreal result = UBZLayerController::errorNum();
itemLayerType::Enum type = static_cast<itemLayerType::Enum>(item->data(UBGraphicsItemData::itemLayerType).toInt());
if (mZLayerController.validLayerType(type)) {
result = mZLayerController.generateZLevel(type);
}
return result;
}
void UBGraphicsScene::setToolCursor(int tool) void UBGraphicsScene::setToolCursor(int tool)
{ {
if (tool != (int)UBStylusTool::Selector if (tool != (int)UBStylusTool::Selector

@ -49,33 +49,47 @@ class UBGraphicsCache;
const double PI = 4.0 * atan(1.0); const double PI = 4.0 * atan(1.0);
class UBZLayerController class UBZLayerController : public QObject
{ {
public: Q_OBJECT
public:
struct ItemLayerTypeData { struct ItemLayerTypeData {
ItemLayerTypeData() : bottomLimit(0), topLimit(0), curValue(0) {;} ItemLayerTypeData() : bottomLimit(0), topLimit(0), curValue(0), incStep(1) {;}
ItemLayerTypeData(qreal bot, qreal top) : bottomLimit(bot), topLimit(top), curValue(bot) {;} ItemLayerTypeData(qreal bot, qreal top, qreal increment = 1) : bottomLimit(bot), topLimit(top), curValue(bot), incStep(increment) {;}
qreal bottomLimit; qreal bottomLimit; //bottom bound of the layer
qreal topLimit; qreal topLimit;//top bound of the layer
qreal curValue; qreal curValue;//current value of variable
qreal incStep;//incremental step
};
enum moveDestination {
up
, down
, top
, bottom
}; };
typedef QMap<itemLayerType::Enum, ItemLayerTypeData> ScopeMap; typedef QMap<itemLayerType::Enum, ItemLayerTypeData> ScopeMap;
UBZLayerController(); UBZLayerController(QGraphicsScene *scene);
qreal getBottomLimit(itemLayerType::Enum key) const {return scopeMap.value(key).bottomLimit;} qreal getBottomLimit(itemLayerType::Enum key) const {return scopeMap.value(key).bottomLimit;}
qreal getTopLimit(itemLayerType::Enum key) const {return scopeMap.value(key).topLimit;} qreal getTopLimit(itemLayerType::Enum key) const {return scopeMap.value(key).topLimit;}
bool validLayerType(itemLayerType::Enum key) const {return scopeMap.contains(key);} bool validLayerType(itemLayerType::Enum key) const {return scopeMap.contains(key);}
static qreal errorNum() {return errorNumber;} static qreal errorNum() {return errorNumber;}
qreal generateZLevel(itemLayerType::Enum key); qreal generateZLevel(itemLayerType::Enum key);
qreal generateZLevel(QGraphicsItem *item);
qreal changeZLevelTo(QGraphicsItem *item, moveDestination dest);
itemLayerType::Enum typeForData(QGraphicsItem *item) const;
private: private:
ScopeMap scopeMap; ScopeMap scopeMap;
static qreal errorNumber; static qreal errorNumber;
QGraphicsScene *mScene;
}; };
class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
@ -242,6 +256,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
void setNominalSize(int pWidth, int pHeight); void setNominalSize(int pWidth, int pHeight);
qreal changeZLevelTo(QGraphicsItem *item, UBZLayerController::moveDestination dest);
enum RenderingContext enum RenderingContext
{ {
Screen = 0, NonScreen, PdfExport, Podcast Screen = 0, NonScreen, PdfExport, Podcast
@ -257,20 +273,6 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
return mRenderingContext; return mRenderingContext;
} }
static qreal backgroundLayerStart;
static qreal objectLayerStart;
static qreal drawingLayerStart;
static qreal toolLayerStart;
static qreal toolOffsetEraser;
static qreal toolOffsetPointer;
static qreal toolOffsetRuler;
static qreal toolOffsetProtractor;
static qreal toolOffsetCompass;
static qreal toolOffsetCurtain;
static qreal toolOffsetTriangle;
static qreal toolOffsetCache;
QSet<QGraphicsItem*> tools(){ return mTools;} QSet<QGraphicsItem*> tools(){ return mTools;}
void registerTool(QGraphicsItem* item) void registerTool(QGraphicsItem* item)
@ -283,6 +285,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
return mPreviousPoint; return mPreviousPoint;
} }
void setSelectedZLevel(QList<QGraphicsItem *> itemList);
void setOwnZlevel(QList<QGraphicsItem *> itemList);
public slots: public slots:
void hideEraser(); void hideEraser();
@ -336,8 +340,6 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
void createEraiser(); void createEraiser();
void createPointer(); void createPointer();
qreal generateZLevel(QGraphicsItem *item);
QGraphicsEllipseItem* mEraser; QGraphicsEllipseItem* mEraser;
QGraphicsEllipseItem* mPointer; QGraphicsEllipseItem* mPointer;
@ -387,7 +389,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
UBMagnifier *magniferControlViewWidget; UBMagnifier *magniferControlViewWidget;
UBMagnifier *magniferDisplayViewWidget; UBMagnifier *magniferDisplayViewWidget;
UBZLayerController mZLayerController; UBZLayerController *mZLayerController;
}; };

@ -109,10 +109,10 @@ void UBGraphicsVideoItem::showOnDisplayChanged(bool shown)
void UBGraphicsVideoItem::mousePressEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsVideoItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
QDrag* mDrag = new QDrag(event->widget()); // QDrag* mDrag = new QDrag(event->widget());
QMimeData* pMime = new QMimeData(); // QMimeData* pMime = new QMimeData();
mDrag->setMimeData(pMime); // mDrag->setMimeData(pMime);
mDrag->start(); // mDrag->start();
mShouldMove = (event->buttons() & Qt::LeftButton); mShouldMove = (event->buttons() & Qt::LeftButton);
mMousePressPos = event->scenePos(); mMousePressPos = event->scenePos();

@ -82,11 +82,13 @@ void UBGraphicsWidgetItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void UBGraphicsWidgetItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void UBGraphicsWidgetItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
sendJSEnterEvent(); sendJSEnterEvent();
mDelegate->hoverEnterEvent(event);
UBGraphicsProxyWidget::hoverEnterEvent(event); UBGraphicsProxyWidget::hoverEnterEvent(event);
} }
void UBGraphicsWidgetItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void UBGraphicsWidgetItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{ {
sendJSLeaveEvent(); sendJSLeaveEvent();
mDelegate->hoverLeaveEvent(event);
UBGraphicsProxyWidget::hoverLeaveEvent(event); UBGraphicsProxyWidget::hoverLeaveEvent(event);
} }

@ -29,7 +29,7 @@ UBItem::~UBItem()
// NOOP // NOOP
} }
void UBGraphicsItem::assignZValue(QGraphicsItem *item, int value) void UBGraphicsItem::assignZValue(QGraphicsItem *item, qreal value)
{ {
item->setZValue(value); item->setZValue(value);
item->setData(UBGraphicsItemData::ItemOwnZValue, value); item->setData(UBGraphicsItemData::ItemOwnZValue, value);

@ -101,7 +101,7 @@ protected:
public: public:
static void assignZValue(QGraphicsItem*, int value); static void assignZValue(QGraphicsItem*, qreal value);
virtual UBGraphicsItemDelegate *Delegate() const = 0; virtual UBGraphicsItemDelegate *Delegate() const = 0;
virtual void remove() = 0; virtual void remove() = 0;

Loading…
Cancel
Save