QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 Q_OBJECT
39
40#ifdef SIP_RUN
42 if ( dynamic_cast<QgsLayoutViewMouseEvent *>( sipCpp ) )
43 sipType = sipType_QgsLayoutViewMouseEvent;
44 else
45 sipType = 0;
47#endif
48
49 public:
53 QgsLayoutViewRubberBand( QgsLayoutView *view = nullptr );
54
55 ~QgsLayoutViewRubberBand() override = default;
56
61
66 virtual void start( QPointF position, Qt::KeyboardModifiers modifiers ) = 0;
67
72 virtual void update( QPointF position, Qt::KeyboardModifiers modifiers ) = 0;
73
79 virtual QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) = 0;
80
85 QgsLayoutView *view() const;
86
91 QgsLayout *layout() const;
92
98 QBrush brush() const;
99
105 void setBrush( const QBrush &brush );
106
112 QPen pen() const;
113
119 void setPen( const QPen &pen );
120
121 signals:
122
129 void sizeChanged( const QString &size );
130
131 protected:
138 QRectF updateRect( QPointF start, QPointF position, bool constrainSquare, bool fromCenter );
139
140 private:
141 QgsLayoutView *mView = nullptr;
142
143 QBrush mBrush = Qt::NoBrush;
144 QPen mPen = QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 );
145};
146
147
153{
154 Q_OBJECT
155
156 public:
161 QgsLayoutViewRectangularRubberBand *create( QgsLayoutView *view ) const override SIP_FACTORY;
162
164
165 void start( QPointF position, Qt::KeyboardModifiers modifiers ) override;
166 void update( QPointF position, Qt::KeyboardModifiers modifiers ) override;
167 QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) override;
168
169 private:
171 QGraphicsRectItem *mRubberBandItem = nullptr;
172
174 QPointF mRubberBandStartPos;
175};
176
182{
183 Q_OBJECT
184
185 public:
190 QgsLayoutViewEllipticalRubberBand *create( QgsLayoutView *view ) const override SIP_FACTORY;
191
193
194 void start( QPointF position, Qt::KeyboardModifiers modifiers ) override;
195 void update( QPointF position, Qt::KeyboardModifiers modifiers ) override;
196 QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) override;
197
198 private:
200 QGraphicsEllipseItem *mRubberBandItem = nullptr;
201
203 QPointF mRubberBandStartPos;
204};
205
211{
212 Q_OBJECT
213
214 public:
219 QgsLayoutViewTriangleRubberBand *create( QgsLayoutView *view ) const override SIP_FACTORY;
220
222
223 void start( QPointF position, Qt::KeyboardModifiers modifiers ) override;
224 void update( QPointF position, Qt::KeyboardModifiers modifiers ) override;
225 QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) override;
226
227 private:
229 QGraphicsPolygonItem *mRubberBandItem = nullptr;
230
232 QPointF mRubberBandStartPos;
233};
234#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