Remove button implemented

preferencesAboutTextFull
Ilia Ryabokon 12 years ago
parent 0594cfe09f
commit fd4d2201b6
  1. 1
      src/domain/UBGraphicsItemDelegate.h
  2. 116
      src/domain/UBSelectionFrame.cpp
  3. 13
      src/domain/UBSelectionFrame.h

@ -314,6 +314,7 @@ 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;}
QGraphicsItem* mDelegated; QGraphicsItem* mDelegated;

@ -11,11 +11,37 @@
UBSelectionFrame::UBSelectionFrame() UBSelectionFrame::UBSelectionFrame()
: mThickness(UBSettings::settings()->objectFrameWidth) : mThickness(UBSettings::settings()->objectFrameWidth)
, mAntiscaleRatio(1.0) , mAntiscaleRatio(1.0)
, mDeleteButton(0)
, mDuplicateButton(0)
, mZOrderUpButton(0)
, mZOrderDownButton(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)));
} }
@ -61,6 +87,9 @@ QPainterPath UBSelectionFrame::shape() const
void UBSelectionFrame::setEnclosedItems(const QList<QGraphicsItem*> pGraphicsItems) void UBSelectionFrame::setEnclosedItems(const QList<QGraphicsItem*> pGraphicsItems)
{ {
mButtons.clear();
mButtons.append(mDeleteButton);
QRegion resultRegion; QRegion resultRegion;
mEnclosedtems.clear(); mEnclosedtems.clear();
foreach (QGraphicsItem *nextItem, pGraphicsItems) { foreach (QGraphicsItem *nextItem, pGraphicsItems) {
@ -74,6 +103,9 @@ void UBSelectionFrame::setEnclosedItems(const QList<QGraphicsItem*> pGraphicsIte
QRectF resultRect = resultRegion.boundingRect(); QRectF resultRect = resultRegion.boundingRect();
setRect(resultRect); setRect(resultRect);
placeButtons();
if (resultRect.isEmpty()) { if (resultRect.isEmpty()) {
hide(); hide();
} }
@ -89,6 +121,8 @@ void UBSelectionFrame::updateRect()
QRectF result = resultRegion.boundingRect(); QRectF result = resultRegion.boundingRect();
setRect(result); setRect(result);
placeButtons();
if (result.isEmpty()) { if (result.isEmpty()) {
setVisible(false); setVisible(false);
} }
@ -143,7 +177,7 @@ void UBSelectionFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void UBSelectionFrame::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/) void UBSelectionFrame::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/)
{ {
mPressedPos = mLastMovedPos = QPointF(); mPressedPos = mLastMovedPos = mLastTranslateOffset = QPointF();
// foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) { // foreach (UBGraphicsItemDelegate *curDelegate, mEnclosedtems) {
// qDebug() << "TransformBefore" << curDelegate->delegated()->transform(); // qDebug() << "TransformBefore" << curDelegate->delegated()->transform();
// } // }
@ -152,12 +186,86 @@ void UBSelectionFrame::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/)
void UBSelectionFrame::onZoomChanged(qreal pZoom) void UBSelectionFrame::onZoomChanged(qreal pZoom)
{ {
mAntiscaleRatio = pZoom; // mAntiscaleRatio = pZoom;
updateScale(); // updateScale();
}
void UBSelectionFrame::remove()
{
foreach (UBGraphicsItemDelegate *d, mEnclosedtems) {
d->remove(true);
}
updateRect();
} }
void UBSelectionFrame::translateItem(QGraphicsItem */*item*/, const QPointF &/*translatePoint*/) void UBSelectionFrame::translateItem(QGraphicsItem */*item*/, const QPointF &/*translatePoint*/)
{ {
} }
void UBSelectionFrame::placeButtons()
{
QTransform tr;
// tr.scale(mAntiScaleRatio, mAntiScaleRatio);
mDeleteButton->setParentItem(this);
// mDeleteButton->setTransform(tr);
qreal topX = rect().left() - mDeleteButton->renderer()->viewBox().width() /** mAntiScaleRatio*/ * 1.2;
qreal topY = rect().top() - mDeleteButton->renderer()->viewBox().height() /** mAntiScaleRatio*/ * 1.2;
qreal bottomX = rect().left() - mDeleteButton->renderer()->viewBox().width() /** mAntiScaleRatio*/ / 2;
qreal bottomY = rect().bottom() - mDeleteButton->renderer()->viewBox().height() /** mAntiScaleRatio*/ / 2;
mDeleteButton->setPos(topX, topY);
// mDeleteButton->setPos(0, 0);
// if (!mDeleteButton->scene())
// {
// if (scene())
// scene()->addItem(mDeleteButton);
// }
mDeleteButton->show();
// if (showUpdated)
// mDeleteButton->show();
// int i = 1, j = 0, k = 0;
// while ((i + j + k) < mButtons.size()) {
// DelegateButton* button = mButtons[i + j];
// if (button->getSection() == Qt::TopLeftSection) {
// button->setParentItem(mFrame);
// button->setPos(topX + (i++ * 1.6 * mFrameWidth * mAntiScaleRatio), topY);
// button->setTransform(tr);
// } else if (button->getSection() == Qt::BottomLeftSection) {
// button->setParentItem(mFrame);
// button->setPos(bottomX + (++j * 1.6 * mFrameWidth * mAntiScaleRatio), bottomY);
// button->setTransform(tr);
// } else if (button->getSection() == Qt::TitleBarArea || button->getSection() == Qt::NoSection){
// ++k;
// }
// if (!button->scene())
// {
// if (mDelegated->scene())
// mDelegated->scene()->addItem(button);
// }
// if (showUpdated) {
// button->show();
// button->setZValue(delegated()->zValue());
// }
// }
}
void UBSelectionFrame::clearButtons()
{
foreach (DelegateButton *b, mButtons)
{
b->setParentItem(0);
b->hide();
}
mButtons.clear();
}

@ -4,6 +4,7 @@
#include <QGraphicsRectItem> #include <QGraphicsRectItem>
#include <QtGui> #include <QtGui>
class DelegateButton;
class UBGraphicsItemDelegate; class UBGraphicsItemDelegate;
class UBSelectionFrame : public QObject, public QGraphicsRectItem class UBSelectionFrame : public QObject, public QGraphicsRectItem
@ -19,7 +20,7 @@ public:
void setLocalBrush(const QBrush &pBrush) {mLocalBrush = pBrush;} void setLocalBrush(const QBrush &pBrush) {mLocalBrush = pBrush;}
QBrush localBrush() const {return mLocalBrush;} QBrush localBrush() const {return mLocalBrush;}
void setEnclosedItems(const QList<UBGraphicsItemDelegate*> pEncItems) {mEnclosedtems = pEncItems; updateRect();} // void setEnclosedItems(const QList<UBGraphicsItemDelegate*> pEncItems) {mEnclosedtems = pEncItems; updateRect();}
void setEnclosedItems(const QList<QGraphicsItem*> pGraphicsItems); void setEnclosedItems(const QList<QGraphicsItem*> pGraphicsItems);
void updateRect(); void updateRect();
void updateScale(); void updateScale();
@ -33,9 +34,12 @@ protected:
private slots: private slots:
void setAntiScaleRatio(qreal pAntiscaleRatio) {mAntiscaleRatio = pAntiscaleRatio;} void setAntiScaleRatio(qreal pAntiscaleRatio) {mAntiscaleRatio = pAntiscaleRatio;}
void onZoomChanged(qreal pZoom); void onZoomChanged(qreal pZoom);
void remove();
private: private:
void translateItem(QGraphicsItem *item, const QPointF &translatePoint); void translateItem(QGraphicsItem *item, const QPointF &translatePoint);
void placeButtons();
void clearButtons();
private: private:
int mThickness; int mThickness;
@ -46,6 +50,13 @@ private:
QPointF mPressedPos; QPointF mPressedPos;
QPointF mLastMovedPos; QPointF mLastMovedPos;
QPointF mLastTranslateOffset; QPointF mLastTranslateOffset;
QList<DelegateButton*> mButtons;
DelegateButton *mDeleteButton;
DelegateButton *mDuplicateButton;
DelegateButton *mZOrderUpButton;
DelegateButton *mZOrderDownButton;
}; };
#endif // UBSELECTIONFRAME_H #endif // UBSELECTIONFRAME_H

Loading…
Cancel
Save