Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qframe.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||
2 | ** | - | ||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||
5 | ** | - | ||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||
7 | ** | - | ||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||
15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||
25 | ** | - | ||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||
29 | ** | - | ||||||
30 | ** $QT_END_LICENSE$ | - | ||||||
31 | ** | - | ||||||
32 | ****************************************************************************/ | - | ||||||
33 | - | |||||||
34 | #include "qframe.h" | - | ||||||
35 | #include "qbitmap.h" | - | ||||||
36 | #include "qdrawutil.h" | - | ||||||
37 | #include "qevent.h" | - | ||||||
38 | #include "qpainter.h" | - | ||||||
39 | #include "qstyle.h" | - | ||||||
40 | #include "qstyleoption.h" | - | ||||||
41 | #include "qapplication.h" | - | ||||||
42 | - | |||||||
43 | #include "qframe_p.h" | - | ||||||
44 | - | |||||||
45 | QT_BEGIN_NAMESPACE | - | ||||||
46 | - | |||||||
47 | QFramePrivate::QFramePrivate() | - | ||||||
48 | : frect(0, 0, 0, 0), | - | ||||||
49 | frameStyle(QFrame::NoFrame | QFrame::Plain), | - | ||||||
50 | lineWidth(1), | - | ||||||
51 | midLineWidth(0), | - | ||||||
52 | frameWidth(0), | - | ||||||
53 | leftFrameWidth(0), rightFrameWidth(0), | - | ||||||
54 | topFrameWidth(0), bottomFrameWidth(0) | - | ||||||
55 | { | - | ||||||
56 | } never executed: end of block | 0 | ||||||
57 | - | |||||||
58 | QFramePrivate::~QFramePrivate() | - | ||||||
59 | { | - | ||||||
60 | } | - | ||||||
61 | - | |||||||
62 | inline void QFramePrivate::init() | - | ||||||
63 | { | - | ||||||
64 | setLayoutItemMargins(QStyle::SE_FrameLayoutItem); | - | ||||||
65 | } never executed: end of block | 0 | ||||||
66 | - | |||||||
67 | /*! | - | ||||||
68 | \class QFrame | - | ||||||
69 | \brief The QFrame class is the base class of widgets that can have a frame. | - | ||||||
70 | - | |||||||
71 | \ingroup abstractwidgets | - | ||||||
72 | \inmodule QtWidgets | - | ||||||
73 | - | |||||||
74 | QMenu uses this to "raise" the menu above the surrounding | - | ||||||
75 | screen. QProgressBar has a "sunken" look. QLabel has a flat look. | - | ||||||
76 | The frames of widgets like these can be changed. | - | ||||||
77 | - | |||||||
78 | \snippet code/src_gui_widgets_qframe.cpp 0 | - | ||||||
79 | - | |||||||
80 | The QFrame class can also be used directly for creating simple | - | ||||||
81 | placeholder frames without any contents. | - | ||||||
82 | - | |||||||
83 | The frame style is specified by a \l{QFrame::Shape}{frame shape} and | - | ||||||
84 | a \l{QFrame::Shadow}{shadow style} that is used to visually separate | - | ||||||
85 | the frame from surrounding widgets. These properties can be set | - | ||||||
86 | together using the setFrameStyle() function and read with frameStyle(). | - | ||||||
87 | - | |||||||
88 | The frame shapes are \l NoFrame, \l Box, \l Panel, \l StyledPanel, | - | ||||||
89 | HLine and \l VLine; the shadow styles are \l Plain, \l Raised and | - | ||||||
90 | \l Sunken. | - | ||||||
91 | - | |||||||
92 | A frame widget has three attributes that describe the thickness of the | - | ||||||
93 | border: \l lineWidth, \l midLineWidth, and \l frameWidth. | - | ||||||
94 | - | |||||||
95 | \list | - | ||||||
96 | \li The line width is the width of the frame border. It can be modified | - | ||||||
97 | to customize the frame's appearance. | - | ||||||
98 | - | |||||||
99 | \li The mid-line width specifies the width of an extra line in the | - | ||||||
100 | middle of the frame, which uses a third color to obtain a special | - | ||||||
101 | 3D effect. Notice that a mid-line is only drawn for \l Box, \l | - | ||||||
102 | HLine and \l VLine frames that are raised or sunken. | - | ||||||
103 | - | |||||||
104 | \li The frame width is determined by the frame style, and the frameWidth() | - | ||||||
105 | function is used to obtain the value defined for the style used. | - | ||||||
106 | \endlist | - | ||||||
107 | - | |||||||
108 | The margin between the frame and the contents of the frame can be | - | ||||||
109 | customized with the QWidget::setContentsMargins() function. | - | ||||||
110 | - | |||||||
111 | \target picture | - | ||||||
112 | This table shows some of the combinations of styles and line widths: | - | ||||||
113 | - | |||||||
114 | \image frames.png Table of frame styles | - | ||||||
115 | */ | - | ||||||
116 | - | |||||||
117 | - | |||||||
118 | /*! | - | ||||||
119 | \enum QFrame::Shape | - | ||||||
120 | - | |||||||
121 | This enum type defines the shapes of frame available. | - | ||||||
122 | - | |||||||
123 | \value NoFrame QFrame draws nothing | - | ||||||
124 | \value Box QFrame draws a box around its contents | - | ||||||
125 | \value Panel QFrame draws a panel to make the contents appear | - | ||||||
126 | raised or sunken | - | ||||||
127 | \value StyledPanel draws a rectangular panel with a look that | - | ||||||
128 | depends on the current GUI style. It can be raised or sunken. | - | ||||||
129 | \value HLine QFrame draws a horizontal line that frames nothing | - | ||||||
130 | (useful as separator) | - | ||||||
131 | \value VLine QFrame draws a vertical line that frames nothing | - | ||||||
132 | (useful as separator) | - | ||||||
133 | \value WinPanel draws a rectangular panel that can be raised or | - | ||||||
134 | sunken like those in Windows 2000. Specifying this shape sets | - | ||||||
135 | the line width to 2 pixels. WinPanel is provided for compatibility. | - | ||||||
136 | For GUI style independence we recommend using StyledPanel instead. | - | ||||||
137 | - | |||||||
138 | When it does not call QStyle, Shape interacts with QFrame::Shadow, | - | ||||||
139 | the lineWidth() and the midLineWidth() to create the total result. | - | ||||||
140 | See the picture of the frames in the main class documentation. | - | ||||||
141 | - | |||||||
142 | \sa QFrame::Shadow, QFrame::style(), QStyle::drawPrimitive() | - | ||||||
143 | */ | - | ||||||
144 | - | |||||||
145 | - | |||||||
146 | /*! | - | ||||||
147 | \enum QFrame::Shadow | - | ||||||
148 | - | |||||||
149 | This enum type defines the types of shadow that are used to give | - | ||||||
150 | a 3D effect to frames. | - | ||||||
151 | - | |||||||
152 | \value Plain the frame and contents appear level with the | - | ||||||
153 | surroundings; draws using the palette QPalette::WindowText color | - | ||||||
154 | (without any 3D effect) | - | ||||||
155 | - | |||||||
156 | \value Raised the frame and contents appear raised; draws a 3D | - | ||||||
157 | raised line using the light and dark colors of the current color | - | ||||||
158 | group | - | ||||||
159 | \value Sunken the frame and contents appear sunken; draws a 3D | - | ||||||
160 | sunken line using the light and dark colors of the current color | - | ||||||
161 | group | - | ||||||
162 | - | |||||||
163 | Shadow interacts with QFrame::Shape, the lineWidth() and the | - | ||||||
164 | midLineWidth(). See the picture of the frames in the main class | - | ||||||
165 | documentation. | - | ||||||
166 | - | |||||||
167 | \sa QFrame::Shape, lineWidth(), midLineWidth() | - | ||||||
168 | */ | - | ||||||
169 | - | |||||||
170 | /*! | - | ||||||
171 | \enum QFrame::StyleMask | - | ||||||
172 | - | |||||||
173 | This enum defines two constants that can be used to extract the | - | ||||||
174 | two components of frameStyle(): | - | ||||||
175 | - | |||||||
176 | \value Shadow_Mask The \l Shadow part of frameStyle() | - | ||||||
177 | \value Shape_Mask The \l Shape part of frameStyle() | - | ||||||
178 | - | |||||||
179 | Normally, you don't need to use these, since frameShadow() and | - | ||||||
180 | frameShape() already extract the \l Shadow and the \l Shape parts | - | ||||||
181 | of frameStyle(). | - | ||||||
182 | - | |||||||
183 | \sa frameStyle(), setFrameStyle() | - | ||||||
184 | */ | - | ||||||
185 | - | |||||||
186 | /*! | - | ||||||
187 | Constructs a frame widget with frame style \l NoFrame and a | - | ||||||
188 | 1-pixel frame width. | - | ||||||
189 | - | |||||||
190 | The \a parent and \a f arguments are passed to the QWidget | - | ||||||
191 | constructor. | - | ||||||
192 | */ | - | ||||||
193 | - | |||||||
194 | QFrame::QFrame(QWidget* parent, Qt::WindowFlags f) | - | ||||||
195 | : QWidget(*new QFramePrivate, parent, f) | - | ||||||
196 | { | - | ||||||
197 | Q_D(QFrame); | - | ||||||
198 | d->init(); | - | ||||||
199 | } never executed: end of block | 0 | ||||||
200 | - | |||||||
201 | /*! \internal */ | - | ||||||
202 | QFrame::QFrame(QFramePrivate &dd, QWidget* parent, Qt::WindowFlags f) | - | ||||||
203 | : QWidget(dd, parent, f) | - | ||||||
204 | { | - | ||||||
205 | Q_D(QFrame); | - | ||||||
206 | d->init(); | - | ||||||
207 | } never executed: end of block | 0 | ||||||
208 | - | |||||||
209 | /*! | - | ||||||
210 | \since 5.5 | - | ||||||
211 | - | |||||||
212 | Initializes \a option with the values from this QFrame. This method is | - | ||||||
213 | useful for subclasses when they need a QStyleOptionFrame but don't want to | - | ||||||
214 | fill in all the information themselves. | - | ||||||
215 | - | |||||||
216 | \sa QStyleOption::initFrom() | - | ||||||
217 | */ | - | ||||||
218 | void QFrame::initStyleOption(QStyleOptionFrame *option) const | - | ||||||
219 | { | - | ||||||
220 | if (!option)
| 0 | ||||||
221 | return; never executed: return; | 0 | ||||||
222 | - | |||||||
223 | Q_D(const QFrame); | - | ||||||
224 | option->initFrom(this); | - | ||||||
225 | - | |||||||
226 | int frameShape = d->frameStyle & QFrame::Shape_Mask; | - | ||||||
227 | int frameShadow = d->frameStyle & QFrame::Shadow_Mask; | - | ||||||
228 | option->frameShape = Shape(int(option->frameShape) | frameShape); | - | ||||||
229 | option->rect = frameRect(); | - | ||||||
230 | switch (frameShape) { | - | ||||||
231 | case QFrame::Box: never executed: case QFrame::Box: | 0 | ||||||
232 | case QFrame::HLine: never executed: case QFrame::HLine: | 0 | ||||||
233 | case QFrame::VLine: never executed: case QFrame::VLine: | 0 | ||||||
234 | case QFrame::StyledPanel: never executed: case QFrame::StyledPanel: | 0 | ||||||
235 | case QFrame::Panel: never executed: case QFrame::Panel: | 0 | ||||||
236 | option->lineWidth = d->lineWidth; | - | ||||||
237 | option->midLineWidth = d->midLineWidth; | - | ||||||
238 | break; never executed: break; | 0 | ||||||
239 | default: never executed: default: | 0 | ||||||
240 | // most frame styles do not handle customized line and midline widths | - | ||||||
241 | // (see updateFrameWidth()). | - | ||||||
242 | option->lineWidth = d->frameWidth; | - | ||||||
243 | break; never executed: break; | 0 | ||||||
244 | } | - | ||||||
245 | - | |||||||
246 | if (frameShadow == Sunken)
| 0 | ||||||
247 | option->state |= QStyle::State_Sunken; never executed: option->state |= QStyle::State_Sunken; | 0 | ||||||
248 | else if (frameShadow == Raised)
| 0 | ||||||
249 | option->state |= QStyle::State_Raised; never executed: option->state |= QStyle::State_Raised; | 0 | ||||||
250 | } never executed: end of block | 0 | ||||||
251 | - | |||||||
252 | - | |||||||
253 | /*! | - | ||||||
254 | Destroys the frame. | - | ||||||
255 | */ | - | ||||||
256 | QFrame::~QFrame() | - | ||||||
257 | { | - | ||||||
258 | } | - | ||||||
259 | - | |||||||
260 | /*! | - | ||||||
261 | Returns the frame style. | - | ||||||
262 | - | |||||||
263 | The default value is QFrame::Plain. | - | ||||||
264 | - | |||||||
265 | \sa setFrameStyle(), frameShape(), frameShadow() | - | ||||||
266 | */ | - | ||||||
267 | int QFrame::frameStyle() const | - | ||||||
268 | { | - | ||||||
269 | Q_D(const QFrame); | - | ||||||
270 | return d->frameStyle; never executed: return d->frameStyle; | 0 | ||||||
271 | } | - | ||||||
272 | - | |||||||
273 | /*! | - | ||||||
274 | \property QFrame::frameShape | - | ||||||
275 | \brief the frame shape value from the frame style | - | ||||||
276 | - | |||||||
277 | \sa frameStyle(), frameShadow() | - | ||||||
278 | */ | - | ||||||
279 | - | |||||||
280 | QFrame::Shape QFrame::frameShape() const | - | ||||||
281 | { | - | ||||||
282 | Q_D(const QFrame); | - | ||||||
283 | return (Shape) (d->frameStyle & Shape_Mask); never executed: return (Shape) (d->frameStyle & Shape_Mask); | 0 | ||||||
284 | } | - | ||||||
285 | - | |||||||
286 | void QFrame::setFrameShape(QFrame::Shape s) | - | ||||||
287 | { | - | ||||||
288 | Q_D(QFrame); | - | ||||||
289 | setFrameStyle((d->frameStyle & Shadow_Mask) | s); | - | ||||||
290 | } never executed: end of block | 0 | ||||||
291 | - | |||||||
292 | - | |||||||
293 | /*! | - | ||||||
294 | \property QFrame::frameShadow | - | ||||||
295 | \brief the frame shadow value from the frame style | - | ||||||
296 | - | |||||||
297 | \sa frameStyle(), frameShape() | - | ||||||
298 | */ | - | ||||||
299 | QFrame::Shadow QFrame::frameShadow() const | - | ||||||
300 | { | - | ||||||
301 | Q_D(const QFrame); | - | ||||||
302 | return (Shadow) (d->frameStyle & Shadow_Mask); never executed: return (Shadow) (d->frameStyle & Shadow_Mask); | 0 | ||||||
303 | } | - | ||||||
304 | - | |||||||
305 | void QFrame::setFrameShadow(QFrame::Shadow s) | - | ||||||
306 | { | - | ||||||
307 | Q_D(QFrame); | - | ||||||
308 | setFrameStyle((d->frameStyle & Shape_Mask) | s); | - | ||||||
309 | } never executed: end of block | 0 | ||||||
310 | - | |||||||
311 | /*! | - | ||||||
312 | Sets the frame style to \a style. | - | ||||||
313 | - | |||||||
314 | The \a style is the bitwise OR between a frame shape and a frame | - | ||||||
315 | shadow style. See the picture of the frames in the main class | - | ||||||
316 | documentation. | - | ||||||
317 | - | |||||||
318 | The frame shapes are given in \l{QFrame::Shape} and the shadow | - | ||||||
319 | styles in \l{QFrame::Shadow}. | - | ||||||
320 | - | |||||||
321 | If a mid-line width greater than 0 is specified, an additional | - | ||||||
322 | line is drawn for \l Raised or \l Sunken \l Box, \l HLine, and \l | - | ||||||
323 | VLine frames. The mid-color of the current color group is used for | - | ||||||
324 | drawing middle lines. | - | ||||||
325 | - | |||||||
326 | \sa frameStyle() | - | ||||||
327 | */ | - | ||||||
328 | - | |||||||
329 | void QFrame::setFrameStyle(int style) | - | ||||||
330 | { | - | ||||||
331 | Q_D(QFrame); | - | ||||||
332 | if (!testAttribute(Qt::WA_WState_OwnSizePolicy)) {
| 0 | ||||||
333 | QSizePolicy sp; | - | ||||||
334 | - | |||||||
335 | switch (style & Shape_Mask) { | - | ||||||
336 | case HLine: never executed: case HLine: | 0 | ||||||
337 | sp = QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, QSizePolicy::Line); | - | ||||||
338 | break; never executed: break; | 0 | ||||||
339 | case VLine: never executed: case VLine: | 0 | ||||||
340 | sp = QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum, QSizePolicy::Line); | - | ||||||
341 | break; never executed: break; | 0 | ||||||
342 | default: never executed: default: | 0 | ||||||
343 | sp = QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::Frame); | - | ||||||
344 | } never executed: end of block | 0 | ||||||
345 | setSizePolicy(sp); | - | ||||||
346 | setAttribute(Qt::WA_WState_OwnSizePolicy, false); | - | ||||||
347 | } never executed: end of block | 0 | ||||||
348 | d->frameStyle = (short)style; | - | ||||||
349 | update(); | - | ||||||
350 | d->updateFrameWidth(); | - | ||||||
351 | } never executed: end of block | 0 | ||||||
352 | - | |||||||
353 | /*! | - | ||||||
354 | \property QFrame::lineWidth | - | ||||||
355 | \brief the line width | - | ||||||
356 | - | |||||||
357 | Note that the \e total line width for frames used as separators | - | ||||||
358 | (\l HLine and \l VLine) is specified by \l frameWidth. | - | ||||||
359 | - | |||||||
360 | The default value is 1. | - | ||||||
361 | - | |||||||
362 | \sa midLineWidth, frameWidth | - | ||||||
363 | */ | - | ||||||
364 | - | |||||||
365 | void QFrame::setLineWidth(int w) | - | ||||||
366 | { | - | ||||||
367 | Q_D(QFrame); | - | ||||||
368 | if (short(w) == d->lineWidth)
| 0 | ||||||
369 | return; never executed: return; | 0 | ||||||
370 | d->lineWidth = short(w); | - | ||||||
371 | d->updateFrameWidth(); | - | ||||||
372 | } never executed: end of block | 0 | ||||||
373 | - | |||||||
374 | int QFrame::lineWidth() const | - | ||||||
375 | { | - | ||||||
376 | Q_D(const QFrame); | - | ||||||
377 | return d->lineWidth; never executed: return d->lineWidth; | 0 | ||||||
378 | } | - | ||||||
379 | - | |||||||
380 | /*! | - | ||||||
381 | \property QFrame::midLineWidth | - | ||||||
382 | \brief the width of the mid-line | - | ||||||
383 | - | |||||||
384 | The default value is 0. | - | ||||||
385 | - | |||||||
386 | \sa lineWidth, frameWidth | - | ||||||
387 | */ | - | ||||||
388 | - | |||||||
389 | void QFrame::setMidLineWidth(int w) | - | ||||||
390 | { | - | ||||||
391 | Q_D(QFrame); | - | ||||||
392 | if (short(w) == d->midLineWidth)
| 0 | ||||||
393 | return; never executed: return; | 0 | ||||||
394 | d->midLineWidth = short(w); | - | ||||||
395 | d->updateFrameWidth(); | - | ||||||
396 | } never executed: end of block | 0 | ||||||
397 | - | |||||||
398 | int QFrame::midLineWidth() const | - | ||||||
399 | { | - | ||||||
400 | Q_D(const QFrame); | - | ||||||
401 | return d->midLineWidth; never executed: return d->midLineWidth; | 0 | ||||||
402 | } | - | ||||||
403 | - | |||||||
404 | /*! | - | ||||||
405 | \internal | - | ||||||
406 | Updates the frame widths from the style. | - | ||||||
407 | */ | - | ||||||
408 | void QFramePrivate::updateStyledFrameWidths() | - | ||||||
409 | { | - | ||||||
410 | Q_Q(const QFrame); | - | ||||||
411 | QStyleOptionFrame opt; | - | ||||||
412 | q->initStyleOption(&opt); | - | ||||||
413 | - | |||||||
414 | QRect cr = q->style()->subElementRect(QStyle::SE_ShapedFrameContents, &opt, q); | - | ||||||
415 | leftFrameWidth = cr.left() - opt.rect.left(); | - | ||||||
416 | topFrameWidth = cr.top() - opt.rect.top(); | - | ||||||
417 | rightFrameWidth = opt.rect.right() - cr.right(), | - | ||||||
418 | bottomFrameWidth = opt.rect.bottom() - cr.bottom(); | - | ||||||
419 | frameWidth = qMax(qMax(leftFrameWidth, rightFrameWidth), | - | ||||||
420 | qMax(topFrameWidth, bottomFrameWidth)); | - | ||||||
421 | } never executed: end of block | 0 | ||||||
422 | - | |||||||
423 | /*! | - | ||||||
424 | \internal | - | ||||||
425 | Updated the frameWidth parameter. | - | ||||||
426 | */ | - | ||||||
427 | - | |||||||
428 | void QFramePrivate::updateFrameWidth() | - | ||||||
429 | { | - | ||||||
430 | Q_Q(QFrame); | - | ||||||
431 | QRect fr = q->frameRect(); | - | ||||||
432 | updateStyledFrameWidths(); | - | ||||||
433 | q->setFrameRect(fr); | - | ||||||
434 | setLayoutItemMargins(QStyle::SE_FrameLayoutItem); | - | ||||||
435 | } never executed: end of block | 0 | ||||||
436 | - | |||||||
437 | /*! | - | ||||||
438 | \property QFrame::frameWidth | - | ||||||
439 | \brief the width of the frame that is drawn. | - | ||||||
440 | - | |||||||
441 | Note that the frame width depends on the \l{QFrame::setFrameStyle()}{frame style}, | - | ||||||
442 | not only the line width and the mid-line width. For example, the style specified | - | ||||||
443 | by \l NoFrame always has a frame width of 0, whereas the style \l Panel has a | - | ||||||
444 | frame width equivalent to the line width. | - | ||||||
445 | - | |||||||
446 | \sa lineWidth(), midLineWidth(), frameStyle() | - | ||||||
447 | */ | - | ||||||
448 | int QFrame::frameWidth() const | - | ||||||
449 | { | - | ||||||
450 | Q_D(const QFrame); | - | ||||||
451 | return d->frameWidth; never executed: return d->frameWidth; | 0 | ||||||
452 | } | - | ||||||
453 | - | |||||||
454 | - | |||||||
455 | /*! | - | ||||||
456 | \property QFrame::frameRect | - | ||||||
457 | \brief the frame's rectangle | - | ||||||
458 | - | |||||||
459 | The frame's rectangle is the rectangle the frame is drawn in. By | - | ||||||
460 | default, this is the entire widget. Setting the rectangle does | - | ||||||
461 | does \e not cause a widget update. The frame rectangle is | - | ||||||
462 | automatically adjusted when the widget changes size. | - | ||||||
463 | - | |||||||
464 | If you set the rectangle to a null rectangle (for example, | - | ||||||
465 | QRect(0, 0, 0, 0)), then the resulting frame rectangle is | - | ||||||
466 | equivalent to the \l{QWidget::rect()}{widget rectangle}. | - | ||||||
467 | */ | - | ||||||
468 | - | |||||||
469 | QRect QFrame::frameRect() const | - | ||||||
470 | { | - | ||||||
471 | Q_D(const QFrame); | - | ||||||
472 | QRect fr = contentsRect(); | - | ||||||
473 | fr.adjust(-d->leftFrameWidth, -d->topFrameWidth, d->rightFrameWidth, d->bottomFrameWidth); | - | ||||||
474 | return fr; never executed: return fr; | 0 | ||||||
475 | } | - | ||||||
476 | - | |||||||
477 | void QFrame::setFrameRect(const QRect &r) | - | ||||||
478 | { | - | ||||||
479 | Q_D(QFrame); | - | ||||||
480 | QRect cr = r.isValid() ? r : rect();
| 0 | ||||||
481 | cr.adjust(d->leftFrameWidth, d->topFrameWidth, -d->rightFrameWidth, -d->bottomFrameWidth); | - | ||||||
482 | setContentsMargins(cr.left(), cr.top(), rect().right() - cr.right(), rect().bottom() - cr.bottom()); | - | ||||||
483 | } never executed: end of block | 0 | ||||||
484 | - | |||||||
485 | /*!\reimp | - | ||||||
486 | */ | - | ||||||
487 | QSize QFrame::sizeHint() const | - | ||||||
488 | { | - | ||||||
489 | Q_D(const QFrame); | - | ||||||
490 | // Returns a size hint for the frame - for HLine and VLine | - | ||||||
491 | // shapes, this is stretchable one way and 3 pixels wide the | - | ||||||
492 | // other. For other shapes, QWidget::sizeHint() is used. | - | ||||||
493 | switch (d->frameStyle & Shape_Mask) { | - | ||||||
494 | case HLine: never executed: case HLine: | 0 | ||||||
495 | return QSize(-1,3); never executed: return QSize(-1,3); | 0 | ||||||
496 | case VLine: never executed: case VLine: | 0 | ||||||
497 | return QSize(3,-1); never executed: return QSize(3,-1); | 0 | ||||||
498 | default: never executed: default: | 0 | ||||||
499 | return QWidget::sizeHint(); never executed: return QWidget::sizeHint(); | 0 | ||||||
500 | } | - | ||||||
501 | } | - | ||||||
502 | - | |||||||
503 | /*!\reimp | - | ||||||
504 | */ | - | ||||||
505 | - | |||||||
506 | void QFrame::paintEvent(QPaintEvent *) | - | ||||||
507 | { | - | ||||||
508 | QPainter paint(this); | - | ||||||
509 | drawFrame(&paint); | - | ||||||
510 | } never executed: end of block | 0 | ||||||
511 | - | |||||||
512 | /*! | - | ||||||
513 | \internal | - | ||||||
514 | - | |||||||
515 | Used by QLabel and QLCDNumber | - | ||||||
516 | */ | - | ||||||
517 | void QFrame::drawFrame(QPainter *p) | - | ||||||
518 | { | - | ||||||
519 | QStyleOptionFrame opt; | - | ||||||
520 | initStyleOption(&opt); | - | ||||||
521 | style()->drawControl(QStyle::CE_ShapedFrame, &opt, p, this); | - | ||||||
522 | } never executed: end of block | 0 | ||||||
523 | - | |||||||
524 | - | |||||||
525 | /*!\reimp | - | ||||||
526 | */ | - | ||||||
527 | void QFrame::changeEvent(QEvent *ev) | - | ||||||
528 | { | - | ||||||
529 | Q_D(QFrame); | - | ||||||
530 | if (ev->type() == QEvent::StyleChange
| 0 | ||||||
531 | #ifdef Q_OS_MAC | - | ||||||
532 | || ev->type() == QEvent::MacSizeChange | - | ||||||
533 | #endif | - | ||||||
534 | ) | - | ||||||
535 | d->updateFrameWidth(); never executed: d->updateFrameWidth(); | 0 | ||||||
536 | QWidget::changeEvent(ev); | - | ||||||
537 | } never executed: end of block | 0 | ||||||
538 | - | |||||||
539 | /*! \reimp */ | - | ||||||
540 | bool QFrame::event(QEvent *e) | - | ||||||
541 | { | - | ||||||
542 | if (e->type() == QEvent::ParentChange)
| 0 | ||||||
543 | d_func()->updateFrameWidth(); never executed: d_func()->updateFrameWidth(); | 0 | ||||||
544 | bool result = QWidget::event(e); | - | ||||||
545 | //this has to be done after the widget has been polished | - | ||||||
546 | if (e->type() == QEvent::Polish)
| 0 | ||||||
547 | d_func()->updateFrameWidth(); never executed: d_func()->updateFrameWidth(); | 0 | ||||||
548 | return result; never executed: return result; | 0 | ||||||
549 | } | - | ||||||
550 | - | |||||||
551 | QT_END_NAMESPACE | - | ||||||
552 | - | |||||||
553 | #include "moc_qframe.cpp" | - | ||||||
Source code | Switch to Preprocessed file |