RoundRectItem.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package
19 * @author
20 * @date
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#pragma once
25
26#include <QGraphicsObject>
27#include <QLinearGradient>
28#include <QPen>
29
31
32class RoundRectItem : public QGraphicsObject, public armarx::Logging
33{
34 Q_OBJECT
35public:
36 RoundRectItem(const QRectF& bounds, const QColor& color, QGraphicsItem* parent = 0);
37
38 void setColor(QColor newColor);
39 void setRimPen(QPen newPen);
40
41
42 QRectF boundingRect() const override;
43 void setBounds(QRectF newBounds);
44 void setSize(const QSizeF& newSize);
45 void
46 paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0) override;
47
48
49 QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant& value) override;
50 void adjustScale(float& resultScalefactor);
51 virtual QPointF adjustPosition(QPointF& newPos);
52 bool isLevelOfDetailLow(QGraphicsSceneEvent* event) const;
53 void setEditable(bool editable);
54 bool isEditable() const;
55
56private:
57 QLinearGradient fillGradient;
58 bool scalingActive;
59
60 enum
61 {
62 eNone,
63 eTopResizing,
64 eBottomResizing,
65 eLeftResizing,
66 eRightResizing
67 } resizingMode;
68
69 bool setCursor;
70 QColor color;
71 QPen rimPen;
72 bool editable;
73
74 // QGraphicsItem interface
75protected:
76 QRectF bounds;
77
78 void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
79 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
80 void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
81 void hoverMoveEvent(QGraphicsSceneHoverEvent* event) override;
82 void hoverEnterEvent(QGraphicsSceneHoverEvent* event) override;
83 void hoverLeaveEvent(QGraphicsSceneHoverEvent* event) override;
84
85 virtual bool
86 itemResizing(const QRectF& oldSize, QRectF& proposedSize)
87 {
88 return true;
89 }
90
91 virtual void
92 itemResized(const QRectF& oldSize, const QRectF& newSize)
93 {
94 }
95
96 virtual void
97 itemMoved(const QPointF& oldPos, const QPointF& newPos)
98 {
99 }
100
101 virtual void
102 itemBoundingBoxChanged(float oldSize, float size)
103 {
104 }
105
106 void adjustCursor(Qt::CursorShape shape);
107
108
109 QRectF getBottomResizeBB() const;
110 QRectF getTopResizeBB() const;
111 QRectF getLeftResizeBB() const;
112 QRectF getRightResizeBB() const;
113
114 // QGraphicsItem interface
115protected:
116 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
117};
#define option(type, fn)
bool isEditable() const
QRectF getBottomResizeBB() const
void setBounds(QRectF newBounds)
bool isLevelOfDetailLow(QGraphicsSceneEvent *event) const
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
QRectF getRightResizeBB() const
QRectF getLeftResizeBB() const
RoundRectItem(const QRectF &bounds, const QColor &color, QGraphicsItem *parent=0)
void setEditable(bool editable)
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override
QRectF getTopResizeBB() const
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) override
virtual void itemBoundingBoxChanged(float oldSize, float size)
virtual void itemResized(const QRectF &oldSize, const QRectF &newSize)
virtual void itemMoved(const QPointF &oldPos, const QPointF &newPos)
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) override
void setColor(QColor newColor)
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
QRectF boundingRect() const override
virtual QPointF adjustPosition(QPointF &newPos)
void adjustScale(float &resultScalefactor)
void setRimPen(QPen newPen)
void setSize(const QSizeF &newSize)
virtual bool itemResizing(const QRectF &oldSize, QRectF &proposedSize)
void adjustCursor(Qt::CursorShape shape)
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Base Class for all Logging classes.
Definition Logging.h:240