UBSelectionFrame.h 3.76 KB
Newer Older
Claudio Valerio's avatar
Claudio Valerio committed
1
/*
Craig Watson's avatar
Craig Watson committed
2 3
 * Copyright (C) 2015-2016 Département de l'Instruction Publique (DIP-SEM)
 *
Claudio Valerio's avatar
Claudio Valerio committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 * 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 <http://www.gnu.org/licenses/>.
 */


Ilia Ryabokon's avatar
Ilia Ryabokon committed
28 29 30 31 32
#ifndef UBSELECTIONFRAME_H
#define UBSELECTIONFRAME_H

#include <QGraphicsRectItem>
#include <QtGui>
33
#include <core/UB.h>
Ilia Ryabokon's avatar
Ilia Ryabokon committed
34

35 36
#include "domain/UBGraphicsScene.h"

37
class DelegateButton;
Ilia Ryabokon's avatar
Ilia Ryabokon committed
38 39 40 41 42 43 44
class UBGraphicsItemDelegate;

class UBSelectionFrame : public QObject, public QGraphicsRectItem
{
    Q_OBJECT

public:
45
    enum {om_idle, om_moving, om_rotating} mOperationMode;
Ilia Ryabokon's avatar
Ilia Ryabokon committed
46
    enum { Type = UBGraphicsItemType::SelectionFrameType };
47

Ilia Ryabokon's avatar
Ilia Ryabokon committed
48 49 50 51 52 53 54 55
    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;}
56
//    void setEnclosedItems(const QList<UBGraphicsItemDelegate*> pEncItems) {mEnclosedtems = pEncItems; updateRect();}
Ilia Ryabokon's avatar
Ilia Ryabokon committed
57 58 59 60
    void setEnclosedItems(const QList<QGraphicsItem*> pGraphicsItems);
    void updateRect();
    void updateScale();
    bool isEmpty() const {return this->rect().isEmpty();}
61
    virtual int type() const {return Type;}
Ilia Ryabokon's avatar
Ilia Ryabokon committed
62

63 64 65 66 67
protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);

Ilia Ryabokon's avatar
Ilia Ryabokon committed
68 69 70
private slots:
    void setAntiScaleRatio(qreal pAntiscaleRatio) {mAntiscaleRatio = pAntiscaleRatio;}
    void onZoomChanged(qreal pZoom);
71
    void remove();
72
    void duplicate();
73 74 75 76
    void increaseZlevelUp();
    void increaseZlevelTop();
    void increaseZlevelDown();
    void increaseZlevelBottom();
77
    void groupItems();
Ilia Ryabokon's avatar
Ilia Ryabokon committed
78

79
private:
80
    void addSelectionUndo(QList<QGraphicsItem*> items, UBZLayerController::moveDestination dest);
81
    void translateItem(QGraphicsItem *item, const QPointF &translatePoint);
82
    void placeButtons();
83
    void placeExceptionButton(DelegateButton *pButton, QTransform pTransform);
84
    void clearButtons();
Ilia Ryabokon's avatar
Ilia Ryabokon committed
85
    inline int adjThickness() const {return mThickness * mAntiscaleRatio;}
86
    inline UBGraphicsScene* ubscene();
Ilia Ryabokon's avatar
Ilia Ryabokon committed
87
    void setCursorFromAngle(QString angle);
88

89
    QList<QGraphicsItem*> sortedByZ(const QList<QGraphicsItem*> &pItems);
90 91
    QList<DelegateButton*> buttonsForFlags(UBGraphicsFlags fls);

92 93
    QList<QGraphicsItem*> enclosedGraphicsItems();

94

Ilia Ryabokon's avatar
Ilia Ryabokon committed
95 96 97 98 99
private:
    int mThickness;
    qreal mAntiscaleRatio;
    QList<UBGraphicsItemDelegate*> mEnclosedtems;
    QBrush mLocalBrush;
100 101 102 103

    QPointF mPressedPos;
    QPointF mLastMovedPos;
    QPointF mLastTranslateOffset;
104
    qreal mRotationAngle;
105

106 107
    bool mIsLocked;

108 109 110 111 112 113
    QList<DelegateButton*> mButtons;

    DelegateButton *mDeleteButton;
    DelegateButton *mDuplicateButton;
    DelegateButton *mZOrderUpButton;
    DelegateButton *mZOrderDownButton;
114
    DelegateButton *mGroupButton;
115 116 117

    DelegateButton *mRotateButton;

Ilia Ryabokon's avatar
Ilia Ryabokon committed
118 119 120
};

#endif // UBSELECTIONFRAME_H