/*
* Copyright (C) 2013 Open Education Foundation
*
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour
* l'Education Numérique en Afrique (GIP ENA)
*
* This file is part of OpenBoard.
*
* OpenBoard is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* OpenBoard is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenBoard. If not, see .
*/
#ifndef UBSELECTIONFRAME_H
#define UBSELECTIONFRAME_H
#include
#include
#include
#include "domain/UBGraphicsScene.h"
class DelegateButton;
class UBGraphicsItemDelegate;
class UBSelectionFrame : public QObject, public QGraphicsRectItem
{
Q_OBJECT
public:
enum {om_idle, om_moving, om_rotating} mOperationMode;
enum { Type = UBGraphicsItemType::SelectionFrameType };
UBSelectionFrame();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QRectF boundingRect() const;
QPainterPath shape() const;
void setLocalBrush(const QBrush &pBrush) {mLocalBrush = pBrush;}
QBrush localBrush() const {return mLocalBrush;}
// void setEnclosedItems(const QList pEncItems) {mEnclosedtems = pEncItems; updateRect();}
void setEnclosedItems(const QList pGraphicsItems);
void updateRect();
void updateScale();
bool isEmpty() const {return this->rect().isEmpty();}
virtual int type() const {return Type;}
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
private slots:
void setAntiScaleRatio(qreal pAntiscaleRatio) {mAntiscaleRatio = pAntiscaleRatio;}
void onZoomChanged(qreal pZoom);
void remove();
void duplicate();
void increaseZlevelUp();
void increaseZlevelTop();
void increaseZlevelDown();
void increaseZlevelBottom();
private:
void addSelectionUndo(QList items, UBZLayerController::moveDestination dest);
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();
void setCursorFromAngle(QString angle);
QList sortedByZ(const QList &pItems);
QList buttonsForFlags(UBGraphicsFlags fls);
private:
int mThickness;
qreal mAntiscaleRatio;
QList mEnclosedtems;
QBrush mLocalBrush;
QPointF mPressedPos;
QPointF mLastMovedPos;
QPointF mLastTranslateOffset;
qreal mRotationAngle;
QList mButtons;
DelegateButton *mDeleteButton;
DelegateButton *mDuplicateButton;
DelegateButton *mZOrderUpButton;
DelegateButton *mZOrderDownButton;
DelegateButton *mRotateButton;
};
#endif // UBSELECTIONFRAME_H