Safe controls allocation

preferencesAboutTextFull
Ilia Ryabokon 11 years ago
parent 741298c0be
commit 2806b13562
  1. 86
      src/domain/UBGraphicsItemDelegate.cpp
  2. 6
      src/domain/UBGraphicsItemDelegate.h

@ -186,36 +186,47 @@ void UBGraphicsItemDelegate::init()
void UBGraphicsItemDelegate::createControls() void UBGraphicsItemDelegate::createControls()
{ {
if (mToolBarUsed) if (mToolBarUsed && !mToolBarItem)
mToolBarItem = new UBGraphicsToolBarItem(mDelegated); mToolBarItem = new UBGraphicsToolBarItem(mDelegated);
mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio); if (!mFrame) {
mFrame->hide(); mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio);
mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true); mFrame->hide();
mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true);
mDeleteButton = new DelegateButton(":/images/close.svg", mDelegated, mFrame, Qt::TopLeftSection); }
mButtons << mDeleteButton;
connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(remove())); if (!mDeleteButton) {
if (canDuplicate()){ mDeleteButton = new DelegateButton(":/images/close.svg", mDelegated, mFrame, Qt::TopLeftSection);
mDuplicateButton = new DelegateButton(":/images/duplicate.svg", mDelegated, mFrame, Qt::TopLeftSection); mButtons << mDeleteButton;
connect(mDuplicateButton, SIGNAL(clicked(bool)), this, SLOT(duplicate())); connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(remove()));
mButtons << mDuplicateButton; if (canDuplicate()){
mDuplicateButton = new DelegateButton(":/images/duplicate.svg", mDelegated, mFrame, Qt::TopLeftSection);
connect(mDuplicateButton, SIGNAL(clicked(bool)), this, SLOT(duplicate()));
mButtons << mDuplicateButton;
}
}
if (!mMenuButton) {
mMenuButton = new DelegateButton(":/images/menu.svg", mDelegated, mFrame, Qt::TopLeftSection);
connect(mMenuButton, SIGNAL(clicked()), this, SLOT(showMenu()));
mButtons << mMenuButton;
}
if (!mZOrderUpButton) {
mZOrderUpButton = new DelegateButton(":/images/z_layer_up.svg", mDelegated, mFrame, Qt::BottomLeftSection);
mZOrderUpButton->setShowProgressIndicator(true);
connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevelUp()));
connect(mZOrderUpButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelTop()));
mButtons << mZOrderUpButton;
}
if (!mZOrderDownButton) {
mZOrderDownButton = new DelegateButton(":/images/z_layer_down.svg", mDelegated, mFrame, Qt::BottomLeftSection);
mZOrderDownButton->setShowProgressIndicator(true);
connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(increaseZLevelDown()));
connect(mZOrderDownButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelBottom()));
mButtons << mZOrderDownButton;
} }
mMenuButton = new DelegateButton(":/images/menu.svg", mDelegated, mFrame, Qt::TopLeftSection);
connect(mMenuButton, SIGNAL(clicked()), this, SLOT(showMenu()));
mButtons << mMenuButton;
mZOrderUpButton = new DelegateButton(":/images/z_layer_up.svg", mDelegated, mFrame, 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", mDelegated, mFrame, Qt::BottomLeftSection);
mZOrderDownButton->setShowProgressIndicator(true);
connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(increaseZLevelDown()));
connect(mZOrderDownButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelBottom()));
mButtons << mZOrderDownButton;
buildButtons(); buildButtons();
@ -242,6 +253,16 @@ void UBGraphicsItemDelegate::freeControls()
freeButtons(); freeButtons();
} }
bool UBGraphicsItemDelegate::controlsExist() const
{
return mFrame
&& mDeleteButton
&& mMenuButton
&& mZOrderUpButton
&& mZOrderDownButton
;
}
UBGraphicsItemDelegate::~UBGraphicsItemDelegate() UBGraphicsItemDelegate::~UBGraphicsItemDelegate()
{ {
@ -255,12 +276,13 @@ UBGraphicsItemDelegate::~UBGraphicsItemDelegate()
QVariant UBGraphicsItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) QVariant UBGraphicsItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{ {
UBGraphicsScene *ubScene = castUBGraphicsScene();
if (change == QGraphicsItem::ItemSelectedHasChanged) { if (change == QGraphicsItem::ItemSelectedHasChanged) {
bool ok; bool ok;
bool selected = value.toUInt(&ok); bool selected = value.toUInt(&ok);
if (ok) { if (ok) {
UBGraphicsScene *ubScene = castUBGraphicsScene();
if (ubScene && !ubScene->multipleSelectionProcess()) { if (ubScene && !ubScene->multipleSelectionProcess()) {
if (selected) { if (selected) {
ubScene->setSelectedZLevel(delegated()); ubScene->setSelectedZLevel(delegated());
@ -271,14 +293,16 @@ QVariant UBGraphicsItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange ch
} }
} }
if ((change == QGraphicsItem::ItemSelectedHasChanged if ((change == QGraphicsItem::ItemSelectedHasChanged
|| change == QGraphicsItem::ItemPositionHasChanged || change == QGraphicsItem::ItemPositionHasChanged
|| change == QGraphicsItem::ItemTransformHasChanged) || change == QGraphicsItem::ItemTransformHasChanged)
&& mDelegated->scene() && ubScene
&& !ubScene->multipleSelectionProcess()
&& UBApplication::boardController) && UBApplication::boardController)
{ {
createControls(); if (!controlsExist()) {
createControls();
}
mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom()); mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom());
positionHandles(); positionHandles();
} }

@ -30,6 +30,7 @@
Scene->removeItem(Object); \ Scene->removeItem(Object); \
} \ } \
delete Object; \ delete Object; \
Object = 0; \
} \ } \
#include <QtGui> #include <QtGui>
@ -228,8 +229,9 @@ class UBGraphicsItemDelegate : public QObject
virtual ~UBGraphicsItemDelegate(); virtual ~UBGraphicsItemDelegate();
void init(); void init();
void createControls(); virtual void createControls();
void freeControls(); virtual void freeControls();
virtual bool controlsExist() const;
virtual bool mousePressEvent(QGraphicsSceneMouseEvent *event); virtual bool mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual bool mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual bool mouseMoveEvent(QGraphicsSceneMouseEvent *event);

Loading…
Cancel
Save