QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
Loading...
Searching...
No Matches
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
25class QgsLayoutView;
26class QGraphicsRectItem;
27class QGraphicsEllipseItem;
28class QGraphicsPolygonItem;
29class QgsLayout;
30
36class GUI_EXPORT QgsLayoutViewRubberBand : public QObject
37{
38
39 Q_OBJECT
40
41#ifdef SIP_RUN
43 if ( dynamic_cast<QgsLayoutViewMouseEvent *>( sipCpp ) )
44 sipType = sipType_QgsLayoutViewMouseEvent;
45 else
46 sipType = 0;
48#endif
49
50 public:
51
55 QgsLayoutViewRubberBand( QgsLayoutView *view = nullptr );
56
57 ~QgsLayoutViewRubberBand() override = default;
58
63
68 virtual void start( QPointF position, Qt::KeyboardModifiers modifiers ) = 0;
69
74 virtual void update( QPointF position, Qt::KeyboardModifiers modifiers ) = 0;
75
81 virtual QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) = 0;
82
87 QgsLayoutView *view() const;
88
93 QgsLayout *layout() const;
94
100 QBrush brush() const;
101
107 void setBrush( const QBrush &brush );
108
114 QPen pen() const;
115
121 void setPen( const QPen &pen );
122
123 signals:
124
131 void sizeChanged( const QString &size );
132
133 protected:
134
141 QRectF updateRect( QPointF start, QPointF position, bool constrainSquare, bool fromCenter );
142
143 private:
144
145 QgsLayoutView *mView = nullptr;
146
147 QBrush mBrush = Qt::NoBrush;
148 QPen mPen = QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 );
149
150};
151
152
158{
159 Q_OBJECT
160
161 public:
162
167 QgsLayoutViewRectangularRubberBand *create( QgsLayoutView *view ) const override SIP_FACTORY;
168
170
171 void start( QPointF position, Qt::KeyboardModifiers modifiers ) override;
172 void update( QPointF position, Qt::KeyboardModifiers modifiers ) override;
173 QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) override;
174
175 private:
176
178 QGraphicsRectItem *mRubberBandItem = nullptr;
179
181 QPointF mRubberBandStartPos;
182
183};
184
190{
191 Q_OBJECT
192
193 public:
194
199 QgsLayoutViewEllipticalRubberBand *create( QgsLayoutView *view ) const override SIP_FACTORY;
200
202
203 void start( QPointF position, Qt::KeyboardModifiers modifiers ) override;
204 void update( QPointF position, Qt::KeyboardModifiers modifiers ) override;
205 QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) override;
206
207 private:
208
210 QGraphicsEllipseItem *mRubberBandItem = nullptr;
211
213 QPointF mRubberBandStartPos;
214
215};
216
222{
223 Q_OBJECT
224
225 public:
226
231 QgsLayoutViewTriangleRubberBand *create( QgsLayoutView *view ) const override SIP_FACTORY;
232
234
235 void start( QPointF position, Qt::KeyboardModifiers modifiers ) override;
236 void update( QPointF position, Qt::KeyboardModifiers modifiers ) override;
237 QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) override;
238
239 private:
240
242 QGraphicsPolygonItem *mRubberBandItem = nullptr;
243
245 QPointF mRubberBandStartPos;
246
247};
248#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 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 QgsLayoutViewRubberBand * create(QgsLayoutView *view) const =0
Creates a new instance of the QgsLayoutViewRubberBand subclass.
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.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:49
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_END
Definition qgis_sip.h:208