qfocusframe.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qfocusframe.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets 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 The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/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 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qfocusframe.h"-
41#include "qstyle.h"-
42#include "qbitmap.h"-
43#include "qstylepainter.h"-
44#include "qstyleoption.h"-
45#include "qdebug.h"-
46#include <private/qwidget_p.h>-
47-
48QT_BEGIN_NAMESPACE-
49-
50class QFocusFramePrivate : public QWidgetPrivate-
51{-
52 Q_DECLARE_PUBLIC(QFocusFrame)-
53 QWidget *widget;-
54 QWidget *frameParent;-
55 bool showFrameAboveWidget;-
56public:-
57 QFocusFramePrivate() {-
58 widget = 0;-
59 frameParent = 0;-
60 sendChildEvents = false;-
61 showFrameAboveWidget = false;-
62 }
never executed: end of block
0
63 void updateSize();-
64 void update();-
65};-
66-
67void QFocusFramePrivate::update()-
68{-
69 Q_Q(QFocusFrame);-
70 q->setParent(frameParent);-
71 updateSize();-
72 if (q->parentWidget()->rect().intersects(q->geometry())) {
q->parentWidge...q->geometry())Description
TRUEnever evaluated
FALSEnever evaluated
0
73 if (showFrameAboveWidget)
showFrameAboveWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
74 q->raise();
never executed: q->raise();
0
75 else-
76 q->stackUnder(widget);
never executed: q->stackUnder(widget);
0
77 q->show();-
78 } else {
never executed: end of block
0
79 q->hide();-
80 }
never executed: end of block
0
81}-
82-
83void QFocusFramePrivate::updateSize()-
84{-
85 Q_Q(QFocusFrame);-
86 if (!widget)
!widgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
87 return;
never executed: return;
0
88-
89 int vmargin = q->style()->pixelMetric(QStyle::PM_FocusFrameVMargin),-
90 hmargin = q->style()->pixelMetric(QStyle::PM_FocusFrameHMargin);-
91 QPoint pos(widget->x(), widget->y());-
92 if (q->parentWidget() != widget->parentWidget())
q->parentWidge...parentWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
93 pos = widget->parentWidget()->mapTo(q->parentWidget(), pos);
never executed: pos = widget->parentWidget()->mapTo(q->parentWidget(), pos);
0
94 QRect geom(pos.x()-hmargin, pos.y()-vmargin,-
95 widget->width()+(hmargin*2), widget->height()+(vmargin*2));-
96 if(q->geometry() == geom)
q->geometry() == geomDescription
TRUEnever evaluated
FALSEnever evaluated
0
97 return;
never executed: return;
0
98-
99 q->setGeometry(geom);-
100 QStyleHintReturnMask mask;-
101 QStyleOption opt;-
102 q->initStyleOption(&opt);-
103 if (q->style()->styleHint(QStyle::SH_FocusFrame_Mask, &opt, q, &mask))
q->style()->st...opt, q, &mask)Description
TRUEnever evaluated
FALSEnever evaluated
0
104 q->setMask(mask.region);
never executed: q->setMask(mask.region);
0
105}
never executed: end of block
0
106-
107/*!-
108 Initialize \a option with the values from this QFocusFrame. This method is useful-
109 for subclasses when they need a QStyleOption, but don't want to fill-
110 in all the information themselves.-
111-
112 \sa QStyleOption::initFrom()-
113*/-
114void QFocusFrame::initStyleOption(QStyleOption *option) const-
115{-
116 if (!option)
!optionDescription
TRUEnever evaluated
FALSEnever evaluated
0
117 return;
never executed: return;
0
118-
119 option->initFrom(this);-
120}
never executed: end of block
0
121-
122/*!-
123 \class QFocusFrame-
124 \brief The QFocusFrame widget provides a focus frame which can be-
125 outside of a widget's normal paintable area.-
126-
127 \ingroup basicwidgets-
128 \inmodule QtWidgets-
129-
130 Normally an application will not need to create its own-
131 QFocusFrame as QStyle will handle this detail for-
132 you. A style writer can optionally use a QFocusFrame to have a-
133 focus area outside of the widget's paintable geometry. In this way-
134 space need not be reserved for the widget to have focus but only-
135 set on a QWidget with QFocusFrame::setWidget. It is, however,-
136 legal to create your own QFocusFrame on a custom widget and set-
137 its geometry manually via QWidget::setGeometry however you will-
138 not get auto-placement when the focused widget changes size or-
139 placement.-
140*/-
141-
142/*!-
143 Constructs a QFocusFrame.-
144-
145 The focus frame will not monitor \a parent for updates but rather-
146 can be placed manually or by using QFocusFrame::setWidget. A-
147 QFocusFrame sets Qt::WA_NoChildEventsForParent attribute; as a-
148 result the parent will not receive a QEvent::ChildAdded event,-
149 this will make it possible to manually set the geometry of the-
150 QFocusFrame inside of a QSplitter or other child event monitoring-
151 widget.-
152-
153 \sa QFocusFrame::setWidget()-
154*/-
155-
156QFocusFrame::QFocusFrame(QWidget *parent)-
157 : QWidget(*new QFocusFramePrivate, parent, 0)-
158{-
159 setAttribute(Qt::WA_TransparentForMouseEvents);-
160 setFocusPolicy(Qt::NoFocus);-
161 setAttribute(Qt::WA_NoChildEventsForParent, true);-
162 setAttribute(Qt::WA_AcceptDrops, style()->styleHint(QStyle::SH_FocusFrame_AboveWidget, 0, this));-
163}
never executed: end of block
0
164-
165/*!-
166 Destructor.-
167*/-
168-
169QFocusFrame::~QFocusFrame()-
170{-
171}-
172-
173/*!-
174 QFocusFrame will track changes to \a widget and resize itself automatically.-
175 If the monitored widget's parent changes, QFocusFrame will follow the widget-
176 and place itself around the widget automatically. If the monitored widget is deleted,-
177 QFocusFrame will set it to zero.-
178-
179 \sa QFocusFrame::widget()-
180*/-
181-
182void-
183QFocusFrame::setWidget(QWidget *widget)-
184{-
185 Q_D(QFocusFrame);-
186-
187 if (style()->styleHint(QStyle::SH_FocusFrame_AboveWidget, 0, this))
style()->style...dget, 0, this)Description
TRUEnever evaluated
FALSEnever evaluated
0
188 d->showFrameAboveWidget = true;
never executed: d->showFrameAboveWidget = true;
0
189 else-
190 d->showFrameAboveWidget = false;
never executed: d->showFrameAboveWidget = false;
0
191-
192 if (widget == d->widget)
widget == d->widgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
193 return;
never executed: return;
0
194 if (d->widget) {
d->widgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
195 // Remove event filters from the widget hierarchy.-
196 QWidget *p = d->widget;-
197 do {-
198 p->removeEventFilter(this);-
199 if (!d->showFrameAboveWidget || p == d->frameParent)
!d->showFrameAboveWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
p == d->frameParentDescription
TRUEnever evaluated
FALSEnever evaluated
0
200 break;
never executed: break;
0
201 p = p->parentWidget();-
202 }while (p);
never executed: end of block
pDescription
TRUEnever evaluated
FALSEnever evaluated
0
203 }
never executed: end of block
0
204 if (widget && !widget->isWindow() && widget->parentWidget()->windowType() != Qt::SubWindow) {
widgetDescription
TRUEnever evaluated
FALSEnever evaluated
!widget->isWindow()Description
TRUEnever evaluated
FALSEnever evaluated
widget->parent... Qt::SubWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
205 d->widget = widget;-
206 d->widget->installEventFilter(this);-
207 QWidget *p = widget->parentWidget();-
208 QWidget *prev = 0;-
209 if (d->showFrameAboveWidget) {
d->showFrameAboveWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
210 // Find the right parent for the focus frame.-
211 while (p) {
pDescription
TRUEnever evaluated
FALSEnever evaluated
0
212 // Traverse the hirerarchy of the 'widget' for setting event filter.-
213 // During this if come across toolbar or a top level, use that-
214 // as the parent for the focus frame. If we find a scroll area-
215 // use its viewport as the parent.-
216 bool isScrollArea = false;-
217 if (p->isWindow() || p->inherits("QToolBar") || (isScrollArea = p->inherits("QAbstractScrollArea"))) {
p->isWindow()Description
TRUEnever evaluated
FALSEnever evaluated
p->inherits("QToolBar")Description
TRUEnever evaluated
FALSEnever evaluated
(isScrollArea ...tScrollArea"))Description
TRUEnever evaluated
FALSEnever evaluated
0
218 d->frameParent = p;-
219 // The previous one in the hierarchy will be the viewport.-
220 if (prev && isScrollArea)
prevDescription
TRUEnever evaluated
FALSEnever evaluated
isScrollAreaDescription
TRUEnever evaluated
FALSEnever evaluated
0
221 d->frameParent = prev;
never executed: d->frameParent = prev;
0
222 break;
never executed: break;
0
223 } else {-
224 p->installEventFilter(this);-
225 prev = p;-
226 p = p->parentWidget();-
227 }
never executed: end of block
0
228 }-
229 } else {
never executed: end of block
0
230 d->frameParent = p;-
231 }
never executed: end of block
0
232 d->update();-
233 } else {
never executed: end of block
0
234 d->widget = 0;-
235 hide();-
236 }
never executed: end of block
0
237}-
238-
239/*!-
240 Returns the currently monitored widget for automatically resize and-
241 update.-
242-
243 \sa QFocusFrame::setWidget()-
244*/-
245-
246QWidget *-
247QFocusFrame::widget() const-
248{-
249 Q_D(const QFocusFrame);-
250 return d->widget;
never executed: return d->widget;
0
251}-
252-
253-
254/*! \reimp */-
255void-
256QFocusFrame::paintEvent(QPaintEvent *)-
257{-
258 Q_D(QFocusFrame);-
259-
260 if (!d->widget)
!d->widgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
261 return;
never executed: return;
0
262-
263 QStylePainter p(this);-
264 QStyleOption option;-
265 initStyleOption(&option);-
266 int vmargin = style()->pixelMetric(QStyle::PM_FocusFrameVMargin);-
267 int hmargin = style()->pixelMetric(QStyle::PM_FocusFrameHMargin);-
268 QWidgetPrivate *wd = qt_widget_private(d->widget);-
269 QRect rect = wd->clipRect().adjusted(0, 0, hmargin*2, vmargin*2);-
270 p.setClipRect(rect);-
271 p.drawControl(QStyle::CE_FocusFrame, option);-
272}
never executed: end of block
0
273-
274-
275/*! \reimp */-
276bool-
277QFocusFrame::eventFilter(QObject *o, QEvent *e)-
278{-
279 Q_D(QFocusFrame);-
280 if(o == d->widget) {
o == d->widgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
281 switch(e->type()) {-
282 case QEvent::Move:
never executed: case QEvent::Move:
0
283 case QEvent::Resize:
never executed: case QEvent::Resize:
0
284 d->updateSize();-
285 break;
never executed: break;
0
286 case QEvent::Hide:
never executed: case QEvent::Hide:
0
287 case QEvent::StyleChange:
never executed: case QEvent::StyleChange:
0
288 hide();-
289 break;
never executed: break;
0
290 case QEvent::ParentChange:
never executed: case QEvent::ParentChange:
0
291 if (d->showFrameAboveWidget) {
d->showFrameAboveWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
292 QWidget *w = d->widget;-
293 setWidget(0);-
294 setWidget(w);-
295 } else {
never executed: end of block
0
296 d->update();-
297 }
never executed: end of block
0
298 break;
never executed: break;
0
299 case QEvent::Show:
never executed: case QEvent::Show:
0
300 d->update();-
301 show();-
302 break;
never executed: break;
0
303 case QEvent::PaletteChange:
never executed: case QEvent::PaletteChange:
0
304 setPalette(d->widget->palette());-
305 break;
never executed: break;
0
306 case QEvent::ZOrderChange:
never executed: case QEvent::ZOrderChange:
0
307 if (style()->styleHint(QStyle::SH_FocusFrame_AboveWidget, 0, this))
style()->style...dget, 0, this)Description
TRUEnever evaluated
FALSEnever evaluated
0
308 raise();
never executed: raise();
0
309 else-
310 stackUnder(d->widget);
never executed: stackUnder(d->widget);
0
311 break;
never executed: break;
0
312 case QEvent::Destroy:
never executed: case QEvent::Destroy:
0
313 setWidget(0);-
314 break;
never executed: break;
0
315 default:
never executed: default:
0
316 break;
never executed: break;
0
317 }-
318 } else if (d->showFrameAboveWidget) {
d->showFrameAboveWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
319 // Handle changes in the parent widgets we are monitoring.-
320 switch(e->type()) {-
321 case QEvent::Move:
never executed: case QEvent::Move:
0
322 case QEvent::Resize:
never executed: case QEvent::Resize:
0
323 d->updateSize();-
324 break;
never executed: break;
0
325 case QEvent::ZOrderChange:
never executed: case QEvent::ZOrderChange:
0
326 raise();-
327 break;
never executed: break;
0
328 default:
never executed: default:
0
329 break;
never executed: break;
0
330 }-
331 }-
332 return false;
never executed: return false;
0
333}-
334-
335/*! \reimp */-
336bool QFocusFrame::event(QEvent *e)-
337{-
338 return QWidget::event(e);
never executed: return QWidget::event(e);
0
339}-
340-
341QT_END_NAMESPACE-
342-
343#include "moc_qfocusframe.cpp"-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9