UBGraphicsRuler.h 2.99 KB
Newer Older
Claudio Valerio's avatar
Claudio Valerio committed
1
/*
Claudio Valerio's avatar
Claudio Valerio committed
2 3
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
Claudio Valerio's avatar
Claudio Valerio committed
4
 * the Free Software Foundation, either version 2 of the License, or
Claudio Valerio's avatar
Claudio Valerio committed
5 6 7 8 9 10
 * (at your option) any later version.
 *
 * This program 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.
Claudio Valerio's avatar
Claudio Valerio committed
11
 *
Claudio Valerio's avatar
Claudio Valerio committed
12 13
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Claudio Valerio's avatar
Claudio Valerio committed
14 15 16 17 18 19 20 21 22 23
 */

#ifndef UBGRAPHICSRULER_H_
#define UBGRAPHICSRULER_H_

#include <QtGui>
#include <QtSvg>

#include "core/UB.h"
#include "domain/UBItem.h"
24
#include "tools/UBAbstractDrawRuler.h"
Claudio Valerio's avatar
Claudio Valerio committed
25 26 27

class UBGraphicsScene;

28
class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, public UBItem
Claudio Valerio's avatar
Claudio Valerio committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
{
    Q_OBJECT;

    public:
        UBGraphicsRuler();
        virtual ~UBGraphicsRuler();

        enum { Type = UBGraphicsItemType::RulerItemType };

        virtual int type() const
        {
            return Type;
        }

        virtual UBItem* deepCopy() const;

45 46
		virtual void StartLine(const QPointF& position, qreal width);
		virtual void DrawLine(const QPointF& position, qreal width);
47
        virtual void EndLine();
48

Claudio Valerio's avatar
Claudio Valerio committed
49
    protected:
50
		
Claudio Valerio's avatar
Claudio Valerio committed
51 52 53 54
        virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget);
        virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);

        // Events
55
        virtual void	mousePressEvent(QGraphicsSceneMouseEvent *event);
Claudio Valerio's avatar
Claudio Valerio committed
56
        virtual void    mouseMoveEvent(QGraphicsSceneMouseEvent *event);
57 58 59 60
        virtual void	mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
        virtual void	hoverEnterEvent(QGraphicsSceneHoverEvent *event);
        virtual void	hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
		virtual void    hoverMoveEvent(QGraphicsSceneHoverEvent *event);
Claudio Valerio's avatar
Claudio Valerio committed
61 62

    private:
unknown's avatar
unknown committed
63 64 65 66 67

		bool mResizing;
        bool mRotating;


Claudio Valerio's avatar
Claudio Valerio committed
68
        // Helpers
69 70 71
        void    fillBackground(QPainter *painter);
        void    paintGraduations(QPainter *painter);
        void    paintRotationCenter(QPainter *painter);
unknown's avatar
unknown committed
72
        virtual void    rotateAroundCenter(qreal angle);
Claudio Valerio's avatar
Claudio Valerio committed
73

unknown's avatar
unknown committed
74
		QGraphicsSvgItem* mRotateSvgItem;
75
		QGraphicsSvgItem* mResizeSvgItem;
76

unknown's avatar
unknown committed
77 78 79 80
		void updateResizeCursor();
		QCursor resizeCursor() const{return mResizeCursor;}

        virtual QPointF             rotationCenter() const;
81 82 83 84
        virtual QRectF           resizeButtonRect() const;
        virtual QRectF            closeButtonRect() const;
        virtual QRectF           rotateButtonRect() const;
        virtual UBGraphicsScene*            scene() const;
Claudio Valerio's avatar
Claudio Valerio committed
85

unknown's avatar
unknown committed
86 87
		QCursor mResizeCursor;

88
		int drawLineDirection;
89

Claudio Valerio's avatar
Claudio Valerio committed
90 91
        // Constants
        static const QRect               sDefaultRect;
unknown's avatar
unknown committed
92

93 94
		static const int	sMinLength = 150;   // 3sm
        static const int	sMaxLength = 35000; // 700sm
Claudio Valerio's avatar
Claudio Valerio committed
95 96 97
};

#endif /* UBGRAPHICSRULER_H_ */