QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
63  virtual QgsLayoutViewRubberBand *create( QgsLayoutView *view ) const = 0 SIP_FACTORY;
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 = nullptr ) = 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 
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 = nullptr ) override;
176 
177  private:
178 
180  QGraphicsRectItem *mRubberBandItem = nullptr;
181 
183  QPointF mRubberBandStartPos;
184 
185 };
186 
193 {
194  Q_OBJECT
195 
196  public:
197 
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 = nullptr ) override;
209 
210  private:
211 
213  QGraphicsEllipseItem *mRubberBandItem = nullptr;
214 
216  QPointF mRubberBandStartPos;
217 
218 };
219 
226 {
227  Q_OBJECT
228 
229  public:
230 
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 = nullptr ) override;
242 
243  private:
244 
246  QGraphicsPolygonItem *mRubberBandItem = nullptr;
247 
249  QPointF mRubberBandStartPos;
250 
251 };
252 #endif // QGSLAYOUTVIEWRUBBERBAND_H
A graphical widget to display and interact with QgsLayouts.
Definition: qgslayoutview.h:49
QgsLayoutViewEllipseRubberBand is elliptical rubber band for use within QgsLayoutView widgets...
QgsLayoutViewTriangleRubberBand is triangular rubber band for use within QgsLayoutView widgets...
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...
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 ...
#define SIP_END
Definition: qgis_sip.h:182
#define SIP_FACTORY
Definition: qgis_sip.h:69
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
virtual QgsLayoutViewRubberBand * create(QgsLayoutView *view) const =0
Creates a new instance of the QgsLayoutViewRubberBand subclass.
QgsLayoutViewRectangularRubberBand is rectangular rubber band for use within QgsLayoutView widgets...
QgsLayoutViewRubberBand is an abstract base class for temporary rubber band items in various shapes...
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:165
virtual QRectF finish(QPointF position=QPointF(), Qt::KeyboardModifiers modifiers=nullptr)=0
Called when a rubber band use has finished and the rubber band is no longer required.