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

Size handle on top of RectangleView represented as small circle or small rectangle. More...

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=0)
 
QRectF boundingRect () const
 
EHandleLocation getHandleLocation () const
 
EHandleType getHandleType () const
 
EHandleLocation getOppositeHandleLocation () const
 
int type () const
 
void updateHandleElementPosition (const QRectF &rect)
 set position from location type using coordinates of external rectangle More...
 

Protected Member Functions

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

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()
 

Detailed 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.

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 = 0 
)

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

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 155 of file SizeHandleElement.cpp.

156 {
157  return m_handleLocation;
158 }

References m_handleLocation.

◆ getHandleType()

SizeHandleElement::EHandleType SizeHandleElement::getHandleType ( ) const

Definition at line 165 of file SizeHandleElement.cpp.

166 {
167  return m_handleType;
168 }

References m_handleType.

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

◆ getOppositeHandleLocation()

SizeHandleElement::EHandleLocation SizeHandleElement::getOppositeHandleLocation ( ) const

Definition at line 160 of file SizeHandleElement.cpp.

161 {
163 }
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)
protected

Definition at line 107 of file SizeHandleElement.cpp.

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

References resize_request().

◆ mouseReleaseEvent()

void SizeHandleElement::mouseReleaseEvent ( QGraphicsSceneMouseEvent *  event)
protected

Definition at line 113 of file SizeHandleElement.cpp.

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

References resize_request().

◆ paint()

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

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  }
105 }
static QPen getSelectionMarkerPen()
static QBrush getSelectionMarkerBrush()
QRectF boundingRect() const
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
inline

Definition at line 30 of file SizeHandleElement.h.

References MaskEditorHelper::SIZEHANDLE.

◆ update_view

void SizeHandleElement::update_view ( )
virtualslot

Definition at line 170 of file SizeHandleElement.cpp.

171 {
172  update();
173 }

◆ updateHandleElementPosition()

void SizeHandleElement::updateHandleElementPosition ( const QRectF &  rect)

set position from location type using coordinates of external rectangle

Definition at line 120 of file SizeHandleElement.cpp.

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

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: