widgets/qrubberband.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qbitmap.h" -
43#include "qevent.h" -
44#include "qstylepainter.h" -
45#include "qrubberband.h" -
46#include "qtimer.h" -
47 -
48#ifndef QT_NO_RUBBERBAND -
49 -
50#include "qstyle.h" -
51#include "qstyleoption.h" -
52#ifdef Q_WS_MAC -
53# include <private/qt_mac_p.h> -
54# include <private/qt_cocoa_helpers_mac_p.h> -
55#endif -
56 -
57#include <qdebug.h> -
58 -
59#include <private/qwidget_p.h> -
60 -
61QT_BEGIN_NAMESPACE -
62 -
63//### a rubberband window type would be a more elegant solution -
64#define RUBBERBAND_WINDOW_TYPE Qt::ToolTip -
65 -
66class QRubberBandPrivate : public QWidgetPrivate -
67{ -
68 Q_DECLARE_PUBLIC(QRubberBand) -
69public: -
70 QRect rect; -
71 QRubberBand::Shape shape; -
72 QRegion clipping; -
73 void updateMask(); -
74}; -
75 -
76/*! -
77 Initialize \a option with the values from this QRubberBand. This method -
78 is useful for subclasses when they need a QStyleOptionRubberBand, but don't want -
79 to fill in all the information themselves. -
80 -
81 \sa QStyleOption::initFrom() -
82*/ -
83void QRubberBand::initStyleOption(QStyleOptionRubberBand *option) const -
84{ -
85 if (!option)
partially evaluated: !option
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:44
0-44
86 return;
never executed: return;
0
87 option->initFrom(this);
executed (the execution status of this line is deduced): option->initFrom(this);
-
88 option->shape = d_func()->shape;
executed (the execution status of this line is deduced): option->shape = d_func()->shape;
-
89#ifndef Q_WS_MAC -
90 option->opaque = true;
executed (the execution status of this line is deduced): option->opaque = true;
-
91#else -
92 option->opaque = windowFlags() & RUBBERBAND_WINDOW_TYPE; -
93#endif -
94}
executed: }
Execution Count:44
44
95 -
96/*! -
97 \class QRubberBand -
98 \brief The QRubberBand class provides a rectangle or line that can -
99 indicate a selection or a boundary. -
100 -
101 \inmodule QtWidgets -
102 -
103 A rubber band is often used to show a new bounding area (as in a -
104 QSplitter or a QDockWidget that is undocking). Historically this has -
105 been implemented using a QPainter and XOR, but this approach -
106 doesn't always work properly since rendering can happen in the -
107 window below the rubber band, but before the rubber band has been -
108 "erased". -
109 -
110 You can create a QRubberBand whenever you need to render a rubber band -
111 around a given area (or to represent a single line), then call -
112 setGeometry(), move() or resize() to position and size it. A common -
113 pattern is to do this in conjunction with mouse events. For example: -
114 -
115 \snippet code/src_gui_widgets_qrubberband.cpp 0 -
116 -
117 If you pass a parent to QRubberBand's constructor, the rubber band will -
118 display only inside its parent, but stays on top of other child widgets. -
119 If no parent is passed, QRubberBand will act as a top-level widget. -
120 -
121 Call show() to make the rubber band visible; also when the -
122 rubber band is not a top-level. Hiding or destroying -
123 the widget will make the rubber band disappear. The rubber band -
124 can be a \l Rectangle or a \l Line (vertical or horizontal), -
125 depending on the shape() it was given when constructed. -
126*/ -
127 -
128// ### DOC: How about some nice convenience constructors? -
129//QRubberBand::QRubberBand(QRubberBand::Type t, const QRect &rect, QWidget *p) -
130//QRubberBand::QRubberBand(QRubberBand::Type t, int x, int y, int w, int h, QWidget *p) -
131 -
132/*! -
133 Constructs a rubber band of shape \a s, with parent \a p. -
134 -
135 By default a rectangular rubber band (\a s is \c Rectangle) will -
136 use a mask, so that a small border of the rectangle is all -
137 that is visible. Some styles (e.g., native Mac OS X) will -
138 change this and call QWidget::setWindowOpacity() to make a -
139 semi-transparent filled selection rectangle. -
140*/ -
141QRubberBand::QRubberBand(Shape s, QWidget *p) -
142 : QWidget(*new QRubberBandPrivate, p, (p && p->windowType() != Qt::Desktop) ? Qt::Widget : RUBBERBAND_WINDOW_TYPE) -
143{ -
144 Q_D(QRubberBand);
executed (the execution status of this line is deduced): QRubberBandPrivate * const d = d_func();
-
145 d->shape = s;
executed (the execution status of this line is deduced): d->shape = s;
-
146 setAttribute(Qt::WA_TransparentForMouseEvents);
executed (the execution status of this line is deduced): setAttribute(Qt::WA_TransparentForMouseEvents);
-
147#ifndef Q_WS_WIN -
148 setAttribute(Qt::WA_NoSystemBackground);
executed (the execution status of this line is deduced): setAttribute(Qt::WA_NoSystemBackground);
-
149#endif //Q_WS_WIN -
150 setAttribute(Qt::WA_WState_ExplicitShowHide);
executed (the execution status of this line is deduced): setAttribute(Qt::WA_WState_ExplicitShowHide);
-
151 setVisible(false);
executed (the execution status of this line is deduced): setVisible(false);
-
152#ifdef Q_WS_MAC -
153 if (isWindow()) { -
154 createWinId(); -
155 extern OSWindowRef qt_mac_window_for(const QWidget *); //qwidget_mac.cpp -
156 macWindowSetHasShadow(qt_mac_window_for(this), false); -
157 } -
158#endif -
159}
executed: }
Execution Count:47
47
160 -
161/*! -
162 Destructor. -
163*/ -
164QRubberBand::~QRubberBand() -
165{ -
166} -
167 -
168/*! -
169 \enum QRubberBand::Shape -
170 -
171 This enum specifies what shape a QRubberBand should have. This is -
172 a drawing hint that is passed down to the style system, and can be -
173 interpreted by each QStyle. -
174 -
175 \value Line A QRubberBand can represent a vertical or horizontal -
176 line. Geometry is still given in rect() and the line -
177 will fill the given geometry on most styles. -
178 -
179 \value Rectangle A QRubberBand can represent a rectangle. Some -
180 styles will interpret this as a filled (often -
181 semi-transparent) rectangle, or a rectangular -
182 outline. -
183*/ -
184 -
185/*! -
186 Returns the shape of this rubber band. The shape can only be set -
187 upon construction. -
188*/ -
189QRubberBand::Shape QRubberBand::shape() const -
190{ -
191 Q_D(const QRubberBand);
never executed (the execution status of this line is deduced): const QRubberBandPrivate * const d = d_func();
-
192 return d->shape;
never executed: return d->shape;
0
193} -
194 -
195/*! -
196 \internal -
197*/ -
198void QRubberBandPrivate::updateMask() -
199{ -
200 Q_Q(QRubberBand);
executed (the execution status of this line is deduced): QRubberBand * const q = q_func();
-
201 QStyleHintReturnMask mask;
executed (the execution status of this line is deduced): QStyleHintReturnMask mask;
-
202 QStyleOptionRubberBand opt;
executed (the execution status of this line is deduced): QStyleOptionRubberBand opt;
-
203 q->initStyleOption(&opt);
executed (the execution status of this line is deduced): q->initStyleOption(&opt);
-
204 if (q->style()->styleHint(QStyle::SH_RubberBand_Mask, &opt, q, &mask)) {
partially evaluated: q->style()->styleHint(QStyle::SH_RubberBand_Mask, &opt, q, &mask)
TRUEFALSE
yes
Evaluation Count:44
no
Evaluation Count:0
0-44
205 q->setMask(mask.region);
executed (the execution status of this line is deduced): q->setMask(mask.region);
-
206 } else {
executed: }
Execution Count:44
44
207 q->clearMask();
never executed (the execution status of this line is deduced): q->clearMask();
-
208 }
never executed: }
0
209} -
210 -
211/*! -
212 \reimp -
213*/ -
214void QRubberBand::paintEvent(QPaintEvent *) -
215{ -
216 QStylePainter painter(this);
never executed (the execution status of this line is deduced): QStylePainter painter(this);
-
217 QStyleOptionRubberBand option;
never executed (the execution status of this line is deduced): QStyleOptionRubberBand option;
-
218 initStyleOption(&option);
never executed (the execution status of this line is deduced): initStyleOption(&option);
-
219 painter.drawControl(QStyle::CE_RubberBand, option);
never executed (the execution status of this line is deduced): painter.drawControl(QStyle::CE_RubberBand, option);
-
220}
never executed: }
0
221 -
222/*! -
223 \reimp -
224*/ -
225void QRubberBand::changeEvent(QEvent *e) -
226{ -
227 QWidget::changeEvent(e);
executed (the execution status of this line is deduced): QWidget::changeEvent(e);
-
228 switch (e->type()) { -
229 case QEvent::ParentChange: -
230 if (parent()) {
never evaluated: parent()
0
231 setWindowFlags(windowFlags() & ~RUBBERBAND_WINDOW_TYPE);
never executed (the execution status of this line is deduced): setWindowFlags(windowFlags() & ~Qt::ToolTip);
-
232 } else {
never executed: }
0
233 setWindowFlags(windowFlags() | RUBBERBAND_WINDOW_TYPE);
never executed (the execution status of this line is deduced): setWindowFlags(windowFlags() | Qt::ToolTip);
-
234 }
never executed: }
0
235 break;
never executed: break;
0
236 default: -
237 break;
executed: break;
Execution Count:8
8
238 } -
239 -
240 if (e->type() == QEvent::ZOrderChange)
partially evaluated: e->type() == QEvent::ZOrderChange
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
0-8
241 raise();
never executed: raise();
0
242}
executed: }
Execution Count:8
8
243 -
244/*! -
245 \reimp -
246*/ -
247void QRubberBand::showEvent(QShowEvent *e) -
248{ -
249 raise();
executed (the execution status of this line is deduced): raise();
-
250 e->ignore();
executed (the execution status of this line is deduced): e->ignore();
-
251}
executed: }
Execution Count:2
2
252 -
253/*! -
254 \reimp -
255*/ -
256void QRubberBand::resizeEvent(QResizeEvent *) -
257{ -
258 Q_D(QRubberBand);
executed (the execution status of this line is deduced): QRubberBandPrivate * const d = d_func();
-
259 d->updateMask();
executed (the execution status of this line is deduced): d->updateMask();
-
260}
executed: }
Execution Count:22
22
261 -
262/*! -
263 \reimp -
264*/ -
265void QRubberBand::moveEvent(QMoveEvent *) -
266{ -
267 Q_D(QRubberBand);
executed (the execution status of this line is deduced): QRubberBandPrivate * const d = d_func();
-
268 d->updateMask();
executed (the execution status of this line is deduced): d->updateMask();
-
269}
executed: }
Execution Count:22
22
270 -
271/*! -
272 \fn void QRubberBand::move(const QPoint &p); -
273 -
274 \overload -
275 -
276 Moves the rubberband to point \a p. -
277 -
278 \sa resize() -
279*/ -
280 -
281/*! -
282 \fn void QRubberBand::move(int x, int y); -
283 -
284 Moves the rubberband to point (\a x, \a y). -
285 -
286 \sa resize() -
287*/ -
288 -
289/*! -
290 \fn void QRubberBand::resize(const QSize &size); -
291 -
292 \overload -
293 -
294 Resizes the rubberband so that its new size is \a size. -
295 -
296 \sa move() -
297*/ -
298 -
299/*! -
300 \fn void QRubberBand::resize(int width, int height); -
301 -
302 Resizes the rubberband so that its width is \a width, and its -
303 height is \a height. -
304 -
305 \sa move() -
306*/ -
307 -
308/*! -
309 \fn void QRubberBand::setGeometry(const QRect &rect) -
310 -
311 Sets the geometry of the rubber band to \a rect, specified in the coordinate system -
312 of its parent widget. -
313 -
314 \sa QWidget::geometry -
315*/ -
316void QRubberBand::setGeometry(const QRect &geom) -
317{ -
318 QWidget::setGeometry(geom);
executed (the execution status of this line is deduced): QWidget::setGeometry(geom);
-
319}
executed: }
Execution Count:263
263
320 -
321/*! -
322 \fn void QRubberBand::setGeometry(int x, int y, int width, int height) -
323 \overload -
324 -
325 Sets the geometry of the rubberband to the rectangle whose top-left corner lies at -
326 the point (\a x, \a y), and with dimensions specified by \a width and \a height. -
327 The geometry is specified in the parent widget's coordinate system. -
328*/ -
329 -
330/*! \reimp */ -
331bool QRubberBand::event(QEvent *e) -
332{ -
333 return QWidget::event(e);
executed: return QWidget::event(e);
Execution Count:180
180
334} -
335 -
336QT_END_NAMESPACE -
337 -
338#endif // QT_NO_RUBBERBAND -
339 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial