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

Generated by Squish Coco Non-Commercial