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 class RoundRectItem : public QGraphicsObject, public armarx::Logging
33 {
34  Q_OBJECT
35 public:
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 
56 private:
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
75 protected:
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
115 protected:
116  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
117 };
RoundRectItem::isLevelOfDetailLow
bool isLevelOfDetailLow(QGraphicsSceneEvent *event) const
Definition: RoundRectItem.cpp:460
RoundRectItem::mouseDoubleClickEvent
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
Definition: RoundRectItem.cpp:542
RoundRectItem::boundingRect
QRectF boundingRect() const override
Definition: RoundRectItem.cpp:80
RoundRectItem::adjustCursor
void adjustCursor(Qt::CursorShape shape)
Definition: RoundRectItem.cpp:304
RoundRectItem::setEditable
void setEditable(bool editable)
Definition: RoundRectItem.cpp:502
RoundRectItem::RoundRectItem
RoundRectItem(const QRectF &bounds, const QColor &color, QGraphicsItem *parent=0)
Definition: RoundRectItem.cpp:38
RoundRectItem::itemChange
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) override
Definition: RoundRectItem.cpp:508
RoundRectItem::hoverMoveEvent
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override
Definition: RoundRectItem.cpp:324
RoundRectItem::setBounds
void setBounds(QRectF newBounds)
Definition: RoundRectItem.cpp:86
RoundRectItem::hoverLeaveEvent
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
Definition: RoundRectItem.cpp:370
RoundRectItem::getLeftResizeBB
QRectF getLeftResizeBB() const
Definition: RoundRectItem.cpp:398
RoundRectItem::itemResized
virtual void itemResized(const QRectF &oldSize, const QRectF &newSize)
Definition: RoundRectItem.h:92
RoundRectItem::setRimPen
void setRimPen(QPen newPen)
Definition: RoundRectItem.cpp:74
RoundRectItem::adjustScale
void adjustScale(float &resultScalefactor)
Definition: RoundRectItem.cpp:414
RoundRectItem::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) override
Definition: RoundRectItem.cpp:115
RoundRectItem::mousePressEvent
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
Definition: RoundRectItem.cpp:142
RoundRectItem::getRightResizeBB
QRectF getRightResizeBB() const
Definition: RoundRectItem.cpp:406
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
RoundRectItem::getTopResizeBB
QRectF getTopResizeBB() const
Definition: RoundRectItem.cpp:390
RoundRectItem::adjustPosition
virtual QPointF adjustPosition(QPointF &newPos)
Definition: RoundRectItem.cpp:437
RoundRectItem::itemMoved
virtual void itemMoved(const QPointF &oldPos, const QPointF &newPos)
Definition: RoundRectItem.h:97
RoundRectItem::setColor
void setColor(QColor newColor)
Definition: RoundRectItem.cpp:63
RoundRectItem::hoverEnterEvent
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override
Definition: RoundRectItem.cpp:365
RoundRectItem::itemBoundingBoxChanged
virtual void itemBoundingBoxChanged(float oldSize, float size)
Definition: RoundRectItem.h:102
RoundRectItem::getBottomResizeBB
QRectF getBottomResizeBB() const
Definition: RoundRectItem.cpp:382
RoundRectItem::mouseMoveEvent
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Definition: RoundRectItem.cpp:220
option
#define option(type, fn)
armarx::Logging
Base Class for all Logging classes.
Definition: Logging.h:239
RoundRectItem
Definition: RoundRectItem.h:32
RoundRectItem::itemResizing
virtual bool itemResizing(const QRectF &oldSize, QRectF &proposedSize)
Definition: RoundRectItem.h:86
RoundRectItem::bounds
QRectF bounds
Definition: RoundRectItem.h:76
RoundRectItem::mouseReleaseEvent
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Definition: RoundRectItem.cpp:205
Logging.h
RoundRectItem::isEditable
bool isEditable() const
Definition: RoundRectItem.cpp:496
RoundRectItem::setSize
void setSize(const QSizeF &newSize)
Definition: RoundRectItem.cpp:100