#ifndef ONMONITORRECTITEM_H
#define ONMONITORRECTITEM_H
+
#include <QtCore>
#include <QGraphicsRectItem>
+class QGraphicsView;
+
enum rectActions { Move, ResizeTopLeft, ResizeBottomLeft, ResizeTopRight, ResizeBottomRight, ResizeLeft, ResizeRight, ResizeTop, ResizeBottom, NoAction };
+
class OnMonitorRectItem : public QObject, public QGraphicsRectItem
{
Q_OBJECT
public:
- OnMonitorRectItem(const QRectF &rect, QGraphicsItem *parent = 0);
-
- /** @brief Enables/Disables the ability to modify the item.
- * @param enabled (default = true) */
- void setEnabled(bool enabled = true);
+ OnMonitorRectItem(const QRectF &rect, double dar, QGraphicsItem *parent = 0);
/** @brief Gets The action mode for the area @param pos +- 4.
* e.g. pos(0,0) returns ResizeTopLeft */
- rectActions getMode(QPoint pos);
-
- enum { Type = UserType + 1};
- /** @brief Reimplemented to make sure casting works. */
- int type() const;
+ rectActions getMode(const QPointF &pos);
/** @brief Reimplemented to draw the handles. */
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0 );
-public slots:
- /** @brief Saves current mouse position and mode. */
- void slotMousePressed(QGraphicsSceneMouseEvent *event);
- /** @brief emits actionFinished signal if item was modified. */
- void slotMouseReleased(QGraphicsSceneMouseEvent *event);
- /** @brief Modifies item according to mouse position and mode. */
- void slotMouseMoved(QGraphicsSceneMouseEvent *event);
+protected:
+ void mousePressEvent(QGraphicsSceneMouseEvent *event);
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+ void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
private:
+ double m_dar;
rectActions m_mode;
- QPointF m_clickPoint;
- bool m_enabled;
+ QRectF m_oldRect;
+ QPointF m_lastPoint;
bool m_modified;
+ QGraphicsView *m_view;
+
+ /** @brief Tries to get the view of the scene. */
+ bool getView();
+
signals:
- void actionFinished();
- void setCursor(const QCursor &);
+ void changed();
};
#endif