| 1 | /****************************************************************************
|
|---|
| 2 | ** $Id: qfocusdata.cpp 2 2005-11-16 15:49:26Z dmik $
|
|---|
| 3 | **
|
|---|
| 4 | ** Implementation of QFocusData class
|
|---|
| 5 | **
|
|---|
| 6 | ** Created : 980622
|
|---|
| 7 | **
|
|---|
| 8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
|
|---|
| 9 | **
|
|---|
| 10 | ** This file is part of the kernel module of the Qt GUI Toolkit.
|
|---|
| 11 | **
|
|---|
| 12 | ** This file may be distributed under the terms of the Q Public License
|
|---|
| 13 | ** as defined by Trolltech AS of Norway and appearing in the file
|
|---|
| 14 | ** LICENSE.QPL included in the packaging of this file.
|
|---|
| 15 | **
|
|---|
| 16 | ** This file may be distributed and/or modified under the terms of the
|
|---|
| 17 | ** GNU General Public License version 2 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 19 | ** packaging of this file.
|
|---|
| 20 | **
|
|---|
| 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
|---|
| 22 | ** licenses may use this file in accordance with the Qt Commercial License
|
|---|
| 23 | ** Agreement provided with the Software.
|
|---|
| 24 | **
|
|---|
| 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|---|
| 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|---|
| 27 | **
|
|---|
| 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
|---|
| 29 | ** information about Qt Commercial License Agreements.
|
|---|
| 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
|---|
| 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
|---|
| 32 | **
|
|---|
| 33 | ** Contact info@trolltech.com if any conditions of this licensing are
|
|---|
| 34 | ** not clear to you.
|
|---|
| 35 | **
|
|---|
| 36 | **********************************************************************/
|
|---|
| 37 |
|
|---|
| 38 | #include "qfocusdata.h"
|
|---|
| 39 |
|
|---|
| 40 | /*!
|
|---|
| 41 | \class QFocusData qfocusdata.h
|
|---|
| 42 | \brief The QFocusData class maintains the list of widgets in the focus
|
|---|
| 43 | chain.
|
|---|
| 44 |
|
|---|
| 45 | \ingroup misc
|
|---|
| 46 |
|
|---|
| 47 | This read-only list always contains at least one widget (i.e. the
|
|---|
| 48 | top-level widget). It provides a simple cursor which can be reset
|
|---|
| 49 | to the current focus widget using home(), or moved to its
|
|---|
| 50 | neighboring widgets using next() and prev(). You can also retrieve
|
|---|
| 51 | the count() of the number of widgets in the list. The list is a
|
|---|
| 52 | loop, so if you keep iterating, for example using next(), you will
|
|---|
| 53 | never come to the end.
|
|---|
| 54 |
|
|---|
| 55 | Some widgets in the list may not accept focus. Widgets are added
|
|---|
| 56 | to the list as necessary, but not removed from it. This lets
|
|---|
| 57 | widgets change focus policy dynamically without disrupting the
|
|---|
| 58 | focus chain the user experiences. When a widget disables and
|
|---|
| 59 | re-enables tab focus, its position in the focus chain does not
|
|---|
| 60 | change.
|
|---|
| 61 |
|
|---|
| 62 | When reimplementing QWidget::focusNextPrevChild() to provide
|
|---|
| 63 | special focus flow, you will usually call QWidget::focusData() to
|
|---|
| 64 | retrieve the focus data stored at the top-level widget. A
|
|---|
| 65 | top-level widget's focus data contains the focus list for its
|
|---|
| 66 | hierarchy of widgets.
|
|---|
| 67 |
|
|---|
| 68 | The cursor may change at any time.
|
|---|
| 69 |
|
|---|
| 70 | This class is \e not thread-safe.
|
|---|
| 71 |
|
|---|
| 72 | \sa QWidget::focusNextPrevChild() QWidget::setTabOrder()
|
|---|
| 73 | QWidget::setFocusPolicy()
|
|---|
| 74 | */
|
|---|
| 75 |
|
|---|
| 76 | /*!
|
|---|
| 77 | \fn QWidget* QFocusData::focusWidget() const
|
|---|
| 78 |
|
|---|
| 79 | Returns the widgets in the hierarchy that are in the focus chain.
|
|---|
| 80 | */
|
|---|
| 81 |
|
|---|
| 82 | /*!
|
|---|
| 83 | \fn int QFocusData::count() const
|
|---|
| 84 |
|
|---|
| 85 | Returns the number of widgets in the focus chain.
|
|---|
| 86 | */
|
|---|
| 87 |
|
|---|
| 88 | /*!
|
|---|
| 89 | Moves the cursor to the focusWidget() and returns that widget. You
|
|---|
| 90 | must call this before next() or prev() to iterate meaningfully.
|
|---|
| 91 | */
|
|---|
| 92 | QWidget* QFocusData::home()
|
|---|
| 93 | {
|
|---|
| 94 | focusWidgets.find(it.current());
|
|---|
| 95 | return focusWidgets.current();
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | /*!
|
|---|
| 99 | Moves the cursor to the next widget in the focus chain. There is
|
|---|
| 100 | \e always a next widget because the list is a loop.
|
|---|
| 101 | */
|
|---|
| 102 | QWidget* QFocusData::next()
|
|---|
| 103 | {
|
|---|
| 104 | QWidget* r = focusWidgets.next();
|
|---|
| 105 | if ( !r )
|
|---|
| 106 | r = focusWidgets.first();
|
|---|
| 107 | return r;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | /*!
|
|---|
| 111 | Moves the cursor to the previous widget in the focus chain. There
|
|---|
| 112 | is \e always a previous widget because the list is a loop.
|
|---|
| 113 | */
|
|---|
| 114 | QWidget* QFocusData::prev()
|
|---|
| 115 | {
|
|---|
| 116 | QWidget* r = focusWidgets.prev();
|
|---|
| 117 | if ( !r )
|
|---|
| 118 | r = focusWidgets.last();
|
|---|
| 119 | return r;
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | /*!
|
|---|
| 123 | Returns the last widget in the focus chain.
|
|---|
| 124 | The cursor is not modified.
|
|---|
| 125 | */
|
|---|
| 126 | QWidget *QFocusData::last() const
|
|---|
| 127 | {
|
|---|
| 128 | return focusWidgets.getLast();
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | /*!
|
|---|
| 132 | Returns the first widget in the focus chain.
|
|---|
| 133 | The cursor is not modified.
|
|---|
| 134 | */
|
|---|
| 135 | QWidget *QFocusData::first() const
|
|---|
| 136 | {
|
|---|
| 137 | return focusWidgets.getFirst();
|
|---|
| 138 | }
|
|---|