QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
qgslayoutviewrubberband.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutviewrubberband.h
3  -------------------------
4  Date : July 2017
5  Copyright : (C) 2017 Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSLAYOUTVIEWRUBBERBAND_H
17 #define QGSLAYOUTVIEWRUBBERBAND_H
18 
19 #include "qgis_gui.h"
20 #include "qgis_sip.h"
21 #include <QBrush>
22 #include <QPen>
23 #include <QObject>
24 
25 class QgsLayoutView;
26 class QGraphicsRectItem;
27 class QGraphicsEllipseItem;
28 class QGraphicsPolygonItem;
29 class QgsLayout;
30 
37 class GUI_EXPORT QgsLayoutViewRubberBand : public QObject
38 {
39 
40  Q_OBJECT
41 
42 #ifdef SIP_RUN
44  if ( dynamic_cast<QgsLayoutViewMouseEvent *>( sipCpp ) )
45  sipType = sipType_QgsLayoutViewMouseEvent;
46  else
47  sipType = 0;
48  SIP_END
49 #endif
50 
51  public:
52 
56  QgsLayoutViewRubberBand( QgsLayoutView *view = nullptr );
57 
58  ~QgsLayoutViewRubberBand() override = default;
59 
64 
69  virtual void start( QPointF position, Qt::KeyboardModifiers modifiers ) = 0;
70 
75  virtual void update( QPointF position, Qt::KeyboardModifiers modifiers ) = 0;
76 
82  virtual QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) = 0;
83 
88  QgsLayoutView *view() const;
89 
94  QgsLayout *layout() const;
95 
101  QBrush brush() const;
102 
108  void setBrush( const QBrush &brush );
109 
115  QPen pen() const;
116 
122  void setPen( const QPen &pen );
123 
124  signals:
125 
132  void sizeChanged( const QString &size );
133 
134  protected:
135 
142  QRectF updateRect( QPointF start, QPointF position, bool constrainSquare, bool fromCenter );
143 
144  private:
145 
146  QgsLayoutView *mView = nullptr;
147 
148  QBrush mBrush = Qt::NoBrush;
149  QPen mPen = QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 );
150 
151 };
152 
153 
160 {
161  Q_OBJECT
162 
163  public:
164 
169  QgsLayoutViewRectangularRubberBand *create( QgsLayoutView *view ) const override SIP_FACTORY;
170 
172 
173  void start( QPointF position, Qt::KeyboardModifiers modifiers ) override;
174  void update( QPointF position, Qt::KeyboardModifiers modifiers ) override;
175  QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) override;
176 
177  private:
178 
180  QGraphicsRectItem *mRubberBandItem = nullptr;
181 
183  QPointF mRubberBandStartPos;
184 
185 };
186 
193 {
194  Q_OBJECT
195 
196  public:
197 
202  QgsLayoutViewEllipticalRubberBand *create( QgsLayoutView *view ) const override SIP_FACTORY;
203 
205 
206  void start( QPointF position, Qt::KeyboardModifiers modifiers ) override;
207  void update( QPointF position, Qt::KeyboardModifiers modifiers ) override;
208  QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) override;
209 
210  private:
211 
213  QGraphicsEllipseItem *mRubberBandItem = nullptr;
214 
216  QPointF mRubberBandStartPos;
217 
218 };
219 
226 {
227  Q_OBJECT
228 
229  public:
230 
235  QgsLayoutViewTriangleRubberBand *create( QgsLayoutView *view ) const override SIP_FACTORY;
236 
238 
239  void start( QPointF position, Qt::KeyboardModifiers modifiers ) override;
240  void update( QPointF position, Qt::KeyboardModifiers modifiers ) override;
241  QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) override;
242 
243  private:
244 
246  QGraphicsPolygonItem *mRubberBandItem = nullptr;
247 
249  QPointF mRubberBandStartPos;
250 
251 };
252 #endif // QGSLAYOUTVIEWRUBBERBAND_H
QgsLayoutViewEllipseRubberBand is elliptical rubber band for use within QgsLayoutView widgets.
A QgsLayoutViewMouseEvent is the result of a user interaction with the mouse on a QgsLayoutView.
QgsLayoutViewRectangularRubberBand is rectangular rubber band for use within QgsLayoutView widgets.
QgsLayoutViewRubberBand is an abstract base class for temporary rubber band items in various shapes,...
~QgsLayoutViewRubberBand() override=default
virtual QRectF finish(QPointF position=QPointF(), Qt::KeyboardModifiers modifiers=Qt::KeyboardModifiers())=0
Called when a rubber band use has finished and the rubber band is no longer required.
void sizeChanged(const QString &size)
Emitted when the size of the rubber band is changed.
virtual QgsLayoutViewRubberBand * create(QgsLayoutView *view) const =0
Creates a new instance of the QgsLayoutViewRubberBand subclass.
virtual void start(QPointF position, Qt::KeyboardModifiers modifiers)=0
Called when a rubber band should be created at the specified starting position (in layout coordinate ...
virtual void update(QPointF position, Qt::KeyboardModifiers modifiers)=0
Called when a rubber band should be updated to reflect a temporary ending position (in layout coordin...
QgsLayoutViewTriangleRubberBand is triangular rubber band for use within QgsLayoutView widgets.
A graphical widget to display and interact with QgsLayouts.
Definition: qgslayoutview.h:50
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:50
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_END
Definition: qgis_sip.h:194