1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the widgets module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "qfocusframe.h"
32
#include "qstylepainter.h"
33
#include "qstyleoption.h"
34
#include <private/qwidget_p.h>
36
class QFocusFramePrivate : public QWidgetPrivate
38
Q_DECLARE_PUBLIC(QFocusFrame)
42
QFocusFramePrivate() {
44
sendChildEvents = false;
48
QStyleOption getStyleOption() const;
51
void QFocusFramePrivate::update()
54
q->setParent(widget->parentWidget());
56
if (q->parentWidget()->rect().contains(q->geometry())) {
57
q->stackUnder(widget);
64
void QFocusFramePrivate::updateSize()
67
int vmargin = q->style()->pixelMetric(QStyle::PM_FocusFrameVMargin),
68
hmargin = q->style()->pixelMetric(QStyle::PM_FocusFrameHMargin);
69
QRect geom(widget->x()-hmargin, widget->y()-vmargin,
70
widget->width()+(hmargin*2), widget->height()+(vmargin*2));
71
if(q->geometry() == geom)
74
QStyleHintReturnMask mask;
75
QStyleOption opt = getStyleOption();
76
if (q->style()->styleHint(QStyle::SH_FocusFrame_Mask, &opt, q, &mask))
77
q->setMask(mask.region);
80
QStyleOption QFocusFramePrivate::getStyleOption() const
82
Q_Q(const QFocusFrame);
91
\brief The QFocusFrame widget provides a focus frame which can be
92
outside of a widget's normal paintable area.
97
Normally an application will not need to create its own
98
QFocusFrame as QStyle will handle this detail for
99
you. A style writer can optionally use a QFocusFrame to have a
100
focus area outside of the widget's paintable geometry. In this way
101
space need not be reserved for the widget to have focus but only
102
set on a QWidget with QFocusFrame::setWidget. It is, however,
103
legal to create your own QFocusFrame on a custom widget and set
104
its geometry manually via QWidget::setGeometry however you will
105
not get auto-placement when the focused widget changes size or
110
Constructs a QFocusFrame.
112
The focus frame will not monitor \a parent for updates but rather
113
can be placed manually or by using QFocusFrame::setWidget. A
114
QFocusFrame sets Qt::WA_NoChildEventsForParent attribute; as a
115
result the parent will not receive a QEvent::ChildInserted event,
116
this will make it possible to manually set the geometry of the
117
QFocusFrame inside of a QSplitter or other child event monitoring
120
\sa QFocusFrame::setWidget()
123
QFocusFrame::QFocusFrame(QWidget *parent)
124
: QWidget(*new QFocusFramePrivate, parent, 0)
126
setAttribute(Qt::WA_TransparentForMouseEvents);
127
setFocusPolicy(Qt::NoFocus);
128
setAttribute(Qt::WA_NoSystemBackground, true);
129
setAttribute(Qt::WA_NoChildEventsForParent, true);
136
QFocusFrame::~QFocusFrame()
141
QFocusFrame will track changes to \a widget and resize itself automatically.
142
If the monitored widget's parent changes, QFocusFrame will follow the widget
143
and place itself around the widget automatically. If the monitored widget is deleted,
144
QFocusFrame will set it to zero.
146
\sa QFocusFrame::widget()
150
QFocusFrame::setWidget(QWidget *widget)
153
if(widget == d->widget)
157
d->widget->removeEventFilter(this);
158
if(widget && !widget->isWindow() && widget->parentWidget()->windowType() != Qt::SubWindow) {
160
widget->installEventFilter(this);
169
Returns the currently monitored widget for automatically resize and
172
\sa QFocusFrame::setWidget()
176
QFocusFrame::widget() const
178
Q_D(const QFocusFrame);
185
QFocusFrame::paintEvent(QPaintEvent *)
188
QStylePainter p(this);
189
p.drawControl(QStyle::CE_FocusFrame, d->getStyleOption());
195
QFocusFrame::eventFilter(QObject *o, QEvent *e)
205
case QEvent::StyleChange:
208
case QEvent::ParentChange:
215
case QEvent::PaletteChange:
216
setPalette(d->widget->palette());
218
case QEvent::ZOrderChange:
219
stackUnder(d->widget);
221
case QEvent::Destroy: