Fixed an issue related to z-level management

preferencesAboutTextFull
Didier Clerc 11 years ago
parent 034800538d
commit be14bdc657
  1. 2
      src/core/UB.h
  2. 8
      src/domain/UBGraphicsItemDelegate.cpp
  3. 59
      src/domain/UBGraphicsItemZLevelUndoCommand.cpp
  4. 32
      src/domain/UBGraphicsItemZLevelUndoCommand.h
  5. 16
      src/domain/UBGraphicsScene.cpp
  6. 3
      src/domain/UBGraphicsScene.h
  7. 32
      src/domain/UBSelectionFrame.cpp
  8. 4
      src/domain/UBSelectionFrame.h
  9. 6
      src/domain/domain.pri

@ -200,7 +200,7 @@ struct UBUndoType
{
enum Enum
{
undotype_UNKNOWN = 0, undotype_DOCUMENT, undotype_GRAPHICITEMTRANSFORM, undotype_GRAPHICITEM, undotype_GRAPHICTEXTITEM, undotype_PAGESIZE, undotype_GRAPHICSGROUPITEM
undotype_UNKNOWN = 0, undotype_DOCUMENT, undotype_GRAPHICITEMTRANSFORM, undotype_GRAPHICITEM, undotype_GRAPHICTEXTITEM, undotype_PAGESIZE, undotype_GRAPHICSGROUPITEM, undotype_GRAPHICITEMZVALUE
};
};

@ -524,28 +524,28 @@ void UBGraphicsItemDelegate::increaseZLevelUp()
{
UBGraphicsScene *curScene = castUBGraphicsScene();
if (curScene) {
curScene->changeZLevelTo(delegated(), UBZLayerController::up);
curScene->changeZLevelTo(delegated(), UBZLayerController::up, true);
}
}
void UBGraphicsItemDelegate::increaseZlevelTop()
{
UBGraphicsScene *curScene = castUBGraphicsScene();
if (curScene) {
curScene->changeZLevelTo(delegated(), UBZLayerController::top);
curScene->changeZLevelTo(delegated(), UBZLayerController::top, true);
}
}
void UBGraphicsItemDelegate::increaseZLevelDown()
{
UBGraphicsScene *curScene = castUBGraphicsScene();
if (curScene) {
curScene->changeZLevelTo(delegated(), UBZLayerController::down);
curScene->changeZLevelTo(delegated(), UBZLayerController::down, true);
}
}
void UBGraphicsItemDelegate::increaseZlevelBottom()
{
UBGraphicsScene *curScene = castUBGraphicsScene();
if (curScene) {
curScene->changeZLevelTo(delegated(), UBZLayerController::bottom);
curScene->changeZLevelTo(delegated(), UBZLayerController::bottom, true);
}
}

@ -0,0 +1,59 @@
#include "UBGraphicsItemZLevelUndoCommand.h"
UBGraphicsItemZLevelUndoCommand::UBGraphicsItemZLevelUndoCommand(UBGraphicsScene *_scene, const QList<QGraphicsItem*>& _items, qreal _previousZLevel, UBZLayerController::moveDestination dest):UBUndoCommand(){
Q_ASSERT(_scene != NULL);
mpScene = _scene;
mItems = _items;
mPreviousZLevel = _previousZLevel;
mDest = dest;
mHack = false;
}
UBGraphicsItemZLevelUndoCommand::UBGraphicsItemZLevelUndoCommand(UBGraphicsScene *_scene, QGraphicsItem* _item, qreal _previousZLevel, UBZLayerController::moveDestination dest):UBUndoCommand(){
Q_ASSERT(_scene != NULL);
mpScene = _scene;
if(NULL != _item)
mItems.append(_item);
mPreviousZLevel = _previousZLevel;
mDest = dest;
mHack = false;
}
UBGraphicsItemZLevelUndoCommand::~UBGraphicsItemZLevelUndoCommand(){
}
void UBGraphicsItemZLevelUndoCommand::undo(){
if(!mpScene)
return;
foreach(QGraphicsItem* item, mItems){
if(mDest == UBZLayerController::down){
mpScene->changeZLevelTo(item, UBZLayerController::up);
}else if(mDest == UBZLayerController::up){
mpScene->changeZLevelTo(item, UBZLayerController::down);
}
updateLazyScene();
}
}
void UBGraphicsItemZLevelUndoCommand::redo(){
if(!mHack){
// Ugly! But pushing a new command to QUndoStack calls redo by itself.
mHack = true;
}else{
if(!mpScene)
return;
foreach(QGraphicsItem* item, mItems){
mpScene->changeZLevelTo(item, mDest);
updateLazyScene();
}
}
}
void UBGraphicsItemZLevelUndoCommand::updateLazyScene(){
mpScene->update(mpScene->sceneRect());
mpScene->updateSelectionFrame();
}

@ -0,0 +1,32 @@
#ifndef UBGRAPHICSITEMZLEVELUNDOCOMMAND_H
#define UBGRAPHICSITEMZLEVELUNDOCOMMAND_H
#include <QGraphicsItem>
#include "UBUndoCommand.h"
#include "UBGraphicsScene.h"
class UBGraphicsItemZLevelUndoCommand : public UBUndoCommand{
public:
UBGraphicsItemZLevelUndoCommand(UBGraphicsScene* _scene, const QList<QGraphicsItem*>& _items, qreal _previousZLevel, UBZLayerController::moveDestination dest);
UBGraphicsItemZLevelUndoCommand(UBGraphicsScene* _scene, QGraphicsItem* _item, qreal _previousZLevel, UBZLayerController::moveDestination dest);
~UBGraphicsItemZLevelUndoCommand();
virtual int getType() const { return UBUndoType::undotype_GRAPHICITEMZVALUE; }
protected:
virtual void undo();
virtual void redo();
private:
void updateLazyScene();
qreal mPreviousZLevel;
QList<QGraphicsItem*> mItems;
UBGraphicsScene* mpScene;
UBZLayerController::moveDestination mDest;
bool mHack;
};
#endif // UBGRAPHICSITEMZLEVELUNDOCOMMAND_H

@ -68,6 +68,7 @@
#include "UBGraphicsTextItem.h"
#include "UBGraphicsStrokesGroup.h"
#include "UBSelectionFrame.h"
#include "UBGraphicsItemZLevelUndoCommand.h"
#include "domain/UBGraphicsGroupContainerItem.h"
@ -164,6 +165,7 @@ qreal UBZLayerController::changeZLevelTo(QGraphicsItem *item, moveDestination de
QMapIterator<qreal, QGraphicsItem*>iCurElement(sortedItems);
if (dest == up) {
qDebug() << "item data zvalue= " << item->data(UBGraphicsItemData::ItemOwnZValue).toReal();
if (iCurElement.findNext(item)) {
if (iCurElement.hasNext()) {
qreal nextZ = iCurElement.peekNext().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal();
@ -1068,8 +1070,6 @@ void UBGraphicsScene::notifyZChanged(QGraphicsItem *item, qreal zValue)
void UBGraphicsScene::updateSelectionFrame()
{
qDebug() << "selected item count" << selectedItems().count();
if (!mSelectionFrame) {
mSelectionFrame = new UBSelectionFrame();
addItem(mSelectionFrame);
@ -2170,9 +2170,17 @@ QUuid UBGraphicsScene::getPersonalUuid(QGraphicsItem *item)
return idCandidate == QUuid().toString() ? QUuid() : QUuid(idCandidate);
}
qreal UBGraphicsScene::changeZLevelTo(QGraphicsItem *item, UBZLayerController::moveDestination dest)
qreal UBGraphicsScene::changeZLevelTo(QGraphicsItem *item, UBZLayerController::moveDestination dest, bool addUndo)
{
return mZLayerController->changeZLevelTo(item, dest);
qreal previousZVal = item->data(UBGraphicsItemData::ItemOwnZValue).toReal();
qreal res = mZLayerController->changeZLevelTo(item, dest);
if(addUndo){
UBGraphicsItemZLevelUndoCommand* uc = new UBGraphicsItemZLevelUndoCommand(this, item, previousZVal, dest);
UBApplication::undoStack->push(uc);
}
return res;
}
QGraphicsItem* UBGraphicsScene::rootItem(QGraphicsItem* item) const

@ -275,7 +275,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
void setNominalSize(int pWidth, int pHeight);
qreal changeZLevelTo(QGraphicsItem *item, UBZLayerController::moveDestination dest);
qreal changeZLevelTo(QGraphicsItem *item, UBZLayerController::moveDestination dest, bool addUndo=false);
enum RenderingContext
{
@ -314,7 +314,6 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
UBBoardView *controlView();
void notifyZChanged(QGraphicsItem *item, qreal zValue);
public slots:
void updateSelectionFrame();
void updateSelectionFrameWrapper(int);

@ -3,12 +3,12 @@
#include <QtGui>
#include "domain/UBItem.h"
#include "domain/UBGraphicsItemZLevelUndoCommand.h"
#include "board/UBBoardController.h"
#include "core/UBSettings.h"
#include "core/UBApplication.h"
#include "gui/UBResources.h"
#include "core/UBApplication.h"
#include "domain/UBGraphicsScene.h"
#include "board/UBBoardView.h"
UBSelectionFrame::UBSelectionFrame()
@ -245,37 +245,58 @@ void UBSelectionFrame::duplicate()
void UBSelectionFrame::increaseZlevelUp()
{
foreach (QGraphicsItem *item, sortedByZ(scene()->selectedItems())) {
QList<QGraphicsItem*> selItems = sortedByZ(scene()->selectedItems());
QList<QGraphicsItem*>::iterator itemIt = selItems.end();
while(itemIt != selItems.begin()){
itemIt--;
QGraphicsItem* item = *itemIt;
ubscene()->changeZLevelTo(item, UBZLayerController::up);
}
addSelectionUndo(selItems, UBZLayerController::up);
}
void UBSelectionFrame::increaseZlevelTop()
{
foreach (QGraphicsItem *item, sortedByZ(scene()->selectedItems())) {
QList<QGraphicsItem*> selItems = sortedByZ(scene()->selectedItems());
foreach (QGraphicsItem *item, selItems) {
ubscene()->changeZLevelTo(item, UBZLayerController::top);
}
addSelectionUndo(selItems, UBZLayerController::top);
}
void UBSelectionFrame::increaseZlevelDown()
{
foreach (QGraphicsItem *item, sortedByZ(scene()->selectedItems())) {
QList<QGraphicsItem*> selItems = sortedByZ(scene()->selectedItems());
foreach (QGraphicsItem *item, selItems) {
ubscene()->changeZLevelTo(item, UBZLayerController::down);
}
addSelectionUndo(selItems, UBZLayerController::down);
}
void UBSelectionFrame::increaseZlevelBottom()
{
QListIterator<QGraphicsItem*> iter(sortedByZ(scene()->selectedItems()));
QList<QGraphicsItem*> selItems = sortedByZ(scene()->selectedItems());
QListIterator<QGraphicsItem*> iter(selItems);
iter.toBack();
while (iter.hasPrevious()) {
ubscene()->changeZLevelTo(iter.previous(), UBZLayerController::bottom);
}
addSelectionUndo(selItems, UBZLayerController::bottom);
// foreach (QGraphicsItem *item, sortedByZ(scene()->selectedItems())) {
// ubscene()->changeZLevelTo(item, UBZLayerController::bottom);
// }
}
void UBSelectionFrame::addSelectionUndo(QList<QGraphicsItem*> items, UBZLayerController::moveDestination dest){
if(!items.empty()){
qreal topItemLevel = items.at(0)->data(UBGraphicsItemData::ItemOwnZValue).toReal();
UBGraphicsItemZLevelUndoCommand* cmd = new UBGraphicsItemZLevelUndoCommand(ubscene(), items, topItemLevel, dest);
UBApplication::undoStack->push(cmd);
}
}
void UBSelectionFrame::translateItem(QGraphicsItem */*item*/, const QPointF &/*translatePoint*/)
{
}
@ -388,6 +409,7 @@ void UBSelectionFrame::setCursorFromAngle(QString angle)
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
// It means: keep only the selected items and remove the selection frame from the list
QMultiMap<qreal, QGraphicsItem*> sortedItems;
foreach (QGraphicsItem *tmpItem, pItems) {
if (tmpItem->type() == Type) {

@ -5,9 +5,10 @@
#include <QtGui>
#include <core/UB.h>
#include "domain/UBGraphicsScene.h"
class DelegateButton;
class UBGraphicsItemDelegate;
class UBGraphicsScene;
class UBSelectionFrame : public QObject, public QGraphicsRectItem
{
@ -48,6 +49,7 @@ private slots:
void increaseZlevelBottom();
private:
void addSelectionUndo(QList<QGraphicsItem*> items, UBZLayerController::moveDestination dest);
void translateItem(QGraphicsItem *item, const QPointF &translatePoint);
void placeButtons();
void placeExceptionButton(DelegateButton *pButton, QTransform pTransform);

@ -24,7 +24,8 @@ HEADERS += src/domain/UBGraphicsScene.h \
src/domain/UBGraphicsWidgetItemDelegate.h \
src/domain/UBGraphicsMediaItemDelegate.h \
src/domain/UBSelectionFrame.h \
src/domain/UBUndoCommand.h
src/domain/UBUndoCommand.h \
src/domain/UBGraphicsItemZLevelUndoCommand.h
SOURCES += src/domain/UBGraphicsScene.cpp \
src/domain/UBGraphicsItemUndoCommand.cpp \
@ -52,4 +53,5 @@ SOURCES += src/domain/UBGraphicsScene.cpp \
src/domain/UBGraphicsDelegateFrame.cpp \
src/domain/UBGraphicsWidgetItemDelegate.cpp \
src/domain/UBSelectionFrame.cpp \
src/domain/UBUndoCommand.cpp
src/domain/UBUndoCommand.cpp \
src/domain/UBGraphicsItemZLevelUndoCommand.cpp

Loading…
Cancel
Save