1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the Qt3Support module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "q3groupbox.h"
|
---|
43 |
|
---|
44 | #include "qlayout.h"
|
---|
45 | #include "qpainter.h"
|
---|
46 | #include "qbitmap.h"
|
---|
47 | #include "q3accel.h"
|
---|
48 | #include "qradiobutton.h"
|
---|
49 | #include "qdrawutil.h"
|
---|
50 | #include "qapplication.h"
|
---|
51 | #include "qstyle.h"
|
---|
52 | #include "qcheckbox.h"
|
---|
53 | #include "qaccessible.h"
|
---|
54 | #include "qstyleoption.h"
|
---|
55 | #include "qdebug.h"
|
---|
56 |
|
---|
57 | QT_BEGIN_NAMESPACE
|
---|
58 |
|
---|
59 | /*!
|
---|
60 | \class Q3GroupBox
|
---|
61 | \brief The Q3GroupBox widget provides a group box frame with a title.
|
---|
62 |
|
---|
63 | \compat
|
---|
64 |
|
---|
65 | A group box provides a frame, a title and a keyboard shortcut, and
|
---|
66 | displays various other widgets inside itself. The title is on top,
|
---|
67 | the keyboard shortcut moves keyboard focus to one of the group
|
---|
68 | box's child widgets, and the child widgets are usually laid out
|
---|
69 | horizontally (or vertically) inside the frame.
|
---|
70 |
|
---|
71 | The simplest way to use it is to create a group box with the
|
---|
72 | desired number of columns (or rows) and orientation, and then just
|
---|
73 | create widgets with the group box as parent.
|
---|
74 |
|
---|
75 | It is also possible to change the orientation() and number of
|
---|
76 | columns() after construction, or to ignore all the automatic
|
---|
77 | layout support and manage the layout yourself. You can add 'empty'
|
---|
78 | spaces to the group box with addSpace().
|
---|
79 |
|
---|
80 | Q3GroupBox also lets you set the title() (normally set in the
|
---|
81 | constructor) and the title's alignment().
|
---|
82 |
|
---|
83 | You can change the spacing used by the group box with
|
---|
84 | setInsideMargin() and setInsideSpacing(). To minimize space
|
---|
85 | consumption, you can remove the right, left and bottom edges of
|
---|
86 | the frame with setFlat().
|
---|
87 |
|
---|
88 | \sa QButtonGroup
|
---|
89 | */
|
---|
90 |
|
---|
91 | class QCheckBox;
|
---|
92 |
|
---|
93 | class Q3GroupBoxPrivate
|
---|
94 | {
|
---|
95 | public:
|
---|
96 | Q3GroupBoxPrivate(Q3GroupBox *w):
|
---|
97 | q(w), vbox(0), grid(0), row(0), col(0), nRows(0), nCols(0), dir(Qt::Horizontal),
|
---|
98 | spac(5), marg(11),
|
---|
99 | checkbox(0),
|
---|
100 | frameStyle(Q3GroupBox::GroupBoxPanel | Q3GroupBox::Sunken),
|
---|
101 | lineWidth(1), midLineWidth(0), frameWidth(0),
|
---|
102 | leftFrameWidth(0), rightFrameWidth(0),
|
---|
103 | topFrameWidth(0), bottomFrameWidth(0) {}
|
---|
104 |
|
---|
105 | void updateFrameWidth();
|
---|
106 | void updateStyledFrameWidths();
|
---|
107 |
|
---|
108 | Q3GroupBox *q;
|
---|
109 | QVBoxLayout *vbox;
|
---|
110 | QGridLayout *grid;
|
---|
111 | int row;
|
---|
112 | int col;
|
---|
113 | int nRows, nCols;
|
---|
114 | Qt::Orientation dir;
|
---|
115 | int spac, marg;
|
---|
116 |
|
---|
117 | QCheckBox *checkbox;
|
---|
118 |
|
---|
119 | int frameStyle;
|
---|
120 | int oldFrameStyle;
|
---|
121 | short lineWidth, //line width
|
---|
122 | midLineWidth; //midline width
|
---|
123 | int frameWidth;
|
---|
124 | short leftFrameWidth, rightFrameWidth,
|
---|
125 | topFrameWidth, bottomFrameWidth;
|
---|
126 | };
|
---|
127 |
|
---|
128 | /*!
|
---|
129 | \internal
|
---|
130 | Updates the frame widths from the style.
|
---|
131 | */
|
---|
132 | void Q3GroupBoxPrivate::updateStyledFrameWidths()
|
---|
133 | {
|
---|
134 | QStyleOptionFrameV2 opt;
|
---|
135 | opt.initFrom(q);
|
---|
136 | QRect cr = q->style()->subElementRect(QStyle::SE_FrameContents, &opt, q);
|
---|
137 | leftFrameWidth = cr.left() - opt.rect.left();
|
---|
|
---|