Duplication, paint all the selected items by highlighting them

preferencesAboutTextFull
Ilia Ryabokon 12 years ago
parent 4576b45323
commit 005d30feb9
  1. 1
      src/board/UBBoardView.cpp
  2. 25
      src/core/UB.h
  3. 10
      src/domain/UBGraphicsDelegateFrame.cpp
  4. 14
      src/domain/UBGraphicsGroupContainerItem.cpp
  5. 6
      src/domain/UBGraphicsGroupContainerItemDelegate.cpp
  6. 88
      src/domain/UBGraphicsItemDelegate.cpp
  7. 33
      src/domain/UBGraphicsItemDelegate.h
  8. 1
      src/domain/UBGraphicsItemUndoCommand.cpp
  9. 6
      src/domain/UBGraphicsMediaItem.cpp
  10. 1
      src/domain/UBGraphicsMediaItem.h
  11. 8
      src/domain/UBGraphicsMediaItemDelegate.cpp
  12. 8
      src/domain/UBGraphicsPDFItem.cpp
  13. 1
      src/domain/UBGraphicsPDFItem.h
  14. 13
      src/domain/UBGraphicsPixmapItem.cpp
  15. 4
      src/domain/UBGraphicsProxyWidget.cpp
  16. 1
      src/domain/UBGraphicsProxyWidget.h
  17. 10
      src/domain/UBGraphicsScene.cpp
  18. 1
      src/domain/UBGraphicsScene.h
  19. 21
      src/domain/UBGraphicsStrokesGroup.cpp
  20. 13
      src/domain/UBGraphicsSvgItem.cpp
  21. 7
      src/domain/UBGraphicsTextItem.cpp
  22. 4
      src/domain/UBGraphicsTextItemDelegate.cpp
  23. 3
      src/domain/UBGraphicsWidgetItem.cpp
  24. 4
      src/domain/UBGraphicsWidgetItemDelegate.cpp
  25. 6
      src/domain/UBItem.cpp
  26. 29
      src/domain/UBItem.h
  27. 168
      src/domain/UBSelectionFrame.cpp
  28. 14
      src/domain/UBSelectionFrame.h
  29. 1
      src/pdf/GraphicsPDFItem.cpp
  30. 1
      src/tools/UBGraphicsCurtainItem.cpp
  31. 5
      src/tools/UBGraphicsCurtainItemDelegate.cpp

@ -67,6 +67,7 @@
#include "domain/UBGraphicsSvgItem.h" #include "domain/UBGraphicsSvgItem.h"
#include "domain/UBGraphicsGroupContainerItem.h" #include "domain/UBGraphicsGroupContainerItem.h"
#include "domain/UBGraphicsStrokesGroup.h" #include "domain/UBGraphicsStrokesGroup.h"
#include "domain/UBGraphicsItemDelegate.h"
#include "document/UBDocumentProxy.h" #include "document/UBDocumentProxy.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 struct DocumentSizeRatio
{ {
enum Enum enum Enum

@ -92,7 +92,7 @@ UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelega
mRotateButton = new QGraphicsSvgItem(":/images/rotate.svg", this); mRotateButton = new QGraphicsSvgItem(":/images/rotate.svg", this);
mRotateButton->setCursor(UBResources::resources()->rotateCursor); mRotateButton->setCursor(UBResources::resources()->rotateCursor);
mRotateButton->setVisible(mDelegate->canRotate()); mRotateButton->setVisible(mDelegate->testUBFlags(GF_REVOLVABLE));
updateResizeCursors(); updateResizeCursors();
@ -452,7 +452,7 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
}else if(resizingRight()){ }else if(resizingRight()){
scaleX = (width + moveX) / width; 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){ if((qAbs(width * scaleX)) < 2*mFrameWidth){
bool negative = (scaleX < 0)?true:false; bool negative = (scaleX < 0)?true:false;
if(negative){ if(negative){
@ -482,7 +482,7 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
scaleY = (height + moveY) / height; 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){ if((qAbs(height * scaleY)) < 2*mFrameWidth){
bool negative = (scaleY < 0)?true:false; bool negative = (scaleY < 0)?true:false;
if(negative){ if(negative){
@ -883,7 +883,7 @@ void UBGraphicsDelegateFrame::positionHandles()
mLeftResizeGripSvgItem->setVisible(!isLocked && (bShowHorizontalResizers || bShowAllResizers)); mLeftResizeGripSvgItem->setVisible(!isLocked && (bShowHorizontalResizers || bShowAllResizers));
mRightResizeGripSvgItem->setVisible(!isLocked && (bShowHorizontalResizers || bShowAllResizers)); mRightResizeGripSvgItem->setVisible(!isLocked && (bShowHorizontalResizers || bShowAllResizers));
mTopResizeGripSvgItem->setVisible(!isLocked && (bShowVerticalResizers || bShowAllResizers)); mTopResizeGripSvgItem->setVisible(!isLocked && (bShowVerticalResizers || bShowAllResizers));
mRotateButton->setVisible(mDelegate->canRotate() && !isLocked); mRotateButton->setVisible(mDelegate->testUBFlags(GF_REVOLVABLE) && !isLocked);
mBottomRightResizeGrip->setVisible(!isLocked && bShowAllResizers); mBottomRightResizeGrip->setVisible(!isLocked && bShowAllResizers);
mBottomResizeGrip->setVisible(!isLocked && (bShowVerticalResizers || bShowAllResizers)); mBottomResizeGrip->setVisible(!isLocked && (bShowVerticalResizers || bShowAllResizers));
@ -947,7 +947,7 @@ UBGraphicsDelegateFrame::FrameTool UBGraphicsDelegateFrame::toolFromPos(QPointF
return ResizeTop; return ResizeTop;
} }
} }
else if (rotateButtonBounds().contains(pos) && mDelegate && mDelegate->canRotate()) else if (rotateButtonBounds().contains(pos) && mDelegate && mDelegate->testUBFlags(GF_REVOLVABLE))
return Rotate; return Rotate;
else else
return Move; return Move;

@ -40,7 +40,6 @@ UBGraphicsGroupContainerItem::UBGraphicsGroupContainerItem(QGraphicsItem *parent
setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);
setDelegate(new UBGraphicsGroupContainerItemDelegate(this, 0)); setDelegate(new UBGraphicsGroupContainerItemDelegate(this, 0));
Delegate()->init();
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemIsSelectable, true);
@ -71,14 +70,14 @@ void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item)
//Check if group is allready rotatable or flippable //Check if group is allready rotatable or flippable
if (childItems().count()) { if (childItems().count()) {
if (UBGraphicsItem::isFlippable(this) && !UBGraphicsItem::isFlippable(item)) { if (UBGraphicsItem::isFlippable(this) && !UBGraphicsItem::isFlippable(item)) {
Delegate()->setFlippable(false); Delegate()->setUBFlag(GF_FLIPPABLE_ALL_AXIS, false);
} }
if (UBGraphicsItem::isRotatable(this) && !UBGraphicsItem::isRotatable(item)) { if (UBGraphicsItem::isRotatable(this) && !UBGraphicsItem::isRotatable(item)) {
Delegate()->setRotatable(false); Delegate()->setUBFlag(GF_REVOLVABLE, false);
} }
} else { } else {
Delegate()->setFlippable(UBGraphicsItem::isFlippable(item)); Delegate()->setUBFlag(GF_FLIPPABLE_ALL_AXIS, UBGraphicsItem::isFlippable(item));
Delegate()->setRotatable(UBGraphicsItem::isRotatable(item)); Delegate()->setUBFlag(GF_REVOLVABLE, UBGraphicsItem::isRotatable(item));
} }
// COMBINE // COMBINE
@ -194,6 +193,7 @@ void UBGraphicsGroupContainerItem::paint(QPainter *painter, const QStyleOptionGr
// painter->setPen(tmpPen); // painter->setPen(tmpPen);
// painter->drawRect(itemsBoundingRect.adjusted(tmpPenWidth / 2, tmpPenWidth / 2, -tmpPenWidth / 2, -tmpPenWidth / 2)); // painter->drawRect(itemsBoundingRect.adjusted(tmpPenWidth / 2, tmpPenWidth / 2, -tmpPenWidth / 2, -tmpPenWidth / 2));
// } // }
Delegate()->postpaint(painter, option, widget);
} }
UBCoreGraphicsScene *UBGraphicsGroupContainerItem::corescene() UBCoreGraphicsScene *UBGraphicsGroupContainerItem::corescene()
@ -334,8 +334,8 @@ void UBGraphicsGroupContainerItem::pRemoveFromGroup(QGraphicsItem *item)
break; break;
} }
} }
Delegate()->setFlippable(flippableNow); Delegate()->setUBFlag(GF_FLIPPABLE_ALL_AXIS, flippableNow);
Delegate()->setRotatable(rotatableNow); Delegate()->setUBFlag(GF_REVOLVABLE, rotatableNow);
} }
} }

@ -36,13 +36,9 @@
#include "core/memcheck.h" #include "core/memcheck.h"
UBGraphicsGroupContainerItemDelegate::UBGraphicsGroupContainerItemDelegate(QGraphicsItem *pDelegated, QObject *parent) : 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() UBGraphicsGroupContainerItem *UBGraphicsGroupContainerItemDelegate::delegated()

@ -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) : QObject(parent)
, mDelegated(pDelegated) , mDelegated(pDelegated)
, mDeleteButton(NULL) , mDeleteButton(NULL)
@ -168,31 +168,19 @@ UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObjec
, mFrameWidth(UBSettings::settings()->objectFrameWidth) , mFrameWidth(UBSettings::settings()->objectFrameWidth)
, mAntiScaleRatio(1.0) , mAntiScaleRatio(1.0)
, mToolBarItem(NULL) , mToolBarItem(NULL)
, mCanRotate(canRotate)
, mCanDuplicate(true)
, mRespectRatio(respectRatio)
, mMimeData(NULL) , mMimeData(NULL)
, mFlippable(false)
, mToolBarUsed(useToolBar)
, mShowGoContentButton(showGoContentButton)
{ {
setUBFlags(fls);
connect(UBApplication::boardController, SIGNAL(zoomChanged(qreal)), this, SLOT(onZoomChanged())); 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() void UBGraphicsItemDelegate::createControls()
{ {
if (mToolBarUsed && !mToolBarItem) if (testUBFlags(GF_TOOLBAR_USED) && !mToolBarItem)
mToolBarItem = new UBGraphicsToolBarItem(mDelegated); mToolBarItem = new UBGraphicsToolBarItem(mDelegated);
if (!mFrame) { 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->hide();
mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true); mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true);
} }
@ -201,7 +189,7 @@ void UBGraphicsItemDelegate::createControls()
mDeleteButton = new DelegateButton(":/images/close.svg", mDelegated, mFrame, Qt::TopLeftSection); mDeleteButton = new DelegateButton(":/images/close.svg", mDelegated, mFrame, Qt::TopLeftSection);
mButtons << mDeleteButton; mButtons << mDeleteButton;
connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(remove())); connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(remove()));
if (canDuplicate()){ if (testUBFlags(GF_DUPLICATION_ENABLED)){
mDuplicateButton = new DelegateButton(":/images/duplicate.svg", mDelegated, mFrame, Qt::TopLeftSection); mDuplicateButton = new DelegateButton(":/images/duplicate.svg", mDelegated, mFrame, Qt::TopLeftSection);
connect(mDuplicateButton, SIGNAL(clicked(bool)), this, SLOT(duplicate())); connect(mDuplicateButton, SIGNAL(clicked(bool)), this, SLOT(duplicate()));
mButtons << mDuplicateButton; mButtons << mDuplicateButton;
@ -319,6 +307,19 @@ UBGraphicsScene *UBGraphicsItemDelegate::castUBGraphicsScene()
return castScene; 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) bool UBGraphicsItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
mDragStartPosition = event->pos(); mDragStartPosition = event->pos();
@ -667,7 +668,7 @@ void UBGraphicsItemDelegate::decorateMenu(QMenu* menu)
showIcon.addPixmap(QPixmap(":/images/eyeClosed.svg"), QIcon::Normal, QIcon::Off); showIcon.addPixmap(QPixmap(":/images/eyeClosed.svg"), QIcon::Normal, QIcon::Off);
mShowOnDisplayAction->setIcon(showIcon); mShowOnDisplayAction->setIcon(showIcon);
if (mShowGoContentButton) if (testUBFlags(GF_SHOW_CONTENT_SOURCE))
{ {
mGotoContentSourceAction = menu->addAction(tr("Go to Content Source"), this, SLOT(gotoContentSource())); mGotoContentSourceAction = menu->addAction(tr("Go to Content Source"), this, SLOT(gotoContentSource()));
@ -711,32 +712,6 @@ void UBGraphicsItemDelegate::showMenu()
mMenu->exec(cv->mapToGlobal(pinPos.bottomRight())); 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() void UBGraphicsItemDelegate::updateFrame()
{ {
if (mFrame && !mFrame->scene() && mDelegated->scene()) 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) : UBGraphicsToolBarItem::UBGraphicsToolBarItem(QGraphicsItem * parent) :
QGraphicsRectItem(parent), QGraphicsRectItem(parent),

@ -174,7 +174,7 @@ class DelegateMediaControl: public QObject, public QGraphicsRectItem
void positionHandles(); void positionHandles();
void updateTicker(qint64 time); void updateTicker(qint64 time);
void totalTimeChanged(qint64 newTotalTime); void totalTimeChanged(qint64 newTotalTime);
QSizeF lcdAreaSize(){return mLCDTimerArea.size();} QSizeF lcdAreaSize() {return mLCDTimerArea.size();}
signals: signals:
void used(); void used();
@ -235,11 +235,10 @@ class UBGraphicsItemDelegate : public QObject
Q_OBJECT Q_OBJECT
public: 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(); virtual ~UBGraphicsItemDelegate();
void init();
virtual void createControls(); virtual void createControls();
virtual void freeControls(); virtual void freeControls();
virtual void showControls(); virtual void showControls();
@ -256,13 +255,13 @@ class UBGraphicsItemDelegate : public QObject
virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change, virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change,
const QVariant &value); const QVariant &value);
virtual UBGraphicsScene *castUBGraphicsScene(); virtual UBGraphicsScene *castUBGraphicsScene();
virtual void postpaint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void printMessage(const QString &mess) {qDebug() << mess;} void printMessage(const QString &mess) {qDebug() << mess;}
QGraphicsItem* delegated(); QGraphicsItem* delegated();
void setCanDuplicate(bool allow){ mCanDuplicate = allow; }
virtual void positionHandles(); virtual void positionHandles();
void setZOrderButtonsVisible(bool visible); void setZOrderButtonsVisible(bool visible);
@ -271,18 +270,12 @@ class UBGraphicsItemDelegate : public QObject
UBGraphicsDelegateFrame* frame() {return mFrame;} UBGraphicsDelegateFrame* frame() {return mFrame;}
bool canRotate() const { return mCanRotate; }
bool isLocked() const; bool isLocked() const;
bool canDuplicate() { return mCanDuplicate; }
QMimeData* mimeData(){ return mMimeData; } QMimeData* mimeData(){ return mMimeData; }
void setMimeData(QMimeData* mimeData); void setMimeData(QMimeData* mimeData);
void setDragPixmap(const QPixmap &pix) {mDragPixmap = pix;} void setDragPixmap(const QPixmap &pix) {mDragPixmap = pix;}
void setFlippable(bool flippable);
void setRotatable(bool pCanRotate);
bool isFlippable();
void setButtonsVisible(bool visible); void setButtonsVisible(bool visible);
UBGraphicsToolBarItem* getToolBarItem() const { return mToolBarItem; } UBGraphicsToolBarItem* getToolBarItem() const { return mToolBarItem; }
@ -290,6 +283,12 @@ class UBGraphicsItemDelegate : public QObject
qreal antiScaleRatio() const { return mAntiScaleRatio; } qreal antiScaleRatio() const { return mAntiScaleRatio; }
virtual void update() {positionHandles();} 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: signals:
void showOnDisplayChanged(bool shown); void showOnDisplayChanged(bool shown);
void lockChanged(bool locked); void lockChanged(bool locked);
@ -314,8 +313,8 @@ class UBGraphicsItemDelegate : public QObject
virtual void freeButtons(); virtual void freeButtons();
virtual void decorateMenu(QMenu *menu); virtual void decorateMenu(QMenu *menu);
virtual void updateMenuActionState(); virtual void updateMenuActionState();
QList<DelegateButton*> buttons() {return mButtons;}
QList<DelegateButton*> buttons() {return mButtons;}
QGraphicsItem* mDelegated; QGraphicsItem* mDelegated;
//buttons from the top left section of delegate frame //buttons from the top left section of delegate frame
@ -355,19 +354,11 @@ private:
QPointF mDragStartPosition; QPointF mDragStartPosition;
qreal mPreviousZValue; qreal mPreviousZValue;
QSizeF mPreviousSize; QSizeF mPreviousSize;
bool mCanRotate;
bool mCanDuplicate;
bool mRespectRatio;
QMimeData* mMimeData; QMimeData* mMimeData;
QPixmap mDragPixmap; QPixmap mDragPixmap;
/** A boolean saying that this object can be flippable (mirror effect) */
bool mFlippable;
bool mToolBarUsed;
bool mShowGoContentButton;
bool mMoved; bool mMoved;
UBGraphicsFlags mFlags;
}; };

@ -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 // force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint
mScene->update(mScene->sceneRect()); mScene->update(mScene->sceneRect());
mScene->updateSelectionFrame();
} }

@ -125,7 +125,6 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte
setWidget(mAudioWidget); setWidget(mAudioWidget);
// media widget should be created and placed on proxy widget here. // media widget should be created and placed on proxy widget here.
Delegate()->init();
if (mediaType_Audio == mMediaType) if (mediaType_Audio == mMediaType)
Delegate()->frame()->setOperationMode(UBGraphicsDelegateFrame::ResizingHorizontally); Delegate()->frame()->setOperationMode(UBGraphicsDelegateFrame::ResizingHorizontally);
@ -193,6 +192,11 @@ void UBGraphicsMediaItem::clearSource()
qDebug() << "cannot delete file: " << path; qDebug() << "cannot delete file: " << path;
} }
void UBGraphicsMediaItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
UBGraphicsProxyWidget::paint(painter, option, widget);
}
void UBGraphicsMediaItem::toggleMute() void UBGraphicsMediaItem::toggleMute()
{ {
mMuted = !mMuted; mMuted = !mMuted;

@ -121,6 +121,7 @@ protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void clearSource(); virtual void clearSource();
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
Phonon::MediaObject *mMediaObject; Phonon::MediaObject *mMediaObject;
Phonon::VideoWidget *mVideoWidget; Phonon::VideoWidget *mVideoWidget;

@ -40,7 +40,10 @@
#include "core/memcheck.h" #include "core/memcheck.h"
UBGraphicsMediaItemDelegate::UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent) 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) , mMedia(pMedia)
, mToolBarShowTimer(NULL) , mToolBarShowTimer(NULL)
, m_iToolBarShowingInterval(5000) , m_iToolBarShowingInterval(5000)
@ -64,9 +67,6 @@ UBGraphicsMediaItemDelegate::UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pD
if (delegated()->isMuted()) if (delegated()->isMuted())
delegated()->setMute(true); delegated()->setMute(true);
//Wrapper function. Use it to set correct data() to QGraphicsItem as well
setFlippable(false);
setRotatable(false);
} }
bool UBGraphicsMediaItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event) bool UBGraphicsMediaItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event)

@ -37,8 +37,7 @@ UBGraphicsPDFItem::UBGraphicsPDFItem(PDFRenderer *renderer, int pageNumber, QGra
setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); //deprecated setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); //deprecated
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::BackgroundItem)); //Necessary to set if we want z value to be assigned correctly 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)); setDelegate(new UBGraphicsItemDelegate(this, 0, GF_COMMON));
Delegate()->init();
} }
@ -91,6 +90,11 @@ void UBGraphicsPDFItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
GraphicsPDFItem::mouseReleaseEvent(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 UBItem* UBGraphicsPDFItem::deepCopy() const
{ {

@ -66,6 +66,7 @@ class UBGraphicsPDFItem: public GraphicsPDFItem, public UBItem, public UBGraphic
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(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); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
}; };

@ -36,10 +36,12 @@
UBGraphicsPixmapItem::UBGraphicsPixmapItem(QGraphicsItem* parent) UBGraphicsPixmapItem::UBGraphicsPixmapItem(QGraphicsItem* parent)
: QGraphicsPixmapItem(parent) : QGraphicsPixmapItem(parent)
{ {
setDelegate(new UBGraphicsItemDelegate(this, 0, true, false, true, true)); setDelegate(new UBGraphicsItemDelegate(this, 0, GF_COMMON
Delegate()->init(); | GF_FLIPPABLE_ALL_AXIS
Delegate()->setFlippable(true); | GF_REVOLVABLE
Delegate()->setRotatable(true); | GF_RESPECT_RATIO
| GF_TOOLBAR_USED
| GF_SHOW_CONTENT_SOURCE));
setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);
setTransformationMode(Qt::SmoothTransformation); 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 // Never draw the rubber band, we draw our custom selection with the DelegateFrame
QStyleOptionGraphicsItem styleOption = QStyleOptionGraphicsItem(*option); QStyleOptionGraphicsItem styleOption = QStyleOptionGraphicsItem(*option);
styleOption.state &= ~QStyle::State_Selected;
styleOption.state &= ~QStyle::State_Selected;
QGraphicsPixmapItem::paint(painter, &styleOption, widget); QGraphicsPixmapItem::paint(painter, &styleOption, widget);
Delegate()->postpaint(painter, option, widget);
} }

@ -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) QVariant UBGraphicsProxyWidget::itemChange(GraphicsItemChange change, const QVariant &value)
{ {

@ -58,6 +58,7 @@ class UBGraphicsProxyWidget: public QGraphicsProxyWidget, public UBItem, public
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
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);
}; };

@ -318,6 +318,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoSta
// Just for debug. Do not delete please // Just for debug. Do not delete please
// connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing())); // connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing()));
connect(this, SIGNAL(selectionChanged()), this, SLOT(updateGroupButtonState())); connect(this, SIGNAL(selectionChanged()), this, SLOT(updateGroupButtonState()));
connect(UBApplication::undoStack.data(), SIGNAL(indexChanged(int)), this, SLOT(updateSelectionFrameWrapper(int)));
} }
UBGraphicsScene::~UBGraphicsScene() UBGraphicsScene::~UBGraphicsScene()
@ -1078,6 +1079,11 @@ void UBGraphicsScene::updateSelectionFrame()
} }
} }
void UBGraphicsScene::updateSelectionFrameWrapper(int)
{
updateSelectionFrame();
}
UBGraphicsPolygonItem* UBGraphicsScene::polygonToPolygonItem(const QPolygonF pPolygon) UBGraphicsPolygonItem* UBGraphicsScene::polygonToPolygonItem(const QPolygonF pPolygon)
{ {
UBGraphicsPolygonItem *polygonItem = new UBGraphicsPolygonItem(pPolygon); UBGraphicsPolygonItem *polygonItem = new UBGraphicsPolygonItem(pPolygon);
@ -1736,6 +1742,10 @@ void UBGraphicsScene::deselectAllItems()
foreach(QGraphicsItem *gi, selectedItems ()) foreach(QGraphicsItem *gi, selectedItems ())
{ {
gi->setSelected(false); gi->setSelected(false);
// Hide selection frame
if (mSelectionFrame) {
mSelectionFrame->setEnclosedItems(QList<QGraphicsItem*>());
}
} }
} }

@ -316,6 +316,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
public slots: public slots:
void updateSelectionFrame(); void updateSelectionFrame();
void updateSelectionFrameWrapper(int);
void initStroke(); void initStroke();
void hideEraser(); void hideEraser();

@ -30,11 +30,10 @@
UBGraphicsStrokesGroup::UBGraphicsStrokesGroup(QGraphicsItem *parent) UBGraphicsStrokesGroup::UBGraphicsStrokesGroup(QGraphicsItem *parent)
:QGraphicsItemGroup(parent), UBGraphicsItem() :QGraphicsItemGroup(parent), UBGraphicsItem()
{ {
setDelegate(new UBGraphicsItemDelegate(this, 0, true, true, false)); setDelegate(new UBGraphicsItemDelegate(this, 0, GF_COMMON
Delegate()->init(); | GF_RESPECT_RATIO
Delegate()->setFlippable(true); | GF_REVOLVABLE
Delegate()->setRotatable(true); | GF_FLIPPABLE_ALL_AXIS));
setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);
@ -186,15 +185,13 @@ void UBGraphicsStrokesGroup::paint(QPainter *painter, const QStyleOptionGraphics
if (styleOption.state & QStyle::State_Selected) { if (styleOption.state & QStyle::State_Selected) {
selectedState = true; selectedState = true;
} }
QStyle::State svState = option->state;
styleOption.state &= ~QStyle::State_Selected; styleOption.state &= ~QStyle::State_Selected;
QGraphicsItemGroup::paint(painter, &styleOption, widget); QGraphicsItemGroup::paint(painter, &styleOption, widget);
if (selectedState && !Delegate()->controlsExist()) { //Restoring state
painter->save(); styleOption.state |= svState;
painter->setPen(Qt::NoPen);
painter->setBrush(QColor(0x88, 0x88, 0x88, 0x77)); Delegate()->postpaint(painter, &styleOption, widget);
painter->drawRect(boundingRect());
painter->restore();
}
} }
QVariant UBGraphicsStrokesGroup::itemChange(GraphicsItemChange change, const QVariant &value) QVariant UBGraphicsStrokesGroup::itemChange(GraphicsItemChange change, const QVariant &value)

@ -61,11 +61,12 @@ void UBGraphicsSvgItem::init()
{ {
setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);
setDelegate(new UBGraphicsItemDelegate(this, 0, true, true, false, true)); setDelegate(new UBGraphicsItemDelegate(this, 0, GF_COMMON
Delegate()->init(); | GF_RESPECT_RATIO
Delegate()->setFlippable(true); | GF_REVOLVABLE
Delegate()->setRotatable(true); | GF_SHOW_CONTENT_SOURCE));
UBGraphicsFlags dfl = Delegate()->ubflags();
Delegate()->setUBFlags(dfl | GF_FLIPPABLE_ALL_AXIS | GF_REVOLVABLE);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
@ -77,7 +78,6 @@ void UBGraphicsSvgItem::init()
setUuid(QUuid::createUuid()); setUuid(QUuid::createUuid());
} }
UBGraphicsSvgItem::~UBGraphicsSvgItem() UBGraphicsSvgItem::~UBGraphicsSvgItem()
{ {
} }
@ -139,6 +139,7 @@ void UBGraphicsSvgItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
styleOption.state &= ~QStyle::State_Selected; styleOption.state &= ~QStyle::State_Selected;
QGraphicsSvgItem::paint(painter, &styleOption, widget); QGraphicsSvgItem::paint(painter, &styleOption, widget);
Delegate()->postpaint(painter, option, widget);
} }

@ -45,11 +45,10 @@ UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) :
, mLastMousePressTime(QTime::currentTime()) , mLastMousePressTime(QTime::currentTime())
{ {
setDelegate(new UBGraphicsTextItemDelegate(this, 0)); setDelegate(new UBGraphicsTextItemDelegate(this, 0));
Delegate()->init();
Delegate()->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); Delegate()->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing);
Delegate()->setFlippable(false); Delegate()->setUBFlag(GF_FLIPPABLE_ALL_AXIS, false);
Delegate()->setRotatable(true); Delegate()->setUBFlag(GF_REVOLVABLE, true);
mTypeTextHereLabel = tr("<Type Text Here>"); mTypeTextHereLabel = tr("<Type Text Here>");
@ -218,6 +217,8 @@ void UBGraphicsTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
painter->setPen(UBSettings::paletteColor); painter->setPen(UBSettings::paletteColor);
painter->drawText(boundingRect(), Qt::AlignCenter, mTypeTextHereLabel); painter->drawText(boundingRect(), Qt::AlignCenter, mTypeTextHereLabel);
} }
Delegate()->postpaint(painter, option, widget);
} }

@ -41,8 +41,8 @@
const int UBGraphicsTextItemDelegate::sMinPixelSize = 8; const int UBGraphicsTextItemDelegate::sMinPixelSize = 8;
const int UBGraphicsTextItemDelegate::sMinPointSize = 8; const int UBGraphicsTextItemDelegate::sMinPointSize = 8;
UBGraphicsTextItemDelegate::UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDelegated, QObject * parent) UBGraphicsTextItemDelegate::UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDelegated, QObject *)
: UBGraphicsItemDelegate(pDelegated,0, parent, true) : UBGraphicsItemDelegate(pDelegated,0, GF_COMMON | GF_REVOLVABLE)
, mLastFontPixelSize(-1) , mLastFontPixelSize(-1)
, delta(5) , delta(5)
{ {

@ -93,7 +93,6 @@ UBGraphicsWidgetItem::UBGraphicsWidgetItem(const QUrl &pWidgetUrl, QGraphicsItem
setPalette(viewPalette); setPalette(viewPalette);
setDelegate(new UBGraphicsWidgetItemDelegate(this)); setDelegate(new UBGraphicsWidgetItemDelegate(this));
Delegate()->init();
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
QGraphicsWebView::setAcceptHoverEvents(true); QGraphicsWebView::setAcceptHoverEvents(true);
@ -587,6 +586,8 @@ void UBGraphicsWidgetItem::paint( QPainter *painter, const QStyleOptionGraphicsI
painter->setPen(Qt::white); painter->setPen(Qt::white);
painter->drawText(rect(), Qt::AlignCenter, message); painter->drawText(rect(), Qt::AlignCenter, message);
} }
Delegate()->postpaint(painter, option, widget);
} }
void UBGraphicsWidgetItem::geometryChangeRequested(const QRect& geom) void UBGraphicsWidgetItem::geometryChangeRequested(const QRect& geom)

@ -38,7 +38,9 @@
#include "core/memcheck.h" #include "core/memcheck.h"
UBGraphicsWidgetItemDelegate::UBGraphicsWidgetItemDelegate(UBGraphicsWidgetItem* pDelegated, int widgetType) 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) , freezeAction(0)
, setAsToolAction(0) , setAsToolAction(0)
{ {

@ -33,6 +33,7 @@
#include "domain/UBGraphicsGroupContainerItem.h" #include "domain/UBGraphicsGroupContainerItem.h"
#include "domain/UBGraphicsWidgetItem.h" #include "domain/UBGraphicsWidgetItem.h"
#include "tools/UBGraphicsCurtainItem.h" #include "tools/UBGraphicsCurtainItem.h"
#include "domain/UBGraphicsItemDelegate.h"
UBItem::UBItem() UBItem::UBItem()
: mUuid(QUuid()) : mUuid(QUuid())
@ -58,6 +59,11 @@ void UBGraphicsItem::setDelegate(UBGraphicsItemDelegate* delegate)
mDelegate = delegate; mDelegate = delegate;
} }
UBGraphicsItemDelegate *UBGraphicsItem::Delegate() const
{
return mDelegate;
}
void UBGraphicsItem::assignZValue(QGraphicsItem *item, qreal value) void UBGraphicsItem::assignZValue(QGraphicsItem *item, qreal value)
{ {
item->setZValue(value); item->setZValue(value);

@ -25,8 +25,8 @@
#define UBITEM_H #define UBITEM_H
#include <QtGui> #include <QtGui>
#include "domain/UBGraphicsItemDelegate.h"
#include "core/UB.h" #include "core/UB.h"
#include "domain/UBGraphicsItemDelegate.h"
class UBGraphicsScene; class UBGraphicsScene;
class UBGraphicsItem; class UBGraphicsItem;
@ -38,7 +38,6 @@ class UBItem
UBItem(); UBItem();
public: public:
virtual ~UBItem(); virtual ~UBItem();
enum RenderingQuality 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 class UBGraphicsItem
{ {
protected: protected:
@ -129,10 +105,9 @@ protected:
void setDelegate(UBGraphicsItemDelegate* mDelegate); void setDelegate(UBGraphicsItemDelegate* mDelegate);
public: public:
virtual int type() const = 0; virtual int type() const = 0;
inline UBGraphicsItemDelegate *Delegate() const { return mDelegate; } UBGraphicsItemDelegate *Delegate() const;
static void assignZValue(QGraphicsItem*, qreal value); static void assignZValue(QGraphicsItem*, qreal value);
static bool isRotatable(QGraphicsItem *item); static bool isRotatable(QGraphicsItem *item);

@ -2,46 +2,29 @@
#include <QtGui> #include <QtGui>
#include "core/UB.h"
#include "domain/UBItem.h" #include "domain/UBItem.h"
#include "board/UBBoardController.h" #include "board/UBBoardController.h"
#include "core/UBSettings.h" #include "core/UBSettings.h"
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "gui/UBResources.h"
#include "core/UBApplication.h"
#include "domain/UBGraphicsScene.h"
UBSelectionFrame::UBSelectionFrame() UBSelectionFrame::UBSelectionFrame()
: mThickness(UBSettings::settings()->objectFrameWidth) : mThickness(UBSettings::settings()->objectFrameWidth)
, mAntiscaleRatio(1.0) , mAntiscaleRatio(1.0)
, mRotationAngle(0)
, mDeleteButton(0) , mDeleteButton(0)
, mDuplicateButton(0) , mDuplicateButton(0)
, mZOrderUpButton(0) , mZOrderUpButton(0)
, mZOrderDownButton(0) , mZOrderDownButton(0)
, mRotateButton(0)
{ {
setLocalBrush(QBrush(UBSettings::paletteColor)); setLocalBrush(QBrush(UBSettings::paletteColor));
setPen(Qt::NoPen); setPen(Qt::NoPen);
setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
setFlags(QGraphicsItem::ItemSendsGeometryChanges | QGraphicsItem::ItemIsSelectable | ItemIsMovable); 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))); connect(UBApplication::boardController, SIGNAL(zoomChanged(qreal)), this, SLOT(onZoomChanged(qreal)));
onZoomChanged(UBApplication::boardController->currentZoom()); onZoomChanged(UBApplication::boardController->currentZoom());
@ -90,25 +73,26 @@ void UBSelectionFrame::setEnclosedItems(const QList<QGraphicsItem*> pGraphicsIte
{ {
mButtons.clear(); mButtons.clear();
mButtons.append(mDeleteButton); mButtons.append(mDeleteButton);
mButtons.append(mZOrderUpButton); mRotationAngle = 0;
mButtons.append(mZOrderDownButton);
QRegion resultRegion; QRegion resultRegion;
UBGraphicsFlags resultFlags;
mEnclosedtems.clear(); mEnclosedtems.clear();
foreach (QGraphicsItem *nextItem, pGraphicsItems) { foreach (QGraphicsItem *nextItem, pGraphicsItems) {
UBGraphicsItemDelegate *nextDelegate = UBGraphicsItem::Delegate(nextItem); UBGraphicsItemDelegate *nextDelegate = UBGraphicsItem::Delegate(nextItem);
if (nextDelegate) { if (nextDelegate) {
mEnclosedtems.append(nextDelegate); mEnclosedtems.append(nextDelegate);
resultRegion |= nextItem->boundingRegion(nextItem->sceneTransform()); resultRegion |= nextItem->boundingRegion(nextItem->sceneTransform());
resultFlags |= nextDelegate->ubflags();
} }
} }
QRectF resultRect = resultRegion.boundingRect(); QRectF resultRect = resultRegion.boundingRect();
setRect(resultRect); setRect(resultRect);
mButtons = buttonsForFlags(resultFlags);
placeButtons(); placeButtons();
if (resultRect.isEmpty()) { if (resultRect.isEmpty()) {
hide(); hide();
} }
@ -141,6 +125,12 @@ void UBSelectionFrame::mousePressEvent(QGraphicsSceneMouseEvent *event)
mPressedPos = mLastMovedPos = event->pos(); mPressedPos = mLastMovedPos = event->pos();
mLastTranslateOffset = QPointF(); mLastTranslateOffset = QPointF();
if (scene()->itemAt(event->scenePos()) == mRotateButton) {
mOperationMode = om_rotating;
} else {
mOperationMode = om_moving;
}
// foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) { // foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) {
// qDebug() << "TransformBefore" << curDelegate->delegated()->transform(); // qDebug() << "TransformBefore" << curDelegate->delegated()->transform();
// } // }
@ -154,6 +144,8 @@ void UBSelectionFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) { foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) {
switch (static_cast<int>(mOperationMode)) {
case om_moving : {
QGraphicsItem *item = curDelegate->delegated(); QGraphicsItem *item = curDelegate->delegated();
QTransform ownTransform = item->transform(); QTransform ownTransform = item->transform();
QTransform dTransform( QTransform dTransform(
@ -171,6 +163,31 @@ void UBSelectionFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
); );
item->setTransform(dTransform); 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.translate(cntrX, cntrY);
mRotationAngle -= dAngle;
ownTransform.rotate(mRotationAngle);
ownTransform.translate(-cntrX, -cntrY);
item->setTransform(ownTransform);
qDebug() << "curAngle" << dAngle;
} break;
}
} }
updateRect(); updateRect();
@ -181,6 +198,17 @@ void UBSelectionFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void UBSelectionFrame::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/) void UBSelectionFrame::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/)
{ {
mPressedPos = mLastMovedPos = mLastTranslateOffset = QPointF(); 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) { // foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) {
// qDebug() << "TransformBefore" << curDelegate->delegated()->transform(); // qDebug() << "TransformBefore" << curDelegate->delegated()->transform();
// } // }
@ -202,9 +230,22 @@ void UBSelectionFrame::onZoomChanged(qreal pZoom)
void UBSelectionFrame::remove() void UBSelectionFrame::remove()
{ {
UBApplication::undoStack->beginMacro("RemovingSelected");
foreach (UBGraphicsItemDelegate *d, mEnclosedtems) { foreach (UBGraphicsItemDelegate *d, mEnclosedtems) {
d->remove(true); d->remove(true);
} }
UBApplication::undoStack->endMacro();
updateRect();
}
void UBSelectionFrame::duplicate()
{
UBApplication::undoStack->beginMacro("RemovingSelected");
foreach (UBGraphicsItemDelegate *d, mEnclosedtems) {
d->duplicate();
}
UBApplication::undoStack->endMacro();
updateRect(); updateRect();
} }
@ -215,6 +256,10 @@ void UBSelectionFrame::translateItem(QGraphicsItem */*item*/, const QPointF &/*t
void UBSelectionFrame::placeButtons() void UBSelectionFrame::placeButtons()
{ {
if (!mButtons.count()) {
return;
}
QTransform tr; QTransform tr;
tr.scale(mAntiscaleRatio, mAntiscaleRatio); tr.scale(mAntiscaleRatio, mAntiscaleRatio);
mDeleteButton->setParentItem(this); mDeleteButton->setParentItem(this);
@ -243,6 +288,10 @@ void UBSelectionFrame::placeButtons()
button->setParentItem(this); button->setParentItem(this);
button->setPos(bottomX + (++j * 1.6 * adjThickness()), bottomY); button->setPos(bottomX + (++j * 1.6 * adjThickness()), bottomY);
button->setTransform(tr); button->setTransform(tr);
} else if (button->getSection() == Qt::NoSection) {
button->setParentItem(this);
placeExceptionButton(button, tr);
k++;
} else { } else {
++k; ++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() void UBSelectionFrame::clearButtons()
{ {
foreach (DelegateButton *b, mButtons) foreach (DelegateButton *b, mButtons)
@ -261,4 +322,61 @@ void UBSelectionFrame::clearButtons()
mButtons.clear(); mButtons.clear();
} }
inline UBGraphicsScene *UBSelectionFrame::ubscene()
{
return qobject_cast<UBGraphicsScene*>(scene());
}
QList<DelegateButton*> UBSelectionFrame::buttonsForFlags(UBGraphicsFlags fls) {
qDebug() << "buttons for flags" << QString::number((int)fls, 2);
QList<DelegateButton*> 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;
}

@ -3,15 +3,19 @@
#include <QGraphicsRectItem> #include <QGraphicsRectItem>
#include <QtGui> #include <QtGui>
#include <core/UB.h>
class DelegateButton; class DelegateButton;
class UBGraphicsItemDelegate; class UBGraphicsItemDelegate;
class UBGraphicsScene;
class UBSelectionFrame : public QObject, public QGraphicsRectItem class UBSelectionFrame : public QObject, public QGraphicsRectItem
{ {
Q_OBJECT Q_OBJECT
public: public:
enum {om_idle, om_moving, om_rotating} mOperationMode;
UBSelectionFrame(); UBSelectionFrame();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
@ -35,12 +39,18 @@ private slots:
void setAntiScaleRatio(qreal pAntiscaleRatio) {mAntiscaleRatio = pAntiscaleRatio;} void setAntiScaleRatio(qreal pAntiscaleRatio) {mAntiscaleRatio = pAntiscaleRatio;}
void onZoomChanged(qreal pZoom); void onZoomChanged(qreal pZoom);
void remove(); void remove();
void duplicate();
private: private:
void translateItem(QGraphicsItem *item, const QPointF &translatePoint); void translateItem(QGraphicsItem *item, const QPointF &translatePoint);
void placeButtons(); void placeButtons();
void placeExceptionButton(DelegateButton *pButton, QTransform pTransform);
void clearButtons(); void clearButtons();
inline int adjThickness() const {return mThickness * mAntiscaleRatio;} inline int adjThickness() const {return mThickness * mAntiscaleRatio;}
inline UBGraphicsScene* ubscene();
QList<DelegateButton*> buttonsForFlags(UBGraphicsFlags fls);
private: private:
int mThickness; int mThickness;
@ -51,6 +61,7 @@ private:
QPointF mPressedPos; QPointF mPressedPos;
QPointF mLastMovedPos; QPointF mLastMovedPos;
QPointF mLastTranslateOffset; QPointF mLastTranslateOffset;
qreal mRotationAngle;
QList<DelegateButton*> mButtons; QList<DelegateButton*> mButtons;
@ -58,6 +69,9 @@ private:
DelegateButton *mDuplicateButton; DelegateButton *mDuplicateButton;
DelegateButton *mZOrderUpButton; DelegateButton *mZOrderUpButton;
DelegateButton *mZOrderDownButton; DelegateButton *mZOrderDownButton;
DelegateButton *mRotateButton;
}; };
#endif // UBSELECTIONFRAME_H #endif // UBSELECTIONFRAME_H

@ -67,4 +67,5 @@ void GraphicsPDFItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
mRenderer->render(painter, mPageNumber, option->exposedRect); mRenderer->render(painter, mPageNumber, option->exposedRect);
else else
qWarning("GraphicsPDFItem::paint: option is null, ignoring painting"); qWarning("GraphicsPDFItem::paint: option is null, ignoring painting");
} }

@ -135,6 +135,7 @@ void UBGraphicsCurtainItem::paint(QPainter *painter, const QStyleOptionGraphicsI
styleOption.state &= ~QStyle::State_Selected; styleOption.state &= ~QStyle::State_Selected;
painter->fillRect(rect(), color); painter->fillRect(rect(), color);
Delegate()->postpaint(painter, option, widget);
} }

@ -32,9 +32,9 @@
#include "core/memcheck.h" #include "core/memcheck.h"
UBGraphicsCurtainItemDelegate::UBGraphicsCurtainItemDelegate(UBGraphicsCurtainItem* pDelegated, QObject * parent) 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() void UBGraphicsCurtainItemDelegate::init()
{ {
UBGraphicsItemDelegate::init();
mFrame->hide(); mFrame->hide();
mZOrderUpButton->hide(); mZOrderUpButton->hide();
mZOrderDownButton->hide(); mZOrderDownButton->hide();

Loading…
Cancel
Save