Qt 4.8
qrubberband.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 
62 
63 //### a rubberband window type would be a more elegant solution
64 #define RUBBERBAND_WINDOW_TYPE Qt::ToolTip
65 
67 {
69 public:
73  void updateMask();
74 };
75 
84 {
85  if (!option)
86  return;
87  option->initFrom(this);
88  option->shape = d_func()->shape;
89 #ifndef Q_WS_MAC
90  option->opaque = true;
91 #else
92  option->opaque = windowFlags() & RUBBERBAND_WINDOW_TYPE;
93 #endif
94 }
95 
129 // ### DOC: How about some nice convenience constructors?
130 //QRubberBand::QRubberBand(QRubberBand::Type t, const QRect &rect, QWidget *p)
131 //QRubberBand::QRubberBand(QRubberBand::Type t, int x, int y, int w, int h, QWidget *p)
132 
143  : QWidget(*new QRubberBandPrivate, p, (p && p->windowType() != Qt::Desktop) ? Qt::Widget : RUBBERBAND_WINDOW_TYPE)
144 {
145  Q_D(QRubberBand);
146  d->shape = s;
148 #ifndef Q_WS_WIN
150 #endif //Q_WS_WIN
152  setVisible(false);
153 #ifdef Q_WS_MAC
154  if (isWindow()) {
155  createWinId();
156  extern OSWindowRef qt_mac_window_for(const QWidget *); //qwidget_mac.cpp
158  }
159 #endif
160 }
161 
166 {
167 }
168 
194 {
195  Q_D(const QRubberBand);
196  return d->shape;
197 }
198 
203 {
204  Q_Q(QRubberBand);
207  q->initStyleOption(&opt);
208  if (q->style()->styleHint(QStyle::SH_RubberBand_Mask, &opt, q, &mask)) {
209  q->setMask(mask.region);
210  } else {
211  q->clearMask();
212  }
213 }
214 
219 {
220  QStylePainter painter(this);
221  QStyleOptionRubberBand option;
222  initStyleOption(&option);
223  painter.drawControl(QStyle::CE_RubberBand, option);
224 }
225 
230 {
232  switch (e->type()) {
234  if (parent()) {
236  } else {
238  }
239  break;
240  default:
241  break;
242  }
243 
244  if (e->type() == QEvent::ZOrderChange)
245  raise();
246 }
247 
252 {
253  raise();
254  e->ignore();
255 }
256 
261 {
262  Q_D(QRubberBand);
263  d->updateMask();
264 }
265 
270 {
271  Q_D(QRubberBand);
272  d->updateMask();
273 }
274 
336 {
337  QWidget::setGeometry(geom);
338 }
339 
354 {
355  return QWidget::event(e);
356 }
357 
359 
360 #endif // QT_NO_RUBBERBAND
double d
Definition: qnumeric_p.h:62
QRubberBand::Shape shape
Definition: qrubberband.cpp:71
#define RUBBERBAND_WINDOW_TYPE
Definition: qrubberband.cpp:64
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void drawControl(QStyle::ControlElement ce, const QStyleOption &opt)
Use the widget&#39;s style to draw a control element ce specified by QStyleOption option.
Definition: qstylepainter.h:87
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
void showEvent(QShowEvent *)
Reimplemented Function
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void resizeEvent(QResizeEvent *)
Reimplemented Function
friend OSWindowRef qt_mac_window_for(const QWidget *w)
Definition: qwidget_mac.mm:484
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qwidget.h:1017
#define Q_D(Class)
Definition: qglobal.h:2482
Shape
This enum specifies what shape a QRubberBand should have.
Definition: qrubberband.h:63
#define Q_Q(Class)
Definition: qglobal.h:2483
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setGeometry(const QRect &r)
Sets the geometry of the rubber band to rect, specified in the coordinate system of its parent widget...
The QMoveEvent class contains event parameters for move events.
Definition: qevent.h:334
void macWindowSetHasShadow(void *window, bool hasShadow)
void moveEvent(QMoveEvent *)
Reimplemented Function
WindowRef OSWindowRef
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
void setWindowFlags(Qt::WindowFlags type)
Definition: qwidget.cpp:10399
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
~QRubberBand()
Destructor.
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
bool opaque
whether the rubber band is required to be drawn in an opaque style
Definition: qstyleoption.h:676
The QStyleOptionRubberBand class is used to describe the parameters needed for drawing a rubber band...
Definition: qstyleoption.h:669
QRegion mask() const
Returns the mask currently set on a widget.
Definition: qwidget.cpp:10058
virtual void setVisible(bool visible)
Definition: qwidget.cpp:7991
void paintEvent(QPaintEvent *)
Reimplemented Function
The QStyleHintReturnMask class provides style hints that return a QRegion.
Definition: qstyleoption.h:923
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
bool event(QEvent *e)
Reimplemented Function
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Definition: qnamespace.h:54
QRubberBand::Shape shape
the shape of the rubber band
Definition: qstyleoption.h:675
void initStyleOption(QStyleOptionRubberBand *option) const
Initialize option with the values from this QRubberBand.
Definition: qrubberband.cpp:83
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
Shape shape() const
Returns the shape of this rubber band.
void createWinId()
Definition: qwidget.cpp:2626
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget...
Definition: qstylepainter.h:55
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void changeEvent(QEvent *)
Reimplemented Function
Qt::WindowFlags windowFlags() const
Window flags are a combination of a type (e.
Definition: qwidget.h:939
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
QRegion region
the region for style hints that return a QRegion
Definition: qstyleoption.h:930
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
QRubberBand(Shape, QWidget *=0)
Constructs a rubber band of shape s, with parent p.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
The QRubberBand class provides a rectangle or line that can indicate a selection or a boundary...
Definition: qrubberband.h:58
Type type() const
Returns the event type.
Definition: qcoreevent.h:303