BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
SizeHandleElement Class Reference

Description

Size handle on top of RectangleView represented as small circle or small rectangle. Placed either in corners on in the middle of the edge.

Definition at line 26 of file SizeHandleElement.h.

Inheritance diagram for SizeHandleElement:
[legend]
Collaboration diagram for SizeHandleElement:
[legend]

Public Types

enum  EHandleLocation {
  NONE , TOPLEFT , TOPMIDDLE , TOPRIGHT ,
  MIDDLELEFT , MIDDLERIGHT , BOTTOMLEFT , BOTTOMMIDLE ,
  BOTTOMRIGHT
}
 
enum  EHandleType { RESIZE , RESIZE_WIDTH , RESIZE_HEIGHT }
 

Public Slots

virtual void update_view ()
 

Signals

void resize_request (bool going_to_resize)
 

Public Member Functions

 SizeHandleElement (EHandleLocation pointType, QGraphicsObject *parent=nullptr)
 
QRectF boundingRect () const override
 
EHandleLocation getHandleLocation () const
 
EHandleType getHandleType () const
 
EHandleLocation getOppositeHandleLocation () const
 
int type () const override
 
void updateHandleElementPosition (const QRectF &rect)
 set position from location type using coordinates of external rectangle More...
 

Protected Member Functions

void mousePressEvent (QGraphicsSceneMouseEvent *event) override
 
void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override
 
void paint (QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
 

Private Attributes

EHandleLocation m_handleLocation
 
EHandleType m_handleType
 

Static Private Attributes

static QMap< EHandleLocation, Qt::CursorShape > m_cursors
 
static QMap< EHandleLocation, EHandleTypem_location_to_type = create_location_to_type_map()
 
static QMap< EHandleLocation, EHandleLocationm_opposite_handle_location = getMapOfOppositeCorners()
 

Member Enumeration Documentation

◆ EHandleLocation

Enumerator
NONE 
TOPLEFT 
TOPMIDDLE 
TOPRIGHT 
MIDDLELEFT 
MIDDLERIGHT 
BOTTOMLEFT 
BOTTOMMIDLE 
BOTTOMRIGHT 

Definition at line 32 of file SizeHandleElement.h.

◆ EHandleType

Enumerator
RESIZE 
RESIZE_WIDTH 
RESIZE_HEIGHT 

Definition at line 44 of file SizeHandleElement.h.

Constructor & Destructor Documentation

◆ SizeHandleElement()

SizeHandleElement::SizeHandleElement ( EHandleLocation  pointType,
QGraphicsObject *  parent = nullptr 
)

Definition at line 80 of file SizeHandleElement.cpp.

81  : QGraphicsObject(parent)
82  , m_handleLocation(pointType)
83  , m_handleType(m_location_to_type[pointType])
84 {
85  setCursor(m_cursors[m_handleLocation]);
86  setParentItem(parent);
87 }
EHandleLocation m_handleLocation
static QMap< EHandleLocation, EHandleType > m_location_to_type
static QMap< EHandleLocation, Qt::CursorShape > m_cursors
EHandleType m_handleType

References m_cursors, and m_handleLocation.

Member Function Documentation

◆ boundingRect()

QRectF SizeHandleElement::boundingRect ( ) const
override

Definition at line 89 of file SizeHandleElement.cpp.

90 {
91  return QRectF(-4, -4, 8, 8);
92 }

Referenced by paint().

◆ getHandleLocation()

SizeHandleElement::EHandleLocation SizeHandleElement::getHandleLocation ( ) const

Definition at line 152 of file SizeHandleElement.cpp.

153 {
154  return m_handleLocation;
155 }

References m_handleLocation.

◆ getHandleType()

SizeHandleElement::EHandleType SizeHandleElement::getHandleType ( ) const

Definition at line 162 of file SizeHandleElement.cpp.

163 {
164  return m_handleType;
165 }

References m_handleType.

Referenced by EllipseView::mouseMoveEvent(), RectangleView::mouseMoveEvent(), and paint().

◆ getOppositeHandleLocation()

SizeHandleElement::EHandleLocation SizeHandleElement::getOppositeHandleLocation ( ) const

Definition at line 157 of file SizeHandleElement.cpp.

158 {
160 }
static QMap< EHandleLocation, EHandleLocation > m_opposite_handle_location

References m_handleLocation, and m_opposite_handle_location.

Referenced by RectangleBaseView::onSizeHandleElementRequest().

◆ mousePressEvent()

void SizeHandleElement::mousePressEvent ( QGraphicsSceneMouseEvent *  event)
overrideprotected

Definition at line 106 of file SizeHandleElement.cpp.

107 {
108  emit resize_request(true);
109  QGraphicsObject::mousePressEvent(event);
110 }
void resize_request(bool going_to_resize)

References resize_request().

◆ mouseReleaseEvent()

void SizeHandleElement::mouseReleaseEvent ( QGraphicsSceneMouseEvent *  event)
overrideprotected

Definition at line 112 of file SizeHandleElement.cpp.

113 {
114  emit resize_request(false);
115  QGraphicsObject::mouseReleaseEvent(event);
116 }

References resize_request().

◆ paint()

void SizeHandleElement::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  ,
QWidget *   
)
overrideprotected

Definition at line 94 of file SizeHandleElement.cpp.

95 {
96  painter->setRenderHints(QPainter::Antialiasing);
97 
98  painter->setBrush(MaskEditorHelper::getSelectionMarkerBrush());
99  painter->setPen(MaskEditorHelper::getSelectionMarkerPen());
100  if (getHandleType() == RESIZE)
101  painter->drawRect(boundingRect());
102  else
103  painter->drawEllipse(boundingRect());
104 }
static QPen getSelectionMarkerPen()
static QBrush getSelectionMarkerBrush()
QRectF boundingRect() const override
EHandleType getHandleType() const

References boundingRect(), getHandleType(), MaskEditorHelper::getSelectionMarkerBrush(), MaskEditorHelper::getSelectionMarkerPen(), and RESIZE.

Here is the call graph for this function:

◆ resize_request

void SizeHandleElement::resize_request ( bool  going_to_resize)
signal

◆ type()

int SizeHandleElement::type ( ) const
inlineoverride

Definition at line 30 of file SizeHandleElement.h.

References MaskEditorHelper::SIZEHANDLE.

◆ update_view

void SizeHandleElement::update_view ( )
virtualslot

Definition at line 167 of file SizeHandleElement.cpp.

168 {
169  update();
170 }

◆ updateHandleElementPosition()

void SizeHandleElement::updateHandleElementPosition ( const QRectF &  rect)

set position from location type using coordinates of external rectangle

Definition at line 119 of file SizeHandleElement.cpp.

120 {
121  if (m_handleLocation == TOPLEFT)
122  setPos(rect.topLeft());
123 
124  else if (m_handleLocation == TOPMIDDLE)
125  setPos(QPointF(rect.x() + rect.width() / 2., rect.y()));
126 
127 
128  else if (m_handleLocation == TOPRIGHT)
129  setPos(rect.topRight());
130 
131 
132  else if (m_handleLocation == MIDDLERIGHT)
133  setPos(QPointF(rect.x() + rect.width(), rect.y() + rect.height() / 2.));
134 
135 
136  else if (m_handleLocation == BOTTOMRIGHT)
137  setPos(rect.bottomRight());
138 
139 
140  else if (m_handleLocation == BOTTOMMIDLE)
141  setPos(QPointF(rect.x() + rect.width() / 2., rect.y() + rect.height()));
142 
143 
144  else if (m_handleLocation == BOTTOMLEFT)
145  setPos(rect.bottomLeft());
146 
147 
148  else if (m_handleLocation == MIDDLELEFT)
149  setPos(QPointF(rect.x(), rect.y() + rect.height() / 2.));
150 }

References BOTTOMLEFT, BOTTOMMIDLE, BOTTOMRIGHT, m_handleLocation, MIDDLELEFT, MIDDLERIGHT, TOPLEFT, TOPMIDDLE, and TOPRIGHT.

Member Data Documentation

◆ m_cursors

QMap< SizeHandleElement::EHandleLocation, Qt::CursorShape > SizeHandleElement::m_cursors
staticprivate
Initial value:
=
create_cursors_map()

Definition at line 70 of file SizeHandleElement.h.

Referenced by SizeHandleElement().

◆ m_handleLocation

EHandleLocation SizeHandleElement::m_handleLocation
private

◆ m_handleType

EHandleType SizeHandleElement::m_handleType
private

Definition at line 69 of file SizeHandleElement.h.

Referenced by getHandleType().

◆ m_location_to_type

QMap< SizeHandleElement::EHandleLocation, SizeHandleElement::EHandleType > SizeHandleElement::m_location_to_type = create_location_to_type_map()
staticprivate

Definition at line 71 of file SizeHandleElement.h.

◆ m_opposite_handle_location

QMap< SizeHandleElement::EHandleLocation, SizeHandleElement::EHandleLocation > SizeHandleElement::m_opposite_handle_location = getMapOfOppositeCorners()
staticprivate

Definition at line 72 of file SizeHandleElement.h.

Referenced by getOppositeHandleLocation().


The documentation for this class was generated from the following files: