1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QRUBBERBAND_H
5#define QRUBBERBAND_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/qwidget.h>
9
10QT_REQUIRE_CONFIG(rubberband);
11
12QT_BEGIN_NAMESPACE
13
14class QRubberBandPrivate;
15class QStyleOptionRubberBand;
16
17class Q_WIDGETS_EXPORT QRubberBand : public QWidget
18{
19 Q_OBJECT
20
21public:
22 enum Shape { Line, Rectangle };
23 explicit QRubberBand(Shape, QWidget * = nullptr);
24 ~QRubberBand();
25
26 Shape shape() const;
27
28 void setGeometry(const QRect &r);
29
30 inline void setGeometry(int x, int y, int w, int h);
31 inline void move(int x, int y);
32 inline void move(const QPoint &p)
33 { move(x: p.x(), y: p.y()); }
34 inline void resize(int w, int h)
35 { setGeometry(x: geometry().x(), y: geometry().y(), w, h); }
36 inline void resize(const QSize &s)
37 { resize(w: s.width(), h: s.height()); }
38
39protected:
40 bool event(QEvent *e) override;
41 void paintEvent(QPaintEvent *) override;
42 void changeEvent(QEvent *) override;
43 void showEvent(QShowEvent *) override;
44 void resizeEvent(QResizeEvent *) override;
45 void moveEvent(QMoveEvent *) override;
46 virtual void initStyleOption(QStyleOptionRubberBand *option) const;
47
48private:
49 Q_DECLARE_PRIVATE(QRubberBand)
50};
51
52inline void QRubberBand::setGeometry(int ax, int ay, int aw, int ah)
53{ setGeometry(QRect(ax, ay, aw, ah)); }
54inline void QRubberBand::move(int ax, int ay)
55{ setGeometry(ax, ay, aw: width(), ah: height()); }
56
57QT_END_NAMESPACE
58
59#endif // QRUBBERBAND_H
60

source code of qtbase/src/widgets/widgets/qrubberband.h