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 
32 
33 
35  public QGraphicsObject,
36  public armarx::Logging
37 {
38  Q_OBJECT
39 public:
40  RoundRectItem(const QRectF& bounds, const QColor& color,
41  QGraphicsItem* parent = 0);
42 
43  void setColor(QColor newColor);
44  void setRimPen(QPen newPen);
45 
46 
47  QRectF boundingRect() const override;
48  void setBounds(QRectF newBounds);
49  void setSize(const QSizeF& newSize);
50  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0) override;
51 
52 
53 
54  QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant& value) override;
55  void adjustScale(float& resultScalefactor);
56  virtual QPointF adjustPosition(QPointF& newPos);
57  bool isLevelOfDetailLow(QGraphicsSceneEvent* event) const;
58  void setEditable(bool editable);
59  bool isEditable() const;
60 private:
61  QLinearGradient fillGradient;
62  bool scalingActive;
63  enum
64  {
65  eNone,
66  eTopResizing,
67  eBottomResizing,
68  eLeftResizing,
69  eRightResizing
70  } resizingMode;
71  bool setCursor;
72  QColor color;
73  QPen rimPen;
74  bool editable;
75 
76  // QGraphicsItem interface
77 protected:
78  QRectF bounds;
79 
80  void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
81  void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
82  void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
83  void hoverMoveEvent(QGraphicsSceneHoverEvent* event) override;
84  void hoverEnterEvent(QGraphicsSceneHoverEvent* event) override;
85  void hoverLeaveEvent(QGraphicsSceneHoverEvent* event) override;
86  virtual bool itemResizing(const QRectF& oldSize, QRectF& proposedSize)
87  {
88  return true;
89  }
90  virtual void itemResized(const QRectF& oldSize, const QRectF& newSize) {}
91  virtual void itemMoved(const QPointF& oldPos, const QPointF& newPos) {}
92  virtual void itemBoundingBoxChanged(float oldSize, float size) {}
93 
94  void adjustCursor(Qt::CursorShape shape);
95 
96 
97  QRectF getBottomResizeBB() const;
98  QRectF getTopResizeBB() const;
99  QRectF getLeftResizeBB() const;
100  QRectF getRightResizeBB() const;
101 
102  // QGraphicsItem interface
103 protected:
104  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
105 };
106 
107 
RoundRectItem::isLevelOfDetailLow
bool isLevelOfDetailLow(QGraphicsSceneEvent *event) const
Definition: RoundRectItem.cpp:445
RoundRectItem::mouseDoubleClickEvent
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
Definition: RoundRectItem.cpp:523
RoundRectItem::boundingRect
QRectF boundingRect() const override
Definition: RoundRectItem.cpp:78
RoundRectItem::adjustCursor
void adjustCursor(Qt::CursorShape shape)
Definition: RoundRectItem.cpp:301
RoundRectItem::setEditable
void setEditable(bool editable)
Definition: RoundRectItem.cpp:483
RoundRectItem::RoundRectItem
RoundRectItem(const QRectF &bounds, const QColor &color, QGraphicsItem *parent=0)
Definition: RoundRectItem.cpp:36
RoundRectItem::itemChange
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) override
Definition: RoundRectItem.cpp:488
RoundRectItem::hoverMoveEvent
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override
Definition: RoundRectItem.cpp:319
RoundRectItem::setBounds
void setBounds(QRectF newBounds)
Definition: RoundRectItem.cpp:83
RoundRectItem::hoverLeaveEvent
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
Definition: RoundRectItem.cpp:364
RoundRectItem::getLeftResizeBB
QRectF getLeftResizeBB() const
Definition: RoundRectItem.cpp:389
RoundRectItem::itemResized
virtual void itemResized(const QRectF &oldSize, const QRectF &newSize)
Definition: RoundRectItem.h:90
RoundRectItem::setRimPen
void setRimPen(QPen newPen)
Definition: RoundRectItem.cpp:73
RoundRectItem::adjustScale
void adjustScale(float &resultScalefactor)
Definition: RoundRectItem.cpp:404
RoundRectItem::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) override
Definition: RoundRectItem.cpp:110
RoundRectItem::mousePressEvent
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
Definition: RoundRectItem.cpp:138
RoundRectItem::getRightResizeBB
QRectF getRightResizeBB() const
Definition: RoundRectItem.cpp:396
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
RoundRectItem::getTopResizeBB
QRectF getTopResizeBB() const
Definition: RoundRectItem.cpp:382
RoundRectItem::adjustPosition
virtual QPointF adjustPosition(QPointF &newPos)
Definition: RoundRectItem.cpp:425
RoundRectItem::itemMoved
virtual void itemMoved(const QPointF &oldPos, const QPointF &newPos)
Definition: RoundRectItem.h:91
RoundRectItem::setColor
void setColor(QColor newColor)
Definition: RoundRectItem.cpp:63
RoundRectItem::hoverEnterEvent
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override
Definition: RoundRectItem.cpp:359
RoundRectItem::itemBoundingBoxChanged
virtual void itemBoundingBoxChanged(float oldSize, float size)
Definition: RoundRectItem.h:92
RoundRectItem::getBottomResizeBB
QRectF getBottomResizeBB() const
Definition: RoundRectItem.cpp:375
RoundRectItem::mouseMoveEvent
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Definition: RoundRectItem.cpp:217
option
#define option(type, fn)
armarx::Logging
Base Class for all Logging classes.
Definition: Logging.h:232
RoundRectItem
Definition: RoundRectItem.h:34
RoundRectItem::itemResizing
virtual bool itemResizing(const QRectF &oldSize, QRectF &proposedSize)
Definition: RoundRectItem.h:86
RoundRectItem::bounds
QRectF bounds
Definition: RoundRectItem.h:78
RoundRectItem::mouseReleaseEvent
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Definition: RoundRectItem.cpp:203
Logging.h
RoundRectItem::isEditable
bool isEditable() const
Definition: RoundRectItem.cpp:478
RoundRectItem::setSize
void setSize(const QSizeF &newSize)
Definition: RoundRectItem.cpp:96