From 005d30feb9461f60877a9cc2eee07d205e23c709 Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Thu, 13 Jun 2013 15:38:08 +0300 Subject: [PATCH] Duplication, paint all the selected items by highlighting them --- src/board/UBBoardView.cpp | 1 + src/core/UB.h | 25 +++ src/domain/UBGraphicsDelegateFrame.cpp | 10 +- src/domain/UBGraphicsGroupContainerItem.cpp | 16 +- .../UBGraphicsGroupContainerItemDelegate.cpp | 6 +- src/domain/UBGraphicsItemDelegate.cpp | 88 ++++---- src/domain/UBGraphicsItemDelegate.h | 33 ++- src/domain/UBGraphicsItemUndoCommand.cpp | 1 + src/domain/UBGraphicsMediaItem.cpp | 6 +- src/domain/UBGraphicsMediaItem.h | 1 + src/domain/UBGraphicsMediaItemDelegate.cpp | 8 +- src/domain/UBGraphicsPDFItem.cpp | 8 +- src/domain/UBGraphicsPDFItem.h | 1 + src/domain/UBGraphicsPixmapItem.cpp | 13 +- src/domain/UBGraphicsProxyWidget.cpp | 4 + src/domain/UBGraphicsProxyWidget.h | 1 + src/domain/UBGraphicsScene.cpp | 10 + src/domain/UBGraphicsScene.h | 1 + src/domain/UBGraphicsStrokesGroup.cpp | 21 +- src/domain/UBGraphicsSvgItem.cpp | 13 +- src/domain/UBGraphicsTextItem.cpp | 7 +- src/domain/UBGraphicsTextItemDelegate.cpp | 4 +- src/domain/UBGraphicsWidgetItem.cpp | 3 +- src/domain/UBGraphicsWidgetItemDelegate.cpp | 4 +- src/domain/UBItem.cpp | 6 + src/domain/UBItem.h | 29 +-- src/domain/UBSelectionFrame.cpp | 196 ++++++++++++++---- src/domain/UBSelectionFrame.h | 14 ++ src/pdf/GraphicsPDFItem.cpp | 1 + src/tools/UBGraphicsCurtainItem.cpp | 1 + src/tools/UBGraphicsCurtainItemDelegate.cpp | 5 +- 31 files changed, 348 insertions(+), 189 deletions(-) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 903f4e54..50adc7f9 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -67,6 +67,7 @@ #include "domain/UBGraphicsSvgItem.h" #include "domain/UBGraphicsGroupContainerItem.h" #include "domain/UBGraphicsStrokesGroup.h" +#include "domain/UBGraphicsItemDelegate.h" #include "document/UBDocumentProxy.h" diff --git a/src/core/UB.h b/src/core/UB.h index 5661abc1..69b1f263 100644 --- a/src/core/UB.h +++ b/src/core/UB.h @@ -160,6 +160,31 @@ struct UBGraphicsItemType }; }; +// Might be fit in int value under most OS +enum UBGraphicsFlag { + GF_NONE = 0x0000 //0000 0000 0000 0000 + ,GF_FLIPPABLE_X_AXIS = 0x0001 //0000 0000 0000 0001 + ,GF_FLIPPABLE_Y_AXIS = 0x0002 //0000 0000 0000 0010 + ,GF_FLIPPABLE_ALL_AXIS = 0x0003 //0000 0000 0000 0011 GF_FLIPPABLE_X_AXIS | GF_FLIPPABLE_Y_AXIS + ,GF_REVOLVABLE = 0x0004 //0000 0000 0000 0100 + ,GF_SCALABLE_X_AXIS = 0x0008 //0000 0000 0000 1000 + ,GF_SCALABLE_Y_AXIS = 0x0010 //0000 0000 0001 0000 + ,GF_SCALABLE_ALL_AXIS = 0x0018 //0000 0000 0001 1000 GF_SCALABLE_X_AXIS | GF_SCALABLE_Y_AXIS + ,GF_DUPLICATION_ENABLED = 0x0020 //0000 0000 0010 0000 + ,GF_MENU_SPECIFIED = 0x0040 //0000 0000 0100 0000 + ,GF_ZORDER_MANIPULATIONS_ALLOWED = 0x0080 //0000 0000 1000 0000 + ,GF_TOOLBAR_USED = 0x0100 //0000 0001 0000 0000 + ,GF_SHOW_CONTENT_SOURCE = 0x0200 //0000 0010 0000 0000 + ,GF_RESPECT_RATIO = 0x0418 //0000 0100 0001 1000 + ,GF_COMMON = 0x00F8 /*0000 0000 1111 1000 GF_SCALABLE_ALL_AXIS + |GF_DUPLICATION_ENABLED + |GF_MENU_SPECIFIED + |GF_ZORDER_MANIPULATIONS_ALLOWED */ + ,GF_ALL = 0xFFFF //1111 1111 1111 1111 +}; +Q_DECLARE_FLAGS(UBGraphicsFlags, UBGraphicsFlag) +Q_DECLARE_OPERATORS_FOR_FLAGS(UBGraphicsFlags ) + struct DocumentSizeRatio { enum Enum diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index 410d7c3b..dcb36249 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -92,7 +92,7 @@ UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelega mRotateButton = new QGraphicsSvgItem(":/images/rotate.svg", this); mRotateButton->setCursor(UBResources::resources()->rotateCursor); - mRotateButton->setVisible(mDelegate->canRotate()); + mRotateButton->setVisible(mDelegate->testUBFlags(GF_REVOLVABLE)); updateResizeCursors(); @@ -452,7 +452,7 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) }else if(resizingRight()){ scaleX = (width + moveX) / width; } - if(mDelegate->isFlippable() && qAbs(scaleX) != 0){ + if(mDelegate->testUBFlags(GF_FLIPPABLE_ALL_AXIS) && qAbs(scaleX) != 0){ if((qAbs(width * scaleX)) < 2*mFrameWidth){ bool negative = (scaleX < 0)?true:false; if(negative){ @@ -482,7 +482,7 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) scaleY = (height + moveY) / height; } - if(mDelegate->isFlippable() && qAbs(scaleY) != 0){ + if(mDelegate->testUBFlags(GF_FLIPPABLE_ALL_AXIS) && qAbs(scaleY) != 0){ if((qAbs(height * scaleY)) < 2*mFrameWidth){ bool negative = (scaleY < 0)?true:false; if(negative){ @@ -883,7 +883,7 @@ void UBGraphicsDelegateFrame::positionHandles() mLeftResizeGripSvgItem->setVisible(!isLocked && (bShowHorizontalResizers || bShowAllResizers)); mRightResizeGripSvgItem->setVisible(!isLocked && (bShowHorizontalResizers || bShowAllResizers)); mTopResizeGripSvgItem->setVisible(!isLocked && (bShowVerticalResizers || bShowAllResizers)); - mRotateButton->setVisible(mDelegate->canRotate() && !isLocked); + mRotateButton->setVisible(mDelegate->testUBFlags(GF_REVOLVABLE) && !isLocked); mBottomRightResizeGrip->setVisible(!isLocked && bShowAllResizers); mBottomResizeGrip->setVisible(!isLocked && (bShowVerticalResizers || bShowAllResizers)); @@ -947,7 +947,7 @@ UBGraphicsDelegateFrame::FrameTool UBGraphicsDelegateFrame::toolFromPos(QPointF return ResizeTop; } } - else if (rotateButtonBounds().contains(pos) && mDelegate && mDelegate->canRotate()) + else if (rotateButtonBounds().contains(pos) && mDelegate && mDelegate->testUBFlags(GF_REVOLVABLE)) return Rotate; else return Move; diff --git a/src/domain/UBGraphicsGroupContainerItem.cpp b/src/domain/UBGraphicsGroupContainerItem.cpp index 8d55177c..69686aff 100644 --- a/src/domain/UBGraphicsGroupContainerItem.cpp +++ b/src/domain/UBGraphicsGroupContainerItem.cpp @@ -39,8 +39,7 @@ UBGraphicsGroupContainerItem::UBGraphicsGroupContainerItem(QGraphicsItem *parent { setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); - setDelegate(new UBGraphicsGroupContainerItemDelegate(this, 0)); - Delegate()->init(); + setDelegate(new UBGraphicsGroupContainerItemDelegate(this, 0)); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setFlag(QGraphicsItem::ItemIsSelectable, true); @@ -71,14 +70,14 @@ void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item) //Check if group is allready rotatable or flippable if (childItems().count()) { if (UBGraphicsItem::isFlippable(this) && !UBGraphicsItem::isFlippable(item)) { - Delegate()->setFlippable(false); + Delegate()->setUBFlag(GF_FLIPPABLE_ALL_AXIS, false); } if (UBGraphicsItem::isRotatable(this) && !UBGraphicsItem::isRotatable(item)) { - Delegate()->setRotatable(false); + Delegate()->setUBFlag(GF_REVOLVABLE, false); } } else { - Delegate()->setFlippable(UBGraphicsItem::isFlippable(item)); - Delegate()->setRotatable(UBGraphicsItem::isRotatable(item)); + Delegate()->setUBFlag(GF_FLIPPABLE_ALL_AXIS, UBGraphicsItem::isFlippable(item)); + Delegate()->setUBFlag(GF_REVOLVABLE, UBGraphicsItem::isRotatable(item)); } // COMBINE @@ -194,6 +193,7 @@ void UBGraphicsGroupContainerItem::paint(QPainter *painter, const QStyleOptionGr // painter->setPen(tmpPen); // painter->drawRect(itemsBoundingRect.adjusted(tmpPenWidth / 2, tmpPenWidth / 2, -tmpPenWidth / 2, -tmpPenWidth / 2)); // } + Delegate()->postpaint(painter, option, widget); } UBCoreGraphicsScene *UBGraphicsGroupContainerItem::corescene() @@ -334,8 +334,8 @@ void UBGraphicsGroupContainerItem::pRemoveFromGroup(QGraphicsItem *item) break; } } - Delegate()->setFlippable(flippableNow); - Delegate()->setRotatable(rotatableNow); + Delegate()->setUBFlag(GF_FLIPPABLE_ALL_AXIS, flippableNow); + Delegate()->setUBFlag(GF_REVOLVABLE, rotatableNow); } } diff --git a/src/domain/UBGraphicsGroupContainerItemDelegate.cpp b/src/domain/UBGraphicsGroupContainerItemDelegate.cpp index b0922814..8f73c2c6 100644 --- a/src/domain/UBGraphicsGroupContainerItemDelegate.cpp +++ b/src/domain/UBGraphicsGroupContainerItemDelegate.cpp @@ -36,13 +36,9 @@ #include "core/memcheck.h" UBGraphicsGroupContainerItemDelegate::UBGraphicsGroupContainerItemDelegate(QGraphicsItem *pDelegated, QObject *parent) : - UBGraphicsItemDelegate(pDelegated, parent, true, false, false), mDestroyGroupButton(0) + UBGraphicsItemDelegate(pDelegated, parent, GF_COMMON | GF_RESPECT_RATIO), mDestroyGroupButton(0) { - //Wrapper function. Use it to set correct data() to QGraphicsItem as well - setFlippable(false); - setRotatable(false); - setCanDuplicate(true); } UBGraphicsGroupContainerItem *UBGraphicsGroupContainerItemDelegate::delegated() diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 7a5e5c59..752758d6 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -152,7 +152,7 @@ void DelegateButton::startShowProgress() } } -UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObject * parent, bool respectRatio, bool canRotate, bool useToolBar, bool showGoContentButton) +UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObject * parent, UBGraphicsFlags fls) : QObject(parent) , mDelegated(pDelegated) , mDeleteButton(NULL) @@ -168,31 +168,19 @@ UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObjec , mFrameWidth(UBSettings::settings()->objectFrameWidth) , mAntiScaleRatio(1.0) , mToolBarItem(NULL) - , mCanRotate(canRotate) - , mCanDuplicate(true) - , mRespectRatio(respectRatio) , mMimeData(NULL) - , mFlippable(false) - , mToolBarUsed(useToolBar) - , mShowGoContentButton(showGoContentButton) { + setUBFlags(fls); connect(UBApplication::boardController, SIGNAL(zoomChanged(qreal)), this, SLOT(onZoomChanged())); } -void UBGraphicsItemDelegate::init() -{ - //Wrapper function. Use it to set correct data() to QGraphicsItem as well - setFlippable(false); - setRotatable(false); -} - void UBGraphicsItemDelegate::createControls() { - if (mToolBarUsed && !mToolBarItem) + if (testUBFlags(GF_TOOLBAR_USED) && !mToolBarItem) mToolBarItem = new UBGraphicsToolBarItem(mDelegated); if (!mFrame) { - mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio); + mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, testUBFlags(GF_RESPECT_RATIO)); mFrame->hide(); mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true); } @@ -201,7 +189,7 @@ void UBGraphicsItemDelegate::createControls() mDeleteButton = new DelegateButton(":/images/close.svg", mDelegated, mFrame, Qt::TopLeftSection); mButtons << mDeleteButton; connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(remove())); - if (canDuplicate()){ + if (testUBFlags(GF_DUPLICATION_ENABLED)){ mDuplicateButton = new DelegateButton(":/images/duplicate.svg", mDelegated, mFrame, Qt::TopLeftSection); connect(mDuplicateButton, SIGNAL(clicked(bool)), this, SLOT(duplicate())); mButtons << mDuplicateButton; @@ -319,6 +307,19 @@ UBGraphicsScene *UBGraphicsItemDelegate::castUBGraphicsScene() return castScene; } +/** Used to render custom data after the main "Paint" operation is finished */ +void UBGraphicsItemDelegate::postpaint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(widget) + if (option->state & QStyle::State_Selected && !controlsExist()) { + painter->save(); + painter->setPen(Qt::NoPen); + painter->setBrush(QColor(0x88, 0x88, 0x88, 0x77)); + painter->drawRect(option->rect); + painter->restore(); + } +} + bool UBGraphicsItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event) { mDragStartPosition = event->pos(); @@ -667,7 +668,7 @@ void UBGraphicsItemDelegate::decorateMenu(QMenu* menu) showIcon.addPixmap(QPixmap(":/images/eyeClosed.svg"), QIcon::Normal, QIcon::Off); mShowOnDisplayAction->setIcon(showIcon); - if (mShowGoContentButton) + if (testUBFlags(GF_SHOW_CONTENT_SOURCE)) { mGotoContentSourceAction = menu->addAction(tr("Go to Content Source"), this, SLOT(gotoContentSource())); @@ -711,32 +712,6 @@ void UBGraphicsItemDelegate::showMenu() mMenu->exec(cv->mapToGlobal(pinPos.bottomRight())); } -void UBGraphicsItemDelegate::setFlippable(bool flippable) -{ - mFlippable = flippable; - - Q_ASSERT (mDelegated); - if (mDelegated) { - mDelegated->setData(UBGraphicsItemData::ItemFlippable, QVariant(flippable)); - } -} - -void UBGraphicsItemDelegate::setRotatable(bool pCanRotate) -{ - mCanRotate = pCanRotate; - - Q_ASSERT(mDelegated); - - if (mDelegated) { - mDelegated->setData(UBGraphicsItemData::ItemRotatable, QVariant(pCanRotate)); - } -} - -bool UBGraphicsItemDelegate::isFlippable() -{ - return mFlippable; -} - void UBGraphicsItemDelegate::updateFrame() { if (mFrame && !mFrame->scene() && mDelegated->scene()) @@ -805,6 +780,31 @@ void UBGraphicsItemDelegate::setButtonsVisible(bool visible) } } +void UBGraphicsItemDelegate::setUBFlags(UBGraphicsFlags pf) +{ + mFlags = pf; + + Q_ASSERT (mDelegated); + if (!mDelegated) { + return; + } + + if (testUBFlags(GF_FLIPPABLE_ALL_AXIS)) { + mDelegated->setData(UBGraphicsItemData::ItemFlippable, QVariant(testUBFlags(GF_FLIPPABLE_ALL_AXIS))); + } + + if (testUBFlags(GF_REVOLVABLE)) { + mDelegated->setData(UBGraphicsItemData::ItemRotatable, QVariant(testUBFlags(GF_REVOLVABLE))); + } +} + +void UBGraphicsItemDelegate::setUBFlag(UBGraphicsFlags pf, bool set) +{ + UBGraphicsFlags fls = mFlags; + set ? fls |= pf : fls &= ~pf; + + setUBFlags(fls); +} UBGraphicsToolBarItem::UBGraphicsToolBarItem(QGraphicsItem * parent) : QGraphicsRectItem(parent), diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index a183c7a1..7c982ce4 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -174,7 +174,7 @@ class DelegateMediaControl: public QObject, public QGraphicsRectItem void positionHandles(); void updateTicker(qint64 time); void totalTimeChanged(qint64 newTotalTime); - QSizeF lcdAreaSize(){return mLCDTimerArea.size();} + QSizeF lcdAreaSize() {return mLCDTimerArea.size();} signals: void used(); @@ -235,11 +235,10 @@ class UBGraphicsItemDelegate : public QObject Q_OBJECT public: - UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObject * parent = 0, bool respectRatio = true, bool canRotate = false, bool useToolBar = true, bool showGoContentButton = false); + UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObject * parent = 0, UBGraphicsFlags fls = 0); virtual ~UBGraphicsItemDelegate(); - void init(); virtual void createControls(); virtual void freeControls(); virtual void showControls(); @@ -256,13 +255,13 @@ class UBGraphicsItemDelegate : public QObject virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value); virtual UBGraphicsScene *castUBGraphicsScene(); + virtual void postpaint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + void printMessage(const QString &mess) {qDebug() << mess;} QGraphicsItem* delegated(); - void setCanDuplicate(bool allow){ mCanDuplicate = allow; } - virtual void positionHandles(); void setZOrderButtonsVisible(bool visible); @@ -271,18 +270,12 @@ class UBGraphicsItemDelegate : public QObject UBGraphicsDelegateFrame* frame() {return mFrame;} - bool canRotate() const { return mCanRotate; } bool isLocked() const; - bool canDuplicate() { return mCanDuplicate; } QMimeData* mimeData(){ return mMimeData; } void setMimeData(QMimeData* mimeData); void setDragPixmap(const QPixmap &pix) {mDragPixmap = pix;} - void setFlippable(bool flippable); - void setRotatable(bool pCanRotate); - bool isFlippable(); - void setButtonsVisible(bool visible); UBGraphicsToolBarItem* getToolBarItem() const { return mToolBarItem; } @@ -290,6 +283,12 @@ class UBGraphicsItemDelegate : public QObject qreal antiScaleRatio() const { return mAntiScaleRatio; } virtual void update() {positionHandles();} + UBGraphicsFlags ubflags() const {return mFlags;} + bool testUBFlags(UBGraphicsFlags pf) const {return mFlags & pf;} + void setUBFlags(UBGraphicsFlags pf); +// void addUBFlags(UBGraphicsFlags pf) {setUBFlags(ubflags() | pf);} + void setUBFlag(UBGraphicsFlags pf, bool set = true); + signals: void showOnDisplayChanged(bool shown); void lockChanged(bool locked); @@ -314,8 +313,8 @@ class UBGraphicsItemDelegate : public QObject virtual void freeButtons(); virtual void decorateMenu(QMenu *menu); virtual void updateMenuActionState(); - QList buttons() {return mButtons;} + QList buttons() {return mButtons;} QGraphicsItem* mDelegated; //buttons from the top left section of delegate frame @@ -355,19 +354,11 @@ private: QPointF mDragStartPosition; qreal mPreviousZValue; QSizeF mPreviousSize; - bool mCanRotate; - bool mCanDuplicate; - bool mRespectRatio; QMimeData* mMimeData; QPixmap mDragPixmap; - /** A boolean saying that this object can be flippable (mirror effect) */ - bool mFlippable; - bool mToolBarUsed; - - bool mShowGoContentButton; - bool mMoved; + UBGraphicsFlags mFlags; }; diff --git a/src/domain/UBGraphicsItemUndoCommand.cpp b/src/domain/UBGraphicsItemUndoCommand.cpp index 1fb1bd3d..daabe22b 100644 --- a/src/domain/UBGraphicsItemUndoCommand.cpp +++ b/src/domain/UBGraphicsItemUndoCommand.cpp @@ -155,6 +155,7 @@ void UBGraphicsItemUndoCommand::undo() // force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint mScene->update(mScene->sceneRect()); + mScene->updateSelectionFrame(); } diff --git a/src/domain/UBGraphicsMediaItem.cpp b/src/domain/UBGraphicsMediaItem.cpp index be0c7112..bde05df5 100644 --- a/src/domain/UBGraphicsMediaItem.cpp +++ b/src/domain/UBGraphicsMediaItem.cpp @@ -125,7 +125,6 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte setWidget(mAudioWidget); // media widget should be created and placed on proxy widget here. - Delegate()->init(); if (mediaType_Audio == mMediaType) Delegate()->frame()->setOperationMode(UBGraphicsDelegateFrame::ResizingHorizontally); @@ -193,6 +192,11 @@ void UBGraphicsMediaItem::clearSource() qDebug() << "cannot delete file: " << path; } +void UBGraphicsMediaItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + UBGraphicsProxyWidget::paint(painter, option, widget); +} + void UBGraphicsMediaItem::toggleMute() { mMuted = !mMuted; diff --git a/src/domain/UBGraphicsMediaItem.h b/src/domain/UBGraphicsMediaItem.h index b512beb2..aaf0f087 100644 --- a/src/domain/UBGraphicsMediaItem.h +++ b/src/domain/UBGraphicsMediaItem.h @@ -121,6 +121,7 @@ protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void clearSource(); + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); Phonon::MediaObject *mMediaObject; Phonon::VideoWidget *mVideoWidget; diff --git a/src/domain/UBGraphicsMediaItemDelegate.cpp b/src/domain/UBGraphicsMediaItemDelegate.cpp index 4d36e134..7d3a66bd 100644 --- a/src/domain/UBGraphicsMediaItemDelegate.cpp +++ b/src/domain/UBGraphicsMediaItemDelegate.cpp @@ -40,7 +40,10 @@ #include "core/memcheck.h" UBGraphicsMediaItemDelegate::UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent) - : UBGraphicsItemDelegate(pDelegated, parent, true, false, true, true) + : UBGraphicsItemDelegate(pDelegated, parent, GF_COMMON + | GF_RESPECT_RATIO + | GF_TOOLBAR_USED + | GF_SHOW_CONTENT_SOURCE) , mMedia(pMedia) , mToolBarShowTimer(NULL) , m_iToolBarShowingInterval(5000) @@ -64,9 +67,6 @@ UBGraphicsMediaItemDelegate::UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pD if (delegated()->isMuted()) delegated()->setMute(true); - //Wrapper function. Use it to set correct data() to QGraphicsItem as well - setFlippable(false); - setRotatable(false); } bool UBGraphicsMediaItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event) diff --git a/src/domain/UBGraphicsPDFItem.cpp b/src/domain/UBGraphicsPDFItem.cpp index 0acc8abe..bbbe46a5 100644 --- a/src/domain/UBGraphicsPDFItem.cpp +++ b/src/domain/UBGraphicsPDFItem.cpp @@ -37,8 +37,7 @@ UBGraphicsPDFItem::UBGraphicsPDFItem(PDFRenderer *renderer, int pageNumber, QGra setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); //deprecated setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::BackgroundItem)); //Necessary to set if we want z value to be assigned correctly - setDelegate(new UBGraphicsItemDelegate(this,0, true, false, false)); - Delegate()->init(); + setDelegate(new UBGraphicsItemDelegate(this, 0, GF_COMMON)); } @@ -91,6 +90,11 @@ void UBGraphicsPDFItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) GraphicsPDFItem::mouseReleaseEvent(event); } +void UBGraphicsPDFItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + GraphicsPDFItem::paint(painter, option, widget); + Delegate()->postpaint(painter, option, widget); +} UBItem* UBGraphicsPDFItem::deepCopy() const { diff --git a/src/domain/UBGraphicsPDFItem.h b/src/domain/UBGraphicsPDFItem.h index 9a1a42da..8493e3ab 100644 --- a/src/domain/UBGraphicsPDFItem.h +++ b/src/domain/UBGraphicsPDFItem.h @@ -66,6 +66,7 @@ class UBGraphicsPDFItem: public GraphicsPDFItem, public UBItem, public UBGraphic virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); }; diff --git a/src/domain/UBGraphicsPixmapItem.cpp b/src/domain/UBGraphicsPixmapItem.cpp index 69e28e7e..adf96f0b 100644 --- a/src/domain/UBGraphicsPixmapItem.cpp +++ b/src/domain/UBGraphicsPixmapItem.cpp @@ -36,10 +36,12 @@ UBGraphicsPixmapItem::UBGraphicsPixmapItem(QGraphicsItem* parent) : QGraphicsPixmapItem(parent) { - setDelegate(new UBGraphicsItemDelegate(this, 0, true, false, true, true)); - Delegate()->init(); - Delegate()->setFlippable(true); - Delegate()->setRotatable(true); + setDelegate(new UBGraphicsItemDelegate(this, 0, GF_COMMON + | GF_FLIPPABLE_ALL_AXIS + | GF_REVOLVABLE + | GF_RESPECT_RATIO + | GF_TOOLBAR_USED + | GF_SHOW_CONTENT_SOURCE)); setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); setTransformationMode(Qt::SmoothTransformation); @@ -110,9 +112,10 @@ void UBGraphicsPixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsIt { // Never draw the rubber band, we draw our custom selection with the DelegateFrame QStyleOptionGraphicsItem styleOption = QStyleOptionGraphicsItem(*option); - styleOption.state &= ~QStyle::State_Selected; + styleOption.state &= ~QStyle::State_Selected; QGraphicsPixmapItem::paint(painter, &styleOption, widget); + Delegate()->postpaint(painter, option, widget); } diff --git a/src/domain/UBGraphicsProxyWidget.cpp b/src/domain/UBGraphicsProxyWidget.cpp index 250304ea..1defd986 100644 --- a/src/domain/UBGraphicsProxyWidget.cpp +++ b/src/domain/UBGraphicsProxyWidget.cpp @@ -51,6 +51,10 @@ UBGraphicsProxyWidget::~UBGraphicsProxyWidget() { } +void UBGraphicsProxyWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Delegate()->postpaint(painter, option, widget); +} QVariant UBGraphicsProxyWidget::itemChange(GraphicsItemChange change, const QVariant &value) { diff --git a/src/domain/UBGraphicsProxyWidget.h b/src/domain/UBGraphicsProxyWidget.h index 37c13d94..61d75538 100644 --- a/src/domain/UBGraphicsProxyWidget.h +++ b/src/domain/UBGraphicsProxyWidget.h @@ -58,6 +58,7 @@ class UBGraphicsProxyWidget: public QGraphicsProxyWidget, public UBItem, public virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); }; diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 82009210..844a5490 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -318,6 +318,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(updateGroupButtonState())); + connect(UBApplication::undoStack.data(), SIGNAL(indexChanged(int)), this, SLOT(updateSelectionFrameWrapper(int))); } UBGraphicsScene::~UBGraphicsScene() @@ -1078,6 +1079,11 @@ void UBGraphicsScene::updateSelectionFrame() } } +void UBGraphicsScene::updateSelectionFrameWrapper(int) +{ + updateSelectionFrame(); +} + UBGraphicsPolygonItem* UBGraphicsScene::polygonToPolygonItem(const QPolygonF pPolygon) { UBGraphicsPolygonItem *polygonItem = new UBGraphicsPolygonItem(pPolygon); @@ -1736,6 +1742,10 @@ void UBGraphicsScene::deselectAllItems() foreach(QGraphicsItem *gi, selectedItems ()) { gi->setSelected(false); + // Hide selection frame + if (mSelectionFrame) { + mSelectionFrame->setEnclosedItems(QList()); + } } } diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index ef0db5a2..7a8b638d 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -316,6 +316,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem public slots: void updateSelectionFrame(); + void updateSelectionFrameWrapper(int); void initStroke(); void hideEraser(); diff --git a/src/domain/UBGraphicsStrokesGroup.cpp b/src/domain/UBGraphicsStrokesGroup.cpp index 9919e70b..4d114d65 100644 --- a/src/domain/UBGraphicsStrokesGroup.cpp +++ b/src/domain/UBGraphicsStrokesGroup.cpp @@ -30,11 +30,10 @@ UBGraphicsStrokesGroup::UBGraphicsStrokesGroup(QGraphicsItem *parent) :QGraphicsItemGroup(parent), UBGraphicsItem() { - setDelegate(new UBGraphicsItemDelegate(this, 0, true, true, false)); - Delegate()->init(); - Delegate()->setFlippable(true); - Delegate()->setRotatable(true); - + setDelegate(new UBGraphicsItemDelegate(this, 0, GF_COMMON + | GF_RESPECT_RATIO + | GF_REVOLVABLE + | GF_FLIPPABLE_ALL_AXIS)); setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); @@ -186,15 +185,13 @@ void UBGraphicsStrokesGroup::paint(QPainter *painter, const QStyleOptionGraphics if (styleOption.state & QStyle::State_Selected) { selectedState = true; } + QStyle::State svState = option->state; styleOption.state &= ~QStyle::State_Selected; QGraphicsItemGroup::paint(painter, &styleOption, widget); - if (selectedState && !Delegate()->controlsExist()) { - painter->save(); - painter->setPen(Qt::NoPen); - painter->setBrush(QColor(0x88, 0x88, 0x88, 0x77)); - painter->drawRect(boundingRect()); - painter->restore(); - } + //Restoring state + styleOption.state |= svState; + + Delegate()->postpaint(painter, &styleOption, widget); } QVariant UBGraphicsStrokesGroup::itemChange(GraphicsItemChange change, const QVariant &value) diff --git a/src/domain/UBGraphicsSvgItem.cpp b/src/domain/UBGraphicsSvgItem.cpp index 37f123e5..00bcdaae 100644 --- a/src/domain/UBGraphicsSvgItem.cpp +++ b/src/domain/UBGraphicsSvgItem.cpp @@ -61,11 +61,12 @@ void UBGraphicsSvgItem::init() { setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); - setDelegate(new UBGraphicsItemDelegate(this, 0, true, true, false, true)); - Delegate()->init(); - Delegate()->setFlippable(true); - Delegate()->setRotatable(true); - + setDelegate(new UBGraphicsItemDelegate(this, 0, GF_COMMON + | GF_RESPECT_RATIO + | GF_REVOLVABLE + | GF_SHOW_CONTENT_SOURCE)); + UBGraphicsFlags dfl = Delegate()->ubflags(); + Delegate()->setUBFlags(dfl | GF_FLIPPABLE_ALL_AXIS | GF_REVOLVABLE); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); @@ -77,7 +78,6 @@ void UBGraphicsSvgItem::init() setUuid(QUuid::createUuid()); } - UBGraphicsSvgItem::~UBGraphicsSvgItem() { } @@ -139,6 +139,7 @@ void UBGraphicsSvgItem::paint(QPainter *painter, const QStyleOptionGraphicsItem styleOption.state &= ~QStyle::State_Selected; QGraphicsSvgItem::paint(painter, &styleOption, widget); + Delegate()->postpaint(painter, option, widget); } diff --git a/src/domain/UBGraphicsTextItem.cpp b/src/domain/UBGraphicsTextItem.cpp index c4d401b4..b69632c1 100644 --- a/src/domain/UBGraphicsTextItem.cpp +++ b/src/domain/UBGraphicsTextItem.cpp @@ -45,11 +45,10 @@ UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) : , mLastMousePressTime(QTime::currentTime()) { setDelegate(new UBGraphicsTextItemDelegate(this, 0)); - Delegate()->init(); Delegate()->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); - Delegate()->setFlippable(false); - Delegate()->setRotatable(true); + Delegate()->setUBFlag(GF_FLIPPABLE_ALL_AXIS, false); + Delegate()->setUBFlag(GF_REVOLVABLE, true); mTypeTextHereLabel = tr(""); @@ -218,6 +217,8 @@ void UBGraphicsTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem painter->setPen(UBSettings::paletteColor); painter->drawText(boundingRect(), Qt::AlignCenter, mTypeTextHereLabel); } + + Delegate()->postpaint(painter, option, widget); } diff --git a/src/domain/UBGraphicsTextItemDelegate.cpp b/src/domain/UBGraphicsTextItemDelegate.cpp index 17b4dd28..fe76a9cf 100644 --- a/src/domain/UBGraphicsTextItemDelegate.cpp +++ b/src/domain/UBGraphicsTextItemDelegate.cpp @@ -41,8 +41,8 @@ const int UBGraphicsTextItemDelegate::sMinPixelSize = 8; const int UBGraphicsTextItemDelegate::sMinPointSize = 8; -UBGraphicsTextItemDelegate::UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDelegated, QObject * parent) - : UBGraphicsItemDelegate(pDelegated,0, parent, true) +UBGraphicsTextItemDelegate::UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDelegated, QObject *) + : UBGraphicsItemDelegate(pDelegated,0, GF_COMMON | GF_REVOLVABLE) , mLastFontPixelSize(-1) , delta(5) { diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index 2f30d47b..b823f724 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -93,7 +93,6 @@ UBGraphicsWidgetItem::UBGraphicsWidgetItem(const QUrl &pWidgetUrl, QGraphicsItem setPalette(viewPalette); setDelegate(new UBGraphicsWidgetItemDelegate(this)); - Delegate()->init(); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); QGraphicsWebView::setAcceptHoverEvents(true); @@ -587,6 +586,8 @@ void UBGraphicsWidgetItem::paint( QPainter *painter, const QStyleOptionGraphicsI painter->setPen(Qt::white); painter->drawText(rect(), Qt::AlignCenter, message); } + + Delegate()->postpaint(painter, option, widget); } void UBGraphicsWidgetItem::geometryChangeRequested(const QRect& geom) diff --git a/src/domain/UBGraphicsWidgetItemDelegate.cpp b/src/domain/UBGraphicsWidgetItemDelegate.cpp index 840da663..7255303a 100644 --- a/src/domain/UBGraphicsWidgetItemDelegate.cpp +++ b/src/domain/UBGraphicsWidgetItemDelegate.cpp @@ -38,7 +38,9 @@ #include "core/memcheck.h" UBGraphicsWidgetItemDelegate::UBGraphicsWidgetItemDelegate(UBGraphicsWidgetItem* pDelegated, int widgetType) - : UBGraphicsItemDelegate(pDelegated, 0, true, false, false, true) + : UBGraphicsItemDelegate(pDelegated, 0, GF_COMMON + | GF_RESPECT_RATIO + | GF_SHOW_CONTENT_SOURCE) , freezeAction(0) , setAsToolAction(0) { diff --git a/src/domain/UBItem.cpp b/src/domain/UBItem.cpp index ffa3962a..22338ba4 100644 --- a/src/domain/UBItem.cpp +++ b/src/domain/UBItem.cpp @@ -33,6 +33,7 @@ #include "domain/UBGraphicsGroupContainerItem.h" #include "domain/UBGraphicsWidgetItem.h" #include "tools/UBGraphicsCurtainItem.h" +#include "domain/UBGraphicsItemDelegate.h" UBItem::UBItem() : mUuid(QUuid()) @@ -58,6 +59,11 @@ void UBGraphicsItem::setDelegate(UBGraphicsItemDelegate* delegate) mDelegate = delegate; } +UBGraphicsItemDelegate *UBGraphicsItem::Delegate() const +{ + return mDelegate; +} + void UBGraphicsItem::assignZValue(QGraphicsItem *item, qreal value) { item->setZValue(value); diff --git a/src/domain/UBItem.h b/src/domain/UBItem.h index 223091fc..726e2ba6 100644 --- a/src/domain/UBItem.h +++ b/src/domain/UBItem.h @@ -25,8 +25,8 @@ #define UBITEM_H #include -#include "domain/UBGraphicsItemDelegate.h" #include "core/UB.h" +#include "domain/UBGraphicsItemDelegate.h" class UBGraphicsScene; class UBGraphicsItem; @@ -38,7 +38,6 @@ class UBItem UBItem(); public: - virtual ~UBItem(); enum RenderingQuality @@ -95,29 +94,6 @@ class UBItem }; -// Might be fit in int value under most OS -enum UBGraphicsFlag { - GF_NONE = 0x0000 //0000 0000 0000 0000 - ,GF_FLIPPABLE_X_AXIS = 0x0001 //0000 0000 0000 0001 - ,GF_FLIPPABLE_Y_AXIS = 0x0002 //0000 0000 0000 0010 - ,GF_FLIPPABLE_ALL_AXIS = 0x0003 //0000 0000 0000 0011 GF_FLIPPABLE_X_AXIS | GF_FLIPPABLE_Y_AXIS - ,GF_REVOLVABLE = 0x0004 //0000 0000 0000 0100 - ,GF_SCALABLE_X_AXIS = 0x0008 //0000 0000 0000 1000 - ,GF_SCALABLE_Y_AXIS = 0x0010 //0000 0000 0001 0000 - ,GF_SCALABLE_ALL_AXIS = 0x0018 //0000 0000 0001 1000 GF_SCALABLE_X_AXIS | GF_SCALABLE_Y_AXIS - ,GF_DUPLICATION_ENABLED = 0x0020 //0000 0000 0010 0000 - ,GF_MENU_SPECIFIED = 0x0040 //0000 0000 0100 0000 - ,GF_ZORDER_MANIPULATIONS_ALLOWED = 0x0080 //0000 0000 1000 0000 - ,GF_TOOLBAR_USED = 0x0100 //0000 0001 0000 0000 - ,GF_SHOW_CONTENT_SOURCE = 0x0200 //0000 0010 0000 0000 - ,GF_COMMON = 0x00F8 /*0000 0000 1111 1000 GF_FLIPPABLE_ALL_AXIS - |GF_DUPLICATION_ENABLED - |GF_MENU_SPECIFIED - |GF_ZORDER_MANIPULATIONS_ALLOWED */ - ,GF_ALL = 0xFFFF //1111 1111 1111 1111 -}; -Q_DECLARE_FLAGS(UBGraphicsFlags, UBGraphicsFlag) - class UBGraphicsItem { protected: @@ -129,10 +105,9 @@ protected: void setDelegate(UBGraphicsItemDelegate* mDelegate); public: - virtual int type() const = 0; - inline UBGraphicsItemDelegate *Delegate() const { return mDelegate; } + UBGraphicsItemDelegate *Delegate() const; static void assignZValue(QGraphicsItem*, qreal value); static bool isRotatable(QGraphicsItem *item); diff --git a/src/domain/UBSelectionFrame.cpp b/src/domain/UBSelectionFrame.cpp index a0497538..b849fc62 100644 --- a/src/domain/UBSelectionFrame.cpp +++ b/src/domain/UBSelectionFrame.cpp @@ -2,46 +2,29 @@ #include -#include "core/UB.h" #include "domain/UBItem.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" UBSelectionFrame::UBSelectionFrame() : mThickness(UBSettings::settings()->objectFrameWidth) , mAntiscaleRatio(1.0) + , mRotationAngle(0) , mDeleteButton(0) , mDuplicateButton(0) , mZOrderUpButton(0) , mZOrderDownButton(0) + , mRotateButton(0) { setLocalBrush(QBrush(UBSettings::paletteColor)); setPen(Qt::NoPen); setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); 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))); onZoomChanged(UBApplication::boardController->currentZoom()); @@ -90,25 +73,26 @@ void UBSelectionFrame::setEnclosedItems(const QList pGraphicsIte { mButtons.clear(); mButtons.append(mDeleteButton); - mButtons.append(mZOrderUpButton); - mButtons.append(mZOrderDownButton); + mRotationAngle = 0; QRegion resultRegion; + UBGraphicsFlags resultFlags; mEnclosedtems.clear(); foreach (QGraphicsItem *nextItem, pGraphicsItems) { UBGraphicsItemDelegate *nextDelegate = UBGraphicsItem::Delegate(nextItem); if (nextDelegate) { mEnclosedtems.append(nextDelegate); resultRegion |= nextItem->boundingRegion(nextItem->sceneTransform()); + resultFlags |= nextDelegate->ubflags(); } } QRectF resultRect = resultRegion.boundingRect(); setRect(resultRect); + mButtons = buttonsForFlags(resultFlags); placeButtons(); - if (resultRect.isEmpty()) { hide(); } @@ -141,6 +125,12 @@ void UBSelectionFrame::mousePressEvent(QGraphicsSceneMouseEvent *event) mPressedPos = mLastMovedPos = event->pos(); mLastTranslateOffset = QPointF(); + if (scene()->itemAt(event->scenePos()) == mRotateButton) { + mOperationMode = om_rotating; + } else { + mOperationMode = om_moving; + } + // foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) { // qDebug() << "TransformBefore" << curDelegate->delegated()->transform(); // } @@ -154,23 +144,50 @@ void UBSelectionFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) { - QGraphicsItem *item = curDelegate->delegated(); - QTransform ownTransform = item->transform(); - QTransform dTransform( - ownTransform.m11() - , ownTransform.m12() - , ownTransform.m13() + switch (static_cast(mOperationMode)) { + case om_moving : { + 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); + } 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.m22() - , ownTransform.m23() + ownTransform.translate(cntrX, cntrY); + mRotationAngle -= dAngle; + ownTransform.rotate(mRotationAngle); + ownTransform.translate(-cntrX, -cntrY); - , ownTransform.m31() + (dp - mLastTranslateOffset).x() - , ownTransform.m32() + (dp - mLastTranslateOffset).y() - , ownTransform.m33() - ); + item->setTransform(ownTransform); + + qDebug() << "curAngle" << dAngle; + } break; + + } - item->setTransform(dTransform); } updateRect(); @@ -181,6 +198,17 @@ void UBSelectionFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void UBSelectionFrame::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/) { 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) { // qDebug() << "TransformBefore" << curDelegate->delegated()->transform(); // } @@ -202,9 +230,22 @@ void UBSelectionFrame::onZoomChanged(qreal pZoom) void UBSelectionFrame::remove() { + UBApplication::undoStack->beginMacro("RemovingSelected"); foreach (UBGraphicsItemDelegate *d, mEnclosedtems) { d->remove(true); } + UBApplication::undoStack->endMacro(); + + updateRect(); +} + +void UBSelectionFrame::duplicate() +{ + UBApplication::undoStack->beginMacro("RemovingSelected"); + foreach (UBGraphicsItemDelegate *d, mEnclosedtems) { + d->duplicate(); + } + UBApplication::undoStack->endMacro(); updateRect(); } @@ -215,6 +256,10 @@ void UBSelectionFrame::translateItem(QGraphicsItem */*item*/, const QPointF &/*t void UBSelectionFrame::placeButtons() { + if (!mButtons.count()) { + return; + } + QTransform tr; tr.scale(mAntiscaleRatio, mAntiscaleRatio); mDeleteButton->setParentItem(this); @@ -243,6 +288,10 @@ void UBSelectionFrame::placeButtons() button->setParentItem(this); button->setPos(bottomX + (++j * 1.6 * adjThickness()), bottomY); button->setTransform(tr); + } else if (button->getSection() == Qt::NoSection) { + button->setParentItem(this); + placeExceptionButton(button, tr); + k++; } else { ++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() { foreach (DelegateButton *b, mButtons) @@ -261,4 +322,61 @@ void UBSelectionFrame::clearButtons() mButtons.clear(); } +inline UBGraphicsScene *UBSelectionFrame::ubscene() +{ + return qobject_cast(scene()); +} + +QList UBSelectionFrame::buttonsForFlags(UBGraphicsFlags fls) { + + qDebug() << "buttons for flags" << QString::number((int)fls, 2); + QList 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; +} + diff --git a/src/domain/UBSelectionFrame.h b/src/domain/UBSelectionFrame.h index d7d392a8..333ae7cc 100644 --- a/src/domain/UBSelectionFrame.h +++ b/src/domain/UBSelectionFrame.h @@ -3,15 +3,19 @@ #include #include +#include class DelegateButton; class UBGraphicsItemDelegate; +class UBGraphicsScene; class UBSelectionFrame : public QObject, public QGraphicsRectItem { Q_OBJECT public: + enum {om_idle, om_moving, om_rotating} mOperationMode; + UBSelectionFrame(); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); @@ -35,12 +39,18 @@ private slots: void setAntiScaleRatio(qreal pAntiscaleRatio) {mAntiscaleRatio = pAntiscaleRatio;} void onZoomChanged(qreal pZoom); void remove(); + void duplicate(); private: void translateItem(QGraphicsItem *item, const QPointF &translatePoint); void placeButtons(); + void placeExceptionButton(DelegateButton *pButton, QTransform pTransform); void clearButtons(); inline int adjThickness() const {return mThickness * mAntiscaleRatio;} + inline UBGraphicsScene* ubscene(); + + QList buttonsForFlags(UBGraphicsFlags fls); + private: int mThickness; @@ -51,6 +61,7 @@ private: QPointF mPressedPos; QPointF mLastMovedPos; QPointF mLastTranslateOffset; + qreal mRotationAngle; QList mButtons; @@ -58,6 +69,9 @@ private: DelegateButton *mDuplicateButton; DelegateButton *mZOrderUpButton; DelegateButton *mZOrderDownButton; + + DelegateButton *mRotateButton; + }; #endif // UBSELECTIONFRAME_H diff --git a/src/pdf/GraphicsPDFItem.cpp b/src/pdf/GraphicsPDFItem.cpp index b4c71edc..bdfbdde1 100644 --- a/src/pdf/GraphicsPDFItem.cpp +++ b/src/pdf/GraphicsPDFItem.cpp @@ -67,4 +67,5 @@ void GraphicsPDFItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o mRenderer->render(painter, mPageNumber, option->exposedRect); else qWarning("GraphicsPDFItem::paint: option is null, ignoring painting"); + } diff --git a/src/tools/UBGraphicsCurtainItem.cpp b/src/tools/UBGraphicsCurtainItem.cpp index 30f92eee..a7894b88 100644 --- a/src/tools/UBGraphicsCurtainItem.cpp +++ b/src/tools/UBGraphicsCurtainItem.cpp @@ -135,6 +135,7 @@ void UBGraphicsCurtainItem::paint(QPainter *painter, const QStyleOptionGraphicsI styleOption.state &= ~QStyle::State_Selected; painter->fillRect(rect(), color); + Delegate()->postpaint(painter, option, widget); } diff --git a/src/tools/UBGraphicsCurtainItemDelegate.cpp b/src/tools/UBGraphicsCurtainItemDelegate.cpp index 0a3da8d9..700b767b 100644 --- a/src/tools/UBGraphicsCurtainItemDelegate.cpp +++ b/src/tools/UBGraphicsCurtainItemDelegate.cpp @@ -32,9 +32,9 @@ #include "core/memcheck.h" UBGraphicsCurtainItemDelegate::UBGraphicsCurtainItemDelegate(UBGraphicsCurtainItem* pDelegated, QObject * parent) - : UBGraphicsItemDelegate(pDelegated, parent, false, false, false) + : UBGraphicsItemDelegate(pDelegated, parent, GF_SCALABLE_ALL_AXIS | GF_MENU_SPECIFIED | GF_ZORDER_MANIPULATIONS_ALLOWED) { - setCanDuplicate(false); + //NOOP } @@ -45,7 +45,6 @@ UBGraphicsCurtainItemDelegate::~UBGraphicsCurtainItemDelegate() void UBGraphicsCurtainItemDelegate::init() { - UBGraphicsItemDelegate::init(); mFrame->hide(); mZOrderUpButton->hide(); mZOrderDownButton->hide();